Z3
src/api/java/FuncDecl.java
Go to the documentation of this file.
00001 
00018 package com.microsoft.z3;
00019 
00020 import com.microsoft.z3.enumerations.Z3_ast_kind;
00021 import com.microsoft.z3.enumerations.Z3_decl_kind;
00022 import com.microsoft.z3.enumerations.Z3_parameter_kind;
00023 
00027 public class FuncDecl extends AST
00028 {
00032     public boolean equals(Object o)
00033     {
00034         FuncDecl casted = null;
00035 
00036         try {
00037             casted = FuncDecl.class.cast(o);
00038         } catch (ClassCastException e) {
00039             return false;
00040         }
00041 
00042         return  
00043             (this == casted) || 
00044             (this != null) &&
00045             (casted != null) &&
00046             (getContext().nCtx() == casted.getContext().nCtx()) &&
00047             (Native.isEqFuncDecl(getContext().nCtx(), getNativeObject(), casted.getNativeObject()));
00048     }
00049 
00053     public int hashCode()
00054     {
00055         return super.hashCode();
00056     }
00057 
00061     public String toString()
00062     {
00063         try
00064         {
00065             return Native.funcDeclToString(getContext().nCtx(), getNativeObject());
00066         } catch (Z3Exception e)
00067         {
00068             return "Z3Exception: " + e.getMessage();
00069         }
00070     }
00071 
00075     public int getId()
00076     {
00077         return Native.getFuncDeclId(getContext().nCtx(), getNativeObject());
00078     }
00079 
00083     public int getArity()
00084     {
00085         return Native.getArity(getContext().nCtx(), getNativeObject());
00086     }
00087 
00092     public int getDomainSize()
00093     {
00094         return Native.getDomainSize(getContext().nCtx(), getNativeObject());
00095     }
00096 
00100     public Sort[] getDomain()
00101     {
00102 
00103         int n = getDomainSize();
00104 
00105         Sort[] res = new Sort[n];
00106         for (int i = 0; i < n; i++)
00107             res[i] = Sort.create(getContext(),
00108                     Native.getDomain(getContext().nCtx(), getNativeObject(), i));
00109         return res;
00110     }
00111 
00115     public Sort getRange()
00116     {
00117 
00118         return Sort.create(getContext(),
00119                 Native.getRange(getContext().nCtx(), getNativeObject()));
00120     }
00121 
00125     public Z3_decl_kind getDeclKind()
00126     {
00127         return Z3_decl_kind.fromInt(Native.getDeclKind(getContext().nCtx(),
00128                 getNativeObject()));
00129     }
00130 
00134     public Symbol getName()
00135     {
00136 
00137         return Symbol.create(getContext(),
00138                 Native.getDeclName(getContext().nCtx(), getNativeObject()));
00139     }
00140 
00144     public int getNumParameters()
00145     {
00146         return Native.getDeclNumParameters(getContext().nCtx(), getNativeObject());
00147     }
00148 
00152     public Parameter[] getParameters()
00153     {
00154 
00155         int num = getNumParameters();
00156         Parameter[] res = new Parameter[num];
00157         for (int i = 0; i < num; i++)
00158         {
00159             Z3_parameter_kind k = Z3_parameter_kind.fromInt(Native
00160                     .getDeclParameterKind(getContext().nCtx(), getNativeObject(), i));
00161             switch (k)
00162             {
00163             case Z3_PARAMETER_INT:
00164                 res[i] = new Parameter(k, Native.getDeclIntParameter(getContext()
00165                         .nCtx(), getNativeObject(), i));
00166                 break;
00167             case Z3_PARAMETER_DOUBLE:
00168                 res[i] = new Parameter(k, Native.getDeclDoubleParameter(
00169                         getContext().nCtx(), getNativeObject(), i));
00170                 break;
00171             case Z3_PARAMETER_SYMBOL:
00172                 res[i] = new Parameter(k, Symbol.create(getContext(), Native
00173                         .getDeclSymbolParameter(getContext().nCtx(),
00174                                 getNativeObject(), i)));
00175                 break;
00176             case Z3_PARAMETER_SORT:
00177                 res[i] = new Parameter(k, Sort.create(getContext(), Native
00178                         .getDeclSortParameter(getContext().nCtx(), getNativeObject(),
00179                                 i)));
00180                 break;
00181             case Z3_PARAMETER_AST:
00182                 res[i] = new Parameter(k, new AST(getContext(),
00183                         Native.getDeclAstParameter(getContext().nCtx(),
00184                                 getNativeObject(), i)));
00185                 break;
00186             case Z3_PARAMETER_FUNC_DECL:
00187                 res[i] = new Parameter(k, new FuncDecl(getContext(),
00188                         Native.getDeclFuncDeclParameter(getContext().nCtx(),
00189                                 getNativeObject(), i)));
00190                 break;
00191             case Z3_PARAMETER_RATIONAL:
00192                 res[i] = new Parameter(k, Native.getDeclRationalParameter(
00193                         getContext().nCtx(), getNativeObject(), i));
00194                 break;
00195             default:
00196                 throw new Z3Exception(
00197                         "Unknown function declaration parameter kind encountered");
00198             }
00199         }
00200         return res;
00201     }
00202 
00206     public class Parameter
00207     {
00208         private Z3_parameter_kind kind;
00209         private int i;
00210         private double d;
00211         private Symbol sym;
00212         private Sort srt;
00213         private AST ast;
00214         private FuncDecl fd;
00215         private String r;
00216 
00220         public int getInt()
00221         {
00222             if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_INT)
00223                 throw new Z3Exception("parameter is not an int");
00224             return i;
00225         }
00226 
00230         public double getDouble()
00231         {
00232             if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_DOUBLE)
00233                 throw new Z3Exception("parameter is not a double ");
00234             return d;
00235         }
00236 
00240         public Symbol getSymbol()
00241         {
00242             if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_SYMBOL)
00243                 throw new Z3Exception("parameter is not a Symbol");
00244             return sym;
00245         }
00246 
00250         public Sort getSort()
00251         {
00252             if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_SORT)
00253                 throw new Z3Exception("parameter is not a Sort");
00254             return srt;
00255         }
00256 
00260         public AST getAST()
00261         {
00262             if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_AST)
00263                 throw new Z3Exception("parameter is not an AST");
00264             return ast;
00265         }
00266 
00270         public FuncDecl getFuncDecl()
00271         {
00272             if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_FUNC_DECL)
00273                 throw new Z3Exception("parameter is not a function declaration");
00274             return fd;
00275         }
00276 
00280         public String getRational()
00281         {
00282             if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_RATIONAL)
00283                 throw new Z3Exception("parameter is not a rational String");
00284             return r;
00285         }
00286 
00290         public Z3_parameter_kind getParameterKind()
00291         {
00292             return kind;
00293         }
00294 
00295         Parameter(Z3_parameter_kind k, int i)
00296         {
00297             this.kind = k;
00298             this.i = i;
00299         }
00300 
00301         Parameter(Z3_parameter_kind k, double d)
00302         {
00303             this.kind = k;
00304             this.d = d;
00305         }
00306 
00307         Parameter(Z3_parameter_kind k, Symbol s)
00308         {
00309             this.kind = k;
00310             this.sym = s;
00311         }
00312 
00313         Parameter(Z3_parameter_kind k, Sort s)
00314         {
00315             this.kind = k;
00316             this.srt = s;
00317         }
00318 
00319         Parameter(Z3_parameter_kind k, AST a)
00320         {
00321             this.kind = k;
00322             this.ast = a;
00323         }
00324 
00325         Parameter(Z3_parameter_kind k, FuncDecl fd)
00326         {
00327             this.kind = k;
00328             this.fd = fd;
00329         }
00330 
00331         Parameter(Z3_parameter_kind k, String r)
00332         {
00333             this.kind = k;
00334             this.r = r;
00335         }
00336     }
00337 
00338     FuncDecl(Context ctx, long obj)
00339     {
00340         super(ctx, obj);
00341 
00342     }
00343 
00344     FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range)
00345            
00346     {
00347         super(ctx, Native.mkFuncDecl(ctx.nCtx(), name.getNativeObject(),
00348                 AST.arrayLength(domain), AST.arrayToNative(domain),
00349                 range.getNativeObject()));
00350 
00351     }
00352 
00353     FuncDecl(Context ctx, String prefix, Sort[] domain, Sort range)
00354            
00355     {
00356         super(ctx, Native.mkFreshFuncDecl(ctx.nCtx(), prefix,
00357                 AST.arrayLength(domain), AST.arrayToNative(domain),
00358                 range.getNativeObject()));
00359 
00360     }
00361 
00362     void checkNativeObject(long obj)
00363     {
00364         if (Native.getAstKind(getContext().nCtx(), obj) != Z3_ast_kind.Z3_FUNC_DECL_AST
00365                 .toInt())
00366             throw new Z3Exception(
00367                     "Underlying object is not a function declaration");
00368         super.checkNativeObject(obj);
00369     }
00370 
00377     public Expr apply(Expr ... args)
00378     {
00379         getContext().checkContextMatch(args);
00380         return Expr.create(getContext(), this, args);
00381     }
00382 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines