diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-09-16 01:51:54 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-09-16 01:51:54 +0000 |
| commit | abf4a3e4c605b90bba8091457ebac400eac10706 (patch) | |
| tree | 97736c7e707c67d128305da87f1aeb01bb2b87f0 /clang/lib/Parse/ParseDecl.cpp | |
| parent | 2cd7a78c760d1c8052fed67317de2abf2844c5ef (diff) | |
| download | bcm5719-llvm-abf4a3e4c605b90bba8091457ebac400eac10706.tar.gz bcm5719-llvm-abf4a3e4c605b90bba8091457ebac400eac10706.zip | |
Implement automatic bracket insertion for Objective-C class message
sends. These are far trickier than instance messages, because we
typically have something like
NSArray alloc]
where it appears to be a declaration of a variable named "alloc" up
until we see the ']' (or a ':'), and at that point we can't backtrace.
So, we use a combination of syntactic and semantic disambiguation to
treat this as a message send only when the type is an Objective-C type
and it has the syntax of a class message send (which would otherwise
be ill-formed).
llvm-svn: 114057
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
| -rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 45487e0fd12..ef495e33d85 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2304,7 +2304,10 @@ bool Parser::isTypeSpecifierQualifier() { /// isDeclarationSpecifier() - Return true if the current token is part of a /// declaration specifier. -bool Parser::isDeclarationSpecifier() { +/// +/// \param DisambiguatingWithExpression True to indicate that the purpose of +/// this check is to disambiguate between an expression and a declaration. +bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) { switch (Tok.getKind()) { default: return false; @@ -2322,6 +2325,16 @@ bool Parser::isDeclarationSpecifier() { return true; if (Tok.is(tok::identifier)) return false; + + // If we're in Objective-C and we have an Objective-C class type followed + // by an identifier and then either ':' or ']', in a place where an + // expression is permitted, then this is probably a class message send + // missing the initial '['. In this case, we won't consider this to be + // the start of a declaration. + if (DisambiguatingWithExpression && + isStartOfObjCClassMessageMissingOpenBracket()) + return false; + return isDeclarationSpecifier(); case tok::coloncolon: // ::foo::bar |

