[cfe-dev] Dump AST without control codes

Stephen Kelly via cfe-dev cfe-dev at lists.llvm.org
Sun Dec 9 04:29:40 PST 2018


On 09/12/2018 07:04, Michael Collison via cfe-dev wrote:
> Hello,
> 
> I am using the clang C++ api to dump filtered declarations to a file 
> using decl->dump(f). The problem I am encountering is the resulting file 
> contains control codes to colorize the display. Is there any way to 
> programmatically dump the ast to achieve the same effect as:
> 
> 'clang -Xclang -ast-dump -fno-diagnostics-color'?


Currently it seems the only way is to set showColors to false in the 
diagnostics engine.

  SourceManager->getDiagnostics().setShowColor(false);
  decl->dump();

In a cruel twist of API, setShowColor() without an explicit argument 
will default to disabling color. So you can use

  // Turn color off!
  SourceManager->getDiagnostics().setShowColor();
  decl->dump();

if you want instead until that API gets fixed.

Thanks,

Stephen.




More information about the cfe-dev mailing list