allow_stage_change = true;
while(!tokenizer.peek_token().empty())
if(RefPtr<Statement> statement = parse_with_recovery(&Parser::parse_global_declaration))
+ {
cur_stage->content.body.push_back(statement);
+ if(next_global_declaration)
+ {
+ cur_stage->content.body.push_back(next_global_declaration);
+ next_global_declaration = 0;
+ }
+ }
if(!errors.empty())
throw invalid_shader_source(join(errors.begin(), errors.end(), "\n"));
cur_stage = &module->stages.back();
stage_types.clear();
+ if(const Stage *builtin = get_builtins(stage))
+ {
+ for(const auto &kvp: builtin->types)
+ stage_types.insert(kvp.first);
+ }
for(const Module *m: imported_modules)
{
auto j = find_member(m->stages, stage, &Stage::type);
}
else if(is_interface_qualifier(token) && tokenizer.peek_token(2)=="{")
{
- RefPtr<InterfaceBlock> iface = parse_interface_block();
- iface->layout = layout;
- return iface;
+ RefPtr<StructDeclaration> iface_strct = parse_interface_block();
+ VariableDeclaration *iface_var = iface_strct->block_declaration;
+ iface_var->layout = layout;
+ next_global_declaration = iface_var;
+ return iface_strct;
}
else
{
if(is_type(next) || is_qualifier(next))
return parse_variable_declaration();
else
- return parse_interface_block();
+ {
+ RefPtr<StructDeclaration> iface_strct = parse_interface_block();
+ next_global_declaration = iface_strct->block_declaration;
+ return iface_strct;
+ }
}
else if(is_qualifier(token))
return parse_variable_declaration();
return call;
}
+void Parser::add_type(TypeDeclaration &type)
+{
+ cur_stage->types[type.name] = &type;
+ if(cur_stage->type==Stage::SHARED)
+ global_types.insert(type.name);
+ else
+ stage_types.insert(type.name);
+}
+
RefPtr<TypeDeclaration> Parser::parse_type_declaration()
{
tokenizer.expect("typedef");
type = parse_basic_type_declaration();
tokenizer.expect(";");
- cur_stage->types[type->name] = type.get();
- if(cur_stage->type==Stage::SHARED)
- global_types.insert(type->name);
- else
- stage_types.insert(type->name);
+ add_type(*type);
return type;
}
parse_block(strct->members, true, &Parser::parse_variable_declaration);
tokenizer.expect(";");
- cur_stage->types[strct->name] = strct.get();
- if(cur_stage->type==Stage::SHARED)
- global_types.insert(strct->name);
- else
- stage_types.insert(strct->name);
+ add_type(*strct);
return strct;
}
return func;
}
-RefPtr<InterfaceBlock> Parser::parse_interface_block()
+RefPtr<StructDeclaration> Parser::parse_interface_block()
{
- RefPtr<InterfaceBlock> iface = create_node<InterfaceBlock>();
-
- iface->interface = tokenizer.parse_token();
- if(!is_interface_qualifier(iface->interface))
- throw parse_error(tokenizer.get_location(), iface->interface, "an interface qualifier");
+ RefPtr<StructDeclaration> strct = create_node<StructDeclaration>();
+ RefPtr<VariableDeclaration> var = create_node<VariableDeclaration>();
- iface->block_name = expect_identifier();
- iface->members = new Block;
- parse_block(*iface->members, true, &Parser::parse_variable_declaration_with_layout);
+ var->interface = tokenizer.parse_token();
+ if(!is_interface_qualifier(var->interface))
+ throw parse_error(tokenizer.get_location(), var->interface, "an interface qualifier");
+
+ strct->block_name = expect_identifier();
+ string name_base = format("_%s_%s", var->interface, strct->block_name);
+ strct->name = name_base;
+ for(unsigned i=1; (stage_types.count(strct->name) || global_types.count(strct->name)); ++i)
+ strct->name = format("%s_%d", name_base, i);
+ var->type = strct->name;
+ parse_block(strct->members, true, &Parser::parse_variable_declaration_with_layout);
if(!check(";"))
{
- iface->instance_name = expect_identifier();
+ var->name = expect_identifier();
if(check("["))
{
- iface->array = true;
+ var->array = true;
tokenizer.expect("]");
}
tokenizer.expect(";");
}
+ else
+ var->name = format("%s %s", var->interface, strct->block_name);
+
+ strct->block_declaration = var.release();
+ add_type(*strct);
- return iface;
+ return strct;
}
RefPtr<Conditional> Parser::parse_conditional()