diff options
| -rw-r--r-- | lib.c | 1 | ||||
| -rw-r--r-- | parse.c | 29 | ||||
| -rw-r--r-- | symbol.c | 2 | ||||
| -rw-r--r-- | symbol.h | 1 |
4 files changed, 31 insertions, 2 deletions
@@ -713,7 +713,6 @@ void create_builtin_stream(void) add_pre_buffer("#define __STDC__ 1\n"); add_pre_buffer("#define __GNUC__ 2\n"); add_pre_buffer("#define __GNUC_MINOR__ 95\n"); - add_pre_buffer("#define __func__ \"function\"\n"); add_pre_buffer("#define __extension__\n"); add_pre_buffer("#define __pragma__\n"); // gcc defines __SIZE_TYPE__ to be size_t. For linux/i86 and @@ -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; } @@ -532,6 +532,7 @@ __IDENT(pragma, "__pragma__"); struct ident __VA_ARGS___ident = __INIT_IDENT("__VA_ARGS__"); struct ident __LINE___ident = __INIT_IDENT("__LINE__"); struct ident __FILE___ident = __INIT_IDENT("__FILE__"); +struct ident __func___ident = __INIT_IDENT("__func__"); void init_symbols(void) { @@ -565,6 +566,7 @@ void init_symbols(void) hash_ident(&defined_ident); hash_ident(&__LINE___ident); hash_ident(&__FILE___ident); + hash_ident(&__func___ident); hash_ident(&__VA_ARGS___ident); hash_ident(&pragma_ident); for (ptr = symbol_init_table; ptr->name; ptr++) { @@ -195,6 +195,7 @@ extern struct ident __asm___ident, __VA_ARGS___ident, __LINE___ident, __FILE___ident, + __func___ident, pragma_ident; #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE) |
