[cfe-commits] r130628 - in /cfe/trunk: include/clang/AST/ lib/AST/ lib/Sema/ lib/Serialization/
Douglas Gregor
dgregor at apple.com
Sun May 1 08:22:05 PDT 2011
On Apr 30, 2011, at 5:51 PM, Chandler Carruth wrote:
> Author: chandlerc
> Date: Sat Apr 30 19:51:33 2011
> New Revision: 130628
>
> URL: http://llvm.org/viewvc/llvm-project?rev=130628&view=rev
> Log:
> Re-applies the patch first applied way back in r106099, with
> accompanying fixes to make it work today.
>
> The core of this patch is to provide a link from a TemplateTypeParmType
> back to the TemplateTypeParmDecl node which declared it. This in turn
> provides much more precise information about the type, where it came
> from, and how it functions for AST consumers.
Excellent!
>
> Modified: cfe/trunk/include/clang/AST/Type.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=130628&r1=130627&r2=130628&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Sat Apr 30 19:51:33 2011
> @@ -2969,44 +2969,68 @@
> };
>
> class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
> - unsigned Depth : 15;
> - unsigned ParameterPack : 1;
> - unsigned Index : 16;
> - IdentifierInfo *Name;
> + // Helper data collector for canonical types.
> + struct CanonicalTTPTInfo {
> + unsigned Depth : 15;
> + unsigned ParameterPack : 1;
> + unsigned Index : 16;
> + };
> +
> + union {
> + // Info for the canonical type.
> + CanonicalTTPTInfo CanTTPTInfo;
> + // Info for the non-canonical type.
> + TemplateTypeParmDecl *TTPDecl;
> + };
>
> - TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N,
> - QualType Canon)
> + /// Build a non-canonical type.
> + TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon)
> : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
> - /*VariablyModified=*/false, PP),
> - Depth(D), ParameterPack(PP), Index(I), Name(N) { }
> + /*VariablyModified=*/false,
> + Canon->getAs<TemplateTypeParmType>()->CanTTPTInfo.ParameterPack),
> + TTPDecl(TTPDecl) { }
>
> + /// Build the canonical type.
> TemplateTypeParmType(unsigned D, unsigned I, bool PP)
> : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true,
> - /*VariablyModified=*/false, PP),
> - Depth(D), ParameterPack(PP), Index(I), Name(0) { }
> + /*VariablyModified=*/false, PP) {
> + CanTTPTInfo.Depth = D;
> + CanTTPTInfo.Index = I;
> + CanTTPTInfo.ParameterPack = PP;
> + }
>
> friend class ASTContext; // ASTContext creates these
>
> + const CanonicalTTPTInfo& getCanTTPTInfo() const {
> + QualType Can = getCanonicalTypeInternal();
> + return Can->getAs<TemplateTypeParmType>()->CanTTPTInfo;
> + }
Ah, this is a place to use castAs rather than getAs.
... and everything else looks good. Thanks for dusting off this old patch and getting it in!
- Doug
More information about the cfe-commits
mailing list