mirror of https://github.com/rui314/chibicc
[GNU] Add __FUNCTION__
This commit is contained in:
parent
ba6b4b6375
commit
82ba010c76
4
parse.c
4
parse.c
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue