[clang] [flang] [flang][Frontend] Implement printing defined macros via -dM (PR #87627)

Peter Klausler via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 9 09:52:54 PDT 2024


================
@@ -46,6 +49,38 @@ bool Definition::set_isDisabled(bool disable) {
   return was;
 }
 
+void Definition::Print(
+    llvm::raw_ostream &out, llvm::StringRef macroName) const {
+  if (!isFunctionLike_) {
+    // If it's not a function-like macro, then just print the replacement.
+    out << ' ' << replacement_.ToString();
+    return;
+  }
+
+  size_t argCount{argumentCount()};
+
+  out << '(';
+  for (size_t i{0}; i != argCount; ++i) {
+    if (i != 0) {
+      out << ", ";
+    }
+    out << argNames_[i];
+  }
+  if (isVariadic_) {
+    out << ", ...";
+  }
+  out << ") ";
+
+  for (size_t i{0}, e{replacement_.SizeInTokens()}; i != e; ++i) {
+    std::string tok{replacement_.TokenAt(i).ToString()};
+    if (size_t idx = getArgumentIndex(tok); idx < argCount) {
----------------
klausler wrote:

`std::size_t idx {GetArgumentIndex(Tok)}; ...`

https://github.com/llvm/llvm-project/pull/87627


More information about the cfe-commits mailing list