[cfe-commits] r161667 - in /cfe/trunk: lib/Parse/ParseDecl.cpp lib/Parse/Parser.cpp test/SemaObjCXX/delay-parsing-cplusfuncs.mm

Fariborz Jahanian fjahanian at apple.com
Fri Aug 10 08:54:40 PDT 2012


Author: fjahanian
Date: Fri Aug 10 10:54:40 2012
New Revision: 161667

URL: http://llvm.org/viewvc/llvm-project?rev=161667&view=rev
Log:
objective-C++: Delayed parsing of most common
member functions defined inside an objc class
implementation. wip.

Added:
    cfe/trunk/test/SemaObjCXX/delay-parsing-cplusfuncs.mm
Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/Parser.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=161667&r1=161666&r2=161667&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Aug 10 10:54:40 2012
@@ -1340,12 +1340,7 @@
       // Look at the next token to make sure that this isn't a function
       // declaration.  We have to check this because __attribute__ might be the
       // start of a function definition in GCC-extended K&R C.
-      // FIXME. Delayed parsing not done for c/c++ functions nested in namespace
-      !isDeclarationAfterDeclarator() && 
-      (!CurParsedObjCImpl || Tok.isNot(tok::l_brace) || 
-       (getLangOpts().CPlusPlus && 
-        (D.getCXXScopeSpec().isSet() || 
-         !Actions.CurContext->isTranslationUnit())))) {
+      !isDeclarationAfterDeclarator()) {
 
     if (isStartOfFunctionDefinition(D)) {
       if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
@@ -1401,14 +1396,6 @@
     DeclsInGroup.push_back(FirstDecl);
 
   bool ExpectSemi = Context != Declarator::ForContext;
-
-  if (CurParsedObjCImpl && D.isFunctionDeclarator() &&
-      Tok.is(tok::l_brace)) {
-    // Consume the tokens and store them for later parsing.
-    StashAwayMethodOrFunctionBodyTokens(FirstDecl);
-    CurParsedObjCImpl->HasCFunction = true;
-    ExpectSemi = false;
-  }
   
   // If we don't have a comma, it is either the end of the list (a ';') or an
   // error, bail out.

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=161667&r1=161666&r2=161667&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Fri Aug 10 10:54:40 2012
@@ -1025,7 +1025,26 @@
     }
     return DP;
   }
-
+  else if (CurParsedObjCImpl && Tok.is(tok::l_brace) && 
+      !TemplateInfo.TemplateParams &&
+      Actions.CurContext->isTranslationUnit()) {
+    MultiTemplateParamsArg TemplateParameterLists(Actions, 0, 0);
+    ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);
+    Scope *ParentScope = getCurScope()->getParent();
+    
+    D.setFunctionDefinitionKind(FDK_Definition);
+    Decl *FuncDecl = Actions.HandleDeclarator(ParentScope, D,
+                                        move(TemplateParameterLists));
+    D.complete(FuncDecl);
+    D.getMutableDeclSpec().abort();
+    if (FuncDecl) {
+      // Consume the tokens and store them for later parsing.
+      StashAwayMethodOrFunctionBodyTokens(FuncDecl);
+      CurParsedObjCImpl->HasCFunction = true;
+      return FuncDecl;
+    }
+  }
+      
   // Enter a scope for the function body.
   ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);
 

Added: cfe/trunk/test/SemaObjCXX/delay-parsing-cplusfuncs.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/delay-parsing-cplusfuncs.mm?rev=161667&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/delay-parsing-cplusfuncs.mm (added)
+++ cfe/trunk/test/SemaObjCXX/delay-parsing-cplusfuncs.mm Fri Aug 10 10:54:40 2012
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -Werror -verify -Wno-objc-root-class %s
+// rdar://10387088
+
+ at interface MyClass
+- (void)someMethod;
+ at end
+
+struct S {
+  int bar(MyClass * myObject);
+
+  int gorfbar(MyClass * myObject);
+
+};
+
+ at implementation MyClass
+- (void)someMethod {
+    [self privateMethod];  // clang already does not warn here
+}
+
+int S::bar(MyClass * myObject) {
+    [myObject privateMethod]; 
+    return gorfbar(myObject);
+}
+- (void)privateMethod { }
+
+int S::gorfbar(MyClass * myObject) {
+    [myObject privateMethod]; 
+    [myObject privateMethod1]; 
+    return getMe + bar(myObject);
+}
+
+- (void)privateMethod1 {
+  getMe = getMe+1;
+}
+
+static int getMe;
+
+ at end





More information about the cfe-commits mailing list