[clang] [clang][frontend] Make DumpModuleInfoAction emit the full macro (PR #85745)
Zhang Yi via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 21 02:15:58 PDT 2024
https://github.com/zhanyi22333 updated https://github.com/llvm/llvm-project/pull/85745
>From 61b24269867dcec12c8fcab0c26b444f33a57454 Mon Sep 17 00:00:00 2001
From: root <root at DESKTOP-15IK7GA>
Date: Sun, 21 Apr 2024 16:43:17 +0800
Subject: [PATCH 1/2] [clang][frontend] change DumpModuleInfoAction test cases.
---
.../test/Modules/cxx20-module-file-info-macros.cpp | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/clang/test/Modules/cxx20-module-file-info-macros.cpp b/clang/test/Modules/cxx20-module-file-info-macros.cpp
index 3b67e9b9acd410..567d21cf1fa43d 100644
--- a/clang/test/Modules/cxx20-module-file-info-macros.cpp
+++ b/clang/test/Modules/cxx20-module-file-info-macros.cpp
@@ -40,6 +40,11 @@
// CHECK-DAG: FUNC_Macro
// CHECK-DAG: CONSTANT
// CHECK-DAG: FOO
+// CHECK: Macro Definition Bodies:
+// CHECK-DAG: REDEFINE
+// CHECK-DAG: FUNC_Macro(X) (X+1)
+// CHECK-DAG: CONSTANT 43
+// CHECK-DAG: FOO
// CHECK-NEXT: ===
//--- include_foo.h
@@ -49,6 +54,10 @@
// CHECK-DAG: CONSTANT
// CHECK-DAG: FUNC_Macro
// CHECK-DAG: FOO
+// CHECK: Macro Definition Bodies:
+// CHECK-DAG: FUNC_Macro(X) (X+1)
+// CHECK-DAG: CONSTANT 43
+// CHECK-DAG: FOO
// CHECK-NEXT: ===
//--- import_foo.h
@@ -58,6 +67,10 @@ import "foo.h";
// CHECK-DAG: CONSTANT
// CHECK-DAG: FUNC_Macro
// CHECK-DAG: FOO
+// CHECK: Macro Definition Bodies:
+// CHECK-DAG: FUNC_Macro
+// CHECK-DAG: CONSTANT
+// CHECK-DAG: FOO
// CHECK-NEXT: ===
//--- named_module.cppm
@@ -66,3 +79,4 @@ module;
export module M;
#define M_Module 43
// CHECK-NOT: Macro Definitions:
+// CHECK-NOT: Macro Definition Bodies:
>From ce3e5abfe2d994974d3a41b98f7e152e358afdb7 Mon Sep 17 00:00:00 2001
From: root <root at DESKTOP-15IK7GA>
Date: Sun, 21 Apr 2024 16:45:04 +0800
Subject: [PATCH 2/2] [clang][frontend] Make DumpModuleInfoAction emit the full
macro.
---
clang/lib/Frontend/FrontendActions.cpp | 61 ++++++++++++++++++++++----
1 file changed, 53 insertions(+), 8 deletions(-)
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp
index 04eb1041326713..3800958e34cca5 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -943,17 +943,62 @@ void DumpModuleInfoAction::ExecuteAction() {
for (/*<IdentifierInfo *, MacroState> pair*/ const auto &Macro :
FilteredMacros)
Out << " " << Macro.first->getName() << "\n";
- }
- // Now let's print out any modules we did not see as part of the Primary.
- for (const auto &SM : SubModMap) {
- if (!SM.second.Seen && SM.second.Mod) {
- Out << " " << ModuleKindName(SM.second.Kind) << " '" << SM.first
- << "' at index #" << SM.second.Idx
- << " has no direct reference in the Primary\n";
+ // Emit the macro definition bodies completely.
+ Out << " Macro Definition Bodies:\n";
+ for (const auto &Macro : FilteredMacros) {
+ Out << " " << Macro.first->getName();
+ clang::MacroInfo *MI = PP.getMacroInfo(Macro.first);
+ if (MI == nullptr) {
+ Out << '\n';
+ continue;
+ }
+ if (MI->isFunctionLike()) {
+ Out << '(';
+ if (!MI->param_empty()) {
+ MacroInfo::param_iterator AI = MI->param_begin(),
+ E = MI->param_end();
+ for (; AI + 1 != E; ++AI) {
+ Out << (*AI)->getName();
+ Out << ',';
+ }
+
+ // Last argument.
+ if ((*AI)->getName() == "__VA_ARGS__")
+ Out << "...";
+ else
+ Out << (*AI)->getName();
+ }
+
+ if (MI->isGNUVarargs())
+ // #define foo(x...)
+ Out << "...";
+
+ Out << ')';
+ }
+
+ SmallString<128> SpellingBuffer;
+ bool First = true;
+ for (const auto &T : MI->tokens()) {
+ if (First || T.hasLeadingSpace())
+ Out << " ";
+ First = false;
+
+ Out << PP.getSpelling(T, SpellingBuffer);
+ }
+ Out << '\n';
+ }
+
+ // Now let's print out any modules we did not see as part of the Primary.
+ for (const auto &SM : SubModMap) {
+ if (!SM.second.Seen && SM.second.Mod) {
+ Out << " " << ModuleKindName(SM.second.Kind) << " '" << SM.first
+ << "' at index #" << SM.second.Idx
+ << " has no direct reference in the Primary\n";
+ }
}
+ Out << " ====== ======\n";
}
- Out << " ====== ======\n";
}
// The reminder of the output is produced from the listener as the AST
More information about the cfe-commits
mailing list