Temporarily silence Parser diagnostics

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

Temporarily silence Parser diagnostics

Hans Wennborg via cfe-dev
Hi all,

Is there a mechanism how to temporarily silence Parser diagnostics in runtime?

The story is that I know there's a bug in input source code and would like to produce helpful error message (FixIt). I speculate what kind of bug it is and check if my guess is right by calling appropriate Parser method. I am using RevertingTentativeParsingAction but Parser methods are printing diagnostics whenever something doesn’t look right. This means that if my assumption about developer’s mistake is wrong I will output false diagnostics so I need a way how to silence diagnostics for the duration of speculative parse (I am interested only in bool result of the attempt).

AFAIK Parser::Diag() is used by all Parser methods to get output stream for diagnostics. So even if there’s nothing ready I might just add some private on/off switch to Parser. Does that make sense?

Thanks.

Best,

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

Re: Temporarily silence Parser diagnostics

Hans Wennborg via cfe-dev


> On Feb 14, 2018, at 10:27 AM, Jan Korous via cfe-dev <[hidden email]> wrote:
>
> Hi all,
>
> Is there a mechanism how to temporarily silence Parser diagnostics in runtime?
>
> The story is that I know there's a bug in input source code and would like to produce helpful error message (FixIt). I speculate what kind of bug it is and check if my guess is right by calling appropriate Parser method. I am using RevertingTentativeParsingAction but Parser methods are printing diagnostics whenever something doesn’t look right. This means that if my assumption about developer’s mistake is wrong I will output false diagnostics so I need a way how to silence diagnostics for the duration of speculative parse (I am interested only in bool result of the attempt).
>
> AFAIK Parser::Diag() is used by all Parser methods to get output stream for diagnostics. So even if there’s nothing ready I might just add some private on/off switch to Parser. Does that make sense?

An on/off switch in the Parser will not be enough, as we might still emit diagnostics in the Lexer, PP, and Sema, depending on which Parser method you call.
You could try using the `DiagnosticsEngine::SupressAllDiagnostics` flag and then determine if the parsing succeeded by tracking the value of `DiagnosticsEngine::TrapNumErrorsOccurred` (it should go up when errors occur).

Cheers,
Alex

>
> Thanks.
>
> Best,
>
> Jan
> _______________________________________________
> 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