remove optimization to avoid looking ahead for cases like ::foo. This
isn't worth the complexity and the code already does a ton of lookahead. llvm-svn: 61671
This commit is contained in:
parent
2c4353d04b
commit
8a7d10d753
|
@ -1309,8 +1309,6 @@ DIAG(err_array_new_needs_size, ERROR,
|
||||||
"array size must be specified in new expressions")
|
"array size must be specified in new expressions")
|
||||||
DIAG(err_bad_new_type, ERROR,
|
DIAG(err_bad_new_type, ERROR,
|
||||||
"cannot allocate %select{function|incomplete|reference}1 type %0 with new")
|
"cannot allocate %select{function|incomplete|reference}1 type %0 with new")
|
||||||
DIAG(err_invalid_qualified_new_delete, ERROR,
|
|
||||||
"invalid use of ::%select{new|delete}0")
|
|
||||||
DIAG(err_new_array_nonconst, ERROR,
|
DIAG(err_new_array_nonconst, ERROR,
|
||||||
"only the first dimension of an allocated array may be non-const")
|
"only the first dimension of an allocated array may be non-const")
|
||||||
DIAG(err_array_size_not_integral, ERROR,
|
DIAG(err_array_size_not_integral, ERROR,
|
||||||
|
|
|
@ -269,7 +269,7 @@ private:
|
||||||
/// for expressions in C.
|
/// for expressions in C.
|
||||||
///
|
///
|
||||||
/// This returns true if the token was annotated.
|
/// This returns true if the token was annotated.
|
||||||
bool TryAnnotateTypeOrScopeToken(const Token *GlobalQualifier = 0);
|
bool TryAnnotateTypeOrScopeToken();
|
||||||
|
|
||||||
/// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
|
/// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
|
||||||
/// annotates C++ scope specifiers. This returns true if the token was
|
/// annotates C++ scope specifiers. This returns true if the token was
|
||||||
|
@ -610,11 +610,9 @@ private:
|
||||||
|
|
||||||
/// MaybeParseCXXScopeSpecifier - 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.
|
/// Returns true if a nested-name-specifier was parsed from the token stream.
|
||||||
|
/// Note that this routine will not parse ::new or ::delete.
|
||||||
///
|
///
|
||||||
/// If GlobalQualifier is non-null, then it is a :: token we should use as the
|
bool MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS);
|
||||||
/// global qualifier.
|
|
||||||
bool MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS,
|
|
||||||
const Token *GlobalQualifier = 0);
|
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// C++ 5.2p1: C++ Casts
|
// C++ 5.2p1: C++ Casts
|
||||||
|
|
|
@ -626,25 +626,21 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression) {
|
||||||
return ParsePostfixExpressionSuffix(move(Res));
|
return ParsePostfixExpressionSuffix(move(Res));
|
||||||
|
|
||||||
case tok::coloncolon: {
|
case tok::coloncolon: {
|
||||||
|
// ::foo::bar -> global qualified name etc. If TryAnnotateTypeOrScopeToken
|
||||||
|
// annotates the token, tail recurse.
|
||||||
|
if (TryAnnotateTypeOrScopeToken())
|
||||||
|
return ParseCastExpression(isUnaryExpression);
|
||||||
|
|
||||||
// ::new -> [C++] new-expression
|
// ::new -> [C++] new-expression
|
||||||
// ::delete -> [C++] delete-expression
|
// ::delete -> [C++] delete-expression
|
||||||
// ::foo::bar -> global qualified name etc.
|
SourceLocation CCLoc = ConsumeToken();
|
||||||
Token ColonColonTok = Tok;
|
|
||||||
ConsumeToken();
|
|
||||||
if (Tok.is(tok::kw_new))
|
if (Tok.is(tok::kw_new))
|
||||||
return ParseCXXNewExpression(true, ColonColonTok.getLocation());
|
return ParseCXXNewExpression(true, CCLoc);
|
||||||
if (Tok.is(tok::kw_delete))
|
if (Tok.is(tok::kw_delete))
|
||||||
return ParseCXXDeleteExpression(true, ColonColonTok.getLocation());
|
return ParseCXXDeleteExpression(true, CCLoc);
|
||||||
// Turn the qualified name into a annot_qualtypename or annot_cxxscope if
|
|
||||||
// it would be valid.
|
|
||||||
if ((Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) &&
|
|
||||||
TryAnnotateTypeOrScopeToken(&ColonColonTok)) {
|
|
||||||
// If so, retry (tail recurse).
|
|
||||||
return ParseCastExpression(isUnaryExpression);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is not a type name or scope specifier, it is an invalid expression.
|
// This is not a type name or scope specifier, it is an invalid expression.
|
||||||
Diag(ColonColonTok, diag::err_expected_expression);
|
Diag(CCLoc, diag::err_expected_expression);
|
||||||
return ExprError();
|
return ExprError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,7 @@ using namespace clang;
|
||||||
/// MaybeParseCXXScopeSpecifier - 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.
|
/// Returns true if a nested-name-specifier was parsed from the token stream.
|
||||||
///
|
///
|
||||||
/// Note that this routine emits an error if you call it with ::new or ::delete
|
/// Note that this routine will not parse ::new or ::delete.
|
||||||
/// as the current tokens, so only call it in contexts where these are invalid.
|
|
||||||
///
|
///
|
||||||
/// '::'[opt] nested-name-specifier
|
/// '::'[opt] nested-name-specifier
|
||||||
/// '::'
|
/// '::'
|
||||||
|
@ -32,42 +31,25 @@ 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]
|
||||||
///
|
///
|
||||||
bool Parser::MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS,
|
bool Parser::MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS) {
|
||||||
const Token *GlobalQualifier) {
|
|
||||||
assert(getLang().CPlusPlus &&
|
assert(getLang().CPlusPlus &&
|
||||||
"Call sites of this function should be guarded by checking for C++");
|
"Call sites of this function should be guarded by checking for C++");
|
||||||
|
|
||||||
if (Tok.is(tok::annot_cxxscope)) {
|
if (Tok.is(tok::annot_cxxscope)) {
|
||||||
assert(GlobalQualifier == 0 &&
|
|
||||||
"Cannot have :: followed by a resolved annotation scope");
|
|
||||||
SS.setScopeRep(Tok.getAnnotationValue());
|
SS.setScopeRep(Tok.getAnnotationValue());
|
||||||
SS.setRange(Tok.getAnnotationRange());
|
SS.setRange(Tok.getAnnotationRange());
|
||||||
ConsumeToken();
|
ConsumeToken();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GlobalQualifier) {
|
if (Tok.is(tok::coloncolon)) {
|
||||||
// Pre-parsed '::'.
|
// ::new and ::delete aren't nested-name-specifiers.
|
||||||
SS.setBeginLoc(GlobalQualifier->getLocation());
|
tok::TokenKind NextKind = NextToken().getKind();
|
||||||
SS.setScopeRep(Actions.ActOnCXXGlobalScopeSpecifier(CurScope,
|
if (NextKind == tok::kw_new || NextKind == tok::kw_delete)
|
||||||
GlobalQualifier->getLocation()));
|
return false;
|
||||||
SS.setEndLoc(GlobalQualifier->getLocation());
|
|
||||||
|
|
||||||
assert(Tok.isNot(tok::kw_new) && Tok.isNot(tok::kw_delete) &&
|
|
||||||
"Never called with preparsed :: qualifier and with new/delete");
|
|
||||||
} else if (Tok.is(tok::coloncolon)) {
|
|
||||||
// '::' - Global scope qualifier.
|
// '::' - Global scope qualifier.
|
||||||
SourceLocation CCLoc = ConsumeToken();
|
SourceLocation CCLoc = ConsumeToken();
|
||||||
|
|
||||||
// ::new and ::delete aren't nested-name-specifiers, and
|
|
||||||
// MaybeParseCXXScopeSpecifier is never called in a context where one
|
|
||||||
// could exist. This means that if we see it, we have a syntax error.
|
|
||||||
if (Tok.is(tok::kw_new) || Tok.is(tok::kw_delete)) {
|
|
||||||
Diag(Tok, diag::err_invalid_qualified_new_delete)
|
|
||||||
<< Tok.is(tok::kw_delete);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SS.setBeginLoc(CCLoc);
|
SS.setBeginLoc(CCLoc);
|
||||||
SS.setScopeRep(Actions.ActOnCXXGlobalScopeSpecifier(CurScope, CCLoc));
|
SS.setScopeRep(Actions.ActOnCXXGlobalScopeSpecifier(CurScope, CCLoc));
|
||||||
SS.setEndLoc(CCLoc);
|
SS.setEndLoc(CCLoc);
|
||||||
|
|
|
@ -746,14 +746,14 @@ Parser::OwningExprResult Parser::ParseSimpleAsm() {
|
||||||
///
|
///
|
||||||
/// Note that this routine emits an error if you call it with ::new or ::delete
|
/// Note that this routine emits an error if you call it with ::new or ::delete
|
||||||
/// as the current tokens, so only call it in contexts where these are invalid.
|
/// as the current tokens, so only call it in contexts where these are invalid.
|
||||||
bool Parser::TryAnnotateTypeOrScopeToken(const Token *GlobalQualifier) {
|
bool Parser::TryAnnotateTypeOrScopeToken() {
|
||||||
assert((Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) &&
|
assert((Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) &&
|
||||||
"Cannot be a type or scope token!");
|
"Cannot be a type or scope token!");
|
||||||
|
|
||||||
// FIXME: Implement template-ids
|
// FIXME: Implement template-ids
|
||||||
CXXScopeSpec SS;
|
CXXScopeSpec SS;
|
||||||
if (getLang().CPlusPlus)
|
if (getLang().CPlusPlus)
|
||||||
MaybeParseCXXScopeSpecifier(SS, GlobalQualifier);
|
MaybeParseCXXScopeSpecifier(SS);
|
||||||
|
|
||||||
if (Tok.is(tok::identifier)) {
|
if (Tok.is(tok::identifier)) {
|
||||||
// Determine whether the identifier is a type name.
|
// Determine whether the identifier is a type name.
|
||||||
|
|
Loading…
Reference in New Issue