How do I get clang to dump the AST without color?

那年仲夏 提交于 2019-12-06 19:49:17

问题


Using clang-check to dump a source code's AST, can be done with the following command:

$ clang-check -ast-dump file.c --

However, the output of this command will appear colorful within the terminal.
When I direct the output to a file, I'm stuck with all of the color escape codes:

$ clang-check -ast-dump file.c -- > out.txt  

example:

[0;1;32mTranslationUnitDecl[0m[0;33m 0x227c5c0[0m <[0;33m<invalid sloc>[0m> [0;33m<invalid sloc>[0m
[0;34m|-[0m[0;1;32mTypedefDecl[0m[0;33m 0x227cac0[0m <[0;33m<invalid sloc>[0m> [0;33m<invalid sloc>[0m implicit[0;1;36m __int128_t[0m [0;32m'__int128'[0m
[0;34m|-[0m[0;1;32mTypedefDecl[0m[0;33m 0x227cb20[0m <[0;33m<invalid sloc>[0m> [0;33m<invalid sloc>[0m implicit[0;1;36m __uint128_t[0m [0;32m'unsigned __int128'[0m
[0;34m|-[0m[0;1;32mTypedefDecl[0m[0;33m 0x227ce70[0m <[0;33m<invalid sloc>[0m> [0;33m<invalid sloc>[0m implicit[0;1;36m __builtin_va_list[0m [0;32m'__va_list_tag [1]'[0m
...

Is there a flag to disable colors in clang-check?
I tried adding the following flag, but it did not work:

--extra-arg="--no-color-diagnostics"

回答1:


You are almost correct. Try

$ clang-check -ast-dump test.c --extra-arg="-fno-color-diagnostics" -- 

Additionally, -fno-diagnostics-color and -fdiagnostics-color=never also seems to work

Reference: http://clang.llvm.org/docs/UsersManual.html#formatting-of-diagnostics



来源:https://stackoverflow.com/questions/32447542/how-do-i-get-clang-to-dump-the-ast-without-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!