I'm using Clang in a code editor extension to implement folding/collapsing and I've run into an issue.
I'm parsing only a single file at a time, as opposed to the entire translation unit. This is partly for speed and simplicity, but also because you can open a header file by itself and not know which cpp to parse anyway.
The issue is that as soon as clang encounters an unknown symbol it just gives up and entire chunks of the file are missing from the AST. Consider the following snippet
void Foo1()
{
while (PeekMessageA())
{
switch (0)
{
}
}
}
The AST for this is just
|-FunctionDecl 0x1fde8f67240 <Folding Test.cpp:1:1, line:9:1> line:1:6 Foo1 'void ()'
| `-CompoundStmt 0x1fde8f673f8 <line:2:1, line:9:1>
There's no information for the while block or the switch block. Obviously It's impossible for clang to know whether PeekMessageA is a function call or object construction, etc and I'm fine with that. I don't need it to be perfect, but I do want to be able to get to the while and switch blocks.
Is there a way to get clang to provide more information in the face in this case? I'm using LibClang currently, but open to using LibTooling as well.