Esempio n. 1
0
 public void Error(Absy subject, string msg, params object[] args)
 {
     Contract.Requires(args != null);
       Contract.Requires(msg != null);
       Contract.Requires(subject != null);
       Error(subject.tok, msg, args);
 }
Esempio n. 2
0
    private void CheckTypeParams(Absy node, TypeParamInstantiation insts) {
      Contract.Requires(insts != null);
      Contract.Requires(node != null);
      foreach (TypeVariable/*!*/ var in insts.FormalTypeParams) {
        Contract.Assert(var != null);
        Type/*!*/ inst = insts[var];
        Contract.Assert(inst != null);

        inTypeSeeker.FoundAmbiguity = false;
        inTypeSeeker.Visit(inst);
        if (inTypeSeeker.FoundAmbiguity)
          TC.Warning(node,
                     "type parameter {0} is ambiguous, instantiating to {1}",
                     var, inst);
      }
    }
Esempio n. 3
0
 public static Absy Desugar(Absy node, out List<Expr/*!*/>/*!*/ axioms, out List<Function/*!*/>/*!*/ functions)
 {
     Contract.Requires(node != null);
       Contract.Ensures(cce.NonNullElements(Contract.ValueAtReturn(out functions)));
       Contract.Ensures(cce.NonNullElements(Contract.ValueAtReturn(out axioms)));
       Contract.Ensures(Contract.Result<Absy>() != null);
       LambdaVisitor v = new LambdaVisitor();
       node = v.Visit(node);
       axioms = v.lambdaAxioms;
       functions = v.lambdaFunctions;
       if (CommandLineOptions.Clo.TraceVerify) {
     Console.WriteLine("Desugaring of lambda expressions produced {0} functions and {1} axioms:", functions.Count, axioms.Count);
     TokenTextWriter wr = new TokenTextWriter("<console>", Console.Out);
     foreach (Function f in functions) {
       f.Emit(wr, 0);
     }
     foreach (Expr ax in axioms) {
       ax.Emit(wr);
       Console.WriteLine();
     }
       }
       return node;
 }
Esempio n. 4
0
 /// <summary>
 /// Switches on node.NodeType to call a visitor method that has been specialized for node.
 /// </summary>
 /// <param name="a">The Absy node to be visited.</param>
 /// <returns> Returns null if node is null. Otherwise returns an updated node (possibly a different object).</returns>
 public abstract Absy/*!*/ Visit(Absy/*!*/ node);
 public static void Collect(Absy node, out List<DeclWithFormals> dependencies)
 {
     var dc = new DependencyCollector();
       dc.Visit(node);
       dependencies = dc.dependencies.ToList();
 }
Esempio n. 6
0
 /// <summary>
 /// Checks if name coincides with the name of a bitvector type.  If so, reports an error and
 /// returns true; otherwise, returns false.
 /// </summary>
 private bool CheckBvNameClashes(Absy absy, string name)
 {
     Contract.Requires(name != null);
       Contract.Requires(absy != null);
       if (name.StartsWith("bv") && name.Length > 2) {
     for (int i = 2; i < name.Length; ++i)
       if (!char.IsDigit(name[i]))
     return false;
     Error(absy, "type name: {0} is registered for bitvectors", name);
     return true;
       }
       return false;
 }
Esempio n. 7
0
 private IEnumerable<Variable> AvailableLinearVars(Absy absy)
 {
     HashSet<Variable> availableVars = new HashSet<Variable>(linearTypeChecker.AvailableLinearVars(absyMap[absy]));
     foreach (var g in civlTypeChecker.globalVarToSharedVarInfo.Keys)
     {
         SharedVariableInfo info = civlTypeChecker.globalVarToSharedVarInfo[g];
         if (!(info.introLayerNum <= layerNum && layerNum <= info.hideLayerNum))
         {
             availableVars.Remove(g);
         }
     }
     foreach (var v in civlTypeChecker.localVarToLocalVariableInfo.Keys)
     {
         LocalVariableInfo info = civlTypeChecker.localVarToLocalVariableInfo[v];
         if (info.isGhost)
         {
             if (info.layer != layerNum)
             {
                 availableVars.Remove(v);
             }
         }
         else
         {
             if (layerNum < info.layer)
             {
                 availableVars.Remove(v);
             }
         }
     }
     return availableVars;
 }
