[cfe-dev] Patch for ContextDecl

Steve Naroff snaroff at apple.com
Fri Apr 4 11:23:44 PDT 2008


On Apr 3, 2008, at 11:25 PM, Chris Lattner wrote:

>
> On Apr 3, 2008, at 3:30 PM, Argiris Kirtzidis wrote:
>>
>> -FunctionDecl, ObjCMethodDecl, TagDecl, ObjCInterfaceDecl inherit
>> from ContextDecl. With TagDecl as ContextDecl, enum constants have a
>> EnumDecl as their context.
>
> I think this makes sense, what do you think Steve?

Looks good to me.

I like adding the ContextDecl slot to ScopedDecl (instead of Decl).

It's unfortunate that all EnumConstantDecl's will grow, however as we  
discussed yesterday, we could likely streamline them by not using  
llvm::APSInt.

>
>
>> -Moved Decl class to a "DeclBase.h" along with ContextDecl class
>> -CurContext is handled by Sema
>
> Thanks!
>
>> Some comments about this approach:
>>
>> A ContextDecl chain ends at null and a null ContextDecl gets the
>> meaning of the global scope. I'm a bit uncomfortable with applying
>> meaning to a null value
>> (instead of regarding it without meaning).I'd like to try an idea to
>> use ContextDecl for name lookup (after namespaces are added) and the
>> usage of null
>> as global scope will make the code a bit less readable.
>>
>> For another example, this:
>>
>> bool isDefinedOutsideFunctionOrMethod() const {
>>  if (getContext())
>>    return !getContext()->isFunctionOrMethod();
>>  else
>>    return true;
>> }
>>
>> seems less elegant than this:
>>
>> bool ScopedDecl::isDefinedOutsideFunctionOrMethod() const {
>>  return isa<TranslationUnitDecl>(getContextDecl());
>> }
>>
>> Any thoughts on the above ?
>
> I agree, I think it would be nice to add back TranslationUnitDecl:
> it's a nice unifying concept.  There are two ways to solve the
> "function has a context but ObjCInterface doesn't" issue: one is to
> just add the pointer to objcinterface, the second is to just say "that
> is the way it should be".

I like the idea of having a TranslationUnit as well (without the  
"Decl":-)

I'd love to have it contain references to ASTContext, SourceManager,  
etc.

snaroff

>
>
> Another next step: what do you think of hoisting
> FunctionDecl::DeclChain to be a member of ContextDecl?  This would
> allow clients to iterate over all decls in a context, likewise for
> EnumDecl::ElementList etc?
>
> -Chris
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list