diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-10-16 06:06:51 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-10-16 06:06:51 +0000 |
| commit | af63531ac3be8d1e3ef96c879aadec182b4d6451 (patch) | |
| tree | 67ff1ea159bd12ce892896b57af79fac4f2f0cb7 | |
| parent | 30f910e88e5c28955bbd91b8d9a306a5d5ef2356 (diff) | |
| download | bcm5719-llvm-af63531ac3be8d1e3ef96c879aadec182b4d6451.tar.gz bcm5719-llvm-af63531ac3be8d1e3ef96c879aadec182b4d6451.zip | |
Make ConsumeToken return the loc of the consumed token to simplify clients
llvm-svn: 38994
| -rw-r--r-- | clang/Parse/ParseDecl.cpp | 24 | ||||
| -rw-r--r-- | clang/Parse/ParseExpr.cpp | 13 | ||||
| -rw-r--r-- | clang/Parse/ParseStmt.cpp | 44 | ||||
| -rw-r--r-- | clang/include/clang/Parse/Parser.h | 7 |
4 files changed, 33 insertions, 55 deletions
diff --git a/clang/Parse/ParseDecl.cpp b/clang/Parse/ParseDecl.cpp index b0ea7d0be8d..87cd4d4d7c3 100644 --- a/clang/Parse/ParseDecl.cpp +++ b/clang/Parse/ParseDecl.cpp @@ -430,9 +430,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { void Parser::ParseStructUnionSpecifier(DeclSpec &DS) { assert((Tok.getKind() == tok::kw_struct || Tok.getKind() == tok::kw_union) && "Not a struct/union specifier"); - SourceLocation Start = Tok.getLocation(); bool isUnion = Tok.getKind() == tok::kw_union; - ConsumeToken(); + SourceLocation Start = ConsumeToken(); // If attributes exist after tag, parse them. if (Tok.getKind() == tok::kw___attribute) @@ -554,8 +553,7 @@ void Parser::ParseStructUnionSpecifier(DeclSpec &DS) { /// void Parser::ParseEnumSpecifier(DeclSpec &DS) { assert(Tok.getKind() == tok::kw_enum && "Not an enum specifier"); - SourceLocation Start = Tok.getLocation(); - ConsumeToken(); + SourceLocation Start = ConsumeToken(); if (Tok.getKind() == tok::kw___attribute) ParseAttributes(); @@ -589,8 +587,7 @@ void Parser::ParseEnumSpecifier(DeclSpec &DS) { if (Tok.getKind() != tok::comma) break; - SourceLocation CommaLoc = Tok.getLocation(); - ConsumeToken(); + SourceLocation CommaLoc = ConsumeToken(); if (Tok.getKind() != tok::identifier && !getLang().C99) Diag(CommaLoc, diag::ext_c99_enumerator_list_comma); @@ -780,8 +777,7 @@ void Parser::ParseDeclaratorInternal(Declarator &D) { return ParseDirectDeclarator(D); // Otherwise, '*' -> pointer. - SourceLocation Loc = Tok.getLocation(); - ConsumeToken(); // Eat the *. + SourceLocation Loc = ConsumeToken(); // Eat the *. DeclSpec DS; ParseTypeQualifierListOpt(DS); @@ -1038,10 +1034,8 @@ void Parser::ParseBracketDeclarator(Declarator &D) { // If valid, this location is the position where we read the 'static' keyword. SourceLocation StaticLoc; - if (Tok.getKind() == tok::kw_static) { - StaticLoc = Tok.getLocation(); - ConsumeToken(); - } + if (Tok.getKind() == tok::kw_static) + StaticLoc = ConsumeToken(); // If there is a type-qualifier-list, read it now. DeclSpec DS; @@ -1049,10 +1043,8 @@ void Parser::ParseBracketDeclarator(Declarator &D) { // If we haven't already read 'static', check to see if there is one after the // type-qualifier-list. - if (!StaticLoc.isValid() && Tok.getKind() == tok::kw_static) { - StaticLoc = Tok.getLocation(); - ConsumeToken(); - } + if (!StaticLoc.isValid() && Tok.getKind() == tok::kw_static) + StaticLoc = ConsumeToken(); // Handle "direct-declarator [ type-qual-list[opt] * ]". bool isStar = false; diff --git a/clang/Parse/ParseExpr.cpp b/clang/Parse/ParseExpr.cpp index cd4e948ba57..77edcf9dc04 100644 --- a/clang/Parse/ParseExpr.cpp +++ b/clang/Parse/ParseExpr.cpp @@ -329,8 +329,7 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec) { } // Eat the colon. - ColonLoc = Tok.getLocation(); - ConsumeToken(); + ColonLoc = ConsumeToken(); } // Parse another leaf here for the RHS of the operator. @@ -617,8 +616,8 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { if (Tok.getKind() != tok::comma) break; - CommaLocs.push_back(Tok.getLocation()); - ConsumeToken(); // Next argument. + // Move to the next argument, remember where the comma was. + CommaLocs.push_back(ConsumeToken()); } } @@ -635,9 +634,8 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { } case tok::arrow: // postfix-expression: p-e '->' identifier case tok::period: { // postfix-expression: p-e '.' identifier - SourceLocation OpLoc = Tok.getLocation(); tok::TokenKind OpKind = Tok.getKind(); - ConsumeToken(); // Eat the "." or "->" token. + SourceLocation OpLoc = ConsumeToken(); // Eat the "." or "->" token. if (Tok.getKind() != tok::identifier) { Diag(Tok, diag::err_expected_ident); @@ -720,11 +718,10 @@ Parser::ExprResult Parser::ParseSizeofAlignofExpression() { /// Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { ExprResult Res(false); - SourceLocation StartLoc = Tok.getLocation(); const IdentifierInfo *BuiltinII = Tok.getIdentifierInfo(); tok::TokenKind T = Tok.getKind(); - ConsumeToken(); // Eat the builtin identifier. + SourceLocation StartLoc = ConsumeToken(); // Eat the builtin identifier. // All of these start with an open paren. if (Tok.getKind() != tok::l_paren) { diff --git a/clang/Parse/ParseStmt.cpp b/clang/Parse/ParseStmt.cpp index a7cc67fe189..83f44881699 100644 --- a/clang/Parse/ParseStmt.cpp +++ b/clang/Parse/ParseStmt.cpp @@ -187,8 +187,7 @@ Parser::StmtResult Parser::ParseIdentifierStatement(bool OnlyStatement) { // identifier ':' statement if (Tok.getKind() == tok::colon) { - SourceLocation ColonLoc = Tok.getLocation(); - ConsumeToken(); + SourceLocation ColonLoc = ConsumeToken(); // Read label attributes, if present. if (Tok.getKind() == tok::kw___attribute) @@ -256,8 +255,7 @@ Parser::StmtResult Parser::ParseIdentifierStatement(bool OnlyStatement) { /// Parser::StmtResult Parser::ParseCaseStatement() { assert(Tok.getKind() == tok::kw_case && "Not a case stmt!"); - SourceLocation CaseLoc = Tok.getLocation(); - ConsumeToken(); // eat the 'case'. + SourceLocation CaseLoc = ConsumeToken(); // eat the 'case'. ExprResult LHS = ParseConstantExpression(); if (LHS.isInvalid) { @@ -270,7 +268,7 @@ Parser::StmtResult Parser::ParseCaseStatement() { ExprTy *RHSVal = 0; if (Tok.getKind() == tok::ellipsis) { Diag(Tok, diag::ext_gnu_case_range); - ConsumeToken(); + DotDotDotLoc = ConsumeToken(); ExprResult RHS = ParseConstantExpression(); if (RHS.isInvalid) { @@ -286,8 +284,7 @@ Parser::StmtResult Parser::ParseCaseStatement() { return true; } - SourceLocation ColonLoc = Tok.getLocation(); - ConsumeToken(); + SourceLocation ColonLoc = ConsumeToken(); // Diagnose the common error "switch (X) { case 4: }", which is not valid. if (Tok.getKind() == tok::r_brace) { @@ -311,8 +308,7 @@ Parser::StmtResult Parser::ParseCaseStatement() { /// Parser::StmtResult Parser::ParseDefaultStatement() { assert(Tok.getKind() == tok::kw_default && "Not a default stmt!"); - SourceLocation DefaultLoc = Tok.getLocation(); - ConsumeToken(); // eat the 'default'. + SourceLocation DefaultLoc = ConsumeToken(); // eat the 'default'. if (Tok.getKind() != tok::colon) { Diag(Tok, diag::err_expected_colon_after, "'default'"); @@ -320,8 +316,7 @@ Parser::StmtResult Parser::ParseDefaultStatement() { return true; } - SourceLocation ColonLoc = Tok.getLocation(); - ConsumeToken(); + SourceLocation ColonLoc = ConsumeToken(); // Diagnose the common error "switch (X) {... default: }", which is not valid. if (Tok.getKind() == tok::r_brace) { @@ -396,8 +391,7 @@ Parser::StmtResult Parser::ParseCompoundStatement() { /// Parser::StmtResult Parser::ParseIfStatement() { assert(Tok.getKind() == tok::kw_if && "Not an if stmt!"); - SourceLocation IfLoc = Tok.getLocation(); - ConsumeToken(); // eat the 'if'. + SourceLocation IfLoc = ConsumeToken(); // eat the 'if'. if (Tok.getKind() != tok::l_paren) { Diag(Tok, diag::err_expected_lparen_after, "if"); @@ -419,8 +413,7 @@ Parser::StmtResult Parser::ParseIfStatement() { SourceLocation ElseLoc; StmtResult ElseStmt(false); if (Tok.getKind() == tok::kw_else) { - ElseLoc = Tok.getLocation(); - ConsumeToken(); + ElseLoc = ConsumeToken(); ElseStmt = ParseStatement(); } @@ -436,8 +429,7 @@ Parser::StmtResult Parser::ParseIfStatement() { /// 'switch' '(' expression ')' statement Parser::StmtResult Parser::ParseSwitchStatement() { assert(Tok.getKind() == tok::kw_switch && "Not a switch stmt!"); - SourceLocation SwitchLoc = Tok.getLocation(); - ConsumeToken(); // eat the 'switch'. + SourceLocation SwitchLoc = ConsumeToken(); // eat the 'switch'. if (Tok.getKind() != tok::l_paren) { Diag(Tok, diag::err_expected_lparen_after, "switch"); @@ -487,8 +479,7 @@ Parser::StmtResult Parser::ParseWhileStatement() { /// Note: this lets the caller parse the end ';'. Parser::StmtResult Parser::ParseDoStatement() { assert(Tok.getKind() == tok::kw_do && "Not a do stmt!"); - SourceLocation DoLoc = Tok.getLocation(); - ConsumeToken(); // eat the 'do'. + SourceLocation DoLoc = ConsumeToken(); // eat the 'do'. // Read the body statement. StmtResult Body = ParseStatement(); @@ -499,8 +490,7 @@ Parser::StmtResult Parser::ParseDoStatement() { SkipUntil(tok::semi); return true; } - SourceLocation WhileLoc = Tok.getLocation(); - ConsumeToken(); + SourceLocation WhileLoc = ConsumeToken(); if (Tok.getKind() != tok::l_paren) { Diag(Tok, diag::err_expected_lparen_after, "do/while"); @@ -521,8 +511,7 @@ Parser::StmtResult Parser::ParseDoStatement() { /// 'for' '(' declaration expr[opt] ';' expr[opt] ')' statement Parser::StmtResult Parser::ParseForStatement() { assert(Tok.getKind() == tok::kw_for && "Not a for stmt!"); - SourceLocation ForLoc = Tok.getLocation(); - ConsumeToken(); // eat the 'for'. + SourceLocation ForLoc = ConsumeToken(); // eat the 'for'. if (Tok.getKind() != tok::l_paren) { Diag(Tok, diag::err_expected_lparen_after, "for"); @@ -597,8 +586,7 @@ Parser::StmtResult Parser::ParseForStatement() { /// Parser::StmtResult Parser::ParseGotoStatement() { assert(Tok.getKind() == tok::kw_goto && "Not a goto stmt!"); - SourceLocation GotoLoc; - ConsumeToken(); // eat the 'goto'. + SourceLocation GotoLoc = ConsumeToken(); // eat the 'goto'. StmtResult Res; if (Tok.getKind() == tok::identifier) { @@ -607,8 +595,7 @@ Parser::StmtResult Parser::ParseGotoStatement() { } else if (Tok.getKind() == tok::star && !getLang().NoExtensions) { // GNU indirect goto extension. Diag(Tok, diag::ext_gnu_indirect_goto); - SourceLocation StarLoc = Tok.getLocation(); - ConsumeToken(); + SourceLocation StarLoc = ConsumeToken(); ExprResult R = ParseExpression(); if (R.isInvalid) { // Skip to the semicolon, but don't consume it. SkipUntil(tok::semi, false, true); @@ -624,8 +611,7 @@ Parser::StmtResult Parser::ParseGotoStatement() { /// 'return' expression[opt] ';' Parser::StmtResult Parser::ParseReturnStatement() { assert(Tok.getKind() == tok::kw_return && "Not a return stmt!"); - SourceLocation ReturnLoc = Tok.getLocation(); - ConsumeToken(); // eat the 'return'. + SourceLocation ReturnLoc = ConsumeToken(); // eat the 'return'. ExprResult R(0); if (Tok.getKind() != tok::semi) { diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index c5f8f8c4042..315f619697b 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -97,12 +97,15 @@ private: /// ConsumeToken - Consume the current 'peek token' and lex the next one. /// This does not work will all kinds of tokens: strings and specific other - /// tokens must be consumed with custom methods below. - void ConsumeToken() { + /// tokens must be consumed with custom methods below. This returns the + /// location of the consumed token. + SourceLocation ConsumeToken() { assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && !isTokenBrace() && "Should consume special tokens with Consume*Token"); + SourceLocation L = Tok.getLocation(); PP.Lex(Tok); + return L; } /// ConsumeAnyToken - Dispatch to the right Consume* method based on the |

