mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
Extend the front-end API for %define variables to more completely
mirror the back-end. This will be useful in the future. * data/bison.m4 (b4_percent_define_get, b4_percent_define_ifdef): Update comments to mention the new front-end counterparts of these macros. * src/muscle_tab.c (MUSCLE_COMMON_DECODE): New macro with common code for muscle_string_decode and muscle_location_decode. (muscle_string_decode): New static function. (muscle_location_decode): Use MUSCLE_COMMON_DECODE. (muscle_percent_define_get, muscle_percent_define_ifdef): New functions. (muscle_percent_define_flag_if): Use muscle_percent_define_ifdef and muscle_percent_define_get to mimic the b4_percent_define_flag_if implementation more closely. (muscle_percent_define_invalid_value): New function. * src/muscle_tab.h (muscle_percent_define_get, muscle_percent_define_ifdef, muscle_percent_define_invalid_value): Prototype.
This commit is contained in:
21
ChangeLog
21
ChangeLog
@@ -1,3 +1,24 @@
|
|||||||
|
2007-05-20 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
|
Extend the front-end API for %define variables to more completely
|
||||||
|
mirror the back-end. This will be useful in the future.
|
||||||
|
* data/bison.m4 (b4_percent_define_get, b4_percent_define_ifdef):
|
||||||
|
Update comments to mention the new front-end counterparts of these
|
||||||
|
macros.
|
||||||
|
* src/muscle_tab.c (MUSCLE_COMMON_DECODE): New macro with common code
|
||||||
|
for muscle_string_decode and muscle_location_decode.
|
||||||
|
(muscle_string_decode): New static function.
|
||||||
|
(muscle_location_decode): Use MUSCLE_COMMON_DECODE.
|
||||||
|
(muscle_percent_define_get, muscle_percent_define_ifdef): New
|
||||||
|
functions.
|
||||||
|
(muscle_percent_define_flag_if): Use muscle_percent_define_ifdef and
|
||||||
|
muscle_percent_define_get to mimic the b4_percent_define_flag_if
|
||||||
|
implementation more closely.
|
||||||
|
(muscle_percent_define_invalid_value): New function.
|
||||||
|
* src/muscle_tab.h (muscle_percent_define_get,
|
||||||
|
muscle_percent_define_ifdef, muscle_percent_define_invalid_value):
|
||||||
|
Prototype.
|
||||||
|
|
||||||
2007-05-07 Joel E. Denny <jdenny@ces.clemson.edu>
|
2007-05-07 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
* NEWS (2.3a+): Mention yesterday's state-removal change.
|
* NEWS (2.3a+): Mention yesterday's state-removal change.
|
||||||
|
|||||||
@@ -338,7 +338,8 @@ m4_popdef([b4_end])dnl
|
|||||||
|
|
||||||
# b4_percent_define_get(VARIABLE)
|
# b4_percent_define_get(VARIABLE)
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
# If the %define variable VARIABLE is defined, emit its value. Also, record
|
# Mimic muscle_percent_define_get in ../src/muscle_tab.h exactly. That is, if
|
||||||
|
# the %define variable VARIABLE is defined, emit its value. Also, record
|
||||||
# Bison's usage of VARIABLE by defining
|
# Bison's usage of VARIABLE by defining
|
||||||
# b4_percent_define_bison_variables(VARIABLE).
|
# b4_percent_define_bison_variables(VARIABLE).
|
||||||
#
|
#
|
||||||
@@ -351,7 +352,8 @@ m4_ifdef([b4_percent_define(]$1[)], [m4_indir([b4_percent_define(]$1[)])])])
|
|||||||
|
|
||||||
# b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE])
|
# b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE])
|
||||||
# ------------------------------------------------------
|
# ------------------------------------------------------
|
||||||
# If the %define variable VARIABLE is defined, expand IF-TRUE, else expand
|
# Mimic muscle_percent_define_ifdef in ../src/muscle_tab.h exactly. That is,
|
||||||
|
# if the %define variable VARIABLE is defined, expand IF-TRUE, else expand
|
||||||
# IF-FALSE. Also, record Bison's usage of VARIABLE by defining
|
# IF-FALSE. Also, record Bison's usage of VARIABLE by defining
|
||||||
# b4_percent_define_bison_variables(VARIABLE).
|
# b4_percent_define_bison_variables(VARIABLE).
|
||||||
#
|
#
|
||||||
|
|||||||
121
src/muscle_tab.c
121
src/muscle_tab.c
@@ -275,6 +275,52 @@ muscle_location_grow (char const *key, location loc)
|
|||||||
muscle_grow (key, "]]", "");
|
muscle_grow (key, "]]", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MUSCLE_COMMON_DECODE(Value) \
|
||||||
|
case '$': \
|
||||||
|
aver (*++(Value) == ']'); \
|
||||||
|
aver (*++(Value) == '['); \
|
||||||
|
obstack_sgrow (&muscle_obstack, "$"); \
|
||||||
|
break; \
|
||||||
|
case '@': \
|
||||||
|
switch (*++(Value)) \
|
||||||
|
{ \
|
||||||
|
case '@': obstack_sgrow (&muscle_obstack, "@" ); break; \
|
||||||
|
case '{': obstack_sgrow (&muscle_obstack, "[" ); break; \
|
||||||
|
case '}': obstack_sgrow (&muscle_obstack, "]" ); break; \
|
||||||
|
default: aver (false); break; \
|
||||||
|
} \
|
||||||
|
break; \
|
||||||
|
default: \
|
||||||
|
obstack_1grow (&muscle_obstack, *(Value)); \
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Reverse of MUSCLE_OBSTACK_SGROW. */
|
||||||
|
static char *
|
||||||
|
muscle_string_decode (char const *key)
|
||||||
|
{
|
||||||
|
char const *value;
|
||||||
|
char *value_decoded;
|
||||||
|
char *result;
|
||||||
|
|
||||||
|
value = muscle_find_const (key);
|
||||||
|
if (!value)
|
||||||
|
return NULL;
|
||||||
|
do {
|
||||||
|
switch (*value)
|
||||||
|
{
|
||||||
|
MUSCLE_COMMON_DECODE (value)
|
||||||
|
case '[':
|
||||||
|
case ']':
|
||||||
|
aver (false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (*value++);
|
||||||
|
value_decoded = obstack_finish (&muscle_obstack);
|
||||||
|
result = xstrdup (value_decoded);
|
||||||
|
obstack_free (&muscle_obstack, value_decoded);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* Reverse of muscle_location_grow. */
|
/* Reverse of muscle_location_grow. */
|
||||||
static location
|
static location
|
||||||
muscle_location_decode (char const *key)
|
muscle_location_decode (char const *key)
|
||||||
@@ -287,20 +333,7 @@ muscle_location_decode (char const *key)
|
|||||||
while (*++value)
|
while (*++value)
|
||||||
switch (*value)
|
switch (*value)
|
||||||
{
|
{
|
||||||
case '$':
|
MUSCLE_COMMON_DECODE (value)
|
||||||
aver (*++value == ']');
|
|
||||||
aver (*++value == '[');
|
|
||||||
obstack_sgrow (&muscle_obstack, "$");
|
|
||||||
break;
|
|
||||||
case '@':
|
|
||||||
switch (*++value)
|
|
||||||
{
|
|
||||||
case '@': obstack_sgrow (&muscle_obstack, "@" ); break;
|
|
||||||
case '{': obstack_sgrow (&muscle_obstack, "[" ); break;
|
|
||||||
case '}': obstack_sgrow (&muscle_obstack, "]" ); break;
|
|
||||||
default: aver (false); break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '[':
|
case '[':
|
||||||
aver (false);
|
aver (false);
|
||||||
break;
|
break;
|
||||||
@@ -330,9 +363,6 @@ muscle_location_decode (char const *key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
obstack_1grow (&muscle_obstack, *value);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
aver (false);
|
aver (false);
|
||||||
return loc;
|
return loc;
|
||||||
@@ -385,13 +415,51 @@ muscle_percent_define_insert (char const *variable, location variable_loc,
|
|||||||
variable_loc);
|
variable_loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
muscle_percent_define_get (char const *variable)
|
||||||
|
{
|
||||||
|
char const *name;
|
||||||
|
char const *usage_name;
|
||||||
|
char *value;
|
||||||
|
|
||||||
|
MUSCLE_USER_NAME_CONVERT (name, "percent_define(", variable, ")");
|
||||||
|
MUSCLE_USER_NAME_CONVERT (usage_name, "percent_define_bison_variables(",
|
||||||
|
variable, ")");
|
||||||
|
|
||||||
|
muscle_insert (usage_name, "");
|
||||||
|
value = muscle_string_decode (name);
|
||||||
|
if (!value)
|
||||||
|
value = xstrdup ("");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
muscle_percent_define_ifdef (char const *variable)
|
||||||
|
{
|
||||||
|
char const *name;
|
||||||
|
char const *usage_name;
|
||||||
|
char const *value;
|
||||||
|
|
||||||
|
MUSCLE_USER_NAME_CONVERT (name, "percent_define(", variable, ")");
|
||||||
|
MUSCLE_USER_NAME_CONVERT (usage_name, "percent_define_bison_variables(",
|
||||||
|
variable, ")");
|
||||||
|
|
||||||
|
value = muscle_find_const (name);
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
muscle_insert (usage_name, "");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
muscle_percent_define_flag_if (char const *variable)
|
muscle_percent_define_flag_if (char const *variable)
|
||||||
{
|
{
|
||||||
char const *name;
|
char const *name;
|
||||||
char const *loc_name;
|
char const *loc_name;
|
||||||
char const *usage_name;
|
char const *usage_name;
|
||||||
char const *value;
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
MUSCLE_USER_NAME_CONVERT (name, "percent_define(", variable, ")");
|
MUSCLE_USER_NAME_CONVERT (name, "percent_define(", variable, ")");
|
||||||
@@ -399,9 +467,9 @@ muscle_percent_define_flag_if (char const *variable)
|
|||||||
MUSCLE_USER_NAME_CONVERT (usage_name, "percent_define_bison_variables(",
|
MUSCLE_USER_NAME_CONVERT (usage_name, "percent_define_bison_variables(",
|
||||||
variable, ")");
|
variable, ")");
|
||||||
|
|
||||||
value = muscle_find_const (name);
|
if (muscle_percent_define_ifdef (variable))
|
||||||
if (value)
|
|
||||||
{
|
{
|
||||||
|
char *value = muscle_percent_define_get (variable);
|
||||||
if (value[0] == '\0' || 0 == strcmp (value, "true"))
|
if (value[0] == '\0' || 0 == strcmp (value, "true"))
|
||||||
result = true;
|
result = true;
|
||||||
else if (0 == strcmp (value, "false"))
|
else if (0 == strcmp (value, "false"))
|
||||||
@@ -410,13 +478,12 @@ muscle_percent_define_flag_if (char const *variable)
|
|||||||
complain_at(muscle_location_decode (loc_name),
|
complain_at(muscle_location_decode (loc_name),
|
||||||
_("invalid value for %%define boolean variable `%s'"),
|
_("invalid value for %%define boolean variable `%s'"),
|
||||||
variable);
|
variable);
|
||||||
|
free (value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fatal(_("undefined %%define variable `%s' passed to muscle_percent_define_flag_if"),
|
fatal(_("undefined %%define variable `%s' passed to muscle_percent_define_flag_if"),
|
||||||
variable);
|
variable);
|
||||||
|
|
||||||
muscle_insert (usage_name, "");
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,6 +506,16 @@ muscle_percent_define_default (char const *variable, char const *value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
muscle_percent_define_invalid_value (char const *variable)
|
||||||
|
{
|
||||||
|
char const *loc_name;
|
||||||
|
MUSCLE_USER_NAME_CONVERT (loc_name, "percent_define_loc(", variable, ")");
|
||||||
|
complain_at(muscle_location_decode (loc_name),
|
||||||
|
_("invalid value for %%define variable `%s'"), variable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
muscle_percent_code_grow (char const *qualifier, location qualifier_loc,
|
muscle_percent_code_grow (char const *qualifier, location qualifier_loc,
|
||||||
char const *code, location code_loc)
|
char const *code, location code_loc)
|
||||||
|
|||||||
@@ -131,6 +131,19 @@ void muscle_user_name_list_grow (char const *key, char const *user_name,
|
|||||||
void muscle_percent_define_insert (char const *variable, location variable_loc,
|
void muscle_percent_define_insert (char const *variable, location variable_loc,
|
||||||
char const *value);
|
char const *value);
|
||||||
|
|
||||||
|
/* Mimic b4_percent_define_get in ../data/bison.m4 exactly. That is, if the
|
||||||
|
%define variable VARIABLE is defined, return its value. Otherwise, return
|
||||||
|
the empty string. Also, record Bison's usage of VARIABLE by defining
|
||||||
|
b4_percent_define_bison_variables(VARIABLE). The caller is responsible for
|
||||||
|
freeing the memory of the returned string. */
|
||||||
|
char *muscle_percent_define_get (char const *variable);
|
||||||
|
|
||||||
|
/* Mimic b4_percent_define_ifdef in ../data/bison.m4 exactly. That is, if the
|
||||||
|
%define variable VARIABLE is defined, return true. Otherwise, return false.
|
||||||
|
Also, record Bison's usage of VARIABLE by defining
|
||||||
|
b4_percent_define_bison_variables(VARIABLE). */
|
||||||
|
bool muscle_percent_define_ifdef (char const *variable);
|
||||||
|
|
||||||
/* Mimic b4_percent_define_flag_if in ../data/bison.m4 exactly. That is, if
|
/* Mimic b4_percent_define_flag_if in ../data/bison.m4 exactly. That is, if
|
||||||
the %define variable VARIABLE is defined to "" or "true", return true. If
|
the %define variable VARIABLE is defined to "" or "true", return true. If
|
||||||
it is defined to "false", return false. Complain if it is undefined (a
|
it is defined to "false", return false. Complain if it is undefined (a
|
||||||
@@ -145,6 +158,10 @@ bool muscle_percent_define_flag_if (char const *variable);
|
|||||||
suspect that the value has yet influenced the output. */
|
suspect that the value has yet influenced the output. */
|
||||||
void muscle_percent_define_default (char const *variable, char const *value);
|
void muscle_percent_define_default (char const *variable, char const *value);
|
||||||
|
|
||||||
|
/* Complain that the value set for the %define variable VARIABLE is
|
||||||
|
invalid. */
|
||||||
|
void muscle_percent_define_invalid_value (char const *variable);
|
||||||
|
|
||||||
/* Grow the muscle for the %code qualifier QUALIFIER appearing at QUALIFIER_LOC
|
/* Grow the muscle for the %code qualifier QUALIFIER appearing at QUALIFIER_LOC
|
||||||
in the grammar file with code CODE appearing at CODE_LOC. Record this as a
|
in the grammar file with code CODE appearing at CODE_LOC. Record this as a
|
||||||
grammar occurrence of VARIABLE by invoking muscle_user_name_list_grow. */
|
grammar occurrence of VARIABLE by invoking muscle_user_name_list_grow. */
|
||||||
|
|||||||
Reference in New Issue
Block a user