+#include <msp/core/algorithm.h>
#include <msp/core/raii.h>
#include <msp/strings/format.h>
#include <msp/strings/regex.h>
if(index>=0)
source_reference(1, name);
- // TODO Need to somehow get type names from imports
if(const Stage *builtin = get_builtins(Stage::SHARED))
{
for(map<string, TypeDeclaration *>::const_iterator i=builtin->types.begin(); i!=builtin->types.end(); ++i)
- declared_types.insert(i->first);
+ global_types.insert(i->first);
}
else
{
- declared_types.insert("void");
- declared_types.insert("bool");
- declared_types.insert("int");
- declared_types.insert("uint");
- declared_types.insert("float");
+ global_types.insert("void");
+ global_types.insert("bool");
+ global_types.insert("int");
+ global_types.insert("uint");
+ global_types.insert("float");
}
tokenizer.begin(source, name);
if(cur_stage->type!=Stage::SHARED)
module->stages.back().previous = cur_stage;
cur_stage = &module->stages.back();
+
+ stage_types.clear();
+ for(vector<const Module *>::const_iterator i=imported_modules.begin(); i!=imported_modules.end(); ++i)
+ {
+ list<Stage>::const_iterator j = find_member((*i)->stages, stage, &Stage::type);
+ if(j!=(*i)->stages.end())
+ {
+ for(map<string, TypeDeclaration *>::const_iterator k=j->types.begin(); k!=j->types.end(); ++k)
+ stage_types.insert(k->first);
+ }
+ }
}
void Parser::line_change(int index, unsigned line)
bool Parser::is_type(const string &token)
{
- return declared_types.count(token);
+ return global_types.count(token) || stage_types.count(token);
}
bool Parser::is_identifier(const string &token)
RefPtr<Import> import = create_node<Import>();
import->module = expect_identifier();
tokenizer.expect(";");
+
+ if(mod_cache)
+ {
+ const Module &imported_mod = mod_cache->get_module(import->module);
+ imported_modules.push_back(&imported_mod);
+ for(map<string, TypeDeclaration *>::const_iterator i=imported_mod.shared.types.begin(); i!=imported_mod.shared.types.end(); ++i)
+ global_types.insert(i->first);
+ }
+
return import;
}
type = parse_basic_type_declaration();
tokenizer.expect(";");
- declared_types.insert(type->name);
+ cur_stage->types[type->name] = type.get();
+ if(cur_stage->type==Stage::SHARED)
+ global_types.insert(type->name);
+ else
+ stage_types.insert(type->name);
return type;
}
parse_block(strct->members, true, &Parser::parse_variable_declaration);
tokenizer.expect(";");
- declared_types.insert(strct->name);
+ cur_stage->types[strct->name] = strct.get();
+ if(cur_stage->type==Stage::SHARED)
+ global_types.insert(strct->name);
+ else
+ stage_types.insert(strct->name);
return strct;
}