public void Constructor1() { string label = "mono"; CodeLabeledStatement cls = new CodeLabeledStatement(label); Assert.IsNull(cls.LinePragma, "#1"); Assert.IsNotNull(cls.Label, "#2"); Assert.AreSame(label, cls.Label, "#3"); Assert.IsNotNull(cls.StartDirectives, "#4"); Assert.AreEqual(0, cls.StartDirectives.Count, "#5"); Assert.IsNotNull(cls.EndDirectives, "#6"); Assert.AreEqual(0, cls.EndDirectives.Count, "#7"); Assert.IsNotNull(cls.UserData, "#8"); Assert.AreEqual(typeof(ListDictionary), cls.UserData.GetType(), "#9"); Assert.AreEqual(0, cls.UserData.Count, "#10"); Assert.IsNull(cls.Statement, "#11"); cls = new CodeLabeledStatement((string)null); Assert.IsNotNull(cls.Label, "#12"); Assert.AreEqual(string.Empty, cls.Label, "#13"); }
public CodeLabeledStatement declLabel(string labelName, CodeStatement statement) { CodeLabeledStatement s = new CodeLabeledStatement(labelName, statement); _enter(s); return(s); }
private void ValidateLabeledStatement(CodeLabeledStatement e) { ValidateIdentifier(e, nameof(e.Label), e.Label); if (e.Statement != null) { ValidateStatement(e.Statement); } }
public static void ReplaceType(this CodeLabeledStatement statement, string oldType, string newType) { if (statement == null) { return; } statement.Statement.ReplaceType(oldType, newType); }
private void ValidateLabeledStatement(CodeLabeledStatement e) { ValidateIdentifier(e, "Label", e.Label); if (e.Statement != null) { this.ValidateStatement(e.Statement); } }
public static CodeLabeledStatement LabeledStatement(string label, CodeStatement statement, CodeDirective[] startDirectives, CodeDirective[] endDirectives, CodeLinePragma linePragma) { var result = new CodeLabeledStatement(label, statement); result.StartDirectives.AddRange(startDirectives); result.EndDirectives.AddRange(endDirectives); result.LinePragma = linePragma; return(result); }
public override object Visit(LabelStatement labelStatement, object data) { System.CodeDom.CodeLabeledStatement labelStmt = new CodeLabeledStatement(labelStatement.Label, (CodeStatement)labelStatement.AcceptVisitor(this, data)); // Add Statement to Current Statement Collection AddStmt(labelStmt); return(labelStmt); }
protected override void GenerateLabeledStatement (CodeLabeledStatement e) { Indent -= 1; Output.Write(e.Label); Output.WriteLine(":"); Indent += 1; GenerateStatement(e.Statement); }
private void GenerateLabeledStatement(CodeLabeledStatement e) { Indent--; output.Write(e.Label); output.WriteLine(":"); Indent++; if (e.Statement != null) { GenerateStatement(e.Statement); } }
public TypescriptLabeledStatement( IStatementFactory statementFactory, IExpressionFactory expressionFactory, CodeLabeledStatement statement, CodeGeneratorOptions options) { _statementFactory = statementFactory; _expressionFactory = expressionFactory; _statement = statement; _options = options; }
private bool HandleDynamic(CodeLabeledStatement obj, Context ctx) { return(HandleIfTrue(() => { ctx.Writer.WriteLine($"{AsIdentifier(obj.Label)}{LabelDefinitionSuffix}"); if (obj.Statement != null) { ctx.Writer.Indent(ctx); ctx.HandlerProvider.StatementHandler.Handle(obj.Statement, ctx); } }, obj, ctx, !string.IsNullOrEmpty(LabelDefinitionSuffix), false)); }
public static CodeLabeledStatement Clone(this CodeLabeledStatement statement) { if (statement == null) { return(null); } CodeLabeledStatement s = new CodeLabeledStatement(); s.EndDirectives.AddRange(statement.EndDirectives); s.Label = statement.Label; s.LinePragma = statement.LinePragma; s.StartDirectives.AddRange(statement.StartDirectives); s.Statement = statement.Statement.Clone(); s.UserData.AddRange(statement.UserData); return(s); }
public void Constructor0() { CodeLabeledStatement cls = new CodeLabeledStatement(); Assert.IsNull(cls.LinePragma, "#1"); Assert.IsNotNull(cls.Label, "#2"); Assert.AreEqual(string.Empty, cls.Label, "#3"); Assert.IsNotNull(cls.StartDirectives, "#4"); Assert.AreEqual(0, cls.StartDirectives.Count, "#5"); Assert.IsNotNull(cls.EndDirectives, "#6"); Assert.AreEqual(0, cls.EndDirectives.Count, "#7"); Assert.IsNotNull(cls.UserData, "#8"); Assert.AreEqual(typeof(ListDictionary), cls.UserData.GetType(), "#9"); Assert.AreEqual(0, cls.UserData.Count, "#10"); string label = "mono"; cls.Label = label; Assert.IsNotNull(cls.Label, "#11"); Assert.AreSame(label, cls.Label, "#12"); cls.Label = null; Assert.IsNotNull(cls.Label, "#13"); Assert.AreEqual(string.Empty, cls.Label, "#14"); CodeLinePragma clp = new CodeLinePragma("mono", 10); cls.LinePragma = clp; Assert.IsNotNull(cls.LinePragma, "#15"); Assert.AreSame(clp, cls.LinePragma, "#16"); cls.LinePragma = null; Assert.IsNull(cls.LinePragma, "#17"); Assert.IsNull(cls.Statement, "#18"); CodeStatement stmt = new CodeStatement(); cls.Statement = stmt; Assert.IsNotNull(cls.Statement, "#19"); Assert.AreSame(stmt, cls.Statement); }
public void CodeLabeledStatementTest() { CodeLabeledStatement cls = new CodeLabeledStatement(); statement = cls; Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, ":{0}", NewLine), Generate(), "#1"); cls.Label = "class"; Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "class:{0}", NewLine), Generate(), "#2"); cls.Statement = new CodeSnippetStatement("A"); Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "class:{0}" + "A{0}", NewLine), Generate(), "#3"); }
private void EmitLabeledStatement(CodeLabeledStatement Labeled) { Depth++; Debug("Marking label: " + Labeled.Label); LabelMetadata Meta = LookupLabel(Labeled.Label); if (Meta.Resolved) { throw new CompileException(Labeled, "Can not mark the label " + Meta.Name + " twice"); } Generator.MarkLabel(Meta.Label); EmitStatement(Labeled.Statement); Meta.Resolved = true; Meta.Bound = Labeled.Statement; 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> }
void EmitLabel(CodeLabeledStatement label) { writer.Write(label.Label); writer.Write(Parser.HotkeyBound); }
protected override void Visit(CodeLabeledStatement statement) { Enumerate(statement.Statement); base.Visit(statement); }
protected override void GenerateLabeledStatement(CodeLabeledStatement e) { Output.Write("labelled"); }
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); }
protected abstract void GenerateLabeledStatement(CodeLabeledStatement e);
protected override void GenerateLabeledStatement(CodeLabeledStatement statement) { throw new NotSupportedException(); }
private void GenerateLabeledStatement(CodeLabeledStatement e) { Indent--; Output.Write(e.Label); Output.WriteLine(":"); Indent++; if (e.Statement != null) { GenerateStatement(e.Statement); } }
protected override void GenerateLabeledStatement(CodeLabeledStatement e) { }
private static IList <CodeVariableDeclarationStatement> _TraceLabeledStatement(CodeLabeledStatement s, CodeStatement t, out bool found) { found = false; if (s == t) { found = true; return(new CodeVariableDeclarationStatement[0]); } if (null != s.Statement) { return(_TraceStatement(s.Statement, t, out found)); } return(new CodeVariableDeclarationStatement[0]); }
protected override void GenerateLabeledStatement(CodeLabeledStatement e) { Output.WriteLine("[CodeLabeledStatement: {0}]", e.ToString()); }
protected abstract void GenerateLabeledStatement(CodeLabeledStatement statement);
public void Visit(CodeLabeledStatement o) { g.GenerateLabeledStatement(o); }
protected virtual void Visit(CodeLabeledStatement statement) { }
protected override void GenerateLabeledStatement(CodeLabeledStatement statement) { throw new NotSupportedException("Labeled statement is not supported in JScript."); }
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 bool ValidateCodeLabeledStatement(CodeLabeledStatement exp) { PushError("CodeLabeledStatement is not allowed."); return(false); }