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 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 const string &SourceMap::get_name(unsigned i) const
35 if(i<source_names.size())
36 return source_names[i];
42 void SourceMap::merge_from(const SourceMap &other)
44 if(other.base_index<base_index)
46 source_names.insert(source_names.begin(), base_index-other.base_index, string());
47 base_index = other.base_index;
49 if(get_count()<other.get_count())
50 source_names.resize(other.get_count()-base_index);
52 for(unsigned i=0; i<other.source_names.size(); ++i)
53 if(!other.source_names[i].empty())
54 source_names[i+other.base_index-base_index] = other.source_names[i];
57 string SourceMap::translate_errors(const string &errors) const
59 static const Regex r_message("^(([0-9]+)\\(([0-9]+)\\) :|ERROR: ([0-9]+):([0-9]+):) (.*)$");
60 vector<string> lines = split(errors, '\n');
62 for(const string &l: lines)
64 RegMatch m = r_message.match(l);
71 index = lexical_cast<unsigned>(m[2].str);
72 line = lexical_cast<unsigned>(m[3].str);
76 index = lexical_cast<unsigned>(m[4].str);
77 line = lexical_cast<unsigned>(m[5].str);
79 const char *src = "<unknown>";
80 if(index<source_names.size() && !source_names[index].empty())
81 src = source_names[index].c_str();
82 translated += format("%s:%d: %s", src, line, m[6].str);