Skip to content

Commit 0b0c873

Browse files
committed
Build accessor methods by using parser subsignature_*() functions
This removes a bunch of special-case logic from `class.c`, making it behave much more similar to regular user-defined methods in the way it creates the signature-handling part of its optree.
1 parent aeaf125 commit 0b0c873

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

class.c

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,26 +1099,18 @@ apply_field_attribute_reader(pTHX_ PADNAME *pn, SV *value)
10991099

11001100
I32 save_ix = block_start(TRUE);
11011101

1102+
subsignature_start();
1103+
11021104
PADOFFSET padix;
11031105

11041106
padix = pad_add_name_pvs("$self", 0, NULL, NULL);
11051107
assert(padix == PADIX_SELF);
11061108

1109+
OP *sigop = subsignature_finish();
1110+
11071111
padix = pad_import_field(pn);
11081112
intro_my();
11091113

1110-
OP *argcheckop;
1111-
{
1112-
struct op_argcheck_aux *aux = (struct op_argcheck_aux *)
1113-
PerlMemShared_malloc(sizeof(*aux));
1114-
1115-
aux->params = 0;
1116-
aux->opt_params = 0;
1117-
aux->slurpy = 0;
1118-
1119-
argcheckop = newUNOP_AUX(OP_ARGCHECK, 0, NULL, (UNOP_AUX_item *)aux);
1120-
}
1121-
11221114
OP *retop;
11231115
{
11241116
OPCODE optype = 0;
@@ -1135,7 +1127,7 @@ apply_field_attribute_reader(pTHX_ PADNAME *pn, SV *value)
11351127
}
11361128

11371129
OP *ops = newLISTOPn(OP_LINESEQ, 0,
1138-
argcheckop,
1130+
sigop,
11391131
retop,
11401132
NULL);
11411133

@@ -1149,18 +1141,6 @@ apply_field_attribute_reader(pTHX_ PADNAME *pn, SV *value)
11491141
CvIsMETHOD_on(cv);
11501142
}
11511143

1152-
/* If '@_' is called "snail", then elements of it can be called "slugs"; i.e.
1153-
* snails out of their container. */
1154-
#define newSLUGOP(idx) S_newSLUGOP(aTHX_ idx)
1155-
static OP *
1156-
S_newSLUGOP(pTHX_ IV idx)
1157-
{
1158-
assert(idx >= 0 && idx <= 255);
1159-
OP *op = newGVOP(OP_AELEMFAST, 0, PL_defgv);
1160-
op->op_private = idx;
1161-
return op;
1162-
}
1163-
11641144
static void
11651145
apply_field_attribute_writer(pTHX_ PADNAME *pn, SV *value)
11661146
{
@@ -1186,36 +1166,35 @@ apply_field_attribute_writer(pTHX_ PADNAME *pn, SV *value)
11861166

11871167
I32 save_ix = block_start(TRUE);
11881168

1169+
subsignature_start();
1170+
11891171
PADOFFSET padix;
11901172

11911173
padix = pad_add_name_pvs("$self", 0, NULL, NULL);
11921174
assert(padix == PADIX_SELF);
11931175

1194-
padix = pad_import_field(pn);
1176+
/* param pad variable doesn't technically need a name, so don't bother as
1177+
* reusing the field name will provoke a warning */
1178+
PADOFFSET param_padix = padix = pad_add_name_pvn("$", 1, 0, NULL, NULL);
11951179
intro_my();
11961180

1197-
OP *argcheckop;
1198-
{
1199-
struct op_argcheck_aux *aux = (struct op_argcheck_aux *)
1200-
PerlMemShared_malloc(sizeof(*aux));
1181+
subsignature_append_positional(param_padix, 0, NULL);
12011182

1202-
aux->params = 1;
1203-
aux->opt_params = 0;
1204-
aux->slurpy = 0;
1183+
OP *sigop = subsignature_finish();
12051184

1206-
argcheckop = newUNOP_AUX(OP_ARGCHECK, 0, NULL, (UNOP_AUX_item *)aux);
1207-
}
1185+
padix = pad_import_field(pn);
1186+
intro_my();
12081187

12091188
OP *assignop = newBINOP(OP_SASSIGN, 0,
1210-
newSLUGOP(0),
1189+
newPADxVOP(OP_PADSV, 0, param_padix),
12111190
newPADxVOP(OP_PADSV, OPf_MOD|OPf_REF, padix));
12121191

12131192
OP *retop = newLISTOP(OP_RETURN, 0,
12141193
newOP(OP_PUSHMARK, 0),
12151194
newPADxVOP(OP_PADSV, 0, PADIX_SELF));
12161195

12171196
OP *ops = newLISTOPn(OP_LINESEQ, 0,
1218-
argcheckop,
1197+
sigop,
12191198
assignop,
12201199
retop,
12211200
NULL);

0 commit comments

Comments
 (0)