]> git.draconx.ca Git - gob-dx.git/commitdiff
Avoid using reserved identifiers.
authorNick Bowler <nbowler@draconx.ca>
Fri, 25 Feb 2022 04:17:57 +0000 (23:17 -0500)
committerNick Bowler <nbowler@draconx.ca>
Fri, 25 Feb 2022 04:41:26 +0000 (23:41 -0500)
In C, all identifiers beginning with an underscore followed by either
another underscore or an uppercase letter are reserved for use by the
implementation in all contexts.

Let's avoid such identifiers in the program proper.  Since most problems
are declarations like 'typedef struct _Foo Foo;' we can just change this
without too much issue.

The generated code still does this sort of thing, but unfortunately
would be a more significant change as this behaviour is documented.

src/generate_treefuncs.pl
src/lexer.l
src/util.h

index 377fe434d0bd902e12eaca5cc5f9c5a683ba2c3b..ab47f3d79700effca730ab3b0dc08d22978db5cb 100755 (executable)
@@ -11,7 +11,7 @@ print OUTC " * Do not edit by hand! */\n\n";
 print OUTH "/* Generated by generate_treefuncs.pl from treefuncs.def!\n";
 print OUTH " * Do not edit by hand! */\n\n";
 
-$typedefs = "typedef union _Node Node;\n";
+$typedefs = "typedef union Node Node;\n";
 $typeenums = "enum {\n";
 
 $typename = "";
@@ -126,9 +126,9 @@ while (<FILE>) {
 
                $typeenums .= "\t$uct"."_NODE,\n";
 
-               $typedefs .= "typedef struct _$typename $typename;\n";
+               $typedefs .= "typedef struct $typename $typename;\n";
 
-               $typestruct{$typename} = "struct _$typename {\n\tNodeType type;\n";
+               $typestruct{$typename} = "struct $typename {\n\tNodeType type;\n";
                $copyfunc_prot{$typename} = "static $typename *\ncopy_$lct ($typename * self)";
                $setfunc_prot{$typename} = "static void\nsetv_$lct ($typename * self, va_list __ap)";
                $freefunc_prot{$typename} = "void\nfree_$lct ($typename * self)";
@@ -261,7 +261,7 @@ foreach $t (sort keys %typestruct) {
        print OUTH "$typestruct{$t}\n\n";
 }
 
-print OUTH "union _Node {\n\tNodeType type;\n";
+print OUTH "union Node {\n\tNodeType type;\n";
 
 foreach $t (sort keys %typestruct) {
        $foo = lc $t;
index d33965db2119190c474205bc44ddaafbb210bff8..11d79eb2d941d826447021b25b6779a1441b5f5d 100644 (file)
@@ -135,22 +135,22 @@ yy_current_state = 0;
 <COMMENT>^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\))        {
 /* Thy evil easter egg */
 #define QQ(x) long x
-#define KK(x) =atoi(__(&,,x,))
+#define KK(x) =atoi(oo(&,,x,))
 #define MM(x,a) {QQ(i);for(i=2;i<x;i++){a}}
 #define PP(Q) (P%Q)==0
-#define ___(x,y,z) if(x z y)
-#define __(a,x,y,z) a(yytext[y] x z)
-#define O__O(a,b) fprintf(stderr,"%s is %s!\n",a,b)
-QQ(m)=1;___(__(,==,2,'P'),__(,==,5,'M'),&&
-){QQ(P)KK(8);MM(P,___(PP(i),,)m=0;)}__(,=,
-7,0);___(,,m){O__O(__( &,,8,),__(&,,2,));}
+#define ooo(x,y,z) if(x z y)
+#define oo(a,x,y,z) a(yytext[y] x z)
+#define OooO(a,b) fprintf(stderr,"%s is %s!\n",a,b)
+QQ(m)=1;ooo(oo(,==,2,'P'),oo(,==,5,'M'),&&
+){QQ(P)KK(8);MM(P,ooo(PP(i),,)m=0;)}oo(,=,
+7,0);ooo(,,m){OooO(oo( &,,8,),oo(&,,2,));}
 #undef QQ
 #undef KK
 #undef MM
 #undef PP
-#undef ___
-#undef __
-#undef O__O
+#undef ooo
+#undef oo
+#undef OooO
 REJECT;
 }
 
index 03a12d12fbd0701efad6f1cb003b204f908554dd..8794394cece87059b5231b408b56f0d89ceb931a 100644 (file)
@@ -26,8 +26,8 @@
 
 #include <glib.h>
 
-struct _Class;
-struct _Type;
+struct Class;
+struct Type;
 
 enum {
        GOB_WARN,
@@ -73,8 +73,8 @@ char * make_pre_macro(const char *base,const  char *pre);
 
 /* get a name usable for a cast from a GObject (without G_TYPE_)*/
 const char *get_cast(const char *type, gboolean simple_only);
-struct _Type *get_tree_type(const char *type, gboolean simple_only);
-char *get_type(const struct _Type *t, gboolean postfix_to_stars);
+struct Type *get_tree_type(const char *type, gboolean simple_only);
+char *get_type(const struct Type *t, gboolean postfix_to_stars);
 
 enum {
        SPECIAL_2POINTER,
@@ -84,7 +84,7 @@ enum {
 };
 
 /* returns TRUE if there are any special types at all */
-gboolean setup_special_array(struct _Class *c, gboolean *special_array);
+gboolean setup_special_array(struct Class *c, gboolean *special_array);
 
 char * make_me_type (const char *type, const char *alt);