aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-parse.in
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2002-04-26 23:53:07 -0700
committerRichard Henderson <rth@gcc.gnu.org>2002-04-26 23:53:07 -0700
commit94a503970399749ed551946b22b9226512480d81 (patch)
treebd925997654b688081b11a738196c7806d4cef5f /gcc/c-parse.in
parent9c0a0632bca68c00acf45fc5ccc6811a652d1406 (diff)
downloadgcc-94a503970399749ed551946b22b9226512480d81.zip
gcc-94a503970399749ed551946b22b9226512480d81.tar.gz
gcc-94a503970399749ed551946b22b9226512480d81.tar.bz2
c-parse.in (malloced_yyss, [...]): New.
* c-parse.in (malloced_yyss, malloced_yyvs): New. (yyoverflow): Re-add. Set them. (free_parser_stacks): New. * c-common.h: Declare it. * c-lex.c (c_common_parse_file): Call it. * parse.y (malloced_yyss, malloced_yyvs): New. (yyoverflow): Re-add. Set them. (free_parser_stacks): New. From-SVN: r52827
Diffstat (limited to 'gcc/c-parse.in')
-rw-r--r--gcc/c-parse.in55
1 files changed, 55 insertions, 0 deletions
diff --git a/gcc/c-parse.in b/gcc/c-parse.in
index ff279a1..679d42d 100644
--- a/gcc/c-parse.in
+++ b/gcc/c-parse.in
@@ -61,6 +61,49 @@ end ifobjc
/* Like YYERROR but do call yyerror. */
#define YYERROR1 { yyerror ("syntax error"); YYERROR; }
+
+/* Like the default stack expander, except (1) use realloc when possible,
+ (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
+
+ Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
+ give malloced_yyvs its proper type. This is ok since all we need from
+ it is to be able to free it. */
+
+static short *malloced_yyss;
+static void *malloced_yyvs;
+
+#define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ) \
+do { \
+ size_t newsize; \
+ short *newss; \
+ YYSTYPE *newvs; \
+ newsize = *(YYSSZ) *= 2; \
+ if (malloced_yyss) \
+ { \
+ newss = (short *) \
+ really_call_realloc (*(SS), newsize * sizeof (short)); \
+ newvs = (YYSTYPE *) \
+ really_call_realloc (*(VS), newsize * sizeof (YYSTYPE)); \
+ } \
+ else \
+ { \
+ newss = (short *) really_call_malloc (newsize * sizeof (short)); \
+ newvs = (YYSTYPE *) really_call_malloc (newsize * sizeof (YYSTYPE)); \
+ if (newss) \
+ memcpy (newss, *(SS), (SSSIZE)); \
+ if (newvs) \
+ memcpy (newvs, *(VS), (VSSIZE)); \
+ } \
+ if (!newss || !newvs) \
+ { \
+ yyerror (MSG); \
+ return 2; \
+ } \
+ *(SS) = newss; \
+ *(VS) = newvs; \
+ malloced_yyss = newss; \
+ malloced_yyvs = (void *) newvs; \
+} while (0)
%}
%start program
@@ -3908,3 +3951,15 @@ make_pointer_declarator (type_quals_attrs, target)
itarget = tree_cons (attrs, target, NULL_TREE);
return build1 (INDIRECT_REF, quals, itarget);
}
+
+/* Free malloced parser stacks if necessary. */
+
+void
+free_parser_stacks ()
+{
+ if (malloced_yyss)
+ {
+ free (malloced_yyss);
+ free (malloced_yyvs);
+ }
+}