From b8351d06f1fd37abfc1a84d165c09a7b9a794695 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 9 Oct 2018 18:58:50 +0200 Subject: [PATCH] C++: issue a better CPP guard and Doxygen file command Currently we use "" as \file argument, and as base for the CPP guard. This is not nice when is absolute, in which case it is expected that the user will use api.location.include to get something nicer. If defined, use that name instead. * data/location.cc (b4_location_path): New. Use it. * tests/c++.at (Shared locations): Check the guard and Doxygen doc. --- data/location.cc | 27 +++++++++++++++++++++------ tests/c++.at | 11 +++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/data/location.cc b/data/location.cc index 44a1f5ab..1b46055c 100644 --- a/data/location.cc +++ b/data/location.cc @@ -37,12 +37,27 @@ b4_percent_define_ifdef([[api.position.file]], b4_percent_define_check_file([b4_location_file], [[api.location.file]], b4_defines_if([[location.hh]])) + +# b4_location_include +# ------------------- # If location.hh is to be generated, the name under which should it be # included. +# +# b4_location_path +# ---------------- +# The path to use for the CPP guard. m4_ifdef([b4_location_file], - [m4_define([b4_location_include], - [b4_percent_define_get([[api.location.include]], - ["b4_location_file"])])]) +[m4_define([b4_location_include], + [b4_percent_define_get([[api.location.include]], + ["b4_location_file"])]) + m4_define([b4_location_path], + b4_percent_define_get([[api.location.include]], + ["b4_dir_prefix[]b4_location_file"])) + m4_define([b4_location_path], + m4_substr(m4_defn([b4_location_path]), 1, m4_eval(m4_len(m4_defn([b4_location_path])) - 2))) + ]) + + # b4_location_define # ------------------ @@ -331,11 +346,11 @@ m4_ifdef([b4_location_file], [[ ]b4_copyright([Locations for Bison parsers in C++])[ /** - ** \file ]b4_dir_prefix[]b4_location_file[ + ** \file ]b4_location_path[ ** Define the ]b4_namespace_ref[::location class. */ -]b4_cpp_guard_open([b4_dir_prefix[]b4_location_file])[ +]b4_cpp_guard_open([b4_location_path])[ # include // std::max # include @@ -346,7 +361,7 @@ m4_ifdef([b4_location_file], [[ ]b4_namespace_open[ ]b4_location_define[ ]b4_namespace_close[ -]b4_cpp_guard_close([b4_dir_prefix[]b4_location_file])[ +]b4_cpp_guard_close([b4_location_path])[ ]b4_output_end[ ]]) diff --git a/tests/c++.at b/tests/c++.at index 2b354c2d..33fbd52e 100644 --- a/tests/c++.at +++ b/tests/c++.at @@ -1324,6 +1324,8 @@ AT_FOR_EACH_CXX([AT_COMPILE_CXX([[input]])]) AT_CLEANUP + + ## ------------------ ## ## Shared locations. ## ## ------------------ ## @@ -1368,6 +1370,15 @@ AT_TEST([x1], %define api.location.file "include/ast/loc.hh" %define api.location.include {}]) +# Check the CPP guard and Doxyen comments. +AT_CHECK([sed -ne '/INCLUDED/p;/\\file/{p;n;p;}' include/ast/loc.hh], [], +[[ ** \file ast/loc.hh + ** Define the x1::location class. +#ifndef YY_YY_AST_LOC_HH_INCLUDED +# define YY_YY_AST_LOC_HH_INCLUDED +#endif // !YY_YY_AST_LOC_HH_INCLUDED +]]) + AT_TEST([x2], [%defines %locations