Module &Parser::parse(const string &s, const string &n, unsigned i)
{
source = s;
- source_index = i;
- parse_source(n);
+ parse_source(n, i);
return *module;
}
Module &Parser::parse(IO::Base &io, const string &n, unsigned i)
{
source = string();
- source_index = i;
while(!io.eof())
{
char buffer[4096];
unsigned len = io.read(buffer, sizeof(buffer));
source.append(buffer, len);
}
- parse_source(n);
+ parse_source(n, i);
return *module;
}
-void Parser::parse_source(const string &name)
+void Parser::parse_source(const string &name, unsigned index)
{
- while(1)
- {
- string::size_type slashes = source.find("//////");
- if(slashes==string::npos)
- break;
-
- string::size_type newline = source.find('\n', slashes);
- string pragma = format("#pragma MSP stage(%s)", source.substr(slashes+6, newline-slashes-6));
- source.replace(slashes, newline-slashes, pragma);
- }
-
delete module;
module = new Module;
cur_stage = &module->shared;
+ source_index = index;
+ module->source_map.set_name(source_index, name);
tokenizer.begin(name, source);
while(RefPtr<Statement> statement = parse_global_declaration())
cur_stage->content.body.push_back(statement);
cur_stage->required_version = ver;
}
-void Parser::stage_change(StageType stage)
+void Parser::stage_change(Stage::Type stage)
{
if(!allow_stage_change)
throw invalid_shader_source(tokenizer.get_location(), "Changing stage not allowed here");
else if(stage<=cur_stage->type)
- throw invalid_shader_source(tokenizer.get_location(), "Stage '%s' not allowed here", stage);
+ throw invalid_shader_source(tokenizer.get_location(), "Stage '%s' not allowed here", Stage::get_stage_name(stage));
module->stages.push_back(stage);
- if(cur_stage->type!=SHARED)
+ if(cur_stage->type!=Stage::SHARED)
module->stages.back().previous = cur_stage;
cur_stage = &module->stages.back();
}
RefPtr<Import> Parser::parse_import()
{
- if(cur_stage->type!=SHARED)
+ if(cur_stage->type!=Stage::SHARED)
throw invalid_shader_source(tokenizer.get_location(), "Imports are only allowed in the shared section");
tokenizer.expect("import");
RefPtr<Passthrough> pass = new Passthrough;
pass->source = source_index;
pass->line = tokenizer.get_location().line;
- if(cur_stage->type==GEOMETRY)
+ if(cur_stage->type==Stage::GEOMETRY)
{
tokenizer.expect("[");
pass->subscript = parse_expression();