Accessing AST

Swhhcsj Jrwhcjxd swhhcsjjrwhcjxd@gmail.com
Tue Nov 28 18:31:27 GMT 2023


How to access AST for a given .cpp file after it is parsed by cp/parser.cc
?

Looking at struct cp_parser, there are several tree fields, but none of
them seem to correspond to the AST.  None of the functions downstream from
parse_file() seem to access any object that would resemble AST. So I have
trouble locating where the constructed AST is stored.

I would like to traverse the AST to do some minor modifications, like
setting unassigned pointers to NULL, checking bounds for pointer
arithmetics in expressions like (x+n), preventing pointer casts to (long
int), preventing pointer casts ( or checking object alignment, to ensure
consistency of pointer cast) and the like, for which AST seems like the
place to do these alterations.


Thanks,
schw


More information about the Gcc-help mailing list