[cfe-dev] Patch for IdentifierResolver

Argiris Kirtzidis akyrtzi at gmail.com
Wed Apr 9 15:35:59 PDT 2008


Chris Lattner wrote:
> Steve and I were talking about this and came up with a potentially 
> interesting refinement to your approach.  The observation we make is 
> that shadowing of decls is actually really really rare in practice. It 
> would be interesting to see stats, but I bet only a very small 
> percentage of identifiers every have a scope chain with length > 1.
Yes, this is true. For "carbon.h", for a total of 41358 identifiers, 
only 1092 get a scope chain length > 1. That's just 2.64 %.
> To take advantage of this, you could abuse the FETokenInfo a bit :), 
> like we do in the 'Selector' class: if the field is null, it obviously 
> doesn't point to anything.  If non-null and the low bit is clear, you 
> could treat it as a pointer to a single unshadowed decl node.  If 
> non-null with the low bit set, you could treat it as a pointer to the 
> IdDeclInfo.
>
> This would keep the common case (no shadowing) extraordinarily cheap, 
> while allowing graceful fallback when there is shadowing.  What do you 
> think?
Excellent idea! Try out the attached patch and let me know what you think:

-Added 'IdentifierResolver' class that handles the shadowed decls 
identifier chains and performs name lookup.
-Replaced get/setFETokenInfo calls from Sema with calls to 
IdentifierResolver'methods:

  /// AddDecl - Link the decl to its shadowed decl chain
  void AddDecl(NamedDecl *D, Scope *S);

  /// AddGlobalDecl - Link the decl at the top of the shadowed decl chain
  void AddGlobalDecl(NamedDecl *D);

  /// RemoveDecl - Unlink the decl from its shadowed decl chain
  bool RemoveDecl(NamedDecl *D);

  /// Lookup - Find the non-shadowed decl that belongs to a particular
  /// Decl::IdentifierNamespace.
  NamedDecl *Lookup(const IdentifierInfo *II, unsigned NSI);


-Argiris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: idresolver.patch
Type: text/x-diff
Size: 16784 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080409/db66e443/attachment.patch>


More information about the cfe-dev mailing list