1 #include <msp/strings/format.h>
2 #include <msp/strings/regex.h>
3 #include <msp/strings/utils.h>
12 SourceMap::SourceMap():
16 void SourceMap::set_name(unsigned i, const std::string &n)
18 if(source_names.empty())
22 source_names.insert(source_names.begin(), base_index-i, string());
27 if(source_names.size()<=i)
28 source_names.resize(i+1);
32 void SourceMap::merge_from(const SourceMap &other)
34 if(other.base_index<base_index)
36 source_names.insert(source_names.begin(), base_index-other.base_index, string());
37 base_index = other.base_index;
39 if(get_count()<other.get_count())
40 source_names.resize(other.get_count()-base_index);
42 for(unsigned i=0; i<other.source_names.size(); ++i)
43 if(!other.source_names[i].empty())
44 source_names[i+other.base_index-base_index] = other.source_names[i];
47 string SourceMap::translate_errors(const string &errors) const
49 static const Regex r_message("^(([0-9]+)\\(([0-9]+)\\) :|ERROR: ([0-9]+):([0-9]+):) (.*)$");
50 vector<string> lines = split(errors, '\n');
52 for(vector<string>::const_iterator i=lines.begin(); i!=lines.end(); ++i)
54 RegMatch m = r_message.match(*i);
61 index = lexical_cast<unsigned>(m[2].str);
62 line = lexical_cast<unsigned>(m[3].str);
66 index = lexical_cast<unsigned>(m[4].str);
67 line = lexical_cast<unsigned>(m[5].str);
69 const char *src = "<unknown>";
70 if(index<source_names.size() && !source_names[index].empty())
71 src = source_names[index].c_str();
72 translated += format("%s:%d: %s", src, line, m[6].str);