本文整理汇总了C#中Function.AddAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Function.AddAttribute方法的具体用法?C# Function.AddAttribute怎么用?C# Function.AddAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Function
的用法示例。
在下文中一共展示了Function.AddAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Extract
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;
}