Z3
ASTVector.cs
Go to the documentation of this file.
1 /*++
2 Copyright (c) 2012 Microsoft Corporation
3 
4 Module Name:
5 
6  ASTVector.cs
7 
8 Abstract:
9 
10  Z3 Managed API: AST Vectors
11 
12 Author:
13 
14  Christoph Wintersteiger (cwinter) 2012-03-21
15 
16 Notes:
17 
18 --*/
19 
20 using System;
21 using System.Diagnostics.Contracts;
22 
23 namespace Microsoft.Z3
24 {
28  internal class ASTVector : Z3Object
29  {
33  public uint Size
34  {
35  get { return Native.Z3_ast_vector_size(Context.nCtx, NativeObject); }
36  }
37 
44  public AST this[uint i]
45  {
46  get
47  {
48  Contract.Ensures(Contract.Result<AST>() != null);
49 
50  return new AST(Context, Native.Z3_ast_vector_get(Context.nCtx, NativeObject, i));
51  }
52  set
53  {
54  Contract.Requires(value != null);
55 
56  Native.Z3_ast_vector_set(Context.nCtx, NativeObject, i, value.NativeObject);
57  }
58  }
59 
64  public void Resize(uint newSize)
65  {
66  Native.Z3_ast_vector_resize(Context.nCtx, NativeObject, newSize);
67  }
68 
74  public void Push(AST a)
75  {
76  Contract.Requires(a != null);
77 
78  Native.Z3_ast_vector_push(Context.nCtx, NativeObject, a.NativeObject);
79  }
80 
86  public ASTVector Translate(Context ctx)
87  {
88  Contract.Requires(ctx != null);
89  Contract.Ensures(Contract.Result<ASTVector>() != null);
90 
91  return new ASTVector(Context, Native.Z3_ast_vector_translate(Context.nCtx, NativeObject, ctx.nCtx));
92  }
93 
97  public override string ToString()
98  {
99  return Native.Z3_ast_vector_to_string(Context.nCtx, NativeObject);
100  }
101 
102  #region Internal
103  internal ASTVector(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
104  internal ASTVector(Context ctx) : base(ctx, Native.Z3_mk_ast_vector(ctx.nCtx)) { Contract.Requires(ctx != null); }
105 
106  internal class DecRefQueue : IDecRefQueue
107  {
108  public override void IncRef(Context ctx, IntPtr obj)
109  {
110  Native.Z3_ast_vector_inc_ref(ctx.nCtx, obj);
111  }
112 
113  public override void DecRef(Context ctx, IntPtr obj)
114  {
115  Native.Z3_ast_vector_dec_ref(ctx.nCtx, obj);
116  }
117  };
118 
119  internal override void IncRef(IntPtr o)
120  {
121  Context.ASTVector_DRQ.IncAndClear(Context, o);
122  base.IncRef(o);
123  }
124 
125  internal override void DecRef(IntPtr o)
126  {
127  Context.ASTVector_DRQ.Add(o);
128  base.DecRef(o);
129  }
130  #endregion
131  }
132 }
Z3_ast_vector Z3_API Z3_mk_ast_vector(__in Z3_context c)
Return an empty AST vector.