public Bpl.Function CreateTypeFunction(ITypeReference type, int parameterCount)
        {
            System.Diagnostics.Debug.Assert(parameterCount >= 0);
            string typename = TypeHelper.GetTypeName(type, NameFormattingOptions.DocumentationId);

            typename = TranslationHelper.TurnStringIntoValidIdentifier(typename);
            Bpl.IToken          tok    = type.Token();
            List <Bpl.Variable> inputs = new List <Bpl.Variable>();

            //for (int i = 0; i < parameterCount; i++) {
            //  inputs.Add(new Bpl.Formal(tok, new Bpl.TypedIdent(tok, "arg"+i, this.TypeType), true));
            //}
            foreach (var t in TranslationHelper.ConsolidatedGenericParameters(type))
            {
                var n  = t.Name.Value;
                var n2 = TranslationHelper.TurnStringIntoValidIdentifier(n);
                inputs.Add(new Bpl.Formal(Bpl.Token.NoToken, new Bpl.TypedIdent(Bpl.Token.NoToken, n2, this.TypeType), true));
            }
            Bpl.Variable output = new Bpl.Formal(tok, new Bpl.TypedIdent(tok, "result", this.TypeType), false);
            Bpl.Function func   = new Bpl.Function(tok, typename, inputs, output);
            var          attrib = new Bpl.QKeyValue(Bpl.Token.NoToken, "constructor", new List <object>(1), null);

            func.Attributes = attrib;
            return(func);
        }
        public Bpl.Expr FromUnion(Bpl.IToken tok, Bpl.Type boogieType, Bpl.Expr expr, bool isStruct)
        {
            if (boogieType == UnionType || boogieType == RefType)
            {
                return(expr);
            }

            Bpl.Function conversion = null;
            if (boogieType == Bpl.Type.Bool)
            {
                conversion = this.Union2Bool;
            }
            else if (boogieType == Bpl.Type.Int)
            {
                conversion = this.Union2Int;
            }
            else if (boogieType == RealType)
            {
                conversion = this.Union2Real;
            }
            else
            {
                throw new InvalidOperationException(String.Format("Unknown Boogie type: '{0}'", boogieType.ToString()));
            }

            var callExpr = new Bpl.NAryExpr(
                tok,
                new Bpl.FunctionCall(conversion),
                new List <Bpl.Expr>(new Bpl.Expr[] { expr })
                );

            callExpr.Type = boogieType;
            return(callExpr);
        }
Beispiel #3
0
 public override Function VisitFunction(Function node) {
   //Contract.Requires(node != null);
   Contract.Ensures(Contract.Result<Function>() != null);
   return base.VisitFunction((Function)node.Clone());
 }
Beispiel #4
0
 public override Function VisitFunction(Function node)
 {
     Contract.Ensures(Contract.Result<Function>() == node);
     node = (Function)this.VisitDeclWithFormals(node);
     if (node.Body != null)
         this.VisitExpr(node.Body);
     return node;
 }
Beispiel #5
0
 public virtual Function VisitFunction(Function node) {
   Contract.Requires(node != null);
   Contract.Ensures(Contract.Result<Function>() != null);
   node = (Function)this.VisitDeclWithFormals(node);
   if (node.Body != null)
     node.Body = this.VisitExpr(node.Body);
   return node;
 }
 public Bpl.Function CreateTypeFunction(ITypeReference type, int parameterCount) {
   System.Diagnostics.Debug.Assert(parameterCount >= 0);
   string typename = TypeHelper.GetTypeName(type, NameFormattingOptions.DocumentationId);
   typename = TranslationHelper.TurnStringIntoValidIdentifier(typename);
   Bpl.IToken tok = type.Token();
   List<Bpl.Variable> inputs = new List<Bpl.Variable>();
   //for (int i = 0; i < parameterCount; i++) {
   //  inputs.Add(new Bpl.Formal(tok, new Bpl.TypedIdent(tok, "arg"+i, this.TypeType), true));
   //}
   foreach (var t in TranslationHelper.ConsolidatedGenericParameters(type)) {
     var n = t.Name.Value;
     var n2 = TranslationHelper.TurnStringIntoValidIdentifier(n);
     inputs.Add(new Bpl.Formal(Bpl.Token.NoToken, new Bpl.TypedIdent(Bpl.Token.NoToken, n2, this.TypeType), true));
   }
   Bpl.Variable output = new Bpl.Formal(tok, new Bpl.TypedIdent(tok, "result", this.TypeType), false);
   Bpl.Function func = new Bpl.Function(tok, typename, inputs, output);
   var attrib = new Bpl.QKeyValue(Bpl.Token.NoToken, "constructor", new List<object>(1), null);
   func.Attributes = attrib;
   return func;
 }