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

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Tue Apr 9 11:08:19 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) {
----------------
kparzysz wrote:

Done.

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


More information about the flang-commits mailing list