@@ -3441,7 +3441,7 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration)
34413441 mSymbolDatabase ->setArrayDimensionsUsingValueFlow ();
34423442 }
34433443
3444- printDebugOutput (1 , std::cout);
3444+ printDebugOutput (std::cout);
34453445
34463446 return true ;
34473447}
@@ -5890,39 +5890,39 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
58905890}
58915891// ---------------------------------------------------------------------------
58925892
5893- void Tokenizer::printDebugOutput (int simplification, std::ostream &out) const
5893+ // TODO: do not depend on --verbose
5894+ void Tokenizer::printDebugOutput (std::ostream &out) const
58945895{
5895- const bool debug = (simplification != 1U && mSettings . debugSimplified ) ||
5896- (simplification != 2U && mSettings . debugnormal ) ;
5896+ if (!list. front ())
5897+ return ;
58975898
5898- if (debug && list.front ()) {
5899- const bool xml = (mSettings .outputFormat == Settings::OutputFormat::xml);
5899+ const bool debug = mSettings .debugSimplified || mSettings .debugnormal || mSettings .debugsymdb || mSettings .debugast || mSettings .debugvalueflow ;
5900+ if (!debug)
5901+ return ;
59005902
5901- if (!xml)
5902- list.front ()->printOut (out, xml, nullptr , list.getFiles ());
5903+ const bool xml = (mSettings .outputFormat == Settings::OutputFormat::xml);
59035904
5904- if (xml)
5905- {
5906- out << " <debug>" << std::endl;
5907- list.front ()->printOut (out, xml, nullptr , list.getFiles ());
5908- }
5905+ if (xml)
5906+ out << " <debug>" << std::endl;
59095907
5910- if (mSymbolDatabase ) {
5911- if (xml)
5912- mSymbolDatabase ->printXml (out);
5913- else if (mSettings .verbose ) {
5914- mSymbolDatabase ->printOut (" Symbol database" );
5915- }
5916- }
5908+ if (mSettings .debugSimplified || mSettings .debugnormal )
5909+ list.front ()->printOut (out, xml, nullptr , list.getFiles ());
5910+
5911+ if (mSymbolDatabase ) {
5912+ if (xml)
5913+ mSymbolDatabase ->printXml (out);
5914+ else if (mSettings .debugsymdb || (mSettings .debugnormal && mSettings .verbose ))
5915+ mSymbolDatabase ->printOut (" Symbol database" );
5916+ }
59175917
5918- if ( mSettings .verbose )
5919- list.front ()->printAst (mSettings .verbose , xml, list.getFiles (), out);
5918+ if ( mSettings . debugast || ( mSettings . debugnormal && mSettings .verbose ) )
5919+ list.front ()->printAst (mSettings .verbose , xml, list.getFiles (), out);
59205920
5921+ if (mSettings .debugnormal || mSettings .debugvalueflow )
59215922 list.front ()->printValueFlow (list.getFiles (), xml, out);
59225923
5923- if (xml)
5924- out << " </debug>" << std::endl;
5925- }
5924+ if (xml)
5925+ out << " </debug>" << std::endl;
59265926}
59275927
59285928void Tokenizer::dump (std::ostream &out) const
@@ -8077,27 +8077,31 @@ bool Tokenizer::isScopeNoReturn(const Token *endScopeToken, bool *unknown) const
80778077
80788078void Tokenizer::syntaxError (const Token *tok, const std::string &code) const
80798079{
8080- printDebugOutput (0 , std::cout);
8080+ if (mSettings .debugSimplified || mSettings .debugnormal )
8081+ printDebugOutput (std::cout);
80818082 throw InternalError (tok, code.empty () ? " syntax error" : " syntax error: " + code, InternalError::SYNTAX);
80828083}
80838084
80848085void Tokenizer::unmatchedToken (const Token *tok) const
80858086{
8086- printDebugOutput (0 , std::cout);
8087+ if (mSettings .debugSimplified || mSettings .debugnormal )
8088+ printDebugOutput (std::cout);
80878089 throw InternalError (tok,
80888090 " Unmatched '" + tok->str () + " '. Configuration: '" + mConfiguration + " '." ,
80898091 InternalError::SYNTAX);
80908092}
80918093
80928094void Tokenizer::syntaxErrorC (const Token *tok, const std::string &what) const
80938095{
8094- printDebugOutput (0 , std::cout);
8096+ if (mSettings .debugSimplified || mSettings .debugnormal )
8097+ printDebugOutput (std::cout);
80958098 throw InternalError (tok, " Code '" +what+" ' is invalid C code." , " Use --std, -x or --language to enforce C++. Or --cpp-header-probe to identify C++ headers via the Emacs marker." , InternalError::SYNTAX);
80968099}
80978100
80988101void Tokenizer::unknownMacroError (const Token *tok1) const
80998102{
8100- printDebugOutput (0 , std::cout);
8103+ if (mSettings .debugSimplified || mSettings .debugnormal )
8104+ printDebugOutput (std::cout);
81018105 throw InternalError (tok1, " There is an unknown macro here somewhere. Configuration is required. If " + tok1->str () + " is a macro then please configure it." , InternalError::UNKNOWN_MACRO);
81028106}
81038107
@@ -8131,7 +8135,7 @@ void Tokenizer::invalidConstFunctionTypeError(const Token *tok) const
81318135
81328136void Tokenizer::cppcheckError (const Token *tok) const
81338137{
8134- printDebugOutput (0 , std::cout);
8138+ printDebugOutput (std::cout);
81358139 throw InternalError (tok, " Analysis failed. If the code is valid then please report this failure." , InternalError::INTERNAL);
81368140}
81378141
0 commit comments