[cfe-commits] r96484 - in /cfe/trunk/lib: CodeGen/CGBlocks.cpp Sema/SemaDeclObjC.cpp

Douglas Gregor dgregor at apple.com
Wed Feb 17 13:33:49 PST 2010


On Feb 17, 2010, at 10:46 AM, Fariborz Jahanian wrote:

> 
> On Feb 17, 2010, at 10:33 AM, Douglas Gregor wrote:
> 
>> Comment below...
>> 
>> Sent from my iPhone
>> 
>> On Feb 17, 2010, at 10:11 AM, Fariborz Jahanian <fjahanian at apple.com> wrote:
>> 
>>> Author: fjahanian
>>> Date: Wed Feb 17 12:10:54 2010
>>> New Revision: 96484
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=96484&view=rev
>>> Log:
>>> Use proper lexcial context for newly added ivars.
>>> 
>>> 
>>> Modified:
>>>  cfe/trunk/lib/CodeGen/CGBlocks.cpp
>>>  cfe/trunk/lib/Sema/SemaDeclObjC.cpp
>>> 
>>> Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=96484&r1=96483&r2=96484&view=diff
>>> 
>>> ==============================================================================
>>> --- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
>>> +++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Feb 17 12:10:54 2010
>>> @@ -110,6 +110,7 @@
>>> /// invoke function.
>>> static void AllocateAllBlockDeclRefs(const CodeGenFunction::BlockInfo &Info,
>>>                                    CodeGenFunction *CGF) {
>>> +#if 0
>>> // Always allocate self, as it is often handy in the debugger, even if there
>>> // is no codegen in the block that uses it.  This is also useful to always do
>>> // this as if we didn't, we'd have to figure out all code that uses a self
>>> @@ -122,6 +123,7 @@
>>>                      SelfDecl->getType(), SourceLocation(), false);
>>>   CGF->AllocateBlockDecl(BDRE);
>>> }
>>> +#endif
>>> 
>>> // FIXME: Also always forward the this pointer in C++ as well.
>>> 
>>> 
>>> Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=96484&r1=96483&r2=96484&view=diff
>>> 
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Feb 17 12:10:54 2010
>>> @@ -825,8 +825,8 @@
>>>   IDecl->setLocEnd(RBrace);
>>>   // Add ivar's to class's DeclContext.
>>>   for (unsigned i = 0, e = numIvars; i != e; ++i) {
>>> -      ivars[i]->setLexicalDeclContext(IDecl);
>>> -      IDecl->addDecl(ivars[i]);
>>> +      ivars[i]->setLexicalDeclContext(ImpDecl);
>>> +      IDecl->makeDeclVisibleInContext(ivars[i], false);
>> 
>> Also,
>> 
>> ImpDecl->addDecl(ivars[i]);
> 
>> 
>> 
>> So that this ivar is stored in the @implementation.
> 
> I am not sure about this. This feature is to conform to what gcc does, which just adds ivar to its class.
> Adding it to @implementation context messes up the lookup.

Then we should fix the lookup. Putting ivars (and any other declaration) into the right lexical context is important when we're walking the source tree, because the lexical context describes how the program was written, and that's exposed through the various Clang APIs (including CIndex). The lookup code can already deal with lookups that find names in a semantic context that is different from their lexical context; we just need to make sure that ivars in implementations get into the right semantic contexts.

	- Doug



More information about the cfe-commits mailing list