]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compiler.cpp
Track source names in SL::Module
[libs/gl.git] / source / glsl / compiler.cpp
index 0579bb017267c08dfab0af9f177a8077e048244d..347e16ad301dba1881b604713a68476095ccf0f2 100644 (file)
@@ -1,8 +1,6 @@
 #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"
@@ -34,6 +32,7 @@ void Compiler::clear()
        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)
@@ -104,44 +103,14 @@ void Compiler::add_shaders(Program &program)
        }
        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);
@@ -192,7 +161,7 @@ void Compiler::import(DataFile::Collection *resources, const string &name)
        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)