From: Robert Pengelly Date: Tue, 8 Sep 2026 15:23:24 +0000 (+0100) Subject: Added __FUNCTION__ support X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=01cc3aa3d17a8b202aac1efd1d78312a2b65987f;p=scc.git Added __FUNCTION__ support --- diff --git a/amd64.c b/amd64.c index 20c9dc0..9cf3d89 100644 --- a/amd64.c +++ b/amd64.c @@ -39162,8 +39162,11 @@ static void parse_function_body (const char *name, int storage_class, int is_inl emit_function_start (name, !emit_public); statement_ends_control_flow = 0; + set_current_function_name (name); parse_block (); + + set_current_function_name (0); check_goto_labels (); if (current_function_is_noreturn && !current_function_has_return_statement && !statement_ends_control_flow) { diff --git a/i386.c b/i386.c index c4e8cd2..7a086c0 100644 --- a/i386.c +++ b/i386.c @@ -36679,8 +36679,11 @@ static void parse_function_body (const char *name, int storage_class, int is_inl emit_function_start (name, !emit_public); statement_ends_control_flow = 0; + set_current_function_name (name); parse_block (); + + set_current_function_name (0); check_goto_labels (); if (current_function_is_noreturn && !current_function_has_return_statement && !statement_ends_control_flow) { diff --git a/token.c b/token.c index cee195e..e4b90ef 100755 --- a/token.c +++ b/token.c @@ -2050,6 +2050,23 @@ static char *token_collect_macro_continuation (char *line_start, char **line_end } +static char *current_function_name = 0; + +void set_current_function_name (const char *name) { + + if (current_function_name) { + + free (current_function_name); + current_function_name = 0; + + } + + if (name) { + current_function_name = xstrdup (name); + } + +} + void get_token (void) { struct history *history; @@ -2180,6 +2197,20 @@ void get_token (void) { if (tok.kind == TOK_IDENT) { + if (current_function_name && strcmp (tok.ident, "__FUNCTION__") == 0) { + + char *value = xmalloc (strlen (current_function_name) + 3); + sprintf (value, "\"%s\"", current_function_name); + + free (tok.ident); + + tok.ident = value; + tok.kind = TOK_PPSTR; + + return; + + } + tok.kind = find_kind (tok.start, tok.caret, tok.ident);; return; diff --git a/token.h b/token.h index 18db011..302da17 100755 --- a/token.h +++ b/token.h @@ -174,4 +174,6 @@ struct punct { struct punct *find_punct (char *p); int init_tokenizer (const char *ifile); +void set_current_function_name (const char *name); + #endif /* _TOKEN_H */