Get rid of the global the_generator variable.
authorJohan Dahlin <johan@gnome.org>
Mon, 10 Dec 2007 23:54:23 +0000 (23:54 +0000)
committerJohan Dahlin <johan@src.gnome.org>
Mon, 10 Dec 2007 23:54:23 +0000 (23:54 +0000)
2007-12-11  Johan Dahlin  <johan@gnome.org>

* src/clexer.l:
* src/cparser.y:
* src/scanner.c: (g_igenerator_new):
* src/scanner.h:
Get rid of the global the_generator variable.

svn path=/trunk/; revision=85

ChangeLog
src/clexer.l
src/cparser.y
src/scanner.c
src/scanner.h

index 8183936..38c49ea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-12-11  Johan Dahlin  <johan@gnome.org>
+
+       * src/clexer.l:
+       * src/cparser.y:
+       * src/scanner.c: (g_igenerator_new):
+       * src/scanner.h:
+       Get rid of the global the_generator variable.
+
 2007-12-10  Johan Dahlin  <johan@gnome.org>
 
        * src/scanner.c (main): Add an output option,
index ee05436..94609d1 100644 (file)
 
 int lineno;
 
+extern int yylex (GIGenerator *igenerator);
+#define YY_DECL int yylex (GIGenerator *igenerator)
 static int yywrap (void);
 static void skip_comment (void);
-static void process_directive (void);
-static int check_identifier (const char *);
+static void process_directive (GIGenerator *igenerator);
+static int check_identifier (GIGenerator *igenerator, const char *);
 %}
 
 intsuffix                              ([uU][lL]?)|([lL][uU]?)
