Skip to content

Commit

Permalink
Demote __FUNCTION__ to an identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed May 20, 2017
1 parent d6cd8e9 commit e259e52
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/parse/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ static void read_primary( struct parse* parse, struct expr_reading* reading ) {
read_paren( parse, reading );
break;
case TK_NAMESPACENAME:
case TK_FUNCTIONNAME:
read_magic_id( parse, reading );
break;
default:
Expand Down
1 change: 0 additions & 1 deletion src/parse/token/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static void read_token_bcs( struct parse* parse ) {
const char* name;
enum tk tk;
} table[] = {
{ "__function__", TK_FUNCTIONNAME },
{ "__namespace__", TK_NAMESPACENAME },
{ "assert", TK_ASSERT },
{ "auto", TK_AUTO },
Expand Down
16 changes: 12 additions & 4 deletions src/semantic/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct param_list_test {
struct builtin_aliases {
struct {
struct alias alias;
struct object object;
struct temp_magic_id magic_id;
} name;
};

Expand Down Expand Up @@ -238,7 +238,7 @@ static void default_value_mismatch( struct semantic* semantic,
static int get_param_number( struct func* func, struct param* target );
static bool test_external_func( struct semantic* semantic, struct func* func );
static void init_builtin_aliases( struct semantic* semantic,
struct func* func );
struct builtin_aliases* aliases, struct func* func );
static void init_magic_id( struct temp_magic_id* magic_id, int name );
static void init_func_test( struct func_test* test, struct func_test* parent,
struct func* func, struct list* labels, struct list* funcscope_vars,
Expand Down Expand Up @@ -2297,6 +2297,8 @@ void s_test_func_body( struct semantic* semantic, struct func* func ) {
s_bail( semantic );
}
s_add_scope( semantic, true );
struct builtin_aliases aliases;
init_builtin_aliases( semantic, &aliases, func );
struct param* param = func->params;
while ( param ) {
if ( param->name ) {
Expand Down Expand Up @@ -2327,8 +2329,14 @@ void s_test_func_body( struct semantic* semantic, struct func* func ) {
}

static void init_builtin_aliases( struct semantic* semantic,
struct func* func ) {

struct builtin_aliases* aliases, struct func* func ) {
init_magic_id( &aliases->name.magic_id, MAGICID_FUNCTION );
struct alias* alias = &aliases->name.alias;
s_init_alias( alias );
alias->object.resolved = true;
alias->target = &aliases->name.magic_id.object;
struct name* name = t_extend_name( semantic->ns->body, "__function__" );
s_bind_local_name( semantic, name, &aliases->name.alias.object, true );
}

static void init_magic_id( struct temp_magic_id* magic_id, int name ) {
Expand Down
12 changes: 12 additions & 0 deletions src/semantic/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2966,6 +2966,18 @@ static void expand_temp_magic_id( struct semantic* semantic,
semantic->func_test->script->number->value );
}
break;
case MAGICID_FUNCTION:
if ( semantic->func_test->func->name ) {
t_copy_name( semantic->func_test->func->name, false, &name );
}
else {
// TODO: Create a nicer name.
str_append( &name, "" );
}
break;
default:
UNREACHABLE();
s_bail( semantic );
}
magic_id->string = t_intern_string_copy( semantic->task,
name.value, name.length );
Expand Down

0 comments on commit e259e52

Please sign in to comment.