[clang][ExtractAPI] Don't print locations for anonymous tags
authorZixu Wang <zixu_wang@apple.com>
Wed, 5 Oct 2022 17:59:58 +0000 (10:59 -0700)
committerZixu Wang <zixu_wang@apple.com>
Wed, 5 Oct 2022 20:11:21 +0000 (13:11 -0700)
ExtractAPI doesn't care about locations of anonymous TagDecls. Set the
printing policy to exclude that from anonymous decl names.

Differential Revision: https://reviews.llvm.org/D135295

clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

index 969ee77..4a97ee9 100644 (file)
@@ -850,6 +850,11 @@ ExtractAPIAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
   CI.getPreprocessor().addPPCallbacks(std::make_unique<MacroCallback>(
       CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy = CI.getASTContext().getPrintingPolicy();
+  Policy.AnonymousTagLocations = false;
+  CI.getASTContext().setPrintingPolicy(Policy);
+
   return std::make_unique<ExtractAPIConsumer>(CI.getASTContext(),
                                               std::move(LCF), *API);
 }