From 867570a2384e3445c5658f0f84cfe2acca13becc Mon Sep 17 00:00:00 2001 From: John McCall Date: Mon, 16 Dec 2019 02:11:49 -0500 Subject: [PATCH] Use property-based serialization for DeclarationName. --- clang/include/clang/AST/AbstractBasicReader.h | 42 ------------------ clang/include/clang/AST/AbstractBasicWriter.h | 38 ----------------- clang/include/clang/AST/PropertiesBase.td | 61 +++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 80 deletions(-) diff --git a/clang/include/clang/AST/AbstractBasicReader.h b/clang/include/clang/AST/AbstractBasicReader.h index b18e89b..3685226 100644 --- a/clang/include/clang/AST/AbstractBasicReader.h +++ b/clang/include/clang/AST/AbstractBasicReader.h @@ -197,48 +197,6 @@ public: return FunctionProtoType::ExtParameterInfo::getFromOpaqueValue(value); } - DeclarationName readDeclarationName() { - auto &ctx = getASTContext(); - auto kind = asImpl().readDeclarationNameKind(); - switch (kind) { - case DeclarationName::Identifier: - return DeclarationName(asImpl().readIdentifier()); - - case DeclarationName::ObjCZeroArgSelector: - case DeclarationName::ObjCOneArgSelector: - case DeclarationName::ObjCMultiArgSelector: - return DeclarationName(asImpl().readSelector()); - - case DeclarationName::CXXConstructorName: - return ctx.DeclarationNames.getCXXConstructorName( - ctx.getCanonicalType(asImpl().readQualType())); - - case DeclarationName::CXXDestructorName: - return ctx.DeclarationNames.getCXXDestructorName( - ctx.getCanonicalType(asImpl().readQualType())); - - case DeclarationName::CXXConversionFunctionName: - return ctx.DeclarationNames.getCXXConversionFunctionName( - ctx.getCanonicalType(asImpl().readQualType())); - - case DeclarationName::CXXDeductionGuideName: - return ctx.DeclarationNames.getCXXDeductionGuideName( - asImpl().readTemplateDeclRef()); - - case DeclarationName::CXXOperatorName: - return ctx.DeclarationNames.getCXXOperatorName( - asImpl().readOverloadedOperatorKind()); - - case DeclarationName::CXXLiteralOperatorName: - return ctx.DeclarationNames.getCXXLiteralOperatorName( - asImpl().readIdentifier()); - - case DeclarationName::CXXUsingDirective: - return DeclarationName::getUsingDirectiveName(); - } - llvm_unreachable("bad name kind"); - } - TemplateName readTemplateName() { auto &ctx = getASTContext(); auto kind = asImpl().readTemplateNameKind(); diff --git a/clang/include/clang/AST/AbstractBasicWriter.h b/clang/include/clang/AST/AbstractBasicWriter.h index 499e5a6..d9ff713 100644 --- a/clang/include/clang/AST/AbstractBasicWriter.h +++ b/clang/include/clang/AST/AbstractBasicWriter.h @@ -178,44 +178,6 @@ public: asImpl().writeUInt32(epi.getOpaqueValue()); } - void writeDeclarationName(DeclarationName name) { - asImpl().writeDeclarationNameKind(name.getNameKind()); - switch (name.getNameKind()) { - case DeclarationName::Identifier: - asImpl().writeIdentifier(name.getAsIdentifierInfo()); - return; - - case DeclarationName::ObjCZeroArgSelector: - case DeclarationName::ObjCOneArgSelector: - case DeclarationName::ObjCMultiArgSelector: - asImpl().writeSelector(name.getObjCSelector()); - return; - - case DeclarationName::CXXConstructorName: - case DeclarationName::CXXDestructorName: - case DeclarationName::CXXConversionFunctionName: - asImpl().writeQualType(name.getCXXNameType()); - return; - - case DeclarationName::CXXDeductionGuideName: - asImpl().writeDeclRef(name.getCXXDeductionGuideTemplate()); - return; - - case DeclarationName::CXXOperatorName: - asImpl().writeOverloadedOperatorKind(name.getCXXOverloadedOperator()); - return; - - case DeclarationName::CXXLiteralOperatorName: - asImpl().writeIdentifier(name.getCXXLiteralIdentifier()); - return; - - case DeclarationName::CXXUsingDirective: - // No extra data to emit - return; - } - llvm_unreachable("bad name kind"); - } - void writeTemplateName(TemplateName name) { asImpl().writeTemplateNameKind(name.getKind()); switch (name.getKind()) { diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td index cdab032..a3f45b0 100644 --- a/clang/include/clang/AST/PropertiesBase.td +++ b/clang/include/clang/AST/PropertiesBase.td @@ -211,3 +211,64 @@ class PropertyTypeCase : HasProperties { string Name = name; } +// DeclarationName +def : PropertyTypeKind; +let Class = PropertyTypeCase in { + def : Property<"identifier", Identifier> { + let Read = [{ node.getAsIdentifierInfo() }]; + } + def : Creator<[{ + return DeclarationName(identifier); + }]>; +} +foreach count = ["Zero", "One", "Multi"] in { + let Class = PropertyTypeCase in { + def : Property<"selector", Selector> { + let Read = [{ node.getObjCSelector() }]; + } + def : Creator<[{ + return DeclarationName(selector); + }]>; + } +} +foreach kind = ["Constructor", "Destructor", "ConversionFunction"] in { + let Class = PropertyTypeCase in { + def : Property<"type", QualType> { + let Read = [{ node.getCXXNameType() }]; + } + def : Creator<[{ + return ctx.DeclarationNames.getCXX}]#kind#[{Name( + ctx.getCanonicalType(type)); + }]>; + } +} +let Class = PropertyTypeCase in { + def : Property<"declaration", TemplateDeclRef> { + let Read = [{ node.getCXXDeductionGuideTemplate() }]; + } + def : Creator<[{ + return ctx.DeclarationNames.getCXXDeductionGuideName(declaration); + }]>; +} +let Class = PropertyTypeCase in { + def : Property<"operatorKind", OverloadedOperatorKind> { + let Read = [{ node.getCXXOverloadedOperator() }]; + } + def : Creator<[{ + return ctx.DeclarationNames.getCXXOperatorName(operatorKind); + }]>; +} +let Class = PropertyTypeCase in { + def : Property<"identifier", Identifier> { + let Read = [{ node.getCXXLiteralIdentifier() }]; + } + def : Creator<[{ + return ctx.DeclarationNames.getCXXLiteralOperatorName(identifier); + }]>; +} +let Class = PropertyTypeCase in { + def : Creator<[{ + return DeclarationName::getUsingDirectiveName(); + }]>; +} -- 2.7.4