Skip to content

Commit aa93969

Browse files
committed
toke.c: Create function to see if an identifier is known
This checks first if there is a lexical variable in scope with the given name, and if not, if there is a global
1 parent 087dc7f commit aa93969

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

embed.fnc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6154,6 +6154,11 @@ S |int |intuit_method |NN char *start \
61546154
|NULLOK NOCHECK CV *cv
61556155
S |int |intuit_more |NN char *s \
61566156
|NN char *e
6157+
S |bool |is_existing_identifier \
6158+
|NN char *s \
6159+
|Size_t len \
6160+
|char sigil \
6161+
|bool is_utf8
61576162
S |I32 |lop |enum yytokentype t \
61586163
|I32 f \
61596164
|U8 x \

embed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +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,d) S_is_existing_identifier(aTHX_ a,b,c,d)
16881689
# define lop(a,b,c,d) S_lop(aTHX_ a,b,c,d)
16891690
# define missingterm(a,b) S_missingterm(aTHX_ a,b)
16901691
# define parse_ident(a,b,c,d,e,f) S_parse_ident(aTHX_ a,b,c,d,e,f)

proto.h

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

toke.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4464,6 +4464,33 @@ S_scan_const(pTHX_ char *start)
44644464
return s;
44654465
}
44664466

4467+
STATIC bool
4468+
S_is_existing_identifier(pTHX_ char *s, Size_t len, char sigil, bool is_utf8)
4469+
{
4470+
PERL_ARGS_ASSERT_IS_EXISTING_IDENTIFIER;
4471+
4472+
/* This returns a boolean indicating if a string represents an identifier
4473+
* known to the program. 'sigil' is the character indicating the type of
4474+
* the identifier to look for. (though '%' is currently not specially
4475+
* handled.) The string from 's + 1' to (s + len) is looked at. s[0] is
4476+
* ignored, but must exist; the function overwrites it temporarily,
4477+
* restoring it before returning */
4478+
4479+
char save_sigil = s[0];
4480+
s[0] = sigil;
4481+
PADOFFSET slot = pad_findmy_pv(s, 0);
4482+
s[0] = save_sigil;
4483+
4484+
return slot != NOT_IN_PAD
4485+
|| gv_fetchpvn_flags(s + 1, len - 1,
4486+
(is_utf8) ? SVf_UTF8 : 0,
4487+
(sigil == '@')
4488+
? SVt_PVAV
4489+
: (sigil == '&')
4490+
? SVt_PVCV
4491+
: SVt_PV);
4492+
}
4493+
44674494
/* S_intuit_more
44684495
* Returns TRUE if there's more to the expression (e.g., a subscript),
44694496
* FALSE otherwise.

0 commit comments

Comments
 (0)