[cfe-dev] Is there a way to run ASTConsumer plugin inspite of compile errors?

Nikola Smiljanic popizdeh at gmail.com
Fri Apr 17 21:51:44 PDT 2015


In general clang produces ast only for valid code. I don't think you'll be
able to get this working if your starting point is code that doesn't
compile. In the example you gave you might be able to get away with it so
long as you don't compile the instantiation of B<A> as that's what produces
the error. But this essentially means having code that compiles...

The only other thing that comes to my mind is having multiple passes in the
hope that each insertion you perform removes errors and allows you to
continue. I have no idea how feasible this would be.

On Fri, Apr 10, 2015 at 11:15 AM, chaitanya vadrevu <chaitanya973 at gmail.com>
wrote:

> Hi All,
>
> I developed a clang plugin which uses AST matchers to find interesting
> record declarations and automatically inserts a function (lets say newfn())
> along with some boiler plate code.
>
> //original code
> class A{
> ....
> };
>
> //modified code after plugin is run
> class A{
>   void newfn() {...}
> };
>
> This works fine as long as there are no compile errors. But there are
> cases when the absence of the
> function is causing the compilation to fail. E.g., the following code
> which expects class A to contain the function.
>
> template<typename T>
> class B{
>   T t;
>   B() {
>     t.newfn();
>   }
> };
>
> Due to the compilation errors, my plugin is not executed.
>
> So the compilation wont proceed unless the function is already present and
> the function can't be added unless compilation succeeds.
>
> Is there a way to solve this?
>
> Thanks,
> Chaitanya
>
> _______________________________________________
> 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/20150418/8b3e9892/attachment.html>


More information about the cfe-dev mailing list