Clang Parsing translation unit without building AST

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Clang Parsing translation unit without building AST

Tom Stellard via cfe-dev
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, waiting for ASTConsumer::HandleTranslationUnit() 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 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. 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang Parsing translation unit without building AST

Tom Stellard via cfe-dev


On Thu, Jun 15, 2017 at 10:40 AM Федор Матанцев via cfe-dev <[hidden email]> 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, waiting for ASTConsumer::HandleTranslationUnit() 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 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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...