本文整理汇总了C#中BreakStatement.AddAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# BreakStatement.AddAnnotation方法的具体用法?C# BreakStatement.AddAnnotation怎么用?C# BreakStatement.AddAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BreakStatement
的用法示例。
在下文中一共展示了BreakStatement.AddAnnotation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitMethodDeclaration
public override void VisitMethodDeclaration (MethodDeclaration methodDeclaration)
{
base.VisitMethodDeclaration (methodDeclaration);
var gotos = methodDeclaration.Body.Descendants.OfType<GotoStatement> ().ToList ();
if (gotos.Count == 0)
return;
var loop = new WhileStatement {
Condition = new PrimitiveExpression (true),
};
var loopBlock = new BlockStatement ();
var loopSwitch = new SwitchStatement {
Expression = new IdentifierExpression ("_goto"),
};
var loopLabel = new LabelStatement {
Label = "_GOTO_LOOP",
};
loopBlock.Statements.Add (loopSwitch);
loop.EmbeddedStatement = loopBlock;
var firstLabel = methodDeclaration.Body.Descendants.First (x => /*(x is GotoStatement) ||*/ (x is LabelStatement && HasGoto ((LabelStatement)x)));
var stmtRole = (Role<Statement>)firstLabel.Role;
var block = firstLabel.Parent;
var labels = new List<Tuple<LabelStatement, List<AstNode>>> ();
labels.Add (new Tuple<LabelStatement, List<AstNode>> (null, new List<AstNode> ()));
var n = firstLabel.Parent.FirstChild;
while (n != null && !n.IsNull) {
var l = n as LabelStatement;
if (l != null && gotos.Any (x => x.Label == l.Label)) {
labels.Add (new Tuple<LabelStatement, List<AstNode>> (l, new List<AstNode> ()));
} else {
labels.Last ().Item2.Add (n);
}
var s = n.NextSibling;
n.Remove ();
n = s;
}
for (int i = 0; i < labels.Count; i++) {
var ls = labels [i];
var sec = new SwitchSection ();
sec.CaseLabels.Add (ls.Item1 != null ? new CaseLabel (new PrimitiveExpression (i)) : new CaseLabel ());
if (ls.Item2.Count == 0 || !StatementIsBranch (ls.Item2.Last ())) {
if (i + 1 < labels.Count) {
ls.Item2.Add (new GotoStatement (labels [i + 1].Item1.Label));
} else {
var br = new BreakStatement ();
br.AddAnnotation (new LabelStatement { Label = "_GOTO_LOOP" });
ls.Item2.Add (br);
}
}
sec.Statements.AddRange (ls.Item2.OfType<Statement> ());
loopSwitch.SwitchSections.Add (sec);
if (ls.Item1 != null) {
block.AddChild (
new VariableDeclarationStatement (new PrimitiveType ("number"), ls.Item1.Label, new PrimitiveExpression (i)),
stmtRole);
}
}
block.AddChild (
new VariableDeclarationStatement (new PrimitiveType ("number"), "_goto", new PrimitiveExpression (0)),
stmtRole);
block.AddChild (loopLabel, stmtRole);
block.AddChild (loop, stmtRole);
}
示例2: VisitBreakStatement
public override void VisitBreakStatement (BreakStatement breakStatement)
{
base.VisitBreakStatement (breakStatement);
var loop = GetOuterLoop (breakStatement);
if (loop == null || loop is SwitchStatement)
return;
var label = GetOrAddStatementLabel (loop, "loop");
breakStatement.AddAnnotation (label);
}