Esempio n. 8
0
 public IEnumerable<Variable> AvailableLinearVars(Absy absy)
 {
     if (availableLinearVars.ContainsKey(absy))
     {
         return availableLinearVars[absy];
     }
     else
     {
         return new HashSet<Variable>();
     }
 }
Esempio n. 9
0
 public override Absy Visit(Absy node)
 {
     Contract.Ensures(Contract.Result<Absy>() == node);
     return node.StdDispatch(this);
 }
Esempio n. 10
0
 private void CheckAndAddLayers(Absy node, QKeyValue attributes, int enclosingProcLayerNum)
 {
     List<int> attrs = FindLayers(attributes);
     if (attrs.Count == 0)
     {
         Error(node, "layer not present");
         return;
     }
     absyToLayerNums[node] = new HashSet<int>();
     foreach (int layerNum in attrs)
     {
         if (layerNum == leastUnimplementedLayerNum || !AllCreatedLayerNums.Contains(layerNum))
         {
             Error(node, "Illegal layer number");
         }
         else if (layerNum > enclosingProcLayerNum)
         {
             Error(node, "The layer cannot be greater than the layer of enclosing procedure");
         }
         else if (maxLayerNum < layerNum && layerNum <= minLayerNum)
         {
             absyToLayerNums[node].Add(layerNum);
         }
         else
         {
             Error(node, string.Format("A variable being accessed in this specification is unavailable at layer {0}", layerNum));
         }
     }
 }
Esempio n. 11
0
 private IEnumerable<Variable> AvailableLinearVars(Absy absy)
 {
     return linearTypeChecker.AvailableLinearVars(absyMap[absy]);
 }
Esempio n. 12
0
 public override Absy Visit(Absy node)
 {
     //Contract.Requires(node != null);
       Contract.Ensures(Contract.Result<Absy>() != null);
       return node.StdDispatch(this);
 }
 private IEnumerable<VariableDescriptor> GetReferencedVariables(Absy node, string proc)
 {
     var VarCollector = new VariableCollector();
       VarCollector.Visit(node);
       return VarCollector.usedVars.Where(Item => VariableRelevantToAnalysis(Item, proc)).
     Select(Item => MakeDescriptor(proc, Item));
 }
Esempio n. 14
0
 private HashSet<Variable> AvailableLinearVars(Absy absy)
 {
     return linearTypeChecker.availableLinearVars[absyMap[absy]];
 }