@@ -59,7 +61,7 @@ stringtext                            ([^"])|(\\.)
 "#define "[a-zA-Z_][a-zA-Z_0-9]*"("    { yyless (yyleng - 1); return FUNCTION_MACRO; }
 "#define "[a-zA-Z_][a-zA-Z_0-9]*       { return OBJECT_MACRO; }
 
-"#"                                    { process_directive(); }
+"#"                                    { process_directive(igenerator); }
 
 "{"                                    { return '{'; }
 "<%"                                   { return '{'; }
@@ -112,7 +114,7 @@ stringtext                          ([^"])|(\\.)
 ","                                    { return ','; }
 "->"                                   { return ARROW; }
 
-[a-zA-Z_][a-zA-Z_0-9]*                 { if (the_igenerator->macro_scan) return IDENTIFIER; else REJECT; }
+[a-zA-Z_][a-zA-Z_0-9]*                 { if (igenerator->macro_scan) return IDENTIFIER; else REJECT; }
 
 "auto"                                 { return AUTO; }
 "break"                                        { return BREAK; }
@@ -149,7 +151,7 @@ stringtext                          ([^"])|(\\.)
 "volatile"                             { return VOLATILE; }
 "while"                                        { return WHILE; }
 
-[a-zA-Z_][a-zA-Z_0-9]*                 { return check_identifier(yytext); }
+[a-zA-Z_][a-zA-Z_0-9]*                 { return check_identifier(igenerator, yytext); }
 
 "0"[xX][0-9a-fA-F]+{intsuffix}?                { return INTEGER; }
 "0"[0-7]+{intsuffix}?                  { return INTEGER; }
@@ -164,7 +166,7 @@ stringtext                          ([^"])|(\\.)
 "\""{stringtext}*"\""                  { return STRING; }
 "L\""{stringtext}*"\""                 { return STRING; }
 
-.                                      { fprintf(stderr, "%s:%d: unexpected character `%c'\n", the_igenerator->current_filename, lineno, yytext[0]); }
+.                                      { fprintf(stderr, "%s:%d: unexpected character `%c'\n", igenerator->current_filename, lineno, yytext[0]); }
 
 %%
 
@@ -188,14 +190,14 @@ static void skip_comment (void)
        }
 }
 
-static int check_identifier (const char *s)
+static int check_identifier (GIGenerator *igenerator, const char *s)
 {
        /*
         * This function checks if `s' is a type name or an
         * identifier.
         */
 
-       if (g_igenerator_is_typedef (the_igenerator, s)) {
+       if (g_igenerator_is_typedef (igenerator, s)) {
                return TYPEDEF_NAME;
        } else if (strcmp (s, "__builtin_va_list") == 0) {
                return TYPEDEF_NAME;
@@ -204,7 +206,7 @@ static int check_identifier (const char *s)
        return IDENTIFIER;
 }
 
-static void process_directive (void)
+static void process_directive (GIGenerator *igenerator)
 {
        /* extract current filename from #line directives */
        GString *filename_builder;
@@ -242,8 +244,8 @@ static void process_directive (void)
 
        if (filename_builder->len > 0) {
                char *filename = g_strcompress (filename_builder->str);
-               g_free (the_igenerator->current_filename);
-               the_igenerator->current_filename = filename;
+               g_free (igenerator->current_filename);
+               igenerator->current_filename = filename;
        }
 
        g_string_free (filename_builder, TRUE);
index 692552b..73f1df7 100644 (file)
@@ -36,8 +36,8 @@ extern FILE *yyin;
 extern int lineno;
 extern char *yytext;
 
-extern int yylex (void);
-static void yyerror(const char *s);
+extern int yylex (GIGenerator *igenerator);
+static void yyerror(GIGenerator *igenerator, const char *s);
 
 static int last_enum_value = -1;
 static GHashTable *const_table = NULL;
@@ -155,6 +155,9 @@ static void csymbol_merge_type (CSymbol *symbol, CType *type)
        UnaryOperator unary_operator;
 }
 
+%parse-param { GIGenerator* igenerator }
+%lex-param { GIGenerator* igenerator }
+
 %token <str> IDENTIFIER "identifier"
 %token <str> TYPEDEF_NAME "typedef-name"
 
@@ -620,7 +623,7 @@ declaration
                        } else {
                                sym->type = CSYMBOL_TYPE_OBJECT;
                        }
-                       g_igenerator_add_symbol (the_igenerator, sym);
+                       g_igenerator_add_symbol (igenerator, sym);
                }
          }
        | declaration_specifiers ';'
@@ -766,7 +769,7 @@ struct_or_union_specifier
                }
                sym->ident = g_strdup ($$->name);
                sym->base_type = ctype_copy ($$);
-               g_igenerator_add_symbol (the_igenerator, sym);
+               g_igenerator_add_symbol (igenerator, sym);
          }
        | struct_or_union '{' struct_declaration_list '}'
          {
@@ -1282,7 +1285,7 @@ object_macro_define
          {
                if ($2->const_int_set || $2->const_string != NULL) {
                        $2->ident = $1;
-                       g_igenerator_add_symbol (the_igenerator, $2);
+                       g_igenerator_add_symbol (igenerator, $2);
                }
          }
        ;
@@ -1296,12 +1299,13 @@ macro
 %%
 
 static void
-yyerror(const char *s)
+yyerror(GIGenerator *igenerator, const char *s)
 {
        /* ignore errors while doing a macro scan as not all object macros
         * have valid expressions */
-       if (!the_igenerator->macro_scan) {
-               fprintf(stderr, "%s:%d: %s\n", the_igenerator->current_filename, lineno, s);
+       if (!igenerator->macro_scan) {
+               fprintf(stderr, "%s:%d: %s\n",
+                       igenerator->current_filename, lineno, s);
        }
 }
 
@@ -1315,7 +1319,7 @@ void g_igenerator_parse (GIGenerator *igenerator, FILE *f)
        const_table = g_hash_table_new (g_str_hash, g_str_equal);
 
        lineno = 1;
-       yyparse();
+       yyparse(igenerator);
 
        g_hash_table_unref (const_table);
        const_table = NULL;
index 7535ec9..51ea71e 100644 (file)
@@ -76,8 +76,6 @@ g_igenerator_new (const gchar *namespace,
     g_hash_table_new (g_str_hash, g_str_equal);
   igenerator->symbols = g_hash_table_new (g_str_hash, g_str_equal);
 
-  the_igenerator = igenerator;
-
   return igenerator;
 }
 
index 6c70d89..90cbed3 100644 (file)
@@ -144,7 +144,5 @@ void g_igenerator_parse (GIGenerator * igenerator, FILE * f);
 void g_igenerator_add_symbol (GIGenerator * igenerator, CSymbol * symbol);
 gboolean g_igenerator_is_typedef (GIGenerator * igenerator, const char *name);
 
-GIGenerator *the_igenerator;
-
 G_END_DECLS
 #endif