Skip to content

Commit f258133

Browse files
committed
toke.c: S_is_existing_identifier: Generalize a bit
This commit adds a parameter to this function to allow it to work with a different sigil than is in the string. This allows it to see if there is an identifier with the same name but a different type. The next commit will use this generality.
1 parent b7e7d5c commit f258133

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

embed.fnc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6086,6 +6086,7 @@ S |int |intuit_more |NN char *s \
60866086
S |Size_t |is_existing_identifier \
60876087
|NN char *s \
60886088
|NN char *e \
6089+
|char sigil \
60896090
|bool is_utf8
60906091
S |I32 |lop |enum yytokentype t \
60916092
|I32 f \

embed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@
16851685
# define incline(a,b) S_incline(aTHX_ a,b)
16861686
# define intuit_method(a,b,c) S_intuit_method(aTHX_ a,b,c)
16871687
# define intuit_more(a,b) S_intuit_more(aTHX_ a,b)
1688-
# define is_existing_identifier(a,b,c) S_is_existing_identifier(aTHX_ a,b,c)
1688+
# define is_existing_identifier(a,b,c,d) S_is_existing_identifier(aTHX_ a,b,c,d)
16891689
# define lop(a,b,c,d) S_lop(aTHX_ a,b,c,d)
16901690
# define missingterm(a,b) S_missingterm(aTHX_ a,b)
16911691
# define parse_ident(a,b,c,d,e,f) S_parse_ident(aTHX_ a,b,c,d,e,f)

proto.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

toke.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,11 +4468,14 @@ S_scan_const(pTHX_ char *start)
44684468
}
44694469

44704470
STATIC Size_t
4471-
S_is_existing_identifier(pTHX_ char *s, char *e, bool is_utf8)
4471+
S_is_existing_identifier(pTHX_ char *s, char *e, char sigil, bool is_utf8)
44724472
{
44734473
/* This checks if the string from 's' to (e - 1) with utf8ness 'is_utf8' is
4474-
* an identifier known to the program. If so, it returns the length of
4475-
* the identifier. If not, it returns 0 */
4474+
* an identifier known to the program of the type given by 'sigil'. So for
4475+
* sigil '$', it checks for a scalar, etc. If so, it returns the length of
4476+
* the identifier. If not, it returns 0
4477+
*
4478+
* It overwrites s[0], restoring it before returning */
44764479

44774480
ptrdiff_t size = e - s;
44784481

@@ -4493,26 +4496,30 @@ S_is_existing_identifier(pTHX_ char *s, char *e, bool is_utf8)
44934496
char * tmpbuf;
44944497
Newx(tmpbuf, size, char);
44954498

4499+
const char save_sigil = s[0];
4500+
s[0] = sigil;
4501+
44964502
/* scan_ident doesn't return the sigil, but pad_findmy_pv wants it */
44974503
scan_ident(s, tmpbuf + 1, size - 1, FALSE);
4498-
tmpbuf[0] = s[0];
4504+
tmpbuf[0] = sigil;
44994505

45004506
Size_t len = strlen(tmpbuf) - 1; /* Doesn't include sigil */
45014507

45024508
PADOFFSET slot = pad_findmy_pv(tmpbuf, 0);
45034509
if ( slot == NOT_IN_PAD
45044510
&& ! gv_fetchpvn_flags(tmpbuf + 1, len,
45054511
(is_utf8) ? SVf_UTF8 : 0,
4506-
(s[0] == '@')
4512+
(sigil == '@')
45074513
? SVt_PVAV
4508-
: (s[0] == '&')
4514+
: (sigil == '&')
45094515
? SVt_PVCV
45104516
: SVt_PV))
45114517
{
45124518
len = 0;
45134519
}
45144520

45154521
Safefree(tmpbuf);
4522+
s[0] = save_sigil;
45164523

45174524
return len;
45184525
}
@@ -4695,7 +4702,7 @@ S_intuit_more(pTHX_ char *s, char *e)
46954702
* identifier already found in the program by that name and type.
46964703
* If so, strongly suspect this isn't a character class */
46974704
if (isWORDCHAR_lazy_if_safe(s+1, PL_bufend, UTF)) {
4698-
Size_t len = is_existing_identifier(s, PL_bufend, UTF);
4705+
Size_t len = is_existing_identifier(s, PL_bufend, s[0], UTF);
46994706

47004707
/* We only mark this as strongly suspect subscript if the
47014708
* identifier is multi-char; otherwise mildly suspect (even if

0 commit comments

Comments
 (0)