[cfe-commits] r38995 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp Parse/ParseExpr.cpp Parse/ParseInit.cpp Parse/ParseStmt.cpp Parse/Parser.cpp include/clang/Parse/Parser.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:26:38 PDT 2007


Author: sabre
Date: Wed Jul 11 11:26:38 2007
New Revision: 38995

URL: http://llvm.org/viewvc/llvm-project?rev=38995&view=rev
Log:
Make ConsumeFoo methods return the location of the consumed token.

Modified:
    cfe/cfe/trunk/Parse/ParseDecl.cpp
    cfe/cfe/trunk/Parse/ParseExpr.cpp
    cfe/cfe/trunk/Parse/ParseInit.cpp
    cfe/cfe/trunk/Parse/ParseStmt.cpp
    cfe/cfe/trunk/Parse/Parser.cpp
    cfe/cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=38995&r1=38994&r2=38995&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:26:38 2007
@@ -448,8 +448,7 @@
     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 @@
     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 @@
 ///         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 @@
 /// [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;

Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=38995&r1=38994&r2=38995&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:26:38 2007
@@ -582,8 +582,7 @@
     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 @@
       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 @@
     return ExprResult(true);
   }
   
-  SourceLocation LParenLoc = Tok.getLocation();
-  ConsumeParen();
+  SourceLocation LParenLoc = ConsumeParen();
   // TODO: Build AST.
 
   switch (T) {
@@ -769,8 +766,7 @@
           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 @@
                                                 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 @@
     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 @@
   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;

Modified: cfe/cfe/trunk/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseInit.cpp?rev=38995&r1=38994&r2=38995&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseInit.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseInit.cpp Wed Jul 11 11:26:38 2007
@@ -86,8 +86,7 @@
     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 @@
   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.

Modified: cfe/cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseStmt.cpp?rev=38995&r1=38994&r2=38995&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseStmt.cpp Wed Jul 11 11:26:38 2007
@@ -362,8 +362,7 @@
 ///
 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 @@
     return 0;
   }
 
-  SourceLocation RBraceLoc = Tok.getLocation();
-  ConsumeBrace();
+  SourceLocation RBraceLoc = ConsumeBrace();
   return Actions.ParseCompoundStmt(LBraceLoc, RBraceLoc,
                                    &Stmts[0], Stmts.size());
 }
@@ -519,8 +517,7 @@
     return true;
   }
 
-  SourceLocation LParenLoc = Tok.getLocation();
-  ConsumeParen();
+  SourceLocation LParenLoc = ConsumeParen();
   
   ExprResult Value;
   
@@ -661,8 +658,7 @@
     SkipUntil(tok::r_paren);
     return true;
   }
-  Loc = Tok.getLocation();
-  ConsumeParen();
+  Loc = ConsumeParen();
   
   ParseAsmStringLiteral();
   
@@ -717,8 +713,7 @@
   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);

Modified: cfe/cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Parser.cpp?rev=38995&r1=38994&r2=38995&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:26:38 2007
@@ -437,8 +437,7 @@
     return;
   }
   
-  SourceLocation Loc = Tok.getLocation();
-  ConsumeParen();
+  SourceLocation Loc = ConsumeParen();
   
   ParseAsmStringLiteral();
   

Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=38995&r1=38994&r2=38995&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:26:38 2007
@@ -124,37 +124,43 @@
   
   /// 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 @@
   /// 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. '['/']'),





More information about the cfe-commits mailing list