[cfe-dev] Template parameters of friend declarations.

Enea Zaffanella zaffanella at cs.unipr.it
Thu Jan 31 02:07:53 PST 2013


On 01/27/2013 10:16 PM, John McCall wrote:
>
> On Jan 26, 2013, at 9:03 AM, Enea Zaffanella <zaffanella at cs.unipr.it> wrote:
>
>> On 01/25/2013 10:57 PM, John McCall wrote:
>>> On Jan 25, 2013, at 9:44 AM, Enea Zaffanella <zaffanella at cs.unipr.it> wrote:
>> [...]
>>>> Please find attached a patch for review, including
>>>> (de-)serialization and pretty printing of the new info attached to
>>>> friend type declarations. On a second though, we kept the
>>>> PointerUnion3 approach, which seems to be simpler (at least, to my
>>>> eyes) when it comes to deserializing the declaration node.
>>>
>>> Please do use post-storage.  You can look at how the template
>>> parameter packs deserialize themselves for an example of how to get
>>> the information for how much extra space to allocate;  it's really
>>> quite straightforward.
>>>
>>> John.
>>>
>>
>> Here is the revised patch for review.
>> (Also fixes method getSourceRange).
>
> +  // The number of "outer" template parameter lists in non-templatic
> +  // (currently unsupported) friend type declarations, such as
> +  //     template <class T> friend class A<T>::B;
> +  unsigned NumTPLists;
>
> Please make 'UnsupportedFriend' an unsigned : 1 bitfield and
> pack this into the remaining 31 bits.
>
> +  // The tail-allocated friend type template parameter lists (if any).
> +  TemplateParameterList **getTPLists() const {
> +    return reinterpret_cast<TemplateParameterList**>
> +      (const_cast<FriendDecl*>(this) + 1);
> +  }
> +
>
> Please just make two overloads.  One should be const and return
> a TemplateParameterList * const *.  The other should be non-const
> and return a TemplateParameterList **.
>
>     FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend,
> -             SourceLocation FriendL)
> +             SourceLocation FriendL, unsigned FriendTypeNumTPLists,
> +             TemplateParameterList **FriendTypeTPLists)
>
> This should be an ArrayRef<TemplateParameterList*>.  Just leave in
> the EmptyShell constructor but make it take a count.
>
> +  /// If this friend declaration doesn't name a type, return the inner
> +  /// declaration.
> +  NamedDecl *getFriendDecl() const {
> +    return Friend.dyn_cast<NamedDecl*>();
> +  }
> +
>
> You seem to have spuriously re-ordered the methods here.
>
>   void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
> +  // Record the number of friend type template parameter lists here
> +  // so as to simplify memory allocation during serialization.
>
> Quibble:  during *deserialization*.  Serialization is what this code is doing.
>
> Approved with those changes.
>
> John.


Committed in r174050.

Enea.



More information about the cfe-dev mailing list