Commit 13cc5ded authored by Roland Levillain's avatar Roland Levillain

Version 1.0.5.

Rework MonoBURG options.

- configure.ac: Version 1.0.5.
- NEWS: Update.
- src/main.c (main): Set default include directory to "" instead
of ".".
Disable uncontrolled emission of `#line' directives.
- src/parser.y (fgets_inc): Likewise.
(WITH_REFERENCES): Rename token as...
(CXX_REF): ...this.
(NO_LINES, NO_GLIB, NO_EXPORTED_SYMBOLS): New tokens.
(yylex): Generate these tokens.
(decls): Use them in this production to recognize new
\%-directives.
(fgets_inc): Don't print empty include dirs.
- tests/sample.brg: Use \%no-lines.

- src/main.c (with_line, with_glib, with_exported_symbols)
(with_references): Rename as...
(lines_p, glib_p, exported_symbols_p, cxx_ref_p): ...these.
(parse_options): Adjust.
- src/monoburg.h,
- src/emit.c (emit_includes, emit_header, emit_label_func) 
(emit_vardefs, emit_vardefs, emit_prototypes)
- src/emit_cost.c (emit_cost_func)
- src/emit_kids.c (emit_kids)
- src/emit_functions.c (emit_emitter_func)
- src/named_subtree.c (compute_vartree_decs_)
- src/parser.y (fgets_inc, yyparsetail, yylex): Adjust.
parent 51107bee
2006-02-01 Roland Levillain <roland@lrde.epita.fr>
Version 1.0.5.
Rework MonoBURG options.
* configure.ac: Version 1.0.5.
* NEWS: Update.
* src/main.c (main): Set default include directory to "" instead
of ".".
Disable uncontrolled emission of `#line' directives.
* src/parser.y (fgets_inc): Likewise.
(WITH_REFERENCES): Rename token as...
(CXX_REF): ...this.
(NO_LINES, NO_GLIB, NO_EXPORTED_SYMBOLS): New tokens.
(yylex): Generate these tokens.
(decls): Use them in this production to recognize new
\%-directives.
(fgets_inc): Don't print empty include dirs.
* tests/sample.brg: Use \%no-lines.
* src/main.c (with_line, with_glib, with_exported_symbols)
(with_references): Rename as...
(lines_p, glib_p, exported_symbols_p, cxx_ref_p): ...these.
(parse_options): Adjust.
* src/monoburg.h,
* src/emit.c (emit_includes, emit_header, emit_label_func)
(emit_vardefs, emit_vardefs, emit_prototypes)
* src/emit_cost.c (emit_cost_func)
* src/emit_kids.c (emit_kids)
* src/emit_functions.c (emit_emitter_func)
* src/named_subtree.c (compute_vartree_decs_)
* src/parser.y (fgets_inc, yyparsetail, yylex): Adjust.
2006-01-19 Roland Levillain <roland@lrde.epita.fr>
* NEWS: Update.
......
* 1.0.4a
* New in 1.0.5, 2006-02-01:
** Support `with-references' option as a %-directive
** Rework MonoBURG options
Monoburg generates C++ references instead of pointers when using
`--with-references', or upon a `%with-references' directive in the
input file.
Instead of `--with-line', provide a `--no-line' option, and output
`#line' directives by default.
The options
`--without-glib',
`--without-exported-symbols' and
`--with-references'
become (respectively)
`--no-glib',
`--no-exported-symbols' and
`--cxx-ref'.
** Support options as %-directives
For instance, MonoBURG generates C++ references instead of pointers
when using `--cxx-ref', or upon a `%cxx-ref' directive in the input
file. Idem for `%no-lines', `%no-glib' and `%no-exported-symbols'.
** Improve #line emission
Default include path is now "" instead of "." to avoid things like
#line 1 "./tree.brg"
* 1.0.4
......
......@@ -14,7 +14,7 @@
## -------------------------------------
## Project
AC_INIT([MonoBURG], [1.0.4a])
AC_INIT([MonoBURG], [1.0.5])
AM_CONFIG_HEADER([config.h])
## -------------------------------------
......
......@@ -3,7 +3,7 @@
**
** MonoBURG, an iburg like code generator generator.
**
** Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
** Copyright (C) 2001, 2002, 2004, 2005, 2006 Ximian, Inc.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
......@@ -45,7 +45,7 @@ void output (char *fmt, ...)
/** Emit includes of external header files. */
void emit_includes ()
{
if (with_glib) {
if (glib_p) {
output ("#include <glib.h>\n");
output ("\n");
}
......@@ -57,10 +57,10 @@ void emit_includes ()
}
}
/** Emit header defines, replace glib definitions if !with_glib. */
/** Emit header defines, replace glib definitions if !glib_p. */
void emit_header ()
{
if (!with_glib) {
if (!glib_p) {
output ("#ifndef guint8\n"
"# define guint8 unsigned char\n"
"#endif /* !guint8 */\n"
......@@ -414,7 +414,7 @@ void emit_label_func ()
output ("}\n\n");
if (!with_exported_symbols)
if (!exported_symbols_p)
output ("static ");
output ("MBState *\n");
output ("mono_burg_label (MBTREE_TYPE *tree, MBCOST_DATA *data)\n{\n");
......@@ -455,7 +455,7 @@ void emit_vardefs ()
if (predefined_terms) {
output ("guint8 mono_burg_arity [MBMAX_OPCODES];\n");
if (!with_exported_symbols)
if (!exported_symbols_p)
output ("static ");
output ("void\nmono_burg_init (void)\n{\n");
......@@ -484,7 +484,7 @@ void emit_vardefs ()
}
output ("};\n\n");
if (with_exported_symbols) {
if (exported_symbols_p) {
output ("const char *const mono_burg_term_string [] = {\n");
output ("\tNULL,\n");
for (l = term_list, i = 0; l; l = l->next) {
......@@ -495,7 +495,7 @@ void emit_vardefs ()
}
}
if (!with_exported_symbols)
if (!exported_symbols_p)
output ("static ");
output ("const char * const mono_burg_rule_string [] = {\n");
output ("\tNULL,\n");
......@@ -530,7 +530,7 @@ void emit_vardefs ()
}
output ("\n");
if (!with_exported_symbols)
if (!exported_symbols_p)
output ("static ");
output ("const guint16 *const mono_burg_nts [] = {\n");
output ("\t0,\n");
......@@ -552,12 +552,12 @@ void emit_prototypes ()
{
if (dag_mode)
output ("typedef void (*MBEmitFunc) (MBState *state, MBTREE_TYPE %ctree, MBCGEN_TYPE *s);\n\n",
(with_references ? '&' : '*'));
(cxx_ref_p ? '&' : '*'));
else
output ("typedef void (*MBEmitFunc) (MBTREE_TYPE %ctree, MBCGEN_TYPE *s);\n\n",
(with_references ? '&' : '*'));
(cxx_ref_p ? '&' : '*'));
if (with_exported_symbols) {
if (exported_symbols_p) {
output ("extern const char * const mono_burg_term_string [];\n");
output ("extern const char * const mono_burg_rule_string [];\n");
output ("extern const guint16 *const mono_burg_nts [];\n");
......
......@@ -29,7 +29,7 @@ void emit_cost_func ()
GList *l;
int i;
if (!with_exported_symbols)
if (!exported_symbols_p)
output ("static int mono_burg_rule (MBState *state, int goal);\n");
for (l = rule_list, i = 0; l; l = l->next) {
......@@ -44,7 +44,7 @@ void emit_cost_func ()
output ("mono_burg_cost_%d (MBState *state, MBCOST_DATA *data)\n", i + 1);
else
output ("mono_burg_cost_%d (MBTREE_TYPE %ctree, MBCOST_DATA *data)\n", i + 1,
(with_references ? '&' : '*'));
(cxx_ref_p ? '&' : '*'));
output ("{\n");
output ("\t(void) data; ");
if (dag_mode)
......
......@@ -44,10 +44,10 @@ void emit_emitter_func ()
if (dag_mode)
output ("mono_burg_emit_%d (MBState *state, MBTREE_TYPE %ctree, MBCGEN_TYPE *s)\n", i,
(with_references ? '&' : '*'));
(cxx_ref_p ? '&' : '*'));
else
output ("mono_burg_emit_%d (MBTREE_TYPE %ctree, MBCGEN_TYPE *s)\n", i,
(with_references ? '&' : '*'));
(cxx_ref_p ? '&' : '*'));
output ("{\n");
output ("\t(void) tree; (void) s;");
......@@ -62,7 +62,7 @@ void emit_emitter_func ()
g_hash_table_destroy (cache);
if (!with_exported_symbols)
if (!exported_symbols_p)
output ("static ");
output ("MBEmitFunc const mono_burg_func [] = {\n");
output ("\tNULL,\n");
......
......@@ -31,7 +31,7 @@ void emit_kids ()
int i, j, c, n, *si;
char **sa;
if (!with_exported_symbols)
if (!exported_symbols_p)
output ("static ");
output ("int\n");
output ("mono_burg_rule (MBState *state, int goal)\n{\n");
......@@ -55,7 +55,7 @@ void emit_kids ()
if (dag_mode) {
if (!with_exported_symbols)
if (!exported_symbols_p)
output ("static ");
output ("MBState **\n");
output ("mono_burg_kids (MBState *state, int rulenr, MBState *kids [])\n{\n");
......@@ -63,7 +63,7 @@ void emit_kids ()
output ("\tg_return_val_if_fail (kids != NULL, NULL);\n\n");
} else {
if (!with_exported_symbols)
if (!exported_symbols_p)
output ("static ");
output ("MBTREE_TYPE **\n");
output ("mono_burg_kids (MBTREE_TYPE *tree, int rulenr, MBTREE_TYPE *kids [])\n{\n");
......
......@@ -3,7 +3,7 @@
**
** MonoBURG, an iburg like code generator generator.
**
** Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
** Copyright (C) 2001, 2002, 2004, 2005, 2006 Ximian, Inc.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
......@@ -30,10 +30,10 @@ static char *header_define = NULL;
static char *cfile = NULL;
static char *deffile = NULL;
static GList *infiles = NULL;
gboolean with_line = FALSE;
gboolean with_glib = TRUE;
gboolean with_exported_symbols = TRUE;
gboolean with_references = FALSE;
gboolean lines_p = TRUE;
gboolean glib_p = TRUE;
gboolean exported_symbols_p = TRUE;
gboolean cxx_ref_p = FALSE;
gboolean dag_mode = 0;
gboolean predefined_terms = 0;
......@@ -88,8 +88,9 @@ static void warning_handler (const gchar *log_domain,
static void parse_options (int argc, char **argv)
{
static gboolean without_glib = FALSE;
static gboolean without_exported_symbols = FALSE;
static gboolean no_lines_p = FALSE;
static gboolean no_glib_p = FALSE;
static gboolean no_exported_symbols_p = FALSE;
static gboolean version = FALSE;
int i;
GError *error = NULL;
......@@ -117,14 +118,14 @@ static void parse_options (int argc, char **argv)
"Set FILE to be the output source code file.", "FILE" },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version,
"Output version number and quit.", NULL },
{ "with-line", 'l', 0, G_OPTION_ARG_NONE, &with_line,
"Output `#line' directives.", NULL },
{ "without-glib", 0, 0, G_OPTION_ARG_NONE, &without_glib,
{ "no-lines", 'l', 0, G_OPTION_ARG_NONE, &no_lines_p,
"Don't output `#line' directives.", NULL },
{ "no-glib", 0, 0, G_OPTION_ARG_NONE, &no_glib_p,
"Output a glib independent code.", NULL },
{ "without-exported-symbols", 0, 0, G_OPTION_ARG_NONE, &without_exported_symbols,
{ "no-exported-symbols", 0, 0, G_OPTION_ARG_NONE, &no_exported_symbols_p,
"Avoid exported symbols as much as possible.", NULL },
{ "with-references", 0, 0, G_OPTION_ARG_NONE, &with_references,
"Make emit functions to take references, not pointers.", NULL },
{ "cxx-ref", 0, 0, G_OPTION_ARG_NONE, &cxx_ref_p,
"Generate emission functions taking references instead of pointers.", NULL },
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
......@@ -140,12 +141,14 @@ static void parse_options (int argc, char **argv)
bad_use (argv[0], error->message);
if ((cfile && !deffile) || (!cfile && deffile))
bad_use (argv[0], "-s and -d must be precised together");
with_glib = !without_glib;
with_exported_symbols = !without_exported_symbols;
if (with_references)
/* Turn `without' options into `with' options. */
lines_p = !no_lines_p;
glib_p = !no_glib_p;
exported_symbols_p = !no_exported_symbols_p;
if (cxx_ref_p)
{
warn_cxx ("`--with-references' option");
g_hash_table_insert (definedvars, g_strdup ("__WITH_REFERENCES"),
warn_cxx ("`--cxx-ref' option");
g_hash_table_insert (definedvars, g_strdup ("__CXX_REF"),
GUINT_TO_POINTER (1));
}
for (i = 1; i < argc; ++i)
......@@ -173,7 +176,9 @@ int main (int argc, char **argv)
/* Initialize vars. */
definedvars = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
include_dirs = g_list_append (include_dirs, ".");
/* Add an empty include directory, referring implicitely to the
current directory. */
include_dirs = g_list_append (include_dirs, "");
parse_options (argc, argv);
/* Start header file. */
......@@ -202,8 +207,13 @@ int main (int argc, char **argv)
exit (-1);
}
input.filename = infile;
if (with_line)
/* FIXME: At this stage, we can emit a #line even if the %no-lines directive
might be read later in the grammar. So, this part has been disabled until
the scanner/parser is revamped to handle this case. */
#if 0
if (lines_p)
output ("#line %d \"%s\"\n", 1, infile);
#endif
yyparse ();
reset_parser ();
......
......@@ -25,10 +25,10 @@
# include <config.h>
# include <glib.h>
extern gboolean with_line;
extern gboolean with_glib;
extern gboolean with_exported_symbols;
extern gboolean with_references;
extern gboolean lines_p;
extern gboolean glib_p;
extern gboolean exported_symbols_p;
extern gboolean cxx_ref_p;
extern int predefined_terms;
extern int dag_mode;
......
......@@ -47,7 +47,7 @@ static char *compute_vartree_decs_ (char *prefix, int depth, VarTree *t)
GList *varnames = t->varnames;
for (; varnames; varnames = varnames->next) {
if (with_references)
if (cxx_ref_p)
tmp_res = "%s\tMBTREE_TYPE &%s = *(%s(&tree))";
else
tmp_res = "%s\tMBTREE_TYPE *%s = (%s(tree))";
......
......@@ -4,7 +4,7 @@
**
** MonoBURG, an iburg like code generator generator.
**
** Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
** Copyright (C) 2001, 2002, 2004, 2005, 2006 Ximian, Inc.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
......@@ -54,7 +54,10 @@ GList *include_dirs = NULL;
%token TERM
%token TERMPREFIX
%token NAMESPACE
%token WITH_REFERENCES
%token NO_LINES
%token NO_GLIB
%token NO_EXPORTED_SYMBOLS
%token CXX_REF
%token <ivalue> INTEGER
%type <tree> tree
......@@ -75,10 +78,14 @@ decls : /* empty */
warn_cxx ("`%namespace' directive");
namespaces = g_list_append (namespaces, $2);
} decls
| WITH_REFERENCES {
warn_cxx ("`%with-references' directive");
| NO_LINES { lines_p = FALSE; } decls
| NO_GLIB { glib_p = FALSE; } decls
| NO_EXPORTED_SYMBOLS { exported_symbols_p = FALSE; } decls
| CXX_REF {
warn_cxx ("`%cxx-ref' directive");
cxx_ref_p = TRUE;
g_hash_table_insert (definedvars,
g_strdup ("__WITH_REFERENCES"),
g_strdup ("__CXX_REF"),
GUINT_TO_POINTER (1));
} decls
| rule_list optcost optcode optcfunc {
......@@ -163,10 +170,15 @@ fgets_inc(char *s, int size)
free (LASTINPUT->filename);
fclose (LASTINPUT->fd);
inputs = g_list_delete_link (inputs, g_list_last (inputs));
if (state != 1 && with_line)
/* FIXME: At this stage, we can emit a #line even if the %no-lines directive
might be read later in the grammar. So, this part has been disabled until
the scanner/parser is revamped to handle this case. */
#if 0
if (state != 1 && lines_p)
output ("#line %d \"%s\"\n",
LASTINPUT->yylineno + 1,
LASTINPUT->filename);
#endif
return fgets_inc(s, size);
}
......@@ -186,7 +198,10 @@ fgets_inc(char *s, int size)
else
while ((b_found == FALSE) && include_dir)
{
sprintf (path, "%s/%s", (char *) include_dir->data, filename);
if (strcmp ((char *) include_dir->data, "") == 0)
sprintf (path, "%s", filename);
else
sprintf (path, "%s/%s", (char *) include_dir->data, filename);
if ((new_include->fd = fopen (path, "r")))
b_found = TRUE;
include_dir = include_dir->next;
......@@ -197,7 +212,7 @@ fgets_inc(char *s, int size)
yyerror ("`%%include %s': %s",
filename, strerror(errno));
}
if (state != 1 && with_line)
if (state != 1 && lines_p)
output ("#line %d \"%s\"\n", 1, path);
new_include->yylineno = 0;
new_include->filename = g_strdup (path);
......@@ -361,7 +376,7 @@ nextchar (void)
void
yyparsetail (void)
{
if (with_line)
if (lines_p)
output ("#line %d \"%s\"\n", LASTINPUT->yylineno,
LASTINPUT->filename);
while (fgets_inc (input, sizeof (input)))
......@@ -384,6 +399,7 @@ yylex (void)
continue;
if (c == '%') {
/* FIXME: Don't hard-code token lengths. */
if (!strncmp (next, "start", 5) && isspace (next[5])) {
next += 5;
return START;
......@@ -404,9 +420,24 @@ yylex (void)
return NAMESPACE;
}
if (!strncmp (next, "with-references", 15) && isspace (next[15])) {
next += 15;
return WITH_REFERENCES;
if (!strncmp (next, "no-lines", 8) && isspace (next[8])) {
next += 8;
return NO_LINES;
}
if (!strncmp (next, "no-glib", 7) && isspace (next[7])) {
next += 7;
return NO_GLIB;
}
if (!strncmp (next, "no-exported-symbols", 19) && isspace (next[19])) {
next += 19;
return NO_EXPORTED_SYMBOLS;
}
if (!strncmp (next, "cxx-ref", 7) && isspace (next[7])) {
next += 7;
return CXX_REF;
}
return c;
......@@ -459,7 +490,7 @@ yylex (void)
static char buf [100000];
g_memmove (buf, "\t{\n", 4);
if (with_line)
if (lines_p)
i += sprintf (buf + 3, "#line %d \"%s\"\n", LASTINPUT->yylineno,
LASTINPUT->filename);
while (d && (c = nextchar ())) {
......
......@@ -22,6 +22,9 @@ struct _MBTree {
# comments start with a '#' as first line character
#
# Don't output #lines, to avoid differences due to the build path.
%no-lines
#
# we must fisrt define the terminals
# with or without numbers
......
Markdown is supported
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