Feature #2455
--dump=parsetree, --dump=parsetree_with_comment
| Status: | Closed | Start date: | 12/08/2009 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 100% |
||
| Category: | core | |||
| Target version: | 2.0.0 |
Description
遠藤です。 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_args]) # +- nd_mid (method id): :+ # +- nd_recv (receiver): # | @ NODE_CALL (line: 1) # | | # [nd_mid]([nd_args]) # | +- nd_mid (method id): :+ # | +- nd_recv (receiver): # | | @ NODE_LIT (line: 1) # | | | # [nd_lit](literal) # | | +- 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](literal) # | | +- 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](literal) # | +- nd_lit (literal): 3 # +- nd_next (next element): # (null node) Ruby のデバッグ以外にも、Ruby のコードに習熟していない人が Ruby の コードを読む際の助けになると思います。 私が昔 compile.c を読み始めていたころを思い出すと、node の構造を 理解していないことが大きな障害になっていました。(ドキュメントはなく、 nd_head, nd_body などの名前が様々な意味で転用・乱用されているので) 「デバッグと研究目的以外に使うな」と明示することで、node が非公開 API であることを再度主張する効果もあるかもしれません。 -- Yusuke Endoh <mame@tsg.ne.jp>
Associated revisions
* node.c: node management added. Currently, only pretty-dumper is
implemented. [ruby-dev:39853]
* ruby.c: --dump=parsetree and --dump=parsetree_with_comment options
added. This is just for debug or research purpose. Note that the
compatibility of these options are not supported at all.
History
Updated by matz (Yukihiro Matsumoto) over 2 years ago
まつもと ゆきひろです 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 <redmine@ruby-lang.org> writes: |Ruby をデバッグする際、node の構造をざっと把握したい場合がしばしば |あります。 |--dump=insns にならって、--dump=parsetree を入れてもいいでしょうか。 笹田さんが反対しなければ入れても構わないと思います。
Updated by ko1 (Koichi Sasada) over 2 years ago
(2009/12/09 16:56), Yukihiro Matsumoto wrote:: > 笹田さんが反対しなければ入れても構わないと思います。 反対しません. -- // SASADA Koichi at atdot dot net
Updated by mame (Yusuke Endoh) over 2 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
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.