public void Constructor0_Deny_Unrestricted() { CodeGotoStatement cgs = new CodeGotoStatement(); Assert.IsNull(cgs.Label, "Label"); cgs.Label = "mono"; }
protected override void GenerateGotoStatement (CodeGotoStatement e) { Output.Write("goto "); Output.Write(e.Label); Output.WriteLine(";"); }
public void Constructor1_Deny_Unrestricted() { CodeGotoStatement cgs = new CodeGotoStatement("mono"); Assert.AreEqual("mono", cgs.Label, "Label"); cgs.Label = "monkey"; // doesn't accept String.Empty }
public void Constructor0() { CodeGotoStatement cgs = new CodeGotoStatement(); Assert.IsNull(cgs.Label, "#1"); Assert.IsNotNull(cgs.StartDirectives, "#2"); Assert.AreEqual(0, cgs.StartDirectives.Count, "#3"); Assert.IsNotNull(cgs.EndDirectives, "#4"); Assert.AreEqual(0, cgs.EndDirectives.Count, "#5"); Assert.IsNotNull(cgs.UserData, "#6"); Assert.AreEqual(typeof(ListDictionary), cgs.UserData.GetType(), "#7"); Assert.AreEqual(0, cgs.UserData.Count, "#8"); Assert.IsNull(cgs.LinePragma, "#9"); CodeLinePragma clp = new CodeLinePragma("mono", 10); cgs.LinePragma = clp; Assert.IsNotNull(cgs.LinePragma, "#10"); Assert.AreSame(clp, cgs.LinePragma, "#11"); cgs.LinePragma = null; Assert.IsNull(cgs.LinePragma, "#12"); string label = "mono"; cgs.Label = label; Assert.AreSame(label, cgs.Label, "#13"); }
static CodeGotoStatement _ParseGotoStatement(_PC pc) { // expects to be on goto. pc.Advance(); _SkipComments(pc); if (pc.IsEnded) { throw new ArgumentException("Unterminated goto statement", "input"); } if (ST.identifier != pc.SymbolId) { throw new ArgumentException("Expecting identifier in goto statement", "input"); } var g = new CodeGotoStatement(pc.Value); pc.Advance(); _SkipComments(pc); if (pc.IsEnded) { throw new ArgumentException("Unterminated goto statement", "input"); } if (ST.semi != pc.SymbolId) { throw new ArgumentException("Expecting ; after goto statement", "input"); } pc.Advance(); return(g); }
public void Constructor1() { string label1 = "mono1"; CodeGotoStatement cgs = new CodeGotoStatement(label1); Assert.IsNotNull(cgs.Label, "#1"); Assert.AreSame(label1, cgs.Label, "#2"); #if NET_2_0 Assert.IsNotNull(cgs.StartDirectives, "#3"); Assert.AreEqual(0, cgs.StartDirectives.Count, "#4"); Assert.IsNotNull(cgs.EndDirectives, "#5"); Assert.AreEqual(0, cgs.EndDirectives.Count, "#6"); #endif Assert.IsNotNull(cgs.UserData, "#7"); Assert.AreEqual(typeof(ListDictionary), cgs.UserData.GetType(), "#8"); Assert.AreEqual(0, cgs.UserData.Count, "#9"); Assert.IsNull(cgs.LinePragma, "#10"); string label2 = "mono2"; cgs.Label = label2; Assert.AreSame(label2, cgs.Label, "#11"); }
public void Constructor1_NullLabel() { CodeGotoStatement cgs = new CodeGotoStatement((string)null); #if ONLY_1_1 Assert.IsNull(cgs.Label, "#1"); #endif }
public void CodeTryCatchFinallyStatementTest() { CodeStatement cs = new CodeGotoStatement("exit"); CodeCatchClause ccc1 = new CodeCatchClause("ex1", new CodeTypeReference("System.ArgumentException")); CodeCatchClause ccc2 = new CodeCatchClause(null, new CodeTypeReference("System.ApplicationException")); CodeSnippetStatement fin1 = new CodeSnippetStatement("A"); CodeSnippetStatement fin2 = new CodeSnippetStatement("B"); statement = new CodeTryCatchFinallyStatement(new CodeStatement[] { cs }, new CodeCatchClause[] { ccc1, ccc2 }, new CodeStatement[] { fin1, fin2 }); Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "try {{{0}" + " goto exit;{0}" + "}}{0}" + "catch (System.ArgumentException ex1) {{{0}" + "}}{0}" + "catch (System.ApplicationException ) {{{0}" + "}}{0}" + "finally {{{0}" + #if NET_2_0 "A{0}" + "B{0}" + #else " A{0}" + " B{0}" + #endif "}}{0}", NewLine), Generate(), "#1"); options.ElseOnClosing = true; Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "try {{{0}" + " goto exit;{0}" + "}} catch (System.ArgumentException ex1) {{{0}" + "}} catch (System.ApplicationException ) {{{0}" + "}} finally {{{0}" + #if NET_2_0 "A{0}" + "B{0}" + #else " A{0}" + " B{0}" + #endif "}}{0}", NewLine), Generate(), "#2"); statement = new CodeTryCatchFinallyStatement(); Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "try {{{0}" + "}}{0}", NewLine), Generate(), "#3"); options.ElseOnClosing = false; Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "try {{{0}" + "}}{0}", NewLine), Generate(), "#4"); }
public void Constructor1_EmptyLabel() { CodeGotoStatement cgs = new CodeGotoStatement(string.Empty); #if ONLY_1_1 Assert.IsNotNull(cgs.Label, "#1"); Assert.AreEqual(string.Empty, cgs.Label, "#2"); #endif }
public void Label_Null() { CodeGotoStatement cgs = new CodeGotoStatement("mono"); cgs.Label = null; #if ONLY_1_1 Assert.IsNull(cgs.Label, "#1"); #endif }
public override object Visit(GotoStatement gotoStatement, object data) { System.CodeDom.CodeGotoStatement gotoStmt = new CodeGotoStatement(gotoStatement.Label); // Add Statement to Current Statement Collection AddStmt(gotoStmt); return(gotoStmt); }
public static CodeGotoStatement GotoStatement(string label, CodeDirective[] startDirectives, CodeDirective[] endDirectives, CodeLinePragma linePragma) { var result = new CodeGotoStatement(label); result.StartDirectives.AddRange(startDirectives); result.EndDirectives.AddRange(endDirectives); result.LinePragma = linePragma; return(result); }
public void Label_Empty() { CodeGotoStatement cgs = new CodeGotoStatement("mono"); cgs.Label = string.Empty; #if ONLY_1_1 Assert.IsNotNull(cgs.Label, "#1"); Assert.AreEqual(string.Empty, cgs.Label, "#2"); #endif }
public TypescriptGotoStatement( IStatementFactory statementFactory, IExpressionFactory expressionFactory, CodeGotoStatement statement, CodeGeneratorOptions options) { _statementFactory = statementFactory; _expressionFactory = expressionFactory; _statement = statement; _options = options; }
private void EmitGotoStatement(CodeGotoStatement Goto) { Depth++; Debug("Emitting goto: " + Goto.Label); LabelMetadata Meta = LookupLabel(Goto.Label); Generator.Emit(OpCodes.Br, Meta.Label); Meta.From = Goto; Depth--; }
public CodeGotoStatementExample() { //<Snippet2> // Declares a type to contain the example code. CodeTypeDeclaration type1 = new CodeTypeDeclaration("Type1"); // Declares an entry point method. CodeEntryPointMethod entry1 = new CodeEntryPointMethod(); type1.Members.Add(entry1); // Adds a goto statement to continue program flow at the "JumpToLabel" label. CodeGotoStatement goto1 = new CodeGotoStatement("JumpToLabel"); entry1.Statements.Add(goto1); // Invokes Console.WriteLine to print "Test Output", which is skipped by the goto statement. CodeMethodInvokeExpression method1 = new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("System.Console"), "WriteLine", new CodePrimitiveExpression("Test Output.")); entry1.Statements.Add(method1); // Declares a label named "JumpToLabel" associated with a method to output a test string using Console.WriteLine. CodeMethodInvokeExpression method2 = new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("System.Console"), "WriteLine", new CodePrimitiveExpression("Output from labeled statement.")); CodeLabeledStatement label1 = new CodeLabeledStatement("JumpToLabel", new CodeExpressionStatement(method2)); entry1.Statements.Add(label1); // A C# code generator produces the following source code for the preceeding example code: // public class Type1 // { // // public static void Main() // { // goto JumpToLabel; // System.Console.WriteLine("Test Output"); // JumpToLabel: // System.Console.WriteLine("Output from labeled statement."); // } // } //</Snippet2> }
private void IterateStatementImpl(CodeStatement state, List <object> list) { ThrowIfNull(state); ThrowIfNull(list); list.Add(state); CodeMethodReturnStatement retState = state as CodeMethodReturnStatement; if (retState != null) { IterateExprImpl(retState.Expression, list); return; } CodeAssignStatement asgState = state as CodeAssignStatement; if (asgState != null) { IterateExprImpl(asgState.Left, list); IterateExprImpl(asgState.Right, list); return; } CodeVariableDeclarationStatement varDeclState = state as CodeVariableDeclarationStatement; if (varDeclState != null) { IterateExprImpl(varDeclState.InitExpression, list); IterateTypeRefImpl(varDeclState.Type, list); return; } CodeConditionStatement condState = state as CodeConditionStatement; if (condState != null) { IterateExprImpl(condState.Condition, list); IterateStatementsImpl(condState.TrueStatements, list); IterateStatementsImpl(condState.FalseStatements, list); return; } CodeLabeledStatement labelState = state as CodeLabeledStatement; if (labelState != null) { return; } CodeGotoStatement gotoState = state as CodeGotoStatement; if (gotoState != null) { return; } CodeExpressionStatement exprState = state as CodeExpressionStatement; if (exprState != null) { IterateExprImpl(exprState.Expression, list); return; } throw new NotImplementedException("Unrecognized statement"); }
public void Visit(CodeGotoStatement o) { g.GenerateGotoStatement(o); }
protected abstract void GenerateGotoStatement(CodeGotoStatement statement);
protected virtual void Visit(CodeGotoStatement statement) { }
void EmitGoto(CodeGotoStatement go) { writer.Write(Parser.FlowGoto); writer.Write(Parser.SingleSpace); writer.Write(go.Label); }
protected override void GenerateGotoStatement(CodeGotoStatement e) { }
private static void ValidateGotoStatement(CodeGotoStatement e) { ValidateIdentifier(e, "Label", e.Label); }
protected override void GenerateGotoStatement(CodeGotoStatement e) { Output.Write("goto"); }
protected override void GenerateGotoStatement(CodeGotoStatement e) { Output.WriteLine("[CodeGotoStatement: {0}]", e.ToString()); }
protected override void GenerateGotoStatement(CodeGotoStatement statement) { throw new NotSupportedException("Goto statement is not supported in JScript."); }
public bool ValidateCodeGotoStatement(CodeGotoStatement exp) { PushError("CodeGotoStatement is not allowed."); return(false); }
protected override void Visit(CodeGotoStatement statement) { base.Visit(statement); }
static CodeStatement _ParseStatement(_PC pc, bool includeComments = false) { #region Preamble CodeLinePragma lp = null; var startDirs = new CodeDirectiveCollection(); while (ST.directive == pc.SymbolId) { var d = _ParseDirective(pc); if (null != d) { var clp = d as CodeLinePragma; if (null != clp) { lp = clp; } else { startDirs.Add(d as CodeDirective); } } while (!includeComments && ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId) { pc.Advance(false); } } CodeStatement stmt = null; if (includeComments && (ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId)) { stmt = _ParseCommentStatement(pc); stmt.StartDirectives.AddRange(startDirs); if (null != lp) { stmt.LinePragma = lp; } } else { while (ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId) { pc.Advance(false); } } #endregion Preamble var l = pc.Line; var c = pc.Column; var p = pc.Position; // if we got here we've parsed our start directives and this isn't a comment statement if (null == stmt) { _PC pc2 = null; switch (pc.SymbolId) { case ST.semi: // can't do much with empty statements pc.Advance(); stmt = new CodeSnippetStatement().SetLoc(l, c, p); break; case ST.gotoKeyword: pc.Advance(); if (ST.identifier != pc.SymbolId) { pc.Error("Expecting label identifier in goto statement"); } stmt = new CodeGotoStatement(pc.Value).SetLoc(l, c, p); if (ST.semi != pc.SymbolId) { pc.Error("Expecting ; in goto statement"); } pc.Advance(); break; case ST.returnKeyword: pc.Advance(); if (ST.semi != pc.SymbolId) { stmt = new CodeMethodReturnStatement(_ParseExpression(pc)).Mark(l, c, p); } else { stmt = new CodeMethodReturnStatement().SetLoc(l, c, p); } if (ST.semi != pc.SymbolId) { pc.Error("Expecting ; in return statement"); } pc.Advance(); break; case ST.throwKeyword: pc.Advance(); var expr = _ParseExpression(pc); stmt = new CodeThrowExceptionStatement(expr).Mark(l, c, p); if (ST.semi != pc.SymbolId) { pc.Error("Expecting ; in throw statement"); } pc.Advance(); break; case ST.ifKeyword: stmt = _ParseIfStatement(pc); break; case ST.whileKeyword: stmt = _ParseWhileStatement(pc); break; case ST.forKeyword: stmt = _ParseForStatement(pc); break; case ST.tryKeyword: stmt = _ParseTryCatchFinallyStatement(pc); break; case ST.varType: stmt = _ParseVariableDeclarationStatement(pc); break; default: // possibly a var decl, a label statement, or an expression statement if (ST.identifier == pc.SymbolId) { pc2 = pc.GetLookAhead(true); pc2.Advance(); if (ST.colon == pc2.SymbolId) // label { var lbl = pc2.Value; pc.Advance(); stmt = new CodeLabeledStatement(lbl, new CodeSnippetStatement().SetLoc(l, c, p)).SetLoc(l, c, p); pc2 = null; break; } } pc2 = null; pc2 = pc.GetLookAhead(true); pc2.ResetAdvanceCount(); var advc = 0; try { // possibly a var decl stmt = _ParseVariableDeclarationStatement(pc2); advc = pc2.AdvanceCount; while (advc > 0) { pc.Advance(false); --advc; } break; } catch (SlangSyntaxException sx) { try { pc.ResetAdvanceCount(); expr = _ParseExpression(pc); if (ST.semi != pc.SymbolId) { pc.Error("Expecting ; in expression statement"); } pc.Advance(); var bo = expr as CodeBinaryOperatorExpression; if (null != bo && CodeBinaryOperatorType.Assign == bo.Operator) { var ur = bo.UserData.Contains("slang:unresolved"); stmt = new CodeAssignStatement(bo.Left, bo.Right).Mark(l, c, p, ur); } else { stmt = new CodeExpressionStatement(expr).Mark(l, c, p); } break; } catch (SlangSyntaxException sx2) { if (pc.AdvanceCount > advc) { throw sx2; } throw sx; } } } } #region Post stmt.StartDirectives.AddRange(startDirs); if (null != lp) { stmt.LinePragma = lp; } while (!includeComments && ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId) { pc.Advance(false); } while (ST.directive == pc.SymbolId && pc.Value.StartsWith("#end", StringComparison.InvariantCulture)) { stmt.EndDirectives.Add(_ParseDirective(pc) as CodeDirective); while (!includeComments && ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId) { pc.Advance(false); } } #endregion Post return(stmt); }
private static void ValidateGotoStatement(CodeGotoStatement e) { ValidateIdentifier(e, nameof(e.Label), e.Label); }
protected abstract void GenerateGotoStatement(CodeGotoStatement e);