summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseExpr.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-01-07 19:29:58 +0000
committerJohn McCall <rjmccall@apple.com>2010-01-07 19:29:58 +0000
commit64fe23370481d2c18460367ff8b933a7e4884c52 (patch)
tree80383372e1fb6d243a15a236e87f16da21b36d80 /clang/lib/Parse/ParseExpr.cpp
parentbd0c5da5fc83c5e170021e8f474c1f61c7dd8231 (diff)
downloadbcm5719-llvm-64fe23370481d2c18460367ff8b933a7e4884c52.tar.gz
bcm5719-llvm-64fe23370481d2c18460367ff8b933a7e4884c52.zip
When parsing an identifier as an expression in C++, only try to annotate it
as a type or scope token if the next token requires it. This eliminates a lot of redundant lookups in C++, but there's room for improvement; a better solution would do a single lookup whose kind and results would be passed through the parser. llvm-svn: 92930
Diffstat (limited to 'clang/lib/Parse/ParseExpr.cpp')
-rw-r--r--clang/lib/Parse/ParseExpr.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index bdbc67f782d..4d6988d5f2c 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -616,9 +616,17 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression,
// Turn a potentially qualified name into a annot_typename or
// annot_cxxscope if it would be valid. This handles things like x::y, etc.
if (getLang().CPlusPlus) {
- // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
- if (TryAnnotateTypeOrScopeToken())
- return ParseCastExpression(isUnaryExpression, isAddressOfOperand);
+ // Avoid the unnecessary parse-time lookup in the common case
+ // where the syntax forbids a type.
+ const Token &Next = NextToken();
+ if (Next.is(tok::coloncolon) ||
+ (!ColonIsSacred && Next.is(tok::colon)) ||
+ Next.is(tok::less) ||
+ Next.is(tok::l_paren)) {
+ // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
+ if (TryAnnotateTypeOrScopeToken())
+ return ParseCastExpression(isUnaryExpression, isAddressOfOperand);
+ }
}
// Consume the identifier so that we can see if it is followed by a '(' or
OpenPOWER on IntegriCloud