+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,
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]?)
"#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 '{'; }
"," { 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; }
"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; }
"\""{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]); }
%%
}
}
-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;
return IDENTIFIER;
}
-static void process_directive (void)
+static void process_directive (GIGenerator *igenerator)
{
/* extract current filename from #line directives */
GString *filename_builder;
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);
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;
UnaryOperator unary_operator;
}
+%parse-param { GIGenerator* igenerator }
+%lex-param { GIGenerator* igenerator }
+
%token <str> IDENTIFIER "identifier"
%token <str> TYPEDEF_NAME "typedef-name"
} else {
sym->type = CSYMBOL_TYPE_OBJECT;
}
- g_igenerator_add_symbol (the_igenerator, sym);
+ g_igenerator_add_symbol (igenerator, sym);
}
}
| declaration_specifiers ';'
}
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 '}'
{
{
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);
}
}
;
%%
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);
}
}
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;
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;
}
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