| 6109 | } |
| 6110 | |
| 6111 | void Tokenizer::dump(std::ostream &out) const |
| 6112 | { |
| 6113 | // Create a xml data dump. |
| 6114 | // The idea is not that this will be readable for humans. It's a |
| 6115 | // data dump that 3rd party tools could load and get useful info from. |
| 6116 | |
| 6117 | std::string outs; |
| 6118 | |
| 6119 | std::set<const Library::Container*> containers; |
| 6120 | |
| 6121 | outs += " <directivelist>"; |
| 6122 | outs += '\n'; |
| 6123 | for (const Directive &dir : mDirectives) { |
| 6124 | outs += " <directive "; |
| 6125 | outs += "file=\""; |
| 6126 | outs += ErrorLogger::toxml(Path::getRelativePath(dir.file, mSettings.basePaths)); |
| 6127 | outs += "\" "; |
| 6128 | outs += "linenr=\""; |
| 6129 | outs += std::to_string(dir.linenr); |
| 6130 | outs += "\" "; |
| 6131 | // str might contain characters such as '"', '<' or '>' which |
| 6132 | // could result in invalid XML, so run it through toxml(). |
| 6133 | outs += "str=\""; |
| 6134 | outs += ErrorLogger::toxml(dir.str); |
| 6135 | outs +="\">"; |
| 6136 | outs += '\n'; |
| 6137 | for (const auto & strToken : dir.strTokens) { |
| 6138 | outs += " <token "; |
| 6139 | outs += "column=\""; |
| 6140 | outs += std::to_string(strToken.column); |
| 6141 | outs += "\" "; |
| 6142 | outs += "str=\""; |
| 6143 | outs += ErrorLogger::toxml(strToken.tokStr); |
| 6144 | outs +="\"/>"; |
| 6145 | outs += '\n'; |
| 6146 | } |
| 6147 | outs += " </directive>"; |
| 6148 | outs += '\n'; |
| 6149 | } |
| 6150 | outs += " </directivelist>"; |
| 6151 | outs += '\n'; |
| 6152 | |
| 6153 | // tokens.. |
| 6154 | outs += " <tokenlist>"; |
| 6155 | outs += '\n'; |
| 6156 | for (const Token *tok = list.front(); tok; tok = tok->next()) { |
| 6157 | outs += " <token id=\""; |
| 6158 | outs += id_string(tok); |
| 6159 | outs += "\" file=\""; |
| 6160 | outs += ErrorLogger::toxml(list.file(tok)); |
| 6161 | outs += "\" linenr=\""; |
| 6162 | outs += std::to_string(tok->linenr()); |
| 6163 | outs += "\" column=\""; |
| 6164 | outs += std::to_string(tok->column()); |
| 6165 | outs += "\""; |
| 6166 | |
| 6167 | outs += " str=\""; |
| 6168 | outs += ErrorLogger::toxml(tok->str()); |