Commit graph

2684 commits

Author SHA1 Message Date
yui-knk
c3b2436154 set_yylval_literal is not used 2024-01-12 21:11:00 +09:00
Nobuyoshi Nakada
3d3bc029c5
Reject encodings determined at runtime as source code encodings
The encodings determined at runtime are affected by the runtime
environment, such as the OS and locale, while the file contents are
not.
2024-01-11 18:46:51 +09:00
Nobuyoshi Nakada
7cc8d58cc9
Remove duplicate function nd_st_key_val 2024-01-11 17:46:09 +09:00
S-H-GAMELINKS
a971229462 Fixed return values for some node types in nd_st_key function 2024-01-11 12:26:30 +09:00
Nobuyoshi Nakada
e59a730477
st_index_t is not VALUE 2024-01-10 14:06:33 +09:00
Peter Zhu
02d8bad6e1 Fix memory leak in parser for invalid syntax
The strterm is leaked when there is invalid syntax.

For example:

    10.times do
      100_000.times do
        begin
          RubyVM::InstructionSequence.compile('private def foo = puts "Hello"')
        rescue SyntaxError
        end
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    20384
    26256
    32592
    36720
    42016
    47888
    53248
    57456
    62928
    65936

After:

    16720
    17488
    17616
    17616
    17616
    17616
    17616
    17616
    17616
    16032

Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2024-01-09 09:41:02 -05:00
Nobuyoshi Nakada
38bc107f0b
Convert a series of else if lines to a switch 2024-01-09 18:47:15 +09:00
yui-knk
db476cc71c Introduce NODE_SYM to manage symbol literal
`:sym` was managed by `NODE_LIT` with `Symbol` object.
This commit introduces `NODE_SYM` so that

1. Symbol literal is detectable from AST Node
2. Reduce dependency on ruby object
2024-01-09 16:07:19 +09:00
Nobuyoshi Nakada
4b01983bf8
Simplify empty hahs with DSTAR 2024-01-09 13:05:34 +09:00
Nobuyoshi Nakada
a4406bc89a
Extract repeating NODE references as a local variable 2024-01-09 13:04:26 +09:00
yui-knk
5ecf2d2880 Use strcmp to compare strings 2024-01-09 07:42:44 +09:00
yui-knk
41e2d180a3 Do not convert NODE_STR to NODE_LIT when the string is hash key
parse.y converted NODE_STR when the string is hash key like

```
h1 = {"str1" => 1}
m1("str2" => 2)
m2({"str3" => 3})
```

This commit stop the conversion.
`static_literal_node_p` needs to know the node is for hash key or not
for the optimization.
2024-01-08 18:48:24 +09:00
yui-knk
7ffff3e043 Change numeric node value functions argument to NODE *
Change the argument to align with other node value functions
like `rb_node_line_lineno_val`.
2024-01-08 14:02:48 +09:00
yui-knk
9527093759 Fix numeric node print by -y option
These nodes are not NOTE_LIT, so need to treat separately.
2024-01-08 11:57:30 +09:00
Nobuyoshi Nakada
8b86d6f0c1
Suppress unused-but-set-variable warning in ripper
`set_yylval_node` in ripper does not use the argument at all.
2024-01-08 01:23:58 +09:00
Nobuyoshi Nakada
c30b8ae947
Adjust styles and indents [ci skip] 2024-01-08 00:50:41 +09:00
S-H-GAMELINKS
ad7aee35e4 Remove unneeded rb_parser_config_struct struct properties for Universal Parser 2024-01-07 21:16:31 +09:00
yui-knk
83c98ead4e Do not remove hash duplicated keys in parse.y
When hash keys are duplicated, e.g. `h = {k: 1, l: 2, k: 3}`,
parser changes node structure for correct compilation.
This generates tricky AST. This commit removes AST manipulation
from parser to keep AST structure simple.
2024-01-07 16:18:16 +09:00
yui-knk
9d3dcb86d1 Check hash key duplication for __LINE__ and __FILE__ 2024-01-07 14:32:10 +09:00
S-H-GAMELINKS
1b8d01136c Introduce Numeric Node's 2024-01-07 09:24:34 +09:00
yui-knk
7a050638b1 Introduce NODE_FILE
`__FILE__` was managed by `NODE_STR` with `String` object.
This commit introduces `NODE_FILE` and `struct rb_parser_string` so that

1. `__FILE__` is detectable from AST Node
2. Reduce dependency ruby object
2024-01-02 14:19:42 +09:00
yui-knk
6ec4d203f7 Warn "literal in condition" for __LINE__
Print warning for a code like

```ruby
if __LINE__
end

# => warning: literal in condition
```
2024-01-02 09:50:32 +09:00
yui-knk
1ade170a6c Introduce NODE_LINE
`__LINE__` was managed by `NODE_LIT` with `Integer` object.
This commit introduces `NODE_LINE` so that

