]> granicus.if.org Git - clang/commitdiff
Added a new memberfor Parser, to be used soon
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 6 Jul 2012 00:42:20 +0000 (00:42 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 6 Jul 2012 00:42:20 +0000 (00:42 +0000)
for doing delayed parsing of c++ method defined in
objc class implementations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159792 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Parser.h
lib/Parse/Parser.cpp

index 66e8662aeb6a3fe2a7c09a895ba5de11ed7f19c7..b9414a4051e9ed9ce5e74b0475e735fc8de099bc 100644 (file)
@@ -1045,6 +1045,7 @@ private:
                                           ParsingDeclSpec *DS = 0);
   bool isDeclarationAfterDeclarator();
   bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator);
+  bool isStartOfDelayParsedFunctionDefinition(const ParsingDeclarator &Declarator);
   DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(
                                                   ParsedAttributesWithRange &attrs,
                                                   ParsingDeclSpec *DS = 0,
index 4cc5fdeae0b16e98299e0dcf3d37cc8c9fc29c2f..070313384993477effcbbee8e8743bbca05a0659 100644 (file)
@@ -797,6 +797,27 @@ bool Parser::isStartOfFunctionDefinition(const ParsingDeclarator &Declarator) {
          Tok.is(tok::kw_try);          // X() try { ... }
 }
 
+/// \brief Determine whether the current token, if it occurs after a
+/// a function declarator, indicates the start of a function definition
+/// inside an objective-C class implementation and thus can be delay parsed. 
+bool Parser::isStartOfDelayParsedFunctionDefinition(
+                                       const ParsingDeclarator &Declarator) {
+  if (!CurParsedObjCImpl ||
+      !Declarator.isFunctionDeclarator())
+    return false;
+  if (Tok.is(tok::l_brace))   // int X() {}
+    return true;
+
+  // Handle K&R C argument lists: int X(f) int f; {}
+  if (!getLangOpts().CPlusPlus &&
+      Declarator.getFunctionTypeInfo().isKNRPrototype()) 
+    return isDeclarationSpecifier();
+  
+  return getLangOpts().CPlusPlus &&
+           (Tok.is(tok::colon) ||         // X() : Base() {} (used for ctors)
+            Tok.is(tok::kw_try));          // X() try { ... }
+}
+
 /// ParseDeclarationOrFunctionDefinition - Parse either a function-definition or
 /// a declaration.  We can't tell which we have until we read up to the
 /// compound-statement in function-definition. TemplateParams, if