From a9db0d9f17f39d6aded8cdae675d94a94d63bc99 Mon Sep 17 00:00:00 2001 From: John McCall Date: Mon, 16 Dec 2019 03:59:21 -0500 Subject: [PATCH] Use property-based serialization for TemplateName. --- clang/include/clang/AST/AbstractBasicReader.h | 59 --------------- clang/include/clang/AST/AbstractBasicWriter.h | 56 -------------- clang/include/clang/AST/PropertiesBase.td | 105 ++++++++++++++++++++++++++ clang/include/clang/AST/TemplateName.h | 4 + 4 files changed, 109 insertions(+), 115 deletions(-) diff --git a/clang/include/clang/AST/AbstractBasicReader.h b/clang/include/clang/AST/AbstractBasicReader.h index 3685226..30eb5cf 100644 --- a/clang/include/clang/AST/AbstractBasicReader.h +++ b/clang/include/clang/AST/AbstractBasicReader.h @@ -197,65 +197,6 @@ public: return FunctionProtoType::ExtParameterInfo::getFromOpaqueValue(value); } - TemplateName readTemplateName() { - auto &ctx = getASTContext(); - auto kind = asImpl().readTemplateNameKind(); - switch (kind) { - case TemplateName::Template: - return TemplateName(asImpl().readTemplateDeclRef()); - - case TemplateName::OverloadedTemplate: { - SmallVector buffer; - auto overloadsArray = asImpl().template readArray(buffer); - - // Copy into an UnresolvedSet to satisfy the interface. - UnresolvedSet<8> overloads; - for (auto overload : overloadsArray) { - overloads.addDecl(overload); - } - - return ctx.getOverloadedTemplateName(overloads.begin(), overloads.end()); - } - - case TemplateName::AssumedTemplate: { - auto name = asImpl().readDeclarationName(); - return ctx.getAssumedTemplateName(name); - } - - case TemplateName::QualifiedTemplate: { - auto qual = asImpl().readNestedNameSpecifier(); - auto hasTemplateKeyword = asImpl().readBool(); - auto templateDecl = asImpl().readTemplateDeclRef(); - return ctx.getQualifiedTemplateName(qual, hasTemplateKeyword, - templateDecl); - } - - case TemplateName::DependentTemplate: { - auto qual = asImpl().readNestedNameSpecifier(); - auto isIdentifier = asImpl().readBool(); - if (isIdentifier) { - return ctx.getDependentTemplateName(qual, asImpl().readIdentifier()); - } else { - return ctx.getDependentTemplateName(qual, - asImpl().readOverloadedOperatorKind()); - } - } - - case TemplateName::SubstTemplateTemplateParm: { - auto param = asImpl().readTemplateTemplateParmDeclRef(); - auto replacement = asImpl().readTemplateName(); - return ctx.getSubstTemplateTemplateParm(param, replacement); - } - - case TemplateName::SubstTemplateTemplateParmPack: { - auto param = asImpl().readTemplateTemplateParmDeclRef(); - auto replacement = asImpl().readTemplateName(); - return ctx.getSubstTemplateTemplateParmPack(param, replacement); - } - } - llvm_unreachable("bad template name kind"); - } - TemplateArgument readTemplateArgument(bool canonicalize = false) { if (canonicalize) { return getASTContext().getCanonicalTemplateArgument( diff --git a/clang/include/clang/AST/AbstractBasicWriter.h b/clang/include/clang/AST/AbstractBasicWriter.h index d9ff713..552a482 100644 --- a/clang/include/clang/AST/AbstractBasicWriter.h +++ b/clang/include/clang/AST/AbstractBasicWriter.h @@ -178,62 +178,6 @@ public: asImpl().writeUInt32(epi.getOpaqueValue()); } - void writeTemplateName(TemplateName name) { - asImpl().writeTemplateNameKind(name.getKind()); - switch (name.getKind()) { - case TemplateName::Template: - asImpl().writeDeclRef(name.getAsTemplateDecl()); - return; - - case TemplateName::OverloadedTemplate: { - OverloadedTemplateStorage *overload = name.getAsOverloadedTemplate(); - asImpl().writeArray(llvm::makeArrayRef(overload->begin(), - overload->end())); - return; - } - - case TemplateName::AssumedTemplate: { - AssumedTemplateStorage *assumed = name.getAsAssumedTemplateName(); - asImpl().writeDeclarationName(assumed->getDeclName()); - return; - } - - case TemplateName::QualifiedTemplate: { - QualifiedTemplateName *qual = name.getAsQualifiedTemplateName(); - asImpl().writeNestedNameSpecifier(qual->getQualifier()); - asImpl().writeBool(qual->hasTemplateKeyword()); - asImpl().writeDeclRef(qual->getTemplateDecl()); - return; - } - - case TemplateName::DependentTemplate: { - DependentTemplateName *dep = name.getAsDependentTemplateName(); - asImpl().writeNestedNameSpecifier(dep->getQualifier()); - asImpl().writeBool(dep->isIdentifier()); - if (dep->isIdentifier()) - asImpl().writeIdentifier(dep->getIdentifier()); - else - asImpl().writeOverloadedOperatorKind(dep->getOperator()); - return; - } - - case TemplateName::SubstTemplateTemplateParm: { - auto subst = name.getAsSubstTemplateTemplateParm(); - asImpl().writeDeclRef(subst->getParameter()); - asImpl().writeTemplateName(subst->getReplacement()); - return; - } - - case TemplateName::SubstTemplateTemplateParmPack: { - auto substPack = name.getAsSubstTemplateTemplateParmPack(); - asImpl().writeDeclRef(substPack->getParameterPack()); - asImpl().writeTemplateArgument(substPack->getArgumentPack()); - return; - } - } - llvm_unreachable("bad template name kind"); - } - void writeTemplateArgument(const TemplateArgument &arg) { asImpl().writeTemplateArgumentKind(arg.getKind()); switch (arg.getKind()) { diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td index c25e953..5f5ad88 100644 --- a/clang/include/clang/AST/PropertiesBase.td +++ b/clang/include/clang/AST/PropertiesBase.td @@ -296,3 +296,108 @@ let Class = PropertyTypeCase in { return DeclarationName::getUsingDirectiveName(); }]>; } + +// Type cases for TemplateName. +def : PropertyTypeKind; +let Class = PropertyTypeCase in { + def : Property<"declaration", TemplateDeclRef> { + let Read = [{ node.getAsTemplateDecl() }]; + } + def : Creator<[{ + return TemplateName(declaration); + }]>; +} +let Class = PropertyTypeCase in { + def : Property<"overloads", Array> { + let Read = [{ node.getAsOverloadedTemplate()->decls() }]; + } + def : Creator<[{ + // Copy into an UnresolvedSet to satisfy the interface. + UnresolvedSet<8> overloadSet; + for (auto overload : overloads) { + overloadSet.addDecl(overload); + } + + return ctx.getOverloadedTemplateName(overloadSet.begin(), + overloadSet.end()); + }]>; +} +let Class = PropertyTypeCase in { + def : Property<"name", DeclarationName> { + let Read = [{ node.getAsAssumedTemplateName()->getDeclName() }]; + } + def : Creator<[{ + return ctx.getAssumedTemplateName(name); + }]>; +} +let Class = PropertyTypeCase in { + def : ReadHelper<[{ + auto qtn = node.getAsQualifiedTemplateName(); + }]>; + def : Property<"qualifier", NestedNameSpecifier> { + let Read = [{ qtn->getQualifier() }]; + } + def : Property<"hasTemplateKeyword", Bool> { + let Read = [{ qtn->hasTemplateKeyword() }]; + } + def : Property<"declaration", TemplateDeclRef> { + let Read = [{ qtn->getTemplateDecl() }]; + } + def : Creator<[{ + return ctx.getQualifiedTemplateName(qualifier, hasTemplateKeyword, + declaration); + }]>; +} +let Class = PropertyTypeCase in { + def : ReadHelper<[{ + auto dtn = node.getAsDependentTemplateName(); + }]>; + def : Property<"qualifier", NestedNameSpecifier> { + let Read = [{ dtn->getQualifier() }]; + } + def : Property<"identifier", Optional> { + let Read = [{ makeOptionalFromPointer( + dtn->isIdentifier() + ? dtn->getIdentifier() + : nullptr) }]; + } + def : Property<"operatorKind", OverloadedOperatorKind> { + let Conditional = [{ identifier }]; + let Read = [{ dtn->getOperator() }]; + } + def : Creator<[{ + if (identifier) { + return ctx.getDependentTemplateName(qualifier, *identifier); + } else { + return ctx.getDependentTemplateName(qualifier, *operatorKind); + } + }]>; +} +let Class = PropertyTypeCase in { + def : ReadHelper<[{ + auto parm = node.getAsSubstTemplateTemplateParm(); + }]>; + def : Property<"parameter", TemplateTemplateParmDeclRef> { + let Read = [{ parm->getParameter() }]; + } + def : Property<"replacement", TemplateName> { + let Read = [{ parm->getReplacement() }]; + } + def : Creator<[{ + return ctx.getSubstTemplateTemplateParm(parameter, replacement); + }]>; +} +let Class = PropertyTypeCase in { + def : ReadHelper<[{ + auto parm = node.getAsSubstTemplateTemplateParmPack(); + }]>; + def : Property<"parameterPack", TemplateTemplateParmDeclRef> { + let Read = [{ parm->getParameterPack() }]; + } + def : Property<"argumentPack", TemplateArgument> { + let Read = [{ parm->getArgumentPack() }]; + } + def : Creator<[{ + return ctx.getSubstTemplateTemplateParmPack(parameterPack, argumentPack); + }]>; +} diff --git a/clang/include/clang/AST/TemplateName.h b/clang/include/clang/AST/TemplateName.h index 4cc6f5e..e99f121 100644 --- a/clang/include/clang/AST/TemplateName.h +++ b/clang/include/clang/AST/TemplateName.h @@ -119,6 +119,10 @@ public: iterator begin() const { return getStorage(); } iterator end() const { return getStorage() + size(); } + + llvm::ArrayRef decls() const { + return llvm::makeArrayRef(begin(), end()); + } }; /// A structure for storing an already-substituted template template -- 2.7.4