[llvm-branch-commits] [cfe-branch] r122489 - in /cfe/branches/Apple/whitney: include/clang/Parse/Parser.h include/clang/Sema/Sema.h lib/Parse/ParseObjc.cpp lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaDeclObjC.cpp test/Index/annotate-tokens.m test/Index/usrs.m
Daniel Dunbar
daniel at zuster.org
Wed Dec 22 21:40:56 PST 2010
Author: ddunbar
Date: Wed Dec 22 23:40:56 2010
New Revision: 122489
URL: http://llvm.org/viewvc/llvm-project?rev=122489&view=rev
Log:
Merge r122347:
--
Author: Douglas Gregor <dgregor at apple.com>
Date: Tue Dec 21 17:34:17 2010 +0000
Fix a major inconsistency in the representation of Objective-C
classes, categories, protocols, and class extensions, where the
methods and properties of these entities would be inserted into the
DeclContext in an ordering that doesn't necessarily reflect source
order. The culprits were Sema::ActOnMethodDeclaration(), which did not
perform the insertion of the just-created method declaration into
the DeclContext for these Objective-C entities, and
Sema::ActOnAtEnd(), which inserted all method declarations at the
*end* of the DeclContext.
With this fix in hand, clean up the code-completion actions for
property setters/getters that worked around this brokenness in the AST.
Fixes <rdar://problem/8062781>, where this problem manifested as poor
token-annotation information, but this would have struck again in many
other places.
Modified:
cfe/branches/Apple/whitney/include/clang/Parse/Parser.h
cfe/branches/Apple/whitney/include/clang/Sema/Sema.h
cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp
cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp
cfe/branches/Apple/whitney/lib/Sema/SemaDeclObjC.cpp
cfe/branches/Apple/whitney/test/Index/annotate-tokens.m
cfe/branches/Apple/whitney/test/Index/usrs.m
Modified: cfe/branches/Apple/whitney/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/Parse/Parser.h?rev=122489&r1=122488&r2=122489&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/Parse/Parser.h (original)
+++ cfe/branches/Apple/whitney/include/clang/Parse/Parser.h Wed Dec 22 23:40:56 2010
@@ -983,8 +983,7 @@
Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
Decl *classDecl,
tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
- void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl,
- Decl **Methods, unsigned NumMethods);
+ void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl);
Decl *ParseObjCMethodDefinition();
Modified: cfe/branches/Apple/whitney/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/Sema/Sema.h?rev=122489&r1=122488&r2=122489&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/Sema/Sema.h (original)
+++ cfe/branches/Apple/whitney/include/clang/Sema/Sema.h Wed Dec 22 23:40:56 2010
@@ -4417,12 +4417,8 @@
void CodeCompleteObjCAtStatement(Scope *S);
void CodeCompleteObjCAtExpression(Scope *S);
void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
- void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl,
- Decl **Methods,
- unsigned NumMethods);
- void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl,
- Decl **Methods,
- unsigned NumMethods);
+ void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl);
+ void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl);
void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS);
void CodeCompleteObjCMessageReceiver(Scope *S);
void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
Modified: cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp?rev=122489&r1=122488&r2=122489&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Parse/ParseObjc.cpp Wed Dec 22 23:40:56 2010
@@ -426,8 +426,7 @@
ObjCDeclSpec OCDS;
// Parse property attribute list, if any.
if (Tok.is(tok::l_paren))
- ParseObjCPropertyAttribute(OCDS, interfaceDecl,
- allMethods.data(), allMethods.size());
+ ParseObjCPropertyAttribute(OCDS, interfaceDecl);
ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties,
OCDS, AtLoc, MethodImplKind);
@@ -476,9 +475,7 @@
/// copy
/// nonatomic
///
-void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl,
- Decl **Methods,
- unsigned NumMethods) {
+void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl) {
assert(Tok.getKind() == tok::l_paren);
SourceLocation LHSLoc = ConsumeParen(); // consume '('
@@ -521,11 +518,9 @@
if (Tok.is(tok::code_completion)) {
if (IsSetter)
- Actions.CodeCompleteObjCPropertySetter(getCurScope(), ClassDecl,
- Methods, NumMethods);
+ Actions.CodeCompleteObjCPropertySetter(getCurScope(), ClassDecl);
else
- Actions.CodeCompleteObjCPropertyGetter(getCurScope(), ClassDecl,
- Methods, NumMethods);
+ Actions.CodeCompleteObjCPropertyGetter(getCurScope(), ClassDecl);
ConsumeCodeCompletionToken();
}
Modified: cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp?rev=122489&r1=122488&r2=122489&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp Wed Dec 22 23:40:56 2010
@@ -4170,9 +4170,7 @@
}
-void Sema::CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl,
- Decl **Methods,
- unsigned NumMethods) {
+void Sema::CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl) {
typedef CodeCompletionResult Result;
// Try to find the interface where getters might live.
@@ -4190,19 +4188,6 @@
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
- // FIXME: We need to do this because Objective-C methods don't get
- // pushed into DeclContexts early enough. Argh!
- for (unsigned I = 0; I != NumMethods; ++I) {
- if (ObjCMethodDecl *Method
- = dyn_cast_or_null<ObjCMethodDecl>(Methods[I]))
- if (Method->isInstanceMethod() &&
- isAcceptableObjCMethod(Method, MK_ZeroArgSelector, 0, 0)) {
- Result R = Result(Method, 0);
- R.AllParametersAreInformative = true;
- Results.MaybeAddResult(R, CurContext);
- }
- }
-
VisitedSelectorSet Selectors;
AddObjCMethods(Class, true, MK_ZeroArgSelector, 0, 0, CurContext, Selectors,
/*AllowSameLength=*/true, Results);
@@ -4212,9 +4197,7 @@
Results.data(),Results.size());
}
-void Sema::CodeCompleteObjCPropertySetter(Scope *S, Decl *ObjCImplDecl,
- Decl **Methods,
- unsigned NumMethods) {
+void Sema::CodeCompleteObjCPropertySetter(Scope *S, Decl *ObjCImplDecl) {
typedef CodeCompletionResult Result;
// Try to find the interface where setters might live.
@@ -4233,19 +4216,6 @@
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
- // FIXME: We need to do this because Objective-C methods don't get
- // pushed into DeclContexts early enough. Argh!
- for (unsigned I = 0; I != NumMethods; ++I) {
- if (ObjCMethodDecl *Method
- = dyn_cast_or_null<ObjCMethodDecl>(Methods[I]))
- if (Method->isInstanceMethod() &&
- isAcceptableObjCMethod(Method, MK_OneArgSelector, 0, 0)) {
- Result R = Result(Method, 0);
- R.AllParametersAreInformative = true;
- Results.MaybeAddResult(R, CurContext);
- }
- }
-
VisitedSelectorSet Selectors;
AddObjCMethods(Class, true, MK_OneArgSelector, 0, 0, CurContext,
Selectors, /*AllowSameLength=*/true, Results);
Modified: cfe/branches/Apple/whitney/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaDeclObjC.cpp?rev=122489&r1=122488&r2=122489&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaDeclObjC.cpp Wed Dec 22 23:40:56 2010
@@ -1459,8 +1459,6 @@
Diag(L, diag::warn_missing_atend);
}
- DeclContext *DC = dyn_cast<DeclContext>(ClassDecl);
-
// FIXME: Remove these and use the ObjCContainerDecl/DeclContext.
llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap;
llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap;
@@ -1480,8 +1478,8 @@
Diag(Method->getLocation(), diag::err_duplicate_method_decl)
<< Method->getDeclName();
Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
+ Method->setInvalidDecl();
} else {
- DC->addDecl(Method);
InsMap[Method->getSelector()] = Method;
/// The following allows us to typecheck messages to "id".
AddInstanceMethodToGlobalPool(Method);
@@ -1499,8 +1497,8 @@
Diag(Method->getLocation(), diag::err_duplicate_method_decl)
<< Method->getDeclName();
Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
+ Method->setInvalidDecl();
} else {
- DC->addDecl(Method);
ClsMap[Method->getSelector()] = Method;
/// The following allows us to typecheck messages to "Class".
AddFactoryMethodToGlobalPool(Method);
@@ -1723,10 +1721,7 @@
const ObjCMethodDecl *InterfaceMD = 0;
- // For implementations (which can be very "coarse grain"), we add the
- // method now. This allows the AST to implement lookup methods that work
- // incrementally (without waiting until we parse the @end). It also allows
- // us to flag multiple declaration errors as they occur.
+ // Add the method now.
if (ObjCImplementationDecl *ImpDecl =
dyn_cast<ObjCImplementationDecl>(ClassDecl)) {
if (MethodType == tok::minus) {
@@ -1753,6 +1748,8 @@
if (ObjCMethod->hasAttrs() &&
containsInvalidMethodImplAttribute(ObjCMethod->getAttrs()))
Diag(EndLoc, diag::warn_attribute_method_def);
+ } else {
+ cast<DeclContext>(ClassDecl)->addDecl(ObjCMethod);
}
if (PrevMethod) {
// You can never have two method definitions with the same name.
Modified: cfe/branches/Apple/whitney/test/Index/annotate-tokens.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/annotate-tokens.m?rev=122489&r1=122488&r2=122489&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/annotate-tokens.m (original)
+++ cfe/branches/Apple/whitney/test/Index/annotate-tokens.m Wed Dec 22 23:40:56 2010
@@ -131,6 +131,11 @@
}
@end
+ at interface Rdar8062781
++ (Foo*)getB;
+ at property (readonly, nonatomic) Foo *blah;
+ at end
+
// RUN: c-index-test -test-annotate-tokens=%s:1:1:118:1 %s -DIBOutlet='__attribute__((iboutlet))' -DIBAction='void)__attribute__((ibaction)' | FileCheck %s
// CHECK: Punctuation: "@" [1:1 - 1:2] ObjCInterfaceDecl=Foo:1:12
// CHECK: Keyword: "interface" [1:2 - 1:11] ObjCInterfaceDecl=Foo:1:12
@@ -305,17 +310,17 @@
// CHECK: Identifier: "anOutlet" [53:21 - 53:29] ObjCIvarDecl=anOutlet:53:21 (Definition)
// CHECK: Punctuation: ";" [53:29 - 53:30] ObjCInterfaceDecl=IBOutletTests:51:12
// CHECK: Punctuation: "}" [54:1 - 54:2] ObjCInterfaceDecl=IBOutletTests:51:12
-// CHECK: Punctuation: "-" [55:1 - 55:2] ObjCInterfaceDecl=IBOutletTests:51:12
-// CHECK: Punctuation: "(" [55:3 - 55:4] ObjCInterfaceDecl=IBOutletTests:51:12
-// CHECK: Identifier: "IBAction" [55:4 - 55:12] macro instantiation=IBAction
-// CHECK: Punctuation: ")" [55:12 - 55:13] ObjCInterfaceDecl=IBOutletTests:51:12
-// CHECK: Identifier: "actionMethod" [55:14 - 55:26] ObjCInterfaceDecl=IBOutletTests:51:12
-// CHECK: Punctuation: ":" [55:26 - 55:27] ObjCInterfaceDecl=IBOutletTests:51:12
-// CHECK: Punctuation: "(" [55:27 - 55:28] ObjCInterfaceDecl=IBOutletTests:51:12
-// CHECK: Identifier: "id" [55:28 - 55:30] ObjCInterfaceDecl=IBOutletTests:51:12
-// CHECK: Punctuation: ")" [55:30 - 55:31] ObjCInterfaceDecl=IBOutletTests:51:12
-// CHECK: Identifier: "arg" [55:31 - 55:34] ObjCInterfaceDecl=IBOutletTests:51:12
-// CHECK: Punctuation: ";" [55:34 - 55:35] ObjCInterfaceDecl=IBOutletTests:51:12
+// CHECK: Punctuation: "-" [55:1 - 55:2] ObjCInstanceMethodDecl=actionMethod::55:1
+// CHECK: Punctuation: "(" [55:3 - 55:4] ObjCInstanceMethodDecl=actionMethod::55:1
+// CHECK: Identifier: "IBAction" [55:4 - 55:12] macro instantiation=IBAction:146:9
+// CHECK: Punctuation: ")" [55:12 - 55:13] ObjCInstanceMethodDecl=actionMethod::55:1
+// CHECK: Identifier: "actionMethod" [55:14 - 55:26] ObjCInstanceMethodDecl=actionMethod::55:1
+// CHECK: Punctuation: ":" [55:26 - 55:27] ObjCInstanceMethodDecl=actionMethod::55:1
+// CHECK: Punctuation: "(" [55:27 - 55:28] ObjCInstanceMethodDecl=actionMethod::55:1
+// CHECK: Identifier: "id" [55:28 - 55:30] TypeRef=id:0:0
+// CHECK: Punctuation: ")" [55:30 - 55:31] ParmDecl=arg:55:31 (Definition)
+// CHECK: Identifier: "arg" [55:31 - 55:34] ParmDecl=arg:55:31 (Definition)
+// CHECK: Punctuation: ";" [55:34 - 55:35] ObjCInstanceMethodDecl=actionMethod::55:1
// CHECK: Punctuation: "@" [56:1 - 56:2] ObjCPropertyDecl=aPropOutlet:56:26
// CHECK: Keyword: "property" [56:2 - 56:10] ObjCPropertyDecl=aPropOutlet:56:26
// CHECK: Identifier: "IBOutlet" [56:11 - 56:19] macro instantiation=IBOutlet
@@ -519,3 +524,27 @@
// CHECK-INSIDE_BLOCK: Identifier: "a" [128:18 - 128:19] VarDecl=a:128:18 (Definition)
// CHECK-INSIDE_BLOCK: Punctuation: "=" [128:20 - 128:21] VarDecl=a:128:18 (Definition)
// CHECK-INSIDE_BLOCK: Identifier: "self" [128:22 - 128:26] DeclRefExpr=self:0:0
+
+// RUN: c-index-test -test-annotate-tokens=%s:134:1:137:1 %s -DIBOutlet='__attribute__((iboutlet))' -DIBAction='void)__attribute__((ibaction)' | FileCheck -check-prefix=CHECK-PROP-AFTER-METHOD %s
+// CHECK-PROP-AFTER-METHOD: Punctuation: "@" [134:1 - 134:2] ObjCInterfaceDecl=Rdar8062781:134:12
+// CHECK-PROP-AFTER-METHOD: Keyword: "interface" [134:2 - 134:11] ObjCInterfaceDecl=Rdar8062781:134:12
+// CHECK-PROP-AFTER-METHOD: Identifier: "Rdar8062781" [134:12 - 134:23] ObjCInterfaceDecl=Rdar8062781:134:12
+// CHECK-PROP-AFTER-METHOD: Punctuation: "+" [135:1 - 135:2] ObjCClassMethodDecl=getB:135:1
+// CHECK-PROP-AFTER-METHOD: Punctuation: "(" [135:3 - 135:4] ObjCClassMethodDecl=getB:135:1
+// CHECK-PROP-AFTER-METHOD: Identifier: "Foo" [135:4 - 135:7] ObjCClassRef=Foo:1:12
+// CHECK-PROP-AFTER-METHOD: Punctuation: "*" [135:7 - 135:8] ObjCClassMethodDecl=getB:135:1
+// CHECK-PROP-AFTER-METHOD: Punctuation: ")" [135:8 - 135:9] ObjCClassMethodDecl=getB:135:1
+// CHECK-PROP-AFTER-METHOD: Identifier: "getB" [135:9 - 135:13] ObjCClassMethodDecl=getB:135:1
+// CHECK-PROP-AFTER-METHOD: Punctuation: ";" [135:13 - 135:14] ObjCClassMethodDecl=getB:135:1
+// CHECK-PROP-AFTER-METHOD: Punctuation: "@" [136:1 - 136:2] ObjCPropertyDecl=blah:136:38
+// CHECK-PROP-AFTER-METHOD: Keyword: "property" [136:2 - 136:10] ObjCPropertyDecl=blah:136:38
+// CHECK-PROP-AFTER-METHOD: Punctuation: "(" [136:11 - 136:12] ObjCPropertyDecl=blah:136:38
+// CHECK-PROP-AFTER-METHOD: Identifier: "readonly" [136:12 - 136:20] ObjCPropertyDecl=blah:136:38
+// CHECK-PROP-AFTER-METHOD: Punctuation: "," [136:20 - 136:21] ObjCPropertyDecl=blah:136:38
+// CHECK-PROP-AFTER-METHOD: Identifier: "nonatomic" [136:22 - 136:31] ObjCPropertyDecl=blah:136:38
+// CHECK-PROP-AFTER-METHOD: Punctuation: ")" [136:31 - 136:32] ObjCPropertyDecl=blah:136:38
+// CHECK-PROP-AFTER-METHOD: Identifier: "Foo" [136:33 - 136:36] ObjCClassRef=Foo:1:12
+// CHECK-PROP-AFTER-METHOD: Punctuation: "*" [136:37 - 136:38] ObjCPropertyDecl=blah:136:38
+// CHECK-PROP-AFTER-METHOD: Identifier: "blah" [136:38 - 136:42] ObjCPropertyDecl=blah:136:38
+// CHECK-PROP-AFTER-METHOD: Punctuation: ";" [136:42 - 136:43] ObjCInterfaceDecl=Rdar8062781:134:12
+// CHECK-PROP-AFTER-METHOD: Punctuation: "@" [137:1 - 137:2] ObjCInterfaceDecl=Rdar8062781:134:12
Modified: cfe/branches/Apple/whitney/test/Index/usrs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/usrs.m?rev=122489&r1=122488&r2=122489&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/usrs.m (original)
+++ cfe/branches/Apple/whitney/test/Index/usrs.m Wed Dec 22 23:40:56 2010
@@ -95,9 +95,9 @@
// CHECK: usrs.m c:objc(cs)Foo Extent=[25:1 - 32:5]
// CHECK: usrs.m c:objc(cs)Foo at x Extent=[26:6 - 26:7]
// CHECK: usrs.m c:objc(cs)Foo at y Extent=[27:6 - 27:7]
-// CHECK: usrs.m c:objc(cs)Foo(py)d1 Extent=[31:1 - 31:17]
// CHECK: usrs.m c:objc(cs)Foo(im)godzilla Extent=[29:1 - 29:17]
// CHECK: usrs.m c:objc(cs)Foo(cm)kingkong Extent=[30:1 - 30:17]
+// CHECK: usrs.m c:objc(cs)Foo(py)d1 Extent=[31:1 - 31:17]
// CHECK: usrs.m c:objc(cs)Foo(im)d1 Extent=[31:15 - 31:17]
// CHECK: usrs.m c:objc(cs)Foo(im)setD1: Extent=[31:15 - 31:17]
// CHECK: usrs.m c:usrs.m at 352objc(cs)Foo(im)setD1:@d1 Extent=[31:15 - 31:17]
@@ -160,11 +160,11 @@
// CHECK-source: usrs.m:26:3: TypeRef=id:0:0 Extent=[26:3 - 26:5]
// CHECK-source: usrs.m:27:6: ObjCIvarDecl=y:27:6 (Definition) Extent=[27:6 - 27:7]
// CHECK-source: usrs.m:27:3: TypeRef=id:0:0 Extent=[27:3 - 27:5]
-// CHECK-source: usrs.m:31:15: ObjCPropertyDecl=d1:31:15 Extent=[31:1 - 31:17]
// CHECK-source: usrs.m:29:1: ObjCInstanceMethodDecl=godzilla:29:1 Extent=[29:1 - 29:17]
// CHECK-source: usrs.m:29:4: TypeRef=id:0:0 Extent=[29:4 - 29:6]
// CHECK-source: usrs.m:30:1: ObjCClassMethodDecl=kingkong:30:1 Extent=[30:1 - 30:17]
// CHECK-source: usrs.m:30:4: TypeRef=id:0:0 Extent=[30:4 - 30:6]
+// CHECK-source: usrs.m:31:15: ObjCPropertyDecl=d1:31:15 Extent=[31:1 - 31:17]
// CHECK-source: usrs.m:31:15: ObjCInstanceMethodDecl=d1:31:15 Extent=[31:15 - 31:17]
// CHECK-source: usrs.m:31:15: ObjCInstanceMethodDecl=setD1::31:15 Extent=[31:15 - 31:17]
// CHECK-source: usrs.m:31:15: ParmDecl=d1:31:15 (Definition) Extent=[31:15 - 31:17]
More information about the llvm-branch-commits
mailing list