public static void AddStatement(this BlockStatement block, Statement statement) { if (block == null) throw new ArgumentNullException("block"); if (statement == null) throw new ArgumentNullException("statement"); block.AddChild(statement); statement.Parent = block; }
public CatchClause(Statement statementBlock) { StatementBlock = statementBlock; typeReference = TypeReference.Null; variableName = ""; condition = Expression.Null; }
void UsingStatement(out Statement statement) { Expression expr = null; Statement block; statement = null; Expect(226); if (Peek(1).kind == Tokens.As) { LocalVariableDeclaration resourceAquisition = new LocalVariableDeclaration(Modifiers.None); VariableDeclarator(resourceAquisition.Variables); while (la.kind == 22) { Get(); VariableDeclarator(resourceAquisition.Variables); } EndOfStmt(); Block(out block); statement = new UsingStatement(resourceAquisition, block); } else if (StartOf(24)) { Expr(out expr); EndOfStmt(); Block(out block); statement = new UsingStatement(new ExpressionStatement(expr), block); } else SynErr(313); Expect(113); Expect(226); }
void ExpressionStatement(out Statement statement) { Expression expr = null; Expression val = null; AssignmentOperatorType op; Location startLoc = la.Location; bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus || la.kind == Tokens.Not || la.kind == Tokens.Times; SimpleExpr(out expr); if (StartOf(46)) { AssignmentOperator(out op); Expr(out val); expr = new AssignmentExpression(expr, op, val); expr.StartLocation = startLoc; expr.EndLocation = t.EndLocation; } else if (la.kind == 1 || la.kind == 21 || la.kind == 111) { if (mustBeAssignment) Error("error in assignment."); } else SynErr(312); if(expr is MemberReferenceExpression || expr is IdentifierExpression) { Location endLocation = expr.EndLocation; expr = new InvocationExpression(expr); expr.StartLocation = startLoc; expr.EndLocation = endLocation; } statement = new ExpressionStatement(expr); }
void SelectStatement(out Statement statement) { Expression expr = null; Expect(197); if (la.kind == 74) { Get(); } Expr(out expr); EndOfStmt(); List<SwitchSection> selectSections = new List<SwitchSection>(); Statement block = null; while (la.kind == 74) { List<CaseLabel> caseClauses = null; Location caseLocation = la.Location; Get(); CaseClauses(out caseClauses); if (IsNotStatementSeparator()) { Expect(21); } EndOfStmt(); SwitchSection selectSection = new SwitchSection(caseClauses); selectSection.StartLocation = caseLocation; Block(out block); selectSection.Children = block.Children; selectSection.EndLocation = t.EndLocation; selectSections.Add(selectSection); } statement = new SwitchStatement(expr, selectSections); Expect(113); Expect(197); }
void StopStatement(out Statement statement) { Expect(206); statement = new StopStatement(); }
void ReDimStatement(out Statement statement) { Expression expr = null; Expect(191); bool isPreserve = false; if (la.kind == 184) { Expect(184); isPreserve = true; } ReDimClause(out expr); ReDimStatement reDimStatement = new ReDimStatement(isPreserve); statement = reDimStatement; SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); while (la.kind == 22) { Get(); ReDimClause(out expr); SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); } }
void ForStatement(out Statement statement) { Expression expr = null; Statement embeddedStatement; statement = null; Location startLocation = la.Location; Expect(124); Expression group = null; TypeReference typeReference; string typeName; if (la.kind == 110) { Get(); LoopControlVariable(out typeReference, out typeName); Expect(138); Expr(out group); EndOfStmt(); Block(out embeddedStatement); Expect(163); if (StartOf(24)) { Expr(out expr); } statement = new ForeachStatement(typeReference, typeName, group, embeddedStatement, expr); statement.StartLocation = startLocation; statement.EndLocation = t.EndLocation; } else if (StartOf(42)) { Expression start = null; Expression end = null; Expression step = null; Expression variableExpr = null; Expression nextExpr = null; List<Expression> nextExpressions = null; if (IsLoopVariableDeclaration()) { LoopControlVariable(out typeReference, out typeName); } else { typeReference = null; typeName = null; SimpleExpr(out variableExpr); } Expect(20); Expr(out start); Expect(216); Expr(out end); if (la.kind == 205) { Get(); Expr(out step); } EndOfStmt(); Block(out embeddedStatement); Expect(163); if (StartOf(24)) { Expr(out nextExpr); nextExpressions = new List<Expression>(); nextExpressions.Add(nextExpr); while (la.kind == 22) { Get(); Expr(out nextExpr); nextExpressions.Add(nextExpr); } } statement = new ForNextStatement { TypeReference = typeReference, VariableName = typeName, LoopVariableExpression = variableExpr, Start = start, End = end, Step = step, EmbeddedStatement = embeddedStatement, NextExpressions = nextExpressions }; } else SynErr(309); }
void ContinueStatement(out Statement statement) { Expect(89); ContinueType continueType = ContinueType.None; if (la.kind == 108 || la.kind == 124 || la.kind == 231) { if (la.kind == 108) { Get(); continueType = ContinueType.Do; } else if (la.kind == 124) { Get(); continueType = ContinueType.For; } else { Get(); continueType = ContinueType.While; } } statement = new ContinueStatement(continueType); }
void TryStatement(out Statement tryStatement) { Statement blockStmt = null; Statement finallyStmt = null; CatchClause clause = null; List<CatchClause> catchClauses = new List<CatchClause>(); Expect(218); EndOfStmt(); Block(out blockStmt); while (la.kind == 75) { CatchClause(out clause); if (clause != null) catchClauses.Add(clause); } if (la.kind == 123) { Get(); EndOfStmt(); Block(out finallyStmt); } Expect(113); Expect(218); tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt); }
void ExitStatement(out Statement statement) { Expect(120); ExitType exitType = ExitType.None; switch (la.kind) { case 210: { Get(); exitType = ExitType.Sub; break; } case 127: { Get(); exitType = ExitType.Function; break; } case 186: { Get(); exitType = ExitType.Property; break; } case 108: { Get(); exitType = ExitType.Do; break; } case 124: { Get(); exitType = ExitType.For; break; } case 218: { Get(); exitType = ExitType.Try; break; } case 231: { Get(); exitType = ExitType.While; break; } case 197: { Get(); exitType = ExitType.Select; break; } default: SynErr(307); break; } statement = new ExitStatement(exitType); }
void LocalDeclarationStatement(out Statement statement) { ModifierList m = new ModifierList(); LocalVariableDeclaration localVariableDeclaration; bool dimfound = false; while (la.kind == 88 || la.kind == 105 || la.kind == 204) { if (la.kind == 88) { Get(); m.Add(Modifiers.Const, t.Location); } else if (la.kind == 204) { Get(); m.Add(Modifiers.Static, t.Location); } else { Get(); dimfound = true; } } if(dimfound && (m.Modifier & Modifiers.Const) != 0) { Error("Dim is not allowed on constants."); } if(m.isNone && dimfound == false) { Error("Const, Dim or Static expected"); } localVariableDeclaration = new LocalVariableDeclaration(m.Modifier); localVariableDeclaration.StartLocation = t.Location; VariableDeclarator(localVariableDeclaration.Variables); while (la.kind == 22) { Get(); VariableDeclarator(localVariableDeclaration.Variables); } statement = localVariableDeclaration; }
void EmbeddedStatement(out Statement statement) { statement = null; string name = String.Empty; Location startLocation = la.Location; if (la.kind == 120) { ExitStatement(out statement); } else if (la.kind == 218) { TryStatement(out statement); } else if (la.kind == 89) { ContinueStatement(out statement); } else if (la.kind == 215) { ThrowStatement(out statement); } else if (la.kind == 195) { ReturnStatement(out statement); } else if (la.kind == 211) { SyncLockStatement(out statement); } else if (la.kind == 189) { RaiseEventStatement(out statement); } else if (la.kind == 233) { WithStatement(out statement); } else if (la.kind == 56) { AddHandlerStatement(out statement); } else if (la.kind == 193) { RemoveHandlerStatement(out statement); } else if (la.kind == 231) { WhileStatement(out statement); } else if (la.kind == 108) { DoLoopStatement(out statement); } else if (la.kind == 124) { ForStatement(out statement); } else if (la.kind == 118) { ErrorStatement(out statement); } else if (la.kind == 191) { ReDimStatement(out statement); } else if (la.kind == 117) { EraseStatement(out statement); } else if (la.kind == 206) { StopStatement(out statement); } else if (la.kind == 135) { IfStatement(out statement); } else if (la.kind == 197) { SelectStatement(out statement); } else if (la.kind == 171) { OnErrorStatement onErrorStatement = null; OnErrorStatement(out onErrorStatement); statement = onErrorStatement; } else if (la.kind == 132) { GotoStatement goToStatement = null; GotoStatement(out goToStatement); statement = goToStatement; } else if (la.kind == 194) { ResumeStatement(out statement); } else if (StartOf(42)) { ExpressionStatement(out statement); } else if (la.kind == 73) { InvocationStatement(out statement); } else if (la.kind == 226) { UsingStatement(out statement); } else if (StartOf(43)) { LocalDeclarationStatement(out statement); } else SynErr(295); if (statement != null) { statement.StartLocation = startLocation; statement.EndLocation = t.EndLocation; } }
void Block(out Statement stmt) { BlockStatement blockStmt = new BlockStatement(); /* in snippet parsing mode, t might be null */ if (t != null) blockStmt.StartLocation = t.EndLocation; BlockStart(blockStmt); while (IsEndStmtAhead() || StartOf(StatementEndOfStmt)) { if (la.kind == 113) { Get(); Token first = t; AddChild(new EndStatement() { StartLocation = first.Location, EndLocation = first.EndLocation } ); EndOfStmt(); } else if (StartOf(1)) { Statement(); EndOfStmt(); } else SynErr(268); } stmt = blockStmt; if (t != null) blockStmt.EndLocation = t.EndLocation; BlockEnd(); }
void WhileStatement(out Statement statement) { Expression expr = null; Statement embeddedStatement; Expect(231); Expr(out expr); EndOfStmt(); Block(out embeddedStatement); Expect(113); Expect(231); statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); }
void ThrowStatement(out Statement statement) { Expression expr = null; Expect(215); if (StartOf(24)) { Expr(out expr); } statement = new ThrowStatement(expr); }
void DoLoopStatement(out Statement statement) { Expression expr = null; Statement embeddedStatement; statement = null; Expect(108); ConditionType conditionType = ConditionType.None; if (la.kind == 224 || la.kind == 231) { WhileOrUntil(out conditionType); Expr(out expr); EndOfStmt(); Block(out embeddedStatement); Expect(152); statement = new DoLoopStatement(expr, embeddedStatement, conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType, ConditionPosition.Start); } else if (la.kind == 1 || la.kind == 21) { EndOfStmt(); Block(out embeddedStatement); Expect(152); if (la.kind == 224 || la.kind == 231) { WhileOrUntil(out conditionType); Expr(out expr); } statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End); } else SynErr(308); }
void ReturnStatement(out Statement statement) { Expression expr = null; Expect(195); if (StartOf(24)) { Expr(out expr); } statement = new ReturnStatement(expr); }
void ErrorStatement(out Statement statement) { Expression expr = null; Expect(118); Expr(out expr); statement = new ErrorStatement(expr); }
void SyncLockStatement(out Statement statement) { Expression expr; Statement embeddedStatement; Expect(211); Expr(out expr); EndOfStmt(); Block(out embeddedStatement); Expect(113); Expect(211); statement = new LockStatement(expr, embeddedStatement); }
void EraseStatement(out Statement statement) { Expression expr = null; Expect(117); Expr(out expr); EraseStatement eraseStatement = new EraseStatement(); if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr);} while (la.kind == 22) { Get(); Expr(out expr); if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr); } } statement = eraseStatement; }
void RaiseEventStatement(out Statement statement) { List<Expression> arguments = null; Expect(189); Identifier(); string name = t.val; if (la.kind == 37) { Get(); ArgumentList(out arguments); Expect(38); } statement = new RaiseEventStatement(name, arguments); }
void IfStatement(out Statement statement) { Expression expr = null; Statement embeddedStatement; statement = null; Expect(135); Location ifStartLocation = t.Location; Expr(out expr); if (la.kind == 214) { Get(); } if (la.kind == 1 || la.kind == 21) { EndOfStmt(); Block(out embeddedStatement); IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement); ifStatement.StartLocation = ifStartLocation; Location elseIfStart; while (la.kind == 112 || (IsElseIf())) { if (IsElseIf()) { Expect(111); elseIfStart = t.Location; Expect(135); } else { Get(); elseIfStart = t.Location; } Expression condition = null; Statement block = null; Expr(out condition); if (la.kind == 214) { Get(); } EndOfStmt(); Block(out block); ElseIfSection elseIfSection = new ElseIfSection(condition, block); elseIfSection.StartLocation = elseIfStart; elseIfSection.EndLocation = t.Location; elseIfSection.Parent = ifStatement; ifStatement.ElseIfSections.Add(elseIfSection); } if (la.kind == 111) { Get(); if (la.kind == 1 || la.kind == 21) { EndOfStmt(); } Block(out embeddedStatement); ifStatement.FalseStatement.Add(embeddedStatement); } Expect(113); Expect(135); ifStatement.EndLocation = t.Location; statement = ifStatement; } else if (StartOf(44)) { IfElseStatement ifStatement = new IfElseStatement(expr); ifStatement.StartLocation = ifStartLocation; SingleLineStatementList(ifStatement.TrueStatement); if (la.kind == 111) { Get(); if (StartOf(44)) { SingleLineStatementList(ifStatement.FalseStatement); } } ifStatement.EndLocation = t.Location; statement = ifStatement; } else SynErr(310); }
void WithStatement(out Statement withStatement) { Statement blockStmt = null; Expression expr = null; Expect(233); Location start = t.Location; Expr(out expr); EndOfStmt(); withStatement = new WithStatement(expr); withStatement.StartLocation = start; Block(out blockStmt); ((WithStatement)withStatement).Body = (BlockStatement)blockStmt; Expect(113); Expect(233); withStatement.EndLocation = t.Location; }
void ResumeStatement(out Statement resumeStatement) { resumeStatement = null; string label = string.Empty; Expect(194); if (StartOf(45)) { if (la.kind == 163) { Get(); resumeStatement = new ResumeStatement(true); } else { LabelName(out label); } } resumeStatement = new ResumeStatement(label); }
void AddHandlerStatement(out Statement statement) { Expression expr = null; Expect(56); Expression handlerExpr = null; Expr(out expr); Expect(22); Expr(out handlerExpr); statement = new AddHandlerStatement(expr, handlerExpr); }
void InvocationStatement(out Statement statement) { Expression expr = null; Expect(73); SimpleExpr(out expr); statement = new ExpressionStatement(expr); }
void RemoveHandlerStatement(out Statement statement) { Expression expr = null; Expect(193); Expression handlerExpr = null; Expr(out expr); Expect(22); Expr(out handlerExpr); statement = new RemoveHandlerStatement(expr, handlerExpr); }
public static Statement CheckNull(Statement statement) { return statement ?? NullStatement.Instance; }
public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock, Expression condition) { TypeReference = typeReference; VariableName = variableName; StatementBlock = statementBlock; Condition = condition; }