+#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);
- }
- else
- {
- declared_types.insert("void");
- declared_types.insert("bool");
- declared_types.insert("int");
- declared_types.insert("uint");
- declared_types.insert("float");
+ for(const auto &kvp: builtin->types)
+ global_types.insert(kvp.first);
}
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(const Module *m: imported_modules)
+ {
+ auto j = find_member(m->stages, stage, &Stage::type);
+ if(j!=m->stages.end())
+ {
+ for(const auto &kvp: j->types)
+ stage_types.insert(kvp.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)
{
static Regex re("^[a-zA-Z_][a-zA-Z0-9_]*$");
- return re.match(token);
+ return static_cast<bool>(re.match(token));
}
template<typename T>
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(const auto &kvp: imported_mod.shared.types)
+ global_types.insert(kvp.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;
}