Clang : What does AST (abstract syntax tree) look like?

后端 未结 3 2008
清酒与你
清酒与你 2021-02-06 01:52

Hi I am new in Compiler development, and am wondering how AST look like. I have a small section of code, and I use Clang for generating the AST. I don\'t get much information ou

3条回答
  •  迷失自我
    2021-02-06 02:09

    There is a small confusion between the various options available:

    • -ast-print will pretty-print the current AST, that is, it will render the code it understood as closely as possible to what it parsed (but making some things explicit, like the apparition of the this)
    • -ast-dump will generate a lisp-like representation of the current AST

    The pretty printer can be useful to check that the AST is lossless (ie, preserved the const-ness of such expression, etc...) but is not really about development.

    If you want to hack on the compiler, you need -ast-dump, which will generate an output that maps directly the in-memory representation of the code that was parsed.

提交回复
热议问题