//Generate Z3 term for fun def
 private static bool GenerateFunction(FunctionDef def, FastTransducerInstance fti)
 {
     fti.functions.Add(new Function(def, fti, z3p));
     return true;
 }
        public Function(FunctionDef def, FastTransducerInstance fti, Z3Provider z3p)
        {
            this.z3p = z3p;
            this.arity = def.inputVariables.Count;
            this.name = def.id.text;
            this.outputSort = getSort(def.outputSort, fti);
            this.inputSorts = new Dictionary<string, Sort>();
            this.variableExprs = new Dictionary<string, Expr>(); //contains the terms for the variables of the function

            #region Compute input and outputs sort
            Sort[] inputs = new Sort[this.arity];
            uint i = 0;
            foreach (var va in def.inputVariables)
            {
                inputs[i] = getSort(va.Value, fti);
                inputSorts.Add(va.Key.text, inputs[i]);
                variableExprs.Add(va.Key.text, z3p.MkVar(i, inputs[i]));
                i++;
            }
            Expr[] varExprs = variableExprs.Values.ToArray();
            #endregion

            this.funcDecl = z3p.MkFreshFuncDecl(this.name, inputs, this.outputSort);
            var e = GenerateZ3ExprFromExpr(def.expr, fti);
            this.functionDef = e.Simplify(); //z3p.MkEqForall(z3p.MkApp(funcDecl, varExprs), GenerateZ3ExprFromExpr(def.expr, fti), varExprs);
        }
Esempio n. 3
0
 //Generate the C# corresponding to one function
 private static bool GenerateFun(FunctionDef def, StringBuilder sb)
 {
     sb.Append("public " + ((def.outputSort.kind == FastSortKind.Real) ? "double" : def.outputSort.name.text) + " " + def.id.text+"(");
     bool needComma=false;
     foreach (var e in def.inputVariables)
     {
         if (needComma)
             sb.Append(",");
         else
             needComma = true;
         sb.Append(((e.Value.name.text == "real") ? "double" : e.Value.name.text) + " " + e.Key.text);
     }
     sb.AppendLine("){");
     sb.Append("return ");
     PrintExpr(new List<FastToken>(), def.expr, sb);
     sb.AppendLine(";");
     sb.Append("}");
     sb.AppendLine();
     return true;
 }