[clang] 3b0eeb6 - [clang][ASTImporter] Add import of 'MacroQualifiedType'
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 16 03:03:36 PDT 2023
Author: dingfei
Date: 2023-08-16T18:03:16+08:00
New Revision: 3b0eeb6cdbd7d8f662f12c4d90bdaee7a01a6354
URL: https://github.com/llvm/llvm-project/commit/3b0eeb6cdbd7d8f662f12c4d90bdaee7a01a6354
DIFF: https://github.com/llvm/llvm-project/commit/3b0eeb6cdbd7d8f662f12c4d90bdaee7a01a6354.diff
LOG: [clang][ASTImporter] Add import of 'MacroQualifiedType'
Add import of 'MacroQualifiedType'.
Reviewed By: balazske
Differential Revision: https://reviews.llvm.org/D157780
Added:
Modified:
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 6da39ca2778bd1..cf8f23c305824d 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -419,6 +419,7 @@ namespace clang {
ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T);
ExpectedType VisitObjCObjectType(const ObjCObjectType *T);
ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T);
+ ExpectedType VisitMacroQualifiedType(const MacroQualifiedType *T);
// Importing declarations
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD,
@@ -1701,6 +1702,17 @@ ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
}
+ExpectedType
+ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
+ ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
+ if (!ToUnderlyingTypeOrErr)
+ return ToUnderlyingTypeOrErr.takeError();
+
+ IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
+ return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
+ ToIdentifier);
+}
+
//----------------------------------------------------------------------------
// Import Declarations
//----------------------------------------------------------------------------
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 9094ff4f25e7be..3aa9a458ef93ba 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -8638,6 +8638,24 @@ TEST_P(ImportInjectedClassNameType, ImportTypedefType) {
EXPECT_TRUE(ToCtx.hasSameType(ToInjTypedef, ToInjParmVar));
}
+TEST_P(ASTImporterOptionSpecificTestBase, ImportMacroQualifiedType) {
+ Decl *From, *To;
+ std::tie(From, To) = getImportedDecl(
+ R"(
+ #define CDECL __attribute__((cdecl))
+ typedef void (CDECL *X)();
+ )",
+ Lang_CXX03, "", Lang_CXX03, "X");
+
+ auto *FromTy =
+ FirstDeclMatcher<MacroQualifiedType>().match(From, macroQualifiedType());
+ auto *ToTy =
+ FirstDeclMatcher<MacroQualifiedType>().match(To, macroQualifiedType());
+
+ EXPECT_TRUE(isa<AttributedType>(FromTy->getUnderlyingType()));
+ EXPECT_TRUE(isa<AttributedType>(ToTy->getUnderlyingType()));
+}
+
TEST_P(ASTImporterOptionSpecificTestBase, ImportCorrectTemplateName) {
constexpr auto TestCode = R"(
template <class T>
More information about the cfe-commits
mailing list