Exemplo n.º 1
0
 public void AddAxiom(Axiom axiom)
 {
     string axiomName = QKeyValue.FindStringAttribute(axiom.Attributes, "name");
       if (axiomName == null)
     return;
       var previous = (Axiom)axioms[axiomName];
       if (previous == null) {
     axioms.Add(axiomName, axiom);
       }
       else {
     var r = (Axiom)SelectNonExtern(axiom, previous);
     if (r == null) {
       Error(axiom, "more than one declaration of axiom name: {0}", axiomName);
     }
     else {
       axioms[axiomName] = r;
     }
       }
 }
Exemplo n.º 2
0
 public override void AddAxiom(Axiom a, string attributes)
 {
 }
Exemplo n.º 3
0
 public override Axiom VisitAxiom(Axiom node) {
   //Contract.Requires(node != null);
   Contract.Ensures(Contract.Result<Axiom>() != null);
   return base.VisitAxiom((Axiom)node.Clone());
 }
Exemplo n.º 4
0
        public override void AddAxiom(Axiom ax, string attributes)
        {
            //Contract.Requires(ax != null);
              base.AddAxiom(ax, attributes);

              axiomConjuncts.Add(translator.Translate(ax.Expr));
        }
Exemplo n.º 5
0
 public virtual void AddAxiom(Axiom a, string attributes)
 {
     Contract.Requires(a != null); ProcessDeclaration(a);
 }
Exemplo n.º 6
0
    public static Expr Extract(Expr expr, Program program, List<Axiom> axioms)
    {
      Contract.Requires(expr != null && program != null && !program.TopLevelDeclarationsAreFrozen && axioms != null);
      
      if (expr is LiteralExpr)
      {
        return expr;
      }

      var extractor = new FunctionExtractor();

      var body = extractor.VisitExpr(expr);

      var name = program.FreshExtractedFunctionName();
      var originalVars = extractor.Substitutions.Keys.ToList();
      var formalInArgs = originalVars.Select(v => new Formal(Token.NoToken, new TypedIdent(Token.NoToken, extractor.Substitutions[v].Name, extractor.Substitutions[v].TypedIdent.Type), true)).ToList<Variable>();
      var formalOutArg = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, name + "$result$", expr.Type), false);
      var func = new Function(Token.NoToken, name, formalInArgs, formalOutArg);
      func.AddAttribute("never_pattern");

      var boundVars = originalVars.Select(k => extractor.Substitutions[k]);
      var axiomCall = new NAryExpr(Token.NoToken, new FunctionCall(func), boundVars.Select(b => new IdentifierExpr(Token.NoToken, b)).ToList<Expr>());
      axiomCall.Type = expr.Type;
      axiomCall.TypeParameters = SimpleTypeParamInstantiation.EMPTY;
      var eq = LiteralExpr.Eq(axiomCall, body);
      eq.Type = body.Type;
      eq.TypeParameters = SimpleTypeParamInstantiation.EMPTY;
      if (0 < formalInArgs.Count)
      {
        var forallExpr = new ForallExpr(Token.NoToken, boundVars.ToList<Variable>(), new Trigger(Token.NoToken, true, new List<Expr> { axiomCall }), eq);
        body = forallExpr;
        forallExpr.Attributes = new QKeyValue(Token.NoToken, "weight", new List<object> { new LiteralExpr(Token.NoToken, Basetypes.BigNum.FromInt(30)) }, null);
        body.Type = Type.Bool;
      }
      else
      {
        body = eq;
      }

      var axiom = new Axiom(Token.NoToken, body);
      func.DefinitionAxiom = axiom;
      program.AddTopLevelDeclaration(func);
      program.AddTopLevelDeclaration(axiom);
      axioms.Add(axiom);

      var call = new NAryExpr(Token.NoToken, new FunctionCall(func), originalVars.Select(v => new IdentifierExpr(Token.NoToken, v)).ToList<Expr>());
      call.Type = expr.Type;
      call.TypeParameters = SimpleTypeParamInstantiation.EMPTY;
      return call;
    }
Exemplo n.º 7
0
 public override Axiom VisitAxiom(Axiom node)
 {
   if (node.DependenciesCollected)
   {
     if (currentDeclaration != null && node.FunctionDependencies != null)
     {
       foreach (var f in node.FunctionDependencies)
       {
         currentDeclaration.AddFunctionDependency(f);
       }
     }
     return node;
   }
   currentAxiom = node;
   var result = base.VisitAxiom(node);
   node.DependenciesCollected = true;
   currentAxiom = null;
   return result;
 }
Exemplo n.º 8
0
 public virtual Axiom VisitAxiom(Axiom node) {
   Contract.Requires(node != null);
   Contract.Ensures(Contract.Result<Axiom>() != null);
   node.Expr = this.VisitExpr(node.Expr);
   return node;
 }
Exemplo n.º 9
0
 public override Axiom VisitAxiom(Axiom node)
 {
     Contract.Ensures(Contract.Result<Axiom>() == node);
     this.VisitExpr(node.Expr);
     return node;
 }
Exemplo n.º 10
0
	void Axiom(out Axiom/*!*/ m) {
		Contract.Ensures(Contract.ValueAtReturn(out m) != null); Expr/*!*/ e; QKeyValue kv = null; 
		Expect(30);
		while (la.kind == 28) {
			Attribute(ref kv);
		}
		IToken/*!*/ x = t; 
		Proposition(out e);
		Expect(9);
		m = new Axiom(x,e, null, kv); 
	}
Exemplo n.º 11
0
 public override Axiom VisitAxiom(Axiom node)
 {
     node.tok = Token.NoToken;
     TokenCount++; 
     return base.VisitAxiom(node);
 }
Exemplo n.º 12
0
    public Axiom CreateDefinitionAxiom(Expr definition, QKeyValue kv = null) {
      Contract.Requires(definition != null);

      List<Variable> dummies = new List<Variable>();
      List<Expr> callArgs = new List<Expr>();
      int i = 0;
      foreach (Formal/*!*/ f in InParams) {
        Contract.Assert(f != null);
        string nm = f.TypedIdent.HasName ? f.TypedIdent.Name : "_" + i;
        dummies.Add(new BoundVariable(f.tok, new TypedIdent(f.tok, nm, f.TypedIdent.Type)));
        callArgs.Add(new IdentifierExpr(f.tok, nm));
        i++;
      }
      List<TypeVariable>/*!*/ quantifiedTypeVars = new List<TypeVariable>();
      foreach (TypeVariable/*!*/ t in TypeParameters) {
        Contract.Assert(t != null);
        quantifiedTypeVars.Add(new TypeVariable(Token.NoToken, t.Name));
      }

      Expr call = new NAryExpr(tok, new FunctionCall(new IdentifierExpr(tok, Name)), callArgs);
      // specify the type of the function, because it might be that
      // type parameters only occur in the output type
      call = Expr.CoerceType(tok, call, (Type)OutParams[0].TypedIdent.Type.Clone());
      Expr def = Expr.Eq(call, definition);
      if (quantifiedTypeVars.Count != 0 || dummies.Count != 0) {
        def = new ForallExpr(tok, quantifiedTypeVars, dummies,
                             kv,
                             new Trigger(tok, true, new List<Expr> { call }, null),
                             def);
      }
      DefinitionAxiom = new Axiom(tok, def);
      return DefinitionAxiom;
    }