[cfe-dev] [PATCH] Ordinary name lookup for class and enum names in C++

Doug Gregor doug.gregor at gmail.com
Sun Apr 13 10:12:00 PDT 2008


On Sun, Apr 13, 2008 at 9:37 AM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
>  How about modifying IdentifierResolver::AddDecl so that, when in C++ and
> decl is a RecordDecl, it looks for 'D' in normal namespace and in the same
> scope,
>  if a decl exists, it puts the RecordDecl on top of it in the chain:
>
>  class D
>  ^- void D()
>
>  That way non-tag decls get precedence when searching in both tag and normal
> namespaces.

I went ahead with this approach. The attached patch allows searching
in both the tag and ordinary namespaces in C++, so that we get the
right name lookup for tag names without introducing implicit typedefs.
Argiris, you might want to take a look at the IdentifierResolver bits.

Interesting bits:
  - IdentifierResolver::AddDecl does exactly what Argiris suggested:
it makes sure that if there is both a tag and an ordinary name in the
same scope, the ordinary name will be on top.

  - IdentifierResolver::Lookup allows NS to be a bitmask, so that we
can search multiple namespaces.

  - Sema::LookupDecl tweaks ordinary name lookup to also look for tags
(C++ only)

  - Sema::ActOnDeclarator ignores any previous declaration it finds in
the tag namespace, because any other declarations will override them
anyway. We *may* need to do the same thing somewhere for
Objective-C++, but I didn't touch that.

  - ASTContext::getTypeDeclType retrieves the QualType for any
TypeDecl. This is the "gimmeTheType" operation that makes it look like
we have the named-types-are-typedefs invariant, even though we don't..
Note that it builds RecordType and EnumType nodes for class types and
enums, rather than TagType nodes. I've switched to using
getTypeDeclType in those places in the front end where we can end up
finding a named type; longer-term, I'd like to remove getTypedefType,
getObjCInterfaceType, and getTagDeclType from ASTContext and have all
clients call getTypeDeclType instead.

The "-rel" version of the patch is relative against the "class" tag
handling patch, here:
  http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-April/001411.html

The other version of the patch is against the latest Clang from
Subversion; it includes the class tag handling changes.

  - Doug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-class-names-bitmask.patch
Type: text/x-patch
Size: 16330 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080413/bfb8cde3/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-class-names-bitmask-rel.patch
Type: text/x-patch
Size: 12283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080413/bfb8cde3/attachment-0001.bin>


More information about the cfe-dev mailing list