@@ -1083,45 +1083,52 @@ std::string Token::expressionString() const
10831083
10841084}
10851085
1086- static std::string astStringXml (const Token *tok, std::size_t indent)
1086+ static void astStringXml (const Token *tok, std::size_t indent, std::ostream &out )
10871087{
10881088 const std::string strindent (indent, ' ' );
10891089
1090+ out << strindent << " <token str=\" " << tok->str () << ' \" ' ;
1091+ if (tok->varId () > 0U )
1092+ out << " varId=\" " << MathLib::toString (tok->varId ()) << ' \" ' ;
1093+ if (tok->variable ())
1094+ out << " variable=\" " << tok->variable () << ' \" ' ;
1095+ if (tok->function ())
1096+ out << " function=\" " << tok->function () << ' \" ' ;
1097+ if (!tok->values .empty ())
1098+ out << " values=\" " << &tok->values << ' \" ' ;
1099+
10901100 if (!tok->astOperand1 () && !tok->astOperand2 ()) {
1091- std::ostringstream ret;
1092- ret << strindent << " <token text=\" " << tok->str () << " \" " ;
1093- if (tok->varId () > 0U )
1094- ret << " varId=\" " << MathLib::toString (tok->varId ()) << " \" " ;
1095- ret << " />" ;
1096- return ret.str ();
1101+ out << " />" << std::endl;
10971102 }
10981103
1099- std::string ret = strindent + " <token text=\" " + tok->str () + " \" >\n " ;
1100- if (tok->astOperand1 ())
1101- ret += astStringXml (tok->astOperand1 (),indent+2U ) + ' \n ' ;
1102- if (tok->astOperand2 ())
1103- ret += astStringXml (tok->astOperand2 (),indent+2U ) + ' \n ' ;
1104- return ret + strindent + " </token>" ;
1104+ else {
1105+ out << ' >' << std::endl;
1106+ if (tok->astOperand1 ())
1107+ astStringXml (tok->astOperand1 (), indent+2U , out);
1108+ if (tok->astOperand2 ())
1109+ astStringXml (tok->astOperand2 (), indent+2U , out);
1110+ out << strindent << " </token>" << std::endl;
1111+ }
11051112}
11061113
1107- void Token::printAst (bool verbose, bool xml) const
1114+ void Token::printAst (bool verbose, bool xml, std::ostream &out ) const
11081115{
11091116 bool title = false ;
11101117
11111118 bool print = true ;
11121119 for (const Token *tok = this ; tok; tok = tok->next ()) {
11131120 if (print && tok->_astOperand1 ) {
11141121 if (!title && !xml)
1115- std::cout << " \n\n ##AST" << std::endl;
1122+ out << " \n\n ##AST" << std::endl;
11161123 title = true ;
11171124 if (xml) {
1118- std::cout << " <ast scope=\" " << tok->scope () << " \" >" << std::endl;
1119- std::cout << astStringXml (tok->astTop (), 2U ) << std::endl ;
1120- std::cout << " </ast>" << std::endl;
1125+ out << " <ast scope=\" " << tok->scope () << " \" fileIndex= \" " << tok-> fileIndex () << " \" linenr= \" " << tok-> linenr () << " \" >" << std::endl;
1126+ astStringXml (tok->astTop (), 2U , out) ;
1127+ out << " </ast>" << std::endl;
11211128 } else if (verbose)
1122- std::cout << tok->astTop ()->astStringVerbose (0 ,0 ) << std::endl;
1129+ out << tok->astTop ()->astStringVerbose (0 ,0 ) << std::endl;
11231130 else
1124- std::cout << tok->astTop ()->astString (" " ) << std::endl;
1131+ out << tok->astTop ()->astString (" " ) << std::endl;
11251132 print = false ;
11261133 if (tok->str () == " (" )
11271134 tok = tok->link ();
@@ -1158,24 +1165,43 @@ std::string Token::astStringVerbose(const unsigned int indent1, const unsigned i
11581165}
11591166
11601167
1161- void Token::printValueFlow () const
1168+ void Token::printValueFlow (bool xml, std::ostream &out ) const
11621169{
11631170 unsigned int line = 0 ;
1164- std::cout << " \n\n ##Value flow" << std::endl;
1171+ if (xml)
1172+ out << " <valueflow>" << std::endl;
1173+ else
1174+ out << " \n\n ##Value flow" << std::endl;
11651175 for (const Token *tok = this ; tok; tok = tok->next ()) {
11661176 if (tok->values .empty ())
11671177 continue ;
1168- if (line != tok->linenr ())
1169- std::cout << " Line " << tok->linenr () << std::endl;
1178+ if (xml)
1179+ out << " <values id=\" " << &tok->values << " \" >" << std::endl;
1180+ else if (line != tok->linenr ())
1181+ out << " Line " << tok->linenr () << std::endl;
11701182 line = tok->linenr ();
1171- std::cout << " " << tok->str () << " :{" ;
1183+ if (!xml)
1184+ out << " " << tok->str () << " :{" ;
11721185 for (std::list<ValueFlow::Value>::const_iterator it=tok->values .begin (); it!=tok->values .end (); ++it) {
1173- if (it != tok->values .begin ())
1174- std::cout << " ," ;
1175- std::cout << it->intvalue ;
1186+ if (xml) {
1187+ out << " <value intvalue=\" " << it->intvalue << " \" " ;
1188+ if (it->condition ) {
1189+ out << " condition-line=\" " << it->condition ->linenr () << ' \" ' ;
1190+ }
1191+ out << " />" << std::endl;
1192+ }
1193+
1194+ else {
1195+ out << (it == tok->values .begin () ? " " : " ," ) << it->intvalue << std::endl;
1196+ }
11761197 }
1177- std::cout << " }" << std::endl;
1198+ if (xml)
1199+ out << " </values>" << std::endl;
1200+ else
1201+ out << " }" << std::endl;
11781202 }
1203+ if (xml)
1204+ out << " </valueflow>" << std::endl;
11791205}
11801206
11811207const ValueFlow::Value * Token::getValueLE (const MathLib::bigint val, const Settings *settings) const
0 commit comments