Issue 122257
Summary libclang: how to visit implicit declarations.
Labels new issue
Assignees
Reporter phadej
    Consider simple `u.h` header

```c
union u {
        int big;
        struct {
                char small1;
 char small2;
        };
};
```

`clang -Xclang -ast-dump -fsyntax-only` prints 

```
`-RecordDecl 0xeba4a10 <u.h:1:1, line:7:1> line:1:7 union u definition
  |-FieldDecl 0xeba4ac8 <line:2:2, col:6> col:6 big 'int'
  |-RecordDecl 0xeba4b18 <line:3:2, line:6:2> line:3:2 struct definition
  | |-FieldDecl 0xeba4bd0 <line:4:3, col:8> col:8 small1 'char'
 | `-FieldDecl 0xeba4c30 <line:5:3, col:8> col:8 small2 'char'
  |-FieldDecl 0xeba4cd8 <line:3:2> col:2 implicit 'struct u::(anonymous at u.h:3:2)'
 |-IndirectFieldDecl 0xeba4d38 <line:4:8> col:8 implicit small1 'char'
  | |-Field 0xeba4cd8 '' 'struct u::(anonymous at u.h:3:2)'
  | `-Field 0xeba4bd0 'small1' 'char'
  `-IndirectFieldDecl 0xeba4d90 <line:5:8> col:8 implicit small2 'char'
    |-Field 0xeba4cd8 '' 'struct u::(anonymous at u.h:3:2)'
    `-Field 0xeba4c30 'small2' 'char'
```

Notice, there is implicit fielddecl for `struct u::(anonymous ...)` as well as (implicit?) `IndirectFieldDecl`s.

However, when using `libclang` interface, in particular, [clang_visitChildren](https://clang.llvm.org/doxygen/group__CINDEX__CURSOR__TRAVERSAL.html#ga5d0a813d937e1a7dcc35f206ad1f7a91) only explicit declarations are visiible. I.e. we can only see first two declarations, `big 'int'` and `struct definition`.

In some cases it's very inconvenient to work with source code with tagless and/or field-nameless substructures.

Is there a way to also traverse implicit declarations?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to