[cfe-commits] [PATCH] ObjC: interface decls pointing to implementation decls
steve naroff
snaroff at apple.com
Mon Jul 20 11:34:36 PDT 2009
On Jul 20, 2009, at 2:18 PM, Argyrios Kyrtzidis wrote:
>
> On Jul 20, 2009, at 5:50 AM, steve naroff wrote:
>
>> Hey Argyrios,
>>
>> I really like the idea of moving this association from Sema-
>> >ASTContext.
>>
>> From my perspective, adding getImplementation to the
>> ObjCContainerDecl AST has the following drawbacks:
>>
>> - The ObjCImplDecl is rarely used. For example Cocoa.h contains
>> ~700 "containers" that don't have implementations (which include
>> classes, categories, and protocols). Even for non-system classes/
>> categories/protocols, the slot would be rarely used as well (since
>> most ObjC files/modules contain a very small number of
>> implementations...1 is very common).
>> - The ObjCImplDecl doesn't make sense for protocols (since they
>> don't have an implementation).
>>
>> Did you consider adding the following API to ASTContext?
>>
>> For example...
>>
>> ObjCImplementationDecl
>> *ASTContext::getImplementation(ObjCInterfaceDecl *);
>> ObjCCategoryImplDecl
>> *ASTContext::getImplementation(ObjCCategoryDecl *);
>>
>> ASTContext would use a "Map" to associate the ObjCContainerDecl
>> with it's ObjCImplDecl.
>
> Hey great idea!
>
> Please see attached patch.
>
Looks great. I really like the following "convenience" functions:
+ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
+ return getASTContext().getObjCImplementation(
+
const_cast<ObjCInterfaceDecl*>(this));
+}
+
+void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl
*ImplD) {
+ getASTContext().setObjCImplementation(this, ImplD);
+}
+
Now that every Decl can get a pointer to it's ASTContext (something
Chris reminded me of earlier today), I bet there are other interesting
space optimizations that we can make to decls (*without* complicating
the API:-). For example, *every* ParmVarDecl currently has a
DefaultArg slot (that is only available for C++). Cocoa.h has 30,000
ParmVarDecl's! Might be interesting to consider using an ASTContext
Map to store these as well.
snaroff
> -Argiris
>
> <objc_impl.patch>
>
>
More information about the cfe-commits
mailing list