[cfe-commits] r161675 - in /cfe/trunk: lib/Parse/ParseObjc.cpp lib/Parse/Parser.cpp test/SemaObjCXX/delay-parsing-func-tryblock.mm
Fariborz Jahanian
fjahanian at apple.com
Fri Aug 10 11:10:56 PDT 2012
Author: fjahanian
Date: Fri Aug 10 13:10:56 2012
New Revision: 161675
URL: http://llvm.org/viewvc/llvm-project?rev=161675&view=rev
Log:
objective-C++: delayed parsing of member function with
function-try-block occuring in objc's implementation
block. wip.
Added:
cfe/trunk/test/SemaObjCXX/delay-parsing-func-tryblock.mm
Modified:
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/Parser.cpp
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=161675&r1=161674&r2=161675&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Fri Aug 10 13:10:56 2012
@@ -1927,11 +1927,19 @@
LexedMethod* LM = new LexedMethod(this, MDecl);
CurParsedObjCImpl->LateParsedObjCMethods.push_back(LM);
CachedTokens &Toks = LM->Toks;
- // Begin by storing the '{' token.
+ // Begin by storing the '{' or 'try' token.
Toks.push_back(Tok);
+ if (Tok.is(tok::kw_try)) {
+ ConsumeToken();
+ Toks.push_back(Tok); // also store '{'
+ }
ConsumeBrace();
// Consume everything up to (and including) the matching right brace.
ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
+ while (Tok.is(tok::kw_catch)) {
+ ConsumeAndStoreUntil(tok::l_brace, Toks, /*StopAtSemi=*/false);
+ ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
+ }
}
/// objc-method-def: objc-method-proto ';'[opt] '{' body '}'
@@ -2863,7 +2871,8 @@
// Consume the previously pushed token.
ConsumeAnyToken();
- assert(Tok.is(tok::l_brace) && "Inline objective-c method not starting with '{'");
+ assert((Tok.is(tok::l_brace) || Tok.is(tok::kw_try)) &&
+ "Inline objective-c method not starting with '{' or 'try'");
// Enter a scope for the method or c-fucntion body.
ParseScope BodyScope(this,
parseMethod
@@ -2876,8 +2885,10 @@
Actions.ActOnStartOfObjCMethodDef(getCurScope(), MCDecl);
else
Actions.ActOnStartOfFunctionDef(getCurScope(), MCDecl);
-
- MCDecl = ParseFunctionStatementBody(MCDecl, BodyScope);
+ if (Tok.is(tok::kw_try))
+ MCDecl = ParseFunctionTryBlock(MCDecl, BodyScope);
+ else
+ 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=161675&r1=161674&r2=161675&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Fri Aug 10 13:10:56 2012
@@ -1025,7 +1025,8 @@
}
return DP;
}
- else if (CurParsedObjCImpl && Tok.is(tok::l_brace) &&
+ else if (CurParsedObjCImpl &&
+ (Tok.is(tok::l_brace) || Tok.is(tok::kw_try)) &&
!TemplateInfo.TemplateParams &&
Actions.CurContext->isTranslationUnit()) {
MultiTemplateParamsArg TemplateParameterLists(Actions, 0, 0);
Added: cfe/trunk/test/SemaObjCXX/delay-parsing-func-tryblock.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/delay-parsing-func-tryblock.mm?rev=161675&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/delay-parsing-func-tryblock.mm (added)
+++ cfe/trunk/test/SemaObjCXX/delay-parsing-func-tryblock.mm Fri Aug 10 13:10:56 2012
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -x objective-c++ -fcxx-exceptions -fsyntax-only -Werror -verify -Wno-objc-root-class %s
+// rdar://10387088
+
+ at interface MyClass
+- (void)someMethod;
+ at end
+
+struct BadReturn {
+ BadReturn(MyClass * myObject);
+ int bar(MyClass * myObject);
+ int i;
+};
+
+ at implementation MyClass
+- (void)someMethod {
+ [self privateMethod]; // clang already does not warn here
+}
+
+int BadReturn::bar(MyClass * myObject) {
+ [myObject privateMethod];
+ return 0;
+}
+
+BadReturn::BadReturn(MyClass * myObject) try {
+} catch(...) {
+ try {
+ [myObject privateMethod];
+ [myObject privateMethod1];
+ getMe = bar(myObject);
+ } catch(int ei) {
+ i = ei;
+ } catch(...) {
+ {
+ i = 0;
+ }
+ }
+}
+
+- (void)privateMethod { }
+
+- (void)privateMethod1 {
+ getMe = getMe+1;
+}
+
+static int getMe;
+
+ at end
More information about the cfe-commits
mailing list