Skip to content

Commit

Permalink
Move all the signature param parsing logic out of perly.y into a help…
Browse files Browse the repository at this point in the history
…er API

Provide a subsignature_*() API

Added:
 * subsignature_start()
 * subsignature_append_slurpy()
 * subsignature_append_positional()
 * subsignature_finish()

Call these from code blocks in perly.y

Make the actual parser signature struct opaque, hidden in toke.c. This
gives it much more robustness against future modifications.
  • Loading branch information
leonerd committed Jan 31, 2025
1 parent 65e079e commit 00a408e
Show file tree
Hide file tree
Showing 10 changed files with 1,653 additions and 1,583 deletions.
13 changes: 13 additions & 0 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -3090,6 +3090,19 @@ ATdmp |bool |strict_utf8_to_uv \
CRp |NV |str_to_version |NN SV *sv
: Used in pp_ctl.c
p |void |sub_crush_depth|NN CV *cv
: Used in perly.y
p |void |subsignature_append_positional \
|NULLOK OP *varop \
|OPCODE defmode \
|NULLOK OP *defexpr
p |void |subsignature_append_slurpy \
|I32 sigil \
|NULLOK OP *varop
p |OP * |subsignature_finish
p |yy_parser_signature *|subsignature_parser_dup \
|NULLOK const yy_parser_signature * const proto \
|NN CLONE_PARAMS * const param
p |void |subsignature_start
Adp |void |suspend_compcv |NN struct suspended_compcv *buffer
ATdip |void |SvAMAGIC_off |NN SV *sv
ATdip |void |SvAMAGIC_on |NN SV *sv
Expand Down
5 changes: 5 additions & 0 deletions embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,11 @@
# define sighandler1 Perl_sighandler1
# define sighandler3 Perl_sighandler3
# define sub_crush_depth(a) Perl_sub_crush_depth(aTHX_ a)
# define subsignature_append_positional(a,b,c) Perl_subsignature_append_positional(aTHX_ a,b,c)
# define subsignature_append_slurpy(a,b) Perl_subsignature_append_slurpy(aTHX_ a,b)
# define subsignature_finish() Perl_subsignature_finish(aTHX)
# define subsignature_parser_dup(a,b) Perl_subsignature_parser_dup(aTHX_ a,b)
# define subsignature_start() Perl_subsignature_start(aTHX)
# define sv_2num(a) Perl_sv_2num(aTHX_ a)
# define sv_clean_all() Perl_sv_clean_all(aTHX)
# define sv_clean_objs() Perl_sv_clean_objs(aTHX)
Expand Down
9 changes: 5 additions & 4 deletions parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ typedef struct yy_lexshared {
SV *re_eval_str; /* "(?{...})" text */
} LEXSHARED;

/* Opaque struct of data relevant during parsing and construction of a
* subroutine signature. Defined and used exclusively by toke.c */
typedef struct yy_parser_signature yy_parser_signature;

typedef struct yy_parser {

/* parser state */
Expand Down Expand Up @@ -112,10 +116,7 @@ typedef struct yy_parser {
line_t herelines; /* number of lines in here-doc */
line_t preambling; /* line # when processing $ENV{PERL5DB} */

/* these are valid while parsing a subroutine signature */
UV sig_elems; /* number of signature elements seen so far */
UV sig_optelems; /* number of optional signature elems seen */
char sig_slurpy; /* the sigil of the slurpy var (or null) */
yy_parser_signature *signature; /* parser state of a subroutine signature */
bool sig_seen; /* the currently parsing sub has a signature */

bool recheck_charset_validity;
Expand Down
Loading

0 comments on commit 00a408e

Please sign in to comment.