[cfe-dev] Keeping invalid AST nodes

Vassil Vassilev vvasilev at cern.ch
Mon Nov 12 08:11:46 PST 2012

On 11/5/12 6:18 AM, Erik Verbruggen wrote:
> When using libclang for syntax highlighting, I noticed that no AST nodes get built for e.g. invalid expressions. For example, in the following C++ code:
> int func(int i) {
>      int j = undefinedFunction(i) + i;
>      return j;
> }
> the whole initialisation for int j gets dropped, including the (somewhat) valid references to i. I understand that this is done to keep the AST valid after parsing, but an IDE or refactoring tools cannot help out with fixing the problem in that snippet. My question: is there some way to keep the invalid AST nodes, or is somebody already working on this?
Have you considered flagging the broken (invalid) nodes as dependent? 
There is a hook in clang::ExternalSemaSource:: LookupUnqualified 
which gets called by clang just before complaining about an error and 
dropping the node. At that point I believe you can declare the name as 
dependent (which will lead to creating a broken AST) and continue 

Does that make sense to you?

> Regards,
> Erik.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121112/b7053d42/attachment.html>

More information about the cfe-dev mailing list