[cfe-dev] Did clang storage the Abstract Syntax Tree after parsing the source file?

Milian Wolff mail at milianw.de
Thu Jun 12 07:42:10 PDT 2014


On Thursday 12 June 2014 21:51:28 BugShan wrote:
> Hello all,
>       I am working on a project(AutoCompletion for SublimeText Editor)
> by using Clang but not libclang.Iwant to have a full access to AST.So
> these days, I download and read the clang's source Code(i am new to
> develop the clang tools), and find that every time to call
> CodeCompete(at ASTUnit.cpp), clang will parse the source file again(at
> ParseAST func). I dont know why but I think it won't be slow?In my mind,
> it would restore all the information into the Abstract Syntax Tree after
> parsing the specified source file,and get the result ASTNode by
> condition from calling CodeComplete function. I think if there is some
> reasons, i am wrong, or I skip the important part in clang source code.
>      If anybody understand what i mean and know something, please give
> me some ideas.

I suggest you to use the clang-c API for this. We in KDevelop do this, and so 
does QtCreator and possibly also XCode.

When you use that API, you can make clang cache most of the stuff in a 
precompiled preamble automatically, which speeds up code completion and 
similar reparsing events tremendously.

For inspiration see e.g. 
https://projects.kde.org/projects/playground/devtools/plugins/kdev-clang/repository/revisions/master/entry/duchain/parsesession.cpp
 and https://projects.kde.org/projects/playground/devtools/plugins/kdev-clang/repository/revisions/master/entry/codecompletion/context.cpp

Bye
-- 
Milian Wolff
mail at milianw.de
http://milianw.de



More information about the cfe-dev mailing list