summaryrefslogtreecommitdiff
path: root/perly.c
Commit message (Collapse)AuthorAgeFilesLines
* perl.h, pp_ctl.c - switch to standard way of terminating compilationYves Orton2023-02-201-1/+2
| | | | | | I did not fully understand the use of yyquit() when I implemented the SYNTAX_ERROR related stuff. It is not needed, and switching to this makes eval compile error messages more consistent.
* style: Detabify indentation of the C code maintained by the core.Michael G. Schwern2021-01-171-49/+49
| | | | | | | | | | | This just detabifies to get rid of the mixed tab/space indentation. Applying consistent indentation and dealing with other tabs are another issue. Done with `expand -i`. * vutil.* left alone, it's part of version. * Left regen managed files alone for now.
* perly.y: avoid <0 test on unsigned valueDavid Mitchell2020-12-081-3/+3
| | | | | | | | | | | | | | | | | | Coverity CID 313707 Moving to a newer version of Bison has changed how the YYTRANSLATE() macro is defined: in particular it now has a <0 test, which Coverity is complaining about, since the arg is an unsigned value. This commit just casts the arg back to a signed value. In more detail: we formerly had: yytoken = YYTRANSLATE(NATIVE_TO_UNI(parser->yychar)); yychar is of type int, but NATIVE_TO_UNI returns a UV. So just cast the result back to an int: yytoken = YYTRANSLATE((int)NATIVE_TO_UNI(parser->yychar));
* Add support for Bison versions up to 3.7Dagfinn Ilmari Mannsåker2020-08-061-0/+18
| | | | | | | | | | | This requires copying the `YY_CAST` and `YY_ATTRIBUTE_UNUSED` macros from the generated code, and extracting the `yysymbol_kind_t` enum if it's defined. We must also handle token type names with escaped double-quotes in them, since it now names the `YYEOF` and `YYUNDEF` tokens `"end of file"` and `"invalid token"` instead of `$end` and `$undefined`, respectively.
* Remove use of dVAR in coreDagfinn Ilmari Mannsåker2020-07-201-1/+0
| | | | | It only does anything under PERL_GLOBAL_STRUCT, which is gone. Keep the dNOOP defintion for CPAN back-compat
* perly.c: Fix typo in commentKarl Williamson2019-04-291-1/+1
|
* perly.c: Clarify commentKarl Williamson2017-02-131-5/+5
|
* yyparse(): extend parser stack before every shift.David Mitchell2016-12-101-28/+20
| | | | | | | | | | | | | | This reverts v5.25.7-60-gb2c9b6e and adds a test. In that previous commit of mine, for efficiency I changed it so that it checked and extended the parser stack only after every reduce rather than every shift, but when it did check, it extended it by at least 15 slots to allow for all the elements of the longest possible rule to be shifted. Turns out this was bad reasoning. The following type of code can shift indefinitely without ever reducing: [{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
* perly.c: silence a -Wempty-body warningDavid Mitchell2016-12-071-1/+2
| | | | | perly.c:350:21: warning: suggest braces around empty body in an ‘if’ statement [ -Wempty-body]
* yyparse: only calculate yytoken on yychar changeDavid Mitchell2016-12-051-22/+28
| | | | | | | | yytoken is a translated (via lookup table) version of parser->yychar. So we only need to recalculate it when yychar changes (usually by assigning the result of yylex() to it). This means when multiple reductions are done without shifting another token, we skip the extra overhead each time.
* yyparse(): only check stack size in outer loopDavid Mitchell2016-12-051-22/+28
| | | | | | Rather than checking before each individual shift whether the parse stack needs extending, only check once per rule, making sure there's enough space to shift all the items for the longest possible rule
* yyparse: reindentDavid Mitchell2016-12-051-216/+215
| | | | | | whitespace-only. The previous commit wrapped the main body of code in a while (1) { ...}
* yyparse: replace yynewstate label with while(1) {}David Mitchell2016-12-051-7/+4
| | | | makes the code easier to understand
* yyparse: eliminate yyreduce labelDavid Mitchell2016-12-051-15/+15
| | | | Makes things slightly simpler.
* yyparse: reindentDavid Mitchell2016-12-051-97/+97
| | | | whitespace-only; previous commit wrapped a block of code in while (1){}
* yyparse: replace some gotos with a while(1) loopDavid Mitchell2016-12-051-7/+6
| | | | | Just as efficient, and more readable. Welcome to 1970's structured programming!
* optimising yyparse: avoid a < 0 checkDavid Mitchell2016-12-051-2/+4
| | | | | casting to unsigned allows (0 <= yyn <= YYLAST) to be done in a single conditional.
* optimising yyparse: replace stack_size with a ptrDavid Mitchell2016-12-051-10/+12
| | | | Makes testing whether the parser stack needs extending cheaper
* Change white space to avoid C++ deprecation warningKarl Williamson2016-11-181-3/+3
| | | | | | | | | | | | | | | | | | | | | | C++11 requires space between the end of a string literal and a macro, so that a feature can unambiguously be added to the language. Starting in g++ 6.2, the compiler emits a warning when there isn't a space (presumably so that future versions can support C++11). Unfortunately there are many such instances in the perl core. This commit fixes those, including those in ext/, but individual commits will be used for the other modules, those in dist/ and cpan/. This commit also inserts space at the end of a macro before a string literal, even though that is not deprecated, and removes useless "" literals following a macro (instead of inserting a blank). The result is easier to read, making the macro stand out, and be clearer as to the intention. Code and modules included with the Perl core need to be compilable using C++. This is so that perl can be embedded in C++ programs. (Actually, only the hdr files need to be so compilable, but it would be hard to test that just the hdrs are compilable.) So we need to accommodate changes to the C++ language.
* sub signatures: use parser rather than lexerDavid Mitchell2016-08-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Currently the signature of a sub (i.e. the '($a, $b = 1)' bit) is parsed in toke.c using a roll-your-own mini-parser. This commit makes the signature be part of the general grammar in perly.y instead. In theory it should still generate the same optree as before, except that an OP_STUB is no longer appended to each signature optree: it's unnecessary, and I assume that was a hangover from early development of the original signature code. Error messages have changed somewhat: the generic 'Parse error' has changed to the generic 'syntax error', with the addition of ', near "xyz"' now appended to each message. Also, some specific error messages have been added; for example (@a=1) now says that slurpy params can't have a default vale, rather than just giving 'Parse error'. It introduces a new lexer expect state, XSIGVAR, since otherwise when the lexer saw something like '($, ...)' it would see the identifier '$,' rather than the tokens '$' and ','. Since it no longer uses parse_termexpr(), it is no longer subject to the bug (#123010) associated with that; so sub f($x = print, $y) {} is no longer mis-interpreted as sub f($x = print($_, $y)) {}
* Add support for bison 3.0David Mitchell2016-02-031-0/+10
| | | | | | Mainly it no longer generates some tables used for debugging. This commit also adds a new define showing what bison version was used.
* Tentative fix for RT#125350 - AFL detected crash.Shlomi Fish2015-09-171-1/+1
|
* Replace common Emacs file-local variables with dir-localsDagfinn Ilmari Mannsåker2015-03-221-6/+0
| | | | | | | | | | | | | | | | An empty cpan/.dir-locals.el stops Emacs using the core defaults for code imported from CPAN. Committer's work: To keep t/porting/cmp_version.t and t/porting/utils.t happy, $VERSION needed to be incremented in many files, including throughout dist/PathTools. perldelta entry for module updates. Add two Emacs control files to MANIFEST; re-sort MANIFEST. For: RT #124119.
* perly.c: Emit nl after ‘Reading a token’Father Chrysostomos2015-01-071-1/+1
| | | | This makes the -DTp output easier to read.
* perly.c: Fix EBCDIC bugKarl Williamson2014-12-091-10/+10
| | | | | | | The code was changing the value in a structure on EBCDIC platforms. It turns out that that structure element is used later under quite limited circumstances. The changed value is actually only needed during an array look-up, so we no longer store the change.
* perly.c: Fix off-by-1 error for EBCDIC platformsKarl Williamson2014-12-031-2/+2
| | | | | | Code point 255 was being omitted in the translation. It's better to use the macro (that has it correctly) and avoid a redundant copy of the test.
* Remove or downgrade unnecessary dVAR.Jarkko Hietaniemi2014-06-251-1/+0
| | | | | | | | You need to configure with g++ *and* -Accflags=-DPERL_GLOBAL_STRUCT or -Accflags=-DPERL_GLOBAL_STRUCT_PRIVATE to see any difference. (g++ does not do the "post-annotation" form of "unused".) The version code has some of these issues, reported upstream.
* Remove MAD.Jarkko Hietaniemi2014-06-131-42/+0
| | | | | | MAD = Misc Attribute Decoration; unmaintained attempt at preserving the Perl parse tree more faithfully so that automatic conversion to Perl 6 would have been easier.
* Silence several -Wunused-parameter warnings about my_perlBrian Fraser2014-06-131-0/+1
| | | | | | | | This meant sprinkling some PERL_UNUSED_CONTEXT invocations, as well as stopping some functions from getting my_perl in the first place; all of the functions in the latter category are internal (S_ prefix and s or i in embed.fnc), so this should be both safe and economical.
* subroutine signaturesZefram2014-02-011-0/+1
| | | | | | | | | | Declarative syntax to unwrap argument list into lexical variables. "sub foo ($a,$b) {...}" checks number of arguments and puts the arguments into lexical variables. Signatures are not equivalent to the existing idiom of "sub foo { my($a,$b) = @_; ... }". Signatures are only available by enabling a non-default feature, and generate warnings about being experimental. The syntactic clash with prototypes is managed by disabling the short prototype syntax when signatures are enabled.
* Remove support for "do SUBROUTINE(LIST)"Dagfinn Ilmari Mannsåker2013-12-221-3/+0
| | | | | It's been deprecated (and emitting a warning) since Perl v5.0.0, and support for it consitutes nearly 3% of the grammar.
* Remove EBCDIC remappingsKarl Williamson2013-08-291-1/+4
| | | | | | | | Now that the Unicode tables are stored in native format, we shouldn't be doing remapping. Note that this assumes that the Latin1 casing tables are stored in native order; not all of this has been done yet.
* pad.c: Use &PL_sv_no for const pad namesFather Chrysostomos2013-07-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently &PL_sv_undef as a pad name can indicate either a free slot available for use by pad_alloc or a slot used by an op target (or, under ithreads, a constant or GV). Currently pad_alloc distinguishes between free slots and unnamed slots based on whether the value in the pad has PADMY or PADTMP set. If neither is set, then the slot is free. If either is set, the slot is in use. This makes it rather difficult to distinguish between constants stored in the pad (under ithreads) and targets. The latter need to be copied when referenced, to give the impression that a new scalar is being returned by an operator each time. (So \"$a" has to return a refer- ence to a new scalar each time, but \1 should return the same one.) Also, constants are shared between recursion levels. Currently, if the value is marked READONLY or is a shared hash key scalar, it is shared. But targets can also me shared hash keys, resulting in bugs. It also makes it impossible for the same constant to be shared by mul- tiple pad slots, as freeing one const op will turn off the PADTMP flag while the other slot still uses it, making the latter appear to be free. Hence a lot of copying occurs under ithreads. (Actually, that may not be true any more since 3b1c21fabed, as freed const ops swipe their constants from the pad. But right now, a lot of copying does still happen.) Also, XS modules may want to create const ops that return the same mutable SV each time. That is currently not possible without various workarounds including custom ops and references. (See <https://rt.perl.org/rt3/Ticket/Display.html?id=105906#txn-1075354>.) This commit changes pad_alloc and pad_free to use &PL_sv_no for con- stants and updates other code to keep all tests passing. Subsequent commits will actually use that information to fix bugs. This will probably break PadWalker, but I think it is an acceptable trade-off. The alternative would be to make PadnamePV forever more complex than necessary, by giving it a special case for &PL_sv_no and having it return NULL. I gave PadnameLEN a special case for &PL_sv_undef, so it may appear that I have simply shifted the complexity around. But if pad names stop being SVs, then this exception will simply disappear, since the global &PL_padname_undef will have 0 in its length field.
* perly.c: Disarm the YYDEBUG defines in perly.hFather Chrysostomos2012-10-011-7/+9
| | | | | | | | See <craigberry-E9C729.16313730092012@cpc2-bmly6-0-0-cust974.2-3.cable.virginmedia.com>. Move the YYDEBUG defines in perly.c back where they were before, but undefine YYDEBUG first. That leaves bison 2.6’s YYDEBUG defines in perly.h harmless.
* Restore perly.o build with -DDEBUGGINGFather Chrysostomos2012-09-251-4/+9
|
* Prevent assertion failure with ‘no a a 3’Father Chrysostomos2012-09-141-2/+0
| | | | | | | | | | | | | | | This particular syntax error, whittled down from ‘no if $] >= 5.17.4 warnings => "deprecated"’ (which contains a type), causes the parser to try to free an op from the new sub (for the BEGIN block) after freeing the new sub. This happens on line 526 of perly.c. It should not be necessary for the parser to free the op at this point, since after an error any ops owned by incomplete subs’ slabs will be freed. I’m leaving the other three instances of op_free in perly.c in place, at least for now, since there are cases where the forced token stack prevents ops from being freed when their subs are.
* Omnibus removal of register declarationsKarl Williamson2012-08-181-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes most register declarations in C code (and accompanying documentation) in the Perl core. Retained are those in the ext directory, Configure, and those that are associated with assembly language. See: http://stackoverflow.com/questions/314994/whats-a-good-example-of-register-variable-usage-in-c which says, in part: There is no good example of register usage when using modern compilers (read: last 10+ years) because it almost never does any good and can do some bad. When you use register, you are telling the compiler "I know how to optimize my code better than you do" which is almost never the case. One of three things can happen when you use register: The compiler ignores it, this is most likely. In this case the only harm is that you cannot take the address of the variable in the code. The compiler honors your request and as a result the code runs slower. The compiler honors your request and the code runs faster, this is the least likely scenario. Even if one compiler produces better code when you use register, there is no reason to believe another will do the same. If you have some critical code that the compiler is not optimizing well enough your best bet is probably to use assembler for that part anyway but of course do the appropriate profiling to verify the generated code is really a problem first.
* Remove op_latefree(d)Father Chrysostomos2012-07-141-110/+1
| | | | | | | This was an early attempt to fix leaking of ops after syntax errors, disabled because it was deemed to fragile. The new slab allocator (8be227a) has solved this problem another way, so latefree(d) no longer serves any purpose.
* update the editor hints for spaces, not tabsRicardo Signes2012-05-291-2/+2
| | | | | This updates the editor hints in our files for Emacs and vim to request that tabs be inserted as spaces.
* Label UTF8 cleanupBrian Fraser2012-03-251-5/+0
| | | | | This meant changing LABEL's definition in perly.y, so most of this commit is actually from the regened files.
* Bump several file copyright datesSteffen Schwigon2012-01-191-1/+2
| | | | | | | Sync copyright dates with actual changes according to git history. [Plus run regen_perly.h to update the SHA-256 checksums, and regen/regcharclass.pl to update regcharclass.h]
* Fix typos (spelling errors) in Perl sources.Peter J. Acklam) (via RT2011-01-071-1/+1
| | | | | | | | | # New Ticket Created by (Peter J. Acklam) # Please include the string: [perl #81904] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=81904 > Signed-off-by: Abigail <abigail@abigail.be>
* function interface to parse Perl statementZefram2010-09-061-6/+26
| | | | | | | | | | | | | yyparse() becomes reentrant. The yacc stack and related resources are allocated in yyparse(), rather than in lex_start(), and they are localised to yyparse(), preserving their values from any outer parser. yyparse() now takes a parameter which determines which production it will parse at the top level. New API function parse_fullstmt() uses this facility to parse just a single statement. The top-level single-statement production that is used for this then messes with the parser's head so that the parsing stops without seeing EOF, and any lookahead token seen after the statement is pushed back to the lexer.
* When discarding a token free the op associated with itGerard Goossen2009-12-181-0/+2
| | | | | | | | | | | | | | | | | | | | When discarding a token free the op associated with it. Fixes memory leak in comp/parser.t Gerard Goossen From 7694ec023ec8856f34964b5eeea58f1b588c89bc Mon Sep 17 00:00:00 2001 From: Gerard Goossen <gerard@ggoossen.net> Date: Fri, 18 Dec 2009 18:32:11 +0100 Subject: [PATCH 4/4] When discarding a token free the op associated with it. Status: O Content-Length: 438 Lines: 20 Fixes memory leak in comp/parser.t Signed-off-by: H.Merijn Brand <h.m.brand@xs4all.nl>
* Fix casting warningsRafael Garcia-Suarez2009-12-161-3/+3
|
* Store the PL_compcv instead of the the PL_comppad in parser stack, and make ↵Gerard Goossen2009-12-161-14/+28
| | | | it reference counted. Properly solves [perl #66094]
* Update copyright years.Nicholas Clark2008-10-251-1/+1
| | | p4raw-id: //depot/perl@34585
* Silence Borland compiler warnings (except for warnings from zlib) here:Steve Hay2008-02-251-1/+1
| | | | | http://www.nntp.perl.org/group/perl.daily-build.reports/2008/02/msg53937.html p4raw-id: //depot/perl@33370
* [perl #43425] local $[: fix scoping during parser error handling.Dave Mitchell2007-07-161-0/+7
| | | | | | | | | Change 22306# inadvertently made 'local $[' statement-scoped rather than block-scoped; so revert that change and add a different fix. The problem was to ensure that the savestack got popped correctly while popping errored tokens. We how record the current value of PL_savestack_ix with each pushed parser state. p4raw-id: //depot/perl@31615
* Make parser_free() be called slightly later,Dave Mitchell2007-04-011-17/+3
| | | | | | i.e. at the point where lexer vars are being restored in a LEAVE, rather than at the end of yyparse() p4raw-id: //depot/perl@30822