[clang] [clang][frontend] Make DumpModuleInfoAction emit the full macro (PR #85745)

Michael Spencer via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 9 13:51:34 PDT 2024


https://github.com/Bigcheese requested changes to this pull request.

Generally when we get the definition of a macro we loop over the tokens, for example:

```c++
  SmallString<128> SpellingBuffer;
  bool First = true;
  for (const auto &T : MI.tokens()) {
    if (!First && T.hasLeadingSpace())
      Value << ' ';

    Value << PP.getSpelling(T, SpellingBuffer);
    First = false;
  }
```

This handles all of the lexing requirements and should have the same output as your loop here. `MacroPPCallbacks::writeMacroDefinition` is a good example here. We do a similar thing in `DeclarationFragmentsBuilder::getFragmentsForMacro`, `PrintMacroDefinition` (PrintPreprocessedOutput.cpp), and `CodeCompletionResult::CreateCodeCompletionStringForMacro`.

At this point we should just have common code that does this. Code completion is a bit special as it's only printing part of it, but I'd like to see macro decl/def printing happen in a single place.

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


More information about the cfe-commits mailing list