[cfe-commits] r60117 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/ParseExprCXX.cpp lib/Parse/Parser.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Wed Nov 26 13:41:53 PST 2008
Author: akirtzidis
Date: Wed Nov 26 15:41:52 2008
New Revision: 60117
URL: http://llvm.org/viewvc/llvm-project?rev=60117&view=rev
Log:
Implement some suggestions by Daniel:
-Change Parser::ParseCXXScopeSpecifier to MaybeParseCXXScopeSpecifier
-Remove Parser::isTokenCXXScopeSpecifier and fold it into MaybeParseCXXScopeSpecifier
-Rename Parser::TryAnnotateScopeToken to TryAnnotateCXXScopeToken and only allow it to be called when in C++
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/Parser.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=60117&r1=60116&r2=60117&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Nov 26 15:41:52 2008
@@ -118,17 +118,6 @@
Tok.getKind() == tok::wide_string_literal;
}
- /// isTokenCXXScopeSpecifier - True if this token is '::', or identifier with
- /// '::' as next token, or a 'C++ scope annotation' token.
- /// When not in C++, always returns false.
- ///
- bool isTokenCXXScopeSpecifier() {
- return getLang().CPlusPlus &&
- (Tok.is(tok::coloncolon) ||
- Tok.is(tok::annot_cxxscope) ||
- (Tok.is(tok::identifier) && NextToken().is(tok::coloncolon)));
- }
-
/// ConsumeToken - Consume the current 'peek token' and lex the next one.
/// This does not work with all kinds of tokens: strings and specific other
/// tokens must be consumed with custom methods below. This returns the
@@ -239,9 +228,9 @@
/// typenames.
void TryAnnotateTypeOrScopeToken();
- /// TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only
+ /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
/// annotates C++ scope specifiers.
- void TryAnnotateScopeToken();
+ void TryAnnotateCXXScopeToken();
/// TentativeParsingAction - An object that is used as a kind of "tentative
/// parsing transaction". It gets instantiated to mark the token position and
@@ -476,7 +465,10 @@
//===--------------------------------------------------------------------===//
// C++ Expressions
ExprResult ParseCXXIdExpression();
- void ParseCXXScopeSpecifier(CXXScopeSpec &SS);
+
+ /// MaybeParseCXXScopeSpecifier - Parse global scope or nested-name-specifier.
+ /// Returns true if a nested-name-specifier was parsed from the token stream.
+ bool MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS);
//===--------------------------------------------------------------------===//
// C++ 5.2p1: C++ Casts
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=60117&r1=60116&r2=60117&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Nov 26 15:41:52 2008
@@ -427,7 +427,7 @@
// Only annotate C++ scope. Allow class-name as an identifier in case
// it's a constructor.
if (getLang().CPlusPlus)
- TryAnnotateScopeToken();
+ TryAnnotateCXXScopeToken();
switch (Tok.getKind()) {
default:
@@ -985,8 +985,7 @@
Attr = ParseAttributes();
CXXScopeSpec SS;
- if (isTokenCXXScopeSpecifier()) {
- ParseCXXScopeSpecifier(SS);
+ if (getLang().CPlusPlus && MaybeParseCXXScopeSpecifier(SS)) {
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident);
if (Tok.isNot(tok::l_brace)) {
@@ -1435,8 +1434,8 @@
CXXScopeSpec &SS = D.getCXXScopeSpec();
DeclaratorScopeObj DeclScopeObj(*this, SS);
- if (D.mayHaveIdentifier() && isTokenCXXScopeSpecifier()) {
- ParseCXXScopeSpecifier(SS);
+ if (D.mayHaveIdentifier() &&
+ getLang().CPlusPlus && MaybeParseCXXScopeSpecifier(SS)) {
// Change the declaration context for name lookup, until this function is
// exited (and the declarator has been parsed).
DeclScopeObj.EnterDeclaratorScope();
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=60117&r1=60116&r2=60117&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Nov 26 15:41:52 2008
@@ -218,8 +218,7 @@
// Parse the (optional) nested-name-specifier.
CXXScopeSpec SS;
- if (isTokenCXXScopeSpecifier()) {
- ParseCXXScopeSpecifier(SS);
+ if (getLang().CPlusPlus && MaybeParseCXXScopeSpecifier(SS)) {
if (Tok.isNot(tok::identifier))
Diag(Tok, diag::err_expected_ident);
}
@@ -362,8 +361,7 @@
// Parse optional '::' and optional nested-name-specifier.
CXXScopeSpec SS;
- if (isTokenCXXScopeSpecifier())
- ParseCXXScopeSpecifier(SS);
+ MaybeParseCXXScopeSpecifier(SS);
// The location of the base class itself.
SourceLocation BaseLoc = Tok.getLocation();
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=60117&r1=60116&r2=60117&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Wed Nov 26 15:41:52 2008
@@ -17,7 +17,8 @@
#include "AstGuard.h"
using namespace clang;
-/// ParseCXXScopeSpecifier - Parse global scope or nested-name-specifier.
+/// MaybeParseCXXScopeSpecifier - Parse global scope or nested-name-specifier.
+/// Returns true if a nested-name-specifier was parsed from the token stream.
///
/// '::'[opt] nested-name-specifier
/// '::'
@@ -28,14 +29,20 @@
/// nested-name-specifier identifier '::'
/// nested-name-specifier 'template'[opt] simple-template-id '::' [TODO]
///
-void Parser::ParseCXXScopeSpecifier(CXXScopeSpec &SS) {
- assert(isTokenCXXScopeSpecifier() && "Not scope specifier!");
+bool Parser::MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS) {
+ assert(getLang().CPlusPlus &&
+ "Call sites of this function should be guarded by checking for C++.");
+
+ if (Tok.isNot(tok::coloncolon) &&
+ Tok.isNot(tok::annot_cxxscope) &&
+ (Tok.isNot(tok::identifier) || NextToken().isNot(tok::coloncolon)))
+ return false;
if (Tok.is(tok::annot_cxxscope)) {
SS.setScopeRep(Tok.getAnnotationValue());
SS.setRange(Tok.getAnnotationRange());
ConsumeToken();
- return;
+ return true;
}
SS.setBeginLoc(Tok.getLocation());
@@ -68,6 +75,8 @@
Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, *II) );
SS.setEndLoc(CCLoc);
}
+
+ return true;
}
/// ParseCXXIdExpression - Handle id-expression.
@@ -126,8 +135,7 @@
// '::' unqualified-id
//
CXXScopeSpec SS;
- if (isTokenCXXScopeSpecifier())
- ParseCXXScopeSpecifier(SS);
+ MaybeParseCXXScopeSpecifier(SS);
// unqualified-id:
// identifier
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=60117&r1=60116&r2=60117&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Wed Nov 26 15:41:52 2008
@@ -705,8 +705,8 @@
return;
CXXScopeSpec SS;
- if (isTokenCXXScopeSpecifier())
- ParseCXXScopeSpecifier(SS);
+ if (getLang().CPlusPlus)
+ MaybeParseCXXScopeSpecifier(SS);
if (Tok.is(tok::identifier)) {
TypeTy *Ty = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope, &SS);
@@ -746,13 +746,15 @@
/// TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only
/// annotates C++ scope specifiers.
-void Parser::TryAnnotateScopeToken() {
+void Parser::TryAnnotateCXXScopeToken() {
+ assert(getLang().CPlusPlus &&
+ "Call sites of this function should be guarded by checking for C++.");
+
if (Tok.is(tok::annot_cxxscope))
return;
- if (isTokenCXXScopeSpecifier()) {
- CXXScopeSpec SS;
- ParseCXXScopeSpecifier(SS);
+ CXXScopeSpec SS;
+ if (MaybeParseCXXScopeSpecifier(SS)) {
// Push the current token back into the token stream (or revert it if it is
// cached) and use an annotation scope token for current token.
More information about the cfe-commits
mailing list