[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: encapsulating code properties
From: |
Joel E. Denny |
Subject: |
Re: encapsulating code properties |
Date: |
Tue, 21 Nov 2006 01:48:55 -0500 (EST) |
On Mon, 13 Nov 2006, Joel E. Denny wrote:
> On Sat, 11 Nov 2006, Paul Eggert wrote:
>
> > The patch changes Bison to pass too many copies of structures around,
> > when we should be passing references to structures.
>
> > If we turn every '->' into a foo_bar_baz_boof_get, our code will get
> > harder to read, with little real benefit. I know why you encapsulated
> > the members inside getters; but to my mind the cost exceeds the
> > benefit, simply in terms of reading the code.
>
> > The Doxygenated comments are hard to read and often don't offer much.
>
> I've tried to adjust the previous patch to address these concerns.
Below is an updated version of the patch with a few corrections to the
scan-code.h comments. Ok to commit?
Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1609
diff -p -u -r1.1609 ChangeLog
--- ChangeLog 21 Nov 2006 00:43:26 -0000 1.1609
+++ ChangeLog 21 Nov 2006 06:39:15 -0000
@@ -1,5 +1,80 @@
2006-11-21 Joel E. Denny <address@hidden>
+ Encapsulate code properties and related functionality for the various
+ destructors, printers, and actions into a code_props structure and
+ interface.
+ * src/location.h (EMPTY_LOCATION_INIT): Define so that it's easier to
+ consistently initialize const structs that have an empty location field.
+ * src/location.c (empty_location): Initialize with EMPTY_LOCATION_INIT
+ to ensure consistency.
+ * src/output.c (symbol_destructors_output, symbol_printers_output):
+ Replace with...
+ (symbol_code_props_output): ... this to eliminate duplicate code.
+ (output_skeleton): Update to use symbol_code_props_output.
+ * 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/reader.c: Update to use new code_props interface for destructors
+ and rule actions.
+ * src/scan-code.h (code_props): New structure.
+ (code_props_none_init, CODE_PROPS_NONE_INIT, code_props_none): New
+ function, macro, and const global variable for initializing a
+ code_props with no code.
+ (code_props_plain_init, code_props_symbol_action_init,
+ code_props_rule_action_init, code_props_translate_code): The rest of
+ the new code_props functional interface.
+ (translate_rule_action, translate_symbol_action, translate_code):
+ Remove as these are now just special cases within
+ code_props_translate_code, which is switched on the code_props kind.
+ (code_scanner_last_string_free): New function similar to
+ gram_scanner_last_string_free.
+ * src/scan-code.l: Implement the new interface.
+ (last_string): New static global similar to the one in scan-gram.l.
+ (SC_SYMBOL_ACTION): For $$, set the is_value_used member of the
+ code_props since Bison will one day use this information for
+ destructors and printers.
+ (<*><<EOF>>): Use STRING_FINISH so that last_string is set.
+ (handle_action_dollar): Update to use the code_props interface of rule
+ actions. Use symbol_list_n_get and set is_value_used directly since
+ symbol_list_n_used_set is removed.
+ * src/symlist.h, src/symlist.c (symbol_list): Replace action,
+ action_location, and used members with a code_props member, and update
+ all uses.
+ (symbol_list_n_used_set): Remove since it would need to break the
+ encapsulation of code_props.
+ (symbol_list_destructor_set, symbol_list_printer_set): Perform code
+ translation here rather than depending on the caller to do so.
+ * src/symtab.h (symbol, semantic_type): Remove destructor_location and
+ printer_location members and change the type of the destructor and
+ printer members to code_props.
+ (symbol_destructor_location_get, symbol_printer_location_get): Remove
+ unneeded.
+ (symbol_destructor_set, symbol_destructor_get, symbol_printer_set,
+ symbol_printer_get, semantic_type_destructor_set,
+ semantic_type_printer_set, default_tagged_destructor_set,
+ default_tagless_destructor_set, default_tagged_printer_set,
+ default_tagless_printer_set): Use code_props in arguments and return
+ types in place of const char * and location.
+ * src/symtab.c: Update implementation for interface and struct changes.
+ (default_tagged_destructor_location,
+ default_tagless_destructor_location, default_tagged_printer_location,
+ default_tagless_printer_location): Remove since we...
+ (default_tagged_destructor, default_tagless_destructor,
+ default_tagged_printer, default_tagless_printer): ... change the type
+ of these to code_props.
+ (SYMBOL_CODE_PRINT): New similar to SYMBOL_ATTR_PRINT but for
+ code_props members.
+ (symbol_print): Use SYMBOL_CODE_PRINT.
+
+ * src/scan-gram.h (gram_last_string): Remove declaration.
+ * src/scan-gram.l (last_string): Declare it static.
+
+2006-11-20 Joel E. Denny <address@hidden>
+
Rename <!> to <>. Discussed starting at
<http://lists.gnu.org/archive/html/bison-patches/2006-11/msg00039.html>.
* NEWS (2.3a+): Update.
Index: src/location.c
===================================================================
RCS file: /sources/bison/bison/src/location.c,v
retrieving revision 1.10
diff -p -u -r1.10 location.c
--- src/location.c 12 Nov 2006 07:39:37 -0000 1.10
+++ src/location.c 21 Nov 2006 06:39:15 -0000
@@ -27,7 +27,7 @@
#include "complain.h"
#include "location.h"
-location const empty_location;
+location const empty_location = EMPTY_LOCATION_INIT;
/* If BUF is null, add BUFSIZE (which in this case must be less than
INT_MAX) to COLUMN; otherwise, add mbsnwidth (BUF, BUFSIZE, 0) to
Index: src/location.h
===================================================================
RCS file: /sources/bison/bison/src/location.h,v
retrieving revision 1.19
diff -p -u -r1.19 location.h
--- src/location.h 12 Nov 2006 07:39:37 -0000 1.19
+++ src/location.h 21 Nov 2006 06:39:15 -0000
@@ -71,6 +71,7 @@ typedef struct
#define YYLTYPE location
+#define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}}
extern location const empty_location;
/* Set *LOC and adjust scanner cursor to account for token TOKEN of
Index: src/output.c
===================================================================
RCS file: /sources/bison/bison/src/output.c,v
retrieving revision 1.259
diff -p -u -r1.259 output.c
--- src/output.c 12 Nov 2006 07:39:37 -0000 1.259
+++ src/output.c 21 Nov 2006 06:39:15 -0000
@@ -373,70 +373,41 @@ token_definitions_output (FILE *out)
}
-/*---------------------------------------.
-| Output the symbol destructors to OUT. |
-`---------------------------------------*/
+/*----------------------------------------------------.
+| Output the symbol destructors and printers to OUT. |
+`----------------------------------------------------*/
static void
-symbol_destructors_output (FILE *out)
+symbol_code_props_output (FILE *out, char const *what,
+ code_props const *(*get)(symbol const *))
{
int i;
char const *sep = "";
- fputs ("m4_define([b4_symbol_destructors], \n[", out);
+ fputs ("m4_define([b4_symbol_", out);
+ fputs (what, out);
+ fputs ("], \n[", out);
for (i = 0; i < nsyms; ++i)
- if (symbol_destructor_get (symbols[i]))
- {
- symbol *sym = symbols[i];
-
- /* Filename, lineno,
- Symbol-name, Symbol-number,
- destructor, optional typename. */
- fprintf (out, "%s[", sep);
- sep = ",\n";
- escaped_output (out, symbol_destructor_location_get (sym).start.file);
- fprintf (out, ", %d, ",
- symbol_destructor_location_get (sym).start.line);
- escaped_output (out, sym->tag);
- fprintf (out, ", %d, [[%s]]", sym->number,
- symbol_destructor_get (sym));
- if (sym->type_name)
- fprintf (out, ", [[%s]]", sym->type_name);
- fputc (']', out);
- }
- fputs ("])\n\n", out);
-}
-
-
-/*------------------------------------.
-| Output the symbol printers to OUT. |
-`------------------------------------*/
-
-static void
-symbol_printers_output (FILE *out)
-{
- int i;
- char const *sep = "";
-
- fputs ("m4_define([b4_symbol_printers], \n[", out);
- for (i = 0; i < nsyms; ++i)
- if (symbol_printer_get (symbols[i]))
- {
- symbol *sym = symbols[i];
-
- /* Filename, lineno,
- Symbol-name, Symbol-number,
- printer, optional typename. */
- fprintf (out, "%s[", sep);
- sep = ",\n";
- escaped_output (out, symbol_printer_location_get (sym).start.file);
- fprintf (out, ", %d, ", symbol_printer_location_get (sym).start.line);
- escaped_output (out, sym->tag);
- fprintf (out, ", %d, [[%s]]", sym->number, symbol_printer_get (sym));
- if (sym->type_name)
- fprintf (out, ", [[%s]]", sym->type_name);
- fputc (']', out);
- }
+ {
+ symbol *sym = symbols[i];
+ char const *code = (*get) (sym)->code;
+ if (code)
+ {
+ location loc = (*get) (sym)->location;
+ /* Filename, lineno,
+ Symbol-name, Symbol-number,
+ code, optional typename. */
+ fprintf (out, "%s[", sep);
+ sep = ",\n";
+ escaped_output (out, loc.start.file);
+ fprintf (out, ", %d, ", loc.start.line);
+ escaped_output (out, sym->tag);
+ fprintf (out, ", %d, [[%s]]", sym->number, code);
+ if (sym->type_name)
+ fprintf (out, ", [[%s]]", sym->type_name);
+ fputc (']', out);
+ }
+ }
fputs ("])\n\n", out);
}
@@ -561,8 +532,8 @@ output_skeleton (void)
user_actions_output (out);
merger_output (out);
token_definitions_output (out);
- symbol_destructors_output (out);
- symbol_printers_output (out);
+ symbol_code_props_output (out, "destructors", &symbol_destructor_get);
+ symbol_code_props_output (out, "printers", &symbol_printer_get);
muscles_m4_output (out);
Index: src/parse-gram.y
===================================================================
RCS file: /sources/bison/bison/src/parse-gram.y,v
retrieving revision 1.99
diff -p -u -r1.99 parse-gram.y
--- src/parse-gram.y 21 Nov 2006 00:43:26 -0000 1.99
+++ src/parse-gram.y 21 Nov 2006 06:39:16 -0000
@@ -182,7 +182,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); }
@@ -222,7 +222,14 @@ 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; }
@@ -237,7 +244,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 ();
}
| "%lex-param" "{...}" { add_param ("lex_param", $2, @2); }
| "%locations" { locations_flag = true; }
@@ -266,17 +278,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"
@@ -327,6 +337,7 @@ grammar_declaration:
union_seen = true;
muscle_code_grow ("stype", body, @3);
+ gram_scanner_last_string_free ();
}
;
@@ -509,8 +520,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;
}
;
@@ -556,8 +571,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 ();
}
;
Index: src/reader.c
===================================================================
RCS file: /sources/bison/bison/src/reader.c,v
retrieving revision 1.279
diff -p -u -r1.279 reader.c
--- src/reader.c 17 Nov 2006 20:07:07 -0000 1.279
+++ src/reader.c 21 Nov 2006 06:39:16 -0000
@@ -253,13 +253,14 @@ grammar_current_rule_begin (symbol *lhs,
static bool
symbol_should_be_used (symbol_list const *s)
{
- if (symbol_destructor_get (s->content.sym))
+ if (symbol_destructor_get (s->content.sym)->code)
return true;
if (warnings_flag & warnings_midrule_values)
- return ((s->midrule && s->midrule->used)
- || (s->midrule_parent_rule
- && symbol_list_n_get (s->midrule_parent_rule,
- s->midrule_parent_rhs_index)->used));
+ return ((s->midrule && s->midrule->action_props.is_value_used)
+ || (s->midrule_parent_rule
+ && symbol_list_n_get (s->midrule_parent_rule,
+ s->midrule_parent_rhs_index)
+ ->action_props.is_value_used));
return false;
}
@@ -278,7 +279,7 @@ grammar_rule_check (const symbol_list *r
Don't worry about the default action if $$ is untyped, since $$'s
value can't be used. */
- if (!r->action && r->content.sym->type_name)
+ if (!r->action_props.code && r->content.sym->type_name)
{
symbol *first_rhs = r->next->content.sym;
/* If $$ is being set in default way, report if any type mismatch. */
@@ -303,10 +304,10 @@ grammar_rule_check (const symbol_list *r
symbol_list const *l = r;
int n = 0;
for (; l && l->content.sym; l = l->next, ++n)
- if (! (l->used
+ if (! (l->action_props.is_value_used
|| !symbol_should_be_used (l)
/* The default action, $$ = $1, `uses' both. */
- || (!r->action && (n == 0 || n == 1))))
+ || (!r->action_props.code && (n == 0 || n == 1))))
{
if (n)
warn_at (r->location, _("unused value: $%d"), n);
@@ -346,7 +347,7 @@ grammar_midrule_action (void)
/* Make a DUMMY nonterminal, whose location is that of the midrule
action. Create the MIDRULE. */
- location dummy_location = current_rule->action_location;
+ location dummy_location = current_rule->action_props.location;
symbol *dummy = dummy_symbol_get (dummy_location);
symbol_list *midrule = symbol_list_sym_new (dummy, dummy_location);
@@ -356,12 +357,11 @@ grammar_midrule_action (void)
++nritems;
/* Attach its location and actions to that of the DUMMY. */
midrule->location = dummy_location;
- midrule->action = current_rule->action;
- midrule->action_location = dummy_location;
- current_rule->action = NULL;
- /* The action has not been translated yet, so $$ use hasn't been
- detected yet. */
- midrule->used = false;
+ code_props_rule_action_init (&midrule->action_props,
+ current_rule->action_props.code,
+ current_rule->action_props.location,
+ midrule);
+ code_props_none_init (¤t_rule->action_props);
if (previous_rule_end)
previous_rule_end->next = midrule;
@@ -427,7 +427,7 @@ grammar_current_rule_merge_set (uniqstr
void
grammar_current_rule_symbol_append (symbol *sym, location loc)
{
- if (current_rule->action)
+ if (current_rule->action_props.code)
grammar_midrule_action ();
grammar_symbol_append (sym, loc);
}
@@ -437,12 +437,12 @@ grammar_current_rule_symbol_append (symb
void
grammar_current_rule_action_append (const char *action, location loc)
{
- if (current_rule->action)
+ if (current_rule->action_props.code)
grammar_midrule_action ();
/* After all symbol declarations have been parsed, packgram invokes
- translate_rule_action. */
- current_rule->action = action;
- current_rule->action_location = loc;
+ code_props_translate_code. */
+ code_props_rule_action_init (¤t_rule->action_props, action, loc,
+ current_rule);
}
@@ -473,8 +473,7 @@ packgram (void)
`$' from any midrule symbol name. */
while (p)
{
- if (p->action)
- p->action = translate_rule_action (p);
+ code_props_translate_code (&p->action_props);
if (p)
p = p->next;
}
@@ -496,16 +495,18 @@ packgram (void)
rules[ruleno].precsym = NULL;
rules[ruleno].location = p->location;
rules[ruleno].useful = true;
- rules[ruleno].action = p->action;
- rules[ruleno].action_location = p->action_location;
+ rules[ruleno].action = p->action_props.code;
+ if (rules[ruleno].action)
+ rules[ruleno].action_location = p->action_props.location;
/* If the midrule's $$ is set or its $n is used, remove the `$' from the
symbol name so that it's a user-defined symbol so that the default
%destructor and %printer apply. */
if (p->midrule_parent_rule
- && (p->used
+ && (p->action_props.is_value_used
|| symbol_list_n_get (p->midrule_parent_rule,
- p->midrule_parent_rhs_index)->used))
+ p->midrule_parent_rhs_index)
+ ->action_props.is_value_used))
p->content.sym->tag += 1;
/* Don't check the generated rule 0. It has no action, so some rhs
Index: src/scan-code.h
===================================================================
RCS file: /sources/bison/bison/src/scan-code.h,v
retrieving revision 1.6
diff -p -u -r1.6 scan-code.h
--- src/scan-code.h 12 Nov 2006 07:39:37 -0000 1.6
+++ src/scan-code.h 21 Nov 2006 06:39:16 -0000
@@ -1,4 +1,4 @@
-/* Bison Action Scanner
+/* Bison code properties structure and scanner.
Copyright (C) 2006 Free Software Foundation, Inc.
@@ -24,24 +24,147 @@
# define SCAN_CODE_H_
# include "location.h"
-# include "symlist.h"
-/* Keeps track of the maximum number of semantic values to the left of
- a handle (those referenced by $0, $-1, etc.) are required by the
- semantic actions of this grammar. */
+struct symbol_list;
+
+/**
+ * Keeps track of the maximum number of semantic values to the left of a handle
+ * (those referenced by $0, $-1, etc.) that are required by the semantic
+ * actions of this grammar.
+ */
extern int max_left_semantic_context;
+/**
+ * A code passage captured from the grammar file and possibly translated,
+ * and/or properties associated with such a code passage. Don't break
+ * encapsulation by modifying the fields directly. Use the provided interface
+ * functions.
+ */
+typedef struct code_props {
+ /** Set by the init functions. */
+ enum {
+ CODE_PROPS_NONE, CODE_PROPS_PLAIN,
+ CODE_PROPS_SYMBOL_ACTION, CODE_PROPS_RULE_ACTION
+ } kind;
+
+ /** \c NULL iff \c code_props::kind is \c CODE_PROPS_NONE. */
+ char const *code;
+ /** Undefined iff \c code_props::code is \c NULL. */
+ location location;
+
+ /**
+ * \c false iff either:
+ * - \c code_props_translate_code has never previously been invoked for
+ * the \c code_props that would contain the code passage associated
+ * with \c self. (That \c code_props is not the same as this one if this
+ * one is for a RHS \c symbol_list node. Instead, it's the \c code_props
+ * for the LHS symbol of the same rule.)
+ * - \c code_props_translate_code has been invoked for that \c code_props,
+ * but the symbol value associated with this \c code_props was not
+ * referenced in the code passage.
+ */
+ bool is_value_used;
+
+ /** \c NULL iff \c code_props::kind is not \c CODE_PROPS_RULE_ACTION. */
+ struct symbol_list *rule;
+} code_props;
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * \post
+ * - \c self has been overwritten to contain no code.
+ */
+void code_props_none_init (code_props *self);
+
+/** Equivalent to \c code_props_none_init. */
+#define CODE_PROPS_NONE_INIT \
+ {CODE_PROPS_NONE, NULL, EMPTY_LOCATION_INIT, false, NULL}
+
+/** Initialized by \c CODE_PROPS_NONE_INIT with no further modification. */
+extern code_props const code_props_none;
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - <tt>code != NULL</tt>.
+ * - \c code is an untranslated code passage containing no Bison escapes.
+ * - \c code was extracted from the grammar file at \c code_loc.
+ * \post
+ * - \c self has been overwritten to represent the specified plain code
+ * passage.
+ * - \c self will become invalid if the caller frees \c code before invoking
+ * \c code_props_translate_code on \c self.
+ */
+void code_props_plain_init (code_props *self, char const *code,
+ location code_loc);
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - <tt>code != NULL</tt>.
+ * - \c code is an untranslated code passage. The only Bison escapes it
+ * might contain are $$ and address@hidden, referring to a single symbol.
+ * - \c code was extracted from the grammar file at \c code_loc.
+ * \post
+ * - \c self has been overwritten to represent the specified symbol action.
+ * - \c self will become invalid if the caller frees \c code before invoking
+ * \c code_props_translate_code on \c self.
+ */
+void code_props_symbol_action_init (code_props *self, char const *code,
+ location code_loc);
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - <tt>code != NULL</tt>.
+ * - <tt>rule != NULL</tt>.
+ * - \c code is the untranslated action of the rule for which \c rule is the
+ * LHS node. Thus, \c code possibly contains Bison escapes such as $$, $1,
+ * $2, etc referring to the values of the rule.
+ * \post
+ * - \c self has been overwritten to represent the specified rule action.
+ * - \c self does not claim responsibility for the memory of \c rule.
+ * - \c self will become invalid if:
+ * - The caller frees \c code before invoking \c code_props_translate_code
+ * on \c self.
+ * - The caller frees \c rule.
+ */
+void code_props_rule_action_init (code_props *self, char const *code,
+ location code_loc, struct symbol_list *rule);
+
+/**
+ * \pre
+ * - If there's a code passage contained in \c self and it contains Bison
+ * escapes, all grammar declarations have already been parsed as they may
+ * affect warnings and complaints issued here.
+ * \post
+ * - All M4 special symbols and Bison escapes have been translated in
+ * \c self->code.
+ * - <tt>self->code != self->address@hidden</tt> unless
+ * <tt>self->address@hidden = NULL</tt>.
+ */
+void code_props_translate_code (code_props *self);
+
+/**
+ * \pre
+ * - None.
+ * \post
+ * - The dynamic memory allocated by the previous invocation of
+ * \c code_props_translate_code (if any) was freed. The \c code_props
+ * instance for which \c code_props_translate_code was invoked is now
+ * invalid.
+ */
+void code_scanner_last_string_free (void);
+
+/**
+ * \pre
+ * - None.
+ * \post
+ * - All dynamic memory allocated during invocations of
+ * \c code_props_translate_code (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);
-
#endif /* !SCAN_CODE_H_ */
Index: src/scan-code.l
===================================================================
RCS file: /sources/bison/bison/src/scan-code.l,v
retrieving revision 1.17
diff -p -u -r1.17 scan-code.l
--- src/scan-code.l 12 Nov 2006 07:39:37 -0000 1.17
+++ src/scan-code.l 21 Nov 2006 06:39:16 -0000
@@ -39,10 +39,11 @@
#include <quote.h>
#include "scan-code.h"
+#include "symlist.h"
/* The current calling start condition: SC_RULE_ACTION or
SC_SYMBOL_ACTION. */
-# define YY_DECL char *code_lex (int sc_context, symbol_list *rule)
+# define YY_DECL static char *code_lex (code_props *self, int sc_context)
YY_DECL;
#define YY_USER_ACTION location_compute (loc, &loc->end, yytext, yyleng);
@@ -53,6 +54,9 @@ static void handle_action_at (symbol_lis
static location the_location;
static location *loc = &the_location;
+/* A string representing the most recent translation. */
+static char *last_string;
+
/* True if an untyped $$ or $n was seen. */
static bool untyped_var_seen;
%}
@@ -151,8 +155,12 @@ splice (\\[ \f\t\v]*\n)*
<SC_RULE_ACTION>
{
- "$"("<"{tag}">")?(-?[0-9]+|"$") handle_action_dollar (rule, yytext, *loc);
- "@"(-?[0-9]+|"$") handle_action_at (rule, yytext, *loc);
+ "$"("<"{tag}">")?(-?[0-9]+|"$") {
+ handle_action_dollar (self->rule, yytext, *loc);
+ }
+ "@"(-?[0-9]+|"$") {
+ handle_action_at (self->rule, yytext, *loc);
+ }
"$" {
warn_at (*loc, _("stray `$'"));
@@ -190,7 +198,10 @@ splice (\\[ \f\t\v]*\n)*
<SC_SYMBOL_ACTION>
{
- "$$" obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar[");
+ "$$" {
+ obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar[");
+ self->is_value_used = true;
+ }
"@$" obstack_sgrow (&obstack_for_string, "]b4_at_dollar[");
}
@@ -215,8 +226,8 @@ splice (\\[ \f\t\v]*\n)*
/* End of processing. */
<*><<EOF>> {
- obstack_1grow (&obstack_for_string, '\0');
- return obstack_finish (&obstack_for_string);
+ STRING_FINISH;
+ return last_string;
}
%%
@@ -238,7 +249,7 @@ int max_left_semantic_context = 0;
static void
handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
{
- const char *type_name = NULL;
+ char const *type_name = NULL;
char *cp = text + 1;
symbol_list *effective_rule;
int effective_rule_length;
@@ -293,7 +304,7 @@ handle_action_dollar (symbol_list *rule,
obstack_fgrow1 (&obstack_for_string,
"]b4_lhs_value([%s])[", type_name);
- rule->used = true;
+ rule->action_props.is_value_used = true;
}
else
{
@@ -321,7 +332,9 @@ handle_action_dollar (symbol_list *rule,
obstack_fgrow3 (&obstack_for_string,
"]b4_rhs_value(%d, %d, [%s])[",
effective_rule_length, n, type_name);
- symbol_list_n_used_set (effective_rule, n, true);
+ if (n > 0)
+ symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
+ true;
}
else
complain_at (dollar_loc, _("integer out of range: %s"), quote (text));
@@ -368,12 +381,11 @@ handle_action_at (symbol_list *rule, cha
| Initialize the scanner. |
`-------------------------*/
-/* Translate the dollars and ats in \a a, whose location is \a l. The
- translation is for \a rule, in the context \a sc_context
+/* Translate the dollars and ats in \a self, in the context \a sc_context
(SC_RULE_ACTION, SC_SYMBOL_ACTION, INITIAL). */
static char const *
-translate_action (int sc_context, symbol_list *rule, char const *a, location l)
+translate_action (code_props *self, int sc_context)
{
char *res;
static bool initialized = false;
@@ -384,36 +396,82 @@ translate_action (int sc_context, symbol
initialized = true;
}
- loc->start = loc->end = l.start;
- yy_switch_to_buffer (yy_scan_string (a));
- res = code_lex (sc_context, rule);
+ loc->start = loc->end = self->location.start;
+ yy_switch_to_buffer (yy_scan_string (self->code));
+ res = code_lex (self, sc_context);
yy_delete_buffer (YY_CURRENT_BUFFER);
return res;
}
-char const *
-translate_rule_action (symbol_list *rule)
+/*------------------------------------------------------------------------.
+| Implementation of the public interface as documented in "scan-code.h". |
+`------------------------------------------------------------------------*/
+
+void
+code_props_none_init (code_props *self)
+{
+ *self = code_props_none;
+}
+
+code_props const code_props_none = CODE_PROPS_NONE_INIT;
+
+void
+code_props_plain_init (code_props *self, char const *code, location code_loc)
+{
+ self->kind = CODE_PROPS_PLAIN;
+ self->code = code;
+ self->location = code_loc;
+ self->is_value_used = false;
+ self->rule = NULL;
+}
+
+void
+code_props_symbol_action_init (code_props *self, char const *code,
+ location code_loc)
{
- return translate_action (SC_RULE_ACTION, rule, rule->action,
- rule->action_location);
+ self->kind = CODE_PROPS_SYMBOL_ACTION;
+ self->code = code;
+ self->location = code_loc;
+ self->is_value_used = false;
+ self->rule = NULL;
}
-char const *
-translate_symbol_action (char const *a, location l)
+void
+code_props_rule_action_init (code_props *self, char const *code,
+ location code_loc, symbol_list *rule)
{
- return translate_action (SC_SYMBOL_ACTION, NULL, a, l);
+ self->kind = CODE_PROPS_RULE_ACTION;
+ self->code = code;
+ self->location = code_loc;
+ self->is_value_used = false;
+ self->rule = rule;
}
-char const *
-translate_code (char const *a, location l)
+void
+code_props_translate_code (code_props *self)
{
- return translate_action (INITIAL, NULL, a, l);
+ switch (self->kind)
+ {
+ case CODE_PROPS_NONE:
+ break;
+ case CODE_PROPS_PLAIN:
+ self->code = translate_action (self, INITIAL);
+ break;
+ case CODE_PROPS_SYMBOL_ACTION:
+ self->code = translate_action (self, SC_SYMBOL_ACTION);
+ break;
+ case CODE_PROPS_RULE_ACTION:
+ self->code = translate_action (self, SC_RULE_ACTION);
+ break;
+ }
}
-/*-----------------------------------------------.
-| Free all the memory allocated to the scanner. |
-`-----------------------------------------------*/
+void
+code_scanner_last_string_free (void)
+{
+ STRING_FREE;
+}
void
code_scanner_free (void)
Index: src/scan-gram.h
===================================================================
RCS file: /sources/bison/bison/src/scan-gram.h,v
retrieving revision 1.5
diff -p -u -r1.5 scan-gram.h
--- src/scan-gram.h 12 Nov 2006 07:39:37 -0000 1.5
+++ src/scan-gram.h 21 Nov 2006 06:39:16 -0000
@@ -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);
Index: src/scan-gram.l
===================================================================
RCS file: /sources/bison/bison/src/scan-gram.l,v
retrieving revision 1.111
diff -p -u -r1.111 scan-gram.l
--- src/scan-gram.l 21 Nov 2006 00:43:26 -0000 1.111
+++ src/scan-gram.l 21 Nov 2006 06:39:16 -0000
@@ -58,7 +58,7 @@ static size_t no_cr_read (FILE *, char *
#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)
Index: src/symlist.c
===================================================================
RCS file: /sources/bison/bison/src/symlist.c,v
retrieving revision 1.26
diff -p -u -r1.26 symlist.c
--- src/symlist.c 21 Nov 2006 00:43:26 -0000 1.26
+++ src/symlist.c 21 Nov 2006 06:39:17 -0000
@@ -23,6 +23,7 @@
#include "system.h"
#include "complain.h"
+#include "scan-code.h"
#include "symlist.h"
@@ -43,8 +44,7 @@ symbol_list_sym_new (symbol *sym, locati
res->midrule_parent_rule = NULL;
res->midrule_parent_rhs_index = 0;
- res->action = NULL;
- res->used = false;
+ code_props_none_init (&res->action_props);
res->ruleprec = NULL;
res->dprec = 0;
@@ -118,7 +118,7 @@ symbol_list_syms_print (const symbol_lis
for (/* Nothing. */; l && l->content.sym; l = l->next)
{
symbol_print (l->content.sym, f);
- fprintf (stderr, l->used ? " used" : " unused");
+ fprintf (stderr, l->action_props.is_value_used ? " used" : " unused");
if (l && l->content.sym)
fprintf (f, ", ");
}
@@ -207,57 +207,50 @@ symbol_list_n_type_name_get (symbol_list
}
-/*--------------------------------------.
-| The item N in symbol list L is USED. |
-`--------------------------------------*/
-
-void
-symbol_list_n_used_set (symbol_list *l, int n, bool used)
-{
- l = symbol_list_n_get (l, n);
- if (l)
- l->used = used;
-}
-
void
-symbol_list_destructor_set (symbol_list *node, const char *destructor,
- location loc)
+symbol_list_destructor_set (symbol_list *node, const char *code, location loc)
{
+ code_props destructor;
+ code_props_symbol_action_init (&destructor, code, loc);
+ code_props_translate_code (&destructor);
switch (node->content_type)
{
case SYMLIST_SYMBOL:
- symbol_destructor_set (node->content.sym, destructor, loc);
+ symbol_destructor_set (node->content.sym, &destructor);
break;
case SYMLIST_TYPE:
semantic_type_destructor_set (
- semantic_type_get (node->content.type_name), destructor, loc);
+ semantic_type_get (node->content.type_name), &destructor);
break;
case SYMLIST_DEFAULT_TAGGED:
- default_tagged_destructor_set (destructor, loc);
+ default_tagged_destructor_set (&destructor);
break;
case SYMLIST_DEFAULT_TAGLESS:
- default_tagless_destructor_set (destructor, loc);
+ default_tagless_destructor_set (&destructor);
break;
}
}
void
-symbol_list_printer_set (symbol_list *node, const char *printer, location loc)
+symbol_list_printer_set (symbol_list *node, const char *code, location loc)
{
+ code_props printer;
+ code_props_symbol_action_init (&printer, code, loc);
+ code_props_translate_code (&printer);
switch (node->content_type)
{
case SYMLIST_SYMBOL:
- symbol_printer_set (node->content.sym, printer, loc);
+ symbol_printer_set (node->content.sym, &printer);
break;
case SYMLIST_TYPE:
semantic_type_printer_set (
- semantic_type_get (node->content.type_name), printer, loc);
+ semantic_type_get (node->content.type_name), &printer);
break;
case SYMLIST_DEFAULT_TAGGED:
- default_tagged_printer_set (printer, loc);
+ default_tagged_printer_set (&printer);
break;
case SYMLIST_DEFAULT_TAGLESS:
- default_tagless_printer_set (printer, loc);
+ default_tagless_printer_set (&printer);
break;
}
}
Index: src/symlist.h
===================================================================
RCS file: /sources/bison/bison/src/symlist.h,v
retrieving revision 1.23
diff -p -u -r1.23 symlist.h
--- src/symlist.h 21 Nov 2006 00:43:26 -0000 1.23
+++ src/symlist.h 21 Nov 2006 06:39:17 -0000
@@ -22,6 +22,7 @@
#ifndef SYMLIST_H_
# define SYMLIST_H_
+# include "scan-code.h"
# include "location.h"
# include "symtab.h"
@@ -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;
@@ -55,12 +61,9 @@ typedef struct symbol_list
struct symbol_list *midrule_parent_rule;
int midrule_parent_rhs_index;
- /* The action is attached to the LHS of a rule. */
- const char *action;
- location action_location;
-
- /* Whether this symbol's value is used in the current action. */
- bool used;
+ /* The action is attached to the LHS of a rule, but action properties for
+ * each RHS are also stored here. */
+ code_props action_props;
/* Precedence/associativity. */
symbol *ruleprec;
@@ -106,15 +109,12 @@ symbol_list *symbol_list_n_get (symbol_l
symbol N in rule RULE. */
uniqstr symbol_list_n_type_name_get (symbol_list *l, location loc, int n);
-/** The item \c n in symbol list \c l is \c used. */
-void symbol_list_n_used_set (symbol_list *l, int n, bool used);
-
/** Set the \c \%destructor for \c node as \c destructor at \c loc. */
-void symbol_list_destructor_set (symbol_list *node, const char *destructor,
+void symbol_list_destructor_set (symbol_list *node, const char *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,
+void symbol_list_printer_set (symbol_list *node, const char *code,
location loc);
#endif /* !SYMLIST_H_ */
Index: src/symtab.c
===================================================================
RCS file: /sources/bison/bison/src/symtab.c,v
retrieving revision 1.86
diff -p -u -r1.86 symtab.c
--- src/symtab.c 12 Nov 2006 07:39:37 -0000 1.86
+++ src/symtab.c 21 Nov 2006 06:39:17 -0000
@@ -45,15 +45,10 @@ location startsymbol_location;
| Default %destructor's and %printer's. |
`---------------------------------------*/
-static const char *default_tagged_destructor = NULL;
-static location default_tagged_destructor_location;
-static const char *default_tagless_destructor = NULL;
-static location default_tagless_destructor_location;
-
-static const char *default_tagged_printer = NULL;
-static location default_tagged_printer_location;
-static const char *default_tagless_printer = NULL;
-static location default_tagless_printer_location;
+static code_props default_tagged_destructor = CODE_PROPS_NONE_INIT;
+static code_props default_tagless_destructor = CODE_PROPS_NONE_INIT;
+static code_props default_tagged_printer = CODE_PROPS_NONE_INIT;
+static code_props default_tagless_printer = CODE_PROPS_NONE_INIT;
/*---------------------------------.
| Create a new symbol, named TAG. |
@@ -69,8 +64,8 @@ symbol_new (uniqstr tag, location loc)
res->location = loc;
res->type_name = NULL;
- res->destructor = NULL;
- res->printer = NULL;
+ code_props_none_init (&res->destructor);
+ code_props_none_init (&res->printer);
res->number = NUMBER_UNDEFINED;
res->prec = 0;
@@ -99,8 +94,8 @@ semantic_type_new (uniqstr tag)
uniqstr_assert (tag);
res->tag = tag;
- res->destructor = NULL;
- res->printer = NULL;
+ code_props_none_init (&res->destructor);
+ code_props_none_init (&res->printer);
return res;
}
@@ -114,6 +109,10 @@ semantic_type_new (uniqstr tag)
if (s->Attr) \
fprintf (f, " %s { %s }", #Attr, s->Attr)
+#define SYMBOL_CODE_PRINT(Attr) \
+ if (&s->Attr.code) \
+ fprintf (f, " %s { %s }", #Attr, s->Attr.code)
+
void
symbol_print (symbol *s, FILE *f)
{
@@ -121,14 +120,15 @@ symbol_print (symbol *s, FILE *f)
{
fprintf (f, "\"%s\"", s->tag);
SYMBOL_ATTR_PRINT (type_name);
- SYMBOL_ATTR_PRINT (destructor);
- SYMBOL_ATTR_PRINT (printer);
+ SYMBOL_CODE_PRINT (destructor);
+ SYMBOL_CODE_PRINT (printer);
}
else
fprintf (f, "<NULL>");
}
#undef SYMBOL_ATTR_PRINT
+#undef SYMBOL_CODE_PRINT
/*------------------------------------------------------------------.
| Complain that S's WHAT is redeclared at SECOND, and was first set |
@@ -171,170 +171,117 @@ symbol_type_set (symbol *sym, uniqstr ty
}
-/*------------------------------------------------------------------.
-| Set the DESTRUCTOR associated with SYM. Do nothing if passed 0. |
-`------------------------------------------------------------------*/
+/*-----------------------------------------.
+| Set the DESTRUCTOR associated with SYM. |
+`-----------------------------------------*/
void
-symbol_destructor_set (symbol *sym, const char *destructor, location loc)
+symbol_destructor_set (symbol *sym, code_props const *destructor)
{
- if (destructor)
- {
- if (sym->destructor)
- symbol_redeclaration (sym, "%destructor", sym->destructor_location,
- loc);
- sym->destructor = destructor;
- sym->destructor_location = loc;
- }
+ if (sym->destructor.code)
+ symbol_redeclaration (sym, "%destructor", sym->destructor.location,
+ destructor->location);
+ sym->destructor = *destructor;
}
-/*-------------------------------------------------------------------.
-| Set the DESTRUCTOR associated with TYPE. Do nothing if passed 0. |
-`-------------------------------------------------------------------*/
+/*------------------------------------------.
+| Set the DESTRUCTOR associated with TYPE. |
+`------------------------------------------*/
void
-semantic_type_destructor_set (semantic_type *type, const char *destructor,
- location loc)
+semantic_type_destructor_set (semantic_type *type,
+ code_props const *destructor)
{
- if (destructor)
- {
- if (type->destructor)
- semantic_type_redeclaration (type, "%destructor",
- type->destructor_location, loc);
- type->destructor = destructor;
- type->destructor_location = loc;
- }
+ if (type->destructor.code)
+ semantic_type_redeclaration (type, "%destructor",
+ type->destructor.location,
+ destructor->location);
+ type->destructor = *destructor;
}
/*---------------------------------------.
| Get the computed %destructor for SYM. |
`---------------------------------------*/
-const char *
-symbol_destructor_get (symbol *sym)
+code_props const *
+symbol_destructor_get (symbol const *sym)
{
/* Per-symbol %destructor. */
- if (sym->destructor != NULL)
- return sym->destructor;
+ if (sym->destructor.code)
+ return &sym->destructor;
/* Per-type %destructor. */
if (sym->type_name)
{
- semantic_type *type = semantic_type_get (sym->type_name);
- if (type->destructor)
- return type->destructor;
+ code_props const *destructor =
+ &semantic_type_get (sym->type_name)->destructor;
+ if (destructor->code)
+ return destructor;
}
/* Apply default %destructor's only to user-defined symbols. */
if (sym->tag[0] == '$' || sym == errtoken)
- return NULL;
+ return &code_props_none;
if (sym->type_name)
- return default_tagged_destructor;
- return default_tagless_destructor;
-}
-
-/*---------------------------------------------------------------.
-| Get the grammar location of the %destructor computed for SYM. |
-`---------------------------------------------------------------*/
-
-location
-symbol_destructor_location_get (symbol *sym)
-{
- if (sym->destructor != NULL)
- return sym->destructor_location;
- if (sym->type_name)
- {
- semantic_type *type = semantic_type_get (sym->type_name);
- if (type->destructor)
- return type->destructor_location;
- return default_tagged_destructor_location;
- }
- return default_tagless_destructor_location;
+ return &default_tagged_destructor;
+ return &default_tagless_destructor;
}
-/*---------------------------------------------------------------.
-| Set the PRINTER associated with SYM. Do nothing if passed 0. |
-`---------------------------------------------------------------*/
+/*--------------------------------------.
+| Set the PRINTER associated with SYM. |
+`--------------------------------------*/
void
-symbol_printer_set (symbol *sym, const char *printer, location loc)
+symbol_printer_set (symbol *sym, code_props const *printer)
{
- if (printer)
- {
- if (sym->printer)
- symbol_redeclaration (sym, "%printer", sym->printer_location, loc);
- sym->printer = printer;
- sym->printer_location = loc;
- }
+ if (sym->printer.code)
+ symbol_redeclaration (sym, "%printer",
+ sym->printer.location, printer->location);
+ sym->printer = *printer;
}
-/*----------------------------------------------------------------.
-| Set the PRINTER associated with TYPE. Do nothing if passed 0. |
-`----------------------------------------------------------------*/
+/*---------------------------------------.
+| Set the PRINTER associated with TYPE. |
+`---------------------------------------*/
void
-semantic_type_printer_set (semantic_type *type, const char *printer,
- location loc)
+semantic_type_printer_set (semantic_type *type, code_props const *printer)
{
- if (printer)
- {
- if (type->printer)
- semantic_type_redeclaration (type, "%printer", type->printer_location,
- loc);
- type->printer = printer;
- type->printer_location = loc;
- }
+ if (type->printer.code)
+ semantic_type_redeclaration (type, "%printer",
+ type->printer.location, printer->location);
+ type->printer = *printer;
}
/*------------------------------------.
| Get the computed %printer for SYM. |
`------------------------------------*/
-const char *
-symbol_printer_get (symbol *sym)
+code_props const *
+symbol_printer_get (symbol const *sym)
{
/* Per-symbol %printer. */
- if (sym->printer != NULL)
- return sym->printer;
+ if (sym->printer.code)
+ return &sym->printer;
/* Per-type %printer. */
if (sym->type_name)
{
- semantic_type *type = semantic_type_get (sym->type_name);
- if (type->printer)
- return type->printer;
+ code_props const *printer = &semantic_type_get (sym->type_name)->printer;
+ if (printer->code)
+ return printer;
}
/* Apply the default %printer only to user-defined symbols. */
if (sym->tag[0] == '$' || sym == errtoken)
- return NULL;
+ return &code_props_none;
if (sym->type_name)
- return default_tagged_printer;
- return default_tagless_printer;
+ return &default_tagged_printer;
+ return &default_tagless_printer;
}
-/*------------------------------------------------------------.
-| Get the grammar location of the %printer computed for SYM. |
-`------------------------------------------------------------*/
-
-location
-symbol_printer_location_get (symbol *sym)
-{
- if (sym->printer != NULL)
- return sym->printer_location;
- if (sym->type_name)
- {
- semantic_type *type = semantic_type_get (sym->type_name);
- if (type->printer)
- return type->printer_location;
- return default_tagged_printer_location;
- }
- return default_tagless_printer_location;
-}
-
-
/*-----------------------------------------------------------------.
| Set the PRECEDENCE associated with SYM. Does nothing if invoked |
| with UNDEF_ASSOC as ASSOC. |
@@ -498,22 +445,20 @@ symbol_check_alias_consistency (symbol *
}
- if (orig->destructor || alias->destructor)
+ if (orig->destructor.code || alias->destructor.code)
{
- if (orig->destructor)
- symbol_destructor_set (alias, orig->destructor,
- orig->destructor_location);
+ if (orig->destructor.code)
+ symbol_destructor_set (alias, &orig->destructor);
else
- symbol_destructor_set (orig, alias->destructor,
- alias->destructor_location);
+ symbol_destructor_set (orig, &alias->destructor);
}
- if (orig->printer || alias->printer)
+ if (orig->printer.code || alias->printer.code)
{
- if (orig->printer)
- symbol_printer_set (alias, orig->printer, orig->printer_location);
+ if (orig->printer.code)
+ symbol_printer_set (alias, &orig->printer);
else
- symbol_printer_set (orig, alias->printer, alias->printer_location);
+ symbol_printer_set (orig, &alias->printer);
}
if (alias->prec || orig->prec)
@@ -942,53 +887,54 @@ symbols_pack (void)
`--------------------------------------------------*/
void
-default_tagged_destructor_set (const char *destructor, location loc)
+default_tagged_destructor_set (code_props const *destructor)
{
- if (default_tagged_destructor != NULL)
+ if (default_tagged_destructor.code)
{
- complain_at (loc, _("redeclaration for default tagged %%destructor"));
- complain_at (default_tagged_destructor_location,
+ complain_at (destructor->location,
+ _("redeclaration for default tagged %%destructor"));
+ complain_at (default_tagged_destructor.location,
_("previous declaration"));
}
- default_tagged_destructor = destructor;
- default_tagged_destructor_location = loc;
+ default_tagged_destructor = *destructor;
}
void
-default_tagless_destructor_set (const char *destructor, location loc)
+default_tagless_destructor_set (code_props const *destructor)
{
- if (default_tagless_destructor != NULL)
+ if (default_tagless_destructor.code)
{
- complain_at (loc, _("redeclaration for default tagless %%destructor"));
- complain_at (default_tagless_destructor_location,
+ complain_at (destructor->location,
+ _("redeclaration for default tagless %%destructor"));
+ complain_at (default_tagless_destructor.location,
_("previous declaration"));
}
- default_tagless_destructor = destructor;
- default_tagless_destructor_location = loc;
+ default_tagless_destructor = *destructor;
}
void
-default_tagged_printer_set (const char *printer, location loc)
+default_tagged_printer_set (code_props const *printer)
{
- if (default_tagged_printer != NULL)
+ if (default_tagged_printer.code)
{
- complain_at (loc, _("redeclaration for default tagged %%printer"));
- complain_at (default_tagged_printer_location,
+ complain_at (printer->location,
+ _("redeclaration for default tagged %%printer"));
+ complain_at (default_tagged_printer.location,
_("previous declaration"));
}
- default_tagged_printer = printer;
- default_tagged_printer_location = loc;
+ default_tagged_printer = *printer;
}
void
-default_tagless_printer_set (const char *printer, location loc)
+default_tagless_printer_set (code_props const *printer)
{
- if (default_tagless_printer != NULL)
+ if (default_tagless_printer.code)
{
- complain_at (loc, _("redeclaration for default tagless %%printer"));
- complain_at (default_tagless_printer_location,
+ complain_at (printer->location,
+ _("redeclaration for default tagless %%printer"));
+ complain_at (default_tagless_printer.location,
_("previous declaration"));
}
- default_tagless_printer = printer;
- default_tagless_printer_location = loc;
+ default_tagless_printer = *printer;
}
+
Index: src/symtab.h
===================================================================
RCS file: /sources/bison/bison/src/symtab.h,v
retrieving revision 1.68
diff -p -u -r1.68 symtab.h
--- src/symtab.h 12 Nov 2006 07:39:37 -0000 1.68
+++ src/symtab.h 21 Nov 2006 06:39:17 -0000
@@ -30,6 +30,7 @@
# include "assoc.h"
# include "location.h"
+# include "scan-code.h"
# include "uniqstr.h"
/*----------.
@@ -72,25 +73,13 @@ struct symbol
example, if <tt>symbol::destructor = NULL</tt>, a default \c \%destructor
or a per-type \c \%destructor might be appropriate, and
\c symbol_destructor_get will compute the correct one. */
- const char *destructor;
-
- /** The location of \c symbol::destructor.
-
- Access this field only through <tt>symbol</tt>'s interface functions.
- \sa symbol::destructor */
- location destructor_location;
+ code_props destructor;
/** Any \c \%printer declared specifically for this symbol.
Access this field only through <tt>symbol</tt>'s interface functions.
\sa symbol::destructor */
- const char *printer;
-
- /** The location of \c symbol::printer.
-
- Access this field only through <tt>symbol</tt>'s interface functions.
- \sa symbol::destructor */
- location printer_location;
+ code_props printer;
symbol_number number;
location prec_location;
@@ -144,26 +133,18 @@ void symbol_make_alias (symbol *sym, sym
void symbol_type_set (symbol *sym, uniqstr type_name, location loc);
/** Set the \c destructor associated with \c sym. */
-void symbol_destructor_set (symbol *sym, const char *destructor, location loc);
-
-/** Get the computed \c \%destructor for \c sym, or \c NULL if none. */
-const char *symbol_destructor_get (symbol *sym);
+void symbol_destructor_set (symbol *sym, code_props const *destructor);
-/** Get the grammar location of the computed \c \%destructor for \c sym.
-
- \pre <tt>symbol_destructor_get (sym) != NULL</tt> */
-location symbol_destructor_location_get (symbol *sym);
+/** Get the computed \c \%destructor for \c sym, which was initialized with
+ \c code_props_none_init if there's no \c \%destructor. */
+code_props const *symbol_destructor_get (symbol const *sym);
/** Set the \c printer associated with \c sym. */
-void symbol_printer_set (symbol *sym, const char *printer, location loc);
+void symbol_printer_set (symbol *sym, code_props const *printer);
-/** Get the computed \c \%printer for \c sym, or \c NULL if none. */
-const char *symbol_printer_get (symbol *sym);
-
-/** Get the grammar location of the computed \c \%printer for \c sym.
-
- \pre <tt>symbol_printer_get (sym) != NULL</tt> */
-location symbol_printer_location_get (symbol *sym);
+/** Get the computed \c \%printer for \c sym, which was initialized with
+ \c code_props_none_init if there's no \c \%printer. */
+code_props const *symbol_printer_get (symbol const *sym);
/* Set the \c precedence associated with \c sym.
@@ -209,14 +190,9 @@ typedef struct semantic_type {
uniqstr tag;
/** Any \c %destructor declared for this semantic type. */
- const char *destructor;
- /** The location of \c semantic_type::destructor. */
- location destructor_location;
-
+ code_props destructor;
/** Any \c %printer declared for this semantic type. */
- const char *printer;
- /** The location of \c semantic_type::printer. */
- location printer_location;
+ code_props printer;
} semantic_type;
/** Fetch (or create) the semantic type associated to KEY. */
@@ -226,12 +202,12 @@ semantic_type *semantic_type_from_uniqst
semantic_type *semantic_type_get (const char *key);
/** Set the \c destructor associated with \c type. */
-void semantic_type_destructor_set (semantic_type *type, const char *destructor,
- location loc);
+void semantic_type_destructor_set (semantic_type *type,
+ code_props const *destructor);
/** Set the \c printer associated with \c type. */
-void semantic_type_printer_set (semantic_type *type, const char *printer,
- location loc);
+void semantic_type_printer_set (semantic_type *type,
+ code_props const *printer);
/*----------------------------------.
| Symbol and semantic type tables. |
@@ -260,13 +236,13 @@ void symbols_pack (void);
`---------------------------------------*/
/** Set the default \c \%destructor for tagged values. */
-void default_tagged_destructor_set (const char *destructor, location loc);
+void default_tagged_destructor_set (code_props const *destructor);
/** Set the default \c \%destructor for tagless values. */
-void default_tagless_destructor_set (const char *destructor, location loc);
+void default_tagless_destructor_set (code_props const *destructor);
/** Set the default \c \%printer for tagged values. */
-void default_tagged_printer_set (const char *printer, location loc);
+void default_tagged_printer_set (code_props const *printer);
/** Set the default \c \%printer for tagless values. */
-void default_tagless_printer_set (const char *printer, location loc);
+void default_tagless_printer_set (code_props const *printer);
#endif /* !SYMTAB_H_ */
- Re: encapsulating code properties, (continued)
- Re: encapsulating code properties, Joel E. Denny, 2006/11/12
- Re: encapsulating code properties, Paul Eggert, 2006/11/12
- Re: encapsulating code properties, Joel E. Denny, 2006/11/12
- Re: encapsulating code properties, Paul Eggert, 2006/11/13
- Re: encapsulating code properties, Joel E. Denny, 2006/11/13
- Re: encapsulating code properties, Paul Eggert, 2006/11/13
- Re: encapsulating code properties, Joel E. Denny, 2006/11/13
- Re: encapsulating code properties, Joel E. Denny, 2006/11/13
Re: encapsulating code properties, Joel E. Denny, 2006/11/13