[cfe-users] Using libclang to get the AST of a single file
Adam Byrd via cfe-users
cfe-users at lists.llvm.org
Mon Jan 14 22:53:23 PST 2019
I've used libclang to implement a code folding/collapsing plugin for my
editor. It's working quite well in my test files, but I ran into a
showstopper when I started using it on real files. If there are any
unresolved symbols (and presumably other types of errors) chunks of the AST
will be missing. For example, if I have a file with the following
void Foo()
{
while (PeekMessageA())
{
}
}
all I'll get out of the AST is a FunctionDecl for Foo and a CompoundStmt.
Nothing for the while loop or function call even with
CXTranslationUnit_SingleFileParse and CXTranslationUnit_KeepGoing specified
for parsing.
This behavior seems to make it impossible to use libclang for code folding
information and other single-file or while-editing tools. It seems
unreasonable to have to parse an entire translation unit for syntax based
folding information in a single file. And I don't want to lose folding
simply because I've got an unresolved symbol in syntactically correct code
while I'm in the process of editing it.
Is there any other way to accomplish this with libclang? I understand that
without being able to resolve the symbol it leaves things ambiguous and
PeekMessageA would likely be an UnexposedDecl. That's fine in this case as
long as the location range is correct.
Cheers,
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20190114/16069c96/attachment.html>
More information about the cfe-users
mailing list