struct AstGlobal {
AstTyped_base;
+ OnyxToken* name;
+
union {
// NOTE: Used when a global is exported with a specific name
OnyxToken* exported_name;
// then resolved to an overloaded function.
AstNode *overloaded_function;
+ OnyxToken* name;
+
union {
// NOTE: Used when a function is exported with a specific name
OnyxToken* exported_name;
b32 convert_numlit_to_type(AstNumLit* num, Type* type);
b32 type_check_or_auto_cast(AstTyped** pnode, Type* type);
Type* resolve_expression_type(AstTyped* node);
+char* get_function_name(AstFunction* func);
typedef enum PolyProcLookupMethod {
PPLM_By_Call,
Package* program_info_package_lookup(ProgramInfo* prog, char* package_name);
Package* program_info_package_lookup_or_create(ProgramInfo* prog, char* package_name, Scope* parent_scope, bh_allocator alloc);
-void scope_include(Scope* target, Scope* source);
+void scope_include(Scope* target, Scope* source, OnyxFilePos pos);
b32 symbol_introduce(Scope* scope, OnyxToken* tkn, AstNode* symbol);
b32 symbol_raw_introduce(Scope* scope, char* tkn, OnyxFilePos pos, AstNode* symbol);
void symbol_builtin_introduce(Scope* scope, char* sym, AstNode *node);
if (arg_pos >= bh_arr_length(arg_arr)) goto type_checking_done;
if (!type_check_or_auto_cast(&arg_arr[arg_pos]->value, formal_params[arg_pos])) {
onyx_report_error(arg_arr[arg_pos]->token->pos,
- "The function '%b' expects a value of type '%s' for %d%s parameter, got '%s'.",
- callee->token->text, callee->token->length,
+ "The procedure '%s' expects a value of type '%s' for %d%s parameter, got '%s'.",
+ get_function_name(callee),
type_get_name(formal_params[arg_pos]),
arg_pos + 1,
bh_num_suffix(arg_pos + 1),
if (arg_pos >= bh_arr_length(arg_arr)) goto type_checking_done;
if (!type_check_or_auto_cast(&arg_arr[arg_pos]->value, variadic_type)) {
onyx_report_error(arg_arr[arg_pos]->token->pos,
- "The function '%b' expects a value of type '%s' for the variadic parameter, '%b', got '%s'.",
- callee->token->text, callee->token->length,
+ "The procedure '%s' expects a value of type '%s' for the variadic parameter, '%b', got '%s'.",
+ get_function_name(callee),
type_get_name(variadic_type),
variadic_param->local->token->text,
variadic_param->local->token->length,
if (func->exported_name == NULL)
func->exported_name = symbol;
+ func->name = symbol;
+
+ } else if (node->kind == Ast_Kind_Polymorphic_Proc) {
+ AstPolyProc* proc = (AstPolyProc *) node;
+
+ if (proc->base_func->exported_name == NULL)
+ proc->base_func->exported_name = symbol;
+
+ proc->base_func->name = symbol;
+
} else if (node->kind == Ast_Kind_Global) {
AstGlobal* global = (AstGlobal *) node;
if (global->exported_name == NULL)
global->exported_name = symbol;
+ global->name = symbol;
+
} else if (node->kind != Ast_Kind_Overloaded_Function
&& node->kind != Ast_Kind_StrLit) {
}
if (package->alias == NULL && package->only == NULL) {
- scope_include(semstate.curr_scope, p->scope);
+ OnyxFilePos pos = { 0 };
+ if (package->token != NULL)
+ pos = package->token->pos;
+
+ scope_include(semstate.curr_scope, p->scope, pos);
}
}
return scope;
}
-void scope_include(Scope* target, Scope* source) {
+void scope_include(Scope* target, Scope* source, OnyxFilePos pos) {
bh_table_each_start(AstNode *, source->symbols);
- symbol_raw_introduce(target, (char *) key, value->token->pos, value);
+ symbol_raw_introduce(target, (char *) key, pos, value);
bh_table_each_end;
}
b32 symbol_raw_introduce(Scope* scope, char* name, OnyxFilePos pos, AstNode* symbol) {
if (bh_table_has(AstNode *, scope->symbols, name)) {
- onyx_report_error(pos, "Redeclaration of symbol '%s'.", name);
- return 0;
+ if (bh_table_get(AstNode *, scope->symbols, name) != symbol) {
+ onyx_report_error(pos, "Redeclaration of symbol '%s'.", name);
+ return 0;
+ }
+
+ return 1;
}
bh_table_put(AstNode *, scope->symbols, name, symbol);
return node->type;
}
+char* get_function_name(AstFunction* func) {
+ if (func->name != NULL) {
+ return bh_aprintf(global_scratch_allocator, "%b", func->name->text, func->name->length);
+ }
+
+ if (func->exported_name != NULL) {
+ return bh_aprintf(global_scratch_allocator,
+ "EXPORTED:%b",
+ func->exported_name->text,
+ func->exported_name->length);
+ }
+
+ return "<anonymous procedure>";
+}