[cfe-dev] Temporarily silence Parser diagnostics

Alex Lorenz via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 14 10:52:20 PST 2018



> On Feb 14, 2018, at 10:27 AM, Jan Korous via cfe-dev <cfe-dev at lists.llvm.org> 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
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list