Esempio n. 15
0
            public override Absy Visit(Absy node)
            {
                //Contract.Requires(node != null);
                Contract.Ensures(Contract.Result<Absy>() != null);
                node = base.Visit(node);

                LambdaExpr lambda = node as LambdaExpr;
                if (lambda != null) {
                  IToken/*!*/ tok = lambda.tok;
                  Contract.Assert(tok != null);

                  Set freeVars = new Set();
                  lambda.ComputeFreeVariables(freeVars);
                  // this is ugly, the output will depend on hashing order
                  Dictionary<Variable, Expr> subst = new Dictionary<Variable, Expr>();
                  List<Variable> formals = new List<Variable>();
                  List<Expr> callArgs = new List<Expr>();
                  List<Expr> axCallArgs = new List<Expr>();
                  List<Variable> dummies = new List<Variable>(lambda.Dummies);
                  List<TypeVariable> freeTypeVars = new List<TypeVariable>();
                  List<Type/*!*/> fnTypeVarActuals = new List<Type/*!*/>();
                  List<TypeVariable> freshTypeVars = new List<TypeVariable>();  // these are only used in the lambda@n function's definition
                  foreach (object o in freeVars) {
                // 'o' is either a Variable or a TypeVariable.  Since the lambda desugaring happens only
                // at the outermost level of a program (where there are no mutable variables) and, for
                // procedure bodies, after the statements have been passified (when mutable variables have
                // been replaced by immutable incarnations), we are interested only in BoundVar's and
                // TypeVariable's.
                BoundVariable v = o as BoundVariable;
                if (v != null) {
                  TypedIdent ti = new TypedIdent(v.TypedIdent.tok, v.TypedIdent.Name, v.TypedIdent.Type);
                  Formal f = new Formal(v.tok, ti, true);
                  formals.Add(f);
                  BoundVariable b = new BoundVariable(v.tok, ti);
                  dummies.Add(b);
                  callArgs.Add(new IdentifierExpr(v.tok, v));
                  Expr/*!*/ id = new IdentifierExpr(f.tok, b);
                  Contract.Assert(id != null);
                  subst.Add(v, id);
                  axCallArgs.Add(id);
                } else if (o is TypeVariable) {
                  TypeVariable tv = (TypeVariable)o;
                  freeTypeVars.Add(tv);
                  fnTypeVarActuals.Add(tv);
                  freshTypeVars.Add(new TypeVariable(tv.tok, tv.Name));
                }
                  }

                  Formal res = new Formal(tok, new TypedIdent(tok, TypedIdent.NoName, cce.NonNull(lambda.Type)), false);
                  Function fn = new Function(tok, "lambda@" + lambdaid++, freshTypeVars, formals, res, "auto-generated lambda function", lambda.Attributes);
                  lambdaFunctions.Add(fn);

                  FunctionCall fcall = new FunctionCall(new IdentifierExpr(tok, fn.Name));
                  fcall.Func = fn;  // resolve here

                  List<Expr/*!*/> selectArgs = new List<Expr/*!*/>();
                  foreach (Variable/*!*/ v in lambda.Dummies) {
                Contract.Assert(v != null);
                selectArgs.Add(new IdentifierExpr(v.tok, v));
                  }
                  NAryExpr axcall = new NAryExpr(tok, fcall, axCallArgs);
                  axcall.Type = res.TypedIdent.Type;
                  axcall.TypeParameters = SimpleTypeParamInstantiation.From(freeTypeVars, fnTypeVarActuals);
                  NAryExpr select = Expr.Select(axcall, selectArgs);
                  select.Type = lambda.Body.Type;
                  List<Type/*!*/> selectTypeParamActuals = new List<Type/*!*/>();
                  List<TypeVariable> forallTypeVariables = new List<TypeVariable>();
                  foreach (TypeVariable/*!*/ tp in lambda.TypeParameters) {
                Contract.Assert(tp != null);
                selectTypeParamActuals.Add(tp);
                forallTypeVariables.Add(tp);
                  }
                  forallTypeVariables.AddRange(freeTypeVars);
                  select.TypeParameters = SimpleTypeParamInstantiation.From(lambda.TypeParameters, selectTypeParamActuals);

                  Expr bb = Substituter.Apply(Substituter.SubstitutionFromHashtable(subst), lambda.Body);
                  NAryExpr body = Expr.Eq(select, bb);
                  body.Type = Type.Bool;
                  body.TypeParameters = SimpleTypeParamInstantiation.EMPTY;
                  Trigger trig = new Trigger(select.tok, true, new List<Expr> { select });
                  lambdaAxioms.Add(new ForallExpr(tok, forallTypeVariables, dummies, lambda.Attributes, trig, body));

                  NAryExpr call = new NAryExpr(tok, fcall, callArgs);
                  call.Type = res.TypedIdent.Type;
                  call.TypeParameters = SimpleTypeParamInstantiation.From(freeTypeVars, fnTypeVarActuals);

                  return call;
                }

                return node;
            }
Esempio n. 16
0
    public override Absy Visit(Absy node) {
      Contract.Requires(node != null);
      Contract.Ensures(Contract.Result<Absy>() != null);

      throw new System.NotImplementedException();
    }
Esempio n. 17
0
 public override Absy Visit(Absy node) {
   return node.StdDispatch(this);
 }
