s.content.visit(*this);
}
+TypeDeclaration *TypeResolver::resolve_type(const string &name)
+{
+ map<string, TypeDeclaration *>::iterator i = stage->types.find(name);
+ if(i!=stage->types.end())
+ {
+ map<TypeDeclaration *, TypeDeclaration *>::iterator j = alias_map.find(i->second);
+ return (j!=alias_map.end() ? j->second : i->second);
+ }
+ else
+ return 0;
+}
+
void TypeResolver::visit(BasicTypeDeclaration &type)
{
- map<string, TypeDeclaration *>::iterator i = stage->types.find(type.base);
- type.base_type = (i!=stage->types.end() ? i->second : 0);
+ type.base_type = resolve_type(type.base);
if(type.kind==BasicTypeDeclaration::VECTOR && type.base_type)
if(BasicTypeDeclaration *basic_base = dynamic_cast<BasicTypeDeclaration *>(type.base_type))
type.size |= basic_base->size<<16;
}
+ if(type.kind==BasicTypeDeclaration::ALIAS && type.base_type)
+ alias_map[&type] = type.base_type;
+
stage->types.insert(make_pair(type.name, &type));
}
void TypeResolver::visit(ImageTypeDeclaration &type)
{
- map<string, TypeDeclaration *>::iterator i = stage->types.find(type.base);
- type.base_type = (i!=stage->types.end() ? i->second : 0);
-
+ type.base_type = resolve_type(type.base);
stage->types.insert(make_pair(type.name, &type));
}
void TypeResolver::visit(VariableDeclaration &var)
{
- map<string, TypeDeclaration *>::iterator i = stage->types.find(var.type);
- if(i!=stage->types.end())
- var.type_declaration = i->second;
+ var.type_declaration = resolve_type(var.type);
+}
+
+void TypeResolver::visit(FunctionDeclaration &func)
+{
+ func.return_type_declaration = resolve_type(func.return_type);
+ TraversingVisitor::visit(func);
}
var.declaration = i->second;
}
- if(var.declaration)
- {
- if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(var.declaration->type_declaration))
- r_members = &strct->members.variables;
- }
- else
+ if(!var.declaration)
{
const map<string, InterfaceBlock *> &blocks = stage->interface_blocks;
map<string, InterfaceBlock *>::const_iterator i = blocks.find("_"+var.name);
/* The name refers to an interface block with an instance name rather
than a variable. Prepare a new syntax tree node accordingly. */
r_iface_ref = new InterfaceBlockReference;
+ r_iface_ref->source = var.source;
+ r_iface_ref->line = var.line;
r_iface_ref->name = var.name;
r_iface_ref->declaration = i->second;
r_members = &i->second->members.variables;
}
}
+ if(var.declaration)
+ if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(var.declaration->type_declaration))
+ r_members = &strct->members.variables;
+
if(record_target)
{
if(r_assignment_target)