Commit 3767e0e3 authored by Michaël Cadilhac's avatar Michaël Cadilhac
Browse files

2005-09-09 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>

	* NOTICE: Correct information.
	* src/rule.c,
	* src/rule.h: Clean code.
	* src/check.c: Check if `nonterm_list' is not empty before
	accessing its first element.
	* src/parser.y: Fix minor bug when more than one file is
	processed.
	* src/main.c: Fix minor bug with `--version' and put option
	parsing in a single function.
	* src/main.c (main): Ease memory leak detection by using a
	programmer-level allocator for list.
	* src/emit_functions.c,
	* src/emit_cost.c: Output C90 compliant code.
parent 5eaa80ee
2005-09-09 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
* NOTICE: Correct information.
* src/rule.c,
* src/rule.h: Clean code.
* src/check.c: Check if `nonterm_list' is not empty before
accessing its first element.
* src/parser.y: Fix minor bug when more than one file is
processed.
* src/main.c: Fix minor bug with `--version' and put option
parsing in a single function.
* src/main.c (main): Ease memory leak detection by using a
programmer-level allocator for list.
* src/emit_functions.c,
* src/emit_cost.c: Output C90 compliant code.
2005-09-01 Akim Demaille <akim@epita.fr>
* configure.ac: Bump to 1.0.2a.
......
......@@ -15,6 +15,4 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
The Vaucanson Group consists of people listed in the `AUTHORS' file.
Contact: mono@novell.com.
......@@ -36,7 +36,8 @@ void check_result ()
g_warning ("unused terminal \"%s\"",term->name);
}
check_reach (((NonTerm *)nonterm_list->data));
if (nonterm_list)
check_reach (((NonTerm *)nonterm_list->data));
for (l = nonterm_list; l; l = l->next) {
NonTerm *n = (NonTerm *)l->data;
......
......@@ -51,7 +51,7 @@ void emit_cost_func ()
output ("(void) state;\n");
else
output ("(void) tree;\n");
output ("%s\n", rule->cfunc);
output ("\t{\n%s\n\t}\n", rule->cfunc);
output ("}\n\n");
}
i++;
......
......@@ -53,12 +53,12 @@ void emit_emitter_func ()
(with_references ? '&' : '*'));
output ("{\n");
output ("(void) tree; (void) s;");
output ("\t(void) tree; (void) s;");
if (dag_mode)
output (" (void) state;");
output ("\n");
output ("\n\t{\n");
emit_rule_variables (rule);
output ("%s\n", rule->code);
output ("%s\n\t}\n", rule->code);
output ("}\n\n");
g_hash_table_insert (cache, rule->code, GINT_TO_POINTER (i));
}
......
......@@ -28,6 +28,10 @@
#include "emit.h"
static gboolean quiet = FALSE;
static char *header_define = NULL;
static char *cfile = NULL;
static char *deffile = NULL;
static GList *infiles = NULL;
gboolean with_glib = TRUE;
gboolean with_exported_symbols = TRUE;
gboolean with_references = FALSE;
......@@ -41,12 +45,12 @@ gboolean predefined_terms = 0;
{ \
(void) data; (void) error; \
(void) option_name; (void) value; \
Code; \
{ Code; } \
}
GOPTION_CALLBACK (add_to_defined_vars,
g_hash_table_insert (definedvars, (char *) value,
g_hash_table_insert (definedvars, g_strdup (value),
GUINT_TO_POINTER (1));
return TRUE;);
......@@ -56,10 +60,6 @@ GOPTION_CALLBACK (add_to_include_dirs,
include_dirs [n_include_dir++] = (char *) g_strdup (value);
return TRUE);
GOPTION_CALLBACK (version,
printf ("%s\n", PACKAGE_STRING);
exit (0));
static void bad_use (const char *program_name, const char *use)
{
fprintf (stderr,
......@@ -89,28 +89,23 @@ static void warning_handler (const gchar *log_domain,
(void) fprintf ((FILE *) user_data, "** WARNING **: %s\n", message);
}
int main (int argc, char **argv)
static void parse_options (int argc, char **argv)
{
FILE *deffd = 0;
FILE *cfd = 0;
static char *header_define = NULL;
static char *cfile = NULL;
static char *deffile = NULL;
static gboolean without_glib = FALSE;
static gboolean without_exported_symbols = FALSE;
GList *infiles = NULL;
static gboolean version = FALSE;
int i;
GError *error = NULL;
GOptionContext* context = g_option_context_new ("- Generate a code generator. If no file is precised, "
"the standard input will be processed.");
static GOptionEntry option_entries[] = {
{ "cost", 'c', 0, G_OPTION_ARG_INT, &default_cost,
"Set the default cost to VALUE.", "VALUE" },
{ "header-file", 'd', 0, G_OPTION_ARG_FILENAME, &deffile,
"FILE will be the header file.", "FILE" },
{ "define", 'D', 0, G_OPTION_ARG_CALLBACK, &add_to_defined_vars,
"VAR will be defined to 1.", "VAR" },
"SYM will be defined to 1.", "SYM" },
{ "dag", 'e', 0, G_OPTION_ARG_NONE, &dag_mode,
"Enable DAG compatibility.", NULL },
{ "include-dir", 'I', 0, G_OPTION_ARG_CALLBACK, &add_to_include_dirs,
......@@ -123,7 +118,7 @@ int main (int argc, char **argv)
"Do not output warning messages.", NULL },
{ "source-file", 's', 0, G_OPTION_ARG_FILENAME, &cfile,
"Set FILE to be the output source code file.", "FILE" },
{ "version", 'v', 0, G_OPTION_ARG_CALLBACK, &version,
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version,
"Output version number and quit.", NULL },
{ "without-glib", 0, 0, G_OPTION_ARG_NONE, &without_glib,
"Output a glib independent code.", NULL },
......@@ -134,17 +129,14 @@ int main (int argc, char **argv)
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
/* GLib log handler. */
g_log_set_handler (NULL, G_LOG_LEVEL_WARNING, warning_handler, stderr);
/* Initialize vars. */
definedvars = g_hash_table_new (g_str_hash, g_str_equal);
include_dirs = g_new (char *, 10);
include_dirs[n_include_dir++] = g_strdup (".");
/* Parse options. */
g_option_context_add_main_entries (context, option_entries, NULL);
g_option_context_parse (context, &argc, &argv, &error);
g_option_context_free (context);
if (version)
{
printf ("%s\n", PACKAGE_STRING);
exit (0);
}
if (error)
bad_use (argv[0], error->message);
if ((cfile && !deffile) || (!cfile && deffile))
......@@ -152,9 +144,37 @@ int main (int argc, char **argv)
with_glib = !without_glib;
with_exported_symbols = !without_exported_symbols;
if (with_references)
{
warn_cxx ("`--with-references' option");
g_hash_table_insert (definedvars, g_strdup ("__WITH_REFERENCES"),
GUINT_TO_POINTER (1));
}
for (i = 1; i < argc; ++i)
infiles = g_list_append (infiles, argv[i]);
}
int main (int argc, char **argv)
{
FILE *deffd = 0;
FILE *cfd = 0;
guint handler_id;
#ifndef NDEBUG
GAllocator *list_allocator;
#endif
/* GLib log handler. */
handler_id = g_log_set_handler (NULL, G_LOG_LEVEL_WARNING, warning_handler, stderr);
#ifndef NDEBUG
/* Install our allocator, to ease leak detection. */
list_allocator = g_allocator_new ("List Allocator", 1024);
g_list_push_allocator (list_allocator);
#endif
/* Initialize vars. */
definedvars = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
include_dirs = g_list_append (include_dirs, ".");
parse_options (argc, argv);
/* Start header file. */
if (deffile) {
......@@ -243,12 +263,5 @@ int main (int argc, char **argv)
if (cfile)
fclose (cfd);
/* Aren't we clean ? */
{
int i;
for (i = 0; i < n_include_dir; ++i)
g_free (include_dirs[i]);
}
g_free (include_dirs);
return 0;
}
......@@ -143,7 +143,8 @@ static int n_input = 0;
static int state = 0;
char *fgets_inc(char *s, int size)
char *
fgets_inc(char *s, int size)
{
int n_length, i;
char filename[MAX_FILENAME_LEN];
......@@ -332,6 +333,7 @@ nextchar ()
if (ll) {
next_state = 2;
*next = 0;
return 0;
}
break;
default:
......@@ -339,7 +341,7 @@ nextchar ()
}
ll = state != 1 || input[0] == '#';
state = next_state;
} while (next_state == 2 || ll);
} while (ll);
}
return *next++;
......@@ -350,7 +352,6 @@ yyparsetail (void)
{
output ("#line %d \"%s\"\n", inputs[n_input].yylineno,
inputs[n_input].filename);
output ("%s", input);
while (fgets_inc (input, sizeof (input)))
output ("%s", input);
}
......
......@@ -31,6 +31,9 @@ GList *rule_list = NULL;
GList *prefix_list = NULL;
int default_cost = 0;
static NonTerm *nonterm (char *id);
Rule *make_rule (char *id, Tree *tree)
{
Rule *rule = g_new0 (Rule, 1);
......@@ -71,13 +74,6 @@ void rule_add (Rule *rule, char *code, char *cost, char *cfunc)
rule->tree->nonterm->chain = g_list_append (rule->tree->nonterm->chain, rule);
}
void create_rule (char *id, Tree *tree, char *code, char *cost, char *cfunc)
{
Rule *rule = make_rule (id, tree);
rule_add (rule, code, cost, cfunc);
}
static void check_varname (char *varname, Tree *t)
{
if (t->varname && !strcmp (varname, t->varname))
......@@ -195,7 +191,7 @@ Term *create_term (char *id, int num)
yyerror ("invalid terminal number %d", num);
if (!term_hash)
term_hash = g_hash_table_new (g_str_hash , g_str_equal);
term_hash = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_foreach (term_hash, (GHFunc) check_term_num, (gpointer) num);
......@@ -212,12 +208,12 @@ Term *create_term (char *id, int num)
return term;
}
NonTerm *nonterm (char *id)
static NonTerm *nonterm (char *id)
{
NonTerm *nterm;
if (!nonterm_hash)
nonterm_hash = g_hash_table_new (g_str_hash , g_str_equal);
nonterm_hash = g_hash_table_new (g_str_hash, g_str_equal);
if ((nterm = g_hash_table_lookup (nonterm_hash, id)))
return nterm;
......
......@@ -71,11 +71,8 @@ Tree *create_tree (char *id, char *varname, Tree *left, Tree *right);
Term *create_term (char *id, int num);
void create_term_prefix (char *id);
GList *rule_list_prepend (GList *list, Rule *rule);
NonTerm *nonterm (char *id);
void start_nonterm (char *id);
Rule *make_rule (char *id, Tree *tree);
void rule_add (Rule *rule, char *code, char *cost, char *cfunc);
void create_rule (char *id, Tree *tree, char *code, char *cost,
char *cfunc);
#endif /* __MONO_RULE_H__ */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment