diff options
author | Dave Mitchell <davem@fdisolutions.com> | 2007-01-01 22:37:40 +0000 |
---|---|---|
committer | Dave Mitchell <davem@fdisolutions.com> | 2007-01-01 22:37:40 +0000 |
commit | acdf0a21427feb34aec09f6fd2cf505bb7b2fe2c (patch) | |
tree | 292da697e7bf6762831b6effeb2fd0385f42e5a1 | |
parent | 3d0ef1696a3e8c1da6e82def28f3c8bd02ab1989 (diff) | |
download | perl-acdf0a21427feb34aec09f6fd2cf505bb7b2fe2c.tar.gz |
split parser initialisation from parser execution
p4raw-id: //depot/perl@29652
-rw-r--r-- | embed.fnc | 1 | ||||
-rw-r--r-- | embed.h | 2 | ||||
-rw-r--r-- | parser.h | 2 | ||||
-rw-r--r-- | perly.c | 27 | ||||
-rw-r--r-- | proto.h | 3 | ||||
-rw-r--r-- | toke.c | 20 |
6 files changed, 34 insertions, 21 deletions
@@ -956,6 +956,7 @@ p |void |write_to_stderr|NN const char* message|int msglen p |int |yyerror |NN const char* s p |int |yylex p |int |yyparse +p |void |parser_free |NN const yy_parser * p |int |yywarn |NN const char* s #if defined(MYMALLOC) Ap |void |dump_mstats |NN char* s @@ -976,6 +976,7 @@ #define yyerror Perl_yyerror #define yylex Perl_yylex #define yyparse Perl_yyparse +#define parser_free Perl_parser_free #define yywarn Perl_yywarn #endif #if defined(MYMALLOC) @@ -3183,6 +3184,7 @@ #define yyerror(a) Perl_yyerror(aTHX_ a) #define yylex() Perl_yylex(aTHX) #define yyparse() Perl_yyparse(aTHX) +#define parser_free(a) Perl_parser_free(aTHX_ a) #define yywarn(a) Perl_yywarn(aTHX_ a) #endif #if defined(MYMALLOC) @@ -9,6 +9,8 @@ * and lexer (perly.c, toke,c). */ +#define YYEMPTY (-2) + typedef struct { YYSTYPE val; /* semantic value */ short state; @@ -45,7 +45,6 @@ typedef signed char yysigned_char; # define YYSIZE_T size_t -#define YYEMPTY (-2) #define YYEOF 0 #define YYTERROR 1 @@ -187,9 +186,6 @@ do { \ # define YY_REDUCE_PRINT(Rule) #endif /* !DEBUGGING */ -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#define YYINITDEPTH 200 - /* called during cleanup (via SAVEDESTRUCTOR_X) to free any items on the * parse stack, thus avoiding leaks if we die */ @@ -300,8 +296,8 @@ S_clear_yystack(pTHX_ const yy_parser *parser) /* delete a parser object */ -static void -S_parser_free(pTHX_ const yy_parser *parser) +void +Perl_parser_free(pTHX_ const yy_parser *parser) { S_clear_yystack(aTHX_ parser); Safefree(parser->stack); @@ -334,7 +330,7 @@ Perl_yyparse (pTHX) #define YYPOPSTACK parser->ps = --ps #define YYPUSHSTACK parser->ps = ++ps - /* The variables used to return semantic value and location from the + /* The variable used to return semantic value and location from the action routines: ie $$. */ YYSTYPE yyval; @@ -347,22 +343,11 @@ Perl_yyparse (pTHX) YYDPRINTF ((Perl_debug_log, "Starting parse\n")); - Newx(parser, 1, yy_parser); - parser->old_parser = PL_parser; - PL_parser = parser; - - Newx(ps, YYINITDEPTH, yy_stack_frame); - parser->stack = ps; - parser->ps = ps; - parser->stack_size = YYINITDEPTH; + parser = PL_parser; + ps = parser->ps; ENTER; /* force parser free before we return */ - SAVEDESTRUCTOR_X(S_parser_free, (void*) parser); - - - ps->state = 0; - parser->yyerrstatus = 0; - parser->yychar = YYEMPTY; /* Cause a token to be read. */ + SAVEDESTRUCTOR_X(Perl_parser_free, (void*) parser); /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | @@ -2597,6 +2597,9 @@ PERL_CALLCONV int Perl_yyerror(pTHX_ const char* s) PERL_CALLCONV int Perl_yylex(pTHX); PERL_CALLCONV int Perl_yyparse(pTHX); +PERL_CALLCONV void Perl_parser_free(pTHX_ const yy_parser *) + __attribute__nonnull__(pTHX_1); + PERL_CALLCONV int Perl_yywarn(pTHX_ const char* s) __attribute__nonnull__(pTHX_1); @@ -25,6 +25,9 @@ #define yylval (PL_parser->yylval) +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#define YYINITDEPTH 200 + static const char ident_too_long[] = "Identifier too long"; static const char commaless_variable_list[] = "comma-less variable list"; @@ -580,6 +583,23 @@ Perl_lex_start(pTHX_ SV *line) dVAR; const char *s; STRLEN len; + yy_parser *parser; + + /* create and initialise a parser */ + + Newx(parser, 1, yy_parser); + parser->old_parser = PL_parser; + PL_parser = parser; + + Newx(parser->stack, YYINITDEPTH, yy_stack_frame); + parser->ps = parser->stack; + parser->stack_size = YYINITDEPTH; + + parser->stack->state = 0; + parser->yyerrstatus = 0; + parser->yychar = YYEMPTY; /* Cause a token to be read. */ + + /* initialise lexer state */ SAVEI32(PL_lex_dojoin); SAVEI32(PL_lex_brackets); |