当前位置: 首页>>代码示例>>C#>>正文


C# BreakStatement.AddAnnotation方法代码示例

本文整理汇总了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);
				}
开发者ID:RReverser,项目名称:Netjs,代码行数:79,代码来源:CsToTs.cs

示例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);
				}
开发者ID:RReverser,项目名称:Netjs,代码行数:12,代码来源:CsToTs.cs


注:本文中的BreakStatement.AddAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。