-2006-11-10 Joel E. Denny <jdenny@ces.clemson.edu>
-
- 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 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,
- code_props_code_get, code_props_location_get,
- code_props_is_value_used): The rest of the new code_props 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-10 Joel E. Denny <jdenny@ces.clemson.edu>
* tests/testsuite.at (AT_CHECK): Don't miss an exit value of 0 because
#include "complain.h"
#include "location.h"
-location const empty_location = EMPTY_LOCATION_INIT;
+location const empty_location;
/* 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
#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
}
-/*----------------------------------------------------.
-| Output the symbol destructors and printers to OUT. |
-`----------------------------------------------------*/
+/*---------------------------------------.
+| Output the symbol destructors to OUT. |
+`---------------------------------------*/
static void
-symbol_code_props_output (FILE *out, char const *what,
- code_props (*get)(symbol *))
+symbol_destructors_output (FILE *out)
{
int i;
char const *sep = "";
- fputs ("m4_define([b4_symbol_", out);
- fputs (what, out);
- fputs ("], \n[", out);
+ fputs ("m4_define([b4_symbol_destructors], \n[", out);
for (i = 0; i < nsyms; ++i)
- {
- symbol *sym = symbols[i];
- char const *code = code_props_code_get ((*get) (sym));
- if (code)
- {
- location loc = code_props_location_get ((*get) (sym));
- /* 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);
- }
- }
+ 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);
+ }
fputs ("])\n\n", out);
}
user_actions_output (out);
merger_output (out);
token_definitions_output (out);
- symbol_code_props_output (out, "destructors", &symbol_destructor_get);
- symbol_code_props_output (out, "printers", &symbol_printer_get);
+ symbol_destructors_output (out);
+ symbol_printers_output (out);
muscles_m4_output (out);
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 210, 210, 218, 220, 224, 225, 233, 234, 235,
- 236, 237, 238, 239, 240, 245, 254, 255, 256, 257,
- 258, 259, 260, 261, 262, 263, 264, 265, 266, 267,
- 268, 272, 273, 274, 278, 285, 292, 296, 300, 301,
- 302, 303, 314, 315, 319, 348, 348, 353, 353, 358,
- 369, 384, 385, 386, 390, 391, 396, 398, 403, 404,
- 408, 409, 410, 411, 416, 421, 426, 432, 438, 449,
- 450, 459, 460, 466, 467, 468, 475, 475, 479, 480,
- 481, 486, 487, 489, 491, 493, 495, 505, 506, 512,
- 516, 521, 541, 543, 552, 557, 558, 563, 570, 572
+ 0, 210, 210, 218, 220, 224, 225, 226, 227, 228,
+ 229, 230, 231, 232, 233, 238, 242, 243, 244, 245,
+ 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
+ 256, 260, 261, 262, 266, 274, 282, 286, 290, 291,
+ 292, 293, 304, 305, 309, 337, 337, 342, 342, 347,
+ 358, 373, 374, 375, 379, 380, 385, 387, 392, 393,
+ 397, 398, 399, 400, 405, 410, 415, 421, 427, 438,
+ 439, 448, 449, 455, 456, 457, 464, 464, 468, 469,
+ 470, 475, 476, 478, 480, 482, 484, 494, 495, 501,
+ 505, 510, 526, 528, 537, 542, 543, 548, 555, 557
};
#endif
/* Line 1269 of yacc.c */
#line 225 "parse-gram.y"
- {
- code_props plain_code;
- code_props_plain_init (&plain_code, (yyvsp[(1) - (1)].chars), (yylsp[(1) - (1)]));
- code_props_translate_code (&plain_code);
- gram_scanner_last_string_free ();
- prologue_augment (code_props_code_get (plain_code), (yylsp[(1) - (1)]), union_seen);
- code_scanner_last_string_free ();
-}
+ { prologue_augment (translate_code ((yyvsp[(1) - (1)].chars), (yylsp[(1) - (1)])), (yylsp[(1) - (1)]), union_seen); }
break;
case 7:
/* Line 1269 of yacc.c */
-#line 233 "parse-gram.y"
+#line 226 "parse-gram.y"
{ debug_flag = true; }
break;
case 8:
/* Line 1269 of yacc.c */
-#line 234 "parse-gram.y"
+#line 227 "parse-gram.y"
{ muscle_insert ((yyvsp[(2) - (3)].chars), (yyvsp[(3) - (3)].chars)); }
break;
case 9:
/* Line 1269 of yacc.c */
-#line 235 "parse-gram.y"
+#line 228 "parse-gram.y"
{ defines_flag = true; }
break;
case 10:
/* Line 1269 of yacc.c */
-#line 236 "parse-gram.y"
+#line 229 "parse-gram.y"
{ error_verbose = true; }
break;
case 11:
/* Line 1269 of yacc.c */
-#line 237 "parse-gram.y"
+#line 230 "parse-gram.y"
{ expected_sr_conflicts = (yyvsp[(2) - (2)].integer); }
break;
case 12:
/* Line 1269 of yacc.c */
-#line 238 "parse-gram.y"
+#line 231 "parse-gram.y"
{ expected_rr_conflicts = (yyvsp[(2) - (2)].integer); }
break;
case 13:
/* Line 1269 of yacc.c */
-#line 239 "parse-gram.y"
+#line 232 "parse-gram.y"
{ spec_file_prefix = (yyvsp[(3) - (3)].chars); }
break;
case 14:
/* Line 1269 of yacc.c */
-#line 241 "parse-gram.y"
+#line 234 "parse-gram.y"
{
nondeterministic_parser = true;
glr_parser = true;
case 15:
/* Line 1269 of yacc.c */
-#line 246 "parse-gram.y"
+#line 239 "parse-gram.y"
{
- code_props action;
- code_props_symbol_action_init (&action, (yyvsp[(2) - (2)].code), (yylsp[(2) - (2)]));
- code_props_translate_code (&action);
- gram_scanner_last_string_free ();
- muscle_code_grow ("initial_action", code_props_code_get (action), (yylsp[(2) - (2)]));
- code_scanner_last_string_free ();
+ muscle_code_grow ("initial_action", translate_symbol_action ((yyvsp[(2) - (2)].code), (yylsp[(2) - (2)])), (yylsp[(2) - (2)]));
}
break;
case 16:
/* Line 1269 of yacc.c */
-#line 254 "parse-gram.y"
+#line 242 "parse-gram.y"
{ add_param ("lex_param", (yyvsp[(2) - (2)].code), (yylsp[(2) - (2)])); }
break;
case 17:
/* Line 1269 of yacc.c */
-#line 255 "parse-gram.y"
+#line 243 "parse-gram.y"
{ locations_flag = true; }
break;
case 18:
/* Line 1269 of yacc.c */
-#line 256 "parse-gram.y"
+#line 244 "parse-gram.y"
{ spec_name_prefix = (yyvsp[(3) - (3)].chars); }
break;
case 19:
/* Line 1269 of yacc.c */
-#line 257 "parse-gram.y"
+#line 245 "parse-gram.y"
{ no_lines_flag = true; }
break;
case 20:
/* Line 1269 of yacc.c */
-#line 258 "parse-gram.y"
+#line 246 "parse-gram.y"
{ nondeterministic_parser = true; }
break;
case 21:
/* Line 1269 of yacc.c */
-#line 259 "parse-gram.y"
+#line 247 "parse-gram.y"
{ spec_outfile = (yyvsp[(3) - (3)].chars); }
break;
case 22:
/* Line 1269 of yacc.c */
-#line 260 "parse-gram.y"
+#line 248 "parse-gram.y"
{ add_param ("parse_param", (yyvsp[(2) - (2)].code), (yylsp[(2) - (2)])); }
break;
case 23:
/* Line 1269 of yacc.c */
-#line 261 "parse-gram.y"
+#line 249 "parse-gram.y"
{ pure_parser = true; }
break;
case 24:
/* Line 1269 of yacc.c */
-#line 262 "parse-gram.y"
+#line 250 "parse-gram.y"
{ push_parser = true; }
break;
case 25:
/* Line 1269 of yacc.c */
-#line 263 "parse-gram.y"
+#line 251 "parse-gram.y"
{ version_check (&(yylsp[(2) - (2)]), (yyvsp[(2) - (2)].chars)); }
break;
case 26:
/* Line 1269 of yacc.c */
-#line 264 "parse-gram.y"
+#line 252 "parse-gram.y"
{ skeleton = (yyvsp[(2) - (2)].chars); }
break;
case 27:
/* Line 1269 of yacc.c */
-#line 265 "parse-gram.y"
+#line 253 "parse-gram.y"
{ token_table_flag = true; }
break;
case 28:
/* Line 1269 of yacc.c */
-#line 266 "parse-gram.y"
+#line 254 "parse-gram.y"
{ report_flag = report_states; }
break;
case 29:
/* Line 1269 of yacc.c */
-#line 267 "parse-gram.y"
+#line 255 "parse-gram.y"
{ yacc_flag = true; }
break;
case 33:
/* Line 1269 of yacc.c */
-#line 275 "parse-gram.y"
+#line 263 "parse-gram.y"
{
grammar_start_symbol_set ((yyvsp[(2) - (2)].symbol), (yylsp[(2) - (2)]));
}
case 34:
/* Line 1269 of yacc.c */
-#line 279 "parse-gram.y"
+#line 267 "parse-gram.y"
{
symbol_list *list;
+ const char *action = translate_symbol_action ((yyvsp[(2) - (3)].code), (yylsp[(2) - (3)]));
for (list = (yyvsp[(3) - (3)].list); list; list = list->next)
- symbol_list_destructor_set (list, (yyvsp[(2) - (3)].code), (yylsp[(2) - (3)]));
+ symbol_list_destructor_set (list, action, (yylsp[(2) - (3)]));
symbol_list_free ((yyvsp[(3) - (3)].list));
}
break;
case 35:
/* Line 1269 of yacc.c */
-#line 286 "parse-gram.y"
+#line 275 "parse-gram.y"
{
symbol_list *list;
+ const char *action = translate_symbol_action ((yyvsp[(2) - (3)].code), (yylsp[(2) - (3)]));
for (list = (yyvsp[(3) - (3)].list); list; list = list->next)
- symbol_list_printer_set (list, (yyvsp[(2) - (3)].code), (yylsp[(2) - (3)]));
+ symbol_list_printer_set (list, action, (yylsp[(2) - (3)]));
symbol_list_free ((yyvsp[(3) - (3)].list));
}
break;
case 36:
/* Line 1269 of yacc.c */
-#line 293 "parse-gram.y"
+#line 283 "parse-gram.y"
{
default_prec = true;
}
case 37:
/* Line 1269 of yacc.c */
-#line 297 "parse-gram.y"
+#line 287 "parse-gram.y"
{
default_prec = false;
}
case 38:
/* Line 1269 of yacc.c */
-#line 300 "parse-gram.y"
+#line 290 "parse-gram.y"
{ prologue_augment ((yyvsp[(2) - (2)].chars), (yylsp[(2) - (2)]), true); }
break;
case 39:
/* Line 1269 of yacc.c */
-#line 301 "parse-gram.y"
+#line 291 "parse-gram.y"
{ prologue_augment ((yyvsp[(2) - (2)].chars), (yylsp[(2) - (2)]), false); }
break;
case 40:
/* Line 1269 of yacc.c */
-#line 302 "parse-gram.y"
+#line 292 "parse-gram.y"
{ muscle_code_grow ("provides", (yyvsp[(2) - (2)].chars), (yylsp[(2) - (2)])); }
break;
case 41:
/* Line 1269 of yacc.c */
-#line 303 "parse-gram.y"
+#line 293 "parse-gram.y"
{ muscle_code_grow ("requires", (yyvsp[(2) - (2)].chars), (yylsp[(2) - (2)])); }
break;
case 42:
/* Line 1269 of yacc.c */
-#line 314 "parse-gram.y"
+#line 304 "parse-gram.y"
{}
break;
case 43:
/* Line 1269 of yacc.c */
-#line 315 "parse-gram.y"
+#line 305 "parse-gram.y"
{ muscle_code_grow ("union_name", (yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); }
break;
case 44:
/* Line 1269 of yacc.c */
-#line 320 "parse-gram.y"
+#line 310 "parse-gram.y"
{
char const *body = (yyvsp[(3) - (3)].code);
union_seen = true;
muscle_code_grow ("stype", body, (yylsp[(3) - (3)]));
- gram_scanner_last_string_free ();
}
break;
case 45:
/* Line 1269 of yacc.c */
-#line 348 "parse-gram.y"
+#line 337 "parse-gram.y"
{ current_class = nterm_sym; }
break;
case 46:
/* Line 1269 of yacc.c */
-#line 349 "parse-gram.y"
+#line 338 "parse-gram.y"
{
current_class = unknown_sym;
current_type = NULL;
case 47:
/* Line 1269 of yacc.c */
-#line 353 "parse-gram.y"
+#line 342 "parse-gram.y"
{ current_class = token_sym; }
break;
case 48:
/* Line 1269 of yacc.c */
-#line 354 "parse-gram.y"
+#line 343 "parse-gram.y"
{
current_class = unknown_sym;
current_type = NULL;
case 49:
/* Line 1269 of yacc.c */
-#line 359 "parse-gram.y"
+#line 348 "parse-gram.y"
{
symbol_list *list;
tag_seen = true;
case 50:
/* Line 1269 of yacc.c */
-#line 370 "parse-gram.y"
+#line 359 "parse-gram.y"
{
symbol_list *list;
++current_prec;
case 51:
/* Line 1269 of yacc.c */
-#line 384 "parse-gram.y"
+#line 373 "parse-gram.y"
{ (yyval.assoc) = left_assoc; }
break;
case 52:
/* Line 1269 of yacc.c */
-#line 385 "parse-gram.y"
+#line 374 "parse-gram.y"
{ (yyval.assoc) = right_assoc; }
break;
case 53:
/* Line 1269 of yacc.c */
-#line 386 "parse-gram.y"
+#line 375 "parse-gram.y"
{ (yyval.assoc) = non_assoc; }
break;
case 54:
/* Line 1269 of yacc.c */
-#line 390 "parse-gram.y"
+#line 379 "parse-gram.y"
{ current_type = NULL; }
break;
case 55:
/* Line 1269 of yacc.c */
-#line 391 "parse-gram.y"
+#line 380 "parse-gram.y"
{ current_type = (yyvsp[(1) - (1)].uniqstr); tag_seen = true; }
break;
case 56:
/* Line 1269 of yacc.c */
-#line 397 "parse-gram.y"
+#line 386 "parse-gram.y"
{ (yyval.list) = symbol_list_sym_new ((yyvsp[(1) - (1)].symbol), (yylsp[(1) - (1)])); }
break;
case 57:
/* Line 1269 of yacc.c */
-#line 399 "parse-gram.y"
+#line 388 "parse-gram.y"
{ (yyval.list) = symbol_list_prepend ((yyvsp[(1) - (2)].list), symbol_list_sym_new ((yyvsp[(2) - (2)].symbol), (yylsp[(2) - (2)]))); }
break;
case 58:
/* Line 1269 of yacc.c */
-#line 403 "parse-gram.y"
+#line 392 "parse-gram.y"
{ (yyval.list) = (yyvsp[(1) - (1)].list); }
break;
case 59:
/* Line 1269 of yacc.c */
-#line 404 "parse-gram.y"
+#line 393 "parse-gram.y"
{ (yyval.list) = symbol_list_prepend ((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].list)); }
break;
case 60:
/* Line 1269 of yacc.c */
-#line 408 "parse-gram.y"
+#line 397 "parse-gram.y"
{ (yyval.list) = symbol_list_sym_new ((yyvsp[(1) - (1)].symbol), (yylsp[(1) - (1)])); }
break;
case 61:
/* Line 1269 of yacc.c */
-#line 409 "parse-gram.y"
+#line 398 "parse-gram.y"
{ (yyval.list) = symbol_list_type_new ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); }
break;
case 62:
/* Line 1269 of yacc.c */
-#line 410 "parse-gram.y"
+#line 399 "parse-gram.y"
{ (yyval.list) = symbol_list_default_tagged_new ((yylsp[(1) - (1)])); }
break;
case 63:
/* Line 1269 of yacc.c */
-#line 411 "parse-gram.y"
+#line 400 "parse-gram.y"
{ (yyval.list) = symbol_list_default_tagless_new ((yylsp[(1) - (1)])); }
break;
case 64:
/* Line 1269 of yacc.c */
-#line 417 "parse-gram.y"
+#line 406 "parse-gram.y"
{
current_type = (yyvsp[(1) - (1)].uniqstr);
tag_seen = true;
case 65:
/* Line 1269 of yacc.c */
-#line 422 "parse-gram.y"
+#line 411 "parse-gram.y"
{
symbol_class_set ((yyvsp[(1) - (1)].symbol), current_class, (yylsp[(1) - (1)]), true);
symbol_type_set ((yyvsp[(1) - (1)].symbol), current_type, (yylsp[(1) - (1)]));
case 66:
/* Line 1269 of yacc.c */
-#line 427 "parse-gram.y"
+#line 416 "parse-gram.y"
{
symbol_class_set ((yyvsp[(1) - (2)].symbol), current_class, (yylsp[(1) - (2)]), true);
symbol_type_set ((yyvsp[(1) - (2)].symbol), current_type, (yylsp[(1) - (2)]));
case 67:
/* Line 1269 of yacc.c */
-#line 433 "parse-gram.y"
+#line 422 "parse-gram.y"
{
symbol_class_set ((yyvsp[(1) - (2)].symbol), current_class, (yylsp[(1) - (2)]), true);
symbol_type_set ((yyvsp[(1) - (2)].symbol), current_type, (yylsp[(1) - (2)]));
case 68:
/* Line 1269 of yacc.c */
-#line 439 "parse-gram.y"
+#line 428 "parse-gram.y"
{
symbol_class_set ((yyvsp[(1) - (3)].symbol), current_class, (yylsp[(1) - (3)]), true);
symbol_type_set ((yyvsp[(1) - (3)].symbol), current_type, (yylsp[(1) - (3)]));
case 75:
/* Line 1269 of yacc.c */
-#line 469 "parse-gram.y"
+#line 458 "parse-gram.y"
{
yyerrok;
}
case 76:
/* Line 1269 of yacc.c */
-#line 475 "parse-gram.y"
+#line 464 "parse-gram.y"
{ current_lhs = (yyvsp[(1) - (1)].symbol); current_lhs_location = (yylsp[(1) - (1)]); }
break;
case 78:
/* Line 1269 of yacc.c */
-#line 479 "parse-gram.y"
+#line 468 "parse-gram.y"
{ grammar_current_rule_end ((yylsp[(1) - (1)])); }
break;
case 79:
/* Line 1269 of yacc.c */
-#line 480 "parse-gram.y"
+#line 469 "parse-gram.y"
{ grammar_current_rule_end ((yylsp[(3) - (3)])); }
break;
case 81:
/* Line 1269 of yacc.c */
-#line 486 "parse-gram.y"
+#line 475 "parse-gram.y"
{ grammar_current_rule_begin (current_lhs, current_lhs_location); }
break;
case 82:
/* Line 1269 of yacc.c */
-#line 488 "parse-gram.y"
+#line 477 "parse-gram.y"
{ grammar_current_rule_symbol_append ((yyvsp[(2) - (2)].symbol), (yylsp[(2) - (2)])); }
break;
case 83:
/* Line 1269 of yacc.c */
-#line 490 "parse-gram.y"
+#line 479 "parse-gram.y"
{ grammar_current_rule_action_append ((yyvsp[(2) - (2)].code), (yylsp[(2) - (2)])); }
break;
case 84:
/* Line 1269 of yacc.c */
-#line 492 "parse-gram.y"
+#line 481 "parse-gram.y"
{ grammar_current_rule_prec_set ((yyvsp[(3) - (3)].symbol), (yylsp[(3) - (3)])); }
break;
case 85:
/* Line 1269 of yacc.c */
-#line 494 "parse-gram.y"
+#line 483 "parse-gram.y"
{ grammar_current_rule_dprec_set ((yyvsp[(3) - (3)].integer), (yylsp[(3) - (3)])); }
break;
case 86:
/* Line 1269 of yacc.c */
-#line 496 "parse-gram.y"
+#line 485 "parse-gram.y"
{ grammar_current_rule_merge_set ((yyvsp[(3) - (3)].uniqstr), (yylsp[(3) - (3)])); }
break;
case 89:
/* Line 1269 of yacc.c */
-#line 512 "parse-gram.y"
+#line 501 "parse-gram.y"
{
static char one[] = "1";
(yyval.chars) = one;
case 91:
/* Line 1269 of yacc.c */
-#line 522 "parse-gram.y"
+#line 511 "parse-gram.y"
{
- code_props plain_code;
(yyvsp[(1) - (1)].code)[strlen ((yyvsp[(1) - (1)].code)) - 1] = '\n';
- code_props_plain_init (&plain_code, (yyvsp[(1) - (1)].code)+1, (yylsp[(1) - (1)]));
- code_props_translate_code (&plain_code);
- gram_scanner_last_string_free ();
- (yyval.chars) = code_props_code_get (plain_code);
+ (yyval.chars) = translate_code ((yyvsp[(1) - (1)].code) + 1, (yylsp[(1) - (1)]));
}
break;
case 92:
/* Line 1269 of yacc.c */
-#line 542 "parse-gram.y"
+#line 527 "parse-gram.y"
{ (yyval.symbol) = symbol_from_uniqstr ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); }
break;
case 93:
/* Line 1269 of yacc.c */
-#line 544 "parse-gram.y"
+#line 529 "parse-gram.y"
{
(yyval.symbol) = symbol_get (char_name ((yyvsp[(1) - (1)].character)), (yylsp[(1) - (1)]));
symbol_class_set ((yyval.symbol), token_sym, (yylsp[(1) - (1)]), false);
case 94:
/* Line 1269 of yacc.c */
-#line 552 "parse-gram.y"
+#line 537 "parse-gram.y"
{ (yyval.symbol) = symbol_from_uniqstr ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); }
break;
case 97:
/* Line 1269 of yacc.c */
-#line 564 "parse-gram.y"
+#line 549 "parse-gram.y"
{
(yyval.symbol) = symbol_get (quotearg_style (c_quoting_style, (yyvsp[(1) - (1)].chars)), (yylsp[(1) - (1)]));
symbol_class_set ((yyval.symbol), token_sym, (yylsp[(1) - (1)]), false);
case 99:
/* Line 1269 of yacc.c */
-#line 573 "parse-gram.y"
+#line 558 "parse-gram.y"
{
- code_props plain_code;
- code_props_plain_init (&plain_code, (yyvsp[(2) - (2)].chars), (yylsp[(2) - (2)]));
- code_props_translate_code (&plain_code);
+ muscle_code_grow ("epilogue", translate_code ((yyvsp[(2) - (2)].chars), (yylsp[(2) - (2)])), (yylsp[(2) - (2)]));
gram_scanner_last_string_free ();
- muscle_code_grow ("epilogue", code_props_code_get (plain_code), (yylsp[(2) - (2)]));
- code_scanner_last_string_free ();
}
break;
/* Line 1269 of yacc.c */
-#line 2550 "parse-gram.c"
+#line 2531 "parse-gram.c"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
/* Line 1486 of yacc.c */
-#line 583 "parse-gram.y"
+#line 564 "parse-gram.y"
%printer { fputs (char_name ($$), stderr); } CHAR
/* braceless is not to be used for rule or symbol actions, as it
- calls code_props_plain_init. */
+ calls translate_code. */
%type <chars> STRING "%{...%}" EPILOGUE braceless content content.opt
%type <code> "{...}"
%printer { fputs (quotearg_style (c_quoting_style, $$), stderr); }
prologue_declaration:
grammar_declaration
-| "%{...%}" {
- 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 (code_props_code_get (plain_code), @1, union_seen);
- code_scanner_last_string_free ();
-}
+| "%{...%}" { prologue_augment (translate_code ($1, @1), @1, union_seen); }
| "%debug" { debug_flag = true; }
| "%define" STRING content.opt { muscle_insert ($2, $3); }
| "%defines" { defines_flag = true; }
}
| "%initial-action" "{...}"
{
- 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", code_props_code_get (action), @2);
- code_scanner_last_string_free ();
+ muscle_code_grow ("initial_action", translate_symbol_action ($2, @2), @2);
}
| "%lex-param" "{...}" { add_param ("lex_param", $2, @2); }
| "%locations" { locations_flag = true; }
| "%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, $2, @2);
+ symbol_list_destructor_set (list, action, @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, $2, @2);
+ symbol_list_printer_set (list, action, @2);
symbol_list_free ($3);
}
| "%default-prec"
union_seen = true;
muscle_code_grow ("stype", body, @3);
- gram_scanner_last_string_free ();
}
;
braceless:
"{...}"
{
- code_props plain_code;
$1[strlen ($1) - 1] = '\n';
- code_props_plain_init (&plain_code, $1+1, @1);
- code_props_translate_code (&plain_code);
- gram_scanner_last_string_free ();
- $$ = code_props_code_get (plain_code);
+ $$ = translate_code ($1 + 1, @1);
}
;
/* Nothing. */
| "%%" EPILOGUE
{
- code_props plain_code;
- code_props_plain_init (&plain_code, $2, @2);
- code_props_translate_code (&plain_code);
+ muscle_code_grow ("epilogue", translate_code ($2, @2), @2);
gram_scanner_last_string_free ();
- muscle_code_grow ("epilogue", code_props_code_get (plain_code), @2);
- code_scanner_last_string_free ();
}
;
static bool
symbol_should_be_used (symbol_list const *s)
{
- if (code_props_code_get (symbol_destructor_get (s->content.sym)))
+ if (symbol_destructor_get (s->content.sym))
return true;
if (warnings_flag & warnings_midrule_values)
- {
- if (s->midrule && code_props_is_value_used (s->midrule->action_props))
- return true;
- if (s->midrule_parent_rule)
- {
- symbol_list *rhs_node =
- symbol_list_n_get (s->midrule_parent_rule,
- s->midrule_parent_rhs_index);
- if (code_props_is_value_used (rhs_node->action_props))
- return true;
- }
- }
+ 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 false;
}
Don't worry about the default action if $$ is untyped, since $$'s
value can't be used. */
- if (!code_props_code_get (r->action_props) && r->content.sym->type_name)
+ if (!r->action && r->content.sym->type_name)
{
symbol *first_rhs = r->next->content.sym;
/* If $$ is being set in default way, report if any type mismatch. */
symbol_list const *l = r;
int n = 0;
for (; l && l->content.sym; l = l->next, ++n)
- if (! (code_props_is_value_used (l->action_props)
+ if (! (l->used
|| !symbol_should_be_used (l)
/* The default action, $$ = $1, `uses' both. */
- || (!code_props_code_get (r->action_props)
- && (n == 0 || n == 1))))
+ || (!r->action && (n == 0 || n == 1))))
{
if (n)
warn_at (r->location, _("unused value: $%d"), n);
/* Make a DUMMY nonterminal, whose location is that of the midrule
action. Create the MIDRULE. */
- location dummy_location =
- code_props_location_get (current_rule->action_props);
+ location dummy_location = current_rule->action_location;
symbol *dummy = dummy_symbol_get (dummy_location);
symbol_list *midrule = symbol_list_sym_new (dummy, dummy_location);
++nritems;
/* Attach its location and actions to that of the DUMMY. */
midrule->location = dummy_location;
- code_props_rule_action_init (
- &midrule->action_props,
- code_props_code_get (current_rule->action_props),
- code_props_location_get (current_rule->action_props),
- midrule);
- code_props_none_init (¤t_rule->action_props);
+ 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;
if (previous_rule_end)
previous_rule_end->next = midrule;
void
grammar_current_rule_symbol_append (symbol *sym, location loc)
{
- if (code_props_code_get (current_rule->action_props))
+ if (current_rule->action)
grammar_midrule_action ();
grammar_symbol_append (sym, loc);
}
void
grammar_current_rule_action_append (const char *action, location loc)
{
- if (code_props_code_get (current_rule->action_props))
+ if (current_rule->action)
grammar_midrule_action ();
/* After all symbol declarations have been parsed, packgram invokes
- code_props_translate_code. */
- code_props_rule_action_init (¤t_rule->action_props, action, loc,
- current_rule);
+ translate_rule_action. */
+ current_rule->action = action;
+ current_rule->action_location = loc;
}
\f
`$' from any midrule symbol name. */
while (p)
{
- code_props_translate_code (&p->action_props);
+ if (p->action)
+ p->action = translate_rule_action (p);
if (p)
p = p->next;
}
rules[ruleno].precsym = NULL;
rules[ruleno].location = p->location;
rules[ruleno].useful = true;
- rules[ruleno].action = code_props_code_get (p->action_props);
- if (rules[ruleno].action)
- rules[ruleno].action_location =
- code_props_location_get (p->action_props);
+ rules[ruleno].action = p->action;
+ rules[ruleno].action_location = p->action_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
- && (code_props_is_value_used (p->action_props)
- || code_props_is_value_used (
- symbol_list_n_get (
- p->midrule_parent_rule,
- p->midrule_parent_rhs_index)->action_props)))
+ && (p->used
+ || symbol_list_n_get (p->midrule_parent_rule,
+ p->midrule_parent_rhs_index)->used))
p->content.sym->tag += 1;
/* Don't check the generated rule 0. It has no action, so some rhs
-/* Bison Code Data Structure and Scanner.
+/* Bison Action Scanner
Copyright (C) 2006 Free Software Foundation, Inc.
# define SCAN_CODE_H_
# include "location.h"
+# include "symlist.h"
-struct symbol_list;
-
-/**
- * \brief
- * Keeps track of the maximum number of semantic values to the left of a
- * handle (those referenced by \c $0, \c $-1, etc.) that are required by the
- * semantic actions of this grammar.
- */
+/* 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. */
extern int max_left_semantic_context;
-/**
- * \brief
- * A code passage captured from the grammar file and possibly translated,
- * and/or properties associated with such a code passage.
- * \note
- * - Don't break encapsulation by accessing the fields directly. Use the
- * provided interface functions.
- */
-typedef struct code_props {
- /**
- * \brief
- * What kind of \c code_props this is.
- * \sa
- * - \c code_props_none_init
- * - \c code_props_plain_init
- * - \c code_props_symbol_action_init
- * - \c code_props_rule_action_init
- */
- enum {
- CODE_PROPS_NONE, CODE_PROPS_PLAIN,
- CODE_PROPS_SYMBOL_ACTION, CODE_PROPS_RULE_ACTION
- } kind;
-
- /**
- * \brief
- * The code passage contained within this \c code_props.
- * \invariant
- * - <tt>code_props::code = NULL</tt> iff
- * <tt>code_props::kind = CODE_PROPS_NONE</tt>.
- */
- char const *code;
- /**
- * \brief
- * The grammar file location of \c code_props::code.
- * \invariant
- * - \c code_props::location is undefined iff
- * <tt>code_props::code = NULL</tt>.
- */
- location location;
- /**
- * \brief
- * The value returned by \c code_props_is_value_used for this
- * \c code_props.
- */
- bool is_value_used;
-
- /**
- * \brief
- * The \c symbol_list node associated with this code passage.
- * \invariant
- * - <tt>code_props::rule != NULL</tt> iff \c code_props::kind is
- * \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. (However, \c self may
- * still be conceptually associated with some passage of code contained
- * elsewhere. Thus, a call on <tt>code_props_is_value_used (*self)</tt>,
- * for example, is still reasonable.)
- */
-void code_props_none_init (code_props *self);
-
-/**
- * \brief A \c code_props initializer equivalent to \c code_props_none_init.
- */
-#define CODE_PROPS_NONE_INIT \
- {CODE_PROPS_NONE, NULL, EMPTY_LOCATION_INIT, false, NULL}
-
-/**
- * \brief
- * A \c code_props 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 does not claim responsibility for the memory of \c code.
- */
-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 \c $$ and \c \@$, 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 does not claim responsibility for the memory of \c code.
- */
-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 \c $$,
- * \c $1, \c $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 code or
- * \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
- * <tt>code_props_code_get (*self)</tt> iff
- * <tt>code_props_code_get (*self \@pre) != NULL</tt>.
- */
-void code_props_translate_code (code_props *self);
-
-/**
- * \pre
- * - None.
- * \post
- * - \c result = either:
- * - The code passage contained with \c self.
- * - \c NULL if none.
- */
-char const *code_props_code_get (code_props const self);
-
-/**
- * \pre
- * - <tt>code_props_code_get (self) != NULL</tt>.
- * \post
- * - \c result = the grammar file location of
- * <tt>code_props_code_get (self)</tt>.
- */
-location code_props_location_get (code_props const self);
+void code_scanner_free (void);
-/**
- * \pre
- * - \c self was not previously initialized with \c code_props_plain_init.
- * \post
- * - \c result = either:
- * - \c false if 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. (If \c self is for a RHS \c symbol_list node, that
- * \c code_props is not \c self. 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 \c self was not
- * referenced in the code passage.
- * - \c true otherwise.
- */
-bool code_props_is_value_used (code_props const self);
+/* 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);
-/**
- * \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 that \c code_props_translate_code was invoked is now
- * invalid.
- */
-void code_scanner_last_string_free (void);
+/* The action A refers to $$ and @$ only, referring to a symbol. */
+char const *translate_symbol_action (char const *a, location l);
-/**
- * \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 and all pointers returned by
- * \c code_props_code_get may now be invalid.
- */
-void code_scanner_free (void);
+/* The action contains no special escapes, just protect M4 special
+ symbols. */
+char const *translate_code (char const *a, location l);
#endif /* !SCAN_CODE_H_ */
#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 static char *code_lex (code_props *self, int sc_context)
+# define YY_DECL char *code_lex (int sc_context, symbol_list *rule)
YY_DECL;
#define YY_USER_ACTION location_compute (loc, &loc->end, yytext, yyleng);
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;
%}
<SC_RULE_ACTION>
{
- "$"("<"{tag}">")?(-?[0-9]+|"$") {
- handle_action_dollar (self->rule, yytext, *loc);
- }
- "@"(-?[0-9]+|"$") {
- handle_action_at (self->rule, yytext, *loc);
- }
+ "$"("<"{tag}">")?(-?[0-9]+|"$") handle_action_dollar (rule, yytext, *loc);
+ "@"(-?[0-9]+|"$") handle_action_at (rule, yytext, *loc);
"$" {
warn_at (*loc, _("stray `$'"));
<SC_SYMBOL_ACTION>
{
- "$$" {
- obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar[");
- self->is_value_used = true;
- }
+ "$$" obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar[");
"@$" obstack_sgrow (&obstack_for_string, "]b4_at_dollar[");
}
/* End of processing. */
<*><<EOF>> {
- STRING_FINISH;
- return last_string;
+ obstack_1grow (&obstack_for_string, '\0');
+ return obstack_finish (&obstack_for_string);
}
%%
static void
handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
{
- char const *type_name = NULL;
+ const char *type_name = NULL;
char *cp = text + 1;
symbol_list *effective_rule;
int effective_rule_length;
obstack_fgrow1 (&obstack_for_string,
"]b4_lhs_value([%s])[", type_name);
- rule->action_props.is_value_used = true;
+ rule->used = true;
}
else
{
obstack_fgrow3 (&obstack_for_string,
"]b4_rhs_value(%d, %d, [%s])[",
effective_rule_length, n, type_name);
- if (n > 0)
- symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
- true;
+ symbol_list_n_used_set (effective_rule, n, true);
}
else
complain_at (dollar_loc, _("integer out of range: %s"), quote (text));
| Initialize the scanner. |
`-------------------------*/
-/* Translate the dollars and ats in \a self, in the context \a sc_context
+/* 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
(SC_RULE_ACTION, SC_SYMBOL_ACTION, INITIAL). */
static char const *
-translate_action (code_props *self, int sc_context)
+translate_action (int sc_context, symbol_list *rule, char const *a, location l)
{
char *res;
static bool initialized = false;
initialized = true;
}
- loc->start = loc->end = self->location.start;
- yy_switch_to_buffer (yy_scan_string (self->code));
- res = code_lex (self, sc_context);
+ loc->start = loc->end = l.start;
+ yy_switch_to_buffer (yy_scan_string (a));
+ res = code_lex (sc_context, rule);
yy_delete_buffer (YY_CURRENT_BUFFER);
return res;
}
-/*------------------------------------------------------------------------.
-| 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)
-{
- self->kind = CODE_PROPS_SYMBOL_ACTION;
- self->code = code;
- self->location = code_loc;
- self->is_value_used = false;
- self->rule = NULL;
-}
-
-void
-code_props_rule_action_init (code_props *self, char const *code,
- location code_loc, symbol_list *rule)
-{
- self->kind = CODE_PROPS_RULE_ACTION;
- self->code = code;
- self->location = code_loc;
- self->is_value_used = false;
- self->rule = rule;
-}
-
-void
-code_props_translate_code (code_props *self)
-{
- 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;
- }
-}
-
char const *
-code_props_code_get (code_props const self)
+translate_rule_action (symbol_list *rule)
{
- return self.code;
+ return translate_action (SC_RULE_ACTION, rule, rule->action,
+ rule->action_location);
}
-location
-code_props_location_get (code_props const self)
+char const *
+translate_symbol_action (char const *a, location l)
{
- aver (self.code != NULL);
- return self.location;
+ return translate_action (SC_SYMBOL_ACTION, NULL, a, l);
}
-bool
-code_props_is_value_used (code_props const self)
+char const *
+translate_code (char const *a, location l)
{
- aver (self.kind != CODE_PROPS_PLAIN);
- return self.is_value_used;
+ return translate_action (INITIAL, NULL, a, l);
}
-void
-code_scanner_last_string_free (void)
-{
- STRING_FREE;
-}
+/*-----------------------------------------------.
+| Free all the memory allocated to the scanner. |
+`-----------------------------------------------*/
void
code_scanner_free (void)
/* 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);
#define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
/* A string representing the most recently saved token. */
-static char *last_string;
+char *last_string;
void
gram_scanner_last_string_free (void)
#include "system.h"
#include "complain.h"
-#include "scan-code.h"
#include "symlist.h"
res->midrule_parent_rule = NULL;
res->midrule_parent_rhs_index = 0;
- code_props_none_init (&res->action_props);
+ res->action = NULL;
+ res->used = false;
res->ruleprec = NULL;
res->dprec = 0;
for (/* Nothing. */; l && l->content.sym; l = l->next)
{
symbol_print (l->content.sym, f);
- fprintf (stderr,
- code_props_is_value_used (l->action_props)
- ? " used" : " unused");
+ fprintf (stderr, l->used ? " used" : " unused");
if (l && l->content.sym)
fprintf (f, ", ");
}
}
+/*--------------------------------------.
+| 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 *code, location loc)
+symbol_list_destructor_set (symbol_list *node, const char *destructor,
+ 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);
+ symbol_destructor_set (node->content.sym, destructor, loc);
break;
case SYMLIST_TYPE:
semantic_type_destructor_set (
- semantic_type_get (node->content.type_name), destructor);
+ semantic_type_get (node->content.type_name), destructor, loc);
break;
case SYMLIST_DEFAULT_TAGGED:
- default_tagged_destructor_set (destructor);
+ default_tagged_destructor_set (destructor, loc);
break;
case SYMLIST_DEFAULT_TAGLESS:
- default_tagless_destructor_set (destructor);
+ default_tagless_destructor_set (destructor, loc);
break;
}
}
void
-symbol_list_printer_set (symbol_list *node, const char *code, location loc)
+symbol_list_printer_set (symbol_list *node, const char *printer, 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);
+ symbol_printer_set (node->content.sym, printer, loc);
break;
case SYMLIST_TYPE:
semantic_type_printer_set (
- semantic_type_get (node->content.type_name), printer);
+ semantic_type_get (node->content.type_name), printer, loc);
break;
case SYMLIST_DEFAULT_TAGGED:
- default_tagged_printer_set (printer);
+ default_tagged_printer_set (printer, loc);
break;
case SYMLIST_DEFAULT_TAGLESS:
- default_tagless_printer_set (printer);
+ default_tagless_printer_set (printer, loc);
break;
}
}
#ifndef SYMLIST_H_
# define SYMLIST_H_
-# include "scan-code.h"
# include "location.h"
# include "symtab.h"
SYMLIST_DEFAULT_TAGGED, SYMLIST_DEFAULT_TAGLESS
} content_type;
union {
- /**
- * The symbol or \c NULL iff
- * <tt>symbol_list::content_type = SYMLIST_SYMBOL</tt>.
- */
+ /** The symbol or \c NULL iff <tt>node_type = SYMLIST_SYMBOL</tt>. */
symbol *sym;
- /**
- * The semantic type iff <tt>symbol_list::content_type = SYMLIST_TYPE</tt>.
- */
+ /** The semantic type iff <tt>node_type = SYMLIST_TYPE</tt>. */
uniqstr type_name;
} content;
location location;
struct symbol_list *midrule_parent_rule;
int midrule_parent_rhs_index;
- /* The action is attached to the LHS of a rule, but action properties for
- * each RHS are also stored here. */
- code_props action_props;
+ /* 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;
/* Precedence/associativity. */
symbol *ruleprec;
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 *code,
+void symbol_list_destructor_set (symbol_list *node, const char *destructor,
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 *code,
+void symbol_list_printer_set (symbol_list *node, const char *printer,
location loc);
#endif /* !SYMLIST_H_ */
| Default %destructor's and %printer's. |
`---------------------------------------*/
-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;
+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;
/*---------------------------------.
| Create a new symbol, named TAG. |
res->location = loc;
res->type_name = NULL;
- code_props_none_init (&res->destructor);
- code_props_none_init (&res->printer);
+ res->destructor = NULL;
+ res->printer = NULL;
res->number = NUMBER_UNDEFINED;
res->prec = 0;
uniqstr_assert (tag);
res->tag = tag;
- code_props_none_init (&res->destructor);
- code_props_none_init (&res->printer);
+ res->destructor = NULL;
+ res->printer = NULL;
return res;
}
if (s->Attr) \
fprintf (f, " %s { %s }", #Attr, s->Attr)
-#define SYMBOL_CODE_PRINT(Attr) \
- if (code_props_code_get (s->Attr)) \
- fprintf (f, " %s { %s }", #Attr, code_props_code_get(s->Attr))
-
void
symbol_print (symbol *s, FILE *f)
{
{
fprintf (f, "\"%s\"", s->tag);
SYMBOL_ATTR_PRINT (type_name);
- SYMBOL_CODE_PRINT (destructor);
- SYMBOL_CODE_PRINT (printer);
+ SYMBOL_ATTR_PRINT (destructor);
+ SYMBOL_ATTR_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 |
}
-/*-----------------------------------------.
-| Set the DESTRUCTOR associated with SYM. |
-`-----------------------------------------*/
+/*------------------------------------------------------------------.
+| Set the DESTRUCTOR associated with SYM. Do nothing if passed 0. |
+`------------------------------------------------------------------*/
void
-symbol_destructor_set (symbol *sym, code_props destructor)
+symbol_destructor_set (symbol *sym, const char *destructor, location loc)
{
- if (code_props_code_get (sym->destructor))
- symbol_redeclaration (sym, "%destructor",
- code_props_location_get (sym->destructor),
- code_props_location_get (destructor));
- sym->destructor = destructor;
+ if (destructor)
+ {
+ if (sym->destructor)
+ symbol_redeclaration (sym, "%destructor", sym->destructor_location,
+ loc);
+ sym->destructor = destructor;
+ sym->destructor_location = loc;
+ }
}
-/*------------------------------------------.
-| Set the DESTRUCTOR associated with TYPE. |
-`------------------------------------------*/
+/*-------------------------------------------------------------------.
+| Set the DESTRUCTOR associated with TYPE. Do nothing if passed 0. |
+`-------------------------------------------------------------------*/
void
-semantic_type_destructor_set (semantic_type *type, code_props destructor)
+semantic_type_destructor_set (semantic_type *type, const char *destructor,
+ location loc)
{
- if (code_props_code_get (type->destructor))
- semantic_type_redeclaration (type, "%destructor",
- code_props_location_get (type->destructor),
- code_props_location_get (destructor));
- type->destructor = destructor;
+ if (destructor)
+ {
+ if (type->destructor)
+ semantic_type_redeclaration (type, "%destructor",
+ type->destructor_location, loc);
+ type->destructor = destructor;
+ type->destructor_location = loc;
+ }
}
/*---------------------------------------.
| Get the computed %destructor for SYM. |
`---------------------------------------*/
-code_props
+const char *
symbol_destructor_get (symbol *sym)
{
/* Per-symbol %destructor. */
- if (code_props_code_get (sym->destructor))
+ if (sym->destructor != NULL)
return sym->destructor;
/* Per-type %destructor. */
if (sym->type_name)
{
- code_props destructor = semantic_type_get (sym->type_name)->destructor;
- if (code_props_code_get (destructor))
- return destructor;
+ semantic_type *type = semantic_type_get (sym->type_name);
+ if (type->destructor)
+ return type->destructor;
}
/* Apply default %destructor's only to user-defined symbols. */
if (sym->tag[0] == '$' || sym == errtoken)
- return code_props_none;
+ return NULL;
if (sym->type_name)
return default_tagged_destructor;
return default_tagless_destructor;
}
-/*--------------------------------------.
-| Set the PRINTER associated with SYM. |
-`--------------------------------------*/
+/*---------------------------------------------------------------.
+| 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;
+}
+
+/*---------------------------------------------------------------.
+| Set the PRINTER associated with SYM. Do nothing if passed 0. |
+`---------------------------------------------------------------*/
void
-symbol_printer_set (symbol *sym, code_props printer)
+symbol_printer_set (symbol *sym, const char *printer, location loc)
{
- if (code_props_code_get (sym->printer))
- symbol_redeclaration (sym, "%printer",
- code_props_location_get (sym->printer),
- code_props_location_get (printer));
- sym->printer = printer;
+ if (printer)
+ {
+ if (sym->printer)
+ symbol_redeclaration (sym, "%printer", sym->printer_location, loc);
+ sym->printer = printer;
+ sym->printer_location = loc;
+ }
}
-/*---------------------------------------.
-| Set the PRINTER associated with TYPE. |
-`---------------------------------------*/
+/*----------------------------------------------------------------.
+| Set the PRINTER associated with TYPE. Do nothing if passed 0. |
+`----------------------------------------------------------------*/
void
-semantic_type_printer_set (semantic_type *type, code_props printer)
+semantic_type_printer_set (semantic_type *type, const char *printer,
+ location loc)
{
- if (code_props_code_get (type->printer))
- semantic_type_redeclaration (type, "%printer",
- code_props_location_get (type->printer),
- code_props_location_get (printer));
- type->printer = printer;
+ if (printer)
+ {
+ if (type->printer)
+ semantic_type_redeclaration (type, "%printer", type->printer_location,
+ loc);
+ type->printer = printer;
+ type->printer_location = loc;
+ }
}
/*------------------------------------.
| Get the computed %printer for SYM. |
`------------------------------------*/
-code_props
+const char *
symbol_printer_get (symbol *sym)
{
/* Per-symbol %printer. */
- if (code_props_code_get (sym->printer))
+ if (sym->printer != NULL)
return sym->printer;
/* Per-type %printer. */
if (sym->type_name)
{
- code_props printer = semantic_type_get (sym->type_name)->printer;
- if (code_props_code_get (printer))
- return printer;
+ semantic_type *type = semantic_type_get (sym->type_name);
+ if (type->printer)
+ return type->printer;
}
/* Apply the default %printer only to user-defined symbols. */
if (sym->tag[0] == '$' || sym == errtoken)
- return code_props_none;
+ return NULL;
if (sym->type_name)
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. |
}
- if (code_props_code_get (orig->destructor)
- || code_props_code_get (alias->destructor))
+ if (orig->destructor || alias->destructor)
{
- if (code_props_code_get (orig->destructor))
- symbol_destructor_set (alias, orig->destructor);
+ if (orig->destructor)
+ symbol_destructor_set (alias, orig->destructor,
+ orig->destructor_location);
else
- symbol_destructor_set (orig, alias->destructor);
+ symbol_destructor_set (orig, alias->destructor,
+ alias->destructor_location);
}
- if (code_props_code_get (orig->printer)
- || code_props_code_get (alias->printer))
+ if (orig->printer || alias->printer)
{
- if (code_props_code_get (orig->printer))
- symbol_printer_set (alias, orig->printer);
+ if (orig->printer)
+ symbol_printer_set (alias, orig->printer, orig->printer_location);
else
- symbol_printer_set (orig, alias->printer);
+ symbol_printer_set (orig, alias->printer, alias->printer_location);
}
if (alias->prec || orig->prec)
`--------------------------------------------------*/
void
-default_tagged_destructor_set (code_props destructor)
+default_tagged_destructor_set (const char *destructor, location loc)
{
- if (code_props_code_get (default_tagged_destructor))
+ if (default_tagged_destructor != NULL)
{
- complain_at (code_props_location_get (destructor),
- _("redeclaration for default tagged %%destructor"));
- complain_at (code_props_location_get (default_tagged_destructor),
+ complain_at (loc, _("redeclaration for default tagged %%destructor"));
+ complain_at (default_tagged_destructor_location,
_("previous declaration"));
}
default_tagged_destructor = destructor;
+ default_tagged_destructor_location = loc;
}
void
-default_tagless_destructor_set (code_props destructor)
+default_tagless_destructor_set (const char *destructor, location loc)
{
- if (code_props_code_get (default_tagless_destructor))
+ if (default_tagless_destructor != NULL)
{
- complain_at (code_props_location_get (destructor),
- _("redeclaration for default tagless %%destructor"));
- complain_at (code_props_location_get (default_tagless_destructor),
+ complain_at (loc, _("redeclaration for default tagless %%destructor"));
+ complain_at (default_tagless_destructor_location,
_("previous declaration"));
}
default_tagless_destructor = destructor;
+ default_tagless_destructor_location = loc;
}
void
-default_tagged_printer_set (code_props printer)
+default_tagged_printer_set (const char *printer, location loc)
{
- if (code_props_code_get (default_tagged_printer))
+ if (default_tagged_printer != NULL)
{
- complain_at (code_props_location_get (printer),
- _("redeclaration for default tagged %%printer"));
- complain_at (code_props_location_get (default_tagged_printer),
+ complain_at (loc, _("redeclaration for default tagged %%printer"));
+ complain_at (default_tagged_printer_location,
_("previous declaration"));
}
default_tagged_printer = printer;
+ default_tagged_printer_location = loc;
}
void
-default_tagless_printer_set (code_props printer)
+default_tagless_printer_set (const char *printer, location loc)
{
- if (code_props_code_get (default_tagless_printer))
+ if (default_tagless_printer != NULL)
{
- complain_at (code_props_location_get (printer),
- _("redeclaration for default tagless %%printer"));
- complain_at (code_props_location_get (default_tagless_printer),
+ complain_at (loc, _("redeclaration for default tagless %%printer"));
+ complain_at (default_tagless_printer_location,
_("previous declaration"));
}
default_tagless_printer = printer;
+ default_tagless_printer_location = loc;
}
-
# include "assoc.h"
# include "location.h"
-# include "scan-code.h"
# include "uniqstr.h"
/*----------.
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. */
- code_props destructor;
+ 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;
/** Any \c \%printer declared specifically for this symbol.
Access this field only through <tt>symbol</tt>'s interface functions.
\sa symbol::destructor */
- code_props printer;
+ 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;
symbol_number number;
location prec_location;
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, code_props destructor);
+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);
-/** 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 symbol_destructor_get (symbol *sym);
+/** 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);
/** Set the \c printer associated with \c sym. */
-void symbol_printer_set (symbol *sym, code_props printer);
+void symbol_printer_set (symbol *sym, const char *printer, location loc);
-/** 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 symbol_printer_get (symbol *sym);
+/** 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);
/* Set the \c precedence associated with \c sym.
uniqstr tag;
/** Any \c %destructor declared for this semantic type. */
- code_props destructor;
+ const char *destructor;
+ /** The location of \c semantic_type::destructor. */
+ location destructor_location;
+
/** Any \c %printer declared for this semantic type. */
- code_props printer;
+ const char *printer;
+ /** The location of \c semantic_type::printer. */
+ location printer_location;
} semantic_type;
/** Fetch (or create) the semantic type associated to KEY. */
semantic_type *semantic_type_get (const char *key);
/** Set the \c destructor associated with \c type. */
-void semantic_type_destructor_set (semantic_type *type, code_props destructor);
+void semantic_type_destructor_set (semantic_type *type, const char *destructor,
+ location loc);
/** Set the \c printer associated with \c type. */
-void semantic_type_printer_set (semantic_type *type, code_props printer);
+void semantic_type_printer_set (semantic_type *type, const char *printer,
+ location loc);
/*----------------------------------.
| Symbol and semantic type tables. |
`---------------------------------------*/
/** Set the default \c \%destructor for tagged values. */
-void default_tagged_destructor_set (code_props destructor);
+void default_tagged_destructor_set (const char *destructor, location loc);
/** Set the default \c \%destructor for tagless values. */
-void default_tagless_destructor_set (code_props destructor);
+void default_tagless_destructor_set (const char *destructor, location loc);
/** Set the default \c \%printer for tagged values. */
-void default_tagged_printer_set (code_props printer);
+void default_tagged_printer_set (const char *printer, location loc);
/** Set the default \c \%printer for tagless values. */
-void default_tagless_printer_set (code_props printer);
+void default_tagless_printer_set (const char *printer, location loc);
#endif /* !SYMTAB_H_ */