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++

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60117 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Argyrios Kyrtzidis 2008-11-26 21:41:52 +00:00
Родитель 3bf4a79712
Коммит 4bdd91c09f
5 изменённых файлов: 34 добавлений и 35 удалений

Просмотреть файл

@ -118,17 +118,6 @@ private:
Tok.getKind() == tok::wide_string_literal; 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. /// ConsumeToken - Consume the current 'peek token' and lex the next one.
/// This does not work with all kinds of tokens: strings and specific other /// This does not work with all kinds of tokens: strings and specific other
/// tokens must be consumed with custom methods below. This returns the /// tokens must be consumed with custom methods below. This returns the
@ -239,9 +228,9 @@ private:
/// typenames. /// typenames.
void TryAnnotateTypeOrScopeToken(); void TryAnnotateTypeOrScopeToken();
/// TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
/// annotates C++ scope specifiers. /// annotates C++ scope specifiers.
void TryAnnotateScopeToken(); void TryAnnotateCXXScopeToken();
/// TentativeParsingAction - An object that is used as a kind of "tentative /// TentativeParsingAction - An object that is used as a kind of "tentative
/// parsing transaction". It gets instantiated to mark the token position and /// parsing transaction". It gets instantiated to mark the token position and
@ -476,7 +465,10 @@ private:
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// C++ Expressions // C++ Expressions
ExprResult ParseCXXIdExpression(); 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 // C++ 5.2p1: C++ Casts

Просмотреть файл

