[cfe-commits] r61638 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseExpr.cpp lib/Parse/ParseExprCXX.cpp
Chris Lattner
sabre at nondot.org
Sun Jan 4 13:25:24 PST 2009
Author: lattner
Date: Sun Jan 4 15:25:24 2009
New Revision: 61638
URL: http://llvm.org/viewvc/llvm-project?rev=61638&view=rev
Log:
eliminate lookahead when parsing ::new / ::delete.
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=61638&r1=61637&r2=61638&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sun Jan 4 15:25:24 2009
@@ -643,10 +643,11 @@
//===--------------------------------------------------------------------===//
// C++ 5.3.4 and 5.3.5: C++ new and delete
- OwningExprResult ParseCXXNewExpression();
bool ParseExpressionListOrTypeId(ExprListTy &Exprs, Declarator &D);
void ParseDirectNewDeclarator(Declarator &D);
- OwningExprResult ParseCXXDeleteExpression();
+ OwningExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start);
+ OwningExprResult ParseCXXDeleteExpression(bool UseGlobal,
+ SourceLocation Start);
//===--------------------------------------------------------------------===//
// C++ if/switch/while/for condition expression.
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=61638&r1=61637&r2=61638&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Sun Jan 4 15:25:24 2009
@@ -626,19 +626,23 @@
Res = ParseCXXIdExpression();
return ParsePostfixExpressionSuffix(move(Res));
- case tok::coloncolon: // [C++] new-expression or [C++] delete-expression
- // If the next token is neither 'new' nor 'delete', the :: would have been
- // parsed as a scope specifier already.
- if (NextToken().is(tok::kw_new))
- return ParseCXXNewExpression();
- else
- return ParseCXXDeleteExpression();
+ case tok::coloncolon: { // [C++] new-expression or [C++] delete-expression
+ SourceLocation ScopeLoc = ConsumeToken();
+ if (Tok.is(tok::kw_new))
+ return ParseCXXNewExpression(true, ScopeLoc);
+ else {
+ // If the next token is neither 'new' nor 'delete', the :: would have been
+ // parsed as a scope specifier already.
+ assert(Tok.is(tok::kw_delete));
+ return ParseCXXDeleteExpression(true, ScopeLoc);
+ }
+ }
case tok::kw_new: // [C++] new-expression
- return ParseCXXNewExpression();
+ return ParseCXXNewExpression(false, Tok.getLocation());
case tok::kw_delete: // [C++] delete-expression
- return ParseCXXDeleteExpression();
+ return ParseCXXDeleteExpression(false, Tok.getLocation());
case tok::at: {
SourceLocation AtLoc = ConsumeToken();
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=61638&r1=61637&r2=61638&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Sun Jan 4 15:25:24 2009
@@ -639,6 +639,10 @@
/// ParseCXXNewExpression - Parse a C++ new-expression. New is used to allocate
/// memory in a typesafe manner and call constructors.
+///
+/// This method is called to parse the new expression after the optional :: has
+/// been already parsed. If the :: was present, "UseGlobal" is true and "Start"
+/// is its location. Otherwise, "Start" is the location of the 'new' token.
///
/// new-expression:
/// '::'[opt] 'new' new-placement[opt] new-type-id
@@ -660,21 +664,10 @@
/// '(' expression-list[opt] ')'
/// [C++0x] braced-init-list [TODO]
///
-Parser::OwningExprResult Parser::ParseCXXNewExpression()
-{
- assert((Tok.is(tok::coloncolon) || Tok.is(tok::kw_new)) &&
- "Expected :: or 'new' keyword");
-
- SourceLocation Start = Tok.getLocation();
- bool UseGlobal = false;
- if (Tok.is(tok::coloncolon)) {
- UseGlobal = true;
- ConsumeToken();
- }
-
- assert(Tok.is(tok::kw_new) && "Lookahead should have ensured 'new'");
- // Consume 'new'
- ConsumeToken();
+Parser::OwningExprResult
+Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) {
+ assert(Tok.is(tok::kw_new) && "expected 'new' token");
+ ConsumeToken(); // Consume 'new'
// A '(' now can be a new-placement or the '(' wrapping the type-id in the
// second form of new-expression. It can't be a new-type-id.
@@ -768,8 +761,7 @@
/// '[' expression ']'
/// direct-new-declarator '[' constant-expression ']'
///
-void Parser::ParseDirectNewDeclarator(Declarator &D)
-{
+void Parser::ParseDirectNewDeclarator(Declarator &D) {
// Parse the array dimensions.
bool first = true;
while (Tok.is(tok::l_square)) {
@@ -802,8 +794,7 @@
/// '(' expression-list ')'
///
bool Parser::ParseExpressionListOrTypeId(ExprListTy &PlacementArgs,
- Declarator &D)
-{
+ Declarator &D) {
// The '(' was already consumed.
if (isTypeIdInParens()) {
ParseSpecifierQualifierList(D.getMutableDeclSpec());
@@ -820,24 +811,18 @@
/// ParseCXXDeleteExpression - Parse a C++ delete-expression. Delete is used
/// to free memory allocated by new.
///
+/// This method is called to parse the 'delete' expression after the optional
+/// '::' has been already parsed. If the '::' was present, "UseGlobal" is true
+/// and "Start" is its location. Otherwise, "Start" is the location of the
+/// 'delete' token.
+///
/// delete-expression:
/// '::'[opt] 'delete' cast-expression
/// '::'[opt] 'delete' '[' ']' cast-expression
-Parser::OwningExprResult Parser::ParseCXXDeleteExpression()
-{
- assert((Tok.is(tok::coloncolon) || Tok.is(tok::kw_delete)) &&
- "Expected :: or 'delete' keyword");
-
- SourceLocation Start = Tok.getLocation();
- bool UseGlobal = false;
- if (Tok.is(tok::coloncolon)) {
- UseGlobal = true;
- ConsumeToken();
- }
-
- assert(Tok.is(tok::kw_delete) && "Lookahead should have ensured 'delete'");
- // Consume 'delete'
- ConsumeToken();
+Parser::OwningExprResult
+Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) {
+ assert(Tok.is(tok::kw_delete) && "Expected 'delete' keyword");
+ ConsumeToken(); // Consume 'delete'
// Array delete?
bool ArrayDelete = false;
More information about the cfe-commits
mailing list