Skip to content

libclang: how to visit implicit declarations. #122257

Open
@phadej

Description

@phadej

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, (EDIT:) without access to these implicit AST nodes.

Is there a way to also traverse implicit declarations?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:as-a-librarylibclang and C++ APIquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions