Use the new code_props interface in parse-gram.y.

* src/parse-gram.y (prologue_declaration, braceless, epilogue.opt):
Update all uses of translate_* functions to use the new code_props
interface and to use gram_scanner_last_string_free and
code_scanner_last_string_free where possible.
(grammar_declaration): symbol_list_destructor_set and
symbol_list_printer_set now perform the translation, so don't do it
here.  Use gram_scanner_last_string_free where possible.
* src/scan-code.h, src/scan-code.l (translate_symbol_action,
translate_code): Remove, no longer used.
* src/symlist.h, src/symlist.c (symbol_list_destructor_set,
symbol_list_printer_set): Perform code translation here rather than
depending on the caller to do so.

* src/symlist.h (struct symbol_list): Correct some documentation typos.
* src/scan-gram.h (gram_last_string): Remove declaration.
* src/scan-gram.l (last_string): Declare it static.
This commit is contained in:
Joel E. Denny
2007-01-03 05:14:57 +00:00
parent 28e52c0d62
commit 7c0c61812d
10 changed files with 382 additions and 330 deletions

View File

@@ -1,3 +1,23 @@
2007-01-02 Joel E. Denny <jdenny@ces.clemson.edu>
Use the new code_props interface in parse-gram.y.
* src/parse-gram.y (prologue_declaration, braceless, epilogue.opt):
Update all uses of translate_* functions to use the new code_props
interface and to use gram_scanner_last_string_free and
code_scanner_last_string_free where possible.
(grammar_declaration): symbol_list_destructor_set and
symbol_list_printer_set now perform the translation, so don't do it
here. Use gram_scanner_last_string_free where possible.
* src/scan-code.h, src/scan-code.l (translate_symbol_action,
translate_code): Remove, no longer used.
* src/symlist.h, src/symlist.c (symbol_list_destructor_set,
symbol_list_printer_set): Perform code translation here rather than
depending on the caller to do so.
* src/symlist.h (struct symbol_list): Correct some documentation typos.
* src/scan-gram.h (gram_last_string): Remove declaration.
* src/scan-gram.l (last_string): Declare it static.
2007-01-02 Joel E. Denny <jdenny@ces.clemson.edu>
Encapsulate code properties and related functionality for the various

File diff suppressed because it is too large Load Diff

View File

@@ -170,8 +170,8 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 1535 of yacc.c */
#line 97 "parse-gram.y"
/* Line 1538 of yacc.c */
#line 98 "parse-gram.y"
symbol *symbol;
symbol_list *list;
@@ -183,7 +183,7 @@ typedef union YYSTYPE
unsigned char character;
}
/* Line 1535 of yacc.c */
/* Line 1538 of yacc.c */
#line 188 "parse-gram.h"
YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1

View File

