-/*------------------------------------------------------------------.
-| TEXT is pointing to a wannabee semantic value (i.e., a `$'). |
-| |
-| Possible inputs: $[<TYPENAME>]($|integer) |
-| |
-| Output to OBSTACK_FOR_STRING a reference to this semantic value. |
-`------------------------------------------------------------------*/
-
-static inline void
-handle_action_dollar (char *text, location loc)
-{
- const char *type_name = NULL;
- char *cp = text + 1;
-
- /* Get the type name if explicit. */
- if (*cp == '<')
- {
- type_name = ++cp;
- while (*cp != '>')
- ++cp;
- *cp = '\0';
- ++cp;
- }
-
- if (*cp == '$')
- {
- if (!type_name)
- type_name = symbol_list_n_type_name_get (current_rule, loc, 0);
- if (!type_name && typed)
- complain_at (loc, _("$$ of `%s' has no declared type"),
- current_rule->sym->tag);
- if (!type_name)
- type_name = "";
- obstack_fgrow1 (&obstack_for_string,
- "]b4_lhs_value([%s])[", type_name);
- }
- else
- {
- long num;
- set_errno (0);
- num = strtol (cp, 0, 10);
-
- if (INT_MIN <= num && num <= rule_length && ! get_errno ())
- {
- int n = num;
- if (!type_name && n > 0)
- type_name = symbol_list_n_type_name_get (current_rule, loc, n);
- if (!type_name && typed)
- complain_at (loc, _("$%d of `%s' has no declared type"),
- n, current_rule->sym->tag);
- if (!type_name)
- type_name = "";
- obstack_fgrow3 (&obstack_for_string,
- "]b4_rhs_value([%d], [%d], [%s])[",
- rule_length, n, type_name);
- }
- else
- complain_at (loc, _("integer out of range: %s"), quote (text));
- }
-}
-
-
-/*---------------------------------------------------------------.
-| TEXT is expected to be $$ in some code associated to a symbol: |
-| destructor or printer. |
-`---------------------------------------------------------------*/
-
-static inline void
-handle_symbol_code_dollar (char *text, location loc)
-{
- char *cp = text + 1;
- if (*cp == '$')
- obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar[");
- else
- complain_at (loc, _("invalid value: %s"), quote (text));
-}
-
-
-/*-----------------------------------------------------------------.
-| Dispatch onto handle_action_dollar, or handle_destructor_dollar, |
-| depending upon CODE_KIND. |
-`-----------------------------------------------------------------*/
-
-static void
-handle_dollar (braced_code braced_code_kind, char *text, location loc)
-{
- switch (braced_code_kind)
- {
- case action_braced_code:
- handle_action_dollar (text, loc);
- break;
-
- case destructor_braced_code:
- case printer_braced_code:
- handle_symbol_code_dollar (text, loc);
- break;
- }
-}
-