本文整理汇总了C#中Program.AddTopLevelDeclaration方法的典型用法代码示例。如果您正苦于以下问题:C# Program.AddTopLevelDeclaration方法的具体用法?C# Program.AddTopLevelDeclaration怎么用?C# Program.AddTopLevelDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Program
的用法示例。
在下文中一共展示了Program.AddTopLevelDeclaration方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExpandLambdas
public static void ExpandLambdas(Program prog) {
Contract.Requires(prog != null);
List<Expr/*!*/>/*!*/ axioms;
List<Function/*!*/>/*!*/ functions;
Desugar(prog, out axioms, out functions);
foreach (var f in functions) {
prog.AddTopLevelDeclaration(f);
}
foreach (var a in axioms) {
prog.AddTopLevelDeclaration(new Axiom(a.tok, a));
}
}
示例2: WholeProgram
public void WholeProgram() {
var p = new Program();
var t = new TypedIdent(Token.NoToken, "foo", Microsoft.Boogie.Type.Bool);
var gv = new GlobalVariable(Token.NoToken, t);
p.AddTopLevelDeclaration(gv);
string metaDataString = "This is a test";
p.SetMetadata(0, metaDataString);
// Now try to clone
var p2 = (Program) d.Visit(p);
// Check global is a copy
int counter = 0;
GlobalVariable gv2 = null;
foreach (var g in p2.TopLevelDeclarations)
{
++counter;
Assert.IsInstanceOf<GlobalVariable>(g);
gv2 = g as GlobalVariable;
}
Assert.AreEqual(1, counter);
Assert.AreNotSame(gv, gv2);
Assert.AreEqual(metaDataString, p2.GetMetadata<string>(0));
// Check Top level declarations list is duplicated properly
var t2 = new TypedIdent(Token.NoToken, "bar", Microsoft.Boogie.Type.Bool);
var gv3 = new GlobalVariable(Token.NoToken, t2);
p2.AddTopLevelDeclaration(gv3);
counter = 0;
foreach (var g in p2.TopLevelDeclarations) {
++counter;
Assert.IsInstanceOf<GlobalVariable>(g);
}
Assert.AreEqual(2, counter);
// The original program should still only have one global variable
counter = 0;
foreach (var g in p.TopLevelDeclarations) {
++counter;
Assert.IsInstanceOf<GlobalVariable>(g);
Assert.AreSame(g, gv);
}
Assert.AreEqual(1, counter);
// Change Metadata in p2, this shouldn't affect p
string newMetaDataString = "Another test";
p2.SetMetadata(0, newMetaDataString);
Assert.AreNotEqual(p2.GetMetadata<string>(0), p.GetMetadata<string>(0));
}
示例3: 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;
}