@@ -1,6 +1,7 @@
%{/* Bison Grammar Parser -*- C -*-
Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,
Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -185,7 +186,7 @@ static int current_prec = 0;
%printer { fputs (char_name ($$), stderr); } CHAR
/* braceless is not to be used for rule or symbol actions, as it
calls translate_code. */
calls code_props_plain_init. */
%type <chars> STRING "%{...%}" EPILOGUE braceless content content.opt
%type <code> "{...}"
%printer { fputs (quotearg_style (c_quoting_style, $$), stderr); }
@@ -225,7 +226,15 @@ prologue_declarations:
prologue_declaration:
grammar_declaration
| "%{...%}" { prologue_augment (translate_code ($1, @1), @1, union_seen); }
| "%{...%}"
{
code_props plain_code;
code_props_plain_init (&plain_code, $1, @1);
code_props_translate_code (&plain_code);
gram_scanner_last_string_free ();
prologue_augment (plain_code.code, @1, union_seen);
code_scanner_last_string_free ();
}
| "%debug" { debug_flag = true; }
| "%define" STRING content.opt { muscle_insert ($2, $3); }
| "%defines" { defines_flag = true; }
@@ -246,7 +255,12 @@ prologue_declaration:
}
| "%initial-action" "{...}"
{
muscle_code_grow ("initial_action", translate_symbol_action ($2, @2), @2);
code_props action;
code_props_symbol_action_init (&action, $2, @2);
code_props_translate_code (&action);
gram_scanner_last_string_free ();
muscle_code_grow ("initial_action", action.code, @2);
code_scanner_last_string_free ();
}
| "%language" STRING { language_argmatch ($2, 1, &@1); }
| "%lex-param" "{...}" { add_param ("lex_param", $2, @2); }
@@ -279,17 +293,15 @@ grammar_declaration:
| "%destructor" "{...}" generic_symlist
{
symbol_list *list;
const char *action = translate_symbol_action ($2, @2);
for (list = $3; list; list = list->next)
symbol_list_destructor_set (list, action, @2);
symbol_list_destructor_set (list, $2, @2);
symbol_list_free ($3);
}
| "%printer" "{...}" generic_symlist
{
symbol_list *list;
const char *action = translate_symbol_action ($2, @2);
for (list = $3; list; list = list->next)
symbol_list_printer_set (list, action, @2);
symbol_list_printer_set (list, $2, @2);
symbol_list_free ($3);
}
| "%default-prec"
@@ -340,6 +352,7 @@ grammar_declaration:
union_seen = true;
muscle_code_grow ("stype", body, @3);
gram_scanner_last_string_free ();
}
;
@@ -522,8 +535,12 @@ content.opt:
braceless:
"{...}"
{
code_props plain_code;
$1[strlen ($1) - 1] = '\n';
$$ = translate_code ($1 + 1, @1);
code_props_plain_init (&plain_code, $1+1, @1);
code_props_translate_code (&plain_code);
gram_scanner_last_string_free ();
$$ = plain_code.code;
}
;
@@ -569,8 +586,12 @@ epilogue.opt:
/* Nothing. */
| "%%" EPILOGUE
{
muscle_code_grow ("epilogue", translate_code ($2, @2), @2);
code_props plain_code;
code_props_plain_init (&plain_code, $2, @2);
code_props_translate_code (&plain_code);
gram_scanner_last_string_free ();
muscle_code_grow ("epilogue", plain_code.code, @2);
code_scanner_last_string_free ();
}
;

View File

@@ -162,22 +162,14 @@ void code_scanner_last_string_free (void);
* \pre
* - None.
* \post
* - All dynamic memory allocated during any previous invocations of
* \c code_props_translate_code, \c translate_rule_action,
* \c translate_symbol_action, and \c translate_code has been freed. All
* \c code_props instances may now be invalid.
* - All dynamic memory allocated during invocations of
* \c code_props_translate_code or \c translate_rule_action (if any) has
* been freed. All \c code_props instances may now be invalid.
*/
void code_scanner_free (void);
/* The action of the rule R contains $$, $1 etc. referring to the values
of the rule R. */
char const *translate_rule_action (symbol_list *r);
/* The action A refers to $$ and @$ only, referring to a symbol. */
char const *translate_symbol_action (char const *a, location l);
/* The action contains no special escapes, just protect M4 special
symbols. */
char const *translate_code (char const *a, location l);
char const *translate_rule_action (struct symbol_list *r);
#endif /* !SCAN_CODE_H_ */

View File

@@ -488,21 +488,3 @@ translate_rule_action (symbol_list *rule)
code_props_translate_code (&cp);
return cp.code;
}
char const *
translate_symbol_action (char const *a, location l)
{
code_props cp;
code_props_symbol_action_init (&cp, a, l);
code_props_translate_code (&cp);
return cp.code;
}
char const *
translate_code (char const *a, location l)
{
code_props cp;
code_props_plain_init (&cp, a, l);
code_props_translate_code (&cp);
return cp.code;
}

View File

@@ -1,6 +1,6 @@
/* Bison Grammar Scanner
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -26,7 +26,6 @@
/* From the scanner. */
extern FILE *gram_in;
extern int gram__flex_debug;
extern char *gram_last_string;
void gram_scanner_initialize (void);
void gram_scanner_free (void);
void gram_scanner_last_string_free (void);

View File

