/* Reverse of muscle_location_grow. */
static location
-location_decode (char const *key)
+location_decode (char const *value)
{
location loc;
- char const *value = muscle_find_const (key);
aver (value);
aver (*value == '[');
aver (*++value == '[');
/* Don't complain is VARIABLE is already defined, but be sure to set
its value to VAL. */
- if (!muscle_find_const (name))
- muscle_percent_define_insert (variable, loc, muscle_keyword, val,
- MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
- if (muscle_percent_define_flag_if (variable) != value)
+ if (!muscle_find_const (name)
+ || muscle_percent_define_flag_if (variable) != value)
muscle_percent_define_insert (variable, loc, muscle_keyword, val,
MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
}
muscle_insert (muscle_name (variable, "bison_variables"), "");
}
+/* The value of %define variable VARIABLE (corresponding to FIELD, if
+ defined). Do not register as used, but diagnose unset variables. */
+
+static
+char const *
+muscle_percent_define_get_raw (char const *variable, char const *field)
+{
+ uniqstr name = muscle_name (variable, field);
+ char const *res = muscle_find_const (name);
+ if (!res)
+ complain (NULL, fatal, _("%s: undefined %%define variable %s"),
+ "muscle_percent_define_get_raw", quote (variable));
+ return res;
+}
+
char *
muscle_percent_define_get (char const *variable)
{
return value;
}
+/* The kind of VARIABLE. An error if undefined. */
+static muscle_kind
+muscle_percent_define_get_kind (char const *variable)
+{
+ return muscle_kind_new (muscle_percent_define_get_raw (variable, "kind"));
+}
+
+/* Check the kind of VARIABLE. An error if undefined. */
+static void
+muscle_percent_define_check_kind (char const *variable, muscle_kind kind)
+{
+ if (muscle_percent_define_get_kind (variable) != kind)
+ {
+ location loc = muscle_percent_define_get_loc (variable);
+ switch (kind)
+ {
+ case muscle_code:
+ complain (&loc, Wdeprecated,
+ "%%define variable '%s' requires '{...}' values",
+ variable);
+ break;
+ case muscle_keyword:
+ complain (&loc, Wdeprecated,
+ "%%define variable '%s' requires keyword values",
+ variable);
+ break;
+ case muscle_string:
+ complain (&loc, Wdeprecated,
+ "%%define variable '%s' requires '\"...\"' values",
+ variable);
+ break;
+ }
+ }
+}
+
+
location
muscle_percent_define_get_loc (char const *variable)
{
- uniqstr loc_name = muscle_name (variable, "loc");
- if (!muscle_find_const (loc_name))
- complain (NULL, fatal, _("%s: undefined %%define variable %s"),
- "muscle_percent_define_get_loc", quote (variable));
- return location_decode (loc_name);
+ return location_decode (muscle_percent_define_get_raw (variable, "loc"));
}
char const *
muscle_percent_define_get_syncline (char const *variable)
{
- uniqstr syncline_name = muscle_name (variable, "syncline");
- char const *syncline = muscle_find_const (syncline_name);
- if (!syncline)
- complain (NULL, fatal, _("%s: undefined %%define variable %s"),
- "muscle_percent_define_get_syncline", quote (variable));
- return syncline;
+ return muscle_percent_define_get_raw (variable, "syncline");
}
bool
if (muscle_percent_define_ifdef (variable))
{
char *value = muscle_percent_define_get (variable);
+ muscle_percent_define_check_kind (variable, muscle_keyword);
if (value[0] == '\0' || STREQ (value, "true"))
result = true;
else if (STREQ (value, "false"))
muscle_percent_define_default (char const *variable, char const *value)
{
uniqstr name = muscle_name (variable, NULL);
- uniqstr loc_name = muscle_name (variable, "loc");
- uniqstr syncline_name = muscle_name (variable, "syncline");
if (!muscle_find_const (name))
{
- location loc;
MUSCLE_INSERT_STRING (name, value);
- loc.start.file = loc.end.file = "<default value>";
- loc.start.line = loc.end.line = -1;
- loc.start.column = loc.end.column = -1;
- muscle_insert (loc_name, "");
- muscle_location_grow (loc_name, loc);
- muscle_insert (syncline_name, "");
+ MUSCLE_INSERT_STRING (muscle_name (variable, "kind"), "keyword");
+ {
+ uniqstr loc_name = muscle_name (variable, "loc");
+ location loc;
+ loc.start.file = loc.end.file = "<default value>";
+ loc.start.line = loc.end.line = -1;
+ loc.start.column = loc.end.column = -1;
+ muscle_insert (loc_name, "");
+ muscle_location_grow (loc_name, loc);
+ }
+ muscle_insert (muscle_name (variable, "syncline"), "");
}
}
char const * const *variablep = values;
uniqstr name = muscle_name (*variablep, NULL);
char *value = string_decode (name);
+ muscle_percent_define_check_kind (*variablep, muscle_keyword);
if (value)
{
for (++values; *values; ++values)