#include <msp/core/algorithm.h>
#include <msp/gl/extensions/ext_gpu_shader4.h>
#include <msp/strings/format.h>
-#include <msp/strings/regex.h>
-#include <msp/strings/utils.h>
#include "compatibility.h"
#include "compiler.h"
#include "error.h"
delete module;
module = new Module();
imported_names.clear();
+ module->source_map.set_name(0, "<generated>");
}
void Compiler::set_source(const string &source, const string &src_name)
}
catch(const compile_error &e)
{
- static const Regex r_message("^(([0-9]+)\\(([0-9]+)\\) :|ERROR: ([0-9]+):([0-9]+):) (.*)$");
- vector<string> lines = split(e.what(), '\n');
- string translated;
- for(vector<string>::const_iterator i=lines.begin(); i!=lines.end(); ++i)
- {
- RegMatch m = r_message.match(*i);
- if(m)
- {
- unsigned index = 0;
- unsigned line = 0;
- if(m[2])
- {
- index = lexical_cast<unsigned>(m[2].str);
- line = lexical_cast<unsigned>(m[3].str);
- }
- else if(m[4])
- {
- index = lexical_cast<unsigned>(m[4].str);
- line = lexical_cast<unsigned>(m[5].str);
- }
- const char *src = "<unknown>";
- if(index==0)
- src = "<generated>";
- else if(index-1<imported_names.size())
- src = imported_names[index-1].c_str();
- translated += format("%s:%d: %s", src, line, m[6].str);
- }
- else
- translated += *i;
- translated += '\n';
- }
-
- throw compile_error(translated);
+ throw compile_error(module->source_map.translate_errors(e.what()));
}
}
void Compiler::append_module(Module &mod, DataFile::Collection *res)
{
+ module->source_map.merge_from(mod.source_map);
+
vector<Import *> imports = NodeGatherer<Import>().apply(mod.shared);
for(vector<Import *>::iterator i=imports.begin(); i!=imports.end(); ++i)
import(res, (*i)->module);
if(!io)
throw runtime_error(format("module %s not found", name));
Parser import_parser;
- append_module(import_parser.parse(*io, fn, imported_names.size()), resources);
+ append_module(import_parser.parse(*io, fn, module->source_map.get_count()), resources);
}
void Compiler::generate(Stage &stage)