Dump AST without control codes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Dump AST without control codes

Richard Smith via cfe-dev
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'?

Regards,

Michael Collison



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Dump AST without control codes

Richard Smith via cfe-dev

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.

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev