Граф коммитов

1790 Коммитов

Автор SHA1 Сообщение Дата
nobu d325d74174 parse.y: fix block passing with empty kwargs
* parse.y (arg_blk_pass): preceeding arguments node may be NULL when
  an empty keyword argument hash splat is optimized away.
  [ruby-core:88890] [Bug #15087]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-20 01:43:35 +00:00
mame fad01941b3 parse.y (arg_append): support NODE_ARGSCAT case
Because of the lack of this case, `[*ary,1,2,3,4,5,6]` was parsed into
an inefficient AST like `ary + [1,2] + [3,4] + [5,6]`.

A patch from Anmol Chopra <anmolchopra@rocketbox.in>.
Fixes [Bug #15018].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22 15:04:05 +00:00
mame d65f7458bc parse.y: remove coverage-related code fragments
The code fragments that initializes coverage data were scattered into
both parse.y and compile.c.  parse.y allocated a coverage data, and
compile.c initialize the data.

To remove this cross-cutting concern, this change moves the allocation
from "coverage" function of parse.y to "rb_iseq_new_top" of iseq.c.
For the sake, parse.y just counts the line number of the original source
code, and the number is passed via rb_ast_body_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22 10:38:56 +00:00
yui-knk e70cad6091 parse.y (heredoc_identifier): Update comment for term_len
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-16 02:07:44 +00:00
yui-knk d21f468dab parse.y: Add comment for `rb_strterm_heredoc_struct.sourceline`
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-16 01:26:25 +00:00
mame bae638ad5b parse.y: Deprecate flip-flops
Ref #5400

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-15 08:53:15 +00:00
mame 606d6b3470 Revert "range.c: prohibit `(1..nil)`"
This reverts commit a44c010764a16ae09aaed49d76eec055ca0057c8.
Refs #14845.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-13 11:00:28 +00:00
mame 48de2ea5f9 range.c: prohibit `(1..nil)`
Now endless range can be created by either a literal `(1..)` or explicit
range creation `Range.new(1, nil)`.  [Bug #14845]

This change is intended for "early failure"; for example,
`(1..var).to_a` causes out of memory if `var` is inadvertently nil.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-13 09:04:32 +00:00
yui-knk 744b0bdb7b parse.y: Fix locations of none and mid-rule actions
When an empty rule or a mid-rule action is reduced,
`YYLLOC_DEFAULT` is called with the third parameter to be zero.
If we use `RUBY_SET_YYLLOC_OF_NONE` to set their locations,
sometimes the end position of NODE indicates a blank.
For example, `a.b ;` generates `NODE_CALL (line: 1, location: (1,0)-(1,4))*`,
whose end position indicates a blank.

This is because of the following reasons:

* `NODE_CALL` is created when `primary_value call_op operation2 opt_paren_args` is
  reduced to `method_call`.
* `opt_paren_args` is `none`.
* `yylex` is called and `lex.pbeg` moves before `none` is reduced, so
  the beginning position of `none` does not match with the end position of `operation2`.

To fix locations, use `YYRHSLOC(Rhs, 0)` in `YYLLOC_DEFAULT`
(0 "refers to the symbol just before the reduction").

By this change, the bottom of the location stack would be referenced,
so initialize the bottom with `RUBY_SET_YYLLOC_OF_NONE` in `%initial-action`.

Ref: https://www.gnu.org/software/bison/manual/html_node/Location-Default-Action.html#Location-Default-Action

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-10 06:22:15 +00:00
yui-knk aee5c4338b parse.y: Fix locations of NODE_RESCUE
* parse.y (new_bodystmt): Fix locations of NODE_RESCUE
  to end with nd_else or nd_resq. Before this commit,
  locations of NODE_RESCUE included locations of nd_ensr
  of NODE_ENSURE which is a parent node of NODE_RESCUE.

  e.g. The location of the end of NODE_RESCUE is fixed:

  ```
  def a
    :b
  rescue
    :c
  ensure
    :d
  end
  ```

  * Before

  ```
  NODE_RESCUE (line: 2, location: (2,2)-(6,4))
  ```

  * After

  ```
  NODE_RESCUE (line: 3, location: (2,2)-(5,0))
  ```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-10 05:02:26 +00:00
normal 1c1ff52f43 parse.y: use ruby_sized_xfree and SIZED_REALLOC_N
Another part of the plan to reduce dependencies on malloc_usable_size
which costs us speed: https://bugs.ruby-lang.org/issues/10238

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63484 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-22 00:44:22 +00:00
shyouhei 687308cf0d explicit cast to void* required for %p
No automatic type promotion is expected for variadic arguments.
You have to do it by hand.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-21 00:41:57 +00:00
nobu 4dc5b6ff58 parse.y: relax literal in condition warnings
* parse.y (cond0): do not warn literal boolean (true and false) in
  condition expressions, as they are often used as infinite loops,
  deactivated code block, etc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-18 00:36:24 +00:00
nobu 8487c63fa3 rb_parser_printf declaration
* node.h (rb_parser_printf): delcare as PRINTF_ARGS.

* parse.y (parser_token_value_print): cast to adjust to %c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-17 12:36:33 +00:00
nobu b936115ed6 fix potential memory leaks
* parse.y (primary, new_args_tail, local_tbl): keep the order;
  allocate an empty imemo first then xmalloc, to get rid of
  potential memory leak when allocation imemo failed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-11 13:01:36 +00:00
yui-knk 5afa84b028 parse.y: Fix locations of NODE_NIL in endless ranges.
* parse.y: Fix to start with the end of dots.

  e.g. The locations of the NODE_NIL is fixed:

  ```
  1..
  ```

  * Before

  ```
  NODE_NIL (line: 1, location: (1,0)-(1,3))
  ```

  * After

  ```
  NODE_NIL (line: 1, location: (1,3)-(1,3))
  ```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-10 06:34:20 +00:00
nobu 6e06d6440b fix potential memory leaks
* gc.c (rb_alloc_tmp_buffer_with_count): keep the order; allocate
  an empty imemo first then xmalloc, to get rid of potential
  memory leak when allocation imemo failed.

* parse.y (rb_parser_malloc, rb_parser_calloc, rb_parser_realloc):
  ditto.

* process.c (rb_execarg_allocate_dup2_tmpbuf): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09 17:40:04 +00:00
mame e9303e1a00 Rename imemo_alloc with imemo_tmpbuf
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09 07:11:59 +00:00
mame af0696782d gc.c (rb_imemo_alloc_new): split for each purpose
imemo_alloc is used for three purposes: auto-free pointer (alternative
of alloca), alloc_tmp_buffer, and heap allocation for bison.
To make it clear, this change introduces three functions:
rb_imemo_alloc_auto_free_pointer,
rb_imemo_alloc_auto_free_maybe_mark_buffer, and
rb_imemo_alloc_parser_heap.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09 07:08:53 +00:00
mame 58823392b4 gc.c (rb_imemo_alloc_new): improve the API interface
rb_imemo_alloc_new returns rb_imemo_alloc_t*, but took VALUEs, which is
inconsistent.  To make the intention clear, it now takes only a pointer
to the buffer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09 06:12:17 +00:00
mame 7f95eed19e Introduce endless range [Feature#12912]
Typical usages:
```
p ary[1..]          # drop the first element; identical to ary[1..-1]
(1..).each {|n|...} # iterate forever from 1; identical to 1.step{...}
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 15:18:50 +00:00
nobu f168dbd9ef parse.y: fix cmdarg in command_args
* parse.y (call_args): fix invalid CMDARG state after command_args
  followed by tLBRACE_ARG.  [ruby-core:86551] [Bug #14690]

From: Ilya Bylich <ibylich@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63168 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-17 01:22:26 +00:00
nobu 3b93a8bcad parse.y: `else` indent
* parse.y (keyword_else): warn less-indented `else` than `case`.
  [ruby-core:86492] [Bug #14674]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-16 08:54:03 +00:00
nobu a3a5f38d09 parse.y: `when` indent
* parse.y (k_when): warn less-indented `when` than `case`.
  [ruby-core:86492] [Bug #14674]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-12 22:13:09 +00:00
nobu bbcab8c6f3 parse.y: [DOC] Ripper.dedent_string is internal
* parse.y (parser_dedent_string): stated that Ripper.dedent_string
  is for internal use only.

[ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-09 12:39:59 +00:00
nobu 6a57127222 parse.y: extra error message after no digits
* parse.y (no_digits): return tINTEGER instead of unexpected
  end-of-input, to get rid of extra error messages.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-09 11:09:30 +00:00
stomar d33ddd631b parse.y: fix docs for Ripper.dedent_string
* parse.y: [DOC] fix return type in call-seq of Ripper.dedent_string,
  clarify the method's behavior.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-08 19:39:38 +00:00
nobu 9c5d90b516 Use only CMDARG/COND _PUSH/POP for cmdarg/cond management.
From: Ilya Bylich <ibylich@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-29 03:42:32 +00:00
nobu e5a30879f9 parse.y: remove `p->` from bitstack traces
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63032 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-29 01:33:25 +00:00
nobu f3fbf1dfad parse.y: k_else in bodystmt
* parse.y (bodystmt): expand opt_else to show the error message at
  the right place.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-23 01:09:57 +00:00
nobu 140512d222 parse.y: else without rescue
* parse.y (bodystmt): [EXPERIMENTAL] make `else` without `rescue`
  a syntax error.  [DevelopersMeeting20180315Japan]

  https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20180315Japan
  https://docs.google.com/document/d/1RT0ijSo8uJ4Awn3CEvuYkjH0TVeXSYgeAFNmVGYC3ak/edit#
  > * do-else-end
  >   https://twitter.com/joker1007/status/974173396006129664
  >   https://twitter.com/joker1007/status/974173641347756032
  >   https://twitter.com/joker1007/status/974176512554369027
  >   Will be SyntaxError in 2.6-preview2
  >   All of begin/do/def (experimental)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62901 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-23 00:40:08 +00:00
nobu 721b55d70c parse.y: reorder in the place
* parse.y (new_args_tail): reorder required and optional keyword
  argument variable IDs in the place.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-22 06:47:53 +00:00
nobu 58fbe69a5b parse.y: terminator at continued line
* parse.y (here_document): a continuing line is not the
  terminator.  [ruby-core:86283] [Bug #14621]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-21 12:40:16 +00:00
nobu 491f523ab1 parse.y: unindent continued line
* parse.y (tokadd_string): stop at continued line in dedented here
  documents, to dedent for each lines before removing escaped
  newlines.  [ruby-core:86236] [Bug #14621]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-21 10:32:15 +00:00
nobu b4b3de3e7c node.c: predicates for special NODEs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-20 13:30:57 +00:00
nobu 6916130566 parse.y: NUL-terminate ruby_sourcefile
* parse.y (yycompile): in some cases (warning, error, dtrace,...),
  ruby_sourcefile is expected to be NUL-terminated, so ensure it.

* template/prelude.c.tmpl (prelude_name): NUL-terminate to get rid
  of copying static data.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-19 14:12:00 +00:00
nobu 7e199e4156 parse.y: push `do` token info
* parse.y (k_rescue, k_ensure): revert r62838.

* parse.y (k_do, k_do_LAMBDA, k_do_block): push token infos of
  `do`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-19 12:40:34 +00:00
nobu 5399951b00 parse.y: ignore do indentations
* parse.y (k_rescue, k_ensure): ignore indentations of `do`, it
  is not at the beginning of line usually.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-19 08:37:12 +00:00
nobu d34bc779a7 parse.y: mismatched indentations at middle
* parse.y (k_rescue, k_ensure, k_when, k_else, k_elsif): warn
  mismatched indentations at keywords in middle of blocks.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-19 08:21:26 +00:00
nobu 62182eb0a4 parse.y: fix duplicate kwrest
* parse.y (f_kwrest): add the variable name as an argument, as
  well as an internal variable.

* parse.y (new_args_tail): now keyword rest argument variable is
  always placed between keyword arguments and block argument, so
  so just reorder required and optional keyword arguments.  no
  longer kwrest duplicates.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-19 03:16:40 +00:00
nobu 7773cfa496 ripper: fix escaped space
* parse.y: use tSP same as ripper instead of tSPACE.
  [ruby-core:86080] [Bug #14597]

* ext/ripper/eventids2.c: tSP is defined in ripper.c now.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-12 07:55:17 +00:00
nobu f2b094a522 parse.y: fix interpolated string literal dedent
* parse.y (heredoc_dedent): fix interpolated string literal dedent,
  remove indentations from only nodes with the newline flag.
  [ruby-core:85983] [Bug #14584]

* parse.y (here_document): set the newline flag on literal string
  nodes starting at the beginning of line.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-11 12:19:08 +00:00
nobu e1a60b2db9 parse.y: reduce duplicate code
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-11 12:12:08 +00:00
nobu decb59ba83 parse.y: tSPACE for old bison
* parse.y (tSPACE): define a separate token for escaped space, to
  fix `redefining user token number of ' '` error at word list
  separator on bison 2.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-06 09:03:24 +00:00
nobu d2a03300d3 parse.y: named whitespaces
* parse.y: named escaped whitespaces to show unexpected character.
  bare whitespaces should not appear outside of word_list.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-05 08:32:46 +00:00
nobu c9ecea33da parse.y: refine assign_in_cond warning
* parse.y (assign_in_cond): refine a warning message for
  assignment of a literal in conditinal expression.
  [ruby-core:85872] [Bug #14562]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-01 04:10:25 +00:00
nobu 96db72ce38 [DOC] missing docs at toplevel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:18:52 +00:00
nobu 1727c83584 Fix CMDARG manipulation
* parse.y: Fix CMDARG manipulation. Use CMDARG_P to identify
  keyword_do/keyword_do_block.  [Feature #14506] [Fix GH-1823]

From: Ilya Bylich <ibylich@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-22 12:51:41 +00:00
nobu 7036c4062e parse.y: named backslash
* parse.y: named backslash to show unexpected character.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-03 07:30:39 +00:00
nobu 55e606b36c parse.y: use lex_goto_eol to skip to EOL
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-03 07:21:58 +00:00