diff options
author | John McCall <rjmccall@apple.com> | 2010-01-07 19:29:58 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-01-07 19:29:58 +0000 |
commit | b67270724f3924ab7ffbc05ebbe06f83c3fed7e4 (patch) | |
tree | 9f55f1d2b7fe96d0387488b4edd3c98277de79d1 /lib/Parse/ParseExpr.cpp | |
parent | 408a304afe244265187b84268ccb213b8375a9df (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92930 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseExpr.cpp')
-rw-r--r-- | lib/Parse/ParseExpr.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index bdbc67f782..4d6988d5f2 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/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 |