[cfe-dev] Clang Parsing translation unit without building AST
David Blaikie via cfe-dev
cfe-dev at lists.llvm.org
Thu Jun 15 10:50:53 PDT 2017
On Thu, Jun 15, 2017 at 10:40 AM Федор Матанцев via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> 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?
>
Probably not - C++ is context sensitive. So parsing later decls may require
earlier decls to be consulted (for example: 'foo < bar > baz' - is foo a
template or a variable? That'll change how the statement is parsed)
> Are there any other options?
>
> Regards,
> Fedor.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170615/d9106f29/attachment.html>
More information about the cfe-dev
mailing list