[cfe-dev] Clang Parsing translation unit without building AST

Федор Матанцев via cfe-dev cfe-dev at lists.llvm.org
Thu Jun 15 10:16:30 PDT 2017


Hello!
Let me explain my problem:

I have a translation unit which I want to parse but I don't want clang to
build AST because
I will make it externally (in code editor);
At the moment the process looks like calling clang::ParseAST
<https://clang.llvm.org/doxygen/namespaceclang.html#a27f04f4d92161ea521f726019b93073e>,
waiting for ASTConsumer::HandleTranslationUnit
<https://clang.llvm.org/doxygen/classclang_1_1ASTConsumer.html#a2bea2db1d0e8af16c60ee7847f0d46ff>()
and traversing through the clang's AST with sending each token to the
editor that will rebuild its own AST.

First things first, I tried to write my own ParseAST
<https://clang.llvm.org/doxygen/namespaceclang.html#a27f04f4d92161ea521f726019b93073e>
but
I found out that (seemingly) any interaction with Parser or Sema lead to
saving parsing results into the ASTContext;

At the moment I'm thinking on calling Parser::ParseTopLevelDecl() and
translating it's output like I did before for the whole translating unit;
Then call and translate it again and so forth until the EOF.

Is it okay to delete DeclGroups that were already parsed from the AST
Context?
Are there any other options?

Regards,
Fedor.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170615/9f43b4cb/attachment.html>


More information about the cfe-dev mailing list