diff options
Diffstat (limited to 'parse.c')
| -rw-r--r-- | parse.c | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -882,8 +882,35 @@ static struct statement *start_function(struct symbol *sym) ret->ctype.modifiers |= (MOD_AUTO | MOD_REGISTER); bind_symbol(ret, &return_ident, NS_ITERATOR); stmt->ret = ret; - fn_local_symbol(ret); + + // static const char __func__[] = "function-name"; + if (sym->ident) { + struct symbol *funcname = alloc_symbol(sym->pos, SYM_NODE); + struct symbol *array = alloc_symbol(sym->pos, SYM_ARRAY); + struct expression *expr = alloc_expression(sym->pos, EXPR_STRING); + int len = sym->ident->len; + struct string *string = __alloc_string(len+1); + + array->ctype.base_type = &char_ctype; + array->ctype.modifiers = MOD_CONST | MOD_STATIC; + + memcpy(string->data, sym->ident->name, len); + string->data[len] = '\0'; + string->length = len + 1; + + expr->string = string; + + funcname->initializer = expr; + funcname->ctype.modifiers = array->ctype.modifiers; + funcname->ctype.base_type = array; + funcname->ident = &__func___ident; + bind_symbol(funcname, &__func___ident, NS_SYMBOL); + + add_symbol(&stmt->syms, funcname); + fn_local_symbol(funcname); + } + return stmt; } |
