Z3
Data Structures | Public Member Functions
AST Class Reference
+ Inheritance diagram for AST:

Public Member Functions

boolean equals (Object o)
 
int compareTo (AST other)
 
int hashCode ()
 
int getId ()
 
AST translate (Context ctx)
 
Z3_ast_kind getASTKind ()
 
boolean isExpr ()
 
boolean isApp ()
 
boolean isVar ()
 
boolean isQuantifier ()
 
boolean isSort ()
 
boolean isFuncDecl ()
 
String toString ()
 
String getSExpr ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Z3Object
static long[] arrayToNative (Z3Object[] a)
 
static int arrayLength (Z3Object[] a)
 

Detailed Description

The abstract syntax tree (AST) class.

Definition at line 27 of file AST.java.

Member Function Documentation

◆ compareTo()

int compareTo ( AST  other)
inline

Object Comparison.

Parameters
otherAnother AST
Returns
Negative if the object should be sorted before
other
, positive if after else zero.
Exceptions
Z3Exceptionon error

Definition at line 55 of file AST.java.

56  {
57  if (other == null) {
58  return 1;
59  }
60  return Integer.compare(getId(), other.getId());
61  }

◆ equals()

boolean equals ( Object  o)
inline

Object comparison.

Parameters
oanother AST

Reimplemented in Sort, and FuncDecl< R extends Sort >.

Definition at line 35 of file AST.java.

36  {
37  if (o == this) return true;
38  if (!(o instanceof AST)) return false;
39  AST casted = (AST) o;
40 
41  return
42  (getContext().nCtx() == casted.getContext().nCtx()) &&
43  (Native.isEqAst(getContext().nCtx(), getNativeObject(), casted.getNativeObject()));
44  }

◆ getASTKind()

Z3_ast_kind getASTKind ( )
inline

The kind of the AST.

Exceptions
Z3Exceptionon error

Definition at line 103 of file AST.java.

104  {
105  return Z3_ast_kind.fromInt(Native.getAstKind(getContext().nCtx(),
106  getNativeObject()));
107  }
Z3_ast_kind
The different kinds of Z3 AST (abstract syntax trees). That is, terms, formulas and types.
Definition: z3_api.h:141

Referenced by AST.isApp(), AST.isExpr(), AST.isFuncDecl(), AST.isQuantifier(), AST.isSort(), and AST.isVar().

◆ getId()

int getId ( )
inline

A unique identifier for the AST (unique among all ASTs).

Exceptions
Z3Exceptionon error

Reimplemented in Sort, and FuncDecl< R extends Sort >.

Definition at line 78 of file AST.java.

79  {
80  return Native.getAstId(getContext().nCtx(), getNativeObject());
81  }

Referenced by AST.compareTo().

◆ getSExpr()

String getSExpr ( )
inline

A string representation of the AST in s-expression notation.

Definition at line 185 of file AST.java.

186  {
187  return Native.astToString(getContext().nCtx(), getNativeObject());
188  }

◆ hashCode()

int hashCode ( )
inline

The AST's hash code.

Returns
A hash code

Reimplemented in Sort.

Definition at line 69 of file AST.java.

70  {
71  return Native.getAstHash(getContext().nCtx(), getNativeObject());
72  }

◆ isApp()

boolean isApp ( )
inline

Indicates whether the AST is an application

Returns
a boolean
Exceptions
Z3Exceptionon error

Definition at line 133 of file AST.java.

134  {
135  return this.getASTKind() == Z3_ast_kind.Z3_APP_AST;
136  }
Z3_ast_kind getASTKind()
Definition: AST.java:103

◆ isExpr()

boolean isExpr ( )
inline

Indicates whether the AST is an Expr

Exceptions
Z3Exceptionon error
Z3Exceptionon error

Definition at line 114 of file AST.java.

115  {
116  switch (getASTKind())
117  {
118  case Z3_APP_AST:
119  case Z3_NUMERAL_AST:
120  case Z3_QUANTIFIER_AST:
121  case Z3_VAR_AST:
122  return true;
123  default:
124  return false;
125  }
126  }
@ Z3_APP_AST
Definition: z3_api.h:143
@ Z3_VAR_AST
Definition: z3_api.h:144
@ Z3_NUMERAL_AST
Definition: z3_api.h:142
@ Z3_QUANTIFIER_AST
Definition: z3_api.h:145

◆ isFuncDecl()

boolean isFuncDecl ( )
inline

Indicates whether the AST is a FunctionDeclaration

Definition at line 169 of file AST.java.

170  {
171  return this.getASTKind() == Z3_ast_kind.Z3_FUNC_DECL_AST;
172  }

◆ isQuantifier()

boolean isQuantifier ( )
inline

Indicates whether the AST is a Quantifier

Returns
a boolean
Exceptions
Z3Exceptionon error

Definition at line 153 of file AST.java.

154  {
155  return this.getASTKind() == Z3_ast_kind.Z3_QUANTIFIER_AST;
156  }

◆ isSort()

boolean isSort ( )
inline

Indicates whether the AST is a Sort

Definition at line 161 of file AST.java.

162  {
163  return this.getASTKind() == Z3_ast_kind.Z3_SORT_AST;
164  }

◆ isVar()

boolean isVar ( )
inline

Indicates whether the AST is a BoundVariable.

Returns
a boolean
Exceptions
Z3Exceptionon error

Definition at line 143 of file AST.java.

144  {
145  return this.getASTKind() == Z3_ast_kind.Z3_VAR_AST;
146  }

◆ toString()

String toString ( )
inline

A string representation of the AST.

Reimplemented in Sort, Pattern, FuncDecl< R extends Sort >, and Expr< R extends Sort >.

Definition at line 178 of file AST.java.

178  {
179  return Native.astToString(getContext().nCtx(), getNativeObject());
180  }

◆ translate()

AST translate ( Context  ctx)
inline

Translates (copies) the AST to the Context

ctx

.

Parameters
ctxA context
Returns
A copy of the AST which is associated with
ctx
Exceptions
Z3Exceptionon error

Reimplemented in Sort, FuncDecl< R extends Sort >, and Expr< R extends Sort >.

Definition at line 90 of file AST.java.

91  {
92  if (getContext() == ctx) {
93  return this;
94  } else {
95  return create(ctx, Native.translate(getContext().nCtx(), getNativeObject(), ctx.nCtx()));
96  }
97  }

Referenced by AstRef.__copy__(), Goal.__copy__(), AstVector.__copy__(), FuncInterp.__copy__(), ModelRef.__copy__(), Solver.__copy__(), Goal.__deepcopy__(), AstVector.__deepcopy__(), FuncInterp.__deepcopy__(), ModelRef.__deepcopy__(), and Solver.__deepcopy__().