1 #include <msp/strings/format.h>
2 #include <msp/strings/regex.h>
3 #include <msp/strings/utils.h>
12 void SourceMap::set_name(unsigned i, const string &n)
14 if(source_names.empty())
18 source_names.insert(source_names.begin(), base_index-i, string());
23 if(source_names.size()<=i)
24 source_names.resize(i+1);
28 const string &SourceMap::get_name(unsigned i) const
31 if(i<source_names.size())
32 return source_names[i];
38 void SourceMap::merge_from(const SourceMap &other)
40 if(other.base_index<base_index)
42 source_names.insert(source_names.begin(), base_index-other.base_index, string());
43 base_index = other.base_index;
45 if(get_count()<other.get_count())
46 source_names.resize(other.get_count()-base_index);
48 for(unsigned i=0; i<other.source_names.size(); ++i)
49 if(!other.source_names[i].empty())
50 source_names[i+other.base_index-base_index] = other.source_names[i];
53 string SourceMap::translate_errors(const string &errors) const
55 static const Regex r_message("^(([0-9]+)\\(([0-9]+)\\) :|ERROR: ([0-9]+):([0-9]+):) (.*)$");
56 vector<string> lines = split(errors, '\n');
58 for(const string &l: lines)
60 RegMatch m = r_message.match(l);
67 index = lexical_cast<unsigned>(m[2].str);
68 line = lexical_cast<unsigned>(m[3].str);
72 index = lexical_cast<unsigned>(m[4].str);
73 line = lexical_cast<unsigned>(m[5].str);
75 const char *src = "<unknown>";
76 if(index<source_names.size() && !source_names[index].empty())
77 src = source_names[index].c_str();
78 translated += format("%s:%d: %s", src, line, m[6].str);