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

Fariborz Jahanian fjahanian at apple.com
Fri Aug 10 14:15:06 PDT 2012


Author: fjahanian
Date: Fri Aug 10 16:15:06 2012
New Revision: 161699

URL: http://llvm.org/viewvc/llvm-project?rev=161699&view=rev
Log:
objective-C++: dalyed parsing of ctors with member
initializer list defined inside an objc class
implementation. wip

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

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=161699&r1=161698&r2=161699&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Fri Aug 10 16:15:06 2012
@@ -1927,7 +1927,7 @@
   LexedMethod* LM = new LexedMethod(this, MDecl);
   CurParsedObjCImpl->LateParsedObjCMethods.push_back(LM);
   CachedTokens &Toks = LM->Toks;
-  // Begin by storing the '{' or 'try' token.
+  // Begin by storing the '{' or 'try' or ':' token.
   Toks.push_back(Tok);
   if (Tok.is(tok::kw_try)) {
     ConsumeToken();
@@ -1939,8 +1939,14 @@
         ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false);
       }
     }
-    assert(Tok.is(tok::l_brace) 
-           && "StashAwayMethodOrFunctionBodyTokens - '{' not found");
+    Toks.push_back(Tok); // also store '{'
+  }
+  else if (Tok.is(tok::colon)) {
+    ConsumeToken();
+    while (Tok.isNot(tok::l_brace)) {
+      ConsumeAndStoreUntil(tok::l_paren, Toks, /*StopAtSemi=*/false);
+      ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false);
+    }
     Toks.push_back(Tok); // also store '{'
   }
   ConsumeBrace();
@@ -2881,8 +2887,9 @@
   // Consume the previously pushed token.
   ConsumeAnyToken();
     
-  assert((Tok.is(tok::l_brace) || Tok.is(tok::kw_try)) && 
-          "Inline objective-c method not starting with '{' or 'try'");
+  assert((Tok.is(tok::l_brace) || Tok.is(tok::kw_try) ||
+          Tok.is(tok::colon)) && 
+          "Inline objective-c method not starting with '{' or 'try' or ':'");
   // Enter a scope for the method or c-fucntion body.
   ParseScope BodyScope(this,
                        parseMethod
@@ -2897,8 +2904,11 @@
     Actions.ActOnStartOfFunctionDef(getCurScope(), MCDecl);
   if (Tok.is(tok::kw_try))
     MCDecl = ParseFunctionTryBlock(MCDecl, BodyScope);
-  else
+  else {
+    if (Tok.is(tok::colon))
+      ParseConstructorInitializer(MCDecl);
     MCDecl = ParseFunctionStatementBody(MCDecl, BodyScope);
+  }
   
   if (Tok.getLocation() != OrigLoc) {
     // Due to parsing error, we either went over the cached tokens or

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=161699&r1=161698&r2=161699&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Fri Aug 10 16:15:06 2012
@@ -1026,8 +1026,9 @@
     return DP;
   }
   else if (CurParsedObjCImpl && 
-           (Tok.is(tok::l_brace) || Tok.is(tok::kw_try)) && 
-      !TemplateInfo.TemplateParams &&
+           !TemplateInfo.TemplateParams &&
+           (Tok.is(tok::l_brace) || Tok.is(tok::kw_try) ||
+            Tok.is(tok::colon)) && 
       Actions.CurContext->isTranslationUnit()) {
     MultiTemplateParamsArg TemplateParameterLists(Actions, 0, 0);
     ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);

Modified: cfe/trunk/test/SemaObjCXX/delay-parsing-cplusfuncs.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/delay-parsing-cplusfuncs.mm?rev=161699&r1=161698&r2=161699&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/delay-parsing-cplusfuncs.mm (original)
+++ cfe/trunk/test/SemaObjCXX/delay-parsing-cplusfuncs.mm Fri Aug 10 16:15:06 2012
@@ -10,6 +10,12 @@
 
   int gorfbar(MyClass * myObject);
 
+  S();
+  S(MyClass *O1, MyClass *O2);
+  S(MyClass *O1);
+
+  MyClass * Obj1, *Obj2;
+
 };
 
 @implementation MyClass
@@ -29,6 +35,14 @@
     return getMe + bar(myObject);
 }
 
+S::S(MyClass *O1, MyClass *O2) : Obj1(O1), Obj2(O2) {
+    [O1 privateMethod]; 
+    [O2 privateMethod1]; 
+}
+S::S(MyClass *O1) : Obj1(O1){ Obj2 = 0; }
+
+S::S() {}
+
 - (void)privateMethod1 {
   getMe = getMe+1;
 }





More information about the cfe-commits mailing list