本文整理汇总了C#中Constant.AddAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Constant.AddAttribute方法的具体用法?C# Constant.AddAttribute怎么用?C# Constant.AddAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Constant
的用法示例。
在下文中一共展示了Constant.AddAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyStages
public StagedHoudiniPlan ApplyStages()
{
if (NoStages())
{
return null;
}
#region Assign candidates to stages at a given level of granularity
switch(CommandLineOptions.Clo.StagedHoudini) {
case COARSE_STAGES:
Plan = ComputeCoarseStages();
break;
case FINE_STAGES:
Plan = ComputeFineStages();
break;
case BALANCED_STAGES:
Plan = ComputeBalancedStages();
break;
default:
Debug.Assert(false);
Plan = null;
break;
}
foreach(var c in candidates) {
Debug.Assert(Plan.StageForCandidate(c) != null);
}
#endregion
#region Generate boolean variables to control stages
var stageToActiveBoolean = new Dictionary<int, Constant>();
var stageToCompleteBoolean = new Dictionary<int, Constant>();
foreach (var stage in Plan)
{
var stageActive = new Constant(Token.NoToken,
new TypedIdent(Token.NoToken, "_stage_" + stage.GetId() + "_active", Type.Bool),
false);
stageActive.AddAttribute("stage_active", new object[] { new LiteralExpr(Token.NoToken, BigNum.FromInt(stage.GetId())) });
prog.TopLevelDeclarations.Add(stageActive);
stageToActiveBoolean[stage.GetId()] = stageActive;
var stageComplete = new Constant(Token.NoToken,
new TypedIdent(Token.NoToken, "_stage_" + stage.GetId() + "_complete", Type.Bool),
false);
stageComplete.AddAttribute("stage_complete", new object[] { new LiteralExpr(Token.NoToken, BigNum.FromInt(stage.GetId())) });
prog.TopLevelDeclarations.Add(stageComplete);
stageToCompleteBoolean[stage.GetId()] = stageComplete;
}
#endregion
#region Adapt candidate assertions to take account of stages
foreach (var b in prog.TopLevelDeclarations.OfType<Implementation>().Select(Item => Item.Blocks).SelectMany(Item => Item))
{
List<Cmd> newCmds = new List<Cmd>();
foreach (var cmd in b.Cmds)
{
var a = cmd as AssertCmd;
string c;
if (a != null && (Houdini.MatchCandidate(a.Expr, candidates, out c)))
{
newCmds.Add(new AssertCmd(a.tok, Houdini.AddConditionToCandidate(a.Expr,
new IdentifierExpr(Token.NoToken, stageToActiveBoolean[Plan.StageForCandidate(c).GetId()]), c), a.Attributes));
newCmds.Add(new AssumeCmd(a.tok, Houdini.AddConditionToCandidate(a.Expr,
new IdentifierExpr(Token.NoToken, stageToCompleteBoolean[Plan.StageForCandidate(c).GetId()]), c), a.Attributes));
}
else
{
newCmds.Add(cmd);
}
}
b.Cmds = newCmds;
}
#endregion
#region Adapt candidate pre/postconditions to take account of stages
foreach (var p in prog.TopLevelDeclarations.OfType<Procedure>())
{
#region Handle the preconditions
List<Requires> newRequires = new List<Requires>();
foreach(Requires r in p.Requires) {
string c;
if (Houdini.MatchCandidate(r.Condition, candidates, out c)) {
newRequires.Add(new Requires(r.tok, false,
Houdini.AddConditionToCandidate(r.Condition,
new IdentifierExpr(Token.NoToken, stageToActiveBoolean[Plan.StageForCandidate(c).GetId()]), c),
r.Comment, r.Attributes));
newRequires.Add(new Requires(r.tok, true,
Houdini.AddConditionToCandidate(r.Condition,
new IdentifierExpr(Token.NoToken, stageToCompleteBoolean[Plan.StageForCandidate(c).GetId()]), c),
r.Comment, r.Attributes));
} else {
newRequires.Add(r);
}
}
p.Requires = newRequires;
#endregion
//.........这里部分代码省略.........
示例2: ApplyStages
public StagedHoudiniPlan ApplyStages() {
if (NoStages())
{
Debug.Assert(false);
var TrivialGraph = new Graph<ScheduledStage>();
TrivialGraph.AddSource(new ScheduledStage(0, new HashSet<string>()));
return new StagedHoudiniPlan(TrivialGraph);
}
#region Assign annotations to stages at a given level of granularity
switch(CommandLineOptions.Clo.StagedHoudini) {
case COARSE_STAGES:
Plan = ComputeCoarseStages();
break;
case FINE_STAGES:
Plan = ComputeFineStages();
break;
case BALANCED_STAGES:
Plan = ComputeBalancedStages();
break;
default:
Debug.Assert(false);
Plan = null;
break;
}
foreach(var c in AllAnnotationIdentifiers()) {
Debug.Assert(Plan.StageForAnnotation(c) != null);
}
#endregion
#region Generate boolean variables to control stages
var stageToActiveBoolean = new Dictionary<int, Constant>();
var stageToCompleteBoolean = new Dictionary<int, Constant>();
foreach (var stage in Plan)
{
var stageActive = new Constant(Token.NoToken,
new TypedIdent(Token.NoToken, "_stage_" + stage.GetId() + "_active", Type.Bool),
false);
stageActive.AddAttribute("stage_active", new object[] { new LiteralExpr(Token.NoToken, BigNum.FromInt(stage.GetId())) });
prog.AddTopLevelDeclaration(stageActive);
stageToActiveBoolean[stage.GetId()] = stageActive;
var stageComplete = new Constant(Token.NoToken,
new TypedIdent(Token.NoToken, "_stage_" + stage.GetId() + "_complete", Type.Bool),
false);
stageComplete.AddAttribute("stage_complete", new object[] { new LiteralExpr(Token.NoToken, BigNum.FromInt(stage.GetId())) });
prog.AddTopLevelDeclaration(stageComplete);
stageToCompleteBoolean[stage.GetId()] = stageComplete;
}
#endregion
#region Adapt annotation assertions to take account of stages
foreach (var b in prog.Implementations.Select(Item => Item.Blocks).SelectMany(Item => Item))
{
List<Cmd> newCmds = new List<Cmd>();
foreach (var cmd in b.Cmds)
{
var a = cmd as AssertCmd;
string c;
if (a != null) {
if (Houdini.MatchCandidate(a.Expr, CandidateIdentifiers, out c))
{
newCmds.Add(new AssertCmd(a.tok, Houdini.AddConditionToCandidate(a.Expr,
Expr.Ident(stageToActiveBoolean[Plan.StageForAnnotation(c).GetId()]), c), a.Attributes));
newCmds.Add(new AssumeCmd(a.tok, Houdini.AddConditionToCandidate(a.Expr,
Expr.Ident(stageToCompleteBoolean[Plan.StageForAnnotation(c).GetId()]), c), a.Attributes));
} else if (QKeyValue.FindBoolAttribute(a.Attributes, "originated_from_invariant")) {
string tag = GetTagFromNonCandidateAttributes(a.Attributes);
if (tag == null) {
newCmds.Add(a);
} else {
newCmds.Add(new AssertCmd(a.tok, Expr.Imp(
Expr.Ident(stageToActiveBoolean[Plan.StageForAnnotation(tag).GetId()]), a.Expr),
a.Attributes));
newCmds.Add(new AssumeCmd(a.tok, Expr.Imp(
Expr.Ident(stageToCompleteBoolean[Plan.StageForAnnotation(tag).GetId()]), a.Expr),
a.Attributes));
}
}
}
else
{
newCmds.Add(cmd);
}
}
b.Cmds = newCmds;
}
#endregion
#region Adapt pre/postconditions to take account of stages
foreach (var p in prog.NonInlinedProcedures())
{
#region Handle the preconditions
{
List<Requires> newRequires = new List<Requires>();
//.........这里部分代码省略.........