本文整理汇总了C#中LabelStatement类的典型用法代码示例。如果您正苦于以下问题:C# LabelStatement类的具体用法?C# LabelStatement怎么用?C# LabelStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LabelStatement类属于命名空间,在下文中一共展示了LabelStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LabelProducesLabel
public void LabelProducesLabel()
{
var label = new LabelStatement("exit", JS.Return());
Assert.AreEqual("exit", label.Name);
Assert.AreEqual("return;", label.Statement.ToString());
Assert.AreEqual("exit:return;", label.ToString());
label.Name = "loop";
label.Statement = JS.For();
Assert.AreEqual("loop", label.Name);
Assert.AreEqual("for(;;);", label.Statement.ToString());
Assert.AreEqual("loop:for(;;);", label.ToString());
}
示例2: VisitLabelStatement
public override void VisitLabelStatement (LabelStatement labelStatement)
{
base.VisitLabelStatement (labelStatement);
var t = labelStatement.GetParent <TryCatchStatement> ();
if (t == null)
return;
if (t.TryBlock.Statements.First () == labelStatement) {
labelStatement.Remove ();
t.Parent.InsertChildBefore (t, labelStatement, (Role<Statement>)t.Role);
}
}
示例3: Visit
public override object Visit (LabeledStatement labeledStatement)
{
var result = new LabelStatement ();
result.AddChild (new Identifier (labeledStatement.Name, Convert (labeledStatement.loc)), LabelStatement.Roles.Identifier);
return result;
}
示例4: Visit
public override object Visit(LabeledStatement labeledStatement)
{
var result = new LabelStatement();
result.AddChild(Identifier.Create(labeledStatement.Name, Convert(labeledStatement.loc)), Roles.Identifier);
var location = LocationsBag.GetLocations(labeledStatement);
if (location != null)
result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.Colon), Roles.Colon);
return result;
}
示例5: VisitLabelStatement
public override void VisitLabelStatement(LabelStatement labelStatement) {
throw new InvalidOperationException("Visited a LabelStatement in the statement compiler, this should have been taken care of in parent.");
}
示例6: Visit
public void Visit(LabelStatement expression)
{
if (!string.IsNullOrEmpty(expression.Name))
outStream.Write("{0}: ", expression.Name);
Visit(expression.Target);
}
示例7: Visit
public override void Visit(LabelStatement node) { this.action(node); }
示例8: VisitLabelStatement
public void VisitLabelStatement(LabelStatement statement)
{
Formatter.StartNode(statement);
Formatter.WriteIdentifier(statement.Label);
Formatter.WriteToken(":");
Formatter.EndNode();
}
示例9: VisitLabelStatement
public object VisitLabelStatement(LabelStatement labelStatement, object data)
{
return new B.LabelStatement(GetLexicalInfo(labelStatement), labelStatement.Label);
}
示例10: VisitLabelStatement
public void VisitLabelStatement(LabelStatement labelStatement)
{
JsonObject statement = CreateJsonStatement(labelStatement);
statement.AddJsonValue("identifier", GetIdentifier(labelStatement.GetChildByRole(Roles.Identifier)));
Push(statement);
}
示例11: HasBreakto
static bool HasBreakto (LabelStatement label)
{
var m = label.GetParent<MethodDeclaration> ();
if (m == null)
return false;
return m.Descendants.OfType<BreakStatement> ().Any (x => {
var l = x.Annotation<LabelStatement> ();
if (l == null)
return false;
return l.Label == label.Label;
});
}
示例12: HasGoto
static bool HasGoto (LabelStatement label)
{
var m = label.GetParent<MethodDeclaration> ();
if (m == null)
return false;
return m.Descendants.OfType<GotoStatement> ().Any (x => x.Label == label.Label);
}
示例13: 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);
}
示例14: LabelBlock
public LabelBlock(IEmitter emitter, LabelStatement labelStatement) : base(emitter, labelStatement) {
labelStatement_ = labelStatement;
}
示例15: VisitLabelStatement
public override void VisitLabelStatement(LabelStatement labelStatement)
{
base.VisitLabelStatement(labelStatement);
CheckNamedResolveResult(null, labelStatement, AffectedEntity.Label, labelStatement.LabelToken, Modifiers.None);
}