Skip to content

Commit

Permalink
Disallow mixing of local functions and standalone functions
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed May 4, 2017
1 parent fca88c1 commit 7c302e4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/semantic/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2177,12 +2177,12 @@ bool test_external_func( struct semantic* semantic, struct func* func ) {
struct type_info type;
s_init_type_info_func( &type, func->ref, func->structure,
func->enumeration, func->params, func->return_spec,
func->min_param, func->max_param );
func->min_param, func->max_param, false );
struct type_info other_type;
s_init_type_info_func( &other_type, other_func->ref,
other_func->structure, other_func->enumeration, other_func->params,
other_func->return_spec, other_func->min_param,
other_func->max_param );
other_func->max_param, false );
if ( ! s_same_type( &type, &other_type ) ) {
s_diag( semantic, DIAG_POS_ERR, &func->object.pos,
"external function declaration different from %s",
Expand Down
8 changes: 3 additions & 5 deletions src/semantic/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2635,16 +2635,14 @@ static void select_structure_member( struct semantic* semantic,
void select_func( struct semantic* semantic, struct result* result,
struct func* func ) {
if ( func->type == FUNC_USER ) {
struct func_user* impl = func->impl;
s_init_type_info_func( &result->type, func->ref, func->structure,
func->enumeration, func->params, func->return_spec, func->min_param,
func->max_param );
func->max_param, impl->local );
result->usable = true;
result->folded = true;
struct func_user* impl = func->impl;
result->complete = true;
++impl->usage;
if ( ! impl->local ) {
result->complete = true;
}
}
// When an action-special is not called, it decays into an integer value.
// The value is the ID of the action-special.
Expand Down
3 changes: 2 additions & 1 deletion src/semantic/phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ void s_init_type_info_array_ref( struct type_info* type, struct ref* ref,
int dim_count, int spec );
void s_init_type_info_func( struct type_info* type, struct ref* ref,
struct structure* structure, struct enumeration* enumeration,
struct param* params, int return_spec, int min_param, int max_param );
struct param* params, int return_spec, int min_param, int max_param,
bool local );
void s_init_type_info_builtin_func( struct type_info* type );
void s_init_type_info_scalar( struct type_info* type, int spec );
void s_init_type_info_null( struct type_info* type );
Expand Down
12 changes: 10 additions & 2 deletions src/semantic/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ void s_init_type_info_array_ref( struct type_info* type, struct ref* ref,

void s_init_type_info_func( struct type_info* type, struct ref* ref,
struct structure* structure, struct enumeration* enumeration,
struct param* params, int return_spec, int min_param, int max_param ) {
struct param* params, int return_spec, int min_param, int max_param,
bool local ) {
s_init_type_info( type, ref, structure, enumeration, NULL, return_spec,
STORAGE_LOCAL );
// NOTE: At this time, I don't see where in the compiler a distinction needs
Expand All @@ -100,6 +101,7 @@ void s_init_type_info_func( struct type_info* type, struct ref* ref,
func->params = params;
func->min_param = min_param;
func->max_param = max_param;
func->local = local;
type->ref = &func->ref;
}

Expand Down Expand Up @@ -223,7 +225,10 @@ bool same_ref_func( struct ref_func* a, struct ref_func* b ) {
param_a = param_a->next;
param_b = param_b->next;
}
return ( param_a == NULL && param_b == NULL );
return (
param_a == NULL &&
param_b == NULL &&
a->local == b->local );
}

bool same_spec( int a, int b ) {
Expand Down Expand Up @@ -393,6 +398,9 @@ void present_ref( struct ref* ref, struct str* string ) {
str_append( string, "(" );
present_param_list( func->params, string );
str_append( string, ")" );
if ( func->local ) {
str_append( string, " local" );
}
if ( ref->nullable ) {
str_append( string, "?" );
}
Expand Down
1 change: 1 addition & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ struct ref_func* t_alloc_ref_func( void ) {
func->params = NULL;
func->min_param = 0;
func->max_param = 0;
func->local = false;
return func;
}

Expand Down
1 change: 1 addition & 0 deletions src/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ struct ref_func {
struct param* params;
int min_param;
int max_param;
bool local;
};

struct type_alias {
Expand Down

0 comments on commit 7c302e4

Please sign in to comment.