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

Nick Galbreath nickg at modp.com
Fri Oct 17 13:54:45 PDT 2008


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



More information about the cfe-dev mailing list