private IList ConvertToSingleDeclarationStatements(MultipleVariableDeclarationStatement varDecl) { IList newStmts = new ArrayList(); int index = 0; ExpressionCollection initExps = varDecl.InitExpressions; foreach(Identifier ident in varDecl.Identifiers) { // Here we are converting expression from // x:int, y:long = 1, 2L // to an AST representation equivalent to // x:int = 1; y:long = 2L SingleVariableDeclarationStatement svStmt = new SingleVariableDeclarationStatement(ident); if (index < initExps.Count) { svStmt.InitExp = initExps[index]; EnsureNoPostFixStatement(svStmt.InitExp); } index++; newStmts.Add(svStmt); } // We don't need them anymore initExps.Clear(); return newStmts; }
private void EnsureTypeDeclarationsBelongsToThisScope(MultipleVariableDeclarationStatement varDecl, IList stmts) { ISymbolTable namescope = varDecl.Parent.SymbolTable; System.Diagnostics.Debug.Assert( namescope != null ); foreach(SingleVariableDeclarationStatement typeDecl in stmts) { Identifier ident = typeDecl.Identifier; // Most simple of cases: duplicated declaration if (namescope.IsDefined(ident.Name)) { errorReport.Error( "TODOFILENAME", typeDecl.Position, "Sorry but '{0}' is already defined.", ident.Name ); continue; } ApplyDeclarationRules(ident, namescope, typeDecl, varDecl); } }
private void ReplaceOriginalMultipleVariableDeclarationStatement(MultipleVariableDeclarationStatement decl, IList stmts) { int index; // Replace the VariableDeclarationStatement node by a // (possible) sequence of SingleVariableDeclarationStatement IStatementContainer stmtContainer = decl.Parent as IStatementContainer; index = stmtContainer.Statements.IndexOf(decl); stmtContainer.Statements.RemoveAt(index); foreach(SingleVariableDeclarationStatement svDecl in stmts) { stmtContainer.Statements.Insert( index++, svDecl ); } }
private void ProcessMultipleVariableDeclarationStatement(MultipleVariableDeclarationStatement decl) { IList stmts = ConvertToSingleDeclarationStatements(decl); ReplaceOriginalMultipleVariableDeclarationStatement(decl, stmts); EnsureTypeDeclarationsBelongsToThisScope(decl, stmts); }
public override bool VisitMultipleVariableDeclarationStatement(MultipleVariableDeclarationStatement varDecl) { ProcessMultipleVariableDeclarationStatement(varDecl); return base.VisitMultipleVariableDeclarationStatement(varDecl); }
public MultipleVariableDeclarationStatement declaration_statement() //throws RecognitionException, TokenStreamException { MultipleVariableDeclarationStatement stmt; stmt = new MultipleVariableDeclarationStatement(currentAccessLevel); Identifier ident = null; IExpression initExp = null; ident=identifier_withtype(); if (0==inputState.guessing) { stmt.AddIdentifier(ident); } { // ( ... )* for (;;) { if ((LA(1)==COMMA)) { match(COMMA); ident=identifier_withtype(); if (0==inputState.guessing) { stmt.AddIdentifier(ident); } } else { goto _loop42_breakloop; } } _loop42_breakloop: ; } // ( ... )* { switch ( LA(1) ) { case ASSIGN: { match(ASSIGN); initExp=test(); if (0==inputState.guessing) { stmt.AddInitExp(initExp); } { // ( ... )* for (;;) { if ((LA(1)==COMMA)) { match(COMMA); initExp=test(); if (0==inputState.guessing) { stmt.AddInitExp(initExp); } } else { goto _loop45_breakloop; } } _loop45_breakloop: ; } // ( ... )* break; } case EOF: case STATEMENT_END: case SEMI: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } return stmt; }