OLD | NEW |
(Empty) | |
| 1 /* Output the generated parsing program for Bison. |
| 2 |
| 3 Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003, 2004, |
| 4 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
| 5 |
| 6 This file is part of Bison, the GNU Compiler Compiler. |
| 7 |
| 8 This program is free software: you can redistribute it and/or modify |
| 9 it under the terms of the GNU General Public License as published by |
| 10 the Free Software Foundation, either version 3 of the License, or |
| 11 (at your option) any later version. |
| 12 |
| 13 This program is distributed in the hope that it will be useful, |
| 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 GNU General Public License for more details. |
| 17 |
| 18 You should have received a copy of the GNU General Public License |
| 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 20 |
| 21 #include <config.h> |
| 22 #include "system.h" |
| 23 |
| 24 #include <configmake.h> |
| 25 #include <error.h> |
| 26 #include <get-errno.h> |
| 27 #include <quotearg.h> |
| 28 #include <subpipe.h> |
| 29 #include <timevar.h> |
| 30 |
| 31 #include "complain.h" |
| 32 #include "files.h" |
| 33 #include "getargs.h" |
| 34 #include "gram.h" |
| 35 #include "muscle_tab.h" |
| 36 #include "output.h" |
| 37 #include "reader.h" |
| 38 #include "scan-code.h" /* max_left_semantic_context */ |
| 39 #include "scan-skel.h" |
| 40 #include "symtab.h" |
| 41 #include "tables.h" |
| 42 #include <relocatable.h> |
| 43 |
| 44 |
| 45 static struct obstack format_obstack; |
| 46 |
| 47 |
| 48 /*-------------------------------------------------------------------. |
| 49 | Create a function NAME which associates to the muscle NAME the | |
| 50 | result of formatting the FIRST and then TABLE_DATA[BEGIN..END[ (of | |
| 51 | TYPE), and to the muscle NAME_max, the max value of the | |
| 52 | TABLE_DATA. | |
| 53 `-------------------------------------------------------------------*/ |
| 54 |
| 55 |
| 56 #define GENERATE_MUSCLE_INSERT_TABLE(Name, Type) \ |
| 57 \ |
| 58 static void \ |
| 59 Name (char const *name, \ |
| 60 Type *table_data, \ |
| 61 Type first, \ |
| 62 int begin, \ |
| 63 int end) \ |
| 64 { \ |
| 65 Type min = first; \ |
| 66 Type max = first; \ |
| 67 long int lmin; \ |
| 68 long int lmax; \ |
| 69 int i; \ |
| 70 int j = 1; \ |
| 71 \ |
| 72 obstack_fgrow1 (&format_obstack, "%6d", first); \ |
| 73 for (i = begin; i < end; ++i) \ |
| 74 { \ |
| 75 obstack_1grow (&format_obstack, ','); \ |
| 76 if (j >= 10) \ |
| 77 { \ |
| 78 obstack_sgrow (&format_obstack, "\n "); \ |
| 79 j = 1; \ |
| 80 } \ |
| 81 else \ |
| 82 ++j; \ |
| 83 obstack_fgrow1 (&format_obstack, "%6d", table_data[i]); \ |
| 84 if (table_data[i] < min) \ |
| 85 min = table_data[i]; \ |
| 86 if (max < table_data[i]) \ |
| 87 max = table_data[i]; \ |
| 88 } \ |
| 89 obstack_1grow (&format_obstack, 0); \ |
| 90 muscle_insert (name, obstack_finish (&format_obstack)); \ |
| 91 \ |
| 92 lmin = min; \ |
| 93 lmax = max; \ |
| 94 /* Build `NAME_min' and `NAME_max' in the obstack. */ \ |
| 95 obstack_fgrow1 (&format_obstack, "%s_min", name); \ |
| 96 obstack_1grow (&format_obstack, 0); \ |
| 97 MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), lmin); \ |
| 98 obstack_fgrow1 (&format_obstack, "%s_max", name); \ |
| 99 obstack_1grow (&format_obstack, 0); \ |
| 100 MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), lmax); \ |
| 101 } |
| 102 |
| 103 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int) |
| 104 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_int_table, int) |
| 105 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_base_table, base_number) |
| 106 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_rule_number_table, rule_number) |
| 107 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number) |
| 108 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number) |
| 109 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number) |
| 110 |
| 111 |
| 112 /*--------------------------------------------------------------------. |
| 113 | Print to OUT a representation of STRING escaped both for C and M4. | |
| 114 `--------------------------------------------------------------------*/ |
| 115 |
| 116 static void |
| 117 escaped_output (FILE *out, char const *string) |
| 118 { |
| 119 char const *p; |
| 120 fprintf (out, "[["); |
| 121 |
| 122 for (p = quotearg_style (c_quoting_style, string); *p; p++) |
| 123 switch (*p) |
| 124 { |
| 125 case '$': fputs ("$][", out); break; |
| 126 case '@': fputs ("@@", out); break; |
| 127 case '[': fputs ("@{", out); break; |
| 128 case ']': fputs ("@}", out); break; |
| 129 default: fputc (*p, out); break; |
| 130 } |
| 131 |
| 132 fprintf (out, "]]"); |
| 133 } |
| 134 |
| 135 |
| 136 /*------------------------------------------------------------------. |
| 137 | Prepare the muscles related to the symbols: translate, tname, and | |
| 138 | toknum. | |
| 139 `------------------------------------------------------------------*/ |
| 140 |
| 141 static void |
| 142 prepare_symbols (void) |
| 143 { |
| 144 MUSCLE_INSERT_BOOL ("token_table", token_table_flag); |
| 145 MUSCLE_INSERT_INT ("tokens_number", ntokens); |
| 146 MUSCLE_INSERT_INT ("nterms_number", nvars); |
| 147 MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number); |
| 148 MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number); |
| 149 |
| 150 muscle_insert_symbol_number_table ("translate", |
| 151 token_translations, |
| 152 token_translations[0], |
| 153 1, max_user_token_number + 1); |
| 154 |
| 155 /* tname -- token names. */ |
| 156 { |
| 157 int i; |
| 158 /* We assume that the table will be output starting at column 2. */ |
| 159 int j = 2; |
| 160 struct quoting_options *qo = clone_quoting_options (0); |
| 161 set_quoting_style (qo, c_quoting_style); |
| 162 set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS); |
| 163 for (i = 0; i < nsyms; i++) |
| 164 { |
| 165 char *cp = quotearg_alloc (symbols[i]->tag, -1, qo); |
| 166 /* Width of the next token, including the two quotes, the |
| 167 comma and the space. */ |
| 168 int width = strlen (cp) + 2; |
| 169 |
| 170 if (j + width > 75) |
| 171 { |
| 172 obstack_sgrow (&format_obstack, "\n "); |
| 173 j = 1; |
| 174 } |
| 175 |
| 176 if (i) |
| 177 obstack_1grow (&format_obstack, ' '); |
| 178 MUSCLE_OBSTACK_SGROW (&format_obstack, cp); |
| 179 free (cp); |
| 180 obstack_1grow (&format_obstack, ','); |
| 181 j += width; |
| 182 } |
| 183 free (qo); |
| 184 obstack_sgrow (&format_obstack, " ]b4_null["); |
| 185 |
| 186 /* Finish table and store. */ |
| 187 obstack_1grow (&format_obstack, 0); |
| 188 muscle_insert ("tname", obstack_finish (&format_obstack)); |
| 189 } |
| 190 |
| 191 /* Output YYTOKNUM. */ |
| 192 { |
| 193 int i; |
| 194 int *values = xnmalloc (ntokens, sizeof *values); |
| 195 for (i = 0; i < ntokens; ++i) |
| 196 values[i] = symbols[i]->user_token_number; |
| 197 muscle_insert_int_table ("toknum", values, |
| 198 values[0], 1, ntokens); |
| 199 free (values); |
| 200 } |
| 201 } |
| 202 |
| 203 |
| 204 /*-------------------------------------------------------------. |
| 205 | Prepare the muscles related to the rules: rhs, prhs, r1, r2, | |
| 206 | rline, dprec, merger. | |
| 207 `-------------------------------------------------------------*/ |
| 208 |
| 209 static void |
| 210 prepare_rules (void) |
| 211 { |
| 212 rule_number r; |
| 213 unsigned int i = 0; |
| 214 item_number *rhs = xnmalloc (nritems, sizeof *rhs); |
| 215 unsigned int *prhs = xnmalloc (nrules, sizeof *prhs); |
| 216 unsigned int *rline = xnmalloc (nrules, sizeof *rline); |
| 217 symbol_number *r1 = xnmalloc (nrules, sizeof *r1); |
| 218 unsigned int *r2 = xnmalloc (nrules, sizeof *r2); |
| 219 int *dprec = xnmalloc (nrules, sizeof *dprec); |
| 220 int *merger = xnmalloc (nrules, sizeof *merger); |
| 221 |
| 222 for (r = 0; r < nrules; ++r) |
| 223 { |
| 224 item_number *rhsp = NULL; |
| 225 /* Index of rule R in RHS. */ |
| 226 prhs[r] = i; |
| 227 /* RHS of the rule R. */ |
| 228 for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) |
| 229 rhs[i++] = *rhsp; |
| 230 /* LHS of the rule R. */ |
| 231 r1[r] = rules[r].lhs->number; |
| 232 /* Length of rule R's RHS. */ |
| 233 r2[r] = i - prhs[r]; |
| 234 /* Separator in RHS. */ |
| 235 rhs[i++] = -1; |
| 236 /* Line where rule was defined. */ |
| 237 rline[r] = rules[r].location.start.line; |
| 238 /* Dynamic precedence (GLR). */ |
| 239 dprec[r] = rules[r].dprec; |
| 240 /* Merger-function index (GLR). */ |
| 241 merger[r] = rules[r].merger; |
| 242 } |
| 243 aver (i == nritems); |
| 244 |
| 245 muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems); |
| 246 muscle_insert_unsigned_int_table ("prhs", prhs, 0, 0, nrules); |
| 247 muscle_insert_unsigned_int_table ("rline", rline, 0, 0, nrules); |
| 248 muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules); |
| 249 muscle_insert_unsigned_int_table ("r2", r2, 0, 0, nrules); |
| 250 muscle_insert_int_table ("dprec", dprec, 0, 0, nrules); |
| 251 muscle_insert_int_table ("merger", merger, 0, 0, nrules); |
| 252 |
| 253 MUSCLE_INSERT_INT ("rules_number", nrules); |
| 254 MUSCLE_INSERT_INT ("max_left_semantic_context", max_left_semantic_context); |
| 255 |
| 256 free (rhs); |
| 257 free (prhs); |
| 258 free (rline); |
| 259 free (r1); |
| 260 free (r2); |
| 261 free (dprec); |
| 262 free (merger); |
| 263 } |
| 264 |
| 265 /*--------------------------------------------. |
| 266 | Prepare the muscles related to the states. | |
| 267 `--------------------------------------------*/ |
| 268 |
| 269 static void |
| 270 prepare_states (void) |
| 271 { |
| 272 state_number i; |
| 273 symbol_number *values = xnmalloc (nstates, sizeof *values); |
| 274 for (i = 0; i < nstates; ++i) |
| 275 values[i] = states[i]->accessing_symbol; |
| 276 muscle_insert_symbol_number_table ("stos", values, |
| 277 0, 1, nstates); |
| 278 free (values); |
| 279 |
| 280 MUSCLE_INSERT_INT ("last", high); |
| 281 MUSCLE_INSERT_INT ("final_state_number", final_state->number); |
| 282 MUSCLE_INSERT_INT ("states_number", nstates); |
| 283 } |
| 284 |
| 285 |
| 286 |
| 287 /*---------------------------------. |
| 288 | Output the user actions to OUT. | |
| 289 `---------------------------------*/ |
| 290 |
| 291 static void |
| 292 user_actions_output (FILE *out) |
| 293 { |
| 294 rule_number r; |
| 295 |
| 296 fputs ("m4_define([b4_actions], \n[", out); |
| 297 for (r = 0; r < nrules; ++r) |
| 298 if (rules[r].action) |
| 299 { |
| 300 fprintf (out, "b4_case(%d, [b4_syncline(%d, ", r + 1, |
| 301 rules[r].action_location.start.line); |
| 302 escaped_output (out, rules[r].action_location.start.file); |
| 303 fprintf (out, ")\n[ %s]])\n\n", rules[r].action); |
| 304 } |
| 305 fputs ("])\n\n", out); |
| 306 } |
| 307 |
| 308 /*--------------------------------------. |
| 309 | Output the merge functions to OUT. | |
| 310 `--------------------------------------*/ |
| 311 |
| 312 static void |
| 313 merger_output (FILE *out) |
| 314 { |
| 315 int n; |
| 316 merger_list* p; |
| 317 |
| 318 fputs ("m4_define([b4_mergers], \n[[", out); |
| 319 for (n = 1, p = merge_functions; p != NULL; n += 1, p = p->next) |
| 320 { |
| 321 if (p->type[0] == '\0') |
| 322 fprintf (out, " case %d: *yy0 = %s (*yy0, *yy1); break;\n", |
| 323 n, p->name); |
| 324 else |
| 325 fprintf (out, " case %d: yy0->%s = %s (*yy0, *yy1); break;\n", |
| 326 n, p->type, p->name); |
| 327 } |
| 328 fputs ("]])\n\n", out); |
| 329 } |
| 330 |
| 331 /*--------------------------------------. |
| 332 | Output the tokens definition to OUT. | |
| 333 `--------------------------------------*/ |
| 334 |
| 335 static void |
| 336 token_definitions_output (FILE *out) |
| 337 { |
| 338 int i; |
| 339 char const *sep = ""; |
| 340 |
| 341 fputs ("m4_define([b4_tokens], \n[", out); |
| 342 for (i = 0; i < ntokens; ++i) |
| 343 { |
| 344 symbol *sym = symbols[i]; |
| 345 int number = sym->user_token_number; |
| 346 |
| 347 /* At this stage, if there are literal aliases, they are part of |
| 348 SYMBOLS, so we should not find symbols which are the aliases |
| 349 here. */ |
| 350 aver (number != USER_NUMBER_ALIAS); |
| 351 |
| 352 /* Skip error token. */ |
| 353 if (sym == errtoken) |
| 354 continue; |
| 355 |
| 356 /* If this string has an alias, then it is necessarily the alias |
| 357 which is to be output. */ |
| 358 if (sym->alias) |
| 359 sym = sym->alias; |
| 360 |
| 361 /* Don't output literal chars or strings (when defined only as a |
| 362 string). Note that must be done after the alias resolution: |
| 363 think about `%token 'f' "f"'. */ |
| 364 if (sym->tag[0] == '\'' || sym->tag[0] == '\"') |
| 365 continue; |
| 366 |
| 367 /* Don't #define nonliteral tokens whose names contain periods |
| 368 or '$' (as does the default value of the EOF token). */ |
| 369 if (strchr (sym->tag, '.') || strchr (sym->tag, '$')) |
| 370 continue; |
| 371 |
| 372 fprintf (out, "%s[[[%s]], %d]", |
| 373 sep, sym->tag, number); |
| 374 sep = ",\n"; |
| 375 } |
| 376 fputs ("])\n\n", out); |
| 377 } |
| 378 |
| 379 |
| 380 /*---------------------------------------------------. |
| 381 | Output the symbol destructors or printers to OUT. | |
| 382 `---------------------------------------------------*/ |
| 383 |
| 384 static void |
| 385 symbol_code_props_output (FILE *out, char const *what, |
| 386 code_props const *(*get)(symbol const *)) |
| 387 { |
| 388 int i; |
| 389 char const *sep = ""; |
| 390 |
| 391 fputs ("m4_define([b4_symbol_", out); |
| 392 fputs (what, out); |
| 393 fputs ("], \n[", out); |
| 394 for (i = 0; i < nsyms; ++i) |
| 395 { |
| 396 symbol *sym = symbols[i]; |
| 397 char const *code = (*get) (sym)->code; |
| 398 if (code) |
| 399 { |
| 400 location loc = (*get) (sym)->location; |
| 401 /* Filename, lineno, |
| 402 Symbol-name, Symbol-number, |
| 403 code, optional typename. */ |
| 404 fprintf (out, "%s[", sep); |
| 405 sep = ",\n"; |
| 406 escaped_output (out, loc.start.file); |
| 407 fprintf (out, ", %d, ", loc.start.line); |
| 408 escaped_output (out, sym->tag); |
| 409 fprintf (out, ", %d, [[%s]]", sym->number, code); |
| 410 if (sym->type_name) |
| 411 fprintf (out, ", [[%s]]", sym->type_name); |
| 412 fputc (']', out); |
| 413 } |
| 414 } |
| 415 fputs ("])\n\n", out); |
| 416 } |
| 417 |
| 418 |
| 419 static void |
| 420 prepare_actions (void) |
| 421 { |
| 422 /* Figure out the actions for the specified state, indexed by |
| 423 lookahead token type. */ |
| 424 |
| 425 muscle_insert_rule_number_table ("defact", yydefact, |
| 426 yydefact[0], 1, nstates); |
| 427 |
| 428 /* Figure out what to do after reducing with each rule, depending on |
| 429 the saved state from before the beginning of parsing the data |
| 430 that matched this rule. */ |
| 431 muscle_insert_state_number_table ("defgoto", yydefgoto, |
| 432 yydefgoto[0], 1, nsyms - ntokens); |
| 433 |
| 434 |
| 435 /* Output PACT. */ |
| 436 muscle_insert_base_table ("pact", base, |
| 437 base[0], 1, nstates); |
| 438 MUSCLE_INSERT_INT ("pact_ninf", base_ninf); |
| 439 |
| 440 /* Output PGOTO. */ |
| 441 muscle_insert_base_table ("pgoto", base, |
| 442 base[nstates], nstates + 1, nvectors); |
| 443 |
| 444 muscle_insert_base_table ("table", table, |
| 445 table[0], 1, high + 1); |
| 446 MUSCLE_INSERT_INT ("table_ninf", table_ninf); |
| 447 |
| 448 muscle_insert_base_table ("check", check, |
| 449 check[0], 1, high + 1); |
| 450 |
| 451 /* GLR parsing slightly modifies YYTABLE and YYCHECK (and thus |
| 452 YYPACT) so that in states with unresolved conflicts, the default |
| 453 reduction is not used in the conflicted entries, so that there is |
| 454 a place to put a conflict pointer. |
| 455 |
| 456 This means that YYCONFLP and YYCONFL are nonsense for a non-GLR |
| 457 parser, so we could avoid accidents by not writing them out in |
| 458 that case. Nevertheless, it seems even better to be able to use |
| 459 the GLR skeletons even without the non-deterministic tables. */ |
| 460 muscle_insert_unsigned_int_table ("conflict_list_heads", conflict_table, |
| 461 conflict_table[0], 1, high + 1); |
| 462 muscle_insert_unsigned_int_table ("conflicting_rules", conflict_list, |
| 463 0, 1, conflict_list_cnt); |
| 464 } |
| 465 |
| 466 |
| 467 /*---------------------------. |
| 468 | Call the skeleton parser. | |
| 469 `---------------------------*/ |
| 470 |
| 471 static void |
| 472 output_skeleton (void) |
| 473 { |
| 474 FILE *in; |
| 475 FILE *out; |
| 476 int filter_fd[2]; |
| 477 char const *argv[9]; |
| 478 pid_t pid; |
| 479 |
| 480 /* Compute the names of the package data dir and skeleton files. */ |
| 481 char const m4sugar[] = "m4sugar/m4sugar.m4"; |
| 482 char const m4bison[] = "bison.m4"; |
| 483 char *full_m4sugar; |
| 484 char *full_m4bison; |
| 485 char *full_skeleton; |
| 486 char const *p; |
| 487 char const *m4 = (p = getenv ("M4")) ? p : M4; |
| 488 char const *pkgdatadir = compute_pkgdatadir (); |
| 489 size_t skeleton_size = strlen (skeleton) + 1; |
| 490 size_t pkgdatadirlen = strlen (pkgdatadir); |
| 491 while (pkgdatadirlen && pkgdatadir[pkgdatadirlen - 1] == '/') |
| 492 pkgdatadirlen--; |
| 493 full_skeleton = xmalloc (pkgdatadirlen + 1 |
| 494 + (skeleton_size < sizeof m4sugar |
| 495 ? sizeof m4sugar : skeleton_size)); |
| 496 strncpy (full_skeleton, pkgdatadir, pkgdatadirlen); |
| 497 full_skeleton[pkgdatadirlen] = '/'; |
| 498 strcpy (full_skeleton + pkgdatadirlen + 1, m4sugar); |
| 499 full_m4sugar = xstrdup (full_skeleton); |
| 500 strcpy (full_skeleton + pkgdatadirlen + 1, m4bison); |
| 501 full_m4bison = xstrdup (full_skeleton); |
| 502 if (strchr (skeleton, '/')) |
| 503 strcpy (full_skeleton, skeleton); |
| 504 else |
| 505 strcpy (full_skeleton + pkgdatadirlen + 1, skeleton); |
| 506 |
| 507 /* Test whether m4sugar.m4 is readable, to check for proper |
| 508 installation. A faulty installation can cause deadlock, so a |
| 509 cheap sanity check is worthwhile. */ |
| 510 xfclose (xfopen (full_m4sugar, "r")); |
| 511 |
| 512 /* Create an m4 subprocess connected to us via two pipes. */ |
| 513 |
| 514 if (trace_flag & trace_tools) |
| 515 fprintf (stderr, "running: %s %s - %s %s\n", |
| 516 m4, full_m4sugar, full_m4bison, full_skeleton); |
| 517 |
| 518 /* Some future version of GNU M4 (most likely 1.6) may treat the -dV in a |
| 519 position-dependent manner. Keep it as the first argument so that all |
| 520 files are traced. |
| 521 |
| 522 See the thread starting at |
| 523 <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html> |
| 524 for details. */ |
| 525 { |
| 526 int i = 0; |
| 527 argv[i++] = m4; |
| 528 argv[i++] = "-I"; |
| 529 argv[i++] = pkgdatadir; |
| 530 if (trace_flag & trace_m4) |
| 531 argv[i++] = "-dV"; |
| 532 argv[i++] = full_m4sugar; |
| 533 argv[i++] = "-"; |
| 534 argv[i++] = full_m4bison; |
| 535 argv[i++] = full_skeleton; |
| 536 argv[i++] = NULL; |
| 537 } |
| 538 /* When POSIXLY_CORRECT is set, some future versions of GNU M4 (most likely |
| 539 2.0) may drop some of the GNU extensions that Bison's skeletons depend |
| 540 upon. So that the next release of Bison is forward compatible with those |
| 541 future versions of GNU M4, we unset POSIXLY_CORRECT here. |
| 542 |
| 543 FIXME: A user might set POSIXLY_CORRECT to affect processes run from |
| 544 macros like m4_syscmd in a custom skeleton. For now, Bison makes no |
| 545 promises about the behavior of custom skeletons, so this scenario is not a |
| 546 concern. However, we eventually want to eliminate this shortcoming. The |
| 547 next release of GNU M4 (1.4.12 or 1.6) will accept the -g command-line |
| 548 option as a no-op, and later releases will accept it to indicate that |
| 549 POSIXLY_CORRECT should be ignored. Once the GNU M4 versions that accept |
| 550 -g are pervasive, Bison should use -g instead of unsetting |
| 551 POSIXLY_CORRECT. |
| 552 |
| 553 See the thread starting at |
| 554 <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html> |
| 555 for details. */ |
| 556 unsetenv ("POSIXLY_CORRECT"); |
| 557 init_subpipe (); |
| 558 pid = create_subpipe (argv, filter_fd); |
| 559 free (full_m4sugar); |
| 560 free (full_m4bison); |
| 561 free (full_skeleton); |
| 562 |
| 563 out = fdopen (filter_fd[0], "w"); |
| 564 if (! out) |
| 565 error (EXIT_FAILURE, get_errno (), |
| 566 "fdopen"); |
| 567 |
| 568 /* Output the definitions of all the muscles. */ |
| 569 fputs ("m4_init()\n", out); |
| 570 |
| 571 user_actions_output (out); |
| 572 merger_output (out); |
| 573 token_definitions_output (out); |
| 574 symbol_code_props_output (out, "destructors", &symbol_destructor_get); |
| 575 symbol_code_props_output (out, "printers", &symbol_printer_get); |
| 576 |
| 577 muscles_m4_output (out); |
| 578 xfclose (out); |
| 579 |
| 580 /* Read and process m4's output. */ |
| 581 timevar_push (TV_M4); |
| 582 end_of_output_subpipe (pid, filter_fd); |
| 583 in = fdopen (filter_fd[1], "r"); |
| 584 if (! in) |
| 585 error (EXIT_FAILURE, get_errno (), |
| 586 "fdopen"); |
| 587 scan_skel (in); |
| 588 xfclose (in); |
| 589 reap_subpipe (pid, m4); |
| 590 timevar_pop (TV_M4); |
| 591 } |
| 592 |
| 593 static void |
| 594 prepare (void) |
| 595 { |
| 596 /* BISON_USE_PUSH_FOR_PULL is for the test suite and should not be documented |
| 597 for the user. */ |
| 598 char const *use_push_for_pull_env = getenv ("BISON_USE_PUSH_FOR_PULL"); |
| 599 bool use_push_for_pull_flag = false; |
| 600 if (use_push_for_pull_env != NULL |
| 601 && use_push_for_pull_env[0] != '\0' |
| 602 && 0 != strcmp (use_push_for_pull_env, "0")) |
| 603 use_push_for_pull_flag = true; |
| 604 |
| 605 /* Flags. */ |
| 606 MUSCLE_INSERT_BOOL ("debug_flag", debug_flag); |
| 607 MUSCLE_INSERT_BOOL ("defines_flag", defines_flag); |
| 608 MUSCLE_INSERT_BOOL ("error_verbose_flag", error_verbose); |
| 609 MUSCLE_INSERT_BOOL ("glr_flag", glr_parser); |
| 610 MUSCLE_INSERT_BOOL ("locations_flag", locations_flag); |
| 611 MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser); |
| 612 MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag); |
| 613 MUSCLE_INSERT_BOOL ("tag_seen_flag", tag_seen); |
| 614 MUSCLE_INSERT_BOOL ("use_push_for_pull_flag", use_push_for_pull_flag); |
| 615 MUSCLE_INSERT_BOOL ("yacc_flag", yacc_flag); |
| 616 |
| 617 /* File names. */ |
| 618 if (spec_name_prefix) |
| 619 MUSCLE_INSERT_STRING ("prefix", spec_name_prefix); |
| 620 |
| 621 MUSCLE_INSERT_STRING ("file_name_all_but_ext", all_but_ext); |
| 622 |
| 623 #define DEFINE(Name) MUSCLE_INSERT_STRING (#Name, Name ? Name : "") |
| 624 DEFINE (dir_prefix); |
| 625 DEFINE (parser_file_name); |
| 626 DEFINE (spec_defines_file); |
| 627 DEFINE (spec_file_prefix); |
| 628 DEFINE (spec_graph_file); |
| 629 DEFINE (spec_name_prefix); |
| 630 DEFINE (spec_outfile); |
| 631 DEFINE (spec_verbose_file); |
| 632 #undef DEFINE |
| 633 |
| 634 /* Find the right skeleton file, and add muscles about the skeletons. */ |
| 635 if (skeleton) |
| 636 MUSCLE_INSERT_C_STRING ("skeleton", skeleton); |
| 637 else |
| 638 skeleton = language->skeleton; |
| 639 |
| 640 /* About the skeletons. */ |
| 641 { |
| 642 /* b4_pkgdatadir is used inside m4_include in the skeletons, so digraphs |
| 643 would never be expanded. Hopefully no one has M4-special characters in |
| 644 his Bison installation path. */ |
| 645 MUSCLE_INSERT_STRING_RAW ("pkgdatadir", compute_pkgdatadir ()); |
| 646 } |
| 647 } |
| 648 |
| 649 |
| 650 /*----------------------------------------------------------. |
| 651 | Output the parsing tables and the parser code to ftable. | |
| 652 `----------------------------------------------------------*/ |
| 653 |
| 654 void |
| 655 output (void) |
| 656 { |
| 657 obstack_init (&format_obstack); |
| 658 |
| 659 prepare_symbols (); |
| 660 prepare_rules (); |
| 661 prepare_states (); |
| 662 prepare_actions (); |
| 663 |
| 664 prepare (); |
| 665 |
| 666 /* Process the selected skeleton file. */ |
| 667 output_skeleton (); |
| 668 |
| 669 obstack_free (&format_obstack, NULL); |
| 670 } |
| 671 |
| 672 char const * |
| 673 compute_pkgdatadir (void) |
| 674 { |
| 675 char const *pkgdatadir = getenv ("BISON_PKGDATADIR"); |
| 676 return pkgdatadir ? pkgdatadir : relocate (PKGDATADIR); |
| 677 } |
OLD | NEW |