Beispiel #1
0
 public AssertCmd(IToken/*!*/ tok, Expr/*!*/ expr, QKeyValue kv)
     : base(tok, expr, kv)
 {
     Contract.Requires(tok != null);
       Contract.Requires(expr != null);
       errorDataEnhanced = GenerateBoundVarMiningStrategy(expr);
 }
Beispiel #2
0
 public BinderExpr(IToken/*!*/ tok, List<TypeVariable>/*!*/ typeParameters,
     List<Variable>/*!*/ dummies, QKeyValue kv, Expr/*!*/ body)
     : base(tok)
 {
     Contract.Requires(tok != null);
       Contract.Requires(typeParameters != null);
       Contract.Requires(dummies != null);
       Contract.Requires(body != null);
       Contract.Requires(dummies.Count + typeParameters.Count > 0);
       TypeParameters = typeParameters;
       Dummies = dummies;
       Attributes = kv;
       Body = body;
 }
Beispiel #3
0
 public BinderExpr(IToken/*!*/ tok, List<TypeVariable>/*!*/ typeParameters,
                   List<Variable>/*!*/ dummies, QKeyValue kv, Expr/*!*/ body, bool immutable)
   : base(tok, immutable) {
   Contract.Requires(tok != null);
   Contract.Requires(typeParameters != null);
   Contract.Requires(dummies != null);
   Contract.Requires(body != null);
   Contract.Requires(dummies.Count + typeParameters.Count > 0);
   TypeParameters = typeParameters;
   Dummies = dummies;
   Attributes = kv;
   _Body = body;
   if (immutable)
     CachedHashCode = ComputeHashCode();
 }
Beispiel #4
0
	void Attribute(ref QKeyValue kv) {
		Trigger trig = null; 
		AttributeOrTrigger(ref kv, ref trig);
		if (trig != null) this.SemErr("only attributes, not triggers, allowed here"); 
	}
Beispiel #5
0
	void VarOrType(out TypedIdent/*!*/ tyd, out QKeyValue kv) {
		Contract.Ensures(Contract.ValueAtReturn(out tyd) != null);
		string/*!*/ varName = TypedIdent.NoName;
		Bpl.Type/*!*/ ty;
		IToken/*!*/ tok;
		kv = null;
		
		while (la.kind == 28) {
			Attribute(ref kv);
		}
		Type(out ty);
		tok = ty.tok; 
		if (la.kind == 12) {
			Get();
			var uti = ty as UnresolvedTypeIdentifier;
			if (uti != null && uti.Arguments.Count == 0) {
			 varName = uti.Name;
			} else {
			 this.SemErr("expected identifier before ':'");
			}
			
			Type(out ty);
		}
		tyd = new TypedIdent(tok, varName, ty); 
	}
Beispiel #6
0
    // ----------------------------- Substitutions for QKeyValue -------------------------------

    /// <summary>
    /// Apply a substitution to a list of attributes.  Any variables not in domain(subst)
    /// is not changed.  The substitutions apply within the "old", but the "old"
    /// expression remains.
    /// </summary>
    public static QKeyValue Apply(Substitution subst, QKeyValue kv) {
      Contract.Requires(subst != null);
      if (kv == null) {
        return null;
      } else {
        return (QKeyValue)new NormalSubstituter(subst).Visit(kv);
      }
    }
 private void EmitLineDirective(Bpl.IToken methodCallToken) {
   var sloc = this.StmtTraverser.lastSourceLocation;
   if (sloc != null) {
     var fileName = sloc.Document.Location;
     var lineNumber = sloc.StartLine;
     var attrib = new Bpl.QKeyValue(methodCallToken, "sourceLine", new List<object> { Bpl.Expr.Literal((int)lineNumber) }, null);
     attrib = new Bpl.QKeyValue(methodCallToken, "sourceFile", new List<object> { fileName }, attrib);
     this.StmtTraverser.StmtBuilder.Add(new Bpl.AssertCmd(methodCallToken, Bpl.Expr.True, attrib));
   }
 }
