public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); base.Resolve(rc); }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); if ((Key == "minimize" || Key == "maximize") && Params.Count != 1) { rc.Error(this, "attributes :minimize and :maximize accept only one argument"); } if (Key == "verified_under" && Params.Count != 1) { rc.Error(this, "attribute :verified_under accepts only one argument"); } foreach (object p in Params) { if (p is Expr) { ((Expr)p).Resolve(rc); } } }
protected override void ResolveTriggers(ResolutionContext rc) { //Contract.Requires(rc != null); for (Trigger tr = this.Triggers; tr != null; tr = tr.Next) { int prevErrorCount = rc.ErrorCount; tr.Resolve(rc); if (prevErrorCount == rc.ErrorCount) { // for positive triggers, make sure all bound variables are mentioned if (tr.Pos) { Set /*Variable*/ freeVars = new Set /*Variable*/ (); tr.ComputeFreeVariables(freeVars); foreach (Variable/*!*/ v in Dummies) { Contract.Assert(v != null); if (!freeVars[v]) { rc.Error(tr, "trigger must mention all quantified variables, but does not mention: {0}", v); } } } } } }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); foreach (object p in Params) { if (p is Expr) { ((Expr)p).Resolve(rc); } } }
protected virtual void ResolveTriggers(ResolutionContext rc) { Contract.Requires(rc != null); }
public void Register(ResolutionContext rc) { Contract.Requires(rc != null); rc.AddBlock(this); }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); if (Proc != null) { // already resolved return; } ResolveAttributes(Attributes, rc); Proc = rc.LookUpProcedure(callee) as Procedure; if (Proc == null) { rc.Error(this, "call to undeclared procedure: {0}", callee); } foreach (Expr e in Ins) { if (e != null) { e.Resolve(rc); } } HashSet<Variable> actualOuts = new HashSet<Variable>(); foreach (IdentifierExpr ide in Outs) { if (ide != null) { ide.Resolve(rc); if (ide.Decl != null) { if (actualOuts.Contains(ide.Decl)) { rc.Error(this, "left-hand side of call command contains variable twice: {0}", ide.Name); } else { actualOuts.Add(ide.Decl); } } } } if (Proc == null) return; // first make sure that the right number of parameters is given // (a similar check is in CheckArgumentTypes, but we are not // able to call this method because it cannot cope with Ins/Outs // that are null) if (Ins.Count != Proc.InParams.Count) { rc.Error(this.tok, "wrong number of arguments in call to {0}: {1}", callee, Ins.Count); return; } if (Outs.Count != Proc.OutParams.Count) { rc.Error(this.tok, "wrong number of result variables in call to {0}: {1}", callee, Outs.Count); return; } if (IsAsync) { if (Proc.OutParams.Count > 0) { rc.Error(this.tok, "a procedure called asynchronously can have no output parameters"); return; } } // Check that type parameters can be determined using the given // actual i/o arguments. This is done already during resolution // because CheckBoundVariableOccurrences needs a resolution // context List<Type>/*!*/ formalInTypes = new List<Type>(); List<Type>/*!*/ formalOutTypes = new List<Type>(); for (int i = 0; i < Ins.Count; ++i) if (Ins[i] != null) formalInTypes.Add(cce.NonNull(Proc.InParams[i]).TypedIdent.Type); for (int i = 0; i < Outs.Count; ++i) if (Outs[i] != null) formalOutTypes.Add(cce.NonNull(Proc.OutParams[i]).TypedIdent.Type); // we need to bind the type parameters for this // (this is expected by CheckBoundVariableOccurrences) int previousTypeBinderState = rc.TypeBinderState; try { foreach (TypeVariable/*!*/ v in Proc.TypeParameters) { Contract.Assert(v != null); rc.AddTypeBinder(v); } Type.CheckBoundVariableOccurrences(Proc.TypeParameters, formalInTypes, formalOutTypes, this.tok, "types of given arguments", rc); } finally { rc.TypeBinderState = previousTypeBinderState; } }
public static void ResolveAttributes(QKeyValue attributes, ResolutionContext rc) { Contract.Requires(rc != null); for (QKeyValue kv = attributes; kv != null; kv = kv.Next) { kv.Resolve(rc); } }
public override void Resolve(ResolutionContext rc) { }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); // NOTE: WhereExpr needs to be resolved by the caller, because the caller must provide a modified ResolutionContext this.Type = this.Type.ResolveType(rc); }
protected void ResolveAttributes(ResolutionContext rc) { Contract.Requires(rc != null); for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next) { kv.Resolve(rc); } }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); if (Proc != null) { // already resolved return; } DeclWithFormals dwf = rc.LookUpProcedure(cce.NonNull(this.Name)); Proc = dwf as Procedure; if (dwf == null) { rc.Error(this, "implementation given for undeclared procedure: {0}", this.Name); } else if (Proc == null) { rc.Error(this, "implementations given for function, not procedure: {0}", this.Name); } int previousTypeBinderState = rc.TypeBinderState; try { RegisterTypeParameters(rc); rc.PushVarContext(); RegisterFormals(InParams, rc); RegisterFormals(OutParams, rc); foreach (Variable/*!*/ v in LocVars) { Contract.Assert(v != null); v.Register(rc); v.Resolve(rc); } foreach (Variable/*!*/ v in LocVars) { Contract.Assert(v != null); v.ResolveWhere(rc); } rc.PushProcedureContext(); foreach (Block b in Blocks) { b.Register(rc); } ResolveAttributes(rc); rc.StateMode = ResolutionContext.State.Two; foreach (Block b in Blocks) { b.Resolve(rc); } rc.StateMode = ResolutionContext.State.Single; rc.PopProcedureContext(); rc.PopVarContext(); Type.CheckBoundVariableOccurrences(TypeParameters, new List<Type>(InParams.Select(Item => Item.TypedIdent.Type).ToArray()), new List<Type>(OutParams.Select(Item => Item.TypedIdent.Type).ToArray()), this.tok, "implementation arguments", rc); } finally { rc.TypeBinderState = previousTypeBinderState; } SortTypeParams(); }
private void ResolveTypes(ResolutionContext rc) { Contract.Requires(rc != null); // first resolve type constructors foreach (Declaration d in TopLevelDeclarations) { if (d is TypeCtorDecl && !QKeyValue.FindBoolAttribute(d.Attributes, "ignore")) d.Resolve(rc); } // collect type synonym declarations List<TypeSynonymDecl/*!*/>/*!*/ synonymDecls = new List<TypeSynonymDecl/*!*/>(); foreach (Declaration d in TopLevelDeclarations) { Contract.Assert(d != null); if (d is TypeSynonymDecl && !QKeyValue.FindBoolAttribute(d.Attributes, "ignore")) synonymDecls.Add((TypeSynonymDecl)d); } // then resolve the type synonyms by a simple // fixed-point iteration TypeSynonymDecl.ResolveTypeSynonyms(synonymDecls, rc); }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); rc.PushVarContext(); foreach (IdentifierExpr/*!*/ ide in Modifies) { Contract.Assert(ide != null); ide.Resolve(rc); } int previousTypeBinderState = rc.TypeBinderState; try { RegisterTypeParameters(rc); RegisterFormals(InParams, rc); ResolveFormals(InParams, rc); // "where" clauses of in-parameters are resolved without the out-parameters in scope foreach (Requires/*!*/ e in Requires) { Contract.Assert(e != null); e.Resolve(rc); } RegisterFormals(OutParams, rc); ResolveFormals(OutParams, rc); // "where" clauses of out-parameters are resolved with both in- and out-parametes in scope rc.StateMode = ResolutionContext.State.Two; foreach (Ensures/*!*/ e in Ensures) { Contract.Assert(e != null); e.Resolve(rc); } rc.StateMode = ResolutionContext.State.Single; ResolveAttributes(rc); Type.CheckBoundVariableOccurrences(TypeParameters, new List<Type>(InParams.Select(Item => Item.TypedIdent.Type).ToArray()), new List<Type>(OutParams.Select(Item => Item.TypedIdent.Type).ToArray()), this.tok, "procedure arguments", rc); } finally { rc.TypeBinderState = previousTypeBinderState; } rc.PopVarContext(); SortTypeParams(); }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); Contract.Ensures(labelTargets != null); if (labelTargets != null) { // already resolved return; } Contract.Assume(this.labelNames != null); labelTargets = new List<Block>(); foreach (string/*!*/ lbl in labelNames) { Contract.Assert(lbl != null); Block b = rc.LookUpBlock(lbl); if (b == null) { rc.Error(this, "goto to unknown block: {0}", lbl); } else { labelTargets.Add(b); } } Debug.Assert(rc.ErrorCount > 0 || labelTargets.Count == labelNames.Count); }
public override void Resolve(ResolutionContext rc) { if (Lhss.Count != Rhss.Count) rc.Error(this, "number of left-hand sides does not match number of right-hand sides"); foreach (AssignLhs/*!*/ e in Lhss) { Contract.Assert(e != null); e.Resolve(rc); } foreach (Expr/*!*/ e in Rhss) { Contract.Assert(e != null); e.Resolve(rc); } // check for double occurrences of assigned variables // (could be optimised) for (int i = 0; i < Lhss.Count; ++i) { for (int j = i + 1; j < Lhss.Count; ++j) { if (cce.NonNull(Lhss[i].DeepAssignedVariable).Equals( Lhss[j].DeepAssignedVariable)) rc.Error(Lhss[j], "variable {0} is assigned more than once in parallel assignment", Lhss[j].DeepAssignedVariable); } } }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); foreach (IdentifierExpr/*!*/ ide in Vars) { Contract.Assert(ide != null); ide.Resolve(rc); } }
public override void Resolve(ResolutionContext rc) { foreach (Cmd/*!*/ c in Cmds) { Contract.Assert(c != null); c.Resolve(rc); } Contract.Assume(this.TransferCmd != null); TransferCmd.Resolve(rc); }
public override void Resolve(ResolutionContext rc) { Map.Resolve(rc); foreach (Expr/*!*/ e in Indexes) { Contract.Assert(e != null); e.Resolve(rc); } }
public Expr TransitionRelationCompute(bool withOriginalInOutVariables = false) { Expr transitionRelation = Expr.Or(paths.Select(p => CalculatePathCondition(p))); ResolutionContext rc = new ResolutionContext(null); rc.StateMode = ResolutionContext.State.Two; transitionRelation.Resolve(rc); transitionRelation.Typecheck(new TypecheckingContext(null)); if (withOriginalInOutVariables) { Dictionary<Variable, Expr> invertedMap = new Dictionary<Variable, Expr>(); if (first != null) { foreach (var x in first.thatMap) { invertedMap[((IdentifierExpr)x.Value).Decl] = Expr.Ident(x.Key); } } if (second != null) { foreach (var x in second.thisMap) { invertedMap[((IdentifierExpr)x.Value).Decl] = Expr.Ident(x.Key); } } Substitution subst = Substituter.SubstitutionFromHashtable(invertedMap); return Substituter.Apply(subst, transitionRelation); } else { return transitionRelation; } }
public override void Resolve(ResolutionContext rc) { ResolveAttributes(Attributes, rc); foreach (CallCmd callCmd in CallCmds) { callCmd.Resolve(rc); } HashSet<Variable> parallelCallLhss = new HashSet<Variable>(); foreach (CallCmd callCmd in CallCmds) { foreach (IdentifierExpr ie in callCmd.Outs) { if (parallelCallLhss.Contains(ie.Decl)) { rc.Error(this, "left-hand side of parallel call command contains variable twice: {0}", ie.Name); } else { parallelCallLhss.Add(ie.Decl); } } } }
protected void ResolveImpl(Implementation impl) { Contract.Requires(impl != null); Contract.Ensures(impl.Proc != null); ResolutionContext rc = new ResolutionContext(new DummyErrorSink()); foreach (var decl in program.TopLevelDeclarations) { decl.Register(rc); } impl.Proc = null; // to force Resolve() redo the operation impl.Resolve(rc); TypecheckingContext tc = new TypecheckingContext(new DummyErrorSink()); impl.Typecheck(tc); }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); // nothing to resolve }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); if (rc.TriggerMode) { rc.Error(this, "quantifiers are not allowed in triggers"); } int previousTypeBinderState = rc.TypeBinderState; try { foreach (TypeVariable/*!*/ v in TypeParameters) { Contract.Assert(v != null); rc.AddTypeBinder(v); } rc.PushVarContext(); foreach (Variable/*!*/ v in Dummies) { Contract.Assert(v != null); v.Register(rc); v.Resolve(rc); } for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next) { kv.Resolve(rc); } this.ResolveTriggers(rc); Body.Resolve(rc); rc.PopVarContext(); // establish a canonical order of the type parameters this.TypeParameters = Type.SortTypeParams(TypeParameters, new List<Type>(Dummies.Select(Item => Item.TypedIdent.Type).ToArray()), null); } finally { rc.TypeBinderState = previousTypeBinderState; } }
public override void Resolve(ResolutionContext rc) { AssignedVariable.Resolve(rc); }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); rc.TriggerMode = true; foreach (Expr/*!*/ e in this.Tr) { Contract.Assert(e != null); e.Resolve(rc); // just a variable by itself is not allowed if (e is IdentifierExpr) { rc.Error(e, "a matching pattern must be more than just a variable by itself: {0}", e); } // the free-variable check is performed in the surrounding quantifier expression (because that's // where the bound variables are known) } rc.TriggerMode = false; }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); rc.PushVarContext(); foreach (Variable/*!*/ v in Locals) { Contract.Assert(v != null); rc.AddVariable(v, false); } foreach (Cmd/*!*/ cmd in Cmds) { Contract.Assert(cmd != null); cmd.Resolve(rc); } rc.PopVarContext(); }
public override void Resolve(ResolutionContext rc) { //Contract.Requires(rc != null); int oldErrorCount = rc.ErrorCount; this.MergeAdjecentQuantifier(); base.Resolve(rc); if (oldErrorCount == rc.ErrorCount) { this.ApplyNeverTriggers(); } }
public override void Resolve(ResolutionContext rc) { // nothing to resolve }
public override void Resolve(ResolutionContext/*!*/ rc) { // Contract.Requires(rc != null); rc.Error(this, "bitvector bounds in illegal position"); }