diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 55ea54370..7d9f17e7a 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2074,6 +2074,20 @@ void SymbolDatabase::printOut(const char *title) const } } +void SymbolDatabase::printXml() const +{ + // Scopes.. + for (std::list::const_iterator scope = scopeList.begin(); scope != scopeList.end(); ++scope) { + std::cout << "type << "\""; + if (!scope->className.empty()) + std::cout << " className=\"" << scope->className << "\""; + std::cout << " nestedIn=\"" << scope->nestedIn << "\""; + std::cout << "/>" << std::endl; + } +} + //--------------------------------------------------------------------------- void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope) diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index bc78839a1..85855f6d2 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -836,6 +836,7 @@ public: void printOut(const char * title = NULL) const; void printVariable(const Variable *var, const char *indent) const; + void printXml() const; bool isCPP() const; diff --git a/lib/token.cpp b/lib/token.cpp index addc92640..be93fea95 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1083,17 +1083,42 @@ std::string Token::expressionString() const } -void Token::printAst(bool verbose) const +static std::string astStringXml(const Token *tok, std::size_t indent) +{ + const std::string strindent(indent, ' '); + + if (!tok->astOperand1() && !tok->astOperand2()) { + std::ostringstream ret; + ret << strindent << "str() << "\""; + if (tok->varId() > 0U) + ret << " varId=\"" << MathLib::toString(tok->varId()) << "\""; + ret << "/>"; + return ret.str(); + } + + std::string ret = strindent + "str() + "\">\n"; + if (tok->astOperand1()) + ret += astStringXml(tok->astOperand1(),indent+2U) + '\n'; + if (tok->astOperand2()) + ret += astStringXml(tok->astOperand2(),indent+2U) + '\n'; + return ret + strindent + ""; +} + +void Token::printAst(bool verbose, bool xml) const { bool title = false; bool print = true; for (const Token *tok = this; tok; tok = tok->next()) { if (print && tok->_astOperand1) { - if (!title) + if (!title && !xml) std::cout << "\n\n##AST" << std::endl; title = true; - if (verbose) + if (xml) { + std::cout << "scope() << "\">" << std::endl; + std::cout << astStringXml(tok->astTop(), 2U) << std::endl; + std::cout << "" << std::endl; + } else if (verbose) std::cout << tok->astTop()->astStringVerbose(0,0) << std::endl; else std::cout << tok->astTop()->astString(" ") << std::endl; diff --git a/lib/token.h b/lib/token.h index 3a1eaf67f..834d18519 100644 --- a/lib/token.h +++ b/lib/token.h @@ -811,7 +811,7 @@ public: std::string expressionString() const; - void printAst(bool verbose) const; + void printAst(bool verbose, bool xml) const; void printValueFlow() const; }; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1a6f910fa..aadd5f744 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3738,10 +3738,20 @@ void Tokenizer::printDebugOutput() const if (_settings->debug) { list.front()->printOut(0, list.getFiles()); - if (_settings->_verbose && _symbolDatabase) - _symbolDatabase->printOut("Symbol database"); + if (_settings->_xml) + std::cout << "" << std::endl; - list.front()->printAst(_settings->_verbose); + if (_symbolDatabase) { + if (_settings->_xml) + _symbolDatabase->printXml(); + else if (_settings->_verbose) + _symbolDatabase->printOut("Symbol database"); + } + + list.front()->printAst(_settings->_verbose, _settings->_xml); + + if (_settings->_xml) + std::cout << "" << std::endl; list.front()->printValueFlow(); }