Beispiel #8
0
    public static void ComputeBinderFreeVariables(List<TypeVariable> typeParameters, List<Variable> dummies, Expr body, QKeyValue attributes, Set freeVars) {
      Contract.Requires(dummies != null);
      Contract.Requires(body != null);

      foreach (var v in dummies) {
        Contract.Assert(v != null);
        Contract.Assert(!freeVars[v]);
      }
      body.ComputeFreeVariables(freeVars);
      for (var a = attributes; a != null; a = a.Next) {
        foreach (var o in a.Params) {
          var e = o as Expr;
          if (e != null) {
            e.ComputeFreeVariables(freeVars);
          }
        }
      }
      foreach (var v in dummies) {
        freeVars.AddRange(v.TypedIdent.Type.FreeVariables);
      }
      freeVars.RemoveRange(dummies);
      freeVars.RemoveRange(typeParameters);
    }
Beispiel #9
0
 public static QKeyValue RemoveMoverAttribute(QKeyValue iter)
 {
     if (iter == null) return null;
     iter.Next = RemoveMoverAttribute(iter.Next);
     if (iter.Key == "atomic" || iter.Key == "right" || iter.Key == "left" || iter.Key == "both")
         return iter.Next;
     else
         return iter;
 }
Beispiel #10
0
    public QuantifierExpr(IToken/*!*/ tok, List<TypeVariable>/*!*/ typeParameters,
                          List<Variable>/*!*/ dummies, QKeyValue kv, Trigger triggers, Expr/*!*/ body, bool immutable)
      : base(tok, typeParameters, dummies, kv, body, immutable) {
      Contract.Requires(tok != null);
      Contract.Requires(typeParameters != null);
      Contract.Requires(dummies != null);
      Contract.Requires(body != null);
      Contract.Requires(dummies.Count + typeParameters.Count > 0);

      Contract.Assert((this is ForallExpr) || (this is ExistsExpr));

      Triggers = triggers;
      SkolemId = GetNextSkolemId();
    }
Beispiel #11
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));
         }
     }
 }
Beispiel #12
0
 // Return 'true' if {:name true} or {:name} is an attribute in 'kv'
 public static bool FindBoolAttribute(QKeyValue kv, string name) {
   Contract.Requires(name != null);
   for (; kv != null; kv = kv.Next) {
     if (kv.Key == name) {
       return kv.Params.Count == 0 ||
         (kv.Params.Count == 1 && kv.Params[0] is LiteralExpr && ((LiteralExpr)kv.Params[0]).IsTrue);
     }
   }
   return false;
 }
Beispiel #13
0
 public static int FindIntAttribute(QKeyValue kv, string name, int defl) {
   Contract.Requires(name != null);
   Expr e = FindExprAttribute(kv, name);
   LiteralExpr l = e as LiteralExpr;
   if (l != null && l.isBigNum)
     return l.asBigNum.ToIntSafe;
   return defl;
 }
Beispiel #14
0
 // Look for {:name expr} in list of attributes.
 public static Expr FindExprAttribute(QKeyValue kv, string name) {
   Contract.Requires(name != null);
   for (; kv != null; kv = kv.Next) {
     if (kv.Key == name) {
       if (kv.Params.Count == 1 && kv.Params[0] is Expr) {
         return (Expr)kv.Params[0];
       }
     }
   }
   return null;
 }
Beispiel #15
0
 public void AddLast(QKeyValue other) {
   Contract.Requires(other != null);
   QKeyValue current = this;
   while (current.Next != null) {
     current = current.Next;
   }
   current.Next = other;
 }
Beispiel #16
0
 public QKeyValue(IToken tok, string key, IList<object/*!*/>/*!*/ parameters, QKeyValue next)
   : base(tok) {
   Contract.Requires(key != null);
   Contract.Requires(tok != null);
   Contract.Requires(cce.NonNullElements(parameters));
   Key = key;
   this._params = new List<object>(parameters);
   Next = next;
 }
Beispiel #17
0
	void UserDefinedType(out Declaration/*!*/ decl, QKeyValue kv) {
		Contract.Ensures(Contract.ValueAtReturn(out decl) != null); IToken/*!*/ id; List<IToken>/*!*/ paramTokens = new List<IToken> ();
		Bpl.Type/*!*/ body = dummyType; bool synonym = false; 
		Ident(out id);
		if (la.kind == 1) {
			WhiteSpaceIdents(out paramTokens);
		}
		if (la.kind == 32) {
			Get();
			Type(out body);
			synonym = true; 
		}
		if (synonym) {
		 List<TypeVariable>/*!*/ typeParams = new List<TypeVariable>();
		 foreach(Token/*!*/ t in paramTokens){
		   Contract.Assert(t != null);
		   typeParams.Add(new TypeVariable(t, t.val));}
		 decl = new TypeSynonymDecl(id, id.val, typeParams, body, kv);
		} else {
		 decl = new TypeCtorDecl(id, id.val, paramTokens.Count, kv);
		}
		
	}
Beispiel #18
0
 public virtual QKeyValue VisitQKeyValue(QKeyValue node) {
   Contract.Requires(node != null);
   Contract.Ensures(Contract.Result<QKeyValue>() != null);
   var newParams = new List<object>();
   for (int i = 0, n = node.Params.Count; i < n; i++) {
     var e = node.Params[i] as Expr;
     newParams.Add(e != null ? this.Visit(e) : node.Params[i]);
   }
   node.ClearParams();
   node.AddParams(newParams);
   if (node.Next != null) {
     node.Next = (QKeyValue)this.Visit(node.Next);
   }
   return node;
 }
Beispiel #19
0
	void ProcSignature(bool allowWhereClausesOnFormals, out IToken/*!*/ name, out List<TypeVariable>/*!*/ typeParams,
out List<Variable>/*!*/ ins, out List<Variable>/*!*/ outs, out QKeyValue kv) {
		Contract.Ensures(Contract.ValueAtReturn(out name) != null); Contract.Ensures(Contract.ValueAtReturn(out typeParams) != null); Contract.Ensures(Contract.ValueAtReturn(out ins) != null); Contract.Ensures(Contract.ValueAtReturn(out outs) != null);
		IToken/*!*/ typeParamTok; typeParams = new List<TypeVariable>();
		outs = new List<Variable>(); kv = null; 
		while (la.kind == 28) {
			Attribute(ref kv);
		}
		Ident(out name);
		if (la.kind == 20) {
			TypeParams(out typeParamTok, out typeParams);
		}
		ProcFormals(true, allowWhereClausesOnFormals, out ins);
		if (la.kind == 27) {
			Get();
			ProcFormals(false, allowWhereClausesOnFormals, out outs);
		}
	}
Beispiel #20
0
 private QKeyValue RemoveLinearAttribute(QKeyValue iter)
 {
     if (iter == null) return null;
     iter.Next = RemoveLinearAttribute(iter.Next);
     return (iter.Key == "linear" || iter.Key == "linear_in" || iter.Key == "linear_out") ? iter.Next : iter;
 }
Beispiel #21
0
 private static List<int> FindLayers(QKeyValue kv)
 {
     List<int> layers = new List<int>();
     for (; kv != null; kv = kv.Next)
     {
         if (kv.Key != CivlAttributes.LAYER) continue;
         foreach (var o in kv.Params)
         {
             Expr e = o as Expr;
             if (e == null) return null;
             LiteralExpr l = e as LiteralExpr;
             if (l == null) return null;
             if (!l.isBigNum) return null;
             layers.Add(l.asBigNum.ToIntSafe);
         }
     }
     return layers;
 }
Beispiel #22
0
        static void Instrument(Implementation impl, NativeLattice.Element[] pre, NativeLattice.Element[] post)
        {
            Contract.Requires(impl != null);
              Contract.Requires(pre != null);

              foreach (var b in impl.Blocks) {
            var element = pre[b.aiId];
            if (element != null && (b.widenBlock || CommandLineOptions.Clo.InstrumentInfer == CommandLineOptions.InstrumentationPlaces.Everywhere)) {
              List<Cmd> newCommands = new List<Cmd>();
              Expr inv = element.ToExpr();
              PredicateCmd cmd;
              var kv = new QKeyValue(Token.NoToken, "inferred", new List<object>(), null);
              if (CommandLineOptions.Clo.InstrumentWithAsserts) {
            cmd = new AssertCmd(Token.NoToken, inv, kv);
              } else {
            cmd = new AssumeCmd(Token.NoToken, inv, kv);
              }
              newCommands.Add(cmd);
              newCommands.AddRange(b.Cmds);
              if (post != null && post[b.aiId] != null) {
            inv = post[b.aiId].ToExpr();
            kv = new QKeyValue(Token.NoToken, "inferred", new List<object>(), null);
            if (CommandLineOptions.Clo.InstrumentWithAsserts) {
              cmd = new AssertCmd(Token.NoToken, inv, kv);
            } else {
              cmd = new AssumeCmd(Token.NoToken, inv, kv);
            }
            newCommands.Add(cmd);
              }
              b.Cmds = newCommands;  // destructively replace the commands of the block
            }
              }
        }
Beispiel #23
0
 public override QKeyValue VisitQKeyValue(QKeyValue node) {
   Contract.Ensures(Contract.Result<QKeyValue>() == node);
   for (int i = 0, n = node.Params.Count; i < n; i++) {
     var e = node.Params[i] as Expr;
     if (e != null) {
       this.Visit(e);
     }
   }
   if (node.Next != null) {
     this.Visit(node.Next);
   }
   return node;
 }
Beispiel #24
0
 public LambdaExpr(IToken/*!*/ tok, List<TypeVariable>/*!*/ typeParameters,
                   List<Variable>/*!*/ dummies, QKeyValue kv, Expr/*!*/ body, bool immutable=false)
   : base(tok, typeParameters, dummies, kv, body, immutable) {
   Contract.Requires(tok != null);
   Contract.Requires(typeParameters != null);
   Contract.Requires(dummies != null);
   Contract.Requires(body != null);
   Contract.Requires(dummies.Count + typeParameters.Count > 0);
 }
Beispiel #25
0
 public static QKeyValue RemoveYieldsAttribute(QKeyValue iter)
 {
     if (iter == null) return null;
     iter.Next = RemoveYieldsAttribute(iter.Next);
     return (iter.Key == "yields") ? iter.Next : iter;
 }
Beispiel #26
0
	void CallParams(bool isAsync, bool isFree, QKeyValue kv, IToken x, out Cmd c) {
		List<IdentifierExpr> ids = new List<IdentifierExpr>();
		List<Expr> es = new List<Expr>();
		Expr en;
		IToken first; 
		IToken p;
		c = null;
		
		Ident(out first);
		if (la.kind == 10) {
			Get();
			if (StartOf(9)) {
				Expression(out en);
				es.Add(en); 
				while (la.kind == 13) {
					Get();
					Expression(out en);
					es.Add(en); 
				}
			}
			Expect(11);
			c = new CallCmd(x, first.val, es, ids, kv); ((CallCmd) c).IsFree = isFree; ((CallCmd) c).IsAsync = isAsync; 
		} else if (la.kind == 13 || la.kind == 51) {
			ids.Add(new IdentifierExpr(first, first.val)); 
			if (la.kind == 13) {
				Get();
				Ident(out p);
				ids.Add(new IdentifierExpr(p, p.val)); 
				while (la.kind == 13) {
					Get();
					Ident(out p);
					ids.Add(new IdentifierExpr(p, p.val)); 
				}
			}
			Expect(51);
			Ident(out first);
			Expect(10);
			if (StartOf(9)) {
				Expression(out en);
				es.Add(en); 
				while (la.kind == 13) {
					Get();
					Expression(out en);
					es.Add(en); 
				}
			}
			Expect(11);
			c = new CallCmd(x, first.val, es, ids, kv); ((CallCmd) c).IsFree = isFree; ((CallCmd) c).IsAsync = isAsync; 
		} else SynErr(112);
	}
