Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libclang: how to visit implicit declarations. #122257

Open
phadej opened this issue Jan 9, 2025 · 0 comments
Open

libclang: how to visit implicit declarations. #122257

phadej opened this issue Jan 9, 2025 · 0 comments
Labels
clang:as-a-library libclang and C++ API question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@phadej
Copy link

phadej commented Jan 9, 2025

Consider simple u.h header

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?) IndirectFieldDecls.

However, when using libclang interface, in particular, clang_visitChildren 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?

@EugeneZelenko EugeneZelenko added clang:as-a-library libclang and C++ API question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! and removed new issue labels Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:as-a-library libclang and C++ API question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

3 participants