bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

c, c++: provide a default definition for N_


From: Akim Demaille
Subject: c, c++: provide a default definition for N_
Date: Mon, 20 Apr 2020 07:38:25 +0200

commit 81334eb5a0cc386568816fa3413d39d9299e10de
Author: Akim Demaille <address@hidden>
Date:   Mon Apr 20 07:32:53 2020 +0200

    c, c++: provide a default definition for N_
    
    In C/C++, N_ is a no-op.  Define it if the user didn't.
    Suggested by Frank Heckenbach.
    https://lists.gnu.org/r/bug-bison/2020-04/msg00010.html
    
    * src/output.c (prepare_symbol_names): Rename has_translations as
    has_translations_flag.
    * data/skeletons/bison.m4 (b4_has_translations_if): New.
    * data/skeletons/java.m4 (b4_trans): Use it.
    
    * data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/yacc.c
    (N_): Provide a default definition.

diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4
index 007d5eb0..1805df1e 100644
--- a/data/skeletons/bison.m4
+++ b/data/skeletons/bison.m4
@@ -369,6 +369,7 @@ m4_define([b4_$3_if],
 # Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
 b4_define_flag_if([defines])            # Whether headers are requested.
 b4_define_flag_if([glr])                # Whether a GLR parser is requested.
+b4_define_flag_if([has_translations])   # Whether some tokens are 
internalionalized.
 b4_define_flag_if([nondeterministic])   # Whether conflicts should be handled.
 b4_define_flag_if([token_table])        # Whether yytoken_table is demanded.
 b4_define_flag_if([yacc])               # Whether POSIX Yacc is emulated.
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index 027476df..13f0d68d 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -261,6 +261,11 @@ static YYLTYPE yyloc_default][]b4_yyloc_default;])[
 #  define YY_(Msgid) Msgid
 # endif
 #endif
+]b4_has_translations_if([
+#ifndef N_
+# define N_(Msgid) Msgid
+#endif
+])[
 
 #ifndef YYFREE
 # define YYFREE free
diff --git a/data/skeletons/java.m4 b/data/skeletons/java.m4
index ba44ce8e..afc5419e 100644
--- a/data/skeletons/java.m4
+++ b/data/skeletons/java.m4
@@ -344,7 +344,7 @@ m4_define([b4_symbol_translate],
 # ----------------
 # Translate a string if i18n is enabled.  Avoid collision with b4_translate.
 m4_define([b4_trans],
-[m4_if(b4_has_translations, 0, [$1], [i18n($1)])])
+[b4_has_translations_if([i18n($1)], [$1])])
 
 
 
diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index 9c9be93c..93106d39 100644
--- a/data/skeletons/lalr1.cc
+++ b/data/skeletons/lalr1.cc
@@ -523,6 +523,11 @@ m4_if(b4_prefix, [yy], [],
 #  define YY_(msgid) msgid
 # endif
 #endif
+]b4_has_translations_if([
+#ifndef N_
+# define N_(Msgid) Msgid
+#endif
+])[
 
 // Whether we are compiled with exception support.
 #ifndef YY_EXCEPTIONS
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index 930b947f..f910f713 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -463,6 +463,11 @@ typedef int yy_state_fast_t;
 #  define YY_(Msgid) Msgid
 # endif
 #endif
+]b4_has_translations_if([
+#ifndef N_
+# define N_(Msgid) Msgid
+#endif
+])[
 
 ]b4_attribute_define[
 
diff --git a/src/output.c b/src/output.c
index b649737d..1871fd75 100644
--- a/src/output.c
+++ b/src/output.c
@@ -259,7 +259,7 @@ prepare_symbol_names (char const *muscle_name)
   muscle_insert (muscle_name, obstack_finish0 (&format_obstack));
 
   /* Announce whether translation support is needed.  */
-  MUSCLE_INSERT_BOOL ("has_translations", has_translations);
+  MUSCLE_INSERT_BOOL ("has_translations_flag", has_translations);
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]