ref: 5664fb3540ae0dccec628720574520122193ab1b
parent: 655d7e26e72a486b783820fe161a7a06eaa92078
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Mar 17 16:24:30 EDT 2023
cc: add __func__ support
--- a/sys/src/cmd/cc/c99
+++ b/sys/src/cmd/cc/c99
@@ -18,6 +18,7 @@
11, 30, 31, 32. restrict, inline
12. Allow declarations anywhere.
15. for loop declarations
+23. __func__ identifier
28. structs ending in incomplete type.
Unneeded (already had):
@@ -42,5 +43,4 @@
5. __STDC_IEC_559__, __STDC_IEC_559_COMPLEX__,
__STDC_ISO_10646__
13. Digraph tokens
-23. __func__ identifier
--- a/sys/src/cmd/cc/cc.h
+++ b/sys/src/cmd/cc/cc.h
@@ -583,6 +583,7 @@
void edecl(int, Type*, Sym*);
Type* fnproto(Node*);
Type* fnproto1(Node*);
+void fndecls(Node*, int);
void markdcl(void);
Type* paramconv(Type*, int);
void pdecl(int, Type*, Sym*);
--- a/sys/src/cmd/cc/cc.y
+++ b/sys/src/cmd/cc/cc.y
@@ -95,11 +95,13 @@
pdecl
{
argmark($2, 1);
+ fndecls($2, 0);
}
block
{
Node *n;
+ fndecls($2, 1);
n = revertdcl();
if(n)
$6 = new(OLIST, n, $6);
--- a/sys/src/cmd/cc/dcl.c
+++ b/sys/src/cmd/cc/dcl.c
@@ -732,6 +732,30 @@
}
void
+fndecls(Node *f, int pass)
+{
+ static Sym *funcsym;
+ Node *n;
+
+ if(pass == 0){
+ n = new(ONAME, Z, Z);
+ n->type = typ(TARRAY, garbt(types[TCHAR], BCONSTNT));
+ n->type->width = 0;
+ n->sym = slookup("__func__");
+ n->sym->type = n->type;
+ funcsym = dodecl(adecl, CLOCAL, n->type, n)->sym;
+ }else if(funcsym->aused){
+ n = new(OSTRING, Z, Z);
+ n->cstring = f->left->sym->name;
+ n->type = copytyp(funcsym->type);
+ n->type->width = strlen(n->cstring)+1;
+ n->etype = TARRAY;
+ n->class = CSTATIC;
+ doinit(funcsym, funcsym->type, 0L, n);
+ }
+}
+
+void
markdcl(void)
{
Decl *d;