diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/Parse/ParseDecl.cpp | 12 | ||||
| -rw-r--r-- | clang/Parse/ParseExpr.cpp | 31 | ||||
| -rw-r--r-- | clang/Parse/ParseInit.cpp | 6 | ||||
| -rw-r--r-- | clang/Parse/ParseStmt.cpp | 15 | ||||
| -rw-r--r-- | clang/Parse/Parser.cpp | 3 | ||||
| -rw-r--r-- | clang/include/clang/Parse/Parser.h | 16 |
6 files changed, 35 insertions, 48 deletions
diff --git a/clang/Parse/ParseDecl.cpp b/clang/Parse/ParseDecl.cpp index 87cd4d4d7c3..13b67cbe7bb 100644 --- a/clang/Parse/ParseDecl.cpp +++ b/clang/Parse/ParseDecl.cpp @@ -448,8 +448,7 @@ void Parser::ParseStructUnionSpecifier(DeclSpec &DS) { ConsumeToken(); if (Tok.getKind() == tok::l_brace) { - SourceLocation LBraceLoc = Tok.getLocation(); - ConsumeBrace(); + SourceLocation LBraceLoc = ConsumeBrace(); if (Tok.getKind() == tok::r_brace) Diag(Tok, diag::ext_empty_struct_union_enum, isUnion ? "union":"struct"); @@ -569,8 +568,7 @@ void Parser::ParseEnumSpecifier(DeclSpec &DS) { ConsumeToken(); if (Tok.getKind() == tok::l_brace) { - SourceLocation LBraceLoc = Tok.getLocation(); - ConsumeBrace(); + SourceLocation LBraceLoc = ConsumeBrace(); if (Tok.getKind() == tok::r_brace) Diag(Tok, diag::ext_empty_struct_union_enum, "enum"); @@ -864,8 +862,7 @@ void Parser::ParseDirectDeclarator(Declarator &D) { /// identifier-list ',' identifier /// void Parser::ParseParenDeclarator(Declarator &D) { - SourceLocation StartLoc = Tok.getLocation(); - ConsumeParen(); + SourceLocation StartLoc = ConsumeParen(); // If we haven't past the identifier yet (or where the identifier would be // stored, if this is an abstract declarator), then this is probably just @@ -1029,8 +1026,7 @@ void Parser::ParseParenDeclarator(Declarator &D) { /// [C99] direct-declarator '[' type-qual-list 'static' assignment-expr ']' /// [C99] direct-declarator '[' type-qual-list[opt] '*' ']' void Parser::ParseBracketDeclarator(Declarator &D) { - SourceLocation StartLoc = Tok.getLocation(); - ConsumeBracket(); + SourceLocation StartLoc = ConsumeBracket(); // If valid, this location is the position where we read the 'static' keyword. SourceLocation StaticLoc; diff --git a/clang/Parse/ParseExpr.cpp b/clang/Parse/ParseExpr.cpp index 77edcf9dc04..f11f04e97e3 100644 --- a/clang/Parse/ParseExpr.cpp +++ b/clang/Parse/ParseExpr.cpp @@ -582,8 +582,7 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { default: // Not a postfix-expression suffix. return LHS; case tok::l_square: { // postfix-expression: p-e '[' expression ']' - Loc = Tok.getLocation(); - ConsumeBracket(); + Loc = ConsumeBracket(); ExprResult Idx = ParseExpression(); SourceLocation RLoc = Tok.getLocation(); @@ -603,8 +602,7 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { SmallVector<SourceLocation, 8> CommaLocs; bool ArgExprsOk = true; - Loc = Tok.getLocation(); - ConsumeParen(); + Loc = ConsumeParen(); if (Tok.getKind() != tok::r_paren) { while (1) { @@ -729,8 +727,7 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { return ExprResult(true); } - SourceLocation LParenLoc = Tok.getLocation(); - ConsumeParen(); + SourceLocation LParenLoc = ConsumeParen(); // TODO: Build AST. switch (T) { @@ -769,8 +766,7 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { return ExprResult(true); } else if (Tok.getKind() == tok::l_square) { // offsetof-member-designator: offsetof-member-design '[' expression ']' - SourceLocation LSquareLoc = Tok.getLocation(); - ConsumeBracket(); + SourceLocation LSquareLoc = ConsumeBracket(); Res = ParseExpression(); if (Res.isInvalid) { SkipUntil(tok::r_paren); @@ -831,8 +827,7 @@ Parser::ExprResult Parser::ParseParenExpression(ParenParseOption &ExprType, TypeTy *&CastTy, SourceLocation &RParenLoc) { assert(Tok.getKind() == tok::l_paren && "Not a paren expr!"); - SourceLocation OpenLoc = Tok.getLocation(); - ConsumeParen(); + SourceLocation OpenLoc = ConsumeParen(); ExprResult Result(false); CastTy = 0; @@ -847,12 +842,10 @@ Parser::ExprResult Parser::ParseParenExpression(ParenParseOption &ExprType, TypeTy *Ty = ParseTypeName(); // Match the ')'. - if (Tok.getKind() == tok::r_paren) { - RParenLoc = Tok.getLocation(); - ConsumeParen(); - } else { + if (Tok.getKind() == tok::r_paren) + RParenLoc = ConsumeParen(); + else MatchRHSPunctuation(tok::r_paren, OpenLoc); - } if (Tok.getKind() == tok::l_brace) { if (!getLang().C99) // Compound literals don't exist in C90. @@ -882,12 +875,10 @@ Parser::ExprResult Parser::ParseParenExpression(ParenParseOption &ExprType, if (Result.isInvalid) SkipUntil(tok::r_paren); else { - if (Tok.getKind() == tok::r_paren) { - RParenLoc = Tok.getLocation(); - ConsumeParen(); - } else { + if (Tok.getKind() == tok::r_paren) + RParenLoc = ConsumeParen(); + else MatchRHSPunctuation(tok::r_paren, OpenLoc); - } } return Result; diff --git a/clang/Parse/ParseInit.cpp b/clang/Parse/ParseInit.cpp index 924d0a85bc6..fb0b9766194 100644 --- a/clang/Parse/ParseInit.cpp +++ b/clang/Parse/ParseInit.cpp @@ -86,8 +86,7 @@ Parser::ExprResult Parser::ParseInitializerWithPotentialDesignator() { case tok::l_square: { // array-designator: '[' constant-expression ']' // array-designator: '[' constant-expression '...' constant-expression ']' - SourceLocation StartLoc = Tok.getLocation(); - ConsumeBracket(); + SourceLocation StartLoc = ConsumeBracket(); ExprResult Idx = ParseConstantExpression(); if (Idx.isInvalid) { @@ -150,8 +149,7 @@ Parser::ExprResult Parser::ParseInitializer() { if (Tok.getKind() != tok::l_brace) return ParseAssignmentExpression(); - SourceLocation LBraceLoc = Tok.getLocation(); - ConsumeBrace(); + SourceLocation LBraceLoc = ConsumeBrace(); // We support empty initializers, but tell the user that they aren't using // C99-clean code. diff --git a/clang/Parse/ParseStmt.cpp b/clang/Parse/ParseStmt.cpp index 83f44881699..5e1feacc818 100644 --- a/clang/Parse/ParseStmt.cpp +++ b/clang/Parse/ParseStmt.cpp @@ -362,8 +362,7 @@ Parser::StmtResult Parser::ParseDefaultStatement() { /// Parser::StmtResult Parser::ParseCompoundStatement() { assert(Tok.getKind() == tok::l_brace && "Not a compount stmt!"); - SourceLocation LBraceLoc = Tok.getLocation(); - ConsumeBrace(); // eat the '{'. + SourceLocation LBraceLoc = ConsumeBrace(); // eat the '{'. SmallVector<StmtTy*, 32> Stmts; while (Tok.getKind() != tok::r_brace && Tok.getKind() != tok::eof) { @@ -378,8 +377,7 @@ Parser::StmtResult Parser::ParseCompoundStatement() { return 0; } - SourceLocation RBraceLoc = Tok.getLocation(); - ConsumeBrace(); + SourceLocation RBraceLoc = ConsumeBrace(); return Actions.ParseCompoundStmt(LBraceLoc, RBraceLoc, &Stmts[0], Stmts.size()); } @@ -519,8 +517,7 @@ Parser::StmtResult Parser::ParseForStatement() { return true; } - SourceLocation LParenLoc = Tok.getLocation(); - ConsumeParen(); + SourceLocation LParenLoc = ConsumeParen(); ExprResult Value; @@ -661,8 +658,7 @@ Parser::StmtResult Parser::ParseAsmStatement() { SkipUntil(tok::r_paren); return true; } - Loc = Tok.getLocation(); - ConsumeParen(); + Loc = ConsumeParen(); ParseAsmStringLiteral(); @@ -717,8 +713,7 @@ void Parser::ParseAsmOperandsOpt() { while (1) { // Read the [id] if present. if (Tok.getKind() == tok::l_square) { - SourceLocation Loc = Tok.getLocation(); - ConsumeBracket(); + SourceLocation Loc = ConsumeBracket(); if (Tok.getKind() != tok::identifier) { Diag(Tok, diag::err_expected_ident); diff --git a/clang/Parse/Parser.cpp b/clang/Parse/Parser.cpp index a7fd2f39f4f..b51316f890d 100644 --- a/clang/Parse/Parser.cpp +++ b/clang/Parse/Parser.cpp @@ -437,8 +437,7 @@ void Parser::ParseSimpleAsm() { return; } - SourceLocation Loc = Tok.getLocation(); - ConsumeParen(); + SourceLocation Loc = ConsumeParen(); ParseAsmStringLiteral(); diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 315f619697b..354d0164403 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -124,37 +124,43 @@ private: /// ConsumeParen - This consume method keeps the paren count up-to-date. /// - void ConsumeParen() { + SourceLocation ConsumeParen() { assert(isTokenParen() && "wrong consume method"); if (Tok.getKind() == tok::l_paren) ++ParenCount; else if (ParenCount) --ParenCount; // Don't let unbalanced )'s drive the count negative. + SourceLocation L = Tok.getLocation(); PP.Lex(Tok); + return L; } /// ConsumeBracket - This consume method keeps the bracket count up-to-date. /// - void ConsumeBracket() { + SourceLocation ConsumeBracket() { assert(isTokenBracket() && "wrong consume method"); if (Tok.getKind() == tok::l_square) ++BracketCount; else if (BracketCount) --BracketCount; // Don't let unbalanced ]'s drive the count negative. + SourceLocation L = Tok.getLocation(); PP.Lex(Tok); + return L; } /// ConsumeBrace - This consume method keeps the brace count up-to-date. /// - void ConsumeBrace() { + SourceLocation ConsumeBrace() { assert(isTokenBrace() && "wrong consume method"); if (Tok.getKind() == tok::l_brace) ++BraceCount; else if (BraceCount) --BraceCount; // Don't let unbalanced }'s drive the count negative. + SourceLocation L = Tok.getLocation(); PP.Lex(Tok); + return L; } @@ -162,10 +168,12 @@ private: /// and returning the token kind. This method is specific to strings, as it /// handles string literal concatenation, as per C99 5.1.1.2, translation /// phase #6. - void ConsumeStringToken() { + SourceLocation ConsumeStringToken() { assert(isTokenStringLiteral() && "Should only consume string literals with this method"); + SourceLocation L = Tok.getLocation(); PP.Lex(Tok); + return L; } /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'), |

