From 342b8b6e2156e923797745af2da2596e3086ccd5 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 4 Oct 2001 14:55:21 +0000 Subject: [PATCH 1/1] Merge in branch-1_29. --- .cvsignore | 5 +- ChangeLog | 478 ++++++++++++++++++++++++++++++++++++++-- Makefile.am | 4 +- Makefile.maint | 151 ++++++++----- NEWS | 22 +- THANKS | 31 +-- config/prev-version.txt | 2 +- configure.in | 35 ++- doc/bison.1 | 38 +++- doc/bison.texinfo | 467 +++++++++++++++++++++++++++++---------- lib/quotearg.c | 11 +- m4/Makefile.am | 3 +- m4/atconfig.m4 | 22 -- m4/dmalloc.m4 | 22 ++ m4/mbrtowc.m4 | 18 ++ m4/prereq.m4 | 7 +- po/.cvsignore | 1 + po/ChangeLog | 10 + po/POTFILES.in | 1 - src/LR0.c | 36 +-- src/bison.simple | 5 +- src/closure.c | 1 - src/complain.c | 16 +- src/complain.h | 2 +- src/conflicts.c | 20 +- src/conflicts.h | 6 +- src/derives.c | 1 - src/files.c | 178 +++++++++------ src/files.h | 17 +- src/getargs.c | 8 +- src/gram.c | 22 +- src/gram.h | 6 +- src/lalr.c | 1 - src/lex.c | 73 +++--- src/lex.h | 10 +- src/main.c | 27 ++- src/nullable.c | 1 - src/options.c | 12 +- src/output.c | 64 +++--- src/print.c | 204 ++++++++--------- src/print_graph.c | 54 ++--- src/reader.c | 149 ++++--------- src/reduce.c | 7 +- src/symtab.c | 2 +- src/system.h | 22 +- src/vcg.c | 449 ++++++++++++++++++++----------------- src/vcg.h | 87 ++++++-- src/vcg_defaults.h | 14 +- tests/.cvsignore | 6 +- tests/Makefile.am | 41 ++-- tests/atconfig.in | 97 -------- tests/atgeneral.m4 | 420 ----------------------------------- tests/atlocal.in | 10 + tests/bison.in | 11 + tests/calc.at | 144 +++++++----- tests/output.at | 70 ++++++ tests/regression.at | 84 ++++++- tests/suite.at | 61 ----- tests/testsuite.at | 30 +++ 59 files changed, 2211 insertions(+), 1585 deletions(-) delete mode 100644 m4/atconfig.m4 create mode 100644 m4/dmalloc.m4 create mode 100644 m4/mbrtowc.m4 delete mode 100644 tests/atconfig.in delete mode 100644 tests/atgeneral.m4 create mode 100644 tests/atlocal.in create mode 100644 tests/bison.in create mode 100644 tests/output.at delete mode 100644 tests/suite.at create mode 100644 tests/testsuite.at diff --git a/.cvsignore b/.cvsignore index ff660068..fe6b0096 100644 --- a/.cvsignore +++ b/.cvsignore @@ -3,10 +3,11 @@ config.cache config.h config.log config.status -stamp-h +stamp-h* bison-* patches *.patch *.log log patches applied *.prj releases -*.flc \ No newline at end of file +*.flc +autom4te.cache diff --git a/ChangeLog b/ChangeLog index 58e969f6..fe764201 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,451 @@ +2001-10-04 Akim Demaille + + Merge in the branch 1.29. + + * src/reader.c (packsymbols): Use a temporary obstack for + `%%tokendef', since output_stack is already used elsewhere. + + 2001-10-02 Akim Demaille + + Bump 1.29d. + + 2001-10-02 Akim Demaille + + Version 1.29c. + + 2001-10-02 Akim Demaille + + * tests/regression.at (Invalid CPP headers): New. + From Alexander Belopolsky. + * src/files.c (compute_header_macro): Map non alnum chars to `_'. + + 2001-10-02 Akim Demaille + + * tests/regression.at (Invalid input): New. + * src/lex.c (lex): Be sure to set `token_buffer' in any case. + Reported by Shura. + + 2001-10-02 Akim Demaille + + * tests/calc.at: Now that --debug works, the tests must be adjusted. + + 2001-10-02 Akim Demaille + + * src/output.c (output_parser): Assert `skeleton'. + * src/files.c (skeleton_find): Look harder for skeletons on DOSish + systems. + From Shura. + + 2001-10-01 Marc Autret + + * src/lex.h: Echo modifications. + * src/lex.c (unlex): Parameter is now token_t. + From Hans Aberg. + + 2001-10-01 Marc Autret + + * src/main.c: Include lex.h. + From Hans Aberg. + + 2001-09-29 Akim Demaille + + * src/getargs.c (longopts): `--debug' is `-t', not `-d'. + + 2001-09-28 Akim Demaille + + * tests/testsuite.at: Update to newer Autotest. + * tests/Makefile.am (EXTRA_DIST): bison is not to be shipped. + + 2001-09-27 Akim Demaille + + Position independent wrapper. + + * tests/bison: Remove. + * tests/bison.in: New. + * configure.in: Adjust. + + 2001-09-27 Paul Eggert + + Port quotearg fixes from tar 1.13.24. + + * lib/quotearg.c: BSD/OS 4.1 wchar.h requires FILE and struct + tm to be declared. + (HAVE_MBSINIT): Undef if !HAVE_MBRTOWC. + (mbsinit): Define to 1 if !defined mbsinit && !HAVE_MBSINIT. + + * m4/Makefile.am (EXTRA_DIST): Add mbrtowc.m4. + * m4/mbrtowc.m4: New file. + * m4/prereq.m4 (jm_PREREQ_QUOTEARG): Check for mbsinit and stddef.h. + Use jm_FUNC_MBRTOWC instead of AC_CHECK_FUNCS(mbrtowc). + + 2001-09-27 Akim Demaille + + Bump to 1.29c. + + 2001-09-27 Akim Demaille + + Version 1.29b. + + 2001-09-25 Akim Demaille + + * src/system.h: Include `xalloc.h'. + Remove it from the C files. + * src/files.c (output_files): Free the obstacks. + * src/lex.c (init_lex): Rename as... + (lex_init): this. + (lex_free): New. + * src/main.c (main): Use it. + + 2001-09-24 Marc Autret + + * src/vcg.c (open_edge, close_edge, open_node, close_node): Change + to output informations in fout (FILE*). + (open_graph, close_graph): Likewise. + (output_graph, output_edge, output_node): Likewise. + * src/vcg.h: Update function prototypes. + * src/print_graph.c (print_graph): Open output graph file. + (print_actions): Adjust. + * src/files.h: Remove extern declaration. + * src/files.c: Remove graph_obstack declaration. + (open_files): Remove graph_obstack initialization. + (output_files): Remove graph_obstack saving. + + 2001-09-24 Marc Autret + + * src/files.c (compute_output_file_names): Fix. + + 2001-09-24 Marc Autret , + Akim Demaille + + * src/reader.c (reader): Remove call to free_symtab (). + * src/main.c (main): Call it here. + Include symtab.h. + * src/conflicts.c (initialize_conflicts): Rename as... + (solve_conflicts): this. + * src/print.c (print_core, print_actions, print_state) + (print_grammar): Dump to a file instead a `output_obstack'. + (print_results): Dump `output_obstack', and then proceed with the + FILE *. + * src/files.c (compute_output_file_names, close_files): New. + (output_files): Adjust. + * src/main.c (main): Adjust. + + 2001-09-23 Marc Autret + + * src/files.c (compute_header_macro): Computes header macro name + from spec_defines_file when given. + + 2001-09-23 Marc Autret + + * src/files.c (output_files): Add default extensions. + + 2001-09-22 Akim Demaille + + * src/conflicts.c (finalize_conflicts): Rename as... + (free_conflicts): this. + + 2001-09-22 Akim Demaille + + * src/gram.c (gram_free): Rename back as... + (dummy): this. + (output_token_translations): Free `token_translations'. + * src/symtab.c (free_symtab): Free the tag field. + + 2001-09-22 Akim Demaille + + Remove `translations' as it is always set to true. + + * src/gram.h: Adjust. + * src/reader.c (packsymbols, parse_token_decl): Adjust + * src/print.c (print_grammar): Adjust. + * src/output.c (output_token_translations): Adjust. + * src/lex.c (lex): Adjust. + * src/gram.c: Be sure the set pointers to NULL. + (dummy): Rename as... + (gram_free): this. + + 2001-09-22 Akim Demaille + + * configure.in: Invoke AM_LIB_DMALLOC. + * src/system.h: Use dmalloc. + * src/LR0.c: Be sure to have pointers initialized to NULL. + (allocate_itemsets): Allocate kernel_items only if needed. + + 2001-09-22 Akim Demaille + + * configure.in: Bump to 1.29b. + * tests/Makefile.am (DISTCLEANFILES): Add package.m4. + * tests/calc.at (_AT_DATA_CALC_Y): #undef malloc so that we don't + need xmalloc.c in calc.y. + From Pascal Bart. + + 2001-09-21 Akim Demaille + + Version 1.29a. + * Makefile.maint, config/config.guess, config/config.sub, + * config/missing: Update from masters. + * tests/Makefile.am ($(srcdir)/$(TESTSUITE)): No longer depend + upon package.m4. + * configure.in (ALL_LINGUAS): Add `tr'. + + 2001-09-21 Akim Demaille + + * tests/Makefile.am (package.m4): Move to... + ($(srcdir)/$(TESTSUITE)): here. + + 2001-09-20 Akim Demaille + + * src/complain.c: No longer try to be standalone: use system.h. + Don't assume __STDC__ is defined to 1. Just test if it is defined. + * src/complain.h: Likewise. + * src/reduce.c (useless_nonterminals, inaccessable_symbols): + Remove the unused variable `n'. + From Albert Chin-A-Young. + + 2001-09-18 Marc Autret + + * doc/bison.1: Update. + * doc/bison.texinfo (Bison Options): Update --defines and --graph + descriptions. + (Option Cross Key): Update. + Add --graph. + + 2001-09-18 Marc Autret + + * tests/regression.at: New test (comment in %union). + + 2001-09-18 Marc Autret + + * src/reader.c (parse_union_decl): Do not output '/'. Let copy_comment + do that. + Reported by Keith Browne. + + 2001-09-18 Marc Autret + + * tests/output.at: Add tests for --defines and --graph. + + 2001-09-18 Marc Autret + + * tests/output.at: Removes tests of %{header,src}_extension features. + + 2001-09-18 Akim Demaille + + * tests/Makefile.am (package.m4): New. + * tests/calc.at (_AT_CHECK_CALC): Just run `calc input'. + (_AT_CHECK_CALC_ERROR): Likewise. + Factor the `, ' part of verbose error messages. + + 2001-09-18 Marc Autret + + * src/getargs.c (longopts): Declare --defines and --graph as options + with optional arguments. + * src/files.h: Add extern declarations. + * src/files.c (spec_graph_file, spec_defines_file): New. + (output_files): Update. + Remove CPP-outed code. + + 2001-09-18 Marc Autret + + Turn off %{source,header}_extension feature. + + * src/files.c (compute_exts_from_gf): Update. + (compute_exts_from_src): Update. + (output_files): CPP-out useless code. + * src/files.h: Remove {header,source}_extension extern declarations. + * src/reader.c (parse_dquoted_param): CPP-out. + (parse_header_extension_decl): Remove. + (parse_source_extension_decl): Remove. + (read_declarations): Remove cases tok_{hdrext,srcext}. + * src/lex.c (percent_table): Remove {header,source}_extension entries. + * src/lex.h (token_t): Remove tok_hdrext and tok_srcext. + + 2001-09-10 Akim Demaille + + * tests/output.at (AT_CHECK_BISON_FLAGS, AT_CHECK_BISON_PERCENT): + (AT_CHECK_BISON_PERCENT_FLAGS): Merge into... + (AT_CHECK_OUTPUT): this. + Merely check ls' exit status, its output is useless. + + 2001-09-10 Akim Demaille + + * tests/calc.at: Use m4_match. + (_AT_DATA_CALC_Y): Check `yyin != NULL', not `stdin != NULL'. + + 2001-09-10 Marc Autret , + Akim Demaille + + * src/vcg.h (graph_s): color, textcolor, bordercolor are now + enum color_e. + * src/print_graph.c (print_graph): Initalize graph.layoutalgorithm + to `normal'. + * src/reader.c (parse_token_decl): Initialize token with tok_eof. + * src/lex.h: Adjust prototype. + (token_t): Add `tok_undef'. + * src/lex.c (struct percent_table_struct): Retval is now a token_t. + (parse_percent_token): Now returns token_t. + Add default statement in switch. + (lex): Separate `c' as an input variable, from the token_t result + part. + (unlexed): Is a token_t. + + 2001-09-10 Akim Demaille + + * configure.in: Bump to 1.29a. + + 2001-09-07 Akim Demaille + + Version 1.29. + + 2001-08-30 Akim Demaille + + * tests/atgeneral.m4, tests/atconfig.in, tests/suite.at: Remove. + * m4/atconfig.m4: Remove. + * tests/testsuite.at, tests/atlocal.in, tests/output.at, + * tests/bison: New. + * tests/regression.at, tests/calc.at: Use m4_define, AT_BANNER, + m4_if, m4_patsubst, and m4_regexp. + * tests/calc.at (_AT_CHECK_CALC, _AT_CHECK_CALC_ERROR): Use an + `input' file instead of echo. + + 2001-08-29 Akim Demaille + + Bump to 1.28e. + + 2001-08-29 Akim Demaille + + Version 1.28d. + + 2001-08-29 Paul Eggert + + * src/bison.simple (yyparse): Don't take the address of an + item before the start of an array, as that doesn't conform to + the C Standard. + + 2001-08-29 Robert Anisko + + * doc/bison.texinfo (Location Tracking Calc): New node. + + 2001-08-29 Paul Eggert + + * src/output.c (output): Do not define const, as this now + causes more problems than it cures. + + 2001-08-29 Akim Demaille + + * doc/bison.texinfo: Modernize `@node' and `@top' use: just name + the nodes. + Be sure to tag the `detailmenu'. + + 2001-08-29 Akim Demaille + + * Makefile.maint (do-po-update): Wget refuses to overwrite files: + download in a tmp dir. + + 2001-08-28 Marc Autret + + * config/depcomp: New file. + + 2001-08-28 Marc Autret + + * doc/bison.1 (mandoc): Adjust. + From Juan Manuel Guerrero. + + 2001-08-28 Marc Autret + + * src/print_graph.c (print_state): Fix. + + 2001-08-27 Marc Autret + + * src/vcg.h (classname_s, infoname_s, node_s): Constify the + char * members. + Echo modifications to the functions prototypes. + * src/vcg.c (add_classname, add_infoname): Adjust arguments. + + 2001-08-27 Marc Autret + + * src/vcg.c: Include `xalloc.h'. + (add_colorentry): New. + (add_classname): New. + (add_infoname): New. + * src/vcg.h: Add new prototypes. + + 2001-08-27 Akim Demaille + + * Makefile.maint: Sync. again with CVS Autoconf. + + 2001-08-27 Akim Demaille + + * Makefile.maint: Formatting changes. + (po-update, cvs-update, update): New targets. + (AMTAR): Remove. + + 2001-08-27 Akim Demaille + + * Makefile.am (AUTOMAKE_OPTIONS): 1.5. + * Makefile.maint: Sync. with CVS Autoconf. + + 2001-08-27 Marc Autret + + * src/vcg.h (struct infoname_s): New. + (struct colorentry_s): New. + (graph_s): New fields {vertical,horizontal}_order in structure. + Add `infoname' field. + Add `colorentry' field; + * src/vcg_defaults.h (G_VERTICAL_ORDER): New. + (G_HORIZONTAL_ORDER): New. + (G_INFONAME): New. + (G_COLORENTRY): New. + * src/vcg.c (output_graph): Add output of {vertical,horizontal}_order. + Add output of `infoname'. + Add output of `colorentry'. + + 2001-08-27 Marc Autret + + * src/reader.c (parse_dquoted_param): Rename variable `index' to `i'. + This one shadowed a global parameter. + + 2001-08-24 Marc Autret + + * src/print_graph.c (node_output_size): Declared POSIX `size_t' type, + instead of `unsigned'. + (print_state): Do not call obstack_object_size () in obstack_grow () + to avoid macro variables shadowing. + + 2001-08-23 Marc Autret + + * src/lex.c (percent_table): Typo: s/naem/name/. + Add graph option. + Normalize new options declarations. + + 2001-08-20 Pascal Bart + + * tests/suite.at: Exercise %header_extension and %source_extension. + + 2001-08-16 Marc Autret + + * src/reader.c (parse_dquoted_param): New. + (parse_header_extension_decl): Use it. + (parse_source_extension_decl): Likewise. + + 2001-08-16 Marc Autret + + * src/vcg.c: Remove includes of `complain.h' and `xalloc.h'. + (get_xxxx_str): Use assert () instead of complain (). + Remove return invokations in default cases. + (get_decision_str): Modify default behaviour. Remove second argument. + Echo modifications on calls. + (output_graph): Fix. + + 2001-08-16 Marc Autret + + * src/getargs.c (usage): Update with ``-g, --graph''. + + 2001-08-16 Marc Autret + + * doc/bison.texinfo (Bison Options): Add items `-g', `--graph'. + (Option Cross Key): Likewise. + * doc/bison.1: Update. + 2001-09-25 Pascal Bart * src/output.c (output_master_parser): Don't finish action_obstack. @@ -46,7 +494,7 @@ 2001-09-20 Pascal Bart * src/options.c (symtab.h): Include it, need by lex.h. - + 2001-09-20 Pascal Bart * src/lex.c (parse_percent_token): Change type of variable `tx', which @@ -92,7 +540,7 @@ * src/output.c (output): Delete call to reader_output_yylsp. * src/reader.c (reader): Likewise. * src/reader.h: Delete declaration of reader_output_yylsp. - + 2001-09-02 Marc Autret * src/reader.c: Include muscle_tab.h. @@ -102,9 +550,9 @@ (read_declarations, copy_action, read_additionnal_code, : Updated with correct variables and functions names. (packsymbols, reader): Likewise. - + * src/reader.h (muscle_obstack): Extern declaration update. - + * src/output.c: Include muscle_tab.h In all functions using macro_insert, change by using muscle_insert (). (macro_obstack): Rename muscle_obstack. @@ -116,7 +564,7 @@ * src/muscle_tab.h: Update double inclusion macros. (macro_entry_s): Rename muscle_entry_s. Update prototypes. - + * src/muscle_tab.c: Include muscle_tab.h. Rename macro_tabble to muscle_table. (mhash1, mhash2, mcmp): Use muscle_entry. @@ -131,7 +579,7 @@ 2001-09-02 Marc Autret Now the files macro_tab.[ch] are named muscle_tab.[ch]. - + * src/muscle_tab.c, src/muscle_tab.h: Add files. 2001-09-02 Marc Autret @@ -140,7 +588,7 @@ 2001-09-01 Pascal Bart - * src/reader.c (copy_guard): Use muscle to specify the `#line' + * src/reader.c (copy_guard): Use muscle to specify the `#line' filename. 2001-09-01 Marc Autret @@ -166,10 +614,10 @@ and insert the `prefix' muscles. * src/macrotab.c (macro_init): Likewise. (macro_init): Initialization prefix directive by `yy'. - * src/bison.simple: Substitute all %%yylex, %%yychar, %%yylval, + * src/bison.simple: Substitute all %%yylex, %%yychar, %%yylval, %%yydebug, %%yyerror, %%yynerrs and %%yyparse by yylex, yychar, yylval, yydebug, yyerror, yynerrs and yyparse. - New directive `#define' to substitute yydebug, ... with option + New directive `#define' to substitute yydebug, ... with option name_prefix. 2001-08-31 Pascal Bart @@ -180,11 +628,11 @@ 2001-08-31 Pascal Bart , Marc Autret - * src/reader.c (read_additionnal_code): Rename %%user_code to + * src/reader.c (read_additionnal_code): Rename %%user_code to %%epilogue. * src/output.c (output): Rename %%declarations to %%prologue. * src/bison.simple: Echo modifications. - + 2001-08-31 Marc Autret * src/reader.c (readgram): CleanUp. @@ -195,7 +643,7 @@ 2001-08-31 Pascal Bart - * src/reader.c (reader): Delete obsolete call to function + * src/reader.c (reader): Delete obsolete call to function output_trailers and output_headers. * src/output.h: Remove obsolete functions prototypes of output_headers and output_trailers. @@ -203,7 +651,7 @@ 2001-08-30 Pascal Bart * src/main.c: Include macrotab.h. - * src/macrotab.h (macro_entry_s): Constify fields. + * src/macrotab.h (macro_entry_s): Constify fields. Adjust functions prototypes. * src/macrotab.c (macro_insert): Constify key and value. (macro_find): Constify key. @@ -216,7 +664,7 @@ 2001-08-30 Marc Autret * src/reader.c (parse_skel_decl): New. - (read_declarations): Add case `tok_skel', call parse_skel_decl (). + (read_declarations): Add case `tok_skel', call parse_skel_decl (). * src/lex.h (token_t): New token `tok_skel'. * src/lex.c (percent_table): Add skeleton option entry. Standardize. @@ -237,7 +685,7 @@ 2001-08-28 Pascal Bart - * src/output.c (output): Copy attrs_obstack in the '%%definitions' + * src/output.c (output): Copy attrs_obstack in the '%%definitions' directive. * src/bison.simple: Add `%%definitions'. diff --git a/Makefile.am b/Makefile.am index a62eb047..475308db 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ ## Process this file with automake to produce Makefile.in -*-Makefile-*- -AUTOMAKE_OPTIONS = 1.5 check-news readme-alpha +AUTOMAKE_OPTIONS = 1.5 check-news readme-alpha dist-bzip2 ACLOCAL_AMFLAGS = -I m4 @@ -26,3 +26,5 @@ alpha_url_dir = gnu/bison # Files to update automatically. wget_files = $(srcdir)/config/config.guess $(srcdir)/config/config.sub \ $(srcdir)/config/texinfo.tex + +cvs_files = $(srcdir)/config/missing diff --git a/Makefile.maint b/Makefile.maint index b9309170..cedb9de3 100644 --- a/Makefile.maint +++ b/Makefile.maint @@ -22,9 +22,6 @@ # Do not save the original name or timestamp in the .tar.gz file. GZIP_ENV = '--no-name --best' -# Automake 1.4 does not define AMTAR. -AMTAR ?= $(TAR) - CVS = cvs prev_version_file ?= .prev-version @@ -46,12 +43,101 @@ release_archive_dir ?= ../release +## ---------------- ## +## Updating files. ## +## ---------------- ## + +WGET = wget +ftp-gnu = ftp://ftp.gnu.org/gnu + +# Use mv, if you don't have/want move-if-change. +move_if_change ?= move-if-change + +# ------------------- # +# Updating PO files. # +# ------------------- # + +po_repo = http://www.iro.umontreal.ca/contrib/po/maint/$(PACKAGE) +.PHONY: do-po-update po-update +do-po-update: + tmppo=/tmp/$(PACKAGE)-$(VERSION)-po &&\ + rm -rf $$tmppo && \ + mkdir $$tmppo && \ + (cd $$tmppo && $(WGET) -r -l1 -nd --no-parent -A '*.po' $(po_repo)) &&\ + cp $$tmppo/*.po po + cd po && $(MAKE) update-po + $(MAKE) po-check + +po-update: + if test -d "po"; then \ + $(MAKE) do-po-update; \ + fi + +# -------------------------- # +# Updating GNU build tools. # +# -------------------------- # + +# The following pseudo table associates a local directory and a URL +# with each of the files that belongs to some other package and is +# regularly updated from the specified URL. +wget_files ?= $(srcdir)/config.guess $(srcdir)/config.sub \ + $(srcdir)/src/ansi2knr.c \ + $(srcdir)/doc/texinfo.tex +wget-targets = $(patsubst %, get-%, $(wget_files)) + +config.guess-url_prefix = $(ftp-gnu)/config/ +config.sub-url_prefix = $(ftp-gnu)/config/ + +ansi2knr.c-url_prefix = ftp://ftp.cs.wisc.edu/ghost/ + +texinfo.tex-url_prefix = $(ftp-gnu)/texinfo/ + +standards.texi-url_prefix = $(ftp-gnu)/GNUinfo/ +make-stds.texi-url_prefix = $(ftp-gnu)/GNUinfo/ + +target = $(patsubst get-%, %, $@) +url = $($(notdir $(target))-url_prefix)$(notdir $(target)) + +.PHONY: $(wget-targets) +$(wget-targets): + $(WGET) $(url) -O $(target).t \ + && $(move_if_change) $(target).t $(target) + +.PHONY: wget-update +wget-update: $(wget-targets) + + +# Updating tools via CVS. +cvs_files ?= depcomp missing +cvs-targets = $(patsubst %, get-%, $(cvs_files)) + +automake_repo = :pserver:anoncvs@anoncvs.cygnus.com:/cvs/automake +.PHONY: $(cvs-targets) +$(cvs-targets): + $(CVS) -d $(automake_repo) co -p automake/lib/$(notdir $(target)) \ + >$(target).t \ + && $(move_if_change) $(target).t $(target); + +.PHONY: cvs-update +cvs-update: $(cvs-targets) + + +# --------------------- # +# Updating everything. # +# --------------------- # + +.PHONY: update +update: wget-update cvs-update po-update + + + ## --------------- ## ## Sanity checks. ## ## --------------- ## -# Checks that don't require cvs. -local-check: changelog-check po-check writable-files copyright-check +# Checks that don't require cvs. Run `changelog-check' last as +# previous test may reveal problems requiring new ChangeLog entries. +local-check: po-check copyright-check writable-files changelog-check changelog-check: if head ChangeLog | grep 'Version $(VERSION)' >/dev/null; then \ @@ -117,10 +203,16 @@ maintainer-distcheck: changelog-check $(MAKE) my-distcheck + +## -------------- ## +## Making dists. ## +## -------------- ## + + # Tag before making distribution. Also, don't make a distribution if # checks fail. Also, make sure the NEWS file is up-to-date. # FIXME: use dist-hook/my-dist like distcheck-hook/my-distcheck. -cvs-dist: cvs-check maintainer-distcheck +cvs-dist: local-check cvs-check maintainer-distcheck $(CVS) update po $(CVS) tag -c $(this-cvs-tag) $(MAKE) dist @@ -130,6 +222,7 @@ cvs-dist: cvs-check maintainer-distcheck null_AM_MAKEFLAGS = \ ACLOCAL=false \ AUTOCONF=false \ + AUTOM4TE=false \ AUTOMAKE=false \ AUTOHEADER=false \ MAKEINFO=false @@ -177,7 +270,7 @@ rel-check: md5_tmp=/tmp/rel-check-md5-$$$$; \ set -e; \ trap 'status=$$?; rm -f $$tarz $$md5_tmp; exit $$status' 0 1 2 3 15; \ - wget -q --output-document=$$tarz $(url); \ + $(WGET) -q --output-document=$$tarz $(url); \ echo "$(md5) -" > $$md5_tmp; \ md5sum -c $$md5_tmp < $$tarz @@ -228,48 +321,6 @@ announcement: NEWS ChangeLog $(rel-files) -e 'print "\n"."*"x70 ."\n"; s///; print; print "*"x70 ."\n"'; \ ) -WGET = wget -ftp-gnu = ftp://ftp.gnu.org/gnu - -# Use mv, if you don't have/want move-if-change. -move_if_change ?= move-if-change - -# The following pseudo table associates a local directory and a URL -# with each of the files that belongs to some other package and is -# regularly updated from the specified URL. -wget_files ?= $(srcdir)/config.guess $(srcdir)/config.sub \ - $(srcdir)/src/ansi2knr.c \ - $(srcdir)/doc/texinfo.tex -get-targets = $(patsubst %, get-%, $(wget_files)) - -config.guess-url_prefix = $(ftp-gnu)/config/ -config.sub-url_prefix = $(ftp-gnu)/config/ - -ansi2knr.c-url_prefix = ftp://ftp.cs.wisc.edu/ghost/ - -texinfo.tex-url_prefix = $(ftp-gnu)/texinfo/ - -standards.texi-url_prefix = $(ftp-gnu)/GNUinfo/ -make-stds.texi-url_prefix = $(ftp-gnu)/GNUinfo/ - -target = $(patsubst get-%, %, $@) -url = $($(notdir $(target))-url_prefix)$(notdir $(target)) - -.PHONY: $(get-targets) -$(get-targets): - $(WGET) $(url) -O $(target).t \ - && $(move_if_change) $(target).t $(target) - -automake_repo=:pserver:anoncvs@anoncvs.cygnus.com:/cvs/automake -.PHONY: wget-update -wget-update: $(get-targets) - for f in depcomp missing; do \ - test -f $$f || continue; \ - echo checking out $$f...; \ - $(CVS) -d $(automake_repo) co -p automake/lib/$$f > $$f.t \ - && $(move_if_change) $$f.t $$f; \ - done - define emit-rsync-commands echo ===================================== echo ===================================== @@ -284,7 +335,7 @@ endef $(xd-delta): $(release_archive_dir)/$(prev-tgz) $(distdir).tar.gz xdelta delta -9 $^ $@ || : -alpha: local-check +alpha: $(MAKE) cvs-dist $(MAKE) $(xd-delta) $(MAKE) -s announcement > /tmp/announce-$(my_distdir) diff --git a/NEWS b/NEWS index db3cdb27..af7d37d4 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,27 @@ Bison News ---------- -Changes in version 1.28c: +Changes in version 1.29d: + +* `--defines' and `--graph' have now an optionnal argument which is the + output file name. `-d' and `-g' do not change, they do not take any + argument. + +* `%source_extension' and `%header_extension' are removed, failed + experiment. + +* The test suite is more portable. + +* Better portability. + +Changes in version 1.29: + +* The output file does not define const, as this caused problems when used + with common autoconfiguration schemes. If you still use ancient compilers + that lack const, compile with the equivalent of the C compiler option + `-Dconst='. autoconf's AC_C_CONST macro provides one way to do this. + +* Added `-g' and `--graph'. * The Bison manual is now distributed under the terms of the GNU FDL. diff --git a/THANKS b/THANKS index 0c0cdfee..7cf068c6 100644 --- a/THANKS +++ b/THANKS @@ -1,22 +1,27 @@ Bison was originally written by Robert Corbett. It would not be what it is today without the invaluable help of these people: -Akim Demaille akim@epita.fr -Daniel Hagerty hag@gnu.org -David J. MacKenzie djm@gnu.org -Fabrice Bauzac noon@cote-dazur.com -Hans Aberg haberg@matematik.su.se -Jesse Thilo jthilo@gnu.org -Jim Meyering meyering@gnu.org -Laurent Mascherpa laurent.mascherpa@epita.fr +Akim Demaille akim@epita.fr +Albert Chin-A-Young china@thewrittenword.com +Alexander Belopolsky alexb@rentec.com +Daniel Hagerty hag@gnu.org +David J. MacKenzie djm@gnu.org +Fabrice Bauzac noon@cote-dazur.com +Hans Aberg haberg@matematik.su.se +Jesse Thilo jthilo@gnu.org +Jim Meyering meyering@gnu.org +Juan Manuel Guerrero ST001906@HRZ1.HRZ.TU-Darmstadt.De +Keith Browne kbrowne@legato.com +Laurent Mascherpa laurent.mascherpa@epita.fr Marc Autret autret_m@epita.fr -Neil Booth NeilB@earthling.net -Noah Friedman friedman@gnu.org +Neil Booth NeilB@earthling.net +Noah Friedman friedman@gnu.org Pascal Bart pascal.bart@epita.fr -Paul Eggert eggert@twinsun.com -Piotr Gackiewicz gacek@intertel.com.pl -Richard Stallman rms@gnu.org +Paul Eggert eggert@twinsun.com +Piotr Gackiewicz gacek@intertel.com.pl +Richard Stallman rms@gnu.org Robert Anisko anisko_r@epita.fr +Shura debil_urod@ngs.ru Many people are not named here because we lost track of them. We thank them! Please, help us keeping this list up to date. diff --git a/config/prev-version.txt b/config/prev-version.txt index e28936bb..b29581a8 100644 --- a/config/prev-version.txt +++ b/config/prev-version.txt @@ -1 +1 @@ -1.28c +1.29c diff --git a/configure.in b/configure.in index c64e5e95..4d5ed68e 100644 --- a/configure.in +++ b/configure.in @@ -1,12 +1,32 @@ -# Process this file with autoconf to produce a configure script. -AC_PREREQ(2.52) -AC_INIT(bison, 1.28c, bug-bison@gnu.org) +# Configure template for GNU Bison. -*-Autoconf-*- +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +# 02111-1307 USA + +# We need a recent Autoconf to run a recent Autotest. +AC_PREREQ(2.52e) + +AC_INIT([GNU Bison], [1.29d], [bug-bison@gnu.org]) AC_CONFIG_AUX_DIR(config) -AM_INIT_AUTOMAKE(bison, 1.28c) + +AM_INIT_AUTOMAKE([bison], [1.29d]) AM_CONFIG_HEADER(config.h:config.hin) # Initialize the test suite. -AT_CONFIG(../src) +AC_CONFIG_TESTDIR(tests) +AC_CONFIG_FILES([tests/bison], [chmod +x tests/bison]) # Checks for programs. AC_PROG_CC @@ -69,8 +89,9 @@ jm_FUNC_MALLOC jm_FUNC_REALLOC jm_PREREQ_QUOTEARG jm_PREREQ_ERROR +AM_WITH_DMALLOC -ALL_LINGUAS="de es et fr ja nl ru" +ALL_LINGUAS="de es et fr ja nl tr ru" AM_GNU_GETTEXT # This is necessary so that .o files in LIBOBJS are also built via @@ -83,4 +104,4 @@ AC_OUTPUT([Makefile intl/Makefile po/Makefile.in lib/Makefile src/Makefile doc/Makefile m4/Makefile - tests/Makefile tests/atconfig]) + tests/Makefile]) diff --git a/doc/bison.1 b/doc/bison.1 index ebcd396c..927a128f 100644 --- a/doc/bison.1 +++ b/doc/bison.1 @@ -10,7 +10,11 @@ bison \- GNU Project parser generator (yacc replacement) ] [ .B \-d ] [ -.B \-\-defines +.BI \-\-defines= defines-file +] [ +.B \-g +] [ +.BI \-\-graph= graph-file ] [ .B \-k ] [ @@ -123,8 +127,6 @@ chosen as if the input file were named .B \-d .br .ns -.TP -.B \-\-defines Write an extra output file containing macro definitions for the token type names defined in the grammar and the semantic value type .BR YYSTYPE , @@ -145,6 +147,32 @@ in a separate source file, because needs to be able to refer to token type codes and the variable .BR yylval . .TP +.BI \-\-defines= defines-file +The behaviour of +.BI \-\-defines +is the same than +.BI \-d +option. +The only difference is that it has an optionnal argument which is +the name of the output filename. +.TP +.BI \-g +.br +.ns +Output a VCG definition of the LALR(1) grammar automaton computed by +Bison. If the grammar file is +.BR foo.y +, the VCG output file will be +.BR foo.vcg . +.TP +.BI \-\-graph= graph-file +The behaviour of +.BI \-\-graph +is the same than +.BI \-g +option. The only difference is that it has an optionnal argument which +is the name of the output graph filename. +.TP .B \-k .br .ns @@ -315,9 +343,9 @@ bison \-y $* .sp .RE .SH FILES -/usr/local/lib/bison.simple simple parser +/usr/local/share/bison/bison.simple simple parser .br -/usr/local/lib/bison.hairy complicated parser +/usr/local/share/bison/bison.hairy complicated parser .SH "ENVIRONMENT VARIABLES" .TP .SM BISON_SIMPLE diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 72093d43..c7f4def9 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -129,11 +129,13 @@ Cover art by Etienne Suvasa. @contents -@node Top, Introduction, (dir), (dir) +@ifnottex +@node Top +@top Bison -@ifinfo -This manual documents version @value{VERSION} of Bison. -@end ifinfo +This manual documents version @value{VERSION} of Bison, updated +@value{UPDATED}. +@end ifnottex @menu * Introduction:: @@ -159,7 +161,7 @@ Reference sections: * Copying This Manual:: License for copying this manual. * Index:: Cross-references to the text. - --- The Detailed Node Listing --- +@detailmenu --- The Detailed Node Listing --- The Concepts of Bison @@ -182,6 +184,7 @@ Examples * Infix Calc:: Infix (algebraic) notation calculator. Operator precedence is introduced. * Simple Error Recovery:: Continuing after syntax errors. +* Location Tracking Calc:: Demonstrating the use of @@@var{n} and @@$. * Multi-function Calc:: Calculator with memory and trig functions. It uses multiple data-types for semantic values. * Exercises:: Ideas for improving the multi-function calculator. @@ -202,6 +205,12 @@ Grammar Rules for @code{rpcalc} * Rpcalc Line:: * Rpcalc Expr:: +Location Tracking Calculator: @code{ltcalc} + +* Decls: Ltcalc Decls. Bison and C declarations for ltcalc. +* Rules: Ltcalc Rules. Grammar rules for ltcalc, with explanations. +* Lexer: Ltcalc Lexer. The lexical analyzer. + Multi-Function Calculator: @code{mfcalc} * Decl: Mfcalc Decl. Bison declarations for multi-function calculator. @@ -301,9 +310,10 @@ Copying This Manual * GNU Free Documentation License:: License for copying this manual. +@end detailmenu @end menu -@node Introduction, Conditions, Top, Top +@node Introduction @unnumbered Introduction @cindex introduction @@ -329,7 +339,7 @@ multi-character string literals and other features. This edition corresponds to version @value{VERSION} of Bison. -@node Conditions, Copying, Introduction, Top +@node Conditions @unnumbered Conditions for Using Bison As of Bison version 1.24, we have changed the distribution terms for @@ -359,7 +369,7 @@ using the other GNU tools. @include gpl.texi -@node Concepts, Examples, Copying, Top +@node Concepts @chapter The Concepts of Bison This chapter introduces many of the basic concepts without which the @@ -381,7 +391,7 @@ use Bison or Yacc, we suggest you start by reading this chapter carefully. * Grammar Layout:: Overall structure of a Bison grammar file. @end menu -@node Language and Grammar, Grammar in Bison, , Concepts +@node Language and Grammar @section Languages and Context-Free Grammars @cindex context-free grammar @@ -490,7 +500,7 @@ the grammar's start symbol. If we use a grammar for C, the entire input must be a `sequence of definitions and declarations'. If not, the parser reports a syntax error. -@node Grammar in Bison, Semantic Values, Language and Grammar, Concepts +@node Grammar in Bison @section From Formal Rules to Bison Input @cindex Bison grammar @cindex grammar, Bison @@ -535,7 +545,7 @@ stmt: RETURN expr ';' @noindent @xref{Rules, ,Syntax of Grammar Rules}. -@node Semantic Values, Semantic Actions, Grammar in Bison, Concepts +@node Semantic Values @section Semantic Values @cindex semantic value @cindex value, semantic @@ -577,7 +587,7 @@ semantic value that is a number. In a compiler for a programming language, an expression typically has a semantic value that is a tree structure describing the meaning of the expression. -@node Semantic Actions, Locations Overview, Semantic Values, Concepts +@node Semantic Actions @section Semantic Actions @cindex semantic actions @cindex actions, semantic @@ -608,7 +618,7 @@ expr: expr '+' expr @{ $$ = $1 + $3; @} The action says how to produce the semantic value of the sum expression from the values of the two subexpressions. -@node Locations Overview, Bison Parser, Semantic Actions, Concepts +@node Locations Overview @section Locations @cindex location @cindex textual position @@ -637,7 +647,7 @@ rule how @code{@@$} should be formed. When building a new location for a given grouping, the default behavior of the output parser is to take the beginning of the first symbol, and the end of the last symbol. -@node Bison Parser, Stages, Locations Overview, Concepts +@node Bison Parser @section Bison Output: the Parser File @cindex Bison parser @cindex Bison utility @@ -682,7 +692,7 @@ Therefore, you should avoid using C identifiers starting with @samp{yy} or @samp{YY} in the Bison grammar file except for the ones defined in this manual. -@node Stages, Grammar Layout, Bison Parser, Concepts +@node Stages @section Stages in Using Bison @cindex stages in using Bison @cindex using Bison @@ -724,7 +734,7 @@ Compile the code output by Bison, as well as any other source files. Link the object files to produce the finished product. @end enumerate -@node Grammar Layout, , Stages, Concepts +@node Grammar Layout @section The Overall Layout of a Bison Grammar @cindex grammar file @cindex file format @@ -751,8 +761,8 @@ general form of a Bison grammar file is as follows: The @samp{%%}, @samp{%@{} and @samp{%@}} are punctuation that appears in every Bison grammar file to separate the sections. -The prologue may define types and variables used in the actions. You can -also use preprocessor commands to define macros used there, and use +The prologue may define types and variables used in the actions. You can +also use preprocessor commands to define macros used there, and use @code{#include} to include header files that do any of these things. The Bison declarations declare the names of the terminal and nonterminal @@ -762,12 +772,12 @@ semantic values of various symbols. The grammar rules define how to construct each nonterminal symbol from its parts. -The epilogue can contain any code you want to use. Often the definition of -the lexical analyzer @code{yylex} goes here, plus subroutines called by the -actions in the grammar rules. In a simple program, all the rest of the +The epilogue can contain any code you want to use. Often the definition of +the lexical analyzer @code{yylex} goes here, plus subroutines called by the +actions in the grammar rules. In a simple program, all the rest of the program can go here. -@node Examples, Grammar File, Concepts, Top +@node Examples @chapter Examples @cindex simple examples @cindex examples, simple @@ -791,12 +801,13 @@ to try them. * Infix Calc:: Infix (algebraic) notation calculator. Operator precedence is introduced. * Simple Error Recovery:: Continuing after syntax errors. +* Location Tracking Calc:: Demonstrating the use of @@@var{n} and @@$. * Multi-function Calc:: Calculator with memory and trig functions. It uses multiple data-types for semantic values. * Exercises:: Ideas for improving the multi-function calculator. @end menu -@node RPN Calc, Infix Calc, , Examples +@node RPN Calc @section Reverse Polish Notation Calculator @cindex reverse polish notation @cindex polish notation calculator @@ -821,7 +832,7 @@ The source code for this calculator is named @file{rpcalc.y}. The * Comp: Rpcalc Compile. Run the C compiler on the output code. @end menu -@node Rpcalc Decls, Rpcalc Rules, , RPN Calc +@node Rpcalc Decls @subsection Declarations for @code{rpcalc} Here are the C and Bison declarations for the reverse polish notation @@ -861,7 +872,7 @@ arithmetic operators are designated by single-character literals, so the only terminal symbol that needs to be declared is @code{NUM}, the token type for numeric constants. -@node Rpcalc Rules, Rpcalc Lexer, Rpcalc Decls, RPN Calc +@node Rpcalc Rules @subsection Grammar Rules for @code{rpcalc} Here are the grammar rules for the reverse polish notation calculator. @@ -912,7 +923,7 @@ rule are referred to as @code{$1}, @code{$2}, and so on. * Rpcalc Expr:: @end menu -@node Rpcalc Input, Rpcalc Line, , Rpcalc Rules +@node Rpcalc Input @subsubsection Explanation of @code{input} Consider the definition of @code{input}: @@ -946,7 +957,7 @@ The parser function @code{yyparse} continues to process input until a grammatical error is seen or the lexical analyzer says there are no more input tokens; we will arrange for the latter to happen at end of file. -@node Rpcalc Line, Rpcalc Expr, Rpcalc Input, Rpcalc Rules +@node Rpcalc Line @subsubsection Explanation of @code{line} Now consider the definition of @code{line}: @@ -971,7 +982,7 @@ uninitialized (its value will be unpredictable). This would be a bug if that value were ever used, but we don't use it: once rpcalc has printed the value of the user's input line, that value is no longer needed. -@node Rpcalc Expr, , Rpcalc Line, Rpcalc Rules +@node Rpcalc Expr @subsubsection Explanation of @code{expr} The @code{exp} grouping has several rules, one for each kind of expression. @@ -1030,7 +1041,7 @@ exp: NUM @noindent The latter, however, is much more readable. -@node Rpcalc Lexer, Rpcalc Main, Rpcalc Rules, RPN Calc +@node Rpcalc Lexer @subsection The @code{rpcalc} Lexical Analyzer @cindex writing a lexical analyzer @cindex lexical analyzer, writing @@ -1105,7 +1116,7 @@ yylex (void) @end group @end example -@node Rpcalc Main, Rpcalc Error, Rpcalc Lexer, RPN Calc +@node Rpcalc Main @subsection The Controlling Function @cindex controlling function @cindex main function in simple example @@ -1124,7 +1135,7 @@ main (void) @end group @end example -@node Rpcalc Error, Rpcalc Gen, Rpcalc Main, RPN Calc +@node Rpcalc Error @subsection The Error Reporting Routine @cindex error reporting routine @@ -1153,7 +1164,7 @@ have not written any error rules in this example, so any invalid input will cause the calculator program to exit. This is not clean behavior for a real calculator, but it is adequate for the first example. -@node Rpcalc Gen, Rpcalc Compile, Rpcalc Error, RPN Calc +@node Rpcalc Gen @subsection Running Bison to Make the Parser @cindex running Bison (introduction) @@ -1161,7 +1172,7 @@ Before running Bison to produce a parser, we need to decide how to arrange all the source code in one or more source files. For such a simple example, the easiest thing is to put everything in one file. The definitions of @code{yylex}, @code{yyerror} and @code{main} go at the -end, in the epilogue of the file +end, in the epilogue of the file (@pxref{Grammar Layout, ,The Overall Layout of a Bison Grammar}). For a large project, you would probably have several source files, and use @@ -1182,7 +1193,7 @@ Bison contains the source code for @code{yyparse}. The additional functions in the input file (@code{yylex}, @code{yyerror} and @code{main}) are copied verbatim to the output. -@node Rpcalc Compile, , Rpcalc Gen, RPN Calc +@node Rpcalc Compile @subsection Compiling the Parser File @cindex compiling the parser @@ -1227,7 +1238,7 @@ example session using @code{rpcalc}. % @end example -@node Infix Calc, Simple Error Recovery, RPN Calc, Examples +@node Infix Calc @section Infix Notation Calculator: @code{calc} @cindex infix notation calculator @cindex @code{calc} @@ -1313,7 +1324,7 @@ Here is a sample run of @file{calc.y}: 9 @end example -@node Simple Error Recovery, Multi-function Calc, Infix Calc, Examples +@node Simple Error Recovery @section Simple Error Recovery @cindex error recovery, simple @@ -1355,7 +1366,205 @@ input lines; it would also have to discard the rest of the current line of input. We won't discuss this issue further because it is not specific to Bison programs. -@node Multi-function Calc, Exercises, Simple Error Recovery, Examples +@node Location Tracking Calc +@section Location Tracking Calculator: @code{ltcalc} +@cindex location tracking calculator +@cindex @code{ltcalc} +@cindex calculator, location tracking + +This example extends the infix notation calculator with location tracking. +This feature will be used to improve error reporting, and provide better +error messages. + +For the sake of clarity, we will switch for this example to an integer +calculator, since most of the work needed to use locations will be done +in the lexical analyser. + +@menu +* Decls: Ltcalc Decls. Bison and C declarations for ltcalc. +* Rules: Ltcalc Rules. Grammar rules for ltcalc, with explanations. +* Lexer: Ltcalc Lexer. The lexical analyzer. +@end menu + +@node Ltcalc Decls +@subsection Declarations for @code{ltcalc} + +The C and Bison declarations for the location tracking calculator are the same +as the declarations for the infix notation calculator. + +@example +/* Location tracking calculator. */ + +%@{ +#define YYSTYPE int +#include +%@} + +/* Bison declarations. */ +%token NUM + +%left '-' '+' +%left '*' '/' +%left NEG +%right '^' + +%% /* Grammar follows */ +@end example + +In the code above, there are no declarations specific to locations. Defining +a data type for storing locations is not needed: we will use the type provided +by default (@pxref{Location Type, ,Data Types of Locations}), which is a four +member structure with the following integer fields: @code{first_line}, +@code{first_column}, @code{last_line} and @code{last_column}. + +@node Ltcalc Rules +@subsection Grammar Rules for @code{ltcalc} + +Whether you choose to handle locations or not has no effect on the syntax of +your language. Therefore, grammar rules for this example will be very close to +those of the previous example: we will only modify them to benefit from the new +informations we will have. + +Here, we will use locations to report divisions by zero, and locate the wrong +expressions or subexpressions. + +@example +@group +input : /* empty */ + | input line +; +@end group + +@group +line : '\n' + | exp '\n' @{ printf ("%d\n", $1); @} +; +@end group + +@group +exp : NUM @{ $$ = $1; @} + | exp '+' exp @{ $$ = $1 + $3; @} + | exp '-' exp @{ $$ = $1 - $3; @} + | exp '*' exp @{ $$ = $1 * $3; @} +@end group + | exp '/' exp +@group + @{ + if ($3) + $$ = $1 / $3; + else + @{ + $$ = 1; + printf("Division by zero, l%d,c%d-l%d,c%d", + @@3.first_line, @@3.first_column, + @@3.last_line, @@3.last_column); + @} + @} +@end group +@group + | '-' exp %preg NEG @{ $$ = -$2; @} + | exp '^' exp @{ $$ = pow ($1, $3); @} + | '(' exp ')' @{ $$ = $2; @} +@end group +@end example + +This code shows how to reach locations inside of semantic actions, by +using the pseudo-variables @code{@@@var{n}} for rule components, and the +pseudo-variable @code{@@$} for groupings. + +In this example, we never assign a value to @code{@@$}, because the +output parser can do this automatically. By default, before executing +the C code of each action, @code{@@$} is set to range from the beginning +of @code{@@1} to the end of @code{@@@var{n}}, for a rule with @var{n} +components. + +Of course, this behavior can be redefined (@pxref{Location Default +Action, , Default Action for Locations}), and for very specific rules, +@code{@@$} can be computed by hand. + +@node Ltcalc Lexer +@subsection The @code{ltcalc} Lexical Analyzer. + +Until now, we relied on Bison's defaults to enable location tracking. The next +step is to rewrite the lexical analyser, and make it able to feed the parser +with locations of tokens, as he already does for semantic values. + +To do so, we must take into account every single character of the input text, +to avoid the computed locations of being fuzzy or wrong: + +@example +@group +int +yylex (void) +@{ + int c; + + /* skip white space */ + while ((c = getchar ()) == ' ' || c == '\t') + ++yylloc.last_column; + + /* step */ + yylloc.first_line = yylloc.last_line; + yylloc.first_column = yylloc.last_column; +@end group + +@group + /* process numbers */ + if (isdigit (c)) + @{ + yylval = c - '0'; + ++yylloc.last_column; + while (isdigit (c = getchar ())) + @{ + ++yylloc.last_column; + yylval = yylval * 10 + c - '0'; + @} + ungetc (c, stdin); + return NUM; + @} +@end group + + /* return end-of-file */ + if (c == EOF) + return 0; + + /* return single chars and update location */ + if (c == '\n') + @{ + ++yylloc.last_line; + yylloc.last_column = 0; + @} + else + ++yylloc.last_column; + return c; +@} +@end example + +Basically, the lexical analyzer does the same processing as before: it skips +blanks and tabs, and reads numbers or single-character tokens. In addition +to this, it updates the @code{yylloc} global variable (of type @code{YYLTYPE}), +where the location of tokens is stored. + +Now, each time this function returns a token, the parser has it's number as +well as it's semantic value, and it's position in the text. The last needed +change is to initialize @code{yylloc}, for example in the controlling +function: + +@example +int +main (void) +@{ + yylloc.first_line = yylloc.last_line = 1; + yylloc.first_column = yylloc.last_column = 0; + return yyparse (); +@} +@end example + +Remember that computing locations is not a matter of syntax. Every character +must be associated to a location update, whether it is in valid input, in +comments, in literal strings, and so on... + +@node Multi-function Calc @section Multi-Function Calculator: @code{mfcalc} @cindex multi-function calculator @cindex @code{mfcalc} @@ -1407,7 +1616,7 @@ Note that multiple assignment and nested function calls are permitted. * Symtab: Mfcalc Symtab. Symbol table management subroutines. @end menu -@node Mfcalc Decl, Mfcalc Rules, , Multi-function Calc +@node Mfcalc Decl @subsection Declarations for @code{mfcalc} Here are the C and Bison declarations for the multi-function calculator. @@ -1458,7 +1667,7 @@ just as @code{%token} is used for declaring token types. We have not used implicitly by the rules that define them. But @code{exp} must be declared explicitly so we can specify its value type. @xref{Type Decl, ,Nonterminal Symbols}. -@node Mfcalc Rules, Mfcalc Symtab, Mfcalc Decl, Multi-function Calc +@node Mfcalc Rules @subsection Grammar Rules for @code{mfcalc} Here are the grammar rules for the multi-function calculator. @@ -1492,7 +1701,7 @@ exp: NUM @{ $$ = $1; @} %% @end smallexample -@node Mfcalc Symtab, , Mfcalc Rules, Multi-function Calc +@node Mfcalc Symtab @subsection The @code{mfcalc} Symbol Table @cindex symbol table example @@ -1733,7 +1942,7 @@ This program is both powerful and flexible. You may easily add new functions, and it is a simple job to modify this code to install predefined variables such as @code{pi} or @code{e} as well. -@node Exercises, , Multi-function Calc, Examples +@node Exercises @section Exercises @cindex exercises @@ -1751,7 +1960,7 @@ Make the program report an error if the user refers to an uninitialized variable in any way except to store a value in it. @end enumerate -@node Grammar File, Interface, Examples, Top +@node Grammar File @chapter Bison Grammar Files Bison takes as input a context-free grammar specification and produces a @@ -1771,7 +1980,7 @@ The Bison grammar input file conventionally has a name ending in @samp{.y}. * Multiple Parsers:: Putting more than one Bison parser in one program. @end menu -@node Grammar Outline, Symbols, , Grammar File +@node Grammar Outline @section Outline of a Bison Grammar A Bison grammar file has four main sections, shown here with the @@ -1814,7 +2023,7 @@ that they precede the definition of @code{yyparse}. You can use need any C declarations, you may omit the @samp{%@{} and @samp{%@}} delimiters that bracket this section. -@node Bison Declarations, Grammar Rules, Prologue, Grammar Outline +@node Bison Declarations @subsection The Bison Declarations Section @cindex Bison declarations (introduction) @cindex declarations, Bison (introduction) @@ -1824,7 +2033,7 @@ terminal and nonterminal symbols, specify precedence, and so on. In some simple grammars you may not need any declarations. @xref{Declarations, ,Bison Declarations}. -@node Grammar Rules, Epilogue, Bison Declarations, Grammar Outline +@node Grammar Rules @subsection The Grammar Rules Section @cindex grammar rules section @cindex rules section for grammar @@ -1842,11 +2051,11 @@ if it is the first thing in the file. @cindex epilogue @cindex C code, section for additional -The @var{epilogue} is copied verbatim to the end of the parser file, just as -the @var{prologue} is copied to the beginning. This is the most convenient -place to put anything that you want to have in the parser file but which need -not come before the definition of @code{yyparse}. For example, the -definitions of @code{yylex} and @code{yyerror} often go here. +The @var{epilogue} is copied verbatim to the end of the parser file, just as +the @var{prologue} is copied to the beginning. This is the most convenient +place to put anything that you want to have in the parser file but which need +not come before the definition of @code{yyparse}. For example, the +definitions of @code{yylex} and @code{yyerror} often go here. @xref{Interface, ,Parser C-Language Interface}. If the last section is empty, you may omit the @samp{%%} that separates it @@ -1857,7 +2066,7 @@ with @samp{yy} and many macros whose names start with @samp{YY}. It is a good idea to avoid using any such names (except those documented in this manual) in the epilogue of the grammar file. -@node Symbols, Rules, Grammar Outline, Grammar File +@node Symbols @section Symbols, Terminal and Nonterminal @cindex nonterminal symbol @cindex terminal symbol @@ -1969,7 +2178,7 @@ The symbol @code{error} is a terminal symbol reserved for error recovery (@pxref{Error Recovery}); you shouldn't use it for any other purpose. In particular, @code{yylex} should never return this value. -@node Rules, Recursion, Symbols, Grammar File +@node Rules @section Syntax of Grammar Rules @cindex rule syntax @cindex grammar rule syntax @@ -2064,7 +2273,7 @@ expseq1: exp It is customary to write a comment @samp{/* empty */} in each rule with no components. -@node Recursion, Semantics, Rules, Grammar File +@node Recursion @section Recursive Rules @cindex recursive rule @@ -2133,7 +2342,7 @@ primary: constant defines two mutually-recursive nonterminals, since each refers to the other. -@node Semantics, Locations, Recursion, Grammar File +@node Semantics @section Defining Language Semantics @cindex defining language semantics @cindex language semantics, defining @@ -2157,7 +2366,7 @@ the numbers associated with @var{x} and @var{y}. action in the middle of a rule. @end menu -@node Value Type, Multiple Types, , Semantics +@node Value Type @subsection Data Types of Semantic Values @cindex semantic value type @cindex value type, semantic @@ -2176,10 +2385,10 @@ specify some other type, define @code{YYSTYPE} as a macro, like this: @end example @noindent -This macro definition must go in the prologue of the grammar file +This macro definition must go in the prologue of the grammar file (@pxref{Grammar Outline, ,Outline of a Bison Grammar}). -@node Multiple Types, Actions, Value Type, Semantics +@node Multiple Types @subsection More Than One Value Type In most programs, you will need different data types for different kinds @@ -2203,7 +2412,7 @@ and for groupings with the @code{%type} Bison declaration (@pxref{Type Decl, ,Nonterminal Symbols}). @end itemize -@node Actions, Action Types, Multiple Types, Semantics +@node Actions @subsection Actions @cindex action @vindex $$ @@ -2279,7 +2488,7 @@ As long as @code{bar} is used only in the fashion shown here, @code{$0} always refers to the @code{expr} which precedes @code{bar} in the definition of @code{foo}. -@node Action Types, Mid-Rule Actions, Actions, Semantics +@node Action Types @subsection Data Types of Values in Actions @cindex action data types @cindex data types in actions @@ -2324,7 +2533,7 @@ reference. For example, if you have defined types as shown here: then you can write @code{$1} to refer to the first subunit of the rule as an integer, or @code{$1} to refer to it as a double. -@node Mid-Rule Actions, , Action Types, Semantics +@node Mid-Rule Actions @subsection Actions in Mid-Rule @cindex actions in mid-rule @cindex mid-rule actions @@ -2486,7 +2695,7 @@ the action is now at the end of its rule. Any mid-rule action can be converted to an end-of-rule action in this way, and this is what Bison actually does to implement mid-rule actions. -@node Locations, Declarations, Semantics, Grammar File +@node Locations @section Tracking Locations @cindex location @cindex textual position @@ -2507,7 +2716,7 @@ to take when rules are matched. * Location Default Action:: Defining a general way to compute locations. @end menu -@node Location Type, Actions and Locations, , Locations +@node Location Type @subsection Data Type of Locations @cindex data type of locations @cindex default location type @@ -2529,7 +2738,7 @@ struct @} @end example -@node Actions and Locations, Location Default Action, Location Type, Locations +@node Actions and Locations @subsection Actions and Locations @cindex location actions @cindex actions, location @@ -2596,7 +2805,7 @@ exp: @dots{} @end group @end example -@node Location Default Action, , Actions and Locations, Locations +@node Location Default Action @subsection Default Action for Locations @vindex YYLLOC_DEFAULT @@ -2640,7 +2849,7 @@ For consistency with semantic actions, valid indexes for the location array range from 1 to @var{n}. @end itemize -@node Declarations, Multiple Parsers, Locations, Grammar File +@node Declarations @section Bison Declarations @cindex declarations, Bison @cindex Bison declarations @@ -2669,7 +2878,7 @@ it explicitly (@pxref{Language and Grammar, ,Languages and Context-Free Grammars * Decl Summary:: Table of all Bison declarations. @end menu -@node Token Decl, Precedence Decl, , Declarations +@node Token Decl @subsection Token Type Names @cindex declaring token type names @cindex token type names, declaring @@ -2743,7 +2952,7 @@ interchangeably in further declarations or the grammar rules. The @code{yylex} function can use the token name or the literal string to obtain the token type code number (@pxref{Calling Convention}). -@node Precedence Decl, Union Decl, Token Decl, Declarations +@node Precedence Decl @subsection Operator Precedence @cindex precedence declarations @cindex declaring operator precedence @@ -2792,7 +3001,7 @@ When two tokens declared in different precedence declarations associate, the one declared later has the higher precedence and is grouped first. @end itemize -@node Union Decl, Type Decl, Precedence Decl, Declarations +@node Union Decl @subsection The Collection of Value Types @cindex declaring value types @cindex value types, declaring @@ -2823,7 +3032,7 @@ for a terminal or nonterminal symbol (@pxref{Type Decl, ,Nonterminal Symbols}). Note that, unlike making a @code{union} declaration in C, you do not write a semicolon after the closing brace. -@node Type Decl, Expect Decl, Union Decl, Declarations +@node Type Decl @subsection Nonterminal Symbols @cindex declaring value types, nonterminals @cindex value types, nonterminals, declaring @@ -2850,7 +3059,7 @@ use the same @code{<@var{type}>} construction in a declaration for the terminal symbol. All kinds of token declarations allow @code{<@var{type}>}. -@node Expect Decl, Start Decl, Type Decl, Declarations +@node Expect Decl @subsection Suppressing Conflict Warnings @cindex suppressing conflict warnings @cindex preventing warnings about conflicts @@ -2898,7 +3107,7 @@ Now Bison will stop annoying you about the conflicts you have checked, but it will warn you again if changes in the grammar result in additional conflicts. -@node Start Decl, Pure Decl, Expect Decl, Declarations +@node Start Decl @subsection The Start-Symbol @cindex declaring the start symbol @cindex start symbol, declaring @@ -2913,7 +3122,7 @@ may override this restriction with the @code{%start} declaration as follows: %start @var{symbol} @end example -@node Pure Decl, Decl Summary, Start Decl, Declarations +@node Pure Decl @subsection A Pure (Reentrant) Parser @cindex reentrant parser @cindex pure parser @@ -2953,7 +3162,7 @@ Whether the parser is pure has nothing to do with the grammar rules. You can generate either a pure parser or a nonreentrant parser from any valid grammar. -@node Decl Summary, , Pure Decl, Declarations +@node Decl Summary @subsection Bison Declaration Summary @cindex Bison declaration summary @cindex declaration summary @@ -3110,7 +3319,7 @@ The number of parser states (@pxref{Parser States}). @end table @end table -@node Multiple Parsers,, Declarations, Grammar File +@node Multiple Parsers @section Multiple Parsers in the Same Program Most programs that use Bison parse only one language and therefore contain @@ -3140,7 +3349,7 @@ of the parser source file, defining @code{yyparse} as @code{@var{prefix}parse}, and so on. This effectively substitutes one name for the other in the entire parser file. -@node Interface, Algorithm, Grammar File, Top +@node Interface @chapter Parser C-Language Interface @cindex C-language interface @cindex interface @@ -3162,7 +3371,7 @@ in the grammar file, you are likely to run into trouble. * Action Features:: Special features for use in actions. @end menu -@node Parser Function, Lexical, , Interface +@node Parser Function @section The Parser Function @code{yyparse} @findex yyparse @@ -3190,7 +3399,7 @@ Return immediately with value 0 (to report success). Return immediately with value 1 (to report failure). @end table -@node Lexical, Error Reporting, Parser Function, Interface +@node Lexical @section The Lexical Analyzer Function @code{yylex} @findex yylex @cindex lexical analyzer @@ -3219,7 +3428,7 @@ that need it. @xref{Invocation, ,Invoking Bison}.@refill in a pure parser (@pxref{Pure Decl, ,A Pure (Reentrant) Parser}). @end menu -@node Calling Convention, Token Values, , Lexical +@node Calling Convention @subsection Calling Convention for @code{yylex} The value that @code{yylex} returns must be the numeric code for the type @@ -3296,7 +3505,7 @@ The @code{yytname} table is generated only if you use the @code{%token_table} declaration. @xref{Decl Summary}. @end itemize -@node Token Values, Token Positions, Calling Convention, Lexical +@node Token Values @subsection Semantic Values of Tokens @vindex yylval @@ -3342,7 +3551,7 @@ then the code in @code{yylex} might look like this: @end group @end example -@node Token Positions, Pure Calling, Token Values, Lexical +@node Token Positions @subsection Textual Positions of Tokens @vindex yylloc @@ -3363,7 +3572,7 @@ feature makes the parser noticeably slower. @tindex YYLTYPE The data type of @code{yylloc} has the name @code{YYLTYPE}. -@node Pure Calling, , Token Positions, Lexical +@node Pure Calling @subsection Calling Conventions for Pure Parsers When you use the Bison declaration @code{%pure_parser} to request a @@ -3470,7 +3679,7 @@ You can use @samp{%pure_parser} to request a reentrant parser without also using @code{YYPARSE_PARAM}. Then you should call @code{yyparse} with no arguments, as usual. -@node Error Reporting, Action Features, Lexical, Interface +@node Error Reporting @section The Error Reporting Function @code{yyerror} @cindex error reporting function @findex yyerror @@ -3530,7 +3739,7 @@ encountered so far. Normally this variable is global; but if you request a pure parser (@pxref{Pure Decl, ,A Pure (Reentrant) Parser}) then it is a local variable which only the actions can access. -@node Action Features, , Error Reporting, Interface +@node Action Features @section Special Features for Use in Actions @cindex summary, action features @cindex action features summary @@ -3644,7 +3853,7 @@ Tracking Locations}. @end table -@node Algorithm, Error Recovery, Interface, Top +@node Algorithm @chapter The Bison Parser Algorithm @cindex Bison parser algorithm @cindex algorithm of parser @@ -3711,7 +3920,7 @@ This kind of parser is known in the literature as a bottom-up parser. * Stack Overflow:: What happens when stack gets full. How to avoid it. @end menu -@node Look-Ahead, Shift/Reduce, , Algorithm +@node Look-Ahead @section Look-Ahead Tokens @cindex look-ahead token @@ -3766,7 +3975,7 @@ doing so would produce on the stack the sequence of symbols @code{expr The current look-ahead token is stored in the variable @code{yychar}. @xref{Action Features, ,Special Features for Use in Actions}. -@node Shift/Reduce, Precedence, Look-Ahead, Algorithm +@node Shift/Reduce @section Shift/Reduce Conflicts @cindex conflicts @cindex shift/reduce conflicts @@ -3862,7 +4071,7 @@ expr: variable ; @end example -@node Precedence, Contextual Precedence, Shift/Reduce, Algorithm +@node Precedence @section Operator Precedence @cindex operator precedence @cindex precedence of operators @@ -3879,7 +4088,7 @@ shift and when to reduce. * How Precedence:: How they work. @end menu -@node Why Precedence, Using Precedence, , Precedence +@node Why Precedence @subsection When Precedence is Needed Consider the following ambiguous grammar fragment (ambiguous because the @@ -3926,7 +4135,7 @@ matter of whether the parser chooses to shift or reduce when the stack contains @w{@samp{1 - 2}} and the look-ahead token is @samp{-}: shifting makes right-associativity. -@node Using Precedence, Precedence Examples, Why Precedence, Precedence +@node Using Precedence @subsection Specifying Operator Precedence @findex %left @findex %right @@ -3947,7 +4156,7 @@ order in which they are declared. The first @code{%left} or precedence is lowest, the next such declaration declares the operators whose precedence is a little higher, and so on. -@node Precedence Examples, How Precedence, Using Precedence, Precedence +@node Precedence Examples @subsection Precedence Examples In our example, we would want the following declarations: @@ -3973,7 +4182,7 @@ declared with @code{'-'}: and so on. We assume that these tokens are more than one character long and therefore are represented by names, not character literals.) -@node How Precedence, , Precedence Examples, Precedence +@node How Precedence @subsection How Precedence Works The first effect of the precedence declarations is to assign precedence @@ -3994,7 +4203,7 @@ how each conflict was resolved. Not all rules and not all tokens have precedence. If either the rule or the look-ahead token has no precedence, then the default is to shift. -@node Contextual Precedence, Parser States, Precedence, Algorithm +@node Contextual Precedence @section Context-Dependent Precedence @cindex context-dependent precedence @cindex unary operator precedence @@ -4052,7 +4261,7 @@ exp: @dots{} @end group @end example -@node Parser States, Reduce/Reduce, Contextual Precedence, Algorithm +@node Parser States @section Parser States @cindex finite-state machine @cindex parser state @@ -4078,7 +4287,7 @@ There is one other alternative: the table can say that the look-ahead token is erroneous in the current state. This causes error processing to begin (@pxref{Error Recovery}). -@node Reduce/Reduce, Mystery Conflicts, Parser States, Algorithm +@node Reduce/Reduce @section Reduce/Reduce Conflicts @cindex reduce/reduce conflict @cindex conflicts, reduce/reduce @@ -4193,7 +4402,7 @@ redirects:redirect ; @end example -@node Mystery Conflicts, Stack Overflow, Reduce/Reduce, Algorithm +@node Mystery Conflicts @section Mysterious Reduce/Reduce Conflicts Sometimes reduce/reduce conflicts can occur that don't look warranted. @@ -4301,7 +4510,7 @@ return_spec: ; @end example -@node Stack Overflow, , Mystery Conflicts, Algorithm +@node Stack Overflow @section Stack Overflow, and How to Avoid It @cindex stack overflow @cindex parser stack overflow @@ -4335,7 +4544,7 @@ You can control how much stack is allocated initially by defining the macro @code{YYINITDEPTH}. This value too must be a compile-time constant integer. The default is 200. -@node Error Recovery, Context Dependency, Algorithm, Top +@node Error Recovery @chapter Error Recovery @cindex error recovery @cindex recovery from errors @@ -4453,7 +4662,7 @@ value 1 when the parser is recovering from a syntax error, and 0 the rest of the time. A value of 1 indicates that error messages are currently suppressed for new syntax errors. -@node Context Dependency, Debugging, Error Recovery, Top +@node Context Dependency @chapter Handling Context Dependencies The Bison paradigm is to parse tokens first, then group them into larger @@ -4472,7 +4681,7 @@ languages. (Actually, ``kludge'' means any technique that gets its job done but is neither clean nor robust.) -@node Semantic Tokens, Lexical Tie-ins, , Context Dependency +@node Semantic Tokens @section Semantic Info in Token Types The C language has a context dependency: the way an identifier is used @@ -4547,7 +4756,7 @@ here the information is global, and is used for other purposes in the program. A true lexical tie-in has a special-purpose flag controlled by the syntactic context. -@node Lexical Tie-ins, Tie-in Recovery, Semantic Tokens, Context Dependency +@node Lexical Tie-ins @section Lexical Tie-ins @cindex lexical tie-in @@ -4596,11 +4805,11 @@ Here we assume that @code{yylex} looks at the value of @code{hexflag}; when it is nonzero, all integers are parsed in hexadecimal, and tokens starting with letters are parsed as integers if possible. -The declaration of @code{hexflag} shown in the prologue of the parser file -is needed to make it accessible to the actions (@pxref{Prologue, ,The Prologue}). +The declaration of @code{hexflag} shown in the prologue of the parser file +is needed to make it accessible to the actions (@pxref{Prologue, ,The Prologue}). You must also write the code in @code{yylex} to obey the flag. -@node Tie-in Recovery, , Lexical Tie-ins, Context Dependency +@node Tie-in Recovery @section Lexical Tie-ins and Error Recovery Lexical tie-ins make strict demands on any error recovery rules you have. @@ -4655,7 +4864,7 @@ make sure your error recovery rules are not of this kind. Each rule must be such that you can be sure that it always will, or always won't, have to clear the flag. -@node Debugging, Invocation, Context Dependency, Top +@node Debugging @chapter Debugging Your Parser @findex YYDEBUG @findex yydebug @@ -4666,13 +4875,13 @@ If a Bison grammar compiles properly but doesn't do what you want when it runs, the @code{yydebug} parser-trace feature can help you figure out why. To enable compilation of trace facilities, you must define the macro -@code{YYDEBUG} when you compile the parser. You could use @samp{-DYYDEBUG=1} -as a compiler option or you could put @samp{#define YYDEBUG 1} in the prologue -of the grammar file (@pxref{Prologue, , The Prologue}). Alternatively, use the -@samp{-t} option when you run Bison (@pxref{Invocation, ,Invoking Bison}). +@code{YYDEBUG} when you compile the parser. You could use @samp{-DYYDEBUG=1} +as a compiler option or you could put @samp{#define YYDEBUG 1} in the prologue +of the grammar file (@pxref{Prologue, , The Prologue}). Alternatively, use the +@samp{-t} option when you run Bison (@pxref{Invocation, ,Invoking Bison}). We always define @code{YYDEBUG} so that debugging is always possible. -The trace facility uses @code{stderr}, so you must add +The trace facility uses @code{stderr}, so you must add @w{@code{#include }} to the prologue unless it is already there. Once you have compiled the program with trace facilities, the way to @@ -4736,7 +4945,7 @@ yyprint (FILE *file, int type, YYSTYPE value) @} @end smallexample -@node Invocation, Table of Symbols, Debugging, Top +@node Invocation @chapter Invoking Bison @cindex invoking Bison @cindex Bison invocation @@ -4782,7 +4991,7 @@ will produce @file{output.c++} and @file{outfile.h++}. * VMS Invocation:: Bison command syntax on VMS. @end menu -@node Bison Options, Environment Variables, , Invocation +@node Bison Options @section Bison Options Bison supports both traditional single-letter options and mnemonic long @@ -4875,12 +5084,16 @@ Adjust the output: @table @option @item -d -@itemx --defines Pretend that @code{%verbose} was specified, i.e., write an extra output file containing macro definitions for the token type names defined in the grammar and the semantic value type @code{YYSTYPE}, as well as a few @code{extern} variable declarations. @xref{Decl Summary}. +@item --defines=@var{defines-file} +The behaviour of @var{--defines} is the same than @samp{-d}. The only +difference is that it has an optionnal argument which is the name of +the output filename. + @item -b @var{file-prefix} @itemx --file-prefix=@var{prefix} Specify a prefix to use for all Bison output file names. The names are @@ -4898,9 +5111,19 @@ Specify the name @var{outfile} for the parser file. The other output files' names are constructed from @var{outfile} as described under the @samp{-v} and @samp{-d} options. + +@item -g +Output a VCG definition of the LALR(1) grammar automaton computed by +Bison. If the grammar file is @file{foo.y}, the VCG output file will +be @file{foo.vcg}. + +@item --graph=@var{graph-file} +The behaviour of @var{--graph} is the same than @samp{-g}. The only +difference is that it has an optionnal argument which is the name of +the output graph filename. @end table -@node Environment Variables, Option Cross Key, Bison Options, Invocation +@node Environment Variables @section Environment Variables @cindex environment variables @cindex BISON_HAIRY @@ -4925,7 +5148,7 @@ also be specified or overridden in a similar fashion, with the @end table -@node Option Cross Key, VMS Invocation, Environment Variables, Invocation +@node Option Cross Key @section Option Cross Key Here is a list of options, alphabetized by long option, to help you find @@ -4939,6 +5162,7 @@ the corresponding short option. \line{ --defines \leaderfill -d} \line{ --file-prefix \leaderfill -b} \line{ --fixed-output-files \leaderfill -y} +\line{ --graph \leaderfill -g} \line{ --help \leaderfill -h} \line{ --name-prefix \leaderfill -p} \line{ --no-lines \leaderfill -l} @@ -4954,9 +5178,10 @@ the corresponding short option. @ifinfo @example --debug -t ---defines -d +--defines=@var{defines-file} -d --file-prefix=@var{prefix} -b @var{file-prefix} --fixed-output-files --yacc -y +--graph=@var{graph-file} -d --help -h --name-prefix=@var{prefix} -p @var{name-prefix} --no-lines -l @@ -4968,7 +5193,7 @@ the corresponding short option. @end example @end ifinfo -@node VMS Invocation, , Option Cross Key, Invocation +@node VMS Invocation @section Invoking Bison under VMS @cindex invoking Bison under VMS @cindex VMS @@ -4996,7 +5221,7 @@ The VMS file system does not permit filenames such as @file{foo.tab.c}. In the above example, the output file would instead be named @file{foo_tab.c}. -@node Table of Symbols, Glossary, Invocation, Top +@node Table of Symbols @appendix Bison Symbols @cindex Bison symbols, table of @cindex symbols in Bison, table of @@ -5196,7 +5421,7 @@ Bison declarations section or the epilogue. @item %@{ %@} All code listed between @samp{%@{} and @samp{%@}} is copied directly to -the output file uninterpreted. Such code forms the prologue of the input +the output file uninterpreted. Such code forms the prologue of the input file. @xref{Grammar Outline, ,Outline of a Bison Grammar}. @@ -5215,7 +5440,7 @@ Separates alternate rules for the same result nonterminal. @xref{Rules, ,Syntax of Grammar Rules}. @end table -@node Glossary, Copying This Manual, Table of Symbols, Top +@node Glossary @appendix Glossary @cindex glossary @@ -5376,7 +5601,7 @@ grammatically indivisible. The piece of text it represents is a token. @xref{Language and Grammar, ,Languages and Context-Free Grammars}. @end table -@node Copying This Manual, Index, Glossary, Top +@node Copying This Manual @appendix Copying This Manual @menu @@ -5385,7 +5610,7 @@ grammatically indivisible. The piece of text it represents is a token. @include fdl.texi -@node Index, , Copying This Manual, Top +@node Index @unnumbered Index @printindex cp diff --git a/lib/quotearg.c b/lib/quotearg.c index 2a7ba4c4..ca42365e 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -63,6 +63,11 @@ #endif #if HAVE_WCHAR_H + +/* BSD/OS 4.1 wchar.h requires FILE and struct tm to be declared. */ +# include +# include + # include #endif @@ -73,8 +78,12 @@ # undef MB_CUR_MAX # define MB_CUR_MAX 1 # define mbrtowc(pwc, s, n, ps) ((*(pwc) = *(s)) != 0) -# define mbsinit(ps) 1 # define iswprint(wc) ISPRINT ((unsigned char) (wc)) +# undef HAVE_MBSINIT +#endif + +#if !defined mbsinit && !HAVE_MBSINIT +# define mbsinit(ps) 1 #endif #ifndef iswprint diff --git a/m4/Makefile.am b/m4/Makefile.am index 82e99cd9..261cc7d8 100644 --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -1,8 +1,8 @@ ## Process this file with automake to produce Makefile.in -*-Makefile-*- EXTRA_DIST = \ -atconfig.m4 \ c-bs-a.m4 \ codeset.m4 \ +dmalloc.m4 \ error.m4 \ gettext.m4 \ glibc21.m4 \ @@ -11,6 +11,7 @@ isc-posix.m4 \ lcmessage.m4 \ m4.m4 \ malloc.m4 \ +mbrtowc.m4 \ mbstate_t.m4 \ prereq.m4 \ progtest.m4 \ diff --git a/m4/atconfig.m4 b/m4/atconfig.m4 deleted file mode 100644 index f4a4de49..00000000 --- a/m4/atconfig.m4 +++ /dev/null @@ -1,22 +0,0 @@ -## ----------------------## -## Prepare for testing. ## -## ----------------------## - -# serial 2 - -# Single argument says where are built sources to test, relative to the -# built test directory. Maybe omitted if the same (flat distribution). - -AC_DEFUN([AT_CONFIG], -[AT_TESTPATH=ifelse([$1], [], [.], [$1]) -AC_SUBST([AT_TESTPATH]) -# Try to be compatible with both Autoconf 2.13 and 2.50. -if test -z "$ECHO_C$ECHO_N$ECHO_T"; then - ECHO_C="$ac_c" - ECHO_N="$ac_n" - ECHO_T="$ac_t" - AC_SUBST([ECHO_C]) - AC_SUBST([ECHO_N]) - AC_SUBST([ECHO_T]) -fi -]) diff --git a/m4/dmalloc.m4 b/m4/dmalloc.m4 new file mode 100644 index 00000000..f7246708 --- /dev/null +++ b/m4/dmalloc.m4 @@ -0,0 +1,22 @@ +## ----------------------------------- ## +## Check if --with-dmalloc was given. ## +## From Franc,ois Pinard ## +## ----------------------------------- ## + +# serial 1 + +AC_DEFUN([AM_WITH_DMALLOC], +[AC_MSG_CHECKING([if malloc debugging is wanted]) +AC_ARG_WITH(dmalloc, +[ --with-dmalloc use dmalloc, as in + http://www.dmalloc.com/dmalloc.tar.gz], +[if test "$withval" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE(WITH_DMALLOC,1, + [Define if using the dmalloc debugging malloc package]) + LIBS="$LIBS -ldmalloc" + LDFLAGS="$LDFLAGS -g" +else + AC_MSG_RESULT(no) +fi], [AC_MSG_RESULT(no)]) +]) diff --git a/m4/mbrtowc.m4 b/m4/mbrtowc.m4 new file mode 100644 index 00000000..87743919 --- /dev/null +++ b/m4/mbrtowc.m4 @@ -0,0 +1,18 @@ +#serial 4 + +dnl From Paul Eggert + +AC_DEFUN([jm_FUNC_MBRTOWC], +[ + AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared], + jm_cv_func_mbrtowc, + [AC_TRY_LINK( + [#include ], + [mbstate_t state; return ! (sizeof state && mbrtowc);], + jm_cv_func_mbrtowc=yes, + jm_cv_func_mbrtowc=no)]) + if test $jm_cv_func_mbrtowc = yes; then + AC_DEFINE(HAVE_MBRTOWC, 1, + [Define to 1 if mbrtowc and mbstate_t are properly declared.]) + fi +]) diff --git a/m4/prereq.m4 b/m4/prereq.m4 index f7114268..9595967a 100644 --- a/m4/prereq.m4 +++ b/m4/prereq.m4 @@ -1,12 +1,13 @@ -#serial 1 +#serial 2 dnl These are the prerequisite macros for files in the lib/ dnl directories of Bison. AC_DEFUN([jm_PREREQ_QUOTEARG], [ - AC_CHECK_FUNCS(isascii iswprint mbrtowc) - AC_CHECK_HEADERS(limits.h stdlib.h string.h wchar.h wctype.h) + AC_CHECK_FUNCS(isascii iswprint mbsinit) + jm_FUNC_MBRTOWC + AC_CHECK_HEADERS(limits.h stddef.h stdlib.h string.h wchar.h wctype.h) AC_HEADER_STDC AC_C_BACKSLASH_A AC_MBSTATE_T diff --git a/po/.cvsignore b/po/.cvsignore index f281fcaf..dcc40cb0 100644 --- a/po/.cvsignore +++ b/po/.cvsignore @@ -4,3 +4,4 @@ Makefile.in POTFILES bison.pot stamp-cat-id +*.gmo diff --git a/po/ChangeLog b/po/ChangeLog index 7f39c2b2..c63aa88f 100644 --- a/po/ChangeLog +++ b/po/ChangeLog @@ -1,3 +1,13 @@ +2001-10-04 gettextize + + * Makefile.in.in: Upgrade to gettext-0.10.40. + * cat-id-tbl.c: Remove file. + +2001-09-27 gettextize + + * Makefile.in.in: Upgrade to gettext-0.10.40. + * cat-id-tbl.c: Remove file. + 2001-08-03 gettextize * Makefile.in.in: Upgrade to gettext-0.10.39. diff --git a/po/POTFILES.in b/po/POTFILES.in index 4adb4f63..6215d608 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -13,7 +13,6 @@ src/print.c src/print_graph.c src/reader.c src/reduce.c -src/vcg.c lib/error.c lib/getopt.c diff --git a/src/LR0.c b/src/LR0.c index b37594e6..133a8218 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -23,7 +23,6 @@ The entry point is generate_states. */ #include "system.h" -#include "xalloc.h" #include "gram.h" #include "state.h" #include "complain.h" @@ -33,39 +32,39 @@ int nstates; int final_state; -core *first_state; -shifts *first_shift; -reductions *first_reduction; +core *first_state = NULL; +shifts *first_shift = NULL; +reductions *first_reduction = NULL; -static core *this_state; -static core *last_state; -static shifts *last_shift; -static reductions *last_reduction; +static core *this_state = NULL; +static core *last_state = NULL; +static shifts *last_shift = NULL; +static reductions *last_reduction = NULL; static int nshifts; -static short *shift_symbol; +static short *shift_symbol = NULL; -static short *redset; -static short *shiftset; +static short *redset = NULL; +static short *shiftset = NULL; -static short **kernel_base; -static short **kernel_end; -static short *kernel_items; +static short **kernel_base = NULL; +static short **kernel_end = NULL; +static short *kernel_items = NULL; /* hash table for states, to recognize equivalent ones. */ #define STATE_TABLE_SIZE 1009 -static core **state_table; +static core **state_table = NULL; static void allocate_itemsets (void) { - short *itemp; + short *itemp = NULL; int symbol; int i; int count; - short *symbol_count; + short *symbol_count = NULL; count = 0; symbol_count = XCALLOC (short, nsyms); @@ -89,7 +88,8 @@ allocate_itemsets (void) We allocate that much space for each symbol. */ kernel_base = XCALLOC (short *, nsyms); - kernel_items = XCALLOC (short, count); + if (count) + kernel_items = XCALLOC (short, count); count = 0; for (i = 0; i < nsyms; i++) diff --git a/src/bison.simple b/src/bison.simple index 9e094384..3f528732 100644 --- a/src/bison.simple +++ b/src/bison.simple @@ -512,13 +512,13 @@ yyparse (YYPARSE_PARAM_ARG) /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ -yynewstate: + yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. so pushing a state here evens the stacks. */ yyssp++; -yysetstate: + yysetstate: *yyssp = yystate; if (yyssp >= yyss + yystacksize - 1) @@ -995,4 +995,3 @@ yyabortlab: #line %%input_line "%%filename" %%epilogue - diff --git a/src/closure.c b/src/closure.c index 6d3d2207..03a59f0b 100644 --- a/src/closure.c +++ b/src/closure.c @@ -19,7 +19,6 @@ 02111-1307, USA. */ #include "system.h" -#include "xalloc.h" #include "gram.h" #include "closure.h" #include "derives.h" diff --git a/src/complain.c b/src/complain.c index b25f0b29..620e726c 100644 --- a/src/complain.c +++ b/src/complain.c @@ -19,14 +19,10 @@ /* Based on error.c and error.h, written by David MacKenzie . */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#include +#include "system.h" #if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC -# if __STDC__ +# ifdef __STDC__ # include # define VA_START(args, lastarg) va_start(args, lastarg) # else @@ -119,7 +115,7 @@ int error_one_per_line; `--------------------------------*/ void -#if defined VA_START && __STDC__ +#if defined VA_START && defined __STDC__ warn (const char *message, ...) #else warn (message, va_alist) @@ -171,7 +167,7 @@ warn (message, va_alist) `-----------------------------------------------------------*/ void -#if defined VA_START && __STDC__ +#if defined VA_START && defined __STDC__ complain (const char *message, ...) #else complain (message, va_alist) @@ -221,7 +217,7 @@ complain (message, va_alist) `-------------------------------------------------*/ void -#if defined VA_START && __STDC__ +#if defined VA_START && defined __STDC__ fatal (const char *message, ...) #else fatal (message, va_alist) @@ -259,7 +255,7 @@ fatal (message, va_alist) `------------------------------------------------------------------*/ void -#if defined VA_START && __STDC__ +#if defined VA_START && defined __STDC__ error (int status, int errnum, const char *message, ...) #else diff --git a/src/complain.h b/src/complain.h index 3642aab3..6a973848 100644 --- a/src/complain.h +++ b/src/complain.h @@ -23,7 +23,7 @@ extern "C" { #endif -#if defined (__STDC__) && __STDC__ +#ifdef __STDC__ /* Informative messages, but we proceed. */ diff --git a/src/conflicts.c b/src/conflicts.c index 208f7910..626db934 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -20,7 +20,6 @@ #include "system.h" #include "getargs.h" -#include "xalloc.h" #include "files.h" #include "gram.h" #include "state.h" @@ -30,12 +29,12 @@ #include "LR0.h" int any_conflicts = 0; -errs **err_table; +errs **err_table = NULL; int expected_conflicts; -static char *conflicts; +static char *conflicts = NULL; -static unsigned *shiftset; -static unsigned *lookaheadset; +static unsigned *shiftset = NULL; +static unsigned *lookaheadset = NULL; static int src_total; static int rrc_total; static int src_count; @@ -264,7 +263,7 @@ set_conflicts (int state) } void -initialize_conflicts (void) +solve_conflicts (void) { int i; @@ -458,7 +457,7 @@ conflict_report (int src_num, int rrc_num) `---------------------------------------------*/ void -print_conflicts (void) +print_conflicts (FILE *out) { int i; @@ -478,9 +477,8 @@ print_conflicts (void) if (verbose_flag) { - obstack_fgrow1 (&output_obstack, _("State %d contains"), i); - obstack_sgrow (&output_obstack, - conflict_report (src_count, rrc_count)); + fprintf (out, _("State %d contains"), i); + fputs (conflict_report (src_count, rrc_count), out); } } } @@ -738,7 +736,7 @@ print_reductions (int state) void -finalize_conflicts (void) +free_conflicts (void) { XFREE (conflicts); XFREE (shiftset); diff --git a/src/conflicts.h b/src/conflicts.h index 38e3c8d5..99a504c8 100644 --- a/src/conflicts.h +++ b/src/conflicts.h @@ -22,10 +22,10 @@ # define CONFLICTS_H_ # include "state.h" -void initialize_conflicts PARAMS ((void)); -void print_conflicts PARAMS ((void)); +void solve_conflicts PARAMS ((void)); +void print_conflicts PARAMS ((FILE *out)); void print_reductions PARAMS ((int)); -void finalize_conflicts PARAMS ((void)); +void free_conflicts PARAMS ((void)); /* Were there conflicts? */ extern int any_conflicts; diff --git a/src/derives.c b/src/derives.c index 49b4edff..e9c75649 100644 --- a/src/derives.c +++ b/src/derives.c @@ -25,7 +25,6 @@ */ #include "system.h" -#include "xalloc.h" #include "types.h" #include "gram.h" #include "derives.h" diff --git a/src/files.c b/src/files.c index 6bf301f9..7e29c4c6 100644 --- a/src/files.c +++ b/src/files.c @@ -22,7 +22,6 @@ #include "system.h" #include "getargs.h" #include "files.h" -#include "xalloc.h" #include "gram.h" #include "complain.h" @@ -34,11 +33,13 @@ struct obstack table_obstack; struct obstack defines_obstack; struct obstack guard_obstack; struct obstack output_obstack; -struct obstack graph_obstack; char *spec_outfile = NULL; /* for -o. */ char *spec_file_prefix = NULL; /* for -b. */ char *spec_name_prefix = NULL; /* for -p. */ +char *spec_verbose_file = NULL; /* for --verbose. */ +char *spec_graph_file = NULL; /* for -g. */ +char *spec_defines_file = NULL; /* for --defines. */ char *infile = NULL; char *attrsfile = NULL; @@ -93,24 +94,26 @@ stringappend (const char *string1, const char *string2) static char * compute_header_macro (void) { - int ite; - char *macro_name; + char *macro_name, *cp; - macro_name = XMALLOC (char, - strlen (base_name) + - strlen (header_extension) + 1); + if (spec_defines_file) + macro_name = xstrdup (spec_defines_file); + else + { + macro_name = XMALLOC (char, + strlen (base_name) + + strlen (header_extension) + 1); - stpcpy (macro_name, base_name); - strcat (macro_name, header_extension); + stpcpy (macro_name, base_name); + strcat (macro_name, header_extension); + } + + for (cp = macro_name; *cp; ++cp) + if (islower (*cp)) + *cp = toupper (*cp); + else if (!isalnum (*cp)) + *cp = '_'; - for (ite = 0; macro_name[ite]; ite++) - if (macro_name[ite] == '.') - macro_name[ite] = '_'; - else - { - if (islower (macro_name[ite])) - macro_name[ite] -= ('a' - 'A'); - } return macro_name; } @@ -194,17 +197,42 @@ skeleton_find (const char *envvar, const char *skeleton_name) { const char *res = getenv (envvar); -#ifdef MSDOS - const char *cp; - - /* File doesn't exist in current directory; try in INIT directory. */ - if (!res && (cp = getenv ("INIT"))) +#if defined (MSDOS) || defined (_WIN32) + if (!res) { - res = XMALLOC (char, strlen (cp) + strlen (skeleton_name) + 2); - sprintf (res, "%s%c%s", cp, '/', skeleton_name); + /* Skeleton file name without path */ + const char *skel_name = strrchr(skeleton_name, '/'); + if (!skel_name) + skel_name = strrchr(skeleton_name, '\\'); + if (!skel_name) + skel_name = skeleton_name; + else + ++skel_name; + + /* File doesn't exist in current directory; try in INIT directory. */ + const char *cp = getenv ("INIT"); + if (cp) + { + res = XMALLOC (char, strlen (cp) + strlen (skel_name) + 2); + sprintf (res, "%s%c%s", cp, '\\', skel_name); + } + else if (access (skel_name, 4) == 0) /* Look in current dir. */ + res = skel_name; + else + { + /* Look in program locations dir. */ + extern char *program_name; + cp = strrchr(program_name, '\\'); + if (!cp) + return skeleton_name; + else + ++cp; + res = XMALLOC (char, cp - program_name + strlen (skel_name) + 1); + strncpy (res, program_name, cp - program_name); + strcpy (res + (cp - program_name), skel_name); + } } -#endif /* !MSDOS */ - +#endif /* defined (MSDOS) || defined (_WIN32) */ if (!res) res = skeleton_name; @@ -260,20 +288,10 @@ get_extension_index (const char *filename) static void compute_exts_from_gf (const char *ext) { - /* Checks if SRC_EXTENSION is NULL. In the other case, %source_extension - was specified in the grammar file. */ - if (src_extension == NULL) - { - src_extension = tr (ext, 'y', 'c'); - src_extension = tr (src_extension, 'Y', 'C'); - } - /* Checks if HEADER_EXTENSION is NULL. In the other case, - %header_extension was specified in the grammar file. */ - if (header_extension == NULL) - { - header_extension = tr (ext, 'y', 'h'); - header_extension = tr (header_extension, 'Y', 'H'); - } + src_extension = tr (ext, 'y', 'c'); + src_extension = tr (src_extension, 'Y', 'C'); + header_extension = tr (ext, 'y', 'h'); + header_extension = tr (header_extension, 'Y', 'H'); } /* Computes extensions from the given c source file extension. */ @@ -395,6 +413,38 @@ compute_base_names (void) } } +/*-------------------------------------------------------. +| Close the open files, compute the output files names. | +`-------------------------------------------------------*/ + +void +compute_output_file_names (void) +{ + compute_base_names (); + + /* If not yet done. */ + if (!src_extension) + src_extension = ".c"; + if (!header_extension) + header_extension = ".h"; + + /* It the defines filename if not given, we create it. */ + if (!spec_defines_file) + spec_defines_file = stringappend (base_name, header_extension); + + /* It the graph filename if not given, we create it. */ + if (!spec_graph_file) + spec_graph_file = stringappend (short_base_name, ".vcg"); + + spec_verbose_file = stringappend (short_base_name, EXT_OUTPUT); + + attrsfile = stringappend (short_base_name, EXT_STYPE_H); +#ifndef MSDOS + attrsfile = stringappend (attrsfile, header_extension); +#endif /* MSDOS */ + +} + /*-----------------------------------------------------------------. | Open the input file. Look for the skeletons. Find the names of | | the output files. Prepare the obstacks. | @@ -412,46 +462,47 @@ open_files (void) obstack_init (&defines_obstack); obstack_init (&guard_obstack); obstack_init (&output_obstack); - obstack_init (&graph_obstack); } -/*-----------------------------------------------------. -| Close the open files, produce all the output files. | -`-----------------------------------------------------*/ +/*-----------------------. +| Close the open file.. | +`-----------------------*/ void -output_files (void) +close_files (void) { xfclose (finput); +} - compute_base_names (); - - /* Set default extensions */ - if (!src_extension) - src_extension = ".c"; - if (!header_extension) - header_extension = ".h"; - - attrsfile = stringappend (short_base_name, EXT_STYPE_H); -#ifndef MSDOS - stringappend (attrsfile, header_extension); -#endif /* MSDOS */ +/*---------------------------. +| Produce the output files. | +`---------------------------*/ +void +output_files (void) +{ /* Output the main file. */ if (spec_outfile) obstack_save (&table_obstack, spec_outfile); else obstack_save (&table_obstack, stringappend (base_name, src_extension)); + obstack_free (&table_obstack, NULL); /* Output the header file if wanted. */ if (defines_flag) - defines_obstack_save (stringappend (base_name, header_extension)); + defines_obstack_save (spec_defines_file); + obstack_free (&defines_obstack, NULL); + +#if 0 + /* Seems to be invalid now --akim. */ /* If we output only the table, dump the actions in ACTFILE. */ if (no_parser_flag) obstack_save (&action_obstack, stringappend (short_base_name, ".act")); + obstack_free (&action_obstack, NULL); +#endif /* If we produced a semantic parser ATTRS_OBSTACK must be dumped into its own file, ATTTRSFILE. */ @@ -460,19 +511,12 @@ output_files (void) char *temp_name; obstack_save (&attrs_obstack, attrsfile); + obstack_free (&attrs_obstack, NULL); temp_name = stringappend (short_base_name, EXT_GUARD_C); #ifndef MSDOS temp_name = stringappend (temp_name, src_extension); #endif /* MSDOS */ obstack_save (&guard_obstack, temp_name); + obstack_free (&guard_obstack, NULL); } - - if (verbose_flag) - /* We used to use just .out if spec_name_prefix (-p) was used, but - that conflicts with Posix. */ - obstack_save (&output_obstack, - stringappend (short_base_name, EXT_OUTPUT)); - - if (graph_flag) - obstack_save (&graph_obstack, stringappend (short_base_name, ".vcg")); } diff --git a/src/files.h b/src/files.h index 3c1b2f06..fa99d6aa 100644 --- a/src/files.h +++ b/src/files.h @@ -33,10 +33,19 @@ extern char *spec_name_prefix; /* File name pfx specified with -b, or 0 if no -b. */ extern char *spec_file_prefix; +/* --verbose. */ +extern char *spec_verbose_file; + +/* File name specified for the output VCG graph. */ +extern char *spec_graph_file; + +/* File name specified with --defines. */ +extern char *spec_defines_file; /* Read grammar specifications. */ extern FILE *finput; + /* Output all the action code; precise form depends on which parser. */ extern struct obstack action_obstack; @@ -56,17 +65,13 @@ extern struct obstack guard_obstack; /* The verbose output. */ extern struct obstack output_obstack; -/* The VCG graph output. */ -extern struct obstack graph_obstack; - extern char *infile; extern char *attrsfile; -extern const char *src_extension; -extern const char *header_extension; - void open_files PARAMS((void)); +void close_files PARAMS((void)); +void compute_output_file_names PARAMS((void)); void output_files PARAMS((void)); FILE *xfopen PARAMS ((const char *name, const char *mode)); diff --git a/src/getargs.c b/src/getargs.c index 7b0046a4..24b6d893 100644 --- a/src/getargs.c +++ b/src/getargs.c @@ -89,7 +89,9 @@ Output:\n\ -d, --defines also produce a header file\n\ -v, --verbose also produce an explanation of the automaton\n\ -b, --file-prefix=PREFIX specify a PREFIX for output files\n\ - -o, --output-file=FILE leave output to FILE\n"), stream); + -o, --output-file=FILE leave output to FILE\n\ + -g, --graph also produce a VCG graph description of the \ +automaton\n"), stream); putc ('\n', stream); fputs (_("\ @@ -153,7 +155,9 @@ getargs (int argc, char *argv[]) exit (0); case 'g': + /* Here, the -g and --graph=FILE options are differentiated. */ graph_flag = 1; + spec_graph_file = optarg; break; case 'v': @@ -165,7 +169,9 @@ getargs (int argc, char *argv[]) break; case 'd': + /* Here, the -d and --defines options are differentiated. */ defines_flag = 1; + spec_defines_file = optarg; break; case 'l': diff --git a/src/gram.c b/src/gram.c index 1e4ae70f..7016ab91 100644 --- a/src/gram.c +++ b/src/gram.c @@ -31,21 +31,19 @@ int nsyms; int ntokens; int nvars; -short *ritem; -short *rlhs; -short *rrhs; -short *rprec; -short *rprecsym; -short *sprec; -short *rassoc; -short *sassoc; -short *token_translations; -short *rline; +short *ritem = NULL; +short *rlhs = NULL; +short *rrhs = NULL; +short *rprec = NULL; +short *rprecsym = NULL; +short *sprec = NULL; +short *rassoc = NULL; +short *sassoc = NULL; +short *token_translations = NULL; +short *rline = NULL; int start_symbol; -int translations; - int max_user_token_number; int semantic_parser; diff --git a/src/gram.h b/src/gram.h index e270db5c..1691c858 100644 --- a/src/gram.h +++ b/src/gram.h @@ -107,13 +107,9 @@ typedef enum /* token translation table: indexed by a token number as returned by the user's yylex routine, it yields the internal token number used - by the parser and throughout bison. If translations is zero, the - translation table is not used because the two kinds of token - numbers are the same. (It is noted in reader.c that "Nowadays - translations is always set to 1...") */ + by the parser and throughout bison. */ extern short *token_translations; -extern int translations; extern int max_user_token_number; /* SEMANTIC_PARSER is nonzero if the input file says to use the hairy diff --git a/src/lalr.c b/src/lalr.c index 7e8aff70..48635ef3 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -26,7 +26,6 @@ #include "system.h" #include "types.h" #include "LR0.h" -#include "xalloc.h" #include "gram.h" #include "complain.h" #include "lalr.h" diff --git a/src/lex.c b/src/lex.c index c18042d4..4eb8f313 100644 --- a/src/lex.c +++ b/src/lex.c @@ -25,7 +25,6 @@ #include "symtab.h" #include "options.h" #include "lex.h" -#include "xalloc.h" #include "complain.h" #include "gram.h" #include "quote.h" @@ -37,15 +36,24 @@ const char *token_buffer = NULL; bucket *symval; int numval; -static int unlexed; /* these two describe a token to be reread */ -static bucket *unlexed_symval; /* by the next call to lex */ +/* these two describe a token to be reread */ +static token_t unlexed = tok_undef; +/* by the next call to lex */ +static bucket *unlexed_symval = NULL; void -init_lex (void) +lex_init (void) { obstack_init (&token_obstack); - unlexed = -1; + unlexed = tok_undef; +} + + +void +lex_free (void) +{ + obstack_free (&token_obstack, NULL); } @@ -314,7 +322,7 @@ literalchar (struct obstack *out, int *pcode, char term) void -unlex (int token) +unlex (token_t token) { unlexed = token; unlexed_symval = symval; @@ -357,12 +365,12 @@ lex (void) /* Just to make sure. */ token_buffer = NULL; - if (unlexed >= 0) + if (unlexed != tok_undef) { + token_t res = unlexed; symval = unlexed_symval; - c = unlexed; - unlexed = -1; - return c; + unlexed = tok_undef; + return res; } c = skip_white_space (); @@ -418,7 +426,6 @@ lex (void) case '\'': /* parse the literal token and compute character code in code */ - translations = -1; { int code, discode; @@ -446,7 +453,6 @@ lex (void) case '\"': /* parse the literal string token and treat as an identifier */ - translations = -1; { int code; /* ignored here */ @@ -464,32 +470,40 @@ lex (void) } case ',': + token_buffer = ","; return tok_comma; case ':': + token_buffer = ":"; return tok_colon; case ';': + token_buffer = ";"; return tok_semicolon; case '|': + token_buffer = "|"; return tok_bar; case '{': + token_buffer = "{"; return tok_left_curly; case '=': + obstack_1grow (&token_obstack, c); do { c = getc (finput); + obstack_1grow (&token_obstack, c); if (c == '\n') lineno++; } while (c == ' ' || c == '\n' || c == '\t'); + obstack_1grow (&token_obstack, '\0'); + token_buffer = obstack_finish (&token_obstack); if (c == '{') { - token_buffer = "={"; return tok_left_curly; } else @@ -506,6 +520,9 @@ lex (void) return parse_percent_token (); default: + obstack_1grow (&token_obstack, c); + obstack_1grow (&token_obstack, '\0'); + token_buffer = obstack_finish (&token_obstack); return tok_illegal; } } @@ -516,28 +533,28 @@ lex (void) static int option_strcmp (const char *left, const char *right) { - const unsigned char *l, *r; - int c; - - assert(left != NULL && right != NULL); - l = (const unsigned char *)left; - r = (const unsigned char *)right; - while (((c = *l - *r++) == 0 && *l != '\0') - || ((*l == '-' || *l == '_') && (*r == '_' || *r == '-'))) - l++; - return c; + const unsigned char *l, *r; + int c; + + assert (left); + assert (right); + l = (const unsigned char *)left; + r = (const unsigned char *)right; + while (((c = *l - *r++) == 0 && *l != '\0') + || ((*l == '-' || *l == '_') && (*r == '_' || *r == '-'))) + l++; + return c; } /* Parse a token which starts with %. Assumes the % has already been read and discarded. */ -int +token_t parse_percent_token (void) { - int c; const struct option_table_struct *tx; - c = getc (finput); + int c = getc (finput); switch (c) { @@ -601,6 +618,10 @@ parse_percent_token (void) case tok_obsolete: fatal (_("`%s' is no longer supported"), token_buffer); break; + + default: + /* Other cases do not apply here. */ + break; } return tx->ret_val; diff --git a/src/lex.h b/src/lex.h index 8721e9a8..cb5a75e8 100644 --- a/src/lex.h +++ b/src/lex.h @@ -24,6 +24,7 @@ /* Token-type codes. */ typedef enum token_e { + tok_undef, /* Not defined. Used to initial token_t vars. */ tok_eof, tok_identifier, tok_comma, @@ -47,8 +48,6 @@ typedef enum token_e tok_number, tok_expect, tok_thong, - tok_hdrext, - tok_srcext, tok_define, tok_skel, tok_noop, @@ -61,9 +60,10 @@ extern const char *token_buffer; extern bucket *symval; extern int numval; -void init_lex PARAMS ((void)); +void lex_init PARAMS ((void)); +void lex_free PARAMS ((void)); int skip_white_space PARAMS ((void)); -void unlex PARAMS ((int)); +void unlex PARAMS ((token_t)); void read_type_name PARAMS ((FILE *fin)); /* Return one of the token-type codes. When an identifier is seen, @@ -73,6 +73,6 @@ void read_type_name PARAMS ((FILE *fin)); token_t lex PARAMS ((void)); -int parse_percent_token PARAMS ((void)); +token_t parse_percent_token PARAMS ((void)); #endif /* !LEX_H_ */ diff --git a/src/main.c b/src/main.c index 6dfffbeb..9cea3ff4 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ /* Top level entry point of bison, - Copyright 1984, 1986, 1989, 1992, 1995, 2000 + Copyright 1984, 1986, 1989, 1992, 1995, 2000, 2001 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -35,6 +35,8 @@ #include "conflicts.h" #include "print_graph.h" #include "muscle_tab.h" +#include "symtab.h" +#include "lex.h" /* The name this program was run with, for messages. */ char *program_name; @@ -81,7 +83,15 @@ main (int argc, char *argv[]) lookahead is not enough to disambiguate the parsing. In file conflicts. Also resolve s/r conflicts based on precedence declarations. */ - initialize_conflicts (); + solve_conflicts (); + + /* Output file names. */ + compute_output_file_names (); + + /* Stop if there were errors, to avoid trashing previous output + files. */ + if (complain_message_count) + exit (1); /* Print information about results, if requested. */ print_results (); @@ -92,12 +102,19 @@ main (int argc, char *argv[]) /* Output the tables and the parser to ftable. In file output. */ output (); - finalize_conflicts (); + /* Free the symbol table data structure. */ + free_symtab (); + + lex_free (); + + /* Close the input files. */ + close_files (); + + free_conflicts (); free_nullable (); free_derives (); - if (!complain_message_count) - output_files (); + output_files (); exit (complain_message_count ? 1 : 0); } diff --git a/src/nullable.c b/src/nullable.c index 7240132f..33654918 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -26,7 +26,6 @@ #include "system.h" #include "types.h" #include "gram.h" -#include "xalloc.h" #include "nullable.h" char *nullable = NULL; diff --git a/src/options.c b/src/options.c index 5d626247..c09ef0a5 100644 --- a/src/options.c +++ b/src/options.c @@ -45,7 +45,7 @@ const struct option_table_struct option_table[] = /* Operation modes. */ {opt_cmd_line, "help", no_argument, 0, 0, 'h'}, {opt_cmd_line, "version", no_argument, 0, 0, 'V'}, - + /* Parser. */ /* was 'a'; apparently unused -wjh */ {opt_cmd_line, "name-prefix", required_argument, 0, 0, 'p'}, @@ -53,7 +53,7 @@ const struct option_table_struct option_table[] = /* Output. */ {opt_cmd_line, "file-prefix", required_argument, 0, 0, 'b'}, {opt_cmd_line, "output-file", required_argument, 0, 0, 'o'}, - {opt_cmd_line, "graph", no_argument, 0, 0, 'g'}, + {opt_cmd_line, "graph", optional_argument, 0, 0, 'g'}, /* Hidden. */ {opt_cmd_line, "statistics", no_argument, &statistics_flag, 0, 1}, @@ -86,8 +86,6 @@ const struct option_table_struct option_table[] = {opt_both, "file-prefix", required_argument,&spec_file_prefix,tok_setopt,'b'}, {opt_both, "name-prefix", required_argument,&spec_name_prefix,tok_setopt,'p'}, #endif - {opt_percent, "header-extension", 0, NULL, tok_hdrext, 0}, - {opt_percent, "source-extension", 0, NULL, tok_srcext, 0}, {opt_percent, "define", 0, NULL, tok_define, 0}, {opt_percent, "semantic-parser", 0, &semantic_parser, tok_noop, 0}, {opt_percent, "pure-parser", 0, &pure_parser, tok_noop, 0}, @@ -97,11 +95,11 @@ const struct option_table_struct option_table[] = */ /* FIXME Usually option use `-' to separe words on command line - and `_' for percent option. But here the separator are always + and `_' for percent option. But here the separator are always the same, the char `-'. */ /* Output. */ - {opt_both, "defines", no_argument, &defines_flag, tok_noop, 'd'}, + {opt_both, "defines", optional_argument, &defines_flag, tok_noop, 'd'}, {opt_both, "verbose", no_argument, &verbose_flag, tok_noop, 'v'}, /* Operation modes. */ @@ -109,7 +107,7 @@ const struct option_table_struct option_table[] = {opt_both, "yacc", no_argument, &yacc_flag, tok_noop, 'y'}, /* Parser. */ - {opt_both, "debug", no_argument, &debug_flag, tok_noop, 'd'}, + {opt_both, "debug", no_argument, &debug_flag, tok_noop, 't'}, {opt_both, "locations", no_argument, &locations_flag, tok_noop, 1}, {opt_both, "no-lines", no_argument, &no_lines_flag, tok_noop, 'l'}, {opt_both, "no-parser", no_argument, &no_parser_flag, tok_noop, 'n'}, diff --git a/src/output.c b/src/output.c index 2e797250..953f7017 100644 --- a/src/output.c +++ b/src/output.c @@ -94,7 +94,6 @@ #include "obstack.h" #include "quotearg.h" #include "getargs.h" -#include "xalloc.h" #include "files.h" #include "gram.h" #include "LR0.h" @@ -109,17 +108,17 @@ extern void berror PARAMS((const char *)); static int nvectors; static int nentries; -static short **froms; -static short **tos; -static short *tally; -static short *width; -static short *actrow; -static short *state_count; -static short *order; -static short *base; -static short *pos; -static short *table; -static short *check; +static short **froms = NULL; +static short **tos = NULL; +static short *tally = NULL; +static short *width = NULL; +static short *actrow = NULL; +static short *state_count = NULL; +static short *order = NULL; +static short *base = NULL; +static short *pos = NULL; +static short *table = NULL; +static short *check = NULL; static int lowzero; static int high; @@ -129,15 +128,15 @@ struct obstack output_obstack; /* FIXME. */ static inline void -output_table_data (struct obstack *oout, - short *table_data, - short first, - short begin, +output_table_data (struct obstack *oout, + short *table_data, + short first, + short begin, short end) { int i; int j = 1; - + obstack_fgrow1 (oout, "%6d", first); for (i = begin; i < end; ++i) { @@ -158,19 +157,20 @@ output_table_data (struct obstack *oout, static void output_token_translations (void) { - output_table_data (&output_obstack, token_translations, + output_table_data (&output_obstack, token_translations, 0, 1, max_user_token_number + 1); muscle_insert ("translate", obstack_finish (&output_obstack)); + XFREE (token_translations); } static void output_gram (void) { - output_table_data (&output_obstack, rrhs, + output_table_data (&output_obstack, rrhs, 0, 1, nrules + 1); muscle_insert ("prhs", obstack_finish (&output_obstack)); - + { size_t yyrhs_size = 1; short *yyrhs, *sp; @@ -183,7 +183,7 @@ output_gram (void) for (sp = ritem + 1, i = 1; *sp; ++sp, ++i) yyrhs[i] = *sp > 0 ? *sp : 0; - output_table_data (&output_obstack, yyrhs, + output_table_data (&output_obstack, yyrhs, ritem[0], 1, yyrhs_size); muscle_insert ("rhs", obstack_finish (&output_obstack)); @@ -200,7 +200,7 @@ output_gram (void) static void output_stos (void) { - output_table_data (&output_obstack, accessing_symbol, + output_table_data (&output_obstack, accessing_symbol, 0, 1, nstates); muscle_insert ("stos", obstack_finish (&output_obstack)); } @@ -275,7 +275,7 @@ output_rule_data (void) muscle_insert ("toknum", obstack_finish (&output_obstack)); /* Output YYR1. */ - output_table_data (&output_obstack, rlhs, + output_table_data (&output_obstack, rlhs, 0, 1, nrules + 1); muscle_insert ("r1", obstack_finish (&output_obstack)); XFREE (rlhs + 1); @@ -285,7 +285,7 @@ output_rule_data (void) for (i = 1; i < nrules; i++) short_tab[i] = rrhs[i + 1] - rrhs[i] - 1; short_tab[nrules] = nitems - rrhs[nrules] - 1; - output_table_data (&output_obstack, short_tab, + output_table_data (&output_obstack, short_tab, 0, 1, nrules + 1); muscle_insert ("r2", obstack_finish (&output_obstack)); XFREE (short_tab); @@ -534,10 +534,10 @@ token_actions (void) save_row (i); } - output_table_data (&output_obstack, yydefact, + output_table_data (&output_obstack, yydefact, yydefact[0], 1, nstates); muscle_insert ("defact", obstack_finish (&output_obstack)); - + XFREE (actrow); XFREE (yydefact); } @@ -675,7 +675,7 @@ goto_actions (void) yydefgoto[i - ntokens] = default_state; } - output_table_data (&output_obstack, yydefgoto, + output_table_data (&output_obstack, yydefgoto, yydefgoto[0], 1, nsyms - ntokens); muscle_insert ("defgoto", obstack_finish (&output_obstack)); @@ -880,12 +880,12 @@ static void output_base (void) { /* Output pact. */ - output_table_data (&output_obstack, base, + output_table_data (&output_obstack, base, base[0], 1, nstates); muscle_insert ("pact", obstack_finish (&output_obstack)); /* Output pgoto. */ - output_table_data (&output_obstack, base, + output_table_data (&output_obstack, base, base[nstates], nstates + 1, nvectors); muscle_insert ("pgoto", obstack_finish (&output_obstack)); @@ -896,7 +896,7 @@ output_base (void) static void output_table (void) { - output_table_data (&output_obstack, table, + output_table_data (&output_obstack, table, table[0], 1, high + 1); muscle_insert ("table", obstack_finish (&output_obstack)); XFREE (table); @@ -906,7 +906,7 @@ output_table (void) static void output_check (void) { - output_table_data (&output_obstack, check, + output_table_data (&output_obstack, check, check[0], 1, high + 1); muscle_insert ("check", obstack_finish (&output_obstack)); XFREE (check); @@ -1109,7 +1109,7 @@ output (void) output_stos (); output_rule_data (); output_actions (); - + #if 0 if (!no_parser_flag) */ #endif diff --git a/src/print.c b/src/print.c index a5be5737..ccafbdc6 100644 --- a/src/print.c +++ b/src/print.c @@ -20,7 +20,6 @@ #include "system.h" -#include "xalloc.h" #include "files.h" #include "gram.h" #include "LR0.h" @@ -35,17 +34,17 @@ static void print_token (int extnum, int token) { - obstack_fgrow2 (&output_obstack, _(" type %d is %s\n"), extnum, tags[token]); + fprintf (out, _(" type %d is %s\n"), extnum, tags[token]); } #endif -/*================================\ +/*--------------------------------. | Report information on a state. | -\================================*/ +`--------------------------------*/ static void -print_core (int state) +print_core (FILE *out, int state) { int i; int k; @@ -68,30 +67,30 @@ print_core (int state) sp++; rule = -(*sp); - obstack_fgrow1 (&output_obstack, " %s -> ", tags[rlhs[rule]]); + fprintf (out, " %s -> ", tags[rlhs[rule]]); for (sp = ritem + rrhs[rule]; sp < sp1; sp++) { - obstack_fgrow1 (&output_obstack, "%s ", tags[*sp]); + fprintf (out, "%s ", tags[*sp]); } - obstack_1grow (&output_obstack, '.'); + fputc ('.', out); while (*sp > 0) { - obstack_fgrow1 (&output_obstack, " %s", tags[*sp]); + fprintf (out, " %s", tags[*sp]); sp++; } - obstack_fgrow1 (&output_obstack, _(" (rule %d)"), rule); - obstack_1grow (&output_obstack, '\n'); + fprintf (out, _(" (rule %d)"), rule); + fputc ('\n', out); } - obstack_1grow (&output_obstack, '\n'); + fputc ('\n', out); } static void -print_actions (int state) +print_actions (FILE *out, int state) { int i; int k; @@ -109,9 +108,9 @@ print_actions (int state) if (!shiftp && !redp) { if (final_state == state) - obstack_sgrow (&output_obstack, _(" $default\taccept\n")); + fprintf (out, _(" $default\taccept\n")); else - obstack_sgrow (&output_obstack, _(" NO ACTIONS\n")); + fprintf (out, _(" NO ACTIONS\n")); return; } @@ -129,16 +128,16 @@ print_actions (int state) if (ISVAR (symbol)) break; if (symbol == 0) /* I.e. strcmp(tags[symbol],"$")==0 */ - obstack_fgrow1 (&output_obstack, - _(" $ \tgo to state %d\n"), state1); + fprintf (out, + _(" $ \tgo to state %d\n"), state1); else - obstack_fgrow2 (&output_obstack, - _(" %-4s\tshift, and go to state %d\n"), - tags[symbol], state1); + fprintf (out, + _(" %-4s\tshift, and go to state %d\n"), + tags[symbol], state1); } if (i > 0) - obstack_1grow (&output_obstack, '\n'); + fputc ('\n', out); } else { @@ -157,21 +156,20 @@ print_actions (int state) if (!errp->errs[j]) continue; symbol = errp->errs[j]; - obstack_fgrow1 (&output_obstack, _(" %-4s\terror (nonassociative)\n"), + fprintf (out, _(" %-4s\terror (nonassociative)\n"), tags[symbol]); } if (j > 0) - obstack_1grow (&output_obstack, '\n'); + fputc ('\n', out); } if (consistent[state] && redp) { rule = redp->rules[0]; symbol = rlhs[rule]; - obstack_fgrow2 (&output_obstack, - _(" $default\treduce using rule %d (%s)\n\n"), - rule, tags[symbol]); + fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"), + rule, tags[symbol]); } else if (redp) { @@ -186,42 +184,41 @@ print_actions (int state) continue; state1 = shiftp->shifts[i]; symbol = accessing_symbol[state1]; - obstack_fgrow2 (&output_obstack, - _(" %-4s\tgo to state %d\n"), - tags[symbol], state1); + fprintf (out, _(" %-4s\tgo to state %d\n"), + tags[symbol], state1); } - obstack_1grow (&output_obstack, '\n'); + fputc ('\n', out); } } static void -print_state (int state) +print_state (FILE *out, int state) { - obstack_sgrow (&output_obstack, "\n\n"); - obstack_fgrow1 (&output_obstack, _("state %d"), state); - obstack_sgrow (&output_obstack, "\n\n"); - print_core (state); - print_actions (state); + fputs ("\n\n", out); + fprintf (out, _("state %d"), state); + fputs ("\n\n", out); + print_core (out, state); + print_actions (out, state); } /*-----------------------------------------. | Print information on the whole grammar. | `-----------------------------------------*/ -#define END_TEST(End) \ -do { \ - if (column + strlen(buffer) > (End)) \ - { \ - obstack_fgrow1 (&output_obstack, "%s\n ", buffer); \ - column = 3; \ - buffer[0] = 0; \ - } \ +#define END_TEST(End) \ +do { \ + if (column + strlen(buffer) > (End)) \ + { \ + fprintf (out, "%s\n ", buffer); \ + column = 3; \ + buffer[0] = 0; \ + } \ } while (0) static void -print_grammar (void) +print_grammar (FILE *out) { int i, j; short *rule; @@ -229,78 +226,46 @@ print_grammar (void) int column = 0; /* rule # : LHS -> RHS */ - obstack_1grow (&output_obstack, '\n'); - obstack_sgrow (&output_obstack, _("Grammar")); - obstack_1grow (&output_obstack, '\n'); + fprintf (out, "\n%s\n", _("Grammar")); for (i = 1; i <= nrules; i++) /* Don't print rules disabled in reduce_grammar_tables. */ if (rlhs[i] >= 0) { - obstack_fgrow2 (&output_obstack, - _("rule %-4d %s ->"), i, tags[rlhs[i]]); + fprintf (out, _("rule %-4d %s ->"), i, tags[rlhs[i]]); rule = &ritem[rrhs[i]]; if (*rule > 0) while (*rule > 0) - obstack_fgrow1 (&output_obstack, " %s", tags[*rule++]); + fprintf (out, " %s", tags[*rule++]); else - obstack_sgrow (&output_obstack, _(" /* empty */")); - obstack_1grow (&output_obstack, '\n'); + fprintf (out, " /* %s */\n", _("empty")); } /* TERMINAL (type #) : rule #s terminal is on RHS */ - obstack_sgrow (&output_obstack, "\n"); - obstack_sgrow (&output_obstack, - _("Terminals, with rules where they appear")); - obstack_sgrow (&output_obstack, "\n\n"); - obstack_fgrow1 (&output_obstack, "%s (-1)\n", tags[0]); - if (translations) - { - for (i = 0; i <= max_user_token_number; i++) - if (token_translations[i] != 2) - { - buffer[0] = 0; - column = strlen (tags[token_translations[i]]); - obstack_sgrow (&output_obstack, tags[token_translations[i]]); - END_TEST (50); - sprintf (buffer, " (%d)", i); - - for (j = 1; j <= nrules; j++) - for (rule = &ritem[rrhs[j]]; *rule > 0; rule++) - if (*rule == token_translations[i]) - { - END_TEST (65); - sprintf (buffer + strlen (buffer), " %d", j); - break; - } - obstack_fgrow1 (&output_obstack, "%s\n", buffer); - } - } - else - { - for (i = 1; i < ntokens; i++) - { - buffer[0] = 0; - column = strlen (tags[i]); - obstack_sgrow (&output_obstack, tags[i]); - END_TEST (50); - sprintf (buffer, " (%d)", i); + fprintf (out, "\n%s\n\n", _("Terminals, with rules where they appear")); + fprintf (out, "%s (-1)\n", tags[0]); - for (j = 1; j <= nrules; j++) - for (rule = &ritem[rrhs[j]]; *rule > 0; rule++) - if (*rule == i) - { - END_TEST (65); - sprintf (buffer + strlen (buffer), " %d", j); - break; - } - obstack_fgrow1 (&output_obstack, "%s\n", buffer); - } - } + for (i = 0; i <= max_user_token_number; i++) + if (token_translations[i] != 2) + { + buffer[0] = 0; + column = strlen (tags[token_translations[i]]); + fputs (tags[token_translations[i]], out); + END_TEST (50); + sprintf (buffer, " (%d)", i); - obstack_sgrow (&output_obstack, "\n"); - obstack_sgrow (&output_obstack, - _("Nonterminals, with rules where they appear")); - obstack_sgrow (&output_obstack, "\n\n"); + for (j = 1; j <= nrules; j++) + for (rule = &ritem[rrhs[j]]; *rule > 0; rule++) + if (*rule == token_translations[i]) + { + END_TEST (65); + sprintf (buffer + strlen (buffer), " %d", j); + break; + } + fprintf (out, "%s\n", buffer); + } + + fprintf (out, "\n%s\n\n", + _("Nonterminals, with rules where they appear")); for (i = ntokens; i <= nsyms - 1; i++) { int left_count = 0, right_count = 0; @@ -318,7 +283,7 @@ print_grammar (void) } buffer[0] = 0; - obstack_sgrow (&output_obstack, tags[i]); + fputs (tags[i], out); column = strlen (tags[i]); sprintf (buffer, " (%d)", i); END_TEST (0); @@ -353,22 +318,33 @@ print_grammar (void) } } } - obstack_fgrow1 (&output_obstack, "%s\n", buffer); + fprintf (out, "%s\n", buffer); } } void print_results (void) { - int i; + if (verbose_flag) + { + int i; - if (any_conflicts) - print_conflicts (); + /* We used to use just .out if spec_name_prefix (-p) was used, but + that conflicts with Posix. */ + FILE *out = xfopen (spec_verbose_file, "w"); - if (verbose_flag) - print_grammar (); + size_t size = obstack_object_size (&output_obstack); + fwrite (obstack_finish (&output_obstack), 1, size, out); - if (verbose_flag) - for (i = 0; i < nstates; i++) - print_state (i); + if (any_conflicts) + print_conflicts (out); + + print_grammar (out); + + for (i = 0; i < nstates; i++) + print_state (out, i); + + xfclose (out); + } + obstack_free (&output_obstack, NULL); } diff --git a/src/print_graph.c b/src/print_graph.c index 5dca0920..a00434db 100644 --- a/src/print_graph.c +++ b/src/print_graph.c @@ -19,7 +19,6 @@ Boston, MA 02111-1307, USA. */ #include "system.h" -#include "xalloc.h" #include "files.h" #include "gram.h" #include "LR0.h" @@ -35,8 +34,9 @@ #include "quotearg.h" static graph_t graph; +static FILE *fgraph = NULL; -static unsigned node_output_size = 0; +static size_t node_output_size = 0; /* Return an unambiguous printable representated, allocated in slot 0, for NAME, suitable for C strings. */ @@ -136,7 +136,7 @@ print_actions (int state, const char *node_name, struct obstack *node_obstack) if (state > state1) edge.type = back_edge; - open_edge (&edge, &graph_obstack); + open_edge (&edge, fgraph); /* The edge source is the current node. */ edge.sourcename = node_name; sprintf (buff, "%d", state1); @@ -145,8 +145,8 @@ print_actions (int state, const char *node_name, struct obstack *node_obstack) /* FIXME: Be aware that quote uses static memory. The string must be output immediately (which is the case here). */ edge.label = tags[symbol] ? quote (tags[symbol]) : NULL; - output_edge (&edge, &graph_obstack); - close_edge (&graph_obstack); + output_edge (&edge, fgraph); + close_edge (fgraph); } } } @@ -198,14 +198,14 @@ print_actions (int state, const char *node_name, struct obstack *node_obstack) symbol = accessing_symbol[state1]; new_edge (&edge); - open_edge (&edge, &graph_obstack); + open_edge (&edge, fgraph); edge.sourcename = node_name; sprintf (buff, "%d", state1); edge.targetname = buff; edge.color = red; edge.label = tags[symbol] ? quote (tags[symbol]) : NULL; - output_edge (&edge, &graph_obstack); - close_edge (&graph_obstack); + output_edge (&edge, fgraph); + close_edge (fgraph); } } } @@ -223,9 +223,6 @@ print_state (int state) new_node (&node); /* Set node attributs default value. */ sprintf (name, "%d", state); node.title = name; /* Give a name to the node. */ - open_node (&node_obstack); - /* Output a VCG formatted attributs list. */ - output_node (&node, &node_obstack); { /* Here we begin to compute the node label. */ @@ -241,15 +238,17 @@ print_state (int state) print_actions (state, node.title, &node_obstack); obstack_sgrow (&node_obstack, "\"\n"); /* Close Label. */ - - close_node (&node_obstack); - } - - /* `obstack_cat' NODE_OBSTACK to GRAPH_OBSTACK. */ - obstack_grow (&graph_obstack, - obstack_base (&node_obstack), - obstack_object_size (&node_obstack)); - obstack_finish (&node_obstack); + } + + open_node (fgraph); + /* Output a VCG formatted attributs list. */ + output_node (&node, fgraph); + /* Save the node label. */ + fwrite (obstack_base (&node_obstack), + obstack_object_size (&node_obstack), 1, fgraph); + close_node (fgraph); + + obstack_free (&node_obstack, 0); } @@ -257,9 +256,13 @@ void print_graph (void) { int i; - + if (!graph_flag) return; + + /* Output file. */ + fgraph = xfopen (spec_graph_file, "w"); + new_graph (&graph); #if 0 @@ -268,7 +271,7 @@ print_graph (void) #endif graph.display_edge_labels = yes; - graph.layoutalgorithm = 0; + graph.layoutalgorithm = normal; graph.port_sharing = no; graph.finetuning = yes; @@ -279,13 +282,14 @@ print_graph (void) graph.crossing_weight = median; /* Output graph options. */ - open_graph (&graph_obstack); - output_graph (&graph, &graph_obstack); + open_graph (fgraph); + output_graph (&graph, fgraph); for (i = 0; i < nstates; i++) /* Output nodes & edges. */ print_state (i); /* Close graph. */ - close_graph (&graph, &graph_obstack); + close_graph (&graph, fgraph); + xfclose (fgraph); } diff --git a/src/reader.c b/src/reader.c index 35e08501..69619358 100644 --- a/src/reader.c +++ b/src/reader.c @@ -26,7 +26,6 @@ #include "quote.h" #include "getargs.h" #include "files.h" -#include "xalloc.h" #include "symtab.h" #include "options.h" #include "lex.h" @@ -431,7 +430,7 @@ copy_definition (void) if (!no_lines_flag) { obstack_fgrow2 (&attrs_obstack, muscle_find ("linef"), - lineno, quotearg_style (c_quoting_style, + lineno, quotearg_style (c_quoting_style, muscle_find("filename"))); } #endif @@ -491,8 +490,8 @@ copy_definition (void) static void parse_token_decl (symbol_class what_is, symbol_class what_is_not) { - token_t token = 0; - char *typename = 0; + token_t token = tok_undef; + char *typename = NULL; /* The symbol being defined. */ struct bucket *symbol = NULL; @@ -541,7 +540,6 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not) /* symbol and symval combined are only one symbol */ nsyms--; } - translations = 1; symbol = NULL; } else if (token == tok_identifier) @@ -566,7 +564,6 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not) else if (symbol && token == tok_number) { symbol->user_token_number = numval; - translations = 1; } else { @@ -708,7 +705,6 @@ parse_assoc_decl (associativity assoc) if (prev == tok_identifier) { symval->user_token_number = numval; - translations = 1; } else { @@ -754,7 +750,7 @@ parse_union_decl (void) if (no_lines_flag) obstack_1grow (&attrs_obstack, '\n'); - + obstack_init (&union_obstack); obstack_sgrow (&union_obstack, "union"); if (defines_flag) @@ -764,9 +760,13 @@ parse_union_decl (void) while (c != EOF) { - obstack_1grow (&union_obstack, c); - if (defines_flag) - obstack_1grow (&defines_obstack, c); + /* If C contains '/', it is output by copy_comment (). */ + if (c != '/') + { + obstack_1grow (&attrs_obstack, c); + if (defines_flag) + obstack_1grow (&defines_obstack, c); + } switch (c) { @@ -852,7 +852,6 @@ parse_thong_decl (void) char *typename = 0; int usrtoknum; - translations = 1; token = lex (); /* fetch typename or first token */ if (token == tok_typename) { @@ -904,8 +903,6 @@ parse_thong_decl (void) nsyms--; } -/* FIXME. */ - static void parse_muscle_decl (void) { @@ -923,7 +920,7 @@ parse_muscle_decl (void) copy_identifier (finput, &muscle_obstack); obstack_1grow (&muscle_obstack, 0); muscle_key = obstack_finish (&muscle_obstack); - + /* Read value. */ ch = skip_white_space (); if (ch != '"') @@ -957,36 +954,6 @@ parse_skel_decl (void) /* Complete with parse_dquoted_param () on the CVS branch 1.29. */ } -/*------------------------------------------. -| Parse what comes after %header_extension. | -`------------------------------------------*/ - -static void -parse_header_extension_decl (void) -{ - char buff[32]; - - if (header_extension) - complain (_("multiple %%header_extension declarations")); - fscanf (finput, "%s", buff); - header_extension = xstrdup (buff); -} - -/*------------------------------------------. -| Parse what comes after %source_extension. | -`------------------------------------------*/ - -static void -parse_source_extension_decl (void) -{ - char buff[32]; - - if (src_extension) - complain (_("multiple %%source_extension declarations")); - fscanf (finput, "%s", buff); - src_extension = xstrdup (buff); -} - /*----------------------------------------------------------------. | Read from finput until `%%' is seen. Discard the `%%'. Handle | | any `%' declarations, and copy the contents of any `%{ ... %}' | @@ -1056,18 +1023,10 @@ read_declarations (void) parse_assoc_decl (non_assoc); break; - case tok_hdrext: - parse_header_extension_decl (); - break; - - case tok_srcext: - parse_source_extension_decl (); - break; - case tok_define: parse_muscle_decl (); break; - + case tok_skel: parse_skel_decl (); break; @@ -1115,7 +1074,7 @@ copy_action (symbol_list *rule, int stack_offset) if (!no_lines_flag) { obstack_fgrow2 (&action_obstack, muscle_find ("linef"), - lineno, quotearg_style (c_quoting_style, + lineno, quotearg_style (c_quoting_style, muscle_find ("filename"))); } obstack_1grow (&action_obstack, '{'); @@ -1678,12 +1637,12 @@ read_additionnal_code (void) { char c; struct obstack el_obstack; - + obstack_init (&el_obstack); while ((c = getc (finput)) != EOF) obstack_1grow (&el_obstack, c); - + obstack_1grow (&el_obstack, 0); muscle_insert ("epilogue", obstack_finish (&el_obstack)); } @@ -1729,9 +1688,10 @@ output_token_defines (struct obstack *oout) continue; obstack_fgrow2 (oout, "# define\t%s\t%d\n", - symbol, - (translations ? bp->user_token_number : bp->value)); + symbol, bp->user_token_number); if (semantic_parser) + /* FIXME: This is certainly dead wrong, and should be just as + above. --akim. */ obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value); } } @@ -1746,9 +1706,9 @@ output_token_defines (struct obstack *oout) static void packsymbols (void) { - bucket *bp; + bucket *bp = NULL; int tokno = 1; - int i; + int i, j; int last_user_token_number; static char DOLLAR[] = "$"; @@ -1812,7 +1772,7 @@ packsymbols (void) if (bp->class == token_sym) { - if (translations && !(bp->user_token_number)) + if (!bp->user_token_number) bp->user_token_number = ++last_user_token_number; if (bp->user_token_number > max_user_token_number) max_user_token_number = bp->user_token_number; @@ -1822,40 +1782,39 @@ packsymbols (void) user_toknums[bp->value] = bp->user_token_number; sprec[bp->value] = bp->prec; sassoc[bp->value] = bp->assoc; - } - if (translations) - { - int j; + token_translations = XCALLOC (short, max_user_token_number + 1); - token_translations = XCALLOC (short, max_user_token_number + 1); + /* initialize all entries for literal tokens to 2, the internal + token number for $undefined., which represents all invalid + inputs. */ + for (j = 0; j <= max_user_token_number; j++) + token_translations[j] = 2; - /* initialize all entries for literal tokens to 2, the internal - token number for $undefined., which represents all invalid - inputs. */ - for (j = 0; j <= max_user_token_number; j++) - token_translations[j] = 2; - - for (bp = firstsymbol; bp; bp = bp->next) - { - if (bp->value >= ntokens) - continue; /* non-terminal */ - if (bp->user_token_number == SALIAS) - continue; - if (token_translations[bp->user_token_number] != 2) - complain (_("tokens %s and %s both assigned number %d"), - tags[token_translations[bp->user_token_number]], - bp->tag, bp->user_token_number); - token_translations[bp->user_token_number] = bp->value; - } + for (bp = firstsymbol; bp; bp = bp->next) + { + if (bp->value >= ntokens) + continue; /* non-terminal */ + if (bp->user_token_number == SALIAS) + continue; + if (token_translations[bp->user_token_number] != 2) + complain (_("tokens %s and %s both assigned number %d"), + tags[token_translations[bp->user_token_number]], + bp->tag, bp->user_token_number); + token_translations[bp->user_token_number] = bp->value; } error_token_number = errtoken->value; - output_token_defines (&output_obstack); - obstack_1grow (&output_obstack, 0); - muscle_insert ("tokendef", obstack_finish (&output_obstack)); + { + struct obstack tokendefs; + obstack_init (&tokendefs); + output_token_defines (&tokendefs); + obstack_1grow (&tokendefs, 0); + muscle_insert ("tokendef", xstrdup (obstack_finish (&tokendefs))); + obstack_free (&tokendefs, NULL); + } #if 0 if (!no_parser_flag) @@ -1980,15 +1939,6 @@ reader (void) start_flag = 0; startval = NULL; /* start symbol not specified yet. */ -#if 0 - /* initially assume token number translation not needed. */ - translations = 0; -#endif - /* Nowadays translations is always set to 1, since we give `error' a - user-token-number to satisfy the Posix demand for YYERRCODE==256. - */ - translations = 1; - nsyms = 1; nvars = 0; nrules = 0; @@ -2004,7 +1954,7 @@ reader (void) grammar = NULL; - init_lex (); + lex_init (); lineno = 1; /* Initialize the muscle obstack. */ @@ -2043,7 +1993,4 @@ reader (void) packsymbols (); /* Convert the grammar into the format described in gram.h. */ packgram (); - /* Free the symbol table data structure since symbols are now all - referred to by symbol number. */ - free_symtab (); } diff --git a/src/reduce.c b/src/reduce.c index c5be01fe..b2299b33 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -29,7 +29,6 @@ #include "getargs.h" #include "files.h" #include "gram.h" -#include "xalloc.h" #include "complain.h" #include "reduce.h" #include "reader.h" @@ -117,7 +116,7 @@ static void useless_nonterminals (void) { BSet Np, Ns; - int i, n; + int i; /* N is set as built. Np is set being built this iteration. P is set of all productions which have a RHS all in N. */ @@ -140,7 +139,6 @@ useless_nonterminals (void) saved to be used when finding useful productions: only productions in this set will appear in the final grammar. */ - n = 0; while (1) { for (i = WORDSIZE (nvars) - 1; i >= 0; i--) @@ -171,7 +169,7 @@ static void inaccessable_symbols (void) { BSet Vp, Vs, Pp; - int i, n; + int i; short t; rule r; @@ -207,7 +205,6 @@ inaccessable_symbols (void) SETBIT (V, start_symbol); - n = 0; while (1) { for (i = WORDSIZE (nsyms) - 1; i >= 0; i--) diff --git a/src/symtab.c b/src/symtab.c index 84479da2..6e5d5ea9 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -20,7 +20,6 @@ #include "system.h" -#include "xalloc.h" #include "symtab.h" #include "gram.h" @@ -143,6 +142,7 @@ free_symtab (void) if (bp->type_name) XFREE (bp->type_name); #endif + XFREE (bp->tag); XFREE (bp); bp = bptmp; } diff --git a/src/system.h b/src/system.h index f5724789..b3c8f6d9 100644 --- a/src/system.h +++ b/src/system.h @@ -73,7 +73,7 @@ extern int errno; # define PARAMS(p) () #endif - +# include "xalloc.h" /*---------------------. | Missing prototypes. | @@ -143,8 +143,6 @@ size_t strnlen PARAMS ((const char *s, size_t maxlen)); # define LOCALEDIR "/usr/local/share/locale" #endif -#endif /* BISON_SYSTEM_H */ - /*-----------. | Booleans. | @@ -161,9 +159,9 @@ typedef int bool; | Obstacks. | `-----------*/ -#define obstack_chunk_alloc xmalloc -#define obstack_chunk_free free -#include "obstack.h" +# define obstack_chunk_alloc xmalloc +# define obstack_chunk_free free +# include "obstack.h" #define obstack_sgrow(Obs, Str) \ obstack_grow (Obs, Str, strlen (Str)) @@ -264,3 +262,15 @@ do { \ # define BISON_HAIRY "c:/usr/local/lib/bison.hairy" # endif #endif + + +/*---------------------------------. +| Debugging the memory allocator. | +`---------------------------------*/ + +# if WITH_DMALLOC +# define DMALLOC_FUNC_CHECK +# include +# endif /* WITH_DMALLOC */ + +#endif /* BISON_SYSTEM_H */ diff --git a/src/vcg.c b/src/vcg.c index ecc4c41a..f6466481 100644 --- a/src/vcg.c +++ b/src/vcg.c @@ -21,8 +21,6 @@ #include "system.h" #include "vcg.h" #include "vcg_defaults.h" -#include "xalloc.h" -#include "complain.h" /* Initialize a graph with the default values. */ void @@ -51,6 +49,9 @@ new_graph (graph_t *g) g->textmode = G_TEXTMODE; g->shape = G_SHAPE; + g->vertical_order = G_VERTICAL_ORDER; + g->horizontal_order = G_HORIZONTAL_ORDER; + g->xmax = G_XMAX; /* Not output. */ g->ymax = G_YMAX; /* Not output. */ @@ -231,8 +232,7 @@ get_color_str (enum color_e c) case orchid: return "orchid"; case black: return "black"; default: - complain (_("vcg graph: no such color.")); - return get_color_str(G_COLOR); + assert (!"Not a default color."); } return NULL; } @@ -246,8 +246,7 @@ get_textmode_str (enum textmode_e t) case left_justify: return "left_justify"; case right_justify: return "right_justify"; default: - complain (_("vcg graph: no such text mode")); - return get_textmode_str(G_TEXTMODE); + assert (!"Not a text mode."); } return NULL; } @@ -262,8 +261,7 @@ get_shape_str (enum shape_e s) case ellipse: return "ellipse"; case triangle: return "triangle"; default: - complain (_("vcg graph: no such shape")); - return get_shape_str(G_SHAPE); + assert (!"Not a shape."); } return NULL; } @@ -288,21 +286,20 @@ get_layoutalgorithm_str (enum layoutalgorithm_e l) case dfs: return "dfs"; case tree: return "tree"; default: - return "normal"; + assert (!"Not a layout algorithm."); } return NULL; } static const char * -get_decision_str (enum decision_e d, enum decision_e defaults) +get_decision_str (enum decision_e d) { switch (d) { case no: return "no"; case yes: return "yes"; default: - complain (_("vcg graph: no such decision")); - return get_decision_str(defaults, 0); + assert (!"Either yes nor no."); } return NULL; } @@ -317,8 +314,7 @@ get_orientation_str (enum orientation_e o) case left_to_right: return "left_to_right"; case right_to_left: return "right_to_left"; default: - complain (_("vcg graph: no such an orientation")); - return get_orientation_str(G_ORIENTATION); + assert (!"Not an orientation."); } return NULL; } @@ -332,8 +328,7 @@ get_node_alignement_str (enum alignement_e a) case top: return "top"; case bottom: return "bottom"; default: - complain (_("vcg graph: no such an alignement")); - return get_node_alignement_str(G_NODE_ALIGNEMENT); + assert (!"Not an alignement."); } return NULL; } @@ -346,8 +341,7 @@ get_arrow_mode_str (enum arrow_mode_e a) case fixed: return "fixed"; case free_a: return "free"; default: - complain (_("vcg graph: no such an arrow mode")); - return get_arrow_mode_str(G_ARROW_MODE); + assert (!"Not an arrow mode."); } return NULL; } @@ -362,8 +356,7 @@ get_crossing_type_str (enum crossing_type_e c) case barymedian: return "barymedian"; case medianbary: return "medianbary"; default: - complain (_("vcg graph: no such crossing_type")); - return get_crossing_type_str(G_CROSSING_WEIGHT); + assert (!"Not a crossing type."); } return NULL; } @@ -379,8 +372,7 @@ get_view_str (enum view_e v) case fcfish: return "fcfish"; case fpfish: return "fpfish"; default: - complain (_("vcg graph: no such view")); - return get_view_str(G_VIEW); + assert (!"Not a view."); } return NULL; } @@ -395,8 +387,7 @@ get_linestyle_str (enum linestyle_e l) case dotted: return "dotted"; case invisible: return "invisible"; default: - complain (_("vcg graph: no such linestyle")); - return get_linestyle_str(E_LINESTYLE); + assert (!"Not a line style."); } return NULL; } @@ -410,8 +401,7 @@ get_arrowstyle_str (enum arrowstyle_e a) case line: return "line"; case none: return "none"; default: - complain (_("vcg graph: no such an arrowstyle")); - return get_arrowstyle_str(E_ARROWSTYLE); + assert (!"Not an arrow style."); } return NULL; } @@ -435,402 +425,461 @@ add_edge (graph_t *graph, edge_t *edge) graph->edge_list = edge; } +void +add_classname (graph_t *g, int val, const char *name) +{ + struct classname_s *classname; + + classname = XMALLOC (struct classname_s, 1); + classname->no = val; + classname->name = name; + classname->next = g->classname; + g->classname = classname; +} + +void +add_infoname (graph_t *g, int integer, const char *string) +{ + struct infoname_s *infoname; + + infoname = XMALLOC (struct infoname_s, 1); + infoname->integer = integer; + infoname->string = string; + infoname->next = g->infoname; + g->infoname = infoname; +} + +/* Build a colorentry struct and add it to the list. */ +void +add_colorentry (graph_t *g, int color_idx, int red_cp, + int green_cp, int blue_cp) +{ + struct colorentry_s *ce; + + ce = XMALLOC (struct colorentry_s, 1); + ce->color_index = color_idx; + ce->red_cp = red_cp; + ce->green_cp = green_cp; + ce->blue_cp = blue_cp; + ce->next = g->colorentry; + g->colorentry = ce; +} + /*-------------------------------------. | Open and close functions (formatted) | `-------------------------------------*/ void -open_edge(edge_t *edge, struct obstack *os) +open_edge(edge_t *edge, FILE *fout) { switch (edge->type) { case normal_edge: - obstack_sgrow (os, "\tedge: {\n"); + fputs ("\tedge: {\n", fout); break; case back_edge: - obstack_sgrow (os, "\tbackedge: {\n"); + fputs ("\tbackedge: {\n", fout); break; case near_edge: - obstack_sgrow (os, "\tnearedge: {\n"); + fputs ("\tnearedge: {\n", fout); break; case bent_near_edge: - obstack_sgrow (os, "\tbentnearedge: {\n"); + fputs ("\tbentnearedge: {\n", fout); break; default: - obstack_sgrow (os, "\tedge: {\n"); + fputs ("\tedge: {\n", fout); } } void -close_edge(struct obstack *os) +close_edge(FILE *fout) { - obstack_sgrow (os, "\t}\n"); + fputs ("\t}\n", fout); } void -open_node(struct obstack *os) +open_node(FILE *fout) { - obstack_sgrow (os, "\tnode: {\n"); + fputs ("\tnode: {\n", fout); } void -close_node(struct obstack *os) +close_node(FILE *fout) { - obstack_sgrow (os, "\t}\n"); + fputs ("\t}\n", fout); } void -open_graph(struct obstack *os) +open_graph(FILE *fout) { - obstack_sgrow (os, "graph: {\n"); + fputs ("graph: {\n", fout); } void -close_graph(graph_t *graph, struct obstack *os) +close_graph(graph_t *graph, FILE *fout) { - obstack_1grow (os, '\n'); + fputc ('\n', fout); + /* FIXME: Unallocate nodes and edges if required. */ { node_t *node; for (node = graph->node_list; node; node = node->next) { - open_node (os); - output_node (node, os); - close_node (os); + open_node (fout); + output_node (node, fout); + close_node (fout); } } - obstack_1grow (os, '\n'); + fputc ('\n', fout); { edge_t *edge; for (edge = graph->edge_list; edge; edge = edge->next) { - open_edge (edge, os); - output_edge (edge, os); - close_edge (os); + open_edge (edge, fout); + output_edge (edge, fout); + close_edge (fout); } } - obstack_sgrow (os, "}\n"); + fputs ("}\n", fout); } /*-------------------------------------------. -| Output functions (formatted) in obstack os | +| Output functions (formatted) in file FOUT | `-------------------------------------------*/ void -output_node (node_t *node, struct obstack *os) +output_node (node_t *node, FILE *fout) { if (node->title != N_TITLE) - obstack_fgrow1 (os, "\t\ttitle:\t\"%s\"\n", node->title); + fprintf (fout, "\t\ttitle:\t\"%s\"\n", node->title); if (node->label != N_LABEL) - obstack_fgrow1 (os, "\t\tlabel:\t\"%s\"\n", node->label); + fprintf (fout, "\t\tlabel:\t\"%s\"\n", node->label); if ((node->locx != N_LOCX) && (node->locy != N_LOCY)) - obstack_fgrow2 (os, "\t\tloc { x: %d y: %d }\t\n", node->locx, node->locy); + fprintf (fout, "\t\tloc { x: %d y: %d }\t\n", node->locx, node->locy); if (node->vertical_order != N_VERTICAL_ORDER) - obstack_fgrow1 (os, "\t\tvertical_order:\t%d\n", node->vertical_order); + fprintf (fout, "\t\tvertical_order:\t%d\n", node->vertical_order); if (node->horizontal_order != N_HORIZONTAL_ORDER) - obstack_fgrow1 (os, "\t\thorizontal_order:\t%d\n", node->horizontal_order); + fprintf (fout, "\t\thorizontal_order:\t%d\n", node->horizontal_order); if (node->width != N_WIDTH) - obstack_fgrow1 (os, "\t\twidth:\t%d\n", node->width); + fprintf (fout, "\t\twidth:\t%d\n", node->width); if (node->height != N_HEIGHT) - obstack_fgrow1 (os, "\t\theight:\t%d\n", node->height); + fprintf (fout, "\t\theight:\t%d\n", node->height); if (node->shrink != N_SHRINK) - obstack_fgrow1 (os, "\t\tshrink:\t%d\n", node->shrink); + fprintf (fout, "\t\tshrink:\t%d\n", node->shrink); if (node->stretch != N_STRETCH) - obstack_fgrow1 (os, "\t\tstretch:\t%d\n", node->stretch); + fprintf (fout, "\t\tstretch:\t%d\n", node->stretch); if (node->folding != N_FOLDING) - obstack_fgrow1 (os, "\t\tfolding:\t%d\n", node->folding); + fprintf (fout, "\t\tfolding:\t%d\n", node->folding); if (node->textmode != N_TEXTMODE) - obstack_fgrow1 (os, "\t\ttextmode:\t%s\n", - get_textmode_str (node->textmode)); + fprintf (fout, "\t\ttextmode:\t%s\n", + get_textmode_str (node->textmode)); if (node->shape != N_SHAPE) - obstack_fgrow1 (os, "\t\tshape:\t%s\n", get_shape_str (node->shape)); + fprintf (fout, "\t\tshape:\t%s\n", get_shape_str (node->shape)); if (node->borderwidth != N_BORDERWIDTH) - obstack_fgrow1 (os, "\t\tborderwidth:\t%d\n", node->borderwidth); + fprintf (fout, "\t\tborderwidth:\t%d\n", node->borderwidth); if (node->color != N_COLOR) - obstack_fgrow1 (os, "\t\tcolor:\t%s\n", get_color_str (node->color)); + fprintf (fout, "\t\tcolor:\t%s\n", get_color_str (node->color)); if (node->textcolor != N_TEXTCOLOR) - obstack_fgrow1 (os, "\t\ttextcolor:\t%s\n", - get_color_str (node->textcolor)); + fprintf (fout, "\t\ttextcolor:\t%s\n", + get_color_str (node->textcolor)); if (node->bordercolor != N_BORDERCOLOR) - obstack_fgrow1 (os, "\t\tbordercolor:\t%s\n", - get_color_str (node->bordercolor)); + fprintf (fout, "\t\tbordercolor:\t%s\n", + get_color_str (node->bordercolor)); if (node->infos[0]) - obstack_fgrow1 (os, "\t\tinfo1:\t\"%s\"\n", node->infos[0]); + fprintf (fout, "\t\tinfo1:\t\"%s\"\n", node->infos[0]); if (node->infos[1]) - obstack_fgrow1 (os, "\t\tinfo2:\t\"%s\"\n", node->infos[1]); + fprintf (fout, "\t\tinfo2:\t\"%s\"\n", node->infos[1]); if (node->infos[2]) - obstack_fgrow1 (os, "\t\tinfo3:\t\"%s\"\n", node->infos[2]); + fprintf (fout, "\t\tinfo3:\t\"%s\"\n", node->infos[2]); } void -output_edge (edge_t *edge, struct obstack *os) +output_edge (edge_t *edge, FILE *fout) { /* FIXME: SOURCENAME and TARGETNAME are mandatory so it has to be fatal not to give these informations. */ if (edge->sourcename != E_SOURCENAME) - obstack_fgrow1 (os, "\t\tsourcename:\t\"%s\"\n", edge->sourcename); + fprintf (fout, "\t\tsourcename:\t\"%s\"\n", edge->sourcename); if (edge->targetname != E_TARGETNAME) - obstack_fgrow1 (os, "\t\ttargetname:\t\"%s\"\n", edge->targetname); + fprintf (fout, "\t\ttargetname:\t\"%s\"\n", edge->targetname); if (edge->label != E_LABEL) - obstack_fgrow1 (os, "\t\tlabel:\t\"%s\"\n", edge->label); + fprintf (fout, "\t\tlabel:\t\"%s\"\n", edge->label); if (edge->linestyle != E_LINESTYLE) - obstack_fgrow1 (os, "\t\tlinestyle:\t\"%s\"\n", - get_linestyle_str(edge->linestyle)); + fprintf (fout, "\t\tlinestyle:\t\"%s\"\n", + get_linestyle_str(edge->linestyle)); if (edge->thickness != E_THICKNESS) - obstack_fgrow1 (os, "\t\tthickness:\t%d\n", edge->thickness); + fprintf (fout, "\t\tthickness:\t%d\n", edge->thickness); if (edge->class != E_CLASS) - obstack_fgrow1 (os, "\t\tclass:\t%d\n", edge->class); + fprintf (fout, "\t\tclass:\t%d\n", edge->class); if (edge->color != E_COLOR) - obstack_fgrow1 (os, "\t\tcolor:\t%s\n", get_color_str (edge->color)); + fprintf (fout, "\t\tcolor:\t%s\n", get_color_str (edge->color)); if (edge->color != E_TEXTCOLOR) - obstack_fgrow1 (os, "\t\ttextcolor:\t%s\n", - get_color_str (edge->textcolor)); + fprintf (fout, "\t\ttextcolor:\t%s\n", + get_color_str (edge->textcolor)); if (edge->arrowcolor != E_ARROWCOLOR) - obstack_fgrow1 (os, "\t\tarrowcolor:\t%s\n", - get_color_str (edge->arrowcolor)); + fprintf (fout, "\t\tarrowcolor:\t%s\n", + get_color_str (edge->arrowcolor)); if (edge->backarrowcolor != E_BACKARROWCOLOR) - obstack_fgrow1 (os, "\t\tbackarrowcolor:\t%s\n", - get_color_str (edge->backarrowcolor)); + fprintf (fout, "\t\tbackarrowcolor:\t%s\n", + get_color_str (edge->backarrowcolor)); if (edge->arrowsize != E_ARROWSIZE) - obstack_fgrow1 (os, "\t\tarrowsize:\t%d\n", edge->arrowsize); + fprintf (fout, "\t\tarrowsize:\t%d\n", edge->arrowsize); if (edge->backarrowsize != E_BACKARROWSIZE) - obstack_fgrow1 (os, "\t\tbackarrowsize:\t%d\n", edge->backarrowsize); + fprintf (fout, "\t\tbackarrowsize:\t%d\n", edge->backarrowsize); if (edge->arrowstyle != E_ARROWSTYLE) - obstack_fgrow1 (os, "\t\tarrowstyle:\t%s\n", - get_arrowstyle_str(edge->arrowstyle)); + fprintf (fout, "\t\tarrowstyle:\t%s\n", + get_arrowstyle_str(edge->arrowstyle)); if (edge->backarrowstyle != E_BACKARROWSTYLE) - obstack_fgrow1 (os, "\t\tbackarrowstyle:\t%s\n", - get_arrowstyle_str(edge->backarrowstyle)); + fprintf (fout, "\t\tbackarrowstyle:\t%s\n", + get_arrowstyle_str(edge->backarrowstyle)); if (edge->priority != E_PRIORITY) - obstack_fgrow1 (os, "\t\tpriority:\t%d\n", edge->priority); + fprintf (fout, "\t\tpriority:\t%d\n", edge->priority); if (edge->anchor != E_ANCHOR) - obstack_fgrow1 (os, "\t\tanchor:\t%d\n", edge->anchor); + fprintf (fout, "\t\tanchor:\t%d\n", edge->anchor); if (edge->horizontal_order != E_HORIZONTAL_ORDER) - obstack_fgrow1 (os, "\t\thorizontal_order:\t%d\n", edge->horizontal_order); + fprintf (fout, "\t\thorizontal_order:\t%d\n", edge->horizontal_order); } void -output_graph (graph_t *graph, struct obstack *os) +output_graph (graph_t *graph, FILE *fout) { if (graph->title) - obstack_fgrow1 (os, "\ttitle:\t\"%s\"\n", graph->title); + fprintf (fout, "\ttitle:\t\"%s\"\n", graph->title); if (graph->label) - obstack_fgrow1 (os, "\tlabel:\t\"%s\"\n", graph->label); + fprintf (fout, "\tlabel:\t\"%s\"\n", graph->label); if (graph->infos[0]) - obstack_fgrow1 (os, "\tinfo1:\t\"%s\"\n", graph->infos[0]); + fprintf (fout, "\tinfo1:\t\"%s\"\n", graph->infos[0]); if (graph->infos[1]) - obstack_fgrow1 (os, "\tinfo2:\t\"%s\"\n", graph->infos[1]); + fprintf (fout, "\tinfo2:\t\"%s\"\n", graph->infos[1]); if (graph->infos[2]) - obstack_fgrow1 (os, "\tinfo3:\t\"%s\"\n", graph->infos[2]); + fprintf (fout, "\tinfo3:\t\"%s\"\n", graph->infos[2]); if (graph->color != G_COLOR) - obstack_fgrow1 (os, "\tcolor:\t%s\n", get_color_str (graph->color)); + fprintf (fout, "\tcolor:\t%s\n", get_color_str (graph->color)); if (graph->textcolor != G_TEXTCOLOR) - obstack_fgrow1 (os, "\ttextcolor:\t%s\n", get_color_str (graph->textcolor)); + fprintf (fout, "\ttextcolor:\t%s\n", get_color_str (graph->textcolor)); if (graph->bordercolor != G_BORDERCOLOR) - obstack_fgrow1 (os, "\tbordercolor:\t%s\n", - get_color_str (graph->bordercolor)); + fprintf (fout, "\tbordercolor:\t%s\n", + get_color_str (graph->bordercolor)); if (graph->width != G_WIDTH) - obstack_fgrow1 (os, "\twidth:\t%d\n", graph->width); + fprintf (fout, "\twidth:\t%d\n", graph->width); if (graph->height != G_HEIGHT) - obstack_fgrow1 (os, "\theight:\t%d\n", graph->height); + fprintf (fout, "\theight:\t%d\n", graph->height); if (graph->borderwidth != G_BORDERWIDTH) - obstack_fgrow1 (os, "\tborderwidth:\t%d\n", graph->borderwidth); + fprintf (fout, "\tborderwidth:\t%d\n", graph->borderwidth); if (graph->x != G_X) - obstack_fgrow1 (os, "\tx:\t%d\n", graph->x); + fprintf (fout, "\tx:\t%d\n", graph->x); if (graph->y != G_Y) - obstack_fgrow1 (os, "\ty:\t%d\n", graph->y); + fprintf (fout, "\ty:\t%d\n", graph->y); if (graph->folding != G_FOLDING) - obstack_fgrow1 (os, "\tfolding:\t%d\n", graph->folding); + fprintf (fout, "\tfolding:\t%d\n", graph->folding); if (graph->shrink != G_SHRINK) - obstack_fgrow1 (os, "\tshrink:\t%d\n", graph->shrink); + fprintf (fout, "\tshrink:\t%d\n", graph->shrink); if (graph->stretch != G_STRETCH) - obstack_fgrow1 (os, "\tstretch:\t%d\n", graph->stretch); + fprintf (fout, "\tstretch:\t%d\n", graph->stretch); if (graph->textmode != G_TEXTMODE) - obstack_fgrow1 (os, "\ttextmode:\t%s\n", - get_textmode_str (graph->textmode)); + fprintf (fout, "\ttextmode:\t%s\n", + get_textmode_str (graph->textmode)); if (graph->shape != G_SHAPE) - obstack_fgrow1 (os, "\tshape:\t%s\n", get_shape_str (graph->shape)); + fprintf (fout, "\tshape:\t%s\n", get_shape_str (graph->shape)); + + if (graph->vertical_order != G_VERTICAL_ORDER) + fprintf (fout, "\tvertical_order:\t%d\n", graph->vertical_order); + if (graph->horizontal_order != G_HORIZONTAL_ORDER) + fprintf (fout, "\thorizontal_order:\t%d\n", graph->horizontal_order); if (graph->xmax != G_XMAX) - obstack_fgrow1 (os, "\txmax:\t%d\n", graph->xmax); + fprintf (fout, "\txmax:\t%d\n", graph->xmax); if (graph->ymax != G_YMAX) - obstack_fgrow1 (os, "\tymax:\t%d\n", graph->ymax); + fprintf (fout, "\tymax:\t%d\n", graph->ymax); if (graph->xbase != G_XBASE) - obstack_fgrow1 (os, "\txbase:\t%d\n", graph->xbase); + fprintf (fout, "\txbase:\t%d\n", graph->xbase); if (graph->ybase != G_YBASE) - obstack_fgrow1 (os, "\tybase:\t%d\n", graph->ybase); + fprintf (fout, "\tybase:\t%d\n", graph->ybase); if (graph->xspace != G_XSPACE) - obstack_fgrow1 (os, "\txspace:\t%d\n", graph->xspace); + fprintf (fout, "\txspace:\t%d\n", graph->xspace); if (graph->yspace != G_YSPACE) - obstack_fgrow1 (os, "\tyspace:\t%d\n", graph->yspace); + fprintf (fout, "\tyspace:\t%d\n", graph->yspace); if (graph->xlspace != G_XLSPACE) - obstack_fgrow1 (os, "\txlspace:\t%d\n", graph->xlspace); + fprintf (fout, "\txlspace:\t%d\n", graph->xlspace); if (graph->xraster != G_XRASTER) - obstack_fgrow1 (os, "\txraster:\t%d\n", graph->xraster); + fprintf (fout, "\txraster:\t%d\n", graph->xraster); if (graph->yraster != G_YRASTER) - obstack_fgrow1 (os, "\tyraster:\t%d\n", graph->yraster); + fprintf (fout, "\tyraster:\t%d\n", graph->yraster); if (graph->xlraster != G_XLRASTER) - obstack_fgrow1 (os, "\txlraster:\t%d\n", graph->xlraster); + fprintf (fout, "\txlraster:\t%d\n", graph->xlraster); if (graph->hidden != G_HIDDEN) - obstack_fgrow1 (os, "\thidden:\t%d\n", graph->hidden); - + fprintf (fout, "\thidden:\t%d\n", graph->hidden); + + /* FIXME: Unallocate struct list if required. + Maybe with a little function. */ if (graph->classname != G_CLASSNAME) { struct classname_s *ite; for (ite = graph->classname; ite; ite = ite->next) - obstack_fgrow2 (os, "\tclassname %d :\t%s\n", ite->no, ite->name); + fprintf (fout, "\tclassname %d :\t%s\n", ite->no, ite->name); + } + + if (graph->infoname != G_INFONAME) + { + struct infoname_s *ite; + + for (ite = graph->infoname; ite; ite = ite->next) + fprintf (fout, "\tinfoname %d :\t%s\n", ite->integer, ite->string); + } + + if (graph->colorentry != G_COLORENTRY) + { + struct colorentry_s *ite; + + for (ite = graph->colorentry; ite; ite = ite->next) + { + fprintf (fout, "\tcolorentry %d :\t%d %d %d\n", + ite->color_index, + ite->red_cp, + ite->green_cp, + ite->blue_cp); + } } if (graph->layoutalgorithm != G_LAYOUTALGORITHM) - obstack_fgrow1 (os, "\tlayoutalgorithm:\t%s\n", - get_layoutalgorithm_str(graph->layoutalgorithm)); + fprintf (fout, "\tlayoutalgorithm:\t%s\n", + get_layoutalgorithm_str(graph->layoutalgorithm)); if (graph->layout_downfactor != G_LAYOUT_DOWNFACTOR) - obstack_fgrow1 (os, "\tlayout_downfactor:\t%d\n", graph->layout_downfactor); + fprintf (fout, "\tlayout_downfactor:\t%d\n", graph->layout_downfactor); if (graph->layout_upfactor != G_LAYOUT_UPFACTOR) - obstack_fgrow1 (os, "\tlayout_upfactor:\t%d\n", graph->layout_upfactor); + fprintf (fout, "\tlayout_upfactor:\t%d\n", graph->layout_upfactor); if (graph->layout_nearfactor != G_LAYOUT_NEARFACTOR) - obstack_fgrow1 (os, "\tlayout_nearfactor:\t%d\n", graph->layout_nearfactor); + fprintf (fout, "\tlayout_nearfactor:\t%d\n", graph->layout_nearfactor); if (graph->layout_splinefactor != G_LAYOUT_SPLINEFACTOR) - obstack_fgrow1 (os, "\tlayout_splinefactor:\t%d\n", - graph->layout_splinefactor); + fprintf (fout, "\tlayout_splinefactor:\t%d\n", + graph->layout_splinefactor); if (graph->late_edge_labels != G_LATE_EDGE_LABELS) - obstack_fgrow1 (os, "\tlate_edge_labels:\t%s\n", - get_decision_str(graph->late_edge_labels, - G_LATE_EDGE_LABELS)); + fprintf (fout, "\tlate_edge_labels:\t%s\n", + get_decision_str(graph->late_edge_labels)); if (graph->display_edge_labels != G_DISPLAY_EDGE_LABELS) - obstack_fgrow1 (os, "\tdisplay_edge_labels:\t%s\n", - get_decision_str(graph->display_edge_labels, - G_DISPLAY_EDGE_LABELS)); + fprintf (fout, "\tdisplay_edge_labels:\t%s\n", + get_decision_str(graph->display_edge_labels)); if (graph->dirty_edge_labels != G_DIRTY_EDGE_LABELS) - obstack_fgrow1 (os, "\tdirty_edge_labels:\t%s\n", - get_decision_str(graph->dirty_edge_labels, - G_DIRTY_EDGE_LABELS)); + fprintf (fout, "\tdirty_edge_labels:\t%s\n", + get_decision_str(graph->dirty_edge_labels)); if (graph->finetuning != G_FINETUNING) - obstack_fgrow1 (os, "\tfinetuning:\t%s\n", - get_decision_str(graph->finetuning, G_FINETUNING)); + fprintf (fout, "\tfinetuning:\t%s\n", + get_decision_str(graph->finetuning)); if (graph->ignore_singles != G_IGNORE_SINGLES) - obstack_fgrow1 (os, "\tignore_singles:\t%s\n", - get_decision_str(graph->ignore_singles, G_IGNORE_SINGLES)); + fprintf (fout, "\tignore_singles:\t%s\n", + get_decision_str(graph->ignore_singles)); if (graph->straight_phase != G_STRAIGHT_PHASE) - obstack_fgrow1 (os, "\tstraight_phase:\t%s\n", - get_decision_str(graph->straight_phase, G_STRAIGHT_PHASE)); + fprintf (fout, "\tstraight_phase:\t%s\n", + get_decision_str(graph->straight_phase)); if (graph->priority_phase != G_PRIORITY_PHASE) - obstack_fgrow1 (os, "\tpriority_phase:\t%s\n", - get_decision_str(graph->priority_phase, G_PRIORITY_PHASE)); + fprintf (fout, "\tpriority_phase:\t%s\n", + get_decision_str(graph->priority_phase)); if (graph->manhattan_edges != G_MANHATTAN_EDGES) - obstack_fgrow1 (os, - "\tmanhattan_edges:\t%s\n", - get_decision_str(graph->manhattan_edges, - G_MANHATTAN_EDGES)); + fprintf (fout, + "\tmanhattan_edges:\t%s\n", + get_decision_str(graph->manhattan_edges)); if (graph->smanhattan_edges != G_SMANHATTAN_EDGES) - obstack_fgrow1 (os, - "\tsmanhattan_edges:\t%s\n", - get_decision_str(graph->smanhattan_edges, - G_SMANHATTAN_EDGES)); + fprintf (fout, + "\tsmanhattan_edges:\t%s\n", + get_decision_str(graph->smanhattan_edges)); if (graph->near_edges != G_NEAR_EDGES) - obstack_fgrow1 (os, "\tnear_edges:\t%s\n", - get_decision_str(graph->near_edges, G_NEAR_EDGES)); + fprintf (fout, "\tnear_edges:\t%s\n", + get_decision_str(graph->near_edges)); if (graph->orientation != G_ORIENTATION) - obstack_fgrow1 (os, "\torientation:\t%s\n", - get_decision_str(graph->orientation, G_ORIENTATION)); + fprintf (fout, "\torientation:\t%s\n", + get_orientation_str(graph->orientation)); if (graph->node_alignement != G_NODE_ALIGNEMENT) - obstack_fgrow1 (os, "\tnode_alignement:\t%s\n", - get_decision_str(graph->node_alignement, - G_NODE_ALIGNEMENT)); + fprintf (fout, "\tnode_alignement:\t%s\n", + get_node_alignement_str(graph->node_alignement)); if (graph->port_sharing != G_PORT_SHARING) - obstack_fgrow1 (os, "\tport_sharing:\t%s\n", - get_decision_str(graph->port_sharing, G_PORT_SHARING)); + fprintf (fout, "\tport_sharing:\t%s\n", + get_decision_str(graph->port_sharing)); if (graph->arrow_mode != G_ARROW_MODE) - obstack_fgrow1 (os, "\tarrow_mode:\t%s\n", - get_arrow_mode_str(graph->arrow_mode)); + fprintf (fout, "\tarrow_mode:\t%s\n", + get_arrow_mode_str(graph->arrow_mode)); if (graph->treefactor != G_TREEFACTOR) - obstack_fgrow1 (os, "\ttreefactor:\t%f\n", graph->treefactor); + fprintf (fout, "\ttreefactor:\t%f\n", graph->treefactor); if (graph->spreadlevel != G_SPREADLEVEL) - obstack_fgrow1 (os, "\tspreadlevel:\t%d\n", graph->spreadlevel); + fprintf (fout, "\tspreadlevel:\t%d\n", graph->spreadlevel); if (graph->crossing_weight != G_CROSSING_WEIGHT) - obstack_fgrow1 (os, "\tcrossing_weight:\t%s\n", - get_crossing_type_str(graph->crossing_weight)); + fprintf (fout, "\tcrossing_weight:\t%s\n", + get_crossing_type_str(graph->crossing_weight)); if (graph->crossing_phase2 != G_CROSSING_PHASE2) - obstack_fgrow1 (os, "\tcrossing_phase2:\t%s\n", - get_decision_str(graph->crossing_phase2, - G_CROSSING_PHASE2)); + fprintf (fout, "\tcrossing_phase2:\t%s\n", + get_decision_str(graph->crossing_phase2)); if (graph->crossing_optimization != G_CROSSING_OPTIMIZATION) - obstack_fgrow1 (os, "\tcrossing_optimization:\t%s\n", - get_decision_str(graph->crossing_optimization, - G_CROSSING_OPTIMIZATION)); + fprintf (fout, "\tcrossing_optimization:\t%s\n", + get_decision_str(graph->crossing_optimization)); if (graph->view != G_VIEW) - obstack_fgrow1 (os, "\tview:\t%s\n", get_view_str(graph->view)); + fprintf (fout, "\tview:\t%s\n", get_view_str(graph->view)); if (graph->edges != G_EDGES) - obstack_fgrow1 (os, "\tedges:\t%s\n", get_decision_str(graph->edges, - G_EDGES)); + fprintf (fout, "\tedges:\t%s\n", get_decision_str(graph->edges)); if (graph->nodes != G_NODES) - obstack_fgrow1 (os,"\tnodes:\t%s\n", - get_decision_str(graph->nodes, G_NODES)); + fprintf (fout,"\tnodes:\t%s\n", get_decision_str(graph->nodes)); if (graph->splines != G_SPLINES) - obstack_fgrow1 (os, "\tsplines:\t%s\n", - get_decision_str(graph->splines, G_SPLINES)); + fprintf (fout, "\tsplines:\t%s\n", get_decision_str(graph->splines)); if (graph->bmax != G_BMAX) - obstack_fgrow1 (os, "\tbmax:\t%d\n", graph->bmax); + fprintf (fout, "\tbmax:\t%d\n", graph->bmax); if (graph->cmin != G_CMIN) - obstack_fgrow1 (os, "\tcmin:\t%d\n", graph->cmin); + fprintf (fout, "\tcmin:\t%d\n", graph->cmin); if (graph->cmax != G_CMAX) - obstack_fgrow1 (os, "\tcmax:\t%d\n", graph->cmax); + fprintf (fout, "\tcmax:\t%d\n", graph->cmax); if (graph->pmin != G_PMIN) - obstack_fgrow1 (os, "\tpmin:\t%d\n", graph->pmin); + fprintf (fout, "\tpmin:\t%d\n", graph->pmin); if (graph->pmax != G_PMAX) - obstack_fgrow1 (os, "\tpmax:\t%d\n", graph->pmax); + fprintf (fout, "\tpmax:\t%d\n", graph->pmax); if (graph->rmin != G_RMIN) - obstack_fgrow1 (os, "\trmin:\t%d\n", graph->rmin); + fprintf (fout, "\trmin:\t%d\n", graph->rmin); if (graph->rmax != G_RMAX) - obstack_fgrow1 (os, "\trmax:\t%d\n", graph->rmax); + fprintf (fout, "\trmax:\t%d\n", graph->rmax); if (graph->smax != G_SMAX) - obstack_fgrow1 (os, "\tsmax:\t%d\n", graph->smax); + fprintf (fout, "\tsmax:\t%d\n", graph->smax); } diff --git a/src/vcg.h b/src/vcg.h index d92559a1..8935cc1b 100644 --- a/src/vcg.h +++ b/src/vcg.h @@ -75,14 +75,32 @@ enum shape_e triangle }; +/* Structure for colorentries. */ +struct colorentry_s +{ + int color_index; + int red_cp; + int green_cp; + int blue_cp; + struct colorentry_s *next; +}; + /* Structure to construct lists of classnames. */ struct classname_s { int no; /* Class number */ - char *name; /* Name associated to the class no. */ + const char *name; /* Name associated to the class no. */ struct classname_s *next; /* next name class association. */ }; +/* Structure is in infoname. */ +struct infoname_s +{ + int integer; + const char *string; + struct infoname_s *next; +}; + /* Layout Algorithms which can be found in VCG. Details about each algoithm can be found below. */ enum layoutalgorithm_e @@ -161,13 +179,13 @@ struct node_s { /* Title the unique string identifying the node. This attribute is mandatory. */ - char *title; + const char *title; /* Label the text displayed inside the node. If no label is specified then the title of the node will be used. Note that this text may contain control characters like NEWLINE that influences the size of the node. */ - char *label; + const char *label; /* loc is the location as x, y position relatively to the system of coordinates of the graph. Locations are specified in the form @@ -277,7 +295,7 @@ struct node_s /* info2, info3 can be selected from the menu. The corresponding text labels can be shown by mouse clicks on nodes. Default are null strings. */ - char *infos[3]; + const char *infos[3]; /* Node border color. Default is textcolor. */ @@ -483,19 +501,19 @@ struct graph_s index 2, green has index 3, etc. Default is white for background and white or transparent for summary nodes. */ - unsigned char color; + enum color_e color; /* Textcolor. need explainations ??? defalut is black for summary nodes. */ - unsigned char textcolor; + enum color_e textcolor; /* Bordercolor is the color of the summary node's border. Default color is the textcolor. width, height are width and height of the displayed part of the window of the outermost graph in pixels, or width and height of the summary node of inner subgraphs. Default is the defalut of the textcolor. */ - unsigned char bordercolor; + enum color_e bordercolor; /* Width, height are width and height of the displayed part of the window of the outermost graph in pixels, or width and height of the @@ -559,7 +577,22 @@ struct graph_s Defalut is box, other: rhomb, ellipse, triangle. */ enum shape_e shape; - /* FIXME {vertival,horizontal}_order */ + /* Vertical order is the level position (rank) of the summary node of an + inner subgraph, if this subgraph is folded. We can also specify + level: int. The level is only recognized, if an automatical layout is + calculated. */ + int vertical_order; + + /* Horizontal order is the horizontal position of the summary node within + a level. The nodes which are specified with horizontal positions are + ordered according to these positions within the levels. The nodes which + do not have this attribute are inserted into this ordering by the + crossing reduction mechanism. Note that connected components are + handled separately, thus it is not possible to intermix such components + by specifying a horizontal order. If the algorithm for downward laid + out trees is used, the horizontal order influences only the order of + the child nodes at a node, but not the order of the whole level. */ + int horizontal_order; /* xmax, ymax specify the maximal size of the virtual window that is used to display the graph. This is usually larger than the displayed @@ -630,8 +663,19 @@ struct graph_s By default, no class names. */ struct classname_s *classname; - /* FIXME : infoname. */ - /* FIXME : colorentry. */ + /* Infoname allows to introduce names for the additional text labels. + The names are used in the menus. + Infoname is given by an integer and a string. + The default value is NULL. */ + struct infoname_s *infoname; + + /* Colorentry allows to fill the color map. A color is a triplet of integer + values for the red/green/blue-part. Each integer is between 0 (off) and + 255 (on), e.g., 0 0 0 is black and 255 255 255 is white. For instance + colorentry 75 : 70 130 180 sets the map entry 75 to steel blue. This + color can be used by specifying just the number 75. + Default id NULL. */ + struct colorentry_s *colorentry; /* layoutalgorithm chooses different graph layout algorithms Possibilities are maxdepth, mindepth, maxdepthslow, mindepthslow, @@ -955,16 +999,21 @@ void new_edge PARAMS ((edge_t *edge)); void add_node PARAMS ((graph_t *graph, node_t *node)); void add_edge PARAMS ((graph_t *graph, edge_t *edge)); -void open_node PARAMS ((struct obstack *os)); -void output_node PARAMS ((node_t *node, struct obstack *os)); -void close_node PARAMS ((struct obstack *os)); +void add_colorentry PARAMS ((graph_t *g, int color_idx, int red_cp, + int green_cp, int blue_cp)); +void add_classname PARAMS ((graph_t *g, int val, const char *name)); +void add_infoname PARAMS ((graph_t *g, int val, const char *name)); + +void open_node PARAMS ((FILE *fout)); +void output_node PARAMS ((node_t *node, FILE *fout)); +void close_node PARAMS ((FILE *fout)); -void open_edge PARAMS ((edge_t *edge, struct obstack *os)); -void output_edge PARAMS ((edge_t *edge, struct obstack *os)); -void close_edge PARAMS ((struct obstack *os)); +void open_edge PARAMS ((edge_t *edge, FILE *fout)); +void output_edge PARAMS ((edge_t *edge, FILE *fout)); +void close_edge PARAMS ((FILE *fout)); -void open_graph PARAMS ((struct obstack *os)); -void output_graph PARAMS ((graph_t *graph, struct obstack *os)); -void close_graph PARAMS ((graph_t *graph, struct obstack *os)); +void open_graph PARAMS ((FILE *fout)); +void output_graph PARAMS ((graph_t *graph, FILE *fout)); +void close_graph PARAMS ((graph_t *graph, FILE *fout)); #endif /* VCG_H_ */ diff --git a/src/vcg_defaults.h b/src/vcg_defaults.h index d40acf43..61a60b84 100644 --- a/src/vcg_defaults.h +++ b/src/vcg_defaults.h @@ -47,8 +47,11 @@ # define G_TEXTMODE centered # define G_SHAPE box -# define G_XMAX 90 /* Not output */ -# define G_YMAX 90 /* Not output */ +# define G_VERTICAL_ORDER 0 /* Unspecified for subgraphs. */ +# define G_HORIZONTAL_ORDER 0 /* Unspecified for subgraphs. */ + +# define G_XMAX 90 /* Not output */ +# define G_YMAX 90 /* Not output */ # define G_XBASE 5 # define G_YBASE 5 @@ -61,9 +64,12 @@ # define G_YRASTER 1 # define G_XLRASTER 1 -# define G_HIDDEN -1 /* No default value. */ +# define G_HIDDEN -1 /* No default value. */ + +# define G_CLASSNAME NULL /* No class name association */ +# define G_INFONAME NULL +# define G_COLORENTRY NULL -# define G_CLASSNAME NULL /* No class name association */ # define G_LAYOUTALGORITHM normal # define G_LAYOUT_DOWNFACTOR 1 # define G_LAYOUT_UPFACTOR 1 diff --git a/tests/.cvsignore b/tests/.cvsignore index 3e35ca4a..05e80ce7 100644 --- a/tests/.cvsignore +++ b/tests/.cvsignore @@ -1,7 +1,6 @@ Makefile Makefile.in at-* -debug-* atconfig empty experr @@ -9,7 +8,12 @@ expout stderr stdout testsuite +testsuite.[0-9] +testsuite.[0-9][0-9] +package.m4 calc.[chy] calc.tab.* calc *.output *.vcg +autom4te.cache +bison diff --git a/tests/Makefile.am b/tests/Makefile.am index bd17ad60..eefd1f96 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -18,23 +18,34 @@ ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA. -# Distribute the testsuite since GNU M4 is needed to build it. -noinst_SCRIPTS = testsuite +EXTRA_DIST = atlocal.in $(TESTSUITE_AT) testsuite -SUITE = calc.at regression.at +DISTCLEANFILES = atconfig atlocal bison package.m4 +MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE) -EXTRA_DIST = atgeneral.m4 suite.at $(SUITE) $(noinst_SCRIPTS) +TESTSUITE_AT = \ + testsuite.at \ + output.at calc.at regression.at +TESTSUITE = $(srcdir)/testsuite -check-local: atconfig $(srcdir)/testsuite - $(SHELL) $(srcdir)/testsuite +AUTOM4TE = autom4te +AUTOTEST = $(AUTOM4TE) --language=autotest +$(srcdir)/$(TESTSUITE): $(TESTSUITE_AT) + $(AUTOTEST) -I $(srcdir) testsuite.at -o $@.tmp + mv $@.tmp $@ -testsuite: atgeneral.m4 suite.at $(SUITE) - $(M4) -I $(srcdir) atgeneral.m4 suite.at | \ - sed -e 's/[ ]*$$//' | \ - sed -e '/^$$/N;/\n$$/D' > $@-tmp - chmod +x $@-tmp - mv $@-tmp $@ +atconfig: $(top_builddir)/config.status + cd $(top_builddir) && ./config.status tests/$@ -CLEANFILES = debug-*.sh empty -DISTCLEANFILES = atconfig -MAINTAINERCLEANFILES = testsuite +atlocal: $(srcdir)/atlocal.in $(top_builddir)/config.status + cd $(top_builddir) && ./config.status tests/$@ + +clean-local: + $(SHELL) $(TESTSUITE) --clean + +check-local: atconfig atlocal $(TESTSUITE) + $(SHELL) $(TESTSUITE) + +# Run the test suite on the *installed* tree. +installcheck-local: + $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin diff --git a/tests/atconfig.in b/tests/atconfig.in deleted file mode 100644 index 3d1bb789..00000000 --- a/tests/atconfig.in +++ /dev/null @@ -1,97 +0,0 @@ -# @configure_input@ -*- shell-script -*- -# Configurable variable values for building test suites. -# Copyright (C) 2000, 2001 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# This script is part of Autotest. Unlimited permission to copy, -# distribute and modify the testing scripts that are the output of -# that Autotest script is given. You need not follow the terms of the -# GNU General Public License when using or distributing such scripts, -# even though portions of the text of Autotest appear in them. The -# GNU General Public License (GPL) does govern all other use of the -# material that constitutes the Autotest. -# -# Certain portions of the Autotest source text are designed to be -# copied (in certain cases, depending on the input) into the output of -# Autotest. We call these the "data" portions. The rest of the -# Autotest source text consists of comments plus executable code that -# decides which of the data portions to output in any given case. We -# call these comments and executable code the "non-data" portions. -# Autotest never copies any of the non-data portions into its output. -# -# This special exception to the GPL applies to versions of Autotest -# released by the Free Software Foundation. When you make and -# distribute a modified version of Autotest, you may extend this -# special exception to the GPL to apply to your modified version as -# well, *unless* your modified version has the potential to copy into -# its output some of the text that was the non-data portion of the -# version that you started with. (In other words, unless your change -# moves or copies text from the non-data portions to the data -# portions.) If your modification has such potential, you must delete -# any notice of this special exception to the GPL from your modified -# version. - -# Snippet (1 -# This debugging script has been automatically generated from `make check'. -# Call it with `--help' to get a quick usage summary. - -at_package='@PACKAGE@' -at_version='@VERSION@' -# Snippet )1 -# Snippet (2 -at_n='@ECHO_N@' -at_c='@ECHO_C@' -test -f atlocal && . ./atlocal - -# LC_MESSAGES is always shadowed by LC_ALL. Here are the only cases: -# - GNU: LANGUAGE -> LC_ALL -> LC_MESSAGES -> LANG -# - POSIX: LC_ALL -> LC_MESSAGES -> LANG -# - XPG4: LC_ALL -> LANG -# - SysV/XPG2: LANG -export LANGUAGE; LANGUAGE=C -export LANG; LANG=C -export LC_ALL; LC_ALL=C - -srcdir=@srcdir@ -top_srcdir=@top_srcdir@ -# Use absolute file notations, as the test might change directories. -at_srcdir=`cd @srcdir@ && pwd` -at_top_srcdir=`cd @top_srcdir@ && pwd` -at_builddir=`pwd` -at_top_builddir=`cd .. && pwd` -if test -n "@AT_TESTPATH@"; then - export PATH; PATH=`pwd`:`cd @AT_TESTPATH@ && pwd`:$PATH -else - export PATH; PATH=`pwd`:$PATH -fi - -# We need GNU M4. -M4='@M4@' - -# We need a C compiler. -CC='@CC@' -CFLAGS='@CFLAGS@' - -# We need `config.h'. -CPPFLAGS="-I$at_top_builddir @CPPFLAGS@" - -# We want to use the files shipped with Bison. -BISON_SIMPLE=$at_top_srcdir/src/bison.simple -export BISON_SIMPLE -BISON_HAIRY=$at_top_srcdir/src/bison.hairy -export BISON_HAIRY -# Snippet )2 diff --git a/tests/atgeneral.m4 b/tests/atgeneral.m4 deleted file mode 100644 index 1387b754..00000000 --- a/tests/atgeneral.m4 +++ /dev/null @@ -1,420 +0,0 @@ -divert(-1) -*- Autoconf -*- -# `m4' macros used in building test suites. -# Copyright (C) 2000 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# This script is part of Autotest. Unlimited permission to copy, -# distribute and modify the testing scripts that are the output of -# that Autotest script is given. You need not follow the terms of the -# GNU General Public License when using or distributing such scripts, -# even though portions of the text of Autotest appear in them. The -# GNU General Public License (GPL) does govern all other use of the -# material that constitutes the Autotest. -# -# Certain portions of the Autotest source text are designed to be -# copied (in certain cases, depending on the input) into the output of -# Autotest. We call these the "data" portions. The rest of the -# Autotest source text consists of comments plus executable code that -# decides which of the data portions to output in any given case. We -# call these comments and executable code the "non-data" portions. -# Autotest never copies any of the non-data portions into its output. -# -# This special exception to the GPL applies to versions of Autotest -# released by the Free Software Foundation. When you make and -# distribute a modified version of Autotest, you may extend this -# special exception to the GPL to apply to your modified version as -# well, *unless* your modified version has the potential to copy into -# its output some of the text that was the non-data portion of the -# version that you started with. (In other words, unless your change -# moves or copies text from the non-data portions to the data -# portions.) If your modification has such potential, you must delete -# any notice of this special exception to the GPL from your modified -# version. - -changequote() -changequote([, ]) - -define([AT_DEFINE], defn([define])) -define([AT_EVAL], defn([eval])) -define([AT_FORMAT], defn([format])) -define([AT_INCLUDE], defn([include])) -define([AT_SHIFT], defn([shift])) -define([AT_UNDEFINE], defn([undefine])) - -undefine([define]) -undefine([eval]) -undefine([format]) -undefine([include]) -undefine([shift]) -undefine([undefine]) - - -# AT_CASE(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT) -# ----------------------------------------------------------- -# m4 equivalent of -# switch (SWITCH) -# { -# case VAL1: -# IF-VAL1; -# break; -# case VAL2: -# IF-VAL2; -# break; -# ... -# default: -# DEFAULT; -# break; -# }. -# All the values are optional, and the macro is robust to active -# symbols properly quoted. -AT_DEFINE([AT_CASE], -[ifelse([$#], 0, [], - [$#], 1, [], - [$#], 2, [$2], - [$1], [$2], [$3], - [AT_CASE([$1], AT_SHIFT(AT_SHIFT(AT_SHIFT($@))))])]) - - -# Use of diversions: -# 0 - overall initialization; for each test group: skipping and cleanups; -# 1 - for each test group: proper code, to reinsert between cleanups; -# 2 - overall wrap up: generation of debugging scripts and statistics. - - -# AT_LINE -# ------- -# Return the current file sans directory, a colon, and the current line. -AT_DEFINE([AT_LINE], -[patsubst(__file__, ^.*/\(.*\), \1):__line__]) - - -# AT_INIT(PROGRAM) -# ---------------- -# Begin testing suite, using PROGRAM to check version. The search path -# should be already preset so the proper executable will be selected. -AT_DEFINE([AT_INIT], -[AT_DEFINE(AT_ordinal, 0) -. ./atconfig -# Snippet (3 -# -e sets to true -at_stop_on_error=false; -# Shall we save and check stdout and stderr? -# -n sets to false -at_check_stds=:; -# Shall we -# -s sets to false, and -v to true -at_verbose=false - -at_usage="Usage: $[0] [OPTION]... - - -e Abort the full suite and inhibit normal clean up if a test fails - -n Do not redirect stdout and stderr and do not test their contents - -s Inhibit verbosity while generating or executing debugging scripts - -v Force more detailed output, default for debugging scripts unless -s - -x Have the shell to trace command execution; also implies option -n" - -# Snippet )3 - -# Snippet (4 -while test $[#] -gt 0; do - case "$[1]" in - --help) echo "$at_usage"; exit 0 ;; - --version) echo "$[0] ($at_package) $at_version"; exit 0 ;; - -e) at_stop_on_error=:;; - -n) at_check_stds=false;; - -s) at_verbose=false; at_silent=1;; - -v) at_verbose=:; at_silent=;; - -x) at_traceon='set -vx'; at_traceoff='set +vx'; at_check_stds=false;; - *) echo 1>&2 "Try \`$[0] --help' for more information."; exit 1 ;; - esac - shift -done - - -# To check whether a test succeeded or not, we compare an expected -# output with a reference. In the testing suite, we just need `cmp' -# but in debugging scripts, we want more information, so we prefer -# `diff -u'. Nonetheless we will use `diff' only, because in DOS -# environments, `diff' considers that two files are equal included -# when there are only differences on the coding of new lines. `cmp' -# does not. -# -# Finally, not all the `diff' support `-u', and some, like Tru64, even -# refuse to `diff' /dev/null. -: >empty - -if diff -u empty empty >/dev/null 2>&1; then - at_diff='diff -u' -else - at_diff='diff' -fi - - - -# Each generated debugging script, containing a single test group, cleans -# up files at the beginning only, not at the end. This is so we can repeat -# the script many times and browse left over files. To cope with such left -# over files, the full test suite cleans up both before and after test groups. -# Snippet )4 - -if $1 --version | grep "$at_package.*$at_version" >/dev/null; then - at_banner="Testing suite for $at_package, version $at_version" - at_dashes=`echo $at_banner | sed s/./=/g` - echo "$at_dashes" - echo "$at_banner" - echo "$at_dashes" -else - echo '=======================================================' - echo 'ERROR: Not using the proper version, no tests performed' - echo '=======================================================' - exit 1 -fi - -# Remove any debugging script resulting from a previous run. -rm -f debug-*.sh - -at_failed_list= -at_ignore_count=0 -divert(2)[]dnl - -# Wrap up the testing suite with summary statistics. - -rm -f at-check-line at-setup-line -at_fail_count=0 -if test -z "$at_failed_list"; then - if test "$at_ignore_count" = 0; then - at_banner="All $at_test_count tests were successful" - else - at_banner="All $at_test_count tests were successful ($at_ignore_count ignored)" - fi -else - echo - echo $at_n "Writing \`debug-NN.sh' scripts, NN =$at_c" - for at_group in $at_failed_list; do - echo $at_n " $at_group$at_c" - ( echo '#!/bin/sh' - sed -n '/^[#] Snippet (1/,/^[#] Snippet )1/p' atconfig - sed -n '/^[#] Snippet (2/,/^[#] Snippet )2/p' atconfig - sed -n "/^[#] Snippet (3/,/^[#] Snippet )3/p" $[0] - test -z "$at_silent" && echo 'at_verbose=:' - sed -n "/^[#] Snippet (4/,/^[#] Snippet )4/p" $[0] - sed -n "/^[#] Snippet (c$at_group(/,/^[#] Snippet )c$at_group)/p" $[0] - at_desc=`sed -n \ - '/^[#] Snippet (d'$at_group'(/,/^[#] Snippet )d'$at_group')/p' $[0] \ - | sed -n '2s/^[#] //p'` - echo 'if $at_verbose; then' - echo ' at_banner="$[0]: '$at_desc'"' - echo ' at_dashes=`echo $at_banner | sed s/./=/g`' - echo ' echo' - echo ' echo "$at_dashes"' - echo ' echo "$at_banner"' - echo ' echo "$at_dashes"' - echo 'fi' - echo - sed -n "/^[#] Snippet (d$at_group(/,/^[#] Snippet )d$at_group)/p" $[0] - sed -n "/^[#] Snippet (s$at_group(/,/^[#] Snippet )s$at_group)/p" $[0] - echo 'exit 0' - ) | grep -v '^[#] Snippet' > debug-$at_group.sh - chmod +x debug-$at_group.sh - at_fail_count=`expr $at_fail_count + 1` - done - echo ', done' - if $at_stop_on_error; then - at_banner='ERROR: One of the tests failed, inhibiting subsequent tests' - else - at_banner="ERROR: Suite unsuccessful, $at_fail_count of $at_test_count tests failed" - fi -fi -at_dashes=`echo $at_banner | sed s/./=/g` -echo -echo "$at_dashes" -echo "$at_banner" -echo "$at_dashes" - -if test -n "$at_failed_list"; then - if test -z "$at_silent"; then - echo - echo 'When reporting failed tests to maintainers, do not merely list test' - echo 'numbers, as the numbering changes between releases and pretests.' - echo 'Be careful to give at least all the information you got about them.' - echo 'You may investigate any problem if you feel able to do so, in which' - echo 'case the generated debugging scripts provide good starting points.' - echo "Go on and modify them at will. \`./debug-NN --help' gives usage" - echo 'information. Now, failed tests will be executed again, verbosely.' - for at_group in $at_failed_list; do - ./debug-$at_group.sh - done - fi - exit 1 -fi - -exit 0 -divert[]dnl -])# AT_INIT - - - -# AT_SETUP(DESCRIPTION) -# --------------------- -# Start a group of related tests, all to be executed in the same subshell. -# The group is testing what DESCRIPTION says. -AT_DEFINE([AT_SETUP], -[AT_DEFINE([AT_ordinal], AT_EVAL(AT_ordinal + 1)) -pushdef([AT_group_description], [$1]) -pushdef([AT_data_files], ) -pushdef([AT_data_expout], ) -pushdef([AT_data_experr], ) -if $at_stop_on_error && test -n "$at_failed_list"; then :; else -divert(1)[]dnl - echo AT_LINE > at-check-line - echo AT_LINE > at-setup-line - if $at_verbose; then - echo 'testing AT_group_description' - echo $at_n " $at_c" - fi - if $at_verbose; then - echo "AT_ordinal. $srcdir/AT_LINE..." - else - echo $at_n "substr(AT_ordinal. $srcdir/AT_LINE , 0, 30)[]$at_c" - fi - if test -z "$at_skip_mode"; then - ( -[#] Snippet (d[]AT_ordinal[]( -[#] Testing AT_group_description -[#] Snippet )d[]AT_ordinal[]) -[#] Snippet (s[]AT_ordinal[]( -[#] starting from `AT_LINE'. -$at_traceon -]) - - -# AT_CLEANUP(FILES) -# ----------------- -# Complete a group of related tests, recursively remove those FILES -# created within the test. There is no need to list stdout, stderr, -# nor files created with AT_DATA. -AT_DEFINE([AT_CLEANUP], -$at_traceoff -[[#] Snippet )s[]AT_ordinal[]) - ) - at_status=$? - $at_verbose && - echo $at_n " AT_ordinal. $srcdir/`cat at-setup-line`: $at_c" - case $at_status in - 0) echo ok - ;; - 77) echo "ignored near \``cat at-check-line`'" - at_ignore_count=`expr $at_ignore_count + 1` - ;; - *) echo "FAILED near \``cat at-check-line`'" - at_failed_list="$at_failed_list AT_ordinal" - ;; - esac - else - echo 'ignored (skipped)' - at_ignore_count=`expr $at_ignore_count + 1` - fi - at_test_count=AT_ordinal - if $at_stop_on_error && test -n "$at_failed_list"; then :; else -divert(0)[]dnl -[#] Snippet (c[]AT_ordinal[]( - -rm ifelse([AT_data_files$1], , [-f], [-rf[]AT_data_files[]ifelse($1, , , [ $1])]) stdout stderr[]AT_data_expout[]AT_data_experr -[#] Snippet )c[]AT_ordinal[]) -undivert(1)[]dnl - rm ifelse([AT_data_files$1], , [-f], [-rf[]AT_data_files[]ifelse($1, , , [ $1])]) stdout stderr[]AT_data_expout[]AT_data_experr - fi -fi -popdef([AT_data_experr]) -popdef([AT_data_expout]) -popdef([AT_data_files]) -popdef([AT_group_description])[]dnl -])# AT_CLEANUP - - -# AT_DATA(FILE, CONTENTS) -# ----------------------- -# Initialize an input data FILE with given CONTENTS, which should end with -# an end of line. -# This macro is not robust to active symbols in CONTENTS *on purpose*. -# If you don't want CONTENT to be evaluated, quote it twice. -AT_DEFINE([AT_DATA], -[AT_DEFINE([AT_data_files], AT_data_files[ ]$1) -cat >$1 <<'_ATEOF' -$2[]_ATEOF -]) - - -# AT_CHECK(COMMANDS, [STATUS], STDOUT, STDERR) -# -------------------------------------------- -# Execute a test by performing given shell COMMANDS. These commands -# should normally exit with STATUS, while producing expected STDOUT and -# STDERR contents. The special word `expout' for STDOUT means that file -# `expout' contents has been set to the expected stdout. The special word -# `experr' for STDERR means that file `experr' contents has been set to -# the expected stderr. -# STATUS is not checked if it is empty. -# STDOUT and STDERR can be the special value `ignore', in which case -# their content is not checked. -AT_DEFINE([AT_CHECK], -[$at_traceoff -$at_verbose && echo "$srcdir/AT_LINE: patsubst([$1], [\([\"`$]\)], \\\1)" -echo AT_LINE > at-check-line -$at_check_stds && exec 5>&1 6>&2 1>stdout 2>stderr -$at_traceon -$1 -ifelse([$2], [], [], -[at_status=$? -if test $at_status != $2; then - $at_verbose && echo "Exit code was $at_status, expected $2" >&6 -dnl Maybe there was an important message to read before it died. - $at_verbose && $at_check_stds && cat stderr >&6 -dnl Preserve exit code 77. - test $at_status = 77 && exit 77 - exit 1 -fi -])dnl -$at_traceoff -if $at_check_stds; then -dnl Restore stdout to fd1 and stderr to fd2. - exec 1>&5 2>&6 -dnl If not verbose, neutralize the output of diff. - $at_verbose || exec 1>/dev/null 2>/dev/null - at_failed=false; - AT_CASE([$4], - ignore, [$at_verbose && cat stderr;:], - experr, [AT_DEFINE([AT_data_experr], [ experr])dnl -$at_diff experr stderr || at_failed=:], - [], [$at_diff empty stderr || at_failed=:], - [echo $at_n "patsubst([$4], [\([\"`$]\)], \\\1)$at_c" | $at_diff - stderr || at_failed=:]) - AT_CASE([$3], - ignore, [$at_verbose && cat stdout;:], - expout, [AT_DEFINE([AT_data_expout], [ expout])dnl -$at_diff expout stdout || at_failed=:], - [], [$at_diff empty stdout || at_failed=:], - [echo $at_n "patsubst([$3], [\([\"`$]\)], \\\1)$at_c" | $at_diff - stdout || at_failed=:]) - if $at_failed; then - exit 1 - else - : - fi -fi -$at_traceon -])# AT_CHECK - - -divert(0)dnl diff --git a/tests/atlocal.in b/tests/atlocal.in new file mode 100644 index 00000000..9a6790af --- /dev/null +++ b/tests/atlocal.in @@ -0,0 +1,10 @@ +# @configure_input@ -*- shell-script -*- +# Configurable variable values for Bison test suite. +# Copyright 2000, 2001 Free Software Foundation, Inc. + +# We need a C compiler. +CC='@CC@' +CFLAGS='@CFLAGS@' + +# We need `config.h'. +CPPFLAGS="-I $top_builddir @CPPFLAGS@" diff --git a/tests/bison.in b/tests/bison.in new file mode 100644 index 00000000..4adaefa6 --- /dev/null +++ b/tests/bison.in @@ -0,0 +1,11 @@ +#! /bin/sh +# @configure_generated@ +# Wrapper around a non installed bison to make it work as an installed one. + +# We want to use the files shipped with Bison. +BISON_SIMPLE='@top_srcpath@/src/bison.simple' +export BISON_SIMPLE +BISON_HAIRY='@top_srcpath@/src/bison.hairy' +export BISON_HAIRY + +exec '@top_buildpath@/src/bison' ${1+"$@"} diff --git a/tests/calc.at b/tests/calc.at index e038eb28..87053158 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -1,11 +1,22 @@ -# -*- Autoconf -*- +# Checking the output filenames. -*- Autotest -*- +# Copyright 2000, 2001 Free Software Foundation, Inc. -cat < +/* We don't need a perfect malloc for these tests. */ +#undef malloc #include #if STDC_HEADERS @@ -211,14 +222,16 @@ power (int base, int exponent) } int -main (int argn, const char **argv) +main (int argc, const char **argv) { - if (argn == 2) + yyin = NULL; + + if (argc == 2) yyin = fopen (argv[1], "r"); else yyin = stdin; - if (!stdin) + if (!yyin) { perror (argv[1]); exit (1); @@ -241,57 +254,83 @@ main (int argn, const char **argv) # AT_DATA_CALC_Y([BISON-OPTIONS]) # ------------------------------- # Produce `calc.y'. -AT_DEFINE([AT_DATA_CALC_Y], +m4_define([AT_DATA_CALC_Y], [_AT_DATA_CALC_Y($[1], $[2], $[3], - [ifelse(regexp([$1], [--yyerror-verbose]), - [-1], [], - [[#define YYERROR_VERBOSE 1]])])]) + [m4_match([$1], [--yyerror-verbose], + [[#define YYERROR_VERBOSE 1]])])]) -# _AT_CHECK_CALC(BISON-OPTIONS, INPUT) -# ------------------------------------ +# _AT_CHECK_CALC(BISON-OPTIONS, INPUT, [NUM-STDERR-LINES = 0]) +# ------------------------------------------------------------ # Run `calc' on INPUT and expect no STDOUT nor STDERR. -# If `--debug' is passed to bison, discard all the debugging traces -# preserving only the `parse errors'. Note that since there should be -# none, the `grep' will fail with exit status 1. -AT_DEFINE([_AT_CHECK_CALC], -[ifelse(regexp([$1], [--debug]), - [-1], - [AT_CHECK([echo "$2" | calc], - [0], [], [])], - [AT_CHECK([echo "$2" | calc 2>&1 >/dev/null | grep 'parse error' >&2], - [1], [], [])])]) - - -# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, INPUT, +# +# If BISON-OPTIONS contains `--debug', then NUM-STDERR-LINES is the number +# of expected lines on stderr. +m4_define([_AT_CHECK_CALC], +[AT_DATA([[input]], +[[$2 +]]) +AT_CHECK([calc input], 0, [], [stderr])dnl +AT_CHECK([wc -l &1 >/dev/null | grep 'parse error' >&2], 0, - [], -[ifelse(regexp([$1], [--location]), - [-1], [], [$3: ])[]dnl +# Run `calc' on INPUT, and expect a `parse error' message. +# +# If BISON-OPTIONS contains `--location', then make sure the ERROR-LOCATION +# is correctly output on stderr. +# +# If BISON-OPTIONS contains `--yyerror-verbose', then make sure the +# IF-YYERROR-VERBOSE message is properly output after `parse error, ' +# on STDERR. +# +# If BISON-OPTIONS contains `--debug', then NUM-STDERR-LINES is the number +# of expected lines on stderr. +m4_define([_AT_CHECK_CALC_ERROR], +[AT_DATA([[input]], +[[$2 +]]) + +AT_CHECK([calc input], 0, [], [stderr]) + + +AT_CHECK([wc -l at-stderr +mv at-stderr stderr + +AT_CHECK([cat stderr], 0, +[m4_match([$1], [--location], [$4: ])[]dnl parse error[]dnl -ifelse(regexp([$1], [--yyerror-verbose]), - [-1], [], [$4])[]dnl +m4_match([$1], [--yyerror-verbose], [, $5])[]dnl + +]) -])]) +]) # AT_CHECK_CALC([BISON-OPTIONS], [PARSER-EXPECTED-STDERR]) # -------------------------------------------------------- # Start a testing chunk which compiles `calc' grammar with # BISON-OPTIONS, and performs several tests over the parser. -AT_DEFINE([AT_CHECK_CALC], +m4_define([AT_CHECK_CALC], [# We use integers to avoid dependencies upon the precision of doubles. AT_SETUP([Calculator $1]) AT_DATA_CALC_Y([$1]) # Specify the output files to avoid problems on different file systems. -AT_CHECK([bison calc.y -o calc.c patsubst([$1], [--yyerror-verbose])], +AT_CHECK([bison calc.y -o calc.c m4_patsubst([$1], [--yyerror-verbose])], [0], [], []) AT_CHECK([$CC $CFLAGS $CPPFLAGS calc.c -o calc], 0, [], []) @@ -309,26 +348,27 @@ _AT_CHECK_CALC([$1], 1 - (2 - 3) = 2 2^2^3 = 256 -(2^2)^3 = 64], [$2]) +(2^2)^3 = 64], [491]) # Some parse errors. -_AT_CHECK_CALC_ERROR([$1], [+1], +_AT_CHECK_CALC_ERROR([$1], [+1], [8], [1.0:1.1], - [, unexpected `'+'']) -_AT_CHECK_CALC_ERROR([$1], [1//2], + [unexpected `'+'']) +_AT_CHECK_CALC_ERROR([$1], [1//2], [17], [1.2:1.3], - [, unexpected `'/'', expecting `NUM' or `'-'' or `'('']) -_AT_CHECK_CALC_ERROR([$1], [error], + [unexpected `'/'', expecting `NUM' or `'-'' or `'('']) +_AT_CHECK_CALC_ERROR([$1], [error], [8], [1.0:1.1], - [, unexpected `$undefined.']) -_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], + [unexpected `$undefined.']) +_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [23], [1.6:1.7], - [, unexpected `'='']) + [unexpected `'='']) _AT_CHECK_CALC_ERROR([$1], [ +1], + [16], [2.0:2.1], - [, unexpected `'+'']) + [unexpected `'+'']) AT_CLEANUP(calc calc.c calc.h calc.output) ])# AT_CHECK_CALC diff --git a/tests/output.at b/tests/output.at new file mode 100644 index 00000000..964e9119 --- /dev/null +++ b/tests/output.at @@ -0,0 +1,70 @@ +# Checking the output filenames. -*- Autotest -*- +# Copyright 2000, 2001 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +AT_BANNER([[Output file names.]]) + + +# AT_CHECK_OUTPUT(INPUT-FILE, [DIRECTIVES], [FLAGS], EXPECTED-FILES) +# ------------------------------------------------------------------ +m4_define([AT_CHECK_OUTPUT], +[AT_SETUP([Output files: $2 & $3.]) +AT_DATA([$1], +[[$2 +%% +foo: {} +]]) + +AT_CHECK([bison $3 $1], 0) +AT_CHECK([ls $4], [], [ignore]) +AT_CLEANUP($4) +]) + +AT_CHECK_OUTPUT([foo.y], [], [-dv], + [foo.output foo.tab.c foo.tab.h]) +AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.c], + [foo.c foo.h foo.output]) +AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.tab.c], + [foo.output foo.tab.c foo.tab.h]) +AT_CHECK_OUTPUT([foo.y], [], [-dv -y], + [y.output y.tab.c y.tab.h]) +AT_CHECK_OUTPUT([foo.y], [], [-dv -b bar], + [bar.output bar.tab.c bar.tab.h]) +AT_CHECK_OUTPUT([foo.y], [], [-dv -g -o foo.c], + [foo.c foo.h foo.output foo.vcg]) + + +AT_CHECK_OUTPUT([foo.y], [%defines %verbose], [], + [foo.output foo.tab.c foo.tab.h]) +AT_CHECK_OUTPUT([foo.y], [%defines %verbose %yacc],[], + [y.output y.tab.c y.tab.h]) + + +# Check priorities of extension control. +AT_CHECK_OUTPUT([foo.yy], [%defines %verbose], [], + [foo.output foo.tab.cc foo.tab.hh]) + +AT_CHECK_OUTPUT([foo.yy], [%defines %verbose ], [-o foo.c], + [foo.c foo.h foo.output]) + +AT_CHECK_OUTPUT([foo.yy], [], + [--defines=foo.hpp -o foo.c++], + [foo.c++ foo.hpp]) + +AT_CHECK_OUTPUT([foo.yy], [], + [-o foo.c++ --graph=foo.gph], + [foo.c++ foo.gph]) diff --git a/tests/regression.at b/tests/regression.at index 8a004831..2be0ea00 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -1,11 +1,22 @@ -# -*- Autoconf -*- +# Bison Regressions. -*- Autotest -*- +# Copyright 2001 Free Software Foundation, Inc. -cat <