summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseObjc.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-09-16 01:51:54 +0000
committerDouglas Gregor <dgregor@apple.com>2010-09-16 01:51:54 +0000
commitabf4a3e4c605b90bba8091457ebac400eac10706 (patch)
tree97736c7e707c67d128305da87f1aeb01bb2b87f0 /clang/lib/Parse/ParseObjc.cpp
parent2cd7a78c760d1c8052fed67317de2abf2844c5ef (diff)
downloadbcm5719-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/ParseObjc.cpp')
-rw-r--r--clang/lib/Parse/ParseObjc.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 46870d95285..a9cab9ec182 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -1862,6 +1862,35 @@ bool Parser::isSimpleObjCMessageExpression() {
GetLookAheadToken(2).is(tok::identifier);
}
+bool Parser::isStartOfObjCClassMessageMissingOpenBracket() {
+ if (!getLang().ObjC1 || !NextToken().is(tok::identifier) ||
+ InMessageExpression)
+ return false;
+
+
+ ParsedType Type;
+
+ if (Tok.is(tok::annot_typename))
+ Type = getTypeAnnotation(Tok);
+ else if (Tok.is(tok::identifier))
+ Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(),
+ getCurScope());
+ else
+ return false;
+
+ if (!Type.get().isNull() && Type.get()->isObjCObjectOrInterfaceType()) {
+ const Token &AfterNext = GetLookAheadToken(2);
+ if (AfterNext.is(tok::colon) || AfterNext.is(tok::r_square)) {
+ if (Tok.is(tok::identifier))
+ TryAnnotateTypeOrScopeToken();
+
+ return Tok.is(tok::annot_typename);
+ }
+ }
+
+ return false;
+}
+
/// objc-message-expr:
/// '[' objc-receiver objc-message-args ']'
///
OpenPOWER on IntegriCloud