Project

General

Profile

Actions

Feature #2455

closed

--dump=parsetree, --dump=parsetree_with_comment

Added by mame (Yusuke Endoh) over 14 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
[ruby-dev:39853]

Description

=begin
遠藤です。

Ruby をデバッグする際、node の構造をざっと把握したい場合がしばしば
あります。
--dump=insns にならって、--dump=parsetree を入れてもいいでしょうか。

$ ./ruby --dump=parsetree -e '1 + 2 + 3'
###############################################

Do NOT use this node dump for any purpose

other than debug and research.

###############################################

@ NODE_SCOPE (line: 1)

+- nd_tbl: (empty)

+- nd_args:

| (null node)

+- nd_body:

@ NODE_CALL (line: 1)

+- nd_mid: :+

+- nd_recv:

| @ NODE_CALL (line: 1)

| +- nd_mid: :+

| +- nd_recv:

| | @ NODE_LIT (line: 1)

| | +- nd_lit: 1

| +- nd_args:

| @ NODE_ARRAY (line: 1)

| +- nd_alen: 1

| +- nd_head:

| | @ NODE_LIT (line: 1)

| | +- nd_lit: 2

| +- nd_next:

| (null node)

+- nd_args:

@ NODE_ARRAY (line: 1)

+- nd_alen: 1

+- nd_head:

| @ NODE_LIT (line: 1)

| +- nd_lit: 3

+- nd_next:

(null node)

$ ./ruby --dump=parsetree_with_comment -e '1 + 2 + 3'
###############################################

Do NOT use this node dump for any purpose

other than debug and research.

###############################################

@ NODE_SCOPE (line: 1)

| # [nd_tbl]: local table, [nd_args]: arguments, [nd_body]: body

+- nd_tbl (local table): (empty)

+- nd_args (arguments):

| (null node)

+- nd_body (body):

@ NODE_CALL (line: 1)

| # nd_mid

+- nd_mid (method id): :+

+- nd_recv (receiver):

| @ NODE_CALL (line: 1)

| | # nd_mid

| +- nd_mid (method id): :+

| +- nd_recv (receiver):

| | @ NODE_LIT (line: 1)

| | | # nd_lit

| | +- nd_lit (literal): 1

| +- nd_args (arguments):

| @ NODE_ARRAY (line: 1)

| | # [ [nd_head], [nd_next].. ] (length: [nd_alen])

| +- nd_alen (length): 1

| +- nd_head (element):

| | @ NODE_LIT (line: 1)

| | | # nd_lit

| | +- nd_lit (literal): 2

| +- nd_next (next element):

| (null node)

+- nd_args (arguments):

@ NODE_ARRAY (line: 1)

| # [ [nd_head], [nd_next].. ] (length: [nd_alen])

+- nd_alen (length): 1

+- nd_head (element):

| @ NODE_LIT (line: 1)

| | # nd_lit

| +- nd_lit (literal): 3

+- nd_next (next element):

(null node)

Ruby のデバッグ以外にも、Ruby のコードに習熟していない人が Ruby の
コードを読む際の助けになると思います。
私が昔 compile.c を読み始めていたころを思い出すと、node の構造を
理解していないことが大きな障害になっていました。(ドキュメントはなく、
nd_head, nd_body などの名前が様々な意味で転用・乱用されているので)

「デバッグと研究目的以外に使うな」と明示することで、node が非公開
API であることを再度主張する効果もあるかもしれません。

--
Yusuke Endoh
=end


Files

dump-parsetree.patch (18.3 KB) dump-parsetree.patch mame (Yusuke Endoh), 12/08/2009 03:46 AM
Actions #1

Updated by matz (Yukihiro Matsumoto) over 14 years ago

=begin
まつもと ゆきひろです

In message "Re: [ruby-dev:39853] [Feature #2455] --dump=parsetree, --dump=parsetree_with_comment"
on Tue, 8 Dec 2009 03:46:08 +0900, Yusuke Endoh writes:

|Ruby をデバッグする際、node の構造をざっと把握したい場合がしばしば
|あります。
|--dump=insns にならって、--dump=parsetree を入れてもいいでしょうか。

笹田さんが反対しなければ入れても構わないと思います。

=end

Actions #2

Updated by ko1 (Koichi Sasada) over 14 years ago

=begin
(2009/12/09 16:56), Yukihiro Matsumoto wrote::

笹田さんが反対しなければ入れても構わないと思います。

 反対しません.

--
// SASADA Koichi at atdot dot net

=end

Actions #3

Updated by mame (Yusuke Endoh) over 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r26053.
Yusuke, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0