Example #1
0
			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;
				});
			}
Example #2
0
				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);
					}
				}
Example #3
0
			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);
			}
Example #4
0
			public override void VisitLabelStatement (LabelStatement labelStatement)
			{
				base.VisitLabelStatement (labelStatement);

				var ifs = labelStatement.NextSibling as IfElseStatement;
				if (ifs == null || !ifs.FalseStatement.IsNull)
					return;

				var b = ifs.TrueStatement as BlockStatement;
				if (b == null || b.Statements.Count == 0)
					return;

				var gt = b.Statements.Last () as GotoStatement;
				if (gt == null || gt.Label != labelStatement.Label)
					return;

				if (labelStatement.GetParent<MethodDeclaration> ().Descendants.OfType<GotoStatement> ().Count () != 1)
					return;

				gt.Remove ();
				b.Remove ();
				var wh = new WhileStatement {
					Condition = ifs.Condition.Clone (),
					EmbeddedStatement = b,
				};

				ifs.ReplaceWith (wh);

				labelStatement.Remove ();

			}