@@ -1,6 +1,7 @@
/* Bison Grammar Scanner -*- C -*-
Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,
Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -58,7 +59,7 @@ static size_t no_cr_read (FILE *, char *, size_t);
#define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
/* A string representing the most recently saved token. */
char *last_string;
static char *last_string;
void
gram_scanner_last_string_free (void)

View File

@@ -208,44 +208,52 @@ symbol_list_n_type_name_get (symbol_list *l, location loc, int n)
void
symbol_list_destructor_set (symbol_list *node, const char *destructor,
symbol_list_destructor_set (symbol_list *node, char const *code,
location loc)
{
code_props destructor;
code_props_symbol_action_init (&destructor, code, loc);
code_props_translate_code (&destructor);
code = destructor.code;
switch (node->content_type)
{
case SYMLIST_SYMBOL:
symbol_destructor_set (node->content.sym, destructor, loc);
symbol_destructor_set (node->content.sym, code, loc);
break;
case SYMLIST_TYPE:
semantic_type_destructor_set (
semantic_type_get (node->content.type_name), destructor, loc);
semantic_type_get (node->content.type_name), code, loc);
break;
case SYMLIST_DEFAULT_TAGGED:
default_tagged_destructor_set (destructor, loc);
default_tagged_destructor_set (code, loc);
break;
case SYMLIST_DEFAULT_TAGLESS:
default_tagless_destructor_set (destructor, loc);
default_tagless_destructor_set (code, loc);
break;
}
}
void
symbol_list_printer_set (symbol_list *node, const char *printer, location loc)
symbol_list_printer_set (symbol_list *node, char const *code, location loc)
{
code_props printer;
code_props_symbol_action_init (&printer, code, loc);
code_props_translate_code (&printer);
code = printer.code;
switch (node->content_type)
{
case SYMLIST_SYMBOL:
symbol_printer_set (node->content.sym, printer, loc);
symbol_printer_set (node->content.sym, code, loc);
break;
case SYMLIST_TYPE:
semantic_type_printer_set (
semantic_type_get (node->content.type_name), printer, loc);
semantic_type_get (node->content.type_name), code, loc);
break;
case SYMLIST_DEFAULT_TAGGED:
default_tagged_printer_set (printer, loc);
default_tagged_printer_set (code, loc);
break;
case SYMLIST_DEFAULT_TAGLESS:
default_tagless_printer_set (printer, loc);
default_tagless_printer_set (code, loc);
break;
}
}

View File

@@ -23,6 +23,7 @@
# define SYMLIST_H_
# include "location.h"
# include "scan-code.h"
# include "symtab.h"
/* A list of symbols, used during the parsing to store the rules. */
@@ -37,9 +38,14 @@ typedef struct symbol_list
SYMLIST_DEFAULT_TAGGED, SYMLIST_DEFAULT_TAGLESS
} content_type;
union {
/** The symbol or \c NULL iff <tt>node_type = SYMLIST_SYMBOL</tt>. */
/**
* The symbol or \c NULL iff
* <tt>symbol_list::content_type = SYMLIST_SYMBOL</tt>.
*/
symbol *sym;
/** The semantic type iff <tt>node_type = SYMLIST_TYPE</tt>. */
/**
* The semantic type iff <tt>symbol_list::content_type = SYMLIST_TYPE</tt>.
*/
uniqstr type_name;
} content;
location location;
@@ -106,12 +112,12 @@ symbol_list *symbol_list_n_get (symbol_list *l, int n);
symbol N in rule RULE. */
uniqstr symbol_list_n_type_name_get (symbol_list *l, location loc, int n);
/** Set the \c \%destructor for \c node as \c destructor at \c loc. */
void symbol_list_destructor_set (symbol_list *node, const char *destructor,
/** Set the \c \%destructor for \c node as \c code at \c loc. */
void symbol_list_destructor_set (symbol_list *node, char const *code,
location loc);
/** Set the \c \%printer for \c node as \c printer at \c loc. */
void symbol_list_printer_set (symbol_list *node, const char *printer,
/** Set the \c \%printer for \c node as \c code at \c loc. */
void symbol_list_printer_set (symbol_list *node, char const *code,
location loc);
#endif /* !SYMLIST_H_ */