Esempio n. 18
0
 public string CodeLabel(Absy code, StratifiedInliningInfo info, string prefix)
 {
     if (info.label2absyInv == null)
     {
         info.label2absyInv = new Dictionary<Absy, string>();
         foreach (int foo in info.label2absy.Keys)
         {
             Absy bar = info.label2absy[foo] as Absy;
             string lbl = foo.ToString();
             info.label2absyInv.Add(bar, lbl);
         }
     }
     if (info.label2absyInv.ContainsKey(code))
     {
         string label = info.label2absyInv[code];
         return prefix+label;
     }
     return null;
 }
Esempio n. 19
0
 private void Error(Absy node, string message)
 {
     checkingContext.Error(node, message);
     errorCount++;
 }
Esempio n. 20
0
        public Term CodeLabeledExpr(RPFP rpfp, RPFP.Node root, Absy code, StratifiedInliningInfo info, string prefix)
        {
            string label = CodeLabel(code, info, prefix);

            if (label != null)
            {
                var res = labels[label];
                return res;
            }
            else return null;
        }
Esempio n. 21
0
 private void AddDisjointnessExpr(List<Cmd> newCmds, Absy absy, Dictionary<string, Variable> domainNameToInputVar)
 {
     Dictionary<string, HashSet<Variable>> domainNameToScope = new Dictionary<string, HashSet<Variable>>();
     foreach (var domainName in linearDomains.Keys)
     {
         domainNameToScope[domainName] = new HashSet<Variable>();
     }
     foreach (Variable v in AvailableLinearVars(absy))
     {
         var domainName = FindDomainName(v);
         domainNameToScope[domainName].Add(v);
     }
     foreach (Variable v in globalVarToDomainName.Keys)
     {
         var domainName = FindDomainName(v);
         domainNameToScope[domainName].Add(v);
     }
     foreach (string domainName in linearDomains.Keys)
     {
         newCmds.Add(new AssumeCmd(Token.NoToken, DisjointnessExpr(domainName, domainNameToInputVar[domainName], domainNameToScope[domainName])));
     }
 }
Esempio n. 22
0
 public bool CodeLabelFalse(RPFP rpfp, RPFP.Node root, Absy code, StratifiedInliningInfo info, string prefix)
 {
     return CodeLabelTrue(rpfp, root, code, info, prefix);
 }
Esempio n. 23
0
 public override Absy Visit(Absy node) {
   //Contract.Requires(node != null);
   Contract.Ensures(Contract.Result<Absy>() != null);
   node = base.Visit(node);
   return node;
 }
Esempio n. 24
0
        public bool CodeLabelTrue(RPFP rpfp, RPFP.Node root, Absy code, StratifiedInliningInfo info, string prefix)
        {
            string label = CodeLabel(code, info, prefix);

            if (label == null)
                throw new LabelNotFound();
            return root.Outgoing.labels.Contains(label);
        }
Esempio n. 25
0
 private void CheckAndAddLayers(Absy node, QKeyValue attributes, int enclosingProcLayerNum)
 {
     List<int> attrs = RemoveDuplicatesAndSort(FindLayers(attributes));
     if (attrs.Count == 0)
     {
         Error(node, "layer not present");
         return;
     }
     LayerRange upperBound = FindLayerRange();
     absyToLayerNums[node] = new HashSet<int>();
     foreach (int layerNum in attrs)
     {
         if (layerNum > enclosingProcLayerNum)
         {
             Error(node, "The layer cannot be greater than the layer of enclosing procedure");
         }
         else if (upperBound.Contains(layerNum))
         {
             absyToLayerNums[node].Add(layerNum);
         }
         else
         {
             Error(node, string.Format("A variable being accessed in this specification is unavailable at layer {0}", layerNum));
         }
     }
 }
Esempio n. 26
0
 public static IEnumerable<Variable> Collect(Absy node)
 {
   var collector = new VariableCollector();
   collector.Visit(node);
   return collector.usedVars;
 }