[cfe-dev] question on -ast dump/print

Daniel Dunbar daniel at zuster.org
Fri Oct 17 14:37:25 PDT 2008


Unfortunately, AST dumping and printing need a fair amount of work. We
really just need someone to take this on as a project. I literally have a
sticky note on my monitor which says "printing needs love", but its been
there for some time.
I think the main thing is to move the printing logic which is in
Driver/ASTConsumers.cpp and merge it with the StmtPrinting stuff. This way
they can reuse the same pretty printing infrastructure. Once that work is
done it will be much easier to just add things on a case by case basis.

For now, the unfortunate truth is that -ast-dump and -ast-print don't work
very well, when something appears incorrect it is more often than not a
problem in the printing rather than a problem in the AST representation.

 - Daniel

On Fri, Oct 17, 2008 at 1:54 PM, Nick Galbreath <nickg at modp.com> wrote:

> Hi there,
> I'm new to clang, so please bet gentle.
>
> On revision 57719, debug build
>
> I'm a bit confused on the -ast-dump/print output.  It seems to be not
> printing global declarations.  I don't know if this is a "feature" or
> "bug" or perhaps me not understanding what should be in the AST.   I
> read the bug reports but didn't see anything relevant.  Oddly
> emit-html correctly prints out everything.
>
> here's some examples:
>
> """
> int i = 0;
> """
>
> gets turned into
>
> """
> $ clang -ast-print junk.c
> typedef char *__builtin_va_list;
> Read top-level variable decl: 'i'
> """
>
> which smells wrong... locals seems to be ok
>
> But...
>
> """
> void f() {
>  int i = 0;
> }
> """
>
> becomes
>
> """
> typedef char *__builtin_va_list;
> void f() {
>  int i = 0;
> }
> """
>
>
> However, enums are also strange:
>
> Something like
> {{{
> int f(void) {
>  enum color { RED, GREEN, BLUE};
>  enum color x = RED;
>  switch (x) {
>  case RED: return 1;
>  case GREEN: return 2;
>  case BLUE: return 3;
>  }
> }
> """
>
> gets turned into:
>
> """
> typedef char *__builtin_va_list;
>
> int f() {
>  enum color;
>  enum color x = RED;
>  switch ((x)) {
>  case RED:
>    return 1;
>  case GREEN:
>    return 2;
>  case BLUE:
>    return 3;
>  }
> }
>
> which zapped away all the enum declarations.
>
> """"
>
> thoughts?
>
> --nickg
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081017/36ff8ac2/attachment.html>


More information about the cfe-dev mailing list