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  public 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 
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 DecRefQueue() : base() { }
109  public DecRefQueue(uint move_limit) : base(move_limit) { }
110  internal override void IncRef(Context ctx, IntPtr obj)
111  {
112  Native.Z3_ast_vector_inc_ref(ctx.nCtx, obj);
113  }
114 
115  internal override void DecRef(Context ctx, IntPtr obj)
116  {
117  Native.Z3_ast_vector_dec_ref(ctx.nCtx, obj);
118  }
119  };
120 
121  internal override void IncRef(IntPtr o)
122  {
123  Context.ASTVector_DRQ.IncAndClear(Context, o);
124  base.IncRef(o);
125  }
126 
127  internal override void DecRef(IntPtr o)
128  {
129  Context.ASTVector_DRQ.Add(o);
130  base.DecRef(o);
131  }
132  #endregion
133  }
134 }
static Z3_ast Z3_ast_vector_get(Z3_context a0, Z3_ast_vector a1, uint a2)
Definition: Native.cs:4464
override string ToString()
Retrieves a string representation of the vector.
Definition: ASTVector.cs:97
void Resize(uint newSize)
Resize the vector to newSize .
Definition: ASTVector.cs:64
ASTVector Translate(Context ctx)
Translates all ASTs in the vector to ctx .
Definition: ASTVector.cs:86
Vectors of ASTs.
Definition: ASTVector.cs:28
static void Z3_ast_vector_push(Z3_context a0, Z3_ast_vector a1, Z3_ast a2)
Definition: Native.cs:4486
static void Z3_ast_vector_resize(Z3_context a0, Z3_ast_vector a1, uint a2)
Definition: Native.cs:4479
static void Z3_ast_vector_set(Z3_context a0, Z3_ast_vector a1, uint a2, Z3_ast a3)
Definition: Native.cs:4472
void Push(AST a)
Add the AST a to the back of the vector. The size is increased by 1.
Definition: ASTVector.cs:74
static Z3_ast_vector Z3_ast_vector_translate(Z3_context a0, Z3_ast_vector a1, Z3_context a2)
Definition: Native.cs:4493
The main interaction with Z3 happens via the Context.
Definition: Context.cs:31
The abstract syntax tree (AST) class.
Definition: AST.cs:31
static uint Z3_ast_vector_size(Z3_context a0, Z3_ast_vector a1)
Definition: Native.cs:4456
Internal base class for interfacing with native Z3 objects. Should not be used externally.
Definition: Z3Object.cs:31
static string Z3_ast_vector_to_string(Z3_context a0, Z3_ast_vector a1)
Definition: Native.cs:4501
Z3_ast_vector Z3_API Z3_mk_ast_vector(__in Z3_context c)
Return an empty AST vector.