[cfe-dev] Written name of conversion operator

Abramo Bagnara abramo.bagnara at gmail.com
Fri Jun 4 02:35:32 PDT 2010


Il 04/06/2010 09:56, John McCall ha scritto:
> On Jun 3, 2010, at 11:54 PM, Abramo Bagnara wrote:
>> We have attempted to extract from AST the name of operator written in
>> the source but we have failed:
>>
>> - using the DeclarationName we get the "wrong" name each time the name
>> is not the one of the canonical type
>>
>> - using the TypeSourceInfo of CXXConversionDecl should be always correct
>> for operator declaration, but it fails on operator call if the name
>> specified in the call is different from the one in the declaration
>>
>> Is there a know way to obtain the written name?
> 
> Unfortunately, no, and I'm not sure there's a straightforward way to make this possible, either.  Possibly some extra storage on a DeclRefExpr / UnresolvedExpr?

... and also in the three kinds of MemberExpr :-(

I'd like to propose you a whole different approach: non canonical
DeclarationName.

The equality comparison would become:

  /// operator== - Determine whether the specified names are identical..
  friend bool operator==(DeclarationName LHS, DeclarationName RHS) {
    return LHS.getCanonical() == RHS.getCanonical();
  }

The size of DeclarationName would not change.

About getCanonical() we have a few options from which to choose taking
in account speed/space tradeoff:

1) each object pointed by DeclarationName ptr contains a "Canonical"
field that getCanonical() implementation read unconditionally.

2) only c++ conversion operator id has a canonical field so
getCanonical() implementation uses a conditional on name kind




More information about the cfe-dev mailing list