From bb6822c219eb531a497d0829626ac3b29af198fa Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 24 Feb 2022 23:17:57 -0500 Subject: [PATCH] Avoid using reserved identifiers. 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 | 8 ++++---- src/lexer.l | 20 ++++++++++---------- src/util.h | 10 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/generate_treefuncs.pl b/src/generate_treefuncs.pl index 377fe43..ab47f3d 100755 --- a/src/generate_treefuncs.pl +++ b/src/generate_treefuncs.pl @@ -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 () { $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; diff --git a/src/lexer.l b/src/lexer.l index d33965d..11d79eb 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -135,22 +135,22 @@ yy_current_state = 0; ^(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 -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); -- 2.43.2