[cfe-commits] r61735 - in /cfe/trunk: Driver/ASTConsumers.cpp docs/InternalsManual.html include/clang/AST/DeclBase.h include/clang/AST/DeclCXX.h include/clang/Parse/Action.h lib/AST/DeclBase.cpp lib/AST/DeclCXX.cpp lib/AST/DeclSerialization.cpp lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Sema/IdentifierResolver.cpp lib/Sema/IdentifierResolver.h lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/SemaCXX/qualified-id-lookup.cpp

Chris Lattner clattner at apple.com
Mon Jan 5 22:49:23 PST 2009


On Jan 5, 2009, at 11:45 AM, Douglas Gregor wrote:

> Author: dgregor
> Date: Mon Jan  5 13:45:36 2009
> New Revision: 61735
>
> URL: http://llvm.org/viewvc/llvm-project?rev=61735&view=rev
> Log:
> Introduce support for "transparent" DeclContexts, which are
> DeclContexts whose members are visible from enclosing DeclContexts up
> to (and including) the innermost enclosing non-transparent
> DeclContexts. Transparent DeclContexts unify the mechanism to be used
> for various language features, including C enumerations, anonymous
> unions, C++0x inline namespaces, and C++ linkage
> specifications. Please refer to the documentation in the Clang
> internals manual for more information.

This is great work, I really like how it simplifies LinkageSpecDecl  
and unifies these underlying concepts!

> +/// buildLookup - Build the lookup data structure with all of the
> +/// declarations in DCtx (and any other contexts linked to it or
> +/// transparent contexts nested within it).
> +void DeclContext::buildLookup(ASTContext &Context, DeclContext  
> *DCtx) {
> +  for (; DCtx; DCtx = DCtx->getNextContext()) {
> +    for (decl_iterator D = DCtx->decls_begin(); D != DCtx- 
> >decls_end(); ++D) {

This recomputes DCtx->decls_end() each time through the loop.

>
> /// true if 'D' belongs to the given declaration context.
> bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx,
>                                        ASTContext &Context, Scope  
> *S) const {
> +  while (Ctx->isTransparentContext())
> +    Ctx = Ctx->getParent();
> +
>   if (Ctx->isFunctionOrMethod()) {
> +    // Ignore the scopes associated within transparent declaration  
> contexts.
> +    while (S->getEntity() &&
> +           ((DeclContext *)S->getEntity())->isTransparentContext())
> +      S = S->getParent();

Do you think other places will want to skip transparent contexts like  
this?  If so, would it make sense to make this a helper function?  I  
see some similar loops in SemaDecl.cpp.

> +void Sema::ActOnEnumStartDefinition(Scope *S, DeclTy *EnumD) {
> +  EnumDecl *Enum = cast_or_null<EnumDecl>((Decl *)EnumD);
> +
> +  if (Enum) {
> +    // Enter the enumeration context.
> +    PushDeclContext(S, Enum);
> +  }
> +}

If Enum is null, will the "popdeclcontext" be properly nullified as  
well, or will there be a push/pop imbalance?

>
> +
> Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
>                                       DeclTy *lastEnumConst,
>                                       SourceLocation IdLoc,  
> IdentifierInfo *Id,
> @@ -3212,20 +3231,22 @@
> void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
>                          DeclTy **Elements, unsigned NumElements) {
>   EnumDecl *Enum = cast<EnumDecl>(static_cast<Decl*>(EnumDeclX));
> +  QualType EnumType = Context.getTypeDeclType(Enum);
>
> +  if (EnumType->getAsEnumType()->getDecl()->isDefinition()) {

Heh, this is similar to the code I was hassling Sebastian about.  Is  
it really necessary to go from Decl -> type -> Decl?  Maybe there  
should be a "get canonical decl" method that does the decl->type->decl  
dance under the covers?  I'd much rather see:

  if (EnumType->getCanonicalDecl()->isDefinition()) {

than the above dance.  Feel free to pick a better name than Canonical  
if appropriate.

-Chris




More information about the cfe-commits mailing list