aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/acidtypes
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-11-29 05:12:33 +0000
committerrsc <devnull@localhost>2005-11-29 05:12:33 +0000
commite3de25fea4065d017fc344c3c7d757738a922c17 (patch)
tree20a735762ace754f995c138273e3d1eae72f66ad /src/cmd/acidtypes
parent6c7ed6b0e6086e32710a0d42e034bce6bdaad7b0 (diff)
downloadplan9port-e3de25fea4065d017fc344c3c7d757738a922c17.tar.gz
plan9port-e3de25fea4065d017fc344c3c7d757738a922c17.tar.bz2
plan9port-e3de25fea4065d017fc344c3c7d757738a922c17.zip
better handling of C++ names.
Diffstat (limited to 'src/cmd/acidtypes')
-rw-r--r--src/cmd/acidtypes/dat.h5
-rw-r--r--src/cmd/acidtypes/main.c1
-rw-r--r--src/cmd/acidtypes/sym.c2
-rw-r--r--src/cmd/acidtypes/type.c50
-rw-r--r--src/cmd/acidtypes/util.c29
5 files changed, 65 insertions, 22 deletions
diff --git a/src/cmd/acidtypes/dat.h b/src/cmd/acidtypes/dat.h
index 5039070a..1c26e6bd 100644
--- a/src/cmd/acidtypes/dat.h
+++ b/src/cmd/acidtypes/dat.h
@@ -87,4 +87,9 @@ char *cleanstl(char*);
void addsymx(char*, char*, Type*);
void dumpsyms(Biobuf*);
+int Bfmt(Fmt*);
+
+#ifdef VARARGCK
+#pragma varargck type "B" char*
+#endif
diff --git a/src/cmd/acidtypes/main.c b/src/cmd/acidtypes/main.c
index 1efff63a..066e8bad 100644
--- a/src/cmd/acidtypes/main.c
+++ b/src/cmd/acidtypes/main.c
@@ -22,6 +22,7 @@ main(int argc, char **argv)
char err[ERRMAX];
quotefmtinstall();
+ fmtinstall('B', Bfmt);
ARGBEGIN{
case 'v':
diff --git a/src/cmd/acidtypes/sym.c b/src/cmd/acidtypes/sym.c
index 3c9bd49e..9aaaa487 100644
--- a/src/cmd/acidtypes/sym.c
+++ b/src/cmd/acidtypes/sym.c
@@ -41,7 +41,7 @@ dumpsyms(Biobuf *b)
}
if(t == nil || t->ty != Aggr)
continue;
- Bprint(b, "complex %s %s%s%s;\n", cleanstl(nameof(t, 1)),
+ Bprint(b, "complex %B %B%s%B;\n", nameof(t, 1),
s->fn ? fixname(s->fn) : "", s->fn ? ":" : "", fixname(s->name));
}
diff --git a/src/cmd/acidtypes/type.c b/src/cmd/acidtypes/type.c
index b8dccb57..01ecc3e7 100644
--- a/src/cmd/acidtypes/type.c
+++ b/src/cmd/acidtypes/type.c
@@ -439,6 +439,14 @@ dorange(Type *t)
t->xsizeof = countbytes(t->hi);
}
+char*
+mkname(char *prefix, char *name)
+{
+ static char buf[65536];
+
+ snprint(buf, sizeof buf, "%s%s", prefix, name);
+ return buf;
+}
char*
nameof(Type *t, int doanon)
@@ -581,9 +589,9 @@ printtype(Biobuf *b, Type *t)
t->printed = 1;
switch(t->ty){
case Aggr:
- name = cleanstl(nameof(t, 1));
- Bprint(b, "sizeof%s = %lud;\n", name, t->xsizeof);
- Bprint(b, "aggr %s {\n", name);
+ name = nameof(t, 1);
+ Bprint(b, "%B = %lud;\n", mkname("sizeof", name), t->xsizeof);
+ Bprint(b, "aggr %B {\n", name);
nprint = 0;
for(j=0; j<t->n; j++){
tt = defer(t->t[j]);
@@ -611,11 +619,11 @@ ttt=ttt->sub;
case Array:
case Function:
nprint++;
- Bprint(b, "\t'%c' %lud %s;\n", basecharof(tt), t->val[j], fixname(t->tname[j]));
+ Bprint(b, "\t'%c' %lud %B;\n", basecharof(tt), t->val[j], fixname(t->tname[j]));
break;
case Aggr:
nprint++;
- Bprint(b, "\t%s %lud %s;\n", nameof(tt, 1), t->val[j], fixname(t->tname[j]));
+ Bprint(b, "\t%B %lud %B;\n", nameof(tt, 1), t->val[j], fixname(t->tname[j]));
break;
}
}
@@ -623,10 +631,10 @@ ttt=ttt->sub;
Bprint(b, "\t'X' 0 __dummy;\n");
Bprint(b, "};\n\n");
- name = cleanstl(nameof(t, 1)); /* might have smashed it */
- Bprint(b, "defn %s(addr) { indent_%s(addr, \"\"); }\n", name, name);
- Bprint(b, "defn indent_%s(addr, indent) {\n", name);
- Bprint(b, "\tcomplex %s addr;\n", name);
+ name = nameof(t, 1); /* might have smashed it */
+ Bprint(b, "defn %B(addr) { %B(addr, \"\"); }\n", name, mkname("indent_", name));
+ Bprint(b, "defn %B(addr, indent) {\n", mkname("indent_", name));
+ Bprint(b, "\tcomplex %B addr;\n", name);
for(j=0; j<t->n; j++){
name = fixname(t->tname[j]);
tt = defer(t->t[j]);
@@ -637,30 +645,30 @@ ttt=ttt->sub;
switch(tt->ty){
case Base:
base:
- Bprint(b, "\tprint(indent, \"%s\t\", addr.%s, \"\\n\");\n",
+ Bprint(b, "\tprint(indent, \"%s\t\", addr.%B, \"\\n\");\n",
name, name);
break;
case Pointer:
ttt = defer(tt->sub);
if(ttt && ttt->ty == Aggr)
- Bprint(b, "\tprint(indent, \"%s\t(%s)\", addr.%s, \"\\n\");\n",
+ Bprint(b, "\tprint(indent, \"%s\t(%s)\", addr.%B, \"\\n\");\n",
name, nameof(ttt, 1), name);
else
goto base;
break;
case Array:
- Bprint(b, "\tprint(indent, \"%s\t\", addr.%s\\X, \"\\n\");\n",
+ Bprint(b, "\tprint(indent, \"%s\t\", addr.%B\\X, \"\\n\");\n",
name, name);
break;
case Enum:
- Bprint(b, "\tprint(indent, \"%s\t\", addr.%s, \" \", %s(addr.%s), \"\\n\");\n",
+ Bprint(b, "\tprint(indent, \"%s\t\", addr.%B, \" \", %B(addr.%B), \"\\n\");\n",
name, name, nameof(tt, 1), name);
break;
case Aggr:
Bprint(b, "\tprint(indent, \"%s\t%s{\\n\");\n",
name, nameof(tt, 0));
- Bprint(b, "\tindent_%s(addr+%lud, indent+\" \");\n",
- nameof(tt, 1), t->val[j]);
+ Bprint(b, "\t%B(addr+%lud, indent+\" \");\n",
+ mkname("indent_", nameof(tt, 1)), t->val[j]);
Bprint(b, "\tprint(indent, \"}\\n\");\n");
break;
}
@@ -672,20 +680,20 @@ ttt=ttt->sub;
name = nameof(t, 1);
Bprint(b, "// enum %s\n", name);
for(j=0; j<t->n; j++)
- Bprint(b, "%s = %ld;\n", fixname(t->tname[j]), t->val[j]);
+ Bprint(b, "%B = %ld;\n", fixname(t->tname[j]), t->val[j]);
- Bprint(b, "vals_%s = {\n", name);
+ Bprint(b, "%B = {\n", mkname("vals_", name));
for(j=0; j<t->n; j++)
Bprint(b, "\t%lud,\n", t->val[j]);
Bprint(b, "};\n");
- Bprint(b, "names_%s = {\n", name);
+ Bprint(b, "%B = {\n", mkname("names_", name));
for(j=0; j<t->n; j++)
Bprint(b, "\t\"%s\",\n", fixname(t->tname[j]));
Bprint(b, "};\n");
- Bprint(b, "defn %s(val) {\n", name);
+ Bprint(b, "defn %B(val) {\n", name);
Bprint(b, "\tlocal i;\n");
- Bprint(b, "\ti = match(val, vals_%s);\n", name);
- Bprint(b, "\tif i >= 0 then return names_%s[i];\n", name);
+ Bprint(b, "\ti = match(val, %B);\n", mkname("vals_", name));
+ Bprint(b, "\tif i >= 0 then return %B[i];\n", mkname("names_", name));
Bprint(b, "\treturn \"???\";\n");
Bprint(b, "};\n");
break;
diff --git a/src/cmd/acidtypes/util.c b/src/cmd/acidtypes/util.c
index 0dbc63e9..47fe193d 100644
--- a/src/cmd/acidtypes/util.c
+++ b/src/cmd/acidtypes/util.c
@@ -61,3 +61,32 @@ mktl(Type *hd, TypeList *tail)
return tl;
}
+static int isBfrog[256];
+
+int
+Bfmt(Fmt *fmt)
+{
+ int i;
+ char *s, *t;
+
+ if(!isBfrog['.']){
+ for(i=0; i<256; i++)
+ if(i != '_' && i != '$' && i < Runeself && !isalnum(i))
+ isBfrog[i] = 1;
+ }
+
+ s = va_arg(fmt->args, char*);
+ for(t=s; *t; t++){
+ if(isBfrog[(uchar)*t]){
+ if(*t == ':' && *(t+1) == ':'){
+ t++;
+ continue;
+ }
+ goto encode;
+ }
+ }
+ return fmtstrcpy(fmt, s);
+
+encode:
+ return fmtprint(fmt, "`%s`", s);
+}