[GNU] Add __FUNCTION__

This commit is contained in:
Rui Ueyama 2020-09-04 11:56:28 +09:00
parent ba6b4b6375
commit 82ba010c76
2 changed files with 10 additions and 0 deletions

View File

@ -2405,6 +2405,10 @@ static Token *function(Token *tok, Type *basety, VarAttr *attr) {
push_scope("__func__")->var =
new_string_literal(fn->name, array_of(ty_char, strlen(fn->name) + 1));
// [GNU] __FUNCTION__ is yet another name of __func__.
push_scope("__FUNCTION__")->var =
new_string_literal(fn->name, array_of(ty_char, strlen(fn->name) + 1));
fn->body = compound_stmt(&tok, tok);
fn->locals = locals;
leave_scope();

View File

@ -118,6 +118,10 @@ char *func_fn(void) {
return __func__;
}
char *function_fn(void) {
return __FUNCTION__;
}
int main() {
ASSERT(3, ret3());
ASSERT(8, add2(3, 5));
@ -198,6 +202,8 @@ int main() {
ASSERT(5, sizeof(__func__));
ASSERT(0, strcmp("main", __func__));
ASSERT(0, strcmp("func_fn", func_fn()));
ASSERT(0, strcmp("main", __FUNCTION__));
ASSERT(0, strcmp("function_fn", function_fn()));
printf("OK\n");
return 0;