Beispiel #27
0
 public override QKeyValue VisitQKeyValue(QKeyValue node) {
   //Contract.Requires(node != null);
   var newParams = new List<object>();
   foreach (var o in node.Params) {
     var e = o as Expr;
     if (e == null) {
       newParams.Add(o);
     } else {
       newParams.Add((Expr)this.Visit(e));
     }
   }
   QKeyValue next = node.Next == null ? null : (QKeyValue)this.Visit(node.Next);
   return new QKeyValue(node.tok, node.Key, newParams, next);
 }
Beispiel #28
0
	void QuantifierBody(IToken/*!*/ q, out List<TypeVariable>/*!*/ typeParams, out List<Variable>/*!*/ ds,
out QKeyValue kv, out Trigger trig, out Expr/*!*/ body) {
		Contract.Requires(q != null); Contract.Ensures(Contract.ValueAtReturn(out typeParams) != null); Contract.Ensures(Contract.ValueAtReturn(out ds) != null); Contract.Ensures(Contract.ValueAtReturn(out body) != null);
		trig = null; typeParams = new List<TypeVariable> ();
		IToken/*!*/ tok;
		kv = null;
		ds = new List<Variable> ();
		
		if (la.kind == 20) {
			TypeParams(out tok, out typeParams);
			if (la.kind == 1 || la.kind == 28) {
				BoundVars(q, out ds);
			}
		} else if (la.kind == 1 || la.kind == 28) {
			BoundVars(q, out ds);
		} else SynErr(129);
		QSep();
		while (la.kind == 28) {
			AttributeOrTrigger(ref kv, ref trig);
		}
		Expression(out body);
	}
Beispiel #29
0
 /// <summary>
 /// Apply a substitution to a list of attributes replacing "old" expressions.
 /// For a further description, see "ApplyReplacingOldExprs" above for Expr.
 /// </summary>    
 public static QKeyValue ApplyReplacingOldExprs(Substitution always, Substitution forOld, QKeyValue kv) {
   Contract.Requires(always != null);
   Contract.Requires(forOld != null);
   if (kv == null) {
     return null;
   } else {
     return (QKeyValue)new ReplacingOldSubstituter(always, forOld).Visit(kv);
   }
 }
Beispiel #30
0
	void AttributeOrTrigger(ref QKeyValue kv, ref Trigger trig) {
		IToken/*!*/ tok;  Expr/*!*/ e;  List<Expr>/*!*/ es;
		string key;
		List<object/*!*/> parameters;  object/*!*/ param;
		
		Expect(28);
		tok = t; 
		if (la.kind == 12) {
			Get();
			Expect(1);
			key = t.val;  parameters = new List<object/*!*/>(); 
			if (StartOf(16)) {
				AttributeParameter(out param);
				parameters.Add(param); 
				while (la.kind == 13) {
					Get();
					AttributeParameter(out param);
					parameters.Add(param); 
				}
			}
			if (key == "nopats") {
			 if (parameters.Count == 1 && parameters[0] is Expr) {
			   e = (Expr)parameters[0];
			   if(trig==null){
			     trig = new Trigger(tok, false, new List<Expr> { e }, null);
			   } else {
			     trig.AddLast(new Trigger(tok, false, new List<Expr> { e }, null));
			   }
			 } else {
			   this.SemErr("the 'nopats' quantifier attribute expects a string-literal parameter");
			 }
			} else {
			 if (kv==null) {
			   kv = new QKeyValue(tok, key, parameters, null);
			 } else {
			   kv.AddLast(new QKeyValue(tok, key, parameters, null));
			 }
			}
			
		} else if (StartOf(9)) {
			Expression(out e);
			es = new List<Expr> { e }; 
			while (la.kind == 13) {
				Get();
				Expression(out e);
				es.Add(e); 
			}
			if (trig==null) {
			 trig = new Trigger(tok, true, es, null);
			} else {
			 trig.AddLast(new Trigger(tok, true, es, null));
			}
			
		} else SynErr(133);
		Expect(29);
	}