[cfe-dev] Written name of conversion operator

Abramo Bagnara abramo.bagnara at gmail.com
Fri Jun 4 23:26:26 PDT 2010


Il 05/06/2010 00:16, Douglas Gregor ha scritto:
> 
> 
> Something like the latter, since we absolutely must make sure that the common case of (IdentifierInfo*, SourceLocation) doesn't require an extra memory allocation. I would probably end up creating something similar to DeclarationName itself, with a bit-mangled pointer for the name and storage for the first two locations.
> 
> 	struct DeclarationNameLoc {
> 	  void *Ptr;
> 	  SourceLocations Locs[2];
> 	};

Following your guideline I've done a little case study (I've excluded
some cases I don't know):

struct DeclarationNameLoc {
  union {
    struct {
      // Already in NamedDecl, *MemberExpr or *DeclRefExpr
      // SourceLocation NameLoc;
    } Identifier;
    struct {
      TypeSourceInfo* TInfo;
    } CXXConstructorName;
    struct {
      // Already in NamedDecl, *MemberExpr or *DeclRefExpr
      // SourceLocation TildeLoc;
      TypeSourceInfo* TInfo;
    } CXXDestructorName;
    struct {
      // Already in NamedDecl, *MemberExpr or *DeclRefExpr
      // SourceLocation OperatorLoc;
      TypeSourceInfo* TInfo;
    } CXXConversionFunctionName;
    struct {
      // Already in NamedDecl, *MemberExpr or *DeclRefExpr
      // SourceLocation OperatorLoc;
      SourceLocation OpLoc;
      SourceLocation LSquareLoc;
      // Not so useful
      // SourceLocation RSquareLoc;
    } CXXOperatorName;
    struct {
      SourceLocation LQuoteLoc;
      SourceLocation RQuoteLoc;
      // Already in NamedDecl, *MemberExpr or *DeclRefExpr
      // SourceLocation NameLoc;
    } CXXLiteralOperatorName;
    struct {
      // ??
    } CXXUsingDirective;
    struct {
      // ??
    } ObjCZeroArgSelector;
    struct {
      // ??
    } ObjCOneArgSelector;
    struct {
      // ??
    } ObjCMultiArgSelector;
  };
};

The kind of info contained is identified using the available
DeclarationName.

For the kinds examined we never need to add indirection to extra memory
and the space needed is at most 8 bytes.

I believe that DeclarationNameLoc should be added to:

FunctionDecl
DeclRefExpr
DependentScopeDeclRefExpr
CXXDependentScopeMemberExpr
MemberExpr
UnresolvedMemberExpr

(also it seems there is some intersection between DeclarationNameLoc and
PseudoDestructorExpr)

We might add to these classes a method like:

DeclarationName CLASS::getDeclarationNameLocs(SourceLocation& MainLoc,
DeclarationNameLoc& Locs);

to query for complete info.

I'm missing something?

Suggestions for improvement?




More information about the cfe-dev mailing list