#include <msp/core/hash.h>
#include <msp/core/raii.h>
#include <msp/strings/lexicalcast.h>
+#include <msp/strings/utils.h>
#include "builtin.h"
#include "generate.h"
bool ExpressionResolver::convert_to_element(RefPtr<Expression> &expr, BasicTypeDeclaration &elem_type)
{
- if(BasicTypeDeclaration *expr_type = dynamic_cast<BasicTypeDeclaration *>(expr->type))
+ if(BasicTypeDeclaration *expr_basic = dynamic_cast<BasicTypeDeclaration *>(expr->type))
{
BasicTypeDeclaration *to_type = &elem_type;
- if(is_vector_or_matrix(*expr_type))
- to_type = find_type(elem_type, expr_type->kind, expr_type->size);
+ if(is_vector_or_matrix(*expr_basic))
+ to_type = find_type(elem_type, expr_basic->kind, expr_basic->size);
if(to_type)
{
convert_to(expr, *to_type);
void FunctionResolver::visit(FunctionCall &call)
{
- map<string, FunctionDeclaration *>::iterator i = stage->functions.find(call.name);
- FunctionDeclaration *declaration = (i!=stage->functions.end() ? i->second : 0);
+ string arg_types;
+ bool has_signature = true;
+ for(NodeArray<Expression>::const_iterator i=call.arguments.begin(); (has_signature && i!=call.arguments.end()); ++i)
+ {
+ if((*i)->type)
+ append(arg_types, ",", (*i)->type->name);
+ else
+ has_signature = false;
+ }
+
+ FunctionDeclaration *declaration = 0;
+ if(has_signature)
+ {
+ map<string, FunctionDeclaration *>::iterator i = stage->functions.find(format("%s(%s)", call.name, arg_types));
+ declaration = (i!=stage->functions.end() ? i->second : 0);
+ }
r_any_resolved |= (declaration!=call.declaration);
call.declaration = declaration;
void FunctionResolver::visit(FunctionDeclaration &func)
{
- FunctionDeclaration *&stage_decl = stage->functions[func.name];
- vector<FunctionDeclaration *> &decls = declarations[func.name];
+ if(func.signature.empty())
+ {
+ string param_types;
+ for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
+ {
+ if((*i)->type_declaration)
+ append(param_types, ",", (*i)->type_declaration->name);
+ else
+ return;
+ }
+ func.signature = format("(%s)", param_types);
+ r_any_resolved = true;
+ }
+
+ string key = func.name+func.signature;
+ FunctionDeclaration *&stage_decl = stage->functions[key];
+ vector<FunctionDeclaration *> &decls = declarations[key];
if(func.definition==&func)
{
stage_decl = &func;