Skip to content

Instantly share code, notes, and snippets.

@aaronpuchert
Last active April 10, 2021 21:07
Show Gist options
  • Save aaronpuchert/5f8c08347f6fb1cb4020e9561b5ccbc5 to your computer and use it in GitHub Desktop.
Save aaronpuchert/5f8c08347f6fb1cb4020e9561b5ccbc5 to your computer and use it in GitHub Desktop.
Remove some clutter from Clang's AST dump
#!/usr/bin/sed -f
# Remove hard-coded typedefs in the beginning.
2,+13d
# Remove addresses from Stmts, Attrs, Comments.
s/\o033\[0m\o033\[0;1;35m\([A-Za-z]*\)\o033\[0m\o033\[0;33m 0x[0-9a-f]*/\o033[0m\o033[0;1;35m\1\o033[0m\o033[0;33m/g
s/\o033\[0m\o033\[0;1;34m\([A-Za-z]*\)\o033\[0m\o033\[0;33m 0x[0-9a-f]*/\o033[0m\o033[0;1;34m\1\o033[0m\o033[0;33m/g
s/\o033\[0m\o033\[0;34m\([A-Za-z]*\)\o033\[0m\o033\[0;33m 0x[0-9a-f]*/\o033[0m\o033[0;34m\1\o033[0m\o033[0;33m/g
# Remove source locations and ranges.
s/ <\o033\[0;33m[^\o033]*\o033\[0m>//g
s/ <\o033\[0;33m[^\o033]*\o033\[0m, \o033\[0;33m[^\o033]*\o033\[0m>//g
s/ \o033\[0;33m[^\o033]*\o033\[0m//g
# Write types italic instead of in '', use → instead of : for canonicalization.
s/\o033\[0;32m'\([^']*\)'\o033\[0m/\o033[0;3;32m\1\o033[0m/g
s/\o033\[0;32m'\([^']*\)':'\([^']*\)'\o033\[0m/\o033[0;3;32m\1\o033[23m → \o033[3m\2\o033[0m/g
@aaronpuchert
Copy link
Author

The addresses are mostly useful on declarations, and source ranges are often not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment