[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
@$ in destructor
From: |
Akim Demaille |
Subject: |
@$ in destructor |
Date: |
19 Jun 2002 10:22:53 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter) |
Index: ChangeLog
from Akim Demaille <address@hidden>
Prepare @$ in %destructor, but currently don't bind it in the
skeleton, as %location use is not cleaned up yet.
* src/scan-gram.l (handle_dollar, handle_destructor_at)
(handle_action_at): New.
(handle_at, handle_action_dollar, handle_destructor_dollar): Take
a braced_code_t and a location as additional arguments.
(handle_destructor_dollar): Instead of requiring `b4_eval', just
unquote one when outputting `b4_dollar_dollar'.
Adjust callers.
* data/bison.simple (b4_eval): Remove.
(b4_symbol_destructor): Adjust.
* tests/input.at (Invalid @n): Adjust.
Index: data/bison.simple
===================================================================
RCS file: /cvsroot/bison/bison/data/bison.simple,v
retrieving revision 1.37
diff -u -u -r1.37 bison.simple
--- data/bison.simple 18 Jun 2002 11:37:20 -0000 1.37
+++ data/bison.simple 19 Jun 2002 08:21:48 -0000
@@ -1275,21 +1275,13 @@
`-------------------------------------------------*/
m4_divert_push([KILL])# M4 code.
-# b4_eval
-# -------
-# FIXME: This is really wrong, we no longer guarantee we don't evaluate
-# the user's input. This demonstrates that decoding actions (BRACED_CODE)
-# ought to be done when output, not when read.
-m4_define([b4_eval],
-[$*])
-
# b4_symbol_destructor(SYMBOL-NUMBER, DESTRUCTOR, TYPE-NAME)
# ----------------------------------------------------------
m4_define([b4_symbol_destructor],
[m4_pushdef([b4_dollar_dollar], [symbol_value.$6])dnl
case $4: /* $3 */
#line $2 "$1"
- b4_eval($5);
+ $5;
#line __oline__ "__ofile__"
break;
m4_popdef([b4_dollar_dollar])])
Index: src/scan-gram.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-gram.l,v
retrieving revision 1.11
diff -u -u -r1.11 scan-gram.l
--- src/scan-gram.l 17 Jun 2002 08:43:11 -0000 1.11
+++ src/scan-gram.l 19 Jun 2002 08:21:48 -0000
@@ -76,13 +76,13 @@
}
-
static int braces_level = 0;
static int percent_percent_count = 0;
-static void handle_action_dollar PARAMS ((char *cp, location_t location));
-static void handle_destructor_dollar PARAMS ((char *cp, location_t location));
-static void handle_at PARAMS ((char *cp));
+static void handle_dollar PARAMS ((braced_code_t code_kind,
+ char *cp, location_t location));
+static void handle_at PARAMS ((braced_code_t code_kind,
+ char *cp, location_t location));
%}
%x SC_COMMENT
@@ -443,19 +443,10 @@
"{" YY_OBS_GROW; braces_level++;
- "$"("<"[^>]+">")?(-?[0-9]+|"$") {
- switch (current_braced_code)
- {
- case action_braced_code:
- handle_action_dollar (yytext, *yylloc);
- break;
-
- case destructor_braced_code:
- handle_destructor_dollar (yytext, *yylloc);
- break;
- }
- }
- "@"(-?[0-9]+|"$") { handle_at (yytext); }
+ "$"("<"[^>]+">")?(-?[0-9]+|"$") { handle_dollar (current_braced_code,
+ yytext, *yylloc); }
+ "@"(-?[0-9]+|"$") { handle_at (current_braced_code,
+ yytext, *yylloc); }
address@hidden/\'\"\{\}\n\r]+ YY_OBS_GROW;
{eols} YY_OBS_GROW; YY_LINES;
@@ -532,7 +523,7 @@
| Output to the STRING_OBSTACK a reference to this semantic value. |
`------------------------------------------------------------------*/
-static void
+static inline void
handle_action_dollar (char *cp, location_t location)
{
const char *type_name = NULL;
@@ -596,21 +587,17 @@
}
-/*---------------------------------------------------------------.
-| CP is pointing to $$ in a destructor. This should probably be |
-| done once the grammar completely parsed, instead of during its |
-| parsing, since that means %type must be specified before |
-| %destructor. |
-`---------------------------------------------------------------*/
+/*---------------------------------------.
+| CP is pointing to $$ in a destructor. |
+`---------------------------------------*/
-static void
+static inline void
handle_destructor_dollar (char *cp, location_t location)
{
++cp;
if (*cp == '$')
{
- /* FIXME: We should find something more robust. */
- obstack_sgrow (&string_obstack, "b4_dollar_dollar");
+ obstack_sgrow (&string_obstack, "]b4_dollar_dollar[");
}
else
{
@@ -620,32 +607,55 @@
}
}
-/*-------------------------------------------------------.
-| CP is pointing to a location (i.e., a `@'). Output to |
-| STRING_OBSTACK a reference to this location. |
-`-------------------------------------------------------*/
+
+/*-----------------------------------------------------------------.
+| Dispatch onto handle_action_dollar, or handle_destructor_dollar, |
+| depending upon CODE_KIND. |
+`-----------------------------------------------------------------*/
static void
-handle_at (char *cp)
+handle_dollar (braced_code_t braced_code_kind,
+ char *text, location_t location)
+{
+ switch (braced_code_kind)
+ {
+ case action_braced_code:
+ handle_action_dollar (text, location);
+ break;
+
+ case destructor_braced_code:
+ handle_destructor_dollar (text, location);
+ break;
+ }
+}
+
+
+/*------------------------------------------------------.
+| TEXT is a location token (i.e., a address@hidden'). Output to |
+| STRING_OBSTACK a reference to this location. |
+`------------------------------------------------------*/
+
+static inline void
+handle_action_at (char *text, location_t location)
{
locations_flag = 1;
- ++cp;
+ ++text;
- if (*cp == '$')
+ if (*text == '$')
{
obstack_sgrow (&string_obstack, "]b4_lhs_location[");
}
- else if (isdigit (*cp) || *cp == '-')
+ else if (isdigit (*text) || *text == '-')
{
/* RULE_LENGTH is the number of values in the current rule so
far, which says where to find `$0' with respect to the top of
the stack. It is not the same as the rule->length in the
case of mid rule actions. */
int rule_length = symbol_list_length (current_rule->next);
- int n = strtol (cp, &cp, 10);
+ int n = strtol (text, &text, 10);
if (n > rule_length)
- complain (_("invalid value: %s%d"), "@", n);
+ complain_at (location, _("invalid value: %s%d"), "@", n);
else
obstack_fgrow2 (&string_obstack, "]b4_rhs_location([%d], [%d])[",
rule_length, n);
@@ -653,17 +663,69 @@
else
{
char buf[] = "@c";
- buf[1] = *cp;
- complain (_("%s is invalid"), quote (buf));
+ buf[1] = *text;
+ complain_at (location, _("%s is invalid"), quote (buf));
}
}
+
+/*--------------------------------------------.
+| TEXT is expexted tp be @$ in a destructor. |
+`--------------------------------------------*/
+
+static inline void
+handle_destructor_at (char *text, location_t location)
+{
+ ++text;
+ if (*text == '$')
+ {
+ obstack_sgrow (&string_obstack, "]b4_at_dollar[");
+ }
+ else
+ {
+ char buf[] = "$c";
+ buf[1] = *text;
+ complain_at (location, _("%s is invalid"), quote (buf));
+ }
+}
+
+
+/*-------------------------------------------------------------------.
+| Dispatch onto handle_action_at, or handle_destructor_at, depending |
+| upon CODE_KIND. |
+`-------------------------------------------------------------------*/
+
+static void
+handle_at (braced_code_t braced_code_kind,
+ char *text, location_t location)
+{
+ switch (braced_code_kind)
+ {
+ case action_braced_code:
+ handle_action_at (text, location);
+ break;
+
+ case destructor_braced_code:
+ handle_destructor_at (text, location);
+ break;
+ }
+}
+
+
+/*-------------------------.
+| Initialize the scanner. |
+`-------------------------*/
+
void
scanner_initialize (void)
{
obstack_init (&string_obstack);
}
+
+/*-----------------------------------------------.
+| Free all the memory allocated to the scanner. |
+`-----------------------------------------------*/
void
scanner_free (void)
Index: tests/input.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/input.at,v
retrieving revision 1.7
diff -u -u -r1.7 input.at
--- tests/input.at 17 Jun 2002 07:04:49 -0000 1.7
+++ tests/input.at 19 Jun 2002 08:21:48 -0000
@@ -75,7 +75,7 @@
]])
AT_CHECK([bison input.y], [1], [],
-[[input.y:2: invalid value: @1
+[[input.y:2.6-14: invalid value: @1
]])
AT_CLEANUP
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- @$ in destructor,
Akim Demaille <=