From 8d34ee63f69e61c352acfbc94fbc451621645053 Mon Sep 17 00:00:00 2001 From: Roger Ferrer Ibanez Date: Fri, 22 Dec 2017 11:57:41 +0000 Subject: [PATCH] Changes for graph-glr You will need a bison with graph glr to test this. --- Makefile.am | 19 +++++++++++++++++++ configure.ac | 39 +++++++++++++++++++++++++++++++++++++++ src/frontend/cxx03.y.in | 11 ++++++++--- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 51933c3ea5..ab71c14680 100644 --- a/Makefile.am +++ b/Makefile.am @@ -423,6 +423,9 @@ EXTRA_DIST += src/frontend/c99-scanner.c EXTRA_DIST += src/frontend/cxx03.l EXTRA_DIST += src/frontend/cxx03.y +if ENABLE_GRAPH_GLR +EXTRA_DIST += src/frontend/cxx03-glr.y +endif EXTRA_DIST += src/frontend/cxx03.y.in EXTRA_DIST += src/frontend/cxx-scanner.c @@ -461,6 +464,9 @@ BUILT_SOURCES += src/frontend/cxx03.l BUILT_SOURCES += src/frontend/c99.y BUILT_SOURCES += src/frontend/cxx03.y +if ENABLE_GRAPH_GLR +BUILT_SOURCES += src/frontend/cxx03-glr.y +endif BUILT_SOURCES += src/frontend/cxx-parser.h BUILT_SOURCES += src/frontend/c99-parser.h @@ -593,16 +599,29 @@ CLEANFILES += src/frontend/cxx-parser.c CLEANFILES += src/frontend/cxx-parser-internal.h CLEANFILES += src/frontend/cxx-parser.output CLEANFILES += src/frontend/cxx03.y +if ENABLE_GRAPH_GLR +CLEANFILES += src/frontend/cxx03-glr.y +endif endif src/frontend/cxx03.y : $(TPP) $(top_srcdir)/src/frontend/cxx03.y.in $(addprefix $(top_srcdir)/, $(ADDITIONAL_GRAMMARS)) $(TPP_verbose)(rm -f src/frontend/cxx03.y && $(TPP) -o src/frontend/cxx03.y -D CPLUSPLUS -I$(top_srcdir)/src/frontend $(top_srcdir)/src/frontend/cxx03.y.in && chmod -w src/frontend/cxx03.y) +src/frontend/cxx03-glr.y : $(TPP) $(top_srcdir)/src/frontend/cxx03.y.in $(addprefix $(top_srcdir)/, $(ADDITIONAL_GRAMMARS)) + $(TPP_verbose)(rm -f src/frontend/cxx03-glr.y && $(TPP) -o src/frontend/cxx03-glr.y -D CPLUSPLUS -D GRAPH_GLR -I$(top_srcdir)/src/frontend $(top_srcdir)/src/frontend/cxx03.y.in && chmod -w src/frontend/cxx03-glr.y) + src/frontend/cxx-parser-internal.h : src/frontend/cxx-parser.c if BISON_BUILDING +if ENABLE_GRAPH_GLR +src/frontend/cxx-parser.c : src/frontend/cxx03-glr.y + rm -f src/frontend/cxx-parser.c + $(BISON_verbose)$(BISON) -pmcxx --debug --defines=src/frontend/cxx-parser-internal.h --report=all --output=src/frontend/cxx-parser.c src/frontend/cxx03-glr.y + chmod -w src/frontend/cxx-parser.c +else src/frontend/cxx-parser.c : src/frontend/cxx03.y $(BISON_verbose)$(BISON) -pmcxx --debug --defines=src/frontend/cxx-parser-internal.h --report=all --output=src/frontend/cxx-parser.c src/frontend/cxx03.y endif +endif # These are obtained when invoking bison, if we write a rule like 'a b : d' it # breaks parallel compilations since bison gets invoked twice. diff --git a/configure.ac b/configure.ac index d37ca60b34..574ef78947 100644 --- a/configure.ac +++ b/configure.ac @@ -1904,6 +1904,7 @@ flex_good=no force_bison=no bison_good=no +enable_graph_glr=no force_gperf=no gperf_good=no @@ -2020,6 +2021,35 @@ then esac fi + if test x$bison_good = xyes; + then + dnl Check if the current bison supports %graph-glr-parser + AC_MSG_CHECKING([bison supports %graph-glr-parser]) + + # Mini grammar file using %graph-glr + cat < tmp.y +%graph-glr-parser +%token A +%start test + +%% +test : A +; +EOF + + AS_IF([$BISON -o /dev/null tmp.y &> /dev/null], + [ + enable_graph_glr=yes + AC_MSG_RESULT([yes]) + ], + [ + AC_MSG_RESULT([no]) + ] + ) + + rm -f tmp.y + fi + dnl Check gperf AC_ARG_ENABLE([gperf-regeneration], AS_HELP_STRING([--enable-gperf-regeneration], [Forces gperf regeneration, even if the version is not recommended or properly detected.]), @@ -2074,6 +2104,14 @@ AM_CONDITIONAL([BISON_BUILDING], test x$bison_good = xyes) AM_CONDITIONAL([FLEX_BUILDING], test x$flex_good = xyes) AM_CONDITIONAL([GPERF_BUILDING], test x$gperf_good = xyes) +ENABLE_GRAPH_GLR=$enable_graph_glr +AC_SUBST([ENABLE_GRAPH_GLR]) +AM_CONDITIONAL([ENABLE_GRAPH_GLR], test x$enable_graph_glr = xyes) +if test x$enable_graph_glr = xyes; +then + AC_DEFINE([ENABLE_GRAPH_GLR], 1, [Define to 1 if the Graph GLR algorithm is used]) +fi + dnl --------------------- End of Regeneration files --------------------- dnl --------------------- Type environments ----------------------------- @@ -2520,6 +2558,7 @@ print_tool() print_tool "Flex " "$FLEX" print_tool "GNU bison " "$BISON" +echo " - Graph GLR is enabled:" $enable_graph_glr print_tool "GNU gperf " "$GPERF" print_tool "git content tracker" "$GIT" diff --git a/src/frontend/cxx03.y.in b/src/frontend/cxx03.y.in index fb18984f51..41dc014b42 100644 --- a/src/frontend/cxx03.y.in +++ b/src/frontend/cxx03.y.in @@ -51,7 +51,12 @@ %} +/*!ifnot GRAPH_GLR*/ %glr-parser +/*!endif*/ +/*!if GRAPH_GLR*/ +%graph-glr-parser +/*!endif*/ %union { token_atrib_t token_atrib; @@ -64,9 +69,6 @@ }; -// This is a specific feature of rofi-bison 2.3 -// %default-merge - %parse-param {AST* parsed_tree} %locations @@ -4891,6 +4893,9 @@ nested_name_specifier_0 : class_or_namespace_name $$ = $1; } | decltype_specifier +{ + $$ = $1; +} ; nested_name_specifier_1 : nested_name_specifier_0