1. `__LINE__` is detectable from AST Node
2. Reduce dependency ruby object
2023-12-29 18:32:27 +09:00
Nobuyoshi Nakada
bc002971b6
[Bug #20094] Distinguish begin and parentheses 2023-12-27 17:50:15 +09:00
Nobuyoshi Nakada
15c280639e
Initialize rb_node_block_t::nd_end at creation 2023-12-27 17:50:15 +09:00
Nobuyoshi Nakada
d0546012f2
Use NODE_ERROR as placeholder of error instead of NODE_BEGIN 2023-12-27 17:50:15 +09:00
yui-knk
33345d2e9f Include new node types into %printer 2023-12-27 12:25:17 +09:00
Nobuyoshi Nakada
596db9c1f4 [Feature #19370] Blocks without anonymous parameters should not affect 2023-12-25 18:28:21 +09:00
Takashi Kokubun
44592c4e20
Implement it (#9199)
[[Feature #18980]](https://bugs.ruby-lang.org/issues/18980)

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
2023-12-25 01:15:41 -08:00
Nobuyoshi Nakada
a9f0961831 [Feature #19370] Prohibit nesting anonymous parameter forwarding 2023-12-25 14:44:04 +09:00
Nobuyoshi Nakada
40e3f782dd Extract forwarding_arg_check function 2023-12-22 23:08:10 +09:00
Nobuyoshi Nakada
11c2aa035b Extract arg_splat nonterminal symbol 2023-12-22 23:08:10 +09:00
Nobuyoshi Nakada
92b10f5be7 [Bug #20062] Fixed numbered parameter syntax error
At the method definition, the local scope that saves the context of
the numbered parameters needs to be pushed before saving.
2023-12-16 02:11:51 +09:00
Nobuyoshi Nakada
9b7a964318 [Bug #19877] Flip-flop needs to be direct condition 2023-12-08 12:53:47 +09:00
Takashi Kokubun
c6eb355e04 Revert "Warn it only with -W:deprecated"
This reverts commit 5458252bb0.

Revert "Fallback rb_warn_deprecated for UNIVERSAL_PARSER"

This reverts commit 680be886f4.

matz actually preferred always warning `it`.
2023-12-07 00:03:03 -08:00
Takashi Kokubun
680be886f4 Fallback rb_warn_deprecated for UNIVERSAL_PARSER 2023-12-07 00:00:36 -08:00
Takashi Kokubun
5458252bb0 Warn it only with -W:deprecated 2023-12-06 23:44:02 -08:00
Takashi Kokubun
ae76c8a11e
Warn it (#9152)
https://bugs.ruby-lang.org/issues/18980
2023-12-07 07:14:59 +00:00
Nobuyoshi Nakada
a607d62d8c [Bug #20033] Dynamic regexp should not assign captures 2023-12-02 03:57:41 +09:00
Nobuyoshi Nakada
e5e1f9813e [Bug #19838] Flush delayed token nonconsecutive with the next token 2023-12-02 02:41:39 +09:00
Nobuyoshi Nakada
add0ab07e8 Extract end_with_newline_p 2023-12-02 02:41:39 +09:00
Nobuyoshi Nakada
6e2b10d456 Prefer proper enum over bare int 2023-12-02 02:41:39 +09:00
Nobuyoshi Nakada
e36b9760fd
Dispatch invalid hex escape content too 2023-12-01 15:04:30 +09:00
Nobuyoshi Nakada
d503e1b95a
[Bug #20030] dispatch invalid escaped character without ignoring it 2023-12-01 15:04:30 +09:00
Nobuyoshi Nakada
1802d14ca8 [Bug #19877] Assign captures for direct regexp literal only 2023-11-30 21:40:22 +09:00
TSUYUSATO Kitsune
fe746747b4 Reject 'class << (return); end` by "void value expression" 2023-11-21 14:07:47 +09:00
yui-knk
51149f335e Keep unused literal nodes
For static analysis, it’s better to keep unused literal nodes.
If simply change `block_append` to fall through, both "unused literal ignored"
and "possibly useless use of a literal in void context" warnings
are shown for the same line. But it’s verbose then remove
"unused literal ignored" warning.

This kind of optimization is already implemented on compile.c.
`compile_block` calls `iseq_compile_each0` with `popped = 1` when NODE_BLOCK
has next.
2023-10-31 17:49:12 +09:00
Nobuyoshi Nakada
13c9cbe09e
Embed rb_args_info in rb_node_args_t 2023-10-30 00:19:43 +09:00
Nobuyoshi Nakada
c8d162c889
[Bug #19973] Warn duplicated keyword arguments after keyword splat 2023-10-26 14:28:39 +09:00
Nobuyoshi Nakada
2f8a719b6a Removed unused argument
Eventually, `read_escape` does not use `encp`.
2023-10-25 21:40:41 +09:00