@ -427,7 +427,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
// Only annotate C++ scope. Allow class-name as an identifier in case // Only annotate C++ scope. Allow class-name as an identifier in case
// it's a constructor. // it's a constructor.
if (getLang().CPlusPlus) if (getLang().CPlusPlus)
TryAnnotateScopeToken(); TryAnnotateCXXScopeToken();
switch (Tok.getKind()) { switch (Tok.getKind()) {
default: default:
@ -985,8 +985,7 @@ void Parser::ParseEnumSpecifier(DeclSpec &DS) {
Attr = ParseAttributes(); Attr = ParseAttributes();
CXXScopeSpec SS; CXXScopeSpec SS;
if (isTokenCXXScopeSpecifier()) { if (getLang().CPlusPlus && MaybeParseCXXScopeSpecifier(SS)) {
ParseCXXScopeSpecifier(SS);
if (Tok.isNot(tok::identifier)) { if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident); Diag(Tok, diag::err_expected_ident);
if (Tok.isNot(tok::l_brace)) { if (Tok.isNot(tok::l_brace)) {
@ -1435,8 +1434,8 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
CXXScopeSpec &SS = D.getCXXScopeSpec(); CXXScopeSpec &SS = D.getCXXScopeSpec();
DeclaratorScopeObj DeclScopeObj(*this, SS); DeclaratorScopeObj DeclScopeObj(*this, SS);
if (D.mayHaveIdentifier() && isTokenCXXScopeSpecifier()) { if (D.mayHaveIdentifier() &&
ParseCXXScopeSpecifier(SS); getLang().CPlusPlus && MaybeParseCXXScopeSpecifier(SS)) {
// Change the declaration context for name lookup, until this function is // Change the declaration context for name lookup, until this function is
// exited (and the declarator has been parsed). // exited (and the declarator has been parsed).
DeclScopeObj.EnterDeclaratorScope(); DeclScopeObj.EnterDeclaratorScope();

Просмотреть файл

@ -218,8 +218,7 @@ void Parser::ParseClassSpecifier(DeclSpec &DS) {
// Parse the (optional) nested-name-specifier. // Parse the (optional) nested-name-specifier.
CXXScopeSpec SS; CXXScopeSpec SS;
if (isTokenCXXScopeSpecifier()) { if (getLang().CPlusPlus && MaybeParseCXXScopeSpecifier(SS)) {
ParseCXXScopeSpecifier(SS);
if (Tok.isNot(tok::identifier)) if (Tok.isNot(tok::identifier))
Diag(Tok, diag::err_expected_ident); Diag(Tok, diag::err_expected_ident);
} }
@ -362,8 +361,7 @@ Parser::BaseResult Parser::ParseBaseSpecifier(DeclTy *ClassDecl)
// Parse optional '::' and optional nested-name-specifier. // Parse optional '::' and optional nested-name-specifier.
CXXScopeSpec SS; CXXScopeSpec SS;
if (isTokenCXXScopeSpecifier()) MaybeParseCXXScopeSpecifier(SS);
ParseCXXScopeSpecifier(SS);
// The location of the base class itself. // The location of the base class itself.
SourceLocation BaseLoc = Tok.getLocation(); SourceLocation BaseLoc = Tok.getLocation();

Просмотреть файл

@ -17,7 +17,8 @@
#include "AstGuard.h" #include "AstGuard.h"
using namespace clang; 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 /// '::'[opt] nested-name-specifier
/// '::' /// '::'
@ -28,14 +29,20 @@ using namespace clang;
/// nested-name-specifier identifier '::' /// nested-name-specifier identifier '::'
/// nested-name-specifier 'template'[opt] simple-template-id '::' [TODO] /// nested-name-specifier 'template'[opt] simple-template-id '::' [TODO]
/// ///
void Parser::ParseCXXScopeSpecifier(CXXScopeSpec &SS) { bool Parser::MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS) {
assert(isTokenCXXScopeSpecifier() && "Not scope specifier!"); 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)) { if (Tok.is(tok::annot_cxxscope)) {
SS.setScopeRep(Tok.getAnnotationValue()); SS.setScopeRep(Tok.getAnnotationValue());
SS.setRange(Tok.getAnnotationRange()); SS.setRange(Tok.getAnnotationRange());
ConsumeToken(); ConsumeToken();
return; return true;
} }
SS.setBeginLoc(Tok.getLocation()); SS.setBeginLoc(Tok.getLocation());
@ -68,6 +75,8 @@ void Parser::ParseCXXScopeSpecifier(CXXScopeSpec &SS) {
Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, *II) ); Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, *II) );
SS.setEndLoc(CCLoc); SS.setEndLoc(CCLoc);
} }
return true;
} }
/// ParseCXXIdExpression - Handle id-expression. /// ParseCXXIdExpression - Handle id-expression.
@ -126,8 +135,7 @@ Parser::ExprResult Parser::ParseCXXIdExpression() {
// '::' unqualified-id // '::' unqualified-id
// //
CXXScopeSpec SS; CXXScopeSpec SS;
if (isTokenCXXScopeSpecifier()) MaybeParseCXXScopeSpecifier(SS);
ParseCXXScopeSpecifier(SS);
// unqualified-id: // unqualified-id:
// identifier // identifier

Просмотреть файл

@ -705,8 +705,8 @@ void Parser::TryAnnotateTypeOrScopeToken() {
return; return;
CXXScopeSpec SS; CXXScopeSpec SS;
if (isTokenCXXScopeSpecifier()) if (getLang().CPlusPlus)
ParseCXXScopeSpecifier(SS); MaybeParseCXXScopeSpecifier(SS);
if (Tok.is(tok::identifier)) { if (Tok.is(tok::identifier)) {
TypeTy *Ty = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope, &SS); TypeTy *Ty = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope, &SS);
@ -746,13 +746,15 @@ void Parser::TryAnnotateTypeOrScopeToken() {
/// TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only /// TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only
/// annotates C++ scope specifiers. /// 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)) if (Tok.is(tok::annot_cxxscope))
return; return;
if (isTokenCXXScopeSpecifier()) { CXXScopeSpec SS;
CXXScopeSpec SS; if (MaybeParseCXXScopeSpecifier(SS)) {
ParseCXXScopeSpecifier(SS);
// Push the current token back into the token stream (or revert it if it is // 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. // cached) and use an annotation scope token for current token.