forked from OSchip/llvm-project
Use property-based serialization for TemplateName.
This commit is contained in:
parent
6887ccfcf2
commit
a9db0d9f17
|
@ -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<NamedDecl *, 8> buffer;
|
||||
auto overloadsArray = asImpl().template readArray<NamedDecl*>(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(
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -296,3 +296,108 @@ let Class = PropertyTypeCase<DeclarationName, "CXXUsingDirective"> in {
|
|||
return DeclarationName::getUsingDirectiveName();
|
||||
}]>;
|
||||
}
|
||||
|
||||
// Type cases for TemplateName.
|
||||
def : PropertyTypeKind<TemplateName, TemplateNameKind, "node.getKind()">;
|
||||
let Class = PropertyTypeCase<TemplateName, "Template"> in {
|
||||
def : Property<"declaration", TemplateDeclRef> {
|
||||
let Read = [{ node.getAsTemplateDecl() }];
|
||||
}
|
||||
def : Creator<[{
|
||||
return TemplateName(declaration);
|
||||
}]>;
|
||||
}
|
||||
let Class = PropertyTypeCase<TemplateName, "OverloadedTemplate"> in {
|
||||
def : Property<"overloads", Array<NamedDeclRef>> {
|
||||
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<TemplateName, "AssumedTemplate"> in {
|
||||
def : Property<"name", DeclarationName> {
|
||||
let Read = [{ node.getAsAssumedTemplateName()->getDeclName() }];
|
||||
}
|
||||
def : Creator<[{
|
||||
return ctx.getAssumedTemplateName(name);
|
||||
}]>;
|
||||
}
|
||||
let Class = PropertyTypeCase<TemplateName, "QualifiedTemplate"> 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<TemplateName, "DependentTemplate"> in {
|
||||
def : ReadHelper<[{
|
||||
auto dtn = node.getAsDependentTemplateName();
|
||||
}]>;
|
||||
def : Property<"qualifier", NestedNameSpecifier> {
|
||||
let Read = [{ dtn->getQualifier() }];
|
||||
}
|
||||
def : Property<"identifier", Optional<Identifier>> {
|
||||
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<TemplateName, "SubstTemplateTemplateParm"> 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<TemplateName, "SubstTemplateTemplateParmPack"> 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);
|
||||
}]>;
|
||||
}
|
||||
|
|
|
@ -119,6 +119,10 @@ public:
|
|||
|
||||
iterator begin() const { return getStorage(); }
|
||||
iterator end() const { return getStorage() + size(); }
|
||||
|
||||
llvm::ArrayRef<NamedDecl*> decls() const {
|
||||
return llvm::makeArrayRef(begin(), end());
|
||||
}
|
||||
};
|
||||
|
||||
/// A structure for storing an already-substituted template template
|
||||
|
|
Loading…
Reference in New Issue