Skip to content

Instantly share code, notes, and snippets.

@aaronpuchert
Last active December 17, 2025 14:14
Show Gist options
  • Select an option

  • Save aaronpuchert/5f8c08347f6fb1cb4020e9561b5ccbc5 to your computer and use it in GitHub Desktop.

Select an option

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 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
# Remove implicit declarations.
/^\o033\[0;34m|-\o033\[0m\o033\[0;1;32m[[:alpha:]]*\o033\[0m\o033\[0;33m 0x[0-9a-f]*\o033\[0m implicit/,/^\o033\[0;34m[|`]-\o033\[0m\o033\[0;1;32m[[:alpha:]]*\o033\[0m\o033\[0;33m 0x[0-9a-f]*\o033\[0m.[^i][^m][^p][^l][^i][^c][^i][^t]/ {
/^\o033\[0;34m[|`]-\o033\[0m\o033\[0;1;32m[[:alpha:]]*\o033\[0m\o033\[0;33m 0x[0-9a-f]*\o033\[0m.[^i][^m][^p][^l][^i][^c][^i][^t]/!d
}
# 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