diff options
author | Kim Grasman <kim.grasman@gmail.com> | 2017-02-11 14:41:53 +0100 |
---|---|---|
committer | Kim Gräsman <kim.grasman@gmail.com> | 2017-02-21 10:40:54 +0100 |
commit | 8065e52a319e1666e77a9616033afd43a2d0e378 (patch) | |
tree | 281d218a3a7c005253130a797b9f1c325235b89f | |
parent | 7cb24d257b4576a1bfc82b4dcdce81e90ea8218d (diff) |
Add optional terse flag to PrintableDecl
Make terse printing the default.
-rw-r--r-- | iwyu_ast_util.cc | 12 | ||||
-rw-r--r-- | iwyu_ast_util.h | 2 |
2 files changed, 10 insertions, 4 deletions
diff --git a/iwyu_ast_util.cc b/iwyu_ast_util.cc index 8ff8420..23b9b05 100644 --- a/iwyu_ast_util.cc +++ b/iwyu_ast_util.cc @@ -402,10 +402,16 @@ string PrintableSourceRange(SourceRange range) { return PrintableLoc(range.getBegin()) + " - " + PrintableLoc(range.getEnd()); } -string PrintableDecl(const Decl* decl) { - std::string buffer; // llvm wants regular string, not our versa-string +string PrintableDecl(const Decl* decl, bool terse/*=true*/) { + // Use the terse flag to limit the level of output to one line. + clang::PrintingPolicy policy = decl->getASTContext().getPrintingPolicy(); + policy.TerseOutput = terse; + policy.SuppressInitializers = terse; + policy.PolishForDeclaration = terse; + + std::string buffer; raw_string_ostream ostream(buffer); - decl->print(ostream); // Note: can also set indentation and printingpolicy + decl->print(ostream, policy); return ostream.str(); } diff --git a/iwyu_ast_util.h b/iwyu_ast_util.h index 1bcf4a2..dd3f5e0 100644 --- a/iwyu_ast_util.h +++ b/iwyu_ast_util.h @@ -424,7 +424,7 @@ const clang::DeclContext* GetDeclContext(const ASTNode* ast_node); string PrintableLoc(clang::SourceLocation loc); string PrintableSourceRange(clang::SourceRange range); -string PrintableDecl(const clang::Decl* decl); +string PrintableDecl(const clang::Decl* decl, bool terse=true); string PrintableStmt(const clang::Stmt* stmt); string PrintableType(const clang::Type* type); string PrintableTypeLoc(const clang::TypeLoc& typeloc); |