diff --git a/.gitignore b/.gitignore index 071622666d5c61..9218a84c4ddacd 100644 --- a/.gitignore +++ b/.gitignore @@ -254,3 +254,13 @@ lcov*.info # /wasm/ /wasm/tests/*.wasm + +# YARP +/lib/yarp/node.rb +/lib/yarp/serialize.rb +/yarp/api_node.c +/yarp/ast.h +/yarp/node.c +/yarp/prettyprint.c +/yarp/serialize.c +/yarp/token_type.c diff --git a/array.c b/array.c index 74a38ef3a91a2d..b4d4cd5bff1410 100644 --- a/array.c +++ b/array.c @@ -1200,7 +1200,6 @@ ary_make_partial(VALUE ary, VALUE klass, long offset, long len) FL_SET_EMBED(result); ary_memcpy(result, 0, len, RARRAY_CONST_PTR(ary) + offset); ARY_SET_EMBED_LEN(result, len); - return result; } else { VALUE shared = ary_make_shared(ary); @@ -1215,9 +1214,10 @@ ary_make_partial(VALUE ary, VALUE klass, long offset, long len) ARY_SET_LEN(result, len); ary_verify(shared); - ary_verify(result); - return result; } + + ary_verify(result); + return result; } static VALUE diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 196fa454ff437b..4f73af89e8507d 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -1,3 +1,22 @@ +# regression test for return type of Integer#/ +# It can return a T_BIGNUM when inputs are T_FIXNUM. +assert_equal 0x3fffffffffffffff.to_s, %q{ + def call(fixnum_min) + (fixnum_min / -1) - 1 + end + + call(-(2**62)) +} + +# regression test for return type of String#<< +assert_equal 'Sub', %q{ + def call(sub) = (sub << sub).itself + + class Sub < String; end + + call(Sub.new('o')).class +} + # test splat filling required and feeding rest assert_equal '[0, 1, 2, [3, 4]]', %q{ public def lead_rest(a, b, *rest) @@ -4092,3 +4111,18 @@ def number = super + 2 Sub.new.number { 3 } } + +# Integer multiplication and overflow +assert_equal '[6, -6, 9671406556917033397649408, -9671406556917033397649408, 21267647932558653966460912964485513216]', %q{ + def foo(a, b) + a * b + end + + r1 = foo(2, 3) + r2 = foo(2, -3) + r3 = foo(2 << 40, 2 << 41) + r4 = foo(2 << 40, -2 << 41) + r5 = foo(1 << 62, 1 << 62) + + [r1, r2, r3, r4, r5] +} diff --git a/common.mk b/common.mk index b9c3b664b92f2e..ea200298c05afb 100644 --- a/common.mk +++ b/common.mk @@ -202,6 +202,40 @@ $(YARP_BUILD_DIR)/.time $(YARP_BUILD_DIR)/enc/.time $(YARP_BUILD_DIR)/util/.time $(Q) $(MAKEDIRS) $(@D) @$(NULLCMD) > $@ +main: $(top_srcdir)/lib/yarp/node.rb +srcs: $(top_srcdir)/lib/yarp/node.rb +$(top_srcdir)/lib/yarp/node.rb: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/lib/yarp/node.rb.erb + $(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb lib/yarp/node.rb $(top_srcdir)/lib/yarp/node.rb + +main: $(top_srcdir)/lib/yarp/serialize.rb +srcs: $(top_srcdir)/lib/yarp/serialize.rb +$(top_srcdir)/lib/yarp/serialize.rb: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/lib/yarp/serialize.rb.erb + $(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb lib/yarp/serialize.rb $(top_srcdir)/lib/yarp/serialize.rb + +srcs: $(top_srcdir)/yarp/api_node.c +$(top_srcdir)/yarp/api_node.c: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/ext/yarp/api_node.c.erb + $(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb ext/yarp/api_node.c $(top_srcdir)/yarp/api_node.c + +srcs: $(top_srcdir)/yarp/ast.h +$(top_srcdir)/yarp/ast.h: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/include/yarp/ast.h.erb + $(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb include/yarp/ast.h $(top_srcdir)/yarp/ast.h + +srcs: $(top_srcdir)/yarp/node.c +$(top_srcdir)/yarp/node.c: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/src/node.c.erb + $(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb src/node.c $(top_srcdir)/yarp/node.c + +srcs: $(top_srcdir)/yarp/prettyprint.c +$(top_srcdir)/yarp/prettyprint.c: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/src/prettyprint.c.erb + $(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb src/prettyprint.c $(top_srcdir)/yarp/prettyprint.c + +srcs: $(top_srcdir)/yarp/serialize.c +$(top_srcdir)/yarp/serialize.c: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/src/serialize.c.erb + $(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb src/serialize.c $(top_srcdir)/yarp/serialize.c + +srcs: $(top_srcdir)/yarp/token_type.c +$(top_srcdir)/yarp/token_type.c: $(top_srcdir)/yarp/templates/template.rb $(top_srcdir)/yarp/templates/src/token_type.c.erb + $(Q) $(BASERUBY) $(top_srcdir)/yarp/templates/template.rb src/token_type.c $(top_srcdir)/yarp/token_type.c + EXPORTOBJS = $(DLNOBJ) \ localeinit.$(OBJEXT) \ loadpath.$(OBJEXT) \ diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 6dadc8d0d6f452..e852d68eedf93b 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -76,9 +76,7 @@ getattr(int fd, conmode *t) #endif static ID id_getc, id_console, id_close; -#if ENABLE_IO_GETPASS -static ID id_gets, id_chomp_bang; -#endif +static ID id_gets, id_flush, id_chomp_bang; #if defined HAVE_RUBY_FIBER_SCHEDULER_H # include "ruby/fiber/scheduler.h" @@ -1534,13 +1532,18 @@ io_getch(int argc, VALUE *argv, VALUE io) return rb_funcallv(io, id_getc, argc, argv); } -#if ENABLE_IO_GETPASS static VALUE puts_call(VALUE io) { return rb_io_write(io, rb_default_rs); } +static VALUE +gets_call(VALUE io) +{ + return rb_funcallv(io, id_gets, 0, 0); +} + static VALUE getpass_call(VALUE io) { @@ -1561,7 +1564,8 @@ static VALUE str_chomp(VALUE str) { if (!NIL_P(str)) { - rb_funcallv(str, id_chomp_bang, 0, 0); + const VALUE rs = rb_default_rs; /* rvalue in TruffleRuby */ + rb_funcallv(str, id_chomp_bang, 1, &rs); } return str; } @@ -1578,6 +1582,12 @@ str_chomp(VALUE str) * see String#chomp!. * * You must require 'io/console' to use this method. + * + * require 'io/console' + * IO::console.getpass("Enter password:") + * Enter password: + * # => "mypassword" + * */ static VALUE console_getpass(int argc, VALUE *argv, VALUE io) @@ -1588,6 +1598,7 @@ console_getpass(int argc, VALUE *argv, VALUE io) wio = rb_io_get_write_io(io); if (wio == io && io == rb_stdin) wio = rb_stderr; prompt(argc, argv, wio); + rb_io_flush(wio); str = rb_ensure(getpass_call, io, puts_call, wio); return str_chomp(str); } @@ -1605,11 +1616,10 @@ io_getpass(int argc, VALUE *argv, VALUE io) rb_check_arity(argc, 0, 1); prompt(argc, argv, io); - str = str_chomp(rb_funcallv(io, id_gets, 0, 0)); - puts_call(io); - return str; + rb_check_funcall(io, id_flush, 0, 0); + str = rb_ensure(gets_call, io, puts_call, io); + return str_chomp(str); } -#endif /* * IO console methods @@ -1619,10 +1629,9 @@ Init_console(void) { #undef rb_intern id_getc = rb_intern("getc"); -#if ENABLE_IO_GETPASS id_gets = rb_intern("gets"); + id_flush = rb_intern("flush"); id_chomp_bang = rb_intern("chomp!"); -#endif id_console = rb_intern("console"); id_close = rb_intern("close"); #define init_rawmode_opt_id(name) \ @@ -1670,16 +1679,12 @@ InitVM_console(void) rb_define_method(rb_cIO, "clear_screen", console_clear_screen, 0); rb_define_method(rb_cIO, "pressed?", console_key_pressed_p, 1); rb_define_method(rb_cIO, "check_winsize_changed", console_check_winsize_changed, 0); -#if ENABLE_IO_GETPASS rb_define_method(rb_cIO, "getpass", console_getpass, -1); -#endif rb_define_singleton_method(rb_cIO, "console", console_dev, -1); { VALUE mReadable = rb_define_module_under(rb_cIO, "generic_readable"); rb_define_method(mReadable, "getch", io_getch, -1); -#if ENABLE_IO_GETPASS rb_define_method(mReadable, "getpass", io_getpass, -1); -#endif } { /* :stopdoc: */ diff --git a/ext/io/console/extconf.rb b/ext/io/console/extconf.rb index 3cbe8954d4c71d..a72403c7f90fa4 100644 --- a/ext/io/console/extconf.rb +++ b/ext/io/console/extconf.rb @@ -35,7 +35,6 @@ elsif have_func("rb_scheduler_timeout") # 3.0 have_func("rb_io_wait") end - $defs << "-D""ENABLE_IO_GETPASS=1" create_makefile("io/console") {|conf| conf << "\n""VK_HEADER = #{vk_header}\n" } diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 1a37ba4112fbe2..ba05fadbaf679b 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -347,6 +347,8 @@ def contents return @contents end end + rescue Zlib::GzipFile::Error, EOFError, Gem::Package::TarInvalidError => e + raise Gem::Package::FormatError.new e.message, @gem end ## @@ -363,7 +365,7 @@ def digest(entry) # :nodoc: algorithms.each do |algorithm| digester = Gem::Security.create_digest(algorithm) - digester << entry.read(16_384) until entry.eof? + digester << entry.readpartial(16_384) until entry.eof? entry.rewind @@ -395,6 +397,8 @@ def extract_files(destination_dir, pattern = "*") break # ignore further entries end end + rescue Zlib::GzipFile::Error, EOFError, Gem::Package::TarInvalidError => e + raise Gem::Package::FormatError.new e.message, @gem end ## @@ -626,7 +630,7 @@ def verify raise rescue Errno::ENOENT => e raise Gem::Package::FormatError.new e.message - rescue Gem::Package::TarInvalidError => e + rescue Zlib::GzipFile::Error, EOFError, Gem::Package::TarInvalidError => e raise Gem::Package::FormatError.new e.message, @gem end diff --git a/lib/rubygems/package/tar_reader.rb b/lib/rubygems/package/tar_reader.rb index b12e83a70367c7..410cf2e0b3c2cc 100644 --- a/lib/rubygems/package/tar_reader.rb +++ b/lib/rubygems/package/tar_reader.rb @@ -13,11 +13,6 @@ class Gem::Package::TarReader include Enumerable - ## - # Raised if the tar IO is not seekable - - class UnexpectedEOF < StandardError; end - ## # Creates a new TarReader on +io+ and yields it to the block, if given. diff --git a/lib/rubygems/package/tar_reader/entry.rb b/lib/rubygems/package/tar_reader/entry.rb index e22efa95b38ebb..5e9d9af5c62e5b 100644 --- a/lib/rubygems/package/tar_reader/entry.rb +++ b/lib/rubygems/package/tar_reader/entry.rb @@ -102,9 +102,7 @@ def full_name # Read one byte from the tar entry def getc - check_closed - - return nil if @read >= @header.size + return nil if eof? ret = @io.getc @read += 1 if ret @@ -156,30 +154,28 @@ def size alias_method :length, :size ## - # Reads +len+ bytes from the tar file entry, or the rest of the entry if - # nil - - def read(len = nil) - check_closed - - len ||= @header.size - @read + # Reads +maxlen+ bytes from the tar file entry, or the rest of the entry if nil - return nil if len > 0 && @read >= @header.size + def read(maxlen = nil) + if eof? + return maxlen.to_i.zero? ? "" : nil + end - max_read = [len, @header.size - @read].min + max_read = [maxlen, @header.size - @read].compact.min ret = @io.read max_read + if ret.nil? + return maxlen ? nil : "" # IO.read returns nil on EOF with len argument + end @read += ret.size ret end - def readpartial(maxlen = nil, outbuf = "".b) - check_closed - - maxlen ||= @header.size - @read - - raise EOFError if maxlen > 0 && @read >= @header.size + def readpartial(maxlen, outbuf = "".b) + if eof? && maxlen > 0 + raise EOFError, "end of file reached" + end max_read = [maxlen, @header.size - @read].min @@ -213,6 +209,8 @@ def seek(offset, whence = IO::SEEK_SET) pending = new_pos - @io.pos + return 0 if pending == 0 + if @io.respond_to?(:seek) begin # avoid reading if the @io supports seeking @@ -230,8 +228,8 @@ def seek(offset, whence = IO::SEEK_SET) end while pending > 0 do - size_read = @io.read([pending, 4096].min).size - raise UnexpectedEOF if @io.eof? + size_read = @io.read([pending, 4096].min)&.size + raise(EOFError, "end of file reached") if size_read.nil? pending -= size_read end diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index da3beee628c466..057c6ccb9ec479 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -343,7 +343,7 @@ def validate_array_attribute(field) String end - unless Array === val && val.all? {|x| x.is_a?(klass) } + unless Array === val && val.all? {|x| x.is_a?(klass) || (field == :licenses && x.nil?) } error "#{field} must be an Array of #{klass}" end end @@ -358,6 +358,8 @@ def validate_licenses_length licenses = @specification.licenses licenses.each do |license| + next if license.nil? + if license.length > 64 error "each license must be 64 characters or less" end @@ -368,11 +370,12 @@ def validate_licenses licenses = @specification.licenses licenses.each do |license| - next if Gem::Licenses.match?(license) + next if Gem::Licenses.match?(license) || license.nil? suggestions = Gem::Licenses.suggestions(license) message = <<-WARNING license value '#{license}' is invalid. Use a license identifier from -http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license. +http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license, +or set it to nil if you don't want to specify a license. WARNING message += "Did you mean #{suggestions.map {|s| "'#{s}'" }.join(", ")}?\n" unless suggestions.nil? warning(message) @@ -380,7 +383,8 @@ def validate_licenses warning <<-WARNING if licenses.empty? licenses is empty, but is recommended. Use a license identifier from -http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license. +http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license, +or set it to nil if you don't want to specify a license. WARNING end diff --git a/lib/rubygems/util/licenses.rb b/lib/rubygems/util/licenses.rb index ab5485d020cf22..77137fdc9847ae 100644 --- a/lib/rubygems/util/licenses.rb +++ b/lib/rubygems/util/licenses.rb @@ -39,6 +39,8 @@ class Gem::Licenses APSL-1.1 APSL-1.2 APSL-2.0 + ASWF-Digital-Assets-1.0 + ASWF-Digital-Assets-1.1 Abstyles AdaCore-doc Adobe-2006 @@ -90,6 +92,7 @@ class Gem::Licenses Bitstream-Charter Bitstream-Vera BlueOak-1.0.0 + Boehm-GC Borceux Brian-Gladman-3-Clause C-UDA-1.0 @@ -144,6 +147,7 @@ class Gem::Licenses CC-BY-SA-3.0 CC-BY-SA-3.0-AT CC-BY-SA-3.0-DE + CC-BY-SA-3.0-IGO CC-BY-SA-4.0 CC-PDDC CC0-1.0 @@ -281,6 +285,7 @@ class Gem::Licenses ImageMagick Imlib2 Info-ZIP + Inner-Net-2.0 Intel Intel-ACPI Interbase-1.0 @@ -317,16 +322,21 @@ class Gem::Licenses LZMA-SDK-9.11-to-9.20 LZMA-SDK-9.22 Latex2e + Latex2e-translated-notice Leptonica LiLiQ-P-1.1 LiLiQ-R-1.1 LiLiQ-Rplus-1.1 Libpng Linux-OpenIB + Linux-man-pages-1-para Linux-man-pages-copyleft + Linux-man-pages-copyleft-2-para + Linux-man-pages-copyleft-var MIT MIT-0 MIT-CMU + MIT-Festival MIT-Modern-Variant MIT-Wu MIT-advertising @@ -360,6 +370,7 @@ class Gem::Licenses NICTA-1.0 NIST-PD NIST-PD-fallback + NIST-Software NLOD-1.0 NLOD-2.0 NLPL @@ -412,8 +423,10 @@ class Gem::Licenses OLDAP-2.6 OLDAP-2.7 OLDAP-2.8 + OLFL-1.3 OML OPL-1.0 + OPL-UK-3.0 OPUBL-1.0 OSET-PL-2.1 OSL-1.0 @@ -451,6 +464,7 @@ class Gem::Licenses SGI-B-1.0 SGI-B-1.1 SGI-B-2.0 + SGP4 SHL-0.5 SHL-0.51 SISSL @@ -487,12 +501,14 @@ class Gem::Licenses TTWL TU-Berlin-1.0 TU-Berlin-2.0 + TermReadKey UCAR UCL-1.0 UPL-1.0 Unicode-DFS-2015 Unicode-DFS-2016 Unicode-TOU + UnixCrypt Unlicense VOSTROM VSL-1.0 @@ -502,12 +518,15 @@ class Gem::Licenses W3C-20150513 WTFPL Watcom-1.0 + Widget-Workshop Wsuipa X11 X11-distribute-modifications-variant XFree86-1.1 XSkat + Xdebug-1.03 Xerox + Xfig Xnet YPL-1.0 YPL-1.1 @@ -527,6 +546,7 @@ class Gem::Licenses copyleft-next-0.3.1 curl diffmark + dtoa dvipdfm eCos-2.0 eGenix @@ -538,6 +558,7 @@ class Gem::Licenses libselinux-1.0 libtiff libutil-David-Nugent + metamail mpi-permissive mpich2 mplus @@ -555,9 +576,11 @@ class Gem::Licenses # exception identifiers EXCEPTION_IDENTIFIERS = %w[ 389-exception + Asterisk-exception Autoconf-exception-2.0 Autoconf-exception-3.0 Autoconf-exception-generic + Autoconf-exception-macro Bison-exception-2.2 Bootloader-exception CLISP-exception-2.0 @@ -569,6 +592,7 @@ class Gem::Licenses GCC-exception-2.0 GCC-exception-3.1 GNAT-exception + GPL-3.0-interface-exception GPL-3.0-linking-exception GPL-3.0-linking-source-exception GPL-CC-1.0 @@ -576,6 +600,7 @@ class Gem::Licenses GStreamer-exception-2008 KiCad-libraries-exception LGPL-3.0-linking-exception + LLGPL LLVM-exception LZMA-exception Libtool-exception @@ -595,13 +620,16 @@ class Gem::Licenses Swift-exception Universal-FOSS-exception-1.0 WxWindows-exception-3.1 + cryptsetup-OpenSSL-exception eCos-exception-2.0 freertos-exception-2.0 gnu-javamail-exception i2p-gpl-java-exception + libpri-OpenH323-exception mif-exception openvpn-openssl-exception u-boot-exception-2.0 + vsftpd-openssl-exception x11vnc-openssl-exception ].freeze diff --git a/lib/yarp.rb b/lib/yarp.rb index 30f361df074163..aa92113d2cc6dc 100644 --- a/lib/yarp.rb +++ b/lib/yarp.rb @@ -381,6 +381,10 @@ def self.cruby_locals(source) # of those here. names = names.grep_v(/^_\d$/) + # For some reason, CRuby occasionally pushes this special local + # variable when there are splat arguments. We get rid of that here. + names = names.grep_v(:"#arg_rest") + # Now push them onto the list of locals. locals << names end diff --git a/lib/yarp/node.rb b/lib/yarp/node.rb deleted file mode 100644 index b01d9ed24b4d5b..00000000000000 --- a/lib/yarp/node.rb +++ /dev/null @@ -1,7480 +0,0 @@ -# frozen_string_literal: true -=begin -This file is generated by the bin/template script and should not be -modified manually. See templates/lib/yarp/node.rb.erb -if you are looking to modify the template -=end - -module YARP - # Represents the use of the `alias` keyword. - # - # alias foo bar - # ^^^^^^^^^^^^^ - class AliasNode < Node - # attr_reader new_name: Node - attr_reader :new_name - - # attr_reader old_name: Node - attr_reader :old_name - - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # def initialize: (new_name: Node, old_name: Node, keyword_loc: Location, location: Location) -> void - def initialize(new_name, old_name, keyword_loc, location) - @new_name = new_name - @old_name = old_name - @keyword_loc = keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_alias_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [new_name, old_name] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { new_name: new_name, old_name: old_name, keyword_loc: keyword_loc, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - end - - # Represents an alternation pattern in pattern matching. - # - # foo => bar | baz - # ^^^^^^^^^ - class AlternationPatternNode < Node - # attr_reader left: Node - attr_reader :left - - # attr_reader right: Node - attr_reader :right - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (left: Node, right: Node, operator_loc: Location, location: Location) -> void - def initialize(left, right, operator_loc, location) - @left = left - @right = right - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_alternation_pattern_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [left, right] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { left: left, right: right, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `&&` operator or the `and` keyword. - # - # left and right - # ^^^^^^^^^^^^^^ - class AndNode < Node - # attr_reader left: Node - attr_reader :left - - # attr_reader right: Node - attr_reader :right - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (left: Node, right: Node, operator_loc: Location, location: Location) -> void - def initialize(left, right, operator_loc, location) - @left = left - @right = right - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_and_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [left, right] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { left: left, right: right, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents a set of arguments to a method or a keyword. - # - # return foo, bar, baz - # ^^^^^^^^^^^^^ - class ArgumentsNode < Node - # attr_reader arguments: Array[Node] - attr_reader :arguments - - # def initialize: (arguments: Array[Node], location: Location) -> void - def initialize(arguments, location) - @arguments = arguments - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_arguments_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*arguments] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { arguments: arguments, location: location } - end - end - - # Represents an array literal. This can be a regular array using brackets or - # a special array using % like %w or %i. - # - # [1, 2, 3] - # ^^^^^^^^^ - class ArrayNode < Node - # attr_reader elements: Array[Node] - attr_reader :elements - - # attr_reader opening_loc: Location? - attr_reader :opening_loc - - # attr_reader closing_loc: Location? - attr_reader :closing_loc - - # def initialize: (elements: Array[Node], opening_loc: Location?, closing_loc: Location?, location: Location) -> void - def initialize(elements, opening_loc, closing_loc, location) - @elements = elements - @opening_loc = opening_loc - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_array_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*elements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { elements: elements, opening_loc: opening_loc, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String? - def opening - opening_loc&.slice - end - - # def closing: () -> String? - def closing - closing_loc&.slice - end - end - - # Represents an array pattern in pattern matching. - # - # foo in 1, 2 - # ^^^^^^^^^^^ - # - # foo in [1, 2] - # ^^^^^^^^^^^^^ - # - # foo in *1 - # ^^^^^^^^^ - # - # foo in Bar[] - # ^^^^^^^^^^^^ - # - # foo in Bar[1, 2, 3] - # ^^^^^^^^^^^^^^^^^^^ - class ArrayPatternNode < Node - # attr_reader constant: Node? - attr_reader :constant - - # attr_reader requireds: Array[Node] - attr_reader :requireds - - # attr_reader rest: Node? - attr_reader :rest - - # attr_reader posts: Array[Node] - attr_reader :posts - - # attr_reader opening_loc: Location? - attr_reader :opening_loc - - # attr_reader closing_loc: Location? - attr_reader :closing_loc - - # def initialize: (constant: Node?, requireds: Array[Node], rest: Node?, posts: Array[Node], opening_loc: Location?, closing_loc: Location?, location: Location) -> void - def initialize(constant, requireds, rest, posts, opening_loc, closing_loc, location) - @constant = constant - @requireds = requireds - @rest = rest - @posts = posts - @opening_loc = opening_loc - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_array_pattern_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [constant, *requireds, rest, *posts] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { constant: constant, requireds: requireds, rest: rest, posts: posts, opening_loc: opening_loc, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String? - def opening - opening_loc&.slice - end - - # def closing: () -> String? - def closing - closing_loc&.slice - end - end - - # Represents a hash key/value pair. - # - # { a => b } - # ^^^^^^ - class AssocNode < Node - # attr_reader key: Node - attr_reader :key - - # attr_reader value: Node? - attr_reader :value - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # def initialize: (key: Node, value: Node?, operator_loc: Location?, location: Location) -> void - def initialize(key, value, operator_loc, location) - @key = key - @value = value - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_assoc_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [key, value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { key: key, value: value, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - end - - # Represents a splat in a hash literal. - # - # { **foo } - # ^^^^^ - class AssocSplatNode < Node - # attr_reader value: Node? - attr_reader :value - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (value: Node?, operator_loc: Location, location: Location) -> void - def initialize(value, operator_loc, location) - @value = value - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_assoc_splat_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { value: value, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents reading a reference to a field in the previous match. - # - # $' - # ^^ - class BackReferenceReadNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_back_reference_read_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents a begin statement. - # - # begin - # foo - # end - # ^^^^^ - class BeginNode < Node - # attr_reader begin_keyword_loc: Location? - attr_reader :begin_keyword_loc - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader rescue_clause: Node? - attr_reader :rescue_clause - - # attr_reader else_clause: Node? - attr_reader :else_clause - - # attr_reader ensure_clause: Node? - attr_reader :ensure_clause - - # attr_reader end_keyword_loc: Location? - attr_reader :end_keyword_loc - - # def initialize: (begin_keyword_loc: Location?, statements: Node?, rescue_clause: Node?, else_clause: Node?, ensure_clause: Node?, end_keyword_loc: Location?, location: Location) -> void - def initialize(begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc, location) - @begin_keyword_loc = begin_keyword_loc - @statements = statements - @rescue_clause = rescue_clause - @else_clause = else_clause - @ensure_clause = ensure_clause - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_begin_node(self) - end - - def set_newline_flag(newline_marked) - # Never mark BeginNode with a newline flag, mark children instead - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [statements, rescue_clause, else_clause, ensure_clause] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { begin_keyword_loc: begin_keyword_loc, statements: statements, rescue_clause: rescue_clause, else_clause: else_clause, ensure_clause: ensure_clause, end_keyword_loc: end_keyword_loc, location: location } - end - - # def begin_keyword: () -> String? - def begin_keyword - begin_keyword_loc&.slice - end - - # def end_keyword: () -> String? - def end_keyword - end_keyword_loc&.slice - end - end - - # Represents block method arguments. - # - # bar(&args) - # ^^^^^^^^^^ - class BlockArgumentNode < Node - # attr_reader expression: Node? - attr_reader :expression - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (expression: Node?, operator_loc: Location, location: Location) -> void - def initialize(expression, operator_loc, location) - @expression = expression - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_block_argument_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [expression] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { expression: expression, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents a block of ruby code. - # - # [1, 2, 3].each { |i| puts x } - # ^^^^^^^^^^^^^^ - class BlockNode < Node - # attr_reader locals: Array[Symbol] - attr_reader :locals - - # attr_reader parameters: Node? - attr_reader :parameters - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # def initialize: (locals: Array[Symbol], parameters: Node?, statements: Node?, opening_loc: Location, closing_loc: Location, location: Location) -> void - def initialize(locals, parameters, statements, opening_loc, closing_loc, location) - @locals = locals - @parameters = parameters - @statements = statements - @opening_loc = opening_loc - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_block_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [parameters, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { locals: locals, parameters: parameters, statements: statements, opening_loc: opening_loc, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - end - - # Represents a block parameter to a method, block, or lambda definition. - # - # def a(&b) - # ^^ - # end - class BlockParameterNode < Node - # attr_reader name_loc: Location? - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (name_loc: Location?, operator_loc: Location, location: Location) -> void - def initialize(name_loc, operator_loc, location) - @name_loc = name_loc - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_block_parameter_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, location: location } - end - - # def name: () -> String? - def name - name_loc&.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents a block's parameters declaration. - # - # -> (a, b = 1; local) { } - # ^^^^^^^^^^^^^^^^^ - # - # foo do |a, b = 1; local| - # ^^^^^^^^^^^^^^^^^ - # end - class BlockParametersNode < Node - # attr_reader parameters: Node? - attr_reader :parameters - - # attr_reader locals: Array[Location] - attr_reader :locals - - # attr_reader opening_loc: Location? - attr_reader :opening_loc - - # attr_reader closing_loc: Location? - attr_reader :closing_loc - - # def initialize: (parameters: Node?, locals: Array[Location], opening_loc: Location?, closing_loc: Location?, location: Location) -> void - def initialize(parameters, locals, opening_loc, closing_loc, location) - @parameters = parameters - @locals = locals - @opening_loc = opening_loc - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_block_parameters_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [parameters] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { parameters: parameters, locals: locals, opening_loc: opening_loc, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String? - def opening - opening_loc&.slice - end - - # def closing: () -> String? - def closing - closing_loc&.slice - end - end - - # Represents the use of the `break` keyword. - # - # break foo - # ^^^^^^^^^ - class BreakNode < Node - # attr_reader arguments: Node? - attr_reader :arguments - - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # def initialize: (arguments: Node?, keyword_loc: Location, location: Location) -> void - def initialize(arguments, keyword_loc, location) - @arguments = arguments - @keyword_loc = keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_break_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [arguments] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { arguments: arguments, keyword_loc: keyword_loc, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - end - - # Represents a method call, in all of the various forms that can take. - # - # foo - # ^^^ - # - # foo() - # ^^^^^ - # - # +foo - # ^^^^ - # - # foo + bar - # ^^^^^^^^^ - # - # foo.bar - # ^^^^^^^ - # - # foo&.bar - # ^^^^^^^^ - class CallNode < Node - # attr_reader receiver: Node? - attr_reader :receiver - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # attr_reader message_loc: Location? - attr_reader :message_loc - - # attr_reader opening_loc: Location? - attr_reader :opening_loc - - # attr_reader arguments: Node? - attr_reader :arguments - - # attr_reader closing_loc: Location? - attr_reader :closing_loc - - # attr_reader block: Node? - attr_reader :block - - # attr_reader flags: Integer - attr_reader :flags - - # attr_reader name: String - attr_reader :name - - # def initialize: (receiver: Node?, operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: Node?, closing_loc: Location?, block: Node?, flags: Integer, name: String, location: Location) -> void - def initialize(receiver, operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location) - @receiver = receiver - @operator_loc = operator_loc - @message_loc = message_loc - @opening_loc = opening_loc - @arguments = arguments - @closing_loc = closing_loc - @block = block - @flags = flags - @name = name - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_call_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [receiver, arguments, block] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { receiver: receiver, operator_loc: operator_loc, message_loc: message_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block, flags: flags, name: name, location: location } - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - - # def message: () -> String? - def message - message_loc&.slice - end - - # def opening: () -> String? - def opening - opening_loc&.slice - end - - # def closing: () -> String? - def closing - closing_loc&.slice - end - - # def safe_navigation?: () -> bool - def safe_navigation? - flags.anybits?(CallNodeFlags::SAFE_NAVIGATION) - end - - # def variable_call?: () -> bool - def variable_call? - flags.anybits?(CallNodeFlags::VARIABLE_CALL) - end - end - - # Represents the use of the `&&=` operator on a call. - # - # foo.bar &&= value - # ^^^^^^^^^^^^^^^^^ - class CallOperatorAndWriteNode < Node - # attr_reader target: Node - attr_reader :target - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (target: Node, operator_loc: Location, value: Node, location: Location) -> void - def initialize(target, operator_loc, value, location) - @target = target - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_call_operator_and_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [target, value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { target: target, operator_loc: operator_loc, value: value, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `||=` operator on a call. - # - # foo.bar ||= value - # ^^^^^^^^^^^^^^^^^ - class CallOperatorOrWriteNode < Node - # attr_reader target: Node - attr_reader :target - - # attr_reader value: Node - attr_reader :value - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (target: Node, value: Node, operator_loc: Location, location: Location) -> void - def initialize(target, value, operator_loc, location) - @target = target - @value = value - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_call_operator_or_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [target, value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { target: target, value: value, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of an assignment operator on a call. - # - # foo.bar += baz - # ^^^^^^^^^^^^^^ - class CallOperatorWriteNode < Node - # attr_reader target: Node - attr_reader :target - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # attr_reader operator_id: Symbol - attr_reader :operator_id - - # def initialize: (target: Node, operator_loc: Location, value: Node, operator_id: Symbol, location: Location) -> void - def initialize(target, operator_loc, value, operator_id, location) - @target = target - @operator_loc = operator_loc - @value = value - @operator_id = operator_id - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_call_operator_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [target, value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { target: target, operator_loc: operator_loc, value: value, operator_id: operator_id, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents assigning to a local variable in pattern matching. - # - # foo => [bar => baz] - # ^^^^^^^^^^^^ - class CapturePatternNode < Node - # attr_reader value: Node - attr_reader :value - - # attr_reader target: Node - attr_reader :target - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (value: Node, target: Node, operator_loc: Location, location: Location) -> void - def initialize(value, target, operator_loc, location) - @value = value - @target = target - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_capture_pattern_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value, target] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { value: value, target: target, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of a case statement. - # - # case true - # ^^^^^^^^^ - # when false - # end - class CaseNode < Node - # attr_reader predicate: Node? - attr_reader :predicate - - # attr_reader conditions: Array[Node] - attr_reader :conditions - - # attr_reader consequent: Node? - attr_reader :consequent - - # attr_reader case_keyword_loc: Location - attr_reader :case_keyword_loc - - # attr_reader end_keyword_loc: Location - attr_reader :end_keyword_loc - - # def initialize: (predicate: Node?, conditions: Array[Node], consequent: Node?, case_keyword_loc: Location, end_keyword_loc: Location, location: Location) -> void - def initialize(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location) - @predicate = predicate - @conditions = conditions - @consequent = consequent - @case_keyword_loc = case_keyword_loc - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_case_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [predicate, *conditions, consequent] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { predicate: predicate, conditions: conditions, consequent: consequent, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc, location: location } - end - - # def case_keyword: () -> String - def case_keyword - case_keyword_loc.slice - end - - # def end_keyword: () -> String - def end_keyword - end_keyword_loc.slice - end - end - - # Represents a class declaration involving the `class` keyword. - # - # class Foo end - # ^^^^^^^^^^^^^ - class ClassNode < Node - # attr_reader locals: Array[Symbol] - attr_reader :locals - - # attr_reader class_keyword_loc: Location - attr_reader :class_keyword_loc - - # attr_reader constant_path: Node - attr_reader :constant_path - - # attr_reader inheritance_operator_loc: Location? - attr_reader :inheritance_operator_loc - - # attr_reader superclass: Node? - attr_reader :superclass - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader end_keyword_loc: Location - attr_reader :end_keyword_loc - - # def initialize: (locals: Array[Symbol], class_keyword_loc: Location, constant_path: Node, inheritance_operator_loc: Location?, superclass: Node?, statements: Node?, end_keyword_loc: Location, location: Location) -> void - def initialize(locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, statements, end_keyword_loc, location) - @locals = locals - @class_keyword_loc = class_keyword_loc - @constant_path = constant_path - @inheritance_operator_loc = inheritance_operator_loc - @superclass = superclass - @statements = statements - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_class_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [constant_path, superclass, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { locals: locals, class_keyword_loc: class_keyword_loc, constant_path: constant_path, inheritance_operator_loc: inheritance_operator_loc, superclass: superclass, statements: statements, end_keyword_loc: end_keyword_loc, location: location } - end - - # def class_keyword: () -> String - def class_keyword - class_keyword_loc.slice - end - - # def inheritance_operator: () -> String? - def inheritance_operator - inheritance_operator_loc&.slice - end - - # def end_keyword: () -> String - def end_keyword - end_keyword_loc.slice - end - end - - # Represents the use of the `&&=` operator for assignment to a class variable. - # - # @@target &&= value - # ^^^^^^^^^^^^^^^^ - class ClassVariableOperatorAndWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_class_variable_operator_and_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `||=` operator for assignment to a class variable. - # - # @@target ||= value - # ^^^^^^^^^^^^^^^^^^ - class ClassVariableOperatorOrWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_class_variable_operator_or_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents assigning to a class variable using an operator that isn't `=`. - # - # @@target += value - # ^^^^^^^^^^^^^^^^^ - class ClassVariableOperatorWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # attr_reader operator: Symbol - attr_reader :operator - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, operator: Symbol, location: Location) -> void - def initialize(name_loc, operator_loc, value, operator, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @operator = operator - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_class_variable_operator_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, operator: operator, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - end - - # Represents referencing a class variable. - # - # @@foo - # ^^^^^ - class ClassVariableReadNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_class_variable_read_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents writing to a class variable. - # - # @@foo = 1 - # ^^^^^^^^^ - class ClassVariableWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader value: Node? - attr_reader :value - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # def initialize: (name_loc: Location, value: Node?, operator_loc: Location?, location: Location) -> void - def initialize(name_loc, value, operator_loc, location) - @name_loc = name_loc - @value = value - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_class_variable_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, value: value, operator_loc: operator_loc, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - end - - # Represents the use of the `&&=` operator for assignment to a constant. - # - # Target &&= value - # ^^^^^^^^^^^^^^^^ - class ConstantOperatorAndWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_constant_operator_and_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `||=` operator for assignment to a constant. - # - # Target ||= value - # ^^^^^^^^^^^^^^^^ - class ConstantOperatorOrWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_constant_operator_or_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents assigning to a constant using an operator that isn't `=`. - # - # Target += value - # ^^^^^^^^^^^^^^^ - class ConstantOperatorWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # attr_reader operator: Symbol - attr_reader :operator - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, operator: Symbol, location: Location) -> void - def initialize(name_loc, operator_loc, value, operator, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @operator = operator - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_constant_operator_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, operator: operator, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - end - - # Represents accessing a constant through a path of `::` operators. - # - # Foo::Bar - # ^^^^^^^^ - class ConstantPathNode < Node - # attr_reader parent: Node? - attr_reader :parent - - # attr_reader child: Node - attr_reader :child - - # attr_reader delimiter_loc: Location - attr_reader :delimiter_loc - - # def initialize: (parent: Node?, child: Node, delimiter_loc: Location, location: Location) -> void - def initialize(parent, child, delimiter_loc, location) - @parent = parent - @child = child - @delimiter_loc = delimiter_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_constant_path_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [parent, child] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { parent: parent, child: child, delimiter_loc: delimiter_loc, location: location } - end - - # def delimiter: () -> String - def delimiter - delimiter_loc.slice - end - end - - # Represents the use of the `&&=` operator for assignment to a constant path. - # - # Parent::Child &&= value - # ^^^^^^^^^^^^^^^^^^^^^^^ - class ConstantPathOperatorAndWriteNode < Node - # attr_reader target: Node - attr_reader :target - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (target: Node, operator_loc: Location, value: Node, location: Location) -> void - def initialize(target, operator_loc, value, location) - @target = target - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_constant_path_operator_and_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [target, value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { target: target, operator_loc: operator_loc, value: value, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `||=` operator for assignment to a constant path. - # - # Parent::Child ||= value - # ^^^^^^^^^^^^^^^^^^^^^^^ - class ConstantPathOperatorOrWriteNode < Node - # attr_reader target: Node - attr_reader :target - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (target: Node, operator_loc: Location, value: Node, location: Location) -> void - def initialize(target, operator_loc, value, location) - @target = target - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_constant_path_operator_or_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [target, value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { target: target, operator_loc: operator_loc, value: value, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents assigning to a constant path using an operator that isn't `=`. - # - # Parent::Child += value - # ^^^^^^^^^^^^^^^^^^^^^^ - class ConstantPathOperatorWriteNode < Node - # attr_reader target: Node - attr_reader :target - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # attr_reader operator: Symbol - attr_reader :operator - - # def initialize: (target: Node, operator_loc: Location, value: Node, operator: Symbol, location: Location) -> void - def initialize(target, operator_loc, value, operator, location) - @target = target - @operator_loc = operator_loc - @value = value - @operator = operator - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_constant_path_operator_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [target, value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { target: target, operator_loc: operator_loc, value: value, operator: operator, location: location } - end - end - - # Represents writing to a constant path. - # - # ::Foo = 1 - # ^^^^^^^^^ - # - # Foo::Bar = 1 - # ^^^^^^^^^^^^ - # - # ::Foo::Bar = 1 - # ^^^^^^^^^^^^^^ - class ConstantPathWriteNode < Node - # attr_reader target: Node - attr_reader :target - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # attr_reader value: Node? - attr_reader :value - - # def initialize: (target: Node, operator_loc: Location?, value: Node?, location: Location) -> void - def initialize(target, operator_loc, value, location) - @target = target - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_constant_path_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [target, value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { target: target, operator_loc: operator_loc, value: value, location: location } - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - end - - # Represents referencing a constant. - # - # Foo - # ^^^ - class ConstantReadNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_constant_read_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents writing to a constant. - # - # Foo = 1 - # ^^^^^^^ - class ConstantWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader value: Node? - attr_reader :value - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # def initialize: (name_loc: Location, value: Node?, operator_loc: Location?, location: Location) -> void - def initialize(name_loc, value, operator_loc, location) - @name_loc = name_loc - @value = value - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_constant_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, value: value, operator_loc: operator_loc, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - end - - # Represents a method definition. - # - # def method - # end - # ^^^^^^^^^^ - class DefNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader receiver: Node? - attr_reader :receiver - - # attr_reader parameters: Node? - attr_reader :parameters - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader locals: Array[Symbol] - attr_reader :locals - - # attr_reader def_keyword_loc: Location - attr_reader :def_keyword_loc - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # attr_reader lparen_loc: Location? - attr_reader :lparen_loc - - # attr_reader rparen_loc: Location? - attr_reader :rparen_loc - - # attr_reader equal_loc: Location? - attr_reader :equal_loc - - # attr_reader end_keyword_loc: Location? - attr_reader :end_keyword_loc - - # def initialize: (name_loc: Location, receiver: Node?, parameters: Node?, statements: Node?, locals: Array[Symbol], def_keyword_loc: Location, operator_loc: Location?, lparen_loc: Location?, rparen_loc: Location?, equal_loc: Location?, end_keyword_loc: Location?, location: Location) -> void - def initialize(name_loc, receiver, parameters, statements, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location) - @name_loc = name_loc - @receiver = receiver - @parameters = parameters - @statements = statements - @locals = locals - @def_keyword_loc = def_keyword_loc - @operator_loc = operator_loc - @lparen_loc = lparen_loc - @rparen_loc = rparen_loc - @equal_loc = equal_loc - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_def_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [receiver, parameters, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, receiver: receiver, parameters: parameters, statements: statements, locals: locals, def_keyword_loc: def_keyword_loc, operator_loc: operator_loc, lparen_loc: lparen_loc, rparen_loc: rparen_loc, equal_loc: equal_loc, end_keyword_loc: end_keyword_loc, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def def_keyword: () -> String - def def_keyword - def_keyword_loc.slice - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - - # def lparen: () -> String? - def lparen - lparen_loc&.slice - end - - # def rparen: () -> String? - def rparen - rparen_loc&.slice - end - - # def equal: () -> String? - def equal - equal_loc&.slice - end - - # def end_keyword: () -> String? - def end_keyword - end_keyword_loc&.slice - end - end - - # Represents the use of the `defined?` keyword. - # - # defined?(a) - # ^^^^^^^^^^^ - class DefinedNode < Node - # attr_reader lparen_loc: Location? - attr_reader :lparen_loc - - # attr_reader value: Node - attr_reader :value - - # attr_reader rparen_loc: Location? - attr_reader :rparen_loc - - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # def initialize: (lparen_loc: Location?, value: Node, rparen_loc: Location?, keyword_loc: Location, location: Location) -> void - def initialize(lparen_loc, value, rparen_loc, keyword_loc, location) - @lparen_loc = lparen_loc - @value = value - @rparen_loc = rparen_loc - @keyword_loc = keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_defined_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { lparen_loc: lparen_loc, value: value, rparen_loc: rparen_loc, keyword_loc: keyword_loc, location: location } - end - - # def lparen: () -> String? - def lparen - lparen_loc&.slice - end - - # def rparen: () -> String? - def rparen - rparen_loc&.slice - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - end - - # Represents an `else` clause in a `case`, `if`, or `unless` statement. - # - # if a then b else c end - # ^^^^^^^^^^ - class ElseNode < Node - # attr_reader else_keyword_loc: Location - attr_reader :else_keyword_loc - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader end_keyword_loc: Location? - attr_reader :end_keyword_loc - - # def initialize: (else_keyword_loc: Location, statements: Node?, end_keyword_loc: Location?, location: Location) -> void - def initialize(else_keyword_loc, statements, end_keyword_loc, location) - @else_keyword_loc = else_keyword_loc - @statements = statements - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_else_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { else_keyword_loc: else_keyword_loc, statements: statements, end_keyword_loc: end_keyword_loc, location: location } - end - - # def else_keyword: () -> String - def else_keyword - else_keyword_loc.slice - end - - # def end_keyword: () -> String? - def end_keyword - end_keyword_loc&.slice - end - end - - # Represents an interpolated set of statements. - # - # "foo #{bar}" - # ^^^^^^ - class EmbeddedStatementsNode < Node - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # def initialize: (opening_loc: Location, statements: Node?, closing_loc: Location, location: Location) -> void - def initialize(opening_loc, statements, closing_loc, location) - @opening_loc = opening_loc - @statements = statements - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_embedded_statements_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { opening_loc: opening_loc, statements: statements, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - end - - # Represents an interpolated variable. - # - # "foo #@bar" - # ^^^^^ - class EmbeddedVariableNode < Node - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader variable: Node - attr_reader :variable - - # def initialize: (operator_loc: Location, variable: Node, location: Location) -> void - def initialize(operator_loc, variable, location) - @operator_loc = operator_loc - @variable = variable - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_embedded_variable_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [variable] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { operator_loc: operator_loc, variable: variable, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents an `ensure` clause in a `begin` statement. - # - # begin - # foo - # ensure - # ^^^^^^ - # bar - # end - class EnsureNode < Node - # attr_reader ensure_keyword_loc: Location - attr_reader :ensure_keyword_loc - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader end_keyword_loc: Location - attr_reader :end_keyword_loc - - # def initialize: (ensure_keyword_loc: Location, statements: Node?, end_keyword_loc: Location, location: Location) -> void - def initialize(ensure_keyword_loc, statements, end_keyword_loc, location) - @ensure_keyword_loc = ensure_keyword_loc - @statements = statements - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_ensure_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { ensure_keyword_loc: ensure_keyword_loc, statements: statements, end_keyword_loc: end_keyword_loc, location: location } - end - - # def ensure_keyword: () -> String - def ensure_keyword - ensure_keyword_loc.slice - end - - # def end_keyword: () -> String - def end_keyword - end_keyword_loc.slice - end - end - - # Represents the use of the literal `false` keyword. - # - # false - # ^^^^^ - class FalseNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_false_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents a find pattern in pattern matching. - # - # foo in *bar, baz, *qux - # ^^^^^^^^^^^^^^^^^^^^^^ - # - # foo in [*bar, baz, *qux] - # ^^^^^^^^^^^^^^^^^^^^^^^^ - # - # foo in Foo(*bar, baz, *qux) - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - class FindPatternNode < Node - # attr_reader constant: Node? - attr_reader :constant - - # attr_reader left: Node - attr_reader :left - - # attr_reader requireds: Array[Node] - attr_reader :requireds - - # attr_reader right: Node - attr_reader :right - - # attr_reader opening_loc: Location? - attr_reader :opening_loc - - # attr_reader closing_loc: Location? - attr_reader :closing_loc - - # def initialize: (constant: Node?, left: Node, requireds: Array[Node], right: Node, opening_loc: Location?, closing_loc: Location?, location: Location) -> void - def initialize(constant, left, requireds, right, opening_loc, closing_loc, location) - @constant = constant - @left = left - @requireds = requireds - @right = right - @opening_loc = opening_loc - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_find_pattern_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [constant, left, *requireds, right] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { constant: constant, left: left, requireds: requireds, right: right, opening_loc: opening_loc, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String? - def opening - opening_loc&.slice - end - - # def closing: () -> String? - def closing - closing_loc&.slice - end - end - - # Represents the use of the `..` or `...` operators to create flip flops. - # - # baz if foo .. bar - # ^^^^^^^^^^ - class FlipFlopNode < Node - # attr_reader left: Node? - attr_reader :left - - # attr_reader right: Node? - attr_reader :right - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader flags: Integer - attr_reader :flags - - # def initialize: (left: Node?, right: Node?, operator_loc: Location, flags: Integer, location: Location) -> void - def initialize(left, right, operator_loc, flags, location) - @left = left - @right = right - @operator_loc = operator_loc - @flags = flags - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_flip_flop_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [left, right] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { left: left, right: right, operator_loc: operator_loc, flags: flags, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - - # def exclude_end?: () -> bool - def exclude_end? - flags.anybits?(RangeFlags::EXCLUDE_END) - end - end - - # Represents a floating point number literal. - # - # 1.0 - # ^^^ - class FloatNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_float_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents the use of the `for` keyword. - # - # for i in a end - # ^^^^^^^^^^^^^^ - class ForNode < Node - # attr_reader index: Node - attr_reader :index - - # attr_reader collection: Node - attr_reader :collection - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader for_keyword_loc: Location - attr_reader :for_keyword_loc - - # attr_reader in_keyword_loc: Location - attr_reader :in_keyword_loc - - # attr_reader do_keyword_loc: Location? - attr_reader :do_keyword_loc - - # attr_reader end_keyword_loc: Location - attr_reader :end_keyword_loc - - # def initialize: (index: Node, collection: Node, statements: Node?, for_keyword_loc: Location, in_keyword_loc: Location, do_keyword_loc: Location?, end_keyword_loc: Location, location: Location) -> void - def initialize(index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc, location) - @index = index - @collection = collection - @statements = statements - @for_keyword_loc = for_keyword_loc - @in_keyword_loc = in_keyword_loc - @do_keyword_loc = do_keyword_loc - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_for_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [index, collection, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { index: index, collection: collection, statements: statements, for_keyword_loc: for_keyword_loc, in_keyword_loc: in_keyword_loc, do_keyword_loc: do_keyword_loc, end_keyword_loc: end_keyword_loc, location: location } - end - - # def for_keyword: () -> String - def for_keyword - for_keyword_loc.slice - end - - # def in_keyword: () -> String - def in_keyword - in_keyword_loc.slice - end - - # def do_keyword: () -> String? - def do_keyword - do_keyword_loc&.slice - end - - # def end_keyword: () -> String - def end_keyword - end_keyword_loc.slice - end - end - - # Represents forwarding all arguments to this method to another method. - # - # def foo(...) - # bar(...) - # ^^^^^^^^ - # end - class ForwardingArgumentsNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_forwarding_arguments_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents the use of the forwarding parameter in a method, block, or lambda declaration. - # - # def foo(...) - # ^^^ - # end - class ForwardingParameterNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_forwarding_parameter_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents the use of the `super` keyword without parentheses or arguments. - # - # super - # ^^^^^ - class ForwardingSuperNode < Node - # attr_reader block: Node? - attr_reader :block - - # def initialize: (block: Node?, location: Location) -> void - def initialize(block, location) - @block = block - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_forwarding_super_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [block] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { block: block, location: location } - end - end - - # Represents the use of the `&&=` operator for assignment to a global variable. - # - # $target &&= value - # ^^^^^^^^^^^^^^^^^ - class GlobalVariableOperatorAndWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_global_variable_operator_and_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `||=` operator for assignment to a global variable. - # - # $target ||= value - # ^^^^^^^^^^^^^^^^^ - class GlobalVariableOperatorOrWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_global_variable_operator_or_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents assigning to a global variable using an operator that isn't `=`. - # - # $target += value - # ^^^^^^^^^^^^^^^^ - class GlobalVariableOperatorWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # attr_reader operator: Symbol - attr_reader :operator - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, operator: Symbol, location: Location) -> void - def initialize(name_loc, operator_loc, value, operator, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @operator = operator - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_global_variable_operator_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, operator: operator, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - end - - # Represents referencing a global variable. - # - # $foo - # ^^^^ - class GlobalVariableReadNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_global_variable_read_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents writing to a global variable. - # - # $foo = 1 - # ^^^^^^^^ - class GlobalVariableWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # attr_reader value: Node? - attr_reader :value - - # def initialize: (name_loc: Location, operator_loc: Location?, value: Node?, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_global_variable_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - end - - # Represents a hash literal. - # - # { a => b } - # ^^^^^^^^^^ - class HashNode < Node - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader elements: Array[Node] - attr_reader :elements - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # def initialize: (opening_loc: Location, elements: Array[Node], closing_loc: Location, location: Location) -> void - def initialize(opening_loc, elements, closing_loc, location) - @opening_loc = opening_loc - @elements = elements - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_hash_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*elements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { opening_loc: opening_loc, elements: elements, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - end - - # Represents a hash pattern in pattern matching. - # - # foo => { a: 1, b: 2 } - # ^^^^^^^^^^^^^^ - # - # foo => { a: 1, b: 2, **c } - # ^^^^^^^^^^^^^^^^^^^ - class HashPatternNode < Node - # attr_reader constant: Node? - attr_reader :constant - - # attr_reader assocs: Array[Node] - attr_reader :assocs - - # attr_reader kwrest: Node? - attr_reader :kwrest - - # attr_reader opening_loc: Location? - attr_reader :opening_loc - - # attr_reader closing_loc: Location? - attr_reader :closing_loc - - # def initialize: (constant: Node?, assocs: Array[Node], kwrest: Node?, opening_loc: Location?, closing_loc: Location?, location: Location) -> void - def initialize(constant, assocs, kwrest, opening_loc, closing_loc, location) - @constant = constant - @assocs = assocs - @kwrest = kwrest - @opening_loc = opening_loc - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_hash_pattern_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [constant, *assocs, kwrest] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { constant: constant, assocs: assocs, kwrest: kwrest, opening_loc: opening_loc, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String? - def opening - opening_loc&.slice - end - - # def closing: () -> String? - def closing - closing_loc&.slice - end - end - - # Represents the use of the `if` keyword, either in the block form or the modifier form. - # - # bar if foo - # ^^^^^^^^^^ - # - # if foo then bar end - # ^^^^^^^^^^^^^^^^^^^ - class IfNode < Node - # attr_reader if_keyword_loc: Location? - attr_reader :if_keyword_loc - - # attr_reader predicate: Node - attr_reader :predicate - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader consequent: Node? - attr_reader :consequent - - # attr_reader end_keyword_loc: Location? - attr_reader :end_keyword_loc - - # def initialize: (if_keyword_loc: Location?, predicate: Node, statements: Node?, consequent: Node?, end_keyword_loc: Location?, location: Location) -> void - def initialize(if_keyword_loc, predicate, statements, consequent, end_keyword_loc, location) - @if_keyword_loc = if_keyword_loc - @predicate = predicate - @statements = statements - @consequent = consequent - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_if_node(self) - end - - def set_newline_flag(newline_marked) - predicate.set_newline_flag(newline_marked) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [predicate, statements, consequent] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { if_keyword_loc: if_keyword_loc, predicate: predicate, statements: statements, consequent: consequent, end_keyword_loc: end_keyword_loc, location: location } - end - - # def if_keyword: () -> String? - def if_keyword - if_keyword_loc&.slice - end - - # def end_keyword: () -> String? - def end_keyword - end_keyword_loc&.slice - end - end - - # Represents an imaginary number literal. - # - # 1.0i - # ^^^^ - class ImaginaryNode < Node - # attr_reader numeric: Node - attr_reader :numeric - - # def initialize: (numeric: Node, location: Location) -> void - def initialize(numeric, location) - @numeric = numeric - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_imaginary_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [numeric] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { numeric: numeric, location: location } - end - end - - # Represents the use of the `in` keyword in a case statement. - # - # case a; in b then c end - # ^^^^^^^^^^^ - class InNode < Node - # attr_reader pattern: Node - attr_reader :pattern - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader in_loc: Location - attr_reader :in_loc - - # attr_reader then_loc: Location? - attr_reader :then_loc - - # def initialize: (pattern: Node, statements: Node?, in_loc: Location, then_loc: Location?, location: Location) -> void - def initialize(pattern, statements, in_loc, then_loc, location) - @pattern = pattern - @statements = statements - @in_loc = in_loc - @then_loc = then_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_in_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [pattern, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { pattern: pattern, statements: statements, in_loc: in_loc, then_loc: then_loc, location: location } - end - - # def in: () -> String - def in - in_loc.slice - end - - # def then: () -> String? - def then - then_loc&.slice - end - end - - # Represents the use of the `&&=` operator for assignment to an instance variable. - # - # @target &&= value - # ^^^^^^^^^^^^^^^^^ - class InstanceVariableOperatorAndWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_instance_variable_operator_and_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `||=` operator for assignment to an instance variable. - # - # @target ||= value - # ^^^^^^^^^^^^^^^^^ - class InstanceVariableOperatorOrWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_instance_variable_operator_or_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents assigning to an instance variable using an operator that isn't `=`. - # - # @target += value - # ^^^^^^^^^^^^^^^^ - class InstanceVariableOperatorWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # attr_reader operator: Symbol - attr_reader :operator - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, operator: Symbol, location: Location) -> void - def initialize(name_loc, operator_loc, value, operator, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @operator = operator - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_instance_variable_operator_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, operator: operator, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - end - - # Represents referencing an instance variable. - # - # @foo - # ^^^^ - class InstanceVariableReadNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_instance_variable_read_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents writing to an instance variable. - # - # @foo = 1 - # ^^^^^^^^ - class InstanceVariableWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader value: Node? - attr_reader :value - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # def initialize: (name_loc: Location, value: Node?, operator_loc: Location?, location: Location) -> void - def initialize(name_loc, value, operator_loc, location) - @name_loc = name_loc - @value = value - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_instance_variable_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, value: value, operator_loc: operator_loc, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - end - - # Represents an integer number literal. - # - # 1 - # ^ - class IntegerNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_integer_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents a regular expression literal that contains interpolation. - # - # /foo #{bar} baz/ - # ^^^^^^^^^^^^^^^^ - class InterpolatedRegularExpressionNode < Node - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader parts: Array[Node] - attr_reader :parts - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # attr_reader flags: Integer - attr_reader :flags - - # def initialize: (opening_loc: Location, parts: Array[Node], closing_loc: Location, flags: Integer, location: Location) -> void - def initialize(opening_loc, parts, closing_loc, flags, location) - @opening_loc = opening_loc - @parts = parts - @closing_loc = closing_loc - @flags = flags - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_interpolated_regular_expression_node(self) - end - - def set_newline_flag(newline_marked) - first = parts.first - first.set_newline_flag(newline_marked) if first - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*parts] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { opening_loc: opening_loc, parts: parts, closing_loc: closing_loc, flags: flags, location: location } - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - - # def ignore_case?: () -> bool - def ignore_case? - flags.anybits?(RegularExpressionFlags::IGNORE_CASE) - end - - # def multi_line?: () -> bool - def multi_line? - flags.anybits?(RegularExpressionFlags::MULTI_LINE) - end - - # def extended?: () -> bool - def extended? - flags.anybits?(RegularExpressionFlags::EXTENDED) - end - - # def euc_jp?: () -> bool - def euc_jp? - flags.anybits?(RegularExpressionFlags::EUC_JP) - end - - # def ascii_8bit?: () -> bool - def ascii_8bit? - flags.anybits?(RegularExpressionFlags::ASCII_8BIT) - end - - # def windows_31j?: () -> bool - def windows_31j? - flags.anybits?(RegularExpressionFlags::WINDOWS_31J) - end - - # def utf_8?: () -> bool - def utf_8? - flags.anybits?(RegularExpressionFlags::UTF_8) - end - - # def once?: () -> bool - def once? - flags.anybits?(RegularExpressionFlags::ONCE) - end - end - - # Represents a string literal that contains interpolation. - # - # "foo #{bar} baz" - # ^^^^^^^^^^^^^^^^ - class InterpolatedStringNode < Node - # attr_reader opening_loc: Location? - attr_reader :opening_loc - - # attr_reader parts: Array[Node] - attr_reader :parts - - # attr_reader closing_loc: Location? - attr_reader :closing_loc - - # def initialize: (opening_loc: Location?, parts: Array[Node], closing_loc: Location?, location: Location) -> void - def initialize(opening_loc, parts, closing_loc, location) - @opening_loc = opening_loc - @parts = parts - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_interpolated_string_node(self) - end - - def set_newline_flag(newline_marked) - first = parts.first - first.set_newline_flag(newline_marked) if first - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*parts] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { opening_loc: opening_loc, parts: parts, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String? - def opening - opening_loc&.slice - end - - # def closing: () -> String? - def closing - closing_loc&.slice - end - end - - # Represents a symbol literal that contains interpolation. - # - # :"foo #{bar} baz" - # ^^^^^^^^^^^^^^^^^ - class InterpolatedSymbolNode < Node - # attr_reader opening_loc: Location? - attr_reader :opening_loc - - # attr_reader parts: Array[Node] - attr_reader :parts - - # attr_reader closing_loc: Location? - attr_reader :closing_loc - - # def initialize: (opening_loc: Location?, parts: Array[Node], closing_loc: Location?, location: Location) -> void - def initialize(opening_loc, parts, closing_loc, location) - @opening_loc = opening_loc - @parts = parts - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_interpolated_symbol_node(self) - end - - def set_newline_flag(newline_marked) - first = parts.first - first.set_newline_flag(newline_marked) if first - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*parts] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { opening_loc: opening_loc, parts: parts, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String? - def opening - opening_loc&.slice - end - - # def closing: () -> String? - def closing - closing_loc&.slice - end - end - - # Represents an xstring literal that contains interpolation. - # - # `foo #{bar} baz` - # ^^^^^^^^^^^^^^^^ - class InterpolatedXStringNode < Node - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader parts: Array[Node] - attr_reader :parts - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # def initialize: (opening_loc: Location, parts: Array[Node], closing_loc: Location, location: Location) -> void - def initialize(opening_loc, parts, closing_loc, location) - @opening_loc = opening_loc - @parts = parts - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_interpolated_x_string_node(self) - end - - def set_newline_flag(newline_marked) - first = parts.first - first.set_newline_flag(newline_marked) if first - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*parts] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { opening_loc: opening_loc, parts: parts, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - end - - # Represents a hash literal without opening and closing braces. - # - # foo(a: b) - # ^^^^ - class KeywordHashNode < Node - # attr_reader elements: Array[Node] - attr_reader :elements - - # def initialize: (elements: Array[Node], location: Location) -> void - def initialize(elements, location) - @elements = elements - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_keyword_hash_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*elements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { elements: elements, location: location } - end - end - - # Represents a keyword parameter to a method, block, or lambda definition. - # - # def a(b:) - # ^^ - # end - # - # def a(b: 1) - # ^^^^ - # end - class KeywordParameterNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader value: Node? - attr_reader :value - - # def initialize: (name_loc: Location, value: Node?, location: Location) -> void - def initialize(name_loc, value, location) - @name_loc = name_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_keyword_parameter_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - end - - # Represents a keyword rest parameter to a method, block, or lambda definition. - # - # def a(**b) - # ^^^ - # end - class KeywordRestParameterNode < Node - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader name_loc: Location? - attr_reader :name_loc - - # def initialize: (operator_loc: Location, name_loc: Location?, location: Location) -> void - def initialize(operator_loc, name_loc, location) - @operator_loc = operator_loc - @name_loc = name_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_keyword_rest_parameter_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { operator_loc: operator_loc, name_loc: name_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - - # def name: () -> String? - def name - name_loc&.slice - end - end - - # Represents using a lambda literal (not the lambda method call). - # - # ->(value) { value * 2 } - # ^^^^^^^^^^^^^^^^^^^^^^^ - class LambdaNode < Node - # attr_reader locals: Array[Symbol] - attr_reader :locals - - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader parameters: Node? - attr_reader :parameters - - # attr_reader statements: Node? - attr_reader :statements - - # def initialize: (locals: Array[Symbol], opening_loc: Location, parameters: Node?, statements: Node?, location: Location) -> void - def initialize(locals, opening_loc, parameters, statements, location) - @locals = locals - @opening_loc = opening_loc - @parameters = parameters - @statements = statements - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_lambda_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [parameters, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { locals: locals, opening_loc: opening_loc, parameters: parameters, statements: statements, location: location } - end - - # def opening: () -> String - def opening - opening_loc.slice - end - end - - # Represents the use of the `&&=` operator for assignment to a local variable. - # - # target &&= value - # ^^^^^^^^^^^^^^^^ - class LocalVariableOperatorAndWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # attr_reader constant_id: Symbol - attr_reader :constant_id - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, constant_id: Symbol, location: Location) -> void - def initialize(name_loc, operator_loc, value, constant_id, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @constant_id = constant_id - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_local_variable_operator_and_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, constant_id: constant_id, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `||=` operator for assignment to a local variable. - # - # target ||= value - # ^^^^^^^^^^^^^^^^ - class LocalVariableOperatorOrWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # attr_reader constant_id: Symbol - attr_reader :constant_id - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, constant_id: Symbol, location: Location) -> void - def initialize(name_loc, operator_loc, value, constant_id, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @constant_id = constant_id - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_local_variable_operator_or_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, constant_id: constant_id, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents assigning to a local variable using an operator that isn't `=`. - # - # target += value - # ^^^^^^^^^^^^^^^ - class LocalVariableOperatorWriteNode < Node - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # attr_reader constant_id: Symbol - attr_reader :constant_id - - # attr_reader operator_id: Symbol - attr_reader :operator_id - - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, constant_id: Symbol, operator_id: Symbol, location: Location) -> void - def initialize(name_loc, operator_loc, value, constant_id, operator_id, location) - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @constant_id = constant_id - @operator_id = operator_id - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_local_variable_operator_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, constant_id: constant_id, operator_id: operator_id, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents reading a local variable. Note that this requires that a local - # variable of the same name has already been written to in the same scope, - # otherwise it is parsed as a method call. - # - # foo - # ^^^ - class LocalVariableReadNode < Node - # attr_reader constant_id: Symbol - attr_reader :constant_id - - # attr_reader depth: Integer - attr_reader :depth - - # def initialize: (constant_id: Symbol, depth: Integer, location: Location) -> void - def initialize(constant_id, depth, location) - @constant_id = constant_id - @depth = depth - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_local_variable_read_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { constant_id: constant_id, depth: depth, location: location } - end - end - - # Represents writing to a local variable. - # - # foo = 1 - # ^^^^^^^ - class LocalVariableWriteNode < Node - # attr_reader constant_id: Symbol - attr_reader :constant_id - - # attr_reader depth: Integer - attr_reader :depth - - # attr_reader value: Node? - attr_reader :value - - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # def initialize: (constant_id: Symbol, depth: Integer, value: Node?, name_loc: Location, operator_loc: Location?, location: Location) -> void - def initialize(constant_id, depth, value, name_loc, operator_loc, location) - @constant_id = constant_id - @depth = depth - @value = value - @name_loc = name_loc - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_local_variable_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { constant_id: constant_id, depth: depth, value: value, name_loc: name_loc, operator_loc: operator_loc, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - end - - # Represents the use of the modifier `in` operator. - # - # foo in bar - # ^^^^^^^^^^ - class MatchPredicateNode < Node - # attr_reader value: Node - attr_reader :value - - # attr_reader pattern: Node - attr_reader :pattern - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (value: Node, pattern: Node, operator_loc: Location, location: Location) -> void - def initialize(value, pattern, operator_loc, location) - @value = value - @pattern = pattern - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_match_predicate_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value, pattern] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { value: value, pattern: pattern, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `=>` operator. - # - # foo => bar - # ^^^^^^^^^^ - class MatchRequiredNode < Node - # attr_reader value: Node - attr_reader :value - - # attr_reader pattern: Node - attr_reader :pattern - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (value: Node, pattern: Node, operator_loc: Location, location: Location) -> void - def initialize(value, pattern, operator_loc, location) - @value = value - @pattern = pattern - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_match_required_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value, pattern] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { value: value, pattern: pattern, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents a node that is missing from the source and results in a syntax - # error. - class MissingNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_missing_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents a module declaration involving the `module` keyword. - # - # module Foo end - # ^^^^^^^^^^^^^^ - class ModuleNode < Node - # attr_reader locals: Array[Symbol] - attr_reader :locals - - # attr_reader module_keyword_loc: Location - attr_reader :module_keyword_loc - - # attr_reader constant_path: Node - attr_reader :constant_path - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader end_keyword_loc: Location - attr_reader :end_keyword_loc - - # def initialize: (locals: Array[Symbol], module_keyword_loc: Location, constant_path: Node, statements: Node?, end_keyword_loc: Location, location: Location) -> void - def initialize(locals, module_keyword_loc, constant_path, statements, end_keyword_loc, location) - @locals = locals - @module_keyword_loc = module_keyword_loc - @constant_path = constant_path - @statements = statements - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_module_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [constant_path, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { locals: locals, module_keyword_loc: module_keyword_loc, constant_path: constant_path, statements: statements, end_keyword_loc: end_keyword_loc, location: location } - end - - # def module_keyword: () -> String - def module_keyword - module_keyword_loc.slice - end - - # def end_keyword: () -> String - def end_keyword - end_keyword_loc.slice - end - end - - # Represents a multi-target expression. - # - # a, b, c = 1, 2, 3 - # ^^^^^^^^^^^^^^^^^ - class MultiWriteNode < Node - # attr_reader targets: Array[Node] - attr_reader :targets - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # attr_reader value: Node? - attr_reader :value - - # attr_reader lparen_loc: Location? - attr_reader :lparen_loc - - # attr_reader rparen_loc: Location? - attr_reader :rparen_loc - - # def initialize: (targets: Array[Node], operator_loc: Location?, value: Node?, lparen_loc: Location?, rparen_loc: Location?, location: Location) -> void - def initialize(targets, operator_loc, value, lparen_loc, rparen_loc, location) - @targets = targets - @operator_loc = operator_loc - @value = value - @lparen_loc = lparen_loc - @rparen_loc = rparen_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_multi_write_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*targets, value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { targets: targets, operator_loc: operator_loc, value: value, lparen_loc: lparen_loc, rparen_loc: rparen_loc, location: location } - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - - # def lparen: () -> String? - def lparen - lparen_loc&.slice - end - - # def rparen: () -> String? - def rparen - rparen_loc&.slice - end - end - - # Represents the use of the `next` keyword. - # - # next 1 - # ^^^^^^ - class NextNode < Node - # attr_reader arguments: Node? - attr_reader :arguments - - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # def initialize: (arguments: Node?, keyword_loc: Location, location: Location) -> void - def initialize(arguments, keyword_loc, location) - @arguments = arguments - @keyword_loc = keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_next_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [arguments] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { arguments: arguments, keyword_loc: keyword_loc, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - end - - # Represents the use of the `nil` keyword. - # - # nil - # ^^^ - class NilNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_nil_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents the use of `**nil` inside method arguments. - # - # def a(**nil) - # ^^^^^ - # end - class NoKeywordsParameterNode < Node - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # def initialize: (operator_loc: Location, keyword_loc: Location, location: Location) -> void - def initialize(operator_loc, keyword_loc, location) - @operator_loc = operator_loc - @keyword_loc = keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_no_keywords_parameter_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { operator_loc: operator_loc, keyword_loc: keyword_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - end - - # Represents reading a numbered reference to a capture in the previous match. - # - # $1 - # ^^ - class NumberedReferenceReadNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_numbered_reference_read_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents an optional parameter to a method, block, or lambda definition. - # - # def a(b = 1) - # ^^^^^ - # end - class OptionalParameterNode < Node - # attr_reader constant_id: Symbol - attr_reader :constant_id - - # attr_reader name_loc: Location - attr_reader :name_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader value: Node - attr_reader :value - - # def initialize: (constant_id: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(constant_id, name_loc, operator_loc, value, location) - @constant_id = constant_id - @name_loc = name_loc - @operator_loc = operator_loc - @value = value - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_optional_parameter_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [value] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { constant_id: constant_id, name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } - end - - # def name: () -> String - def name - name_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `||` operator or the `or` keyword. - # - # left or right - # ^^^^^^^^^^^^^ - class OrNode < Node - # attr_reader left: Node - attr_reader :left - - # attr_reader right: Node - attr_reader :right - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (left: Node, right: Node, operator_loc: Location, location: Location) -> void - def initialize(left, right, operator_loc, location) - @left = left - @right = right - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_or_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [left, right] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { left: left, right: right, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the list of parameters on a method, block, or lambda definition. - # - # def a(b, c, d) - # ^^^^^^^ - # end - class ParametersNode < Node - # attr_reader requireds: Array[Node] - attr_reader :requireds - - # attr_reader optionals: Array[Node] - attr_reader :optionals - - # attr_reader posts: Array[Node] - attr_reader :posts - - # attr_reader rest: Node? - attr_reader :rest - - # attr_reader keywords: Array[Node] - attr_reader :keywords - - # attr_reader keyword_rest: Node? - attr_reader :keyword_rest - - # attr_reader block: Node? - attr_reader :block - - # def initialize: (requireds: Array[Node], optionals: Array[Node], posts: Array[Node], rest: Node?, keywords: Array[Node], keyword_rest: Node?, block: Node?, location: Location) -> void - def initialize(requireds, optionals, posts, rest, keywords, keyword_rest, block, location) - @requireds = requireds - @optionals = optionals - @posts = posts - @rest = rest - @keywords = keywords - @keyword_rest = keyword_rest - @block = block - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_parameters_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*requireds, *optionals, *posts, rest, *keywords, keyword_rest, block] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { requireds: requireds, optionals: optionals, posts: posts, rest: rest, keywords: keywords, keyword_rest: keyword_rest, block: block, location: location } - end - end - - # Represents a parenthesized expression - # - # (10 + 34) - # ^^^^^^^^^ - class ParenthesesNode < Node - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # def initialize: (statements: Node?, opening_loc: Location, closing_loc: Location, location: Location) -> void - def initialize(statements, opening_loc, closing_loc, location) - @statements = statements - @opening_loc = opening_loc - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_parentheses_node(self) - end - - def set_newline_flag(newline_marked) - # Never mark ParenthesesNode with a newline flag, mark children instead - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { statements: statements, opening_loc: opening_loc, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - end - - # Represents the use of the `^` operator for pinning an expression in a - # pattern matching expression. - # - # foo in ^(bar) - # ^^^^^^ - class PinnedExpressionNode < Node - # attr_reader expression: Node - attr_reader :expression - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader lparen_loc: Location - attr_reader :lparen_loc - - # attr_reader rparen_loc: Location - attr_reader :rparen_loc - - # def initialize: (expression: Node, operator_loc: Location, lparen_loc: Location, rparen_loc: Location, location: Location) -> void - def initialize(expression, operator_loc, lparen_loc, rparen_loc, location) - @expression = expression - @operator_loc = operator_loc - @lparen_loc = lparen_loc - @rparen_loc = rparen_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_pinned_expression_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [expression] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { expression: expression, operator_loc: operator_loc, lparen_loc: lparen_loc, rparen_loc: rparen_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - - # def lparen: () -> String - def lparen - lparen_loc.slice - end - - # def rparen: () -> String - def rparen - rparen_loc.slice - end - end - - # Represents the use of the `^` operator for pinning a variable in a pattern - # matching expression. - # - # foo in ^bar - # ^^^^ - class PinnedVariableNode < Node - # attr_reader variable: Node - attr_reader :variable - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # def initialize: (variable: Node, operator_loc: Location, location: Location) -> void - def initialize(variable, operator_loc, location) - @variable = variable - @operator_loc = operator_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_pinned_variable_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [variable] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { variable: variable, operator_loc: operator_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents the use of the `END` keyword. - # - # END { foo } - # ^^^^^^^^^^^ - class PostExecutionNode < Node - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # def initialize: (statements: Node?, keyword_loc: Location, opening_loc: Location, closing_loc: Location, location: Location) -> void - def initialize(statements, keyword_loc, opening_loc, closing_loc, location) - @statements = statements - @keyword_loc = keyword_loc - @opening_loc = opening_loc - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_post_execution_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { statements: statements, keyword_loc: keyword_loc, opening_loc: opening_loc, closing_loc: closing_loc, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - end - - # Represents the use of the `BEGIN` keyword. - # - # BEGIN { foo } - # ^^^^^^^^^^^^^ - class PreExecutionNode < Node - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # def initialize: (statements: Node?, keyword_loc: Location, opening_loc: Location, closing_loc: Location, location: Location) -> void - def initialize(statements, keyword_loc, opening_loc, closing_loc, location) - @statements = statements - @keyword_loc = keyword_loc - @opening_loc = opening_loc - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_pre_execution_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { statements: statements, keyword_loc: keyword_loc, opening_loc: opening_loc, closing_loc: closing_loc, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - end - - # The top level node of any parse tree. - class ProgramNode < Node - # attr_reader locals: Array[Symbol] - attr_reader :locals - - # attr_reader statements: Node - attr_reader :statements - - # def initialize: (locals: Array[Symbol], statements: Node, location: Location) -> void - def initialize(locals, statements, location) - @locals = locals - @statements = statements - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_program_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { locals: locals, statements: statements, location: location } - end - end - - # Represents the use of the `..` or `...` operators. - # - # 1..2 - # ^^^^ - # - # c if a =~ /left/ ... b =~ /right/ - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - class RangeNode < Node - # attr_reader left: Node? - attr_reader :left - - # attr_reader right: Node? - attr_reader :right - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader flags: Integer - attr_reader :flags - - # def initialize: (left: Node?, right: Node?, operator_loc: Location, flags: Integer, location: Location) -> void - def initialize(left, right, operator_loc, flags, location) - @left = left - @right = right - @operator_loc = operator_loc - @flags = flags - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_range_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [left, right] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { left: left, right: right, operator_loc: operator_loc, flags: flags, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - - # def exclude_end?: () -> bool - def exclude_end? - flags.anybits?(RangeFlags::EXCLUDE_END) - end - end - - # Represents a rational number literal. - # - # 1.0r - # ^^^^ - class RationalNode < Node - # attr_reader numeric: Node - attr_reader :numeric - - # def initialize: (numeric: Node, location: Location) -> void - def initialize(numeric, location) - @numeric = numeric - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_rational_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [numeric] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { numeric: numeric, location: location } - end - end - - # Represents the use of the `redo` keyword. - # - # redo - # ^^^^ - class RedoNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_redo_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents a regular expression literal with no interpolation. - # - # /foo/i - # ^^^^^^ - class RegularExpressionNode < Node - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader content_loc: Location - attr_reader :content_loc - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # attr_reader unescaped: String - attr_reader :unescaped - - # attr_reader flags: Integer - attr_reader :flags - - # def initialize: (opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String, flags: Integer, location: Location) -> void - def initialize(opening_loc, content_loc, closing_loc, unescaped, flags, location) - @opening_loc = opening_loc - @content_loc = content_loc - @closing_loc = closing_loc - @unescaped = unescaped - @flags = flags - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_regular_expression_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { opening_loc: opening_loc, content_loc: content_loc, closing_loc: closing_loc, unescaped: unescaped, flags: flags, location: location } - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def content: () -> String - def content - content_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - - # def ignore_case?: () -> bool - def ignore_case? - flags.anybits?(RegularExpressionFlags::IGNORE_CASE) - end - - # def multi_line?: () -> bool - def multi_line? - flags.anybits?(RegularExpressionFlags::MULTI_LINE) - end - - # def extended?: () -> bool - def extended? - flags.anybits?(RegularExpressionFlags::EXTENDED) - end - - # def euc_jp?: () -> bool - def euc_jp? - flags.anybits?(RegularExpressionFlags::EUC_JP) - end - - # def ascii_8bit?: () -> bool - def ascii_8bit? - flags.anybits?(RegularExpressionFlags::ASCII_8BIT) - end - - # def windows_31j?: () -> bool - def windows_31j? - flags.anybits?(RegularExpressionFlags::WINDOWS_31J) - end - - # def utf_8?: () -> bool - def utf_8? - flags.anybits?(RegularExpressionFlags::UTF_8) - end - - # def once?: () -> bool - def once? - flags.anybits?(RegularExpressionFlags::ONCE) - end - end - - # Represents a destructured required parameter node. - # - # def foo((bar, baz)) - # ^^^^^^^^^^ - # end - class RequiredDestructuredParameterNode < Node - # attr_reader parameters: Array[Node] - attr_reader :parameters - - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # def initialize: (parameters: Array[Node], opening_loc: Location, closing_loc: Location, location: Location) -> void - def initialize(parameters, opening_loc, closing_loc, location) - @parameters = parameters - @opening_loc = opening_loc - @closing_loc = closing_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_required_destructured_parameter_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*parameters] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { parameters: parameters, opening_loc: opening_loc, closing_loc: closing_loc, location: location } - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - end - - # Represents a required parameter to a method, block, or lambda definition. - # - # def a(b) - # ^ - # end - class RequiredParameterNode < Node - # attr_reader constant_id: Symbol - attr_reader :constant_id - - # def initialize: (constant_id: Symbol, location: Location) -> void - def initialize(constant_id, location) - @constant_id = constant_id - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_required_parameter_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { constant_id: constant_id, location: location } - end - end - - # Represents an expression modified with a rescue. - # - # foo rescue nil - # ^^^^^^^^^^^^^^ - class RescueModifierNode < Node - # attr_reader expression: Node - attr_reader :expression - - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader rescue_expression: Node - attr_reader :rescue_expression - - # def initialize: (expression: Node, keyword_loc: Location, rescue_expression: Node, location: Location) -> void - def initialize(expression, keyword_loc, rescue_expression, location) - @expression = expression - @keyword_loc = keyword_loc - @rescue_expression = rescue_expression - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_rescue_modifier_node(self) - end - - def set_newline_flag(newline_marked) - expression.set_newline_flag(newline_marked) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [expression, rescue_expression] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { expression: expression, keyword_loc: keyword_loc, rescue_expression: rescue_expression, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - end - - # Represents a rescue statement. - # - # begin - # rescue Foo, *splat, Bar => ex - # ^^^^^^ - # foo - # end - # - # `Foo, *splat, Bar` are in the `exceptions` field. - # `ex` is in the `exception` field. - class RescueNode < Node - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader exceptions: Array[Node] - attr_reader :exceptions - - # attr_reader operator_loc: Location? - attr_reader :operator_loc - - # attr_reader reference: Node? - attr_reader :reference - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader consequent: Node? - attr_reader :consequent - - # def initialize: (keyword_loc: Location, exceptions: Array[Node], operator_loc: Location?, reference: Node?, statements: Node?, consequent: Node?, location: Location) -> void - def initialize(keyword_loc, exceptions, operator_loc, reference, statements, consequent, location) - @keyword_loc = keyword_loc - @exceptions = exceptions - @operator_loc = operator_loc - @reference = reference - @statements = statements - @consequent = consequent - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_rescue_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*exceptions, reference, statements, consequent] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { keyword_loc: keyword_loc, exceptions: exceptions, operator_loc: operator_loc, reference: reference, statements: statements, consequent: consequent, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - - # def operator: () -> String? - def operator - operator_loc&.slice - end - end - - # Represents a rest parameter to a method, block, or lambda definition. - # - # def a(*b) - # ^^ - # end - class RestParameterNode < Node - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader name_loc: Location? - attr_reader :name_loc - - # def initialize: (operator_loc: Location, name_loc: Location?, location: Location) -> void - def initialize(operator_loc, name_loc, location) - @operator_loc = operator_loc - @name_loc = name_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_rest_parameter_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { operator_loc: operator_loc, name_loc: name_loc, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - - # def name: () -> String? - def name - name_loc&.slice - end - end - - # Represents the use of the `retry` keyword. - # - # retry - # ^^^^^ - class RetryNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_retry_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents the use of the `return` keyword. - # - # return 1 - # ^^^^^^^^ - class ReturnNode < Node - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader arguments: Node? - attr_reader :arguments - - # def initialize: (keyword_loc: Location, arguments: Node?, location: Location) -> void - def initialize(keyword_loc, arguments, location) - @keyword_loc = keyword_loc - @arguments = arguments - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_return_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [arguments] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { keyword_loc: keyword_loc, arguments: arguments, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - end - - # Represents the `self` keyword. - # - # self - # ^^^^ - class SelfNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_self_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents a singleton class declaration involving the `class` keyword. - # - # class << self end - # ^^^^^^^^^^^^^^^^^ - class SingletonClassNode < Node - # attr_reader locals: Array[Symbol] - attr_reader :locals - - # attr_reader class_keyword_loc: Location - attr_reader :class_keyword_loc - - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader expression: Node - attr_reader :expression - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader end_keyword_loc: Location - attr_reader :end_keyword_loc - - # def initialize: (locals: Array[Symbol], class_keyword_loc: Location, operator_loc: Location, expression: Node, statements: Node?, end_keyword_loc: Location, location: Location) -> void - def initialize(locals, class_keyword_loc, operator_loc, expression, statements, end_keyword_loc, location) - @locals = locals - @class_keyword_loc = class_keyword_loc - @operator_loc = operator_loc - @expression = expression - @statements = statements - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_singleton_class_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [expression, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { locals: locals, class_keyword_loc: class_keyword_loc, operator_loc: operator_loc, expression: expression, statements: statements, end_keyword_loc: end_keyword_loc, location: location } - end - - # def class_keyword: () -> String - def class_keyword - class_keyword_loc.slice - end - - # def operator: () -> String - def operator - operator_loc.slice - end - - # def end_keyword: () -> String - def end_keyword - end_keyword_loc.slice - end - end - - # Represents the use of the `__ENCODING__` keyword. - # - # __ENCODING__ - # ^^^^^^^^^^^^ - class SourceEncodingNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_source_encoding_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents the use of the `__FILE__` keyword. - # - # __FILE__ - # ^^^^^^^^ - class SourceFileNode < Node - # attr_reader filepath: String - attr_reader :filepath - - # def initialize: (filepath: String, location: Location) -> void - def initialize(filepath, location) - @filepath = filepath - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_source_file_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { filepath: filepath, location: location } - end - end - - # Represents the use of the `__LINE__` keyword. - # - # __LINE__ - # ^^^^^^^^ - class SourceLineNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_source_line_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents the use of the splat operator. - # - # [*a] - # ^^ - class SplatNode < Node - # attr_reader operator_loc: Location - attr_reader :operator_loc - - # attr_reader expression: Node? - attr_reader :expression - - # def initialize: (operator_loc: Location, expression: Node?, location: Location) -> void - def initialize(operator_loc, expression, location) - @operator_loc = operator_loc - @expression = expression - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_splat_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [expression] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { operator_loc: operator_loc, expression: expression, location: location } - end - - # def operator: () -> String - def operator - operator_loc.slice - end - end - - # Represents a set of statements contained within some scope. - # - # foo; bar; baz - # ^^^^^^^^^^^^^ - class StatementsNode < Node - # attr_reader body: Array[Node] - attr_reader :body - - # def initialize: (body: Array[Node], location: Location) -> void - def initialize(body, location) - @body = body - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_statements_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*body] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { body: body, location: location } - end - end - - # Represents the use of compile-time string concatenation. - # - # "foo" "bar" - # ^^^^^^^^^^^ - class StringConcatNode < Node - # attr_reader left: Node - attr_reader :left - - # attr_reader right: Node - attr_reader :right - - # def initialize: (left: Node, right: Node, location: Location) -> void - def initialize(left, right, location) - @left = left - @right = right - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_string_concat_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [left, right] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { left: left, right: right, location: location } - end - end - - # Represents a string literal, a string contained within a `%w` list, or - # plain string content within an interpolated string. - # - # "foo" - # ^^^^^ - # - # %w[foo] - # ^^^ - # - # "foo #{bar} baz" - # ^^^^ ^^^^ - class StringNode < Node - # attr_reader opening_loc: Location? - attr_reader :opening_loc - - # attr_reader content_loc: Location - attr_reader :content_loc - - # attr_reader closing_loc: Location? - attr_reader :closing_loc - - # attr_reader unescaped: String - attr_reader :unescaped - - # def initialize: (opening_loc: Location?, content_loc: Location, closing_loc: Location?, unescaped: String, location: Location) -> void - def initialize(opening_loc, content_loc, closing_loc, unescaped, location) - @opening_loc = opening_loc - @content_loc = content_loc - @closing_loc = closing_loc - @unescaped = unescaped - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_string_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { opening_loc: opening_loc, content_loc: content_loc, closing_loc: closing_loc, unescaped: unescaped, location: location } - end - - # def opening: () -> String? - def opening - opening_loc&.slice - end - - # def content: () -> String - def content - content_loc.slice - end - - # def closing: () -> String? - def closing - closing_loc&.slice - end - end - - # Represents the use of the `super` keyword with parentheses or arguments. - # - # super() - # ^^^^^^^ - # - # super foo, bar - # ^^^^^^^^^^^^^^ - class SuperNode < Node - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader lparen_loc: Location? - attr_reader :lparen_loc - - # attr_reader arguments: Node? - attr_reader :arguments - - # attr_reader rparen_loc: Location? - attr_reader :rparen_loc - - # attr_reader block: Node? - attr_reader :block - - # def initialize: (keyword_loc: Location, lparen_loc: Location?, arguments: Node?, rparen_loc: Location?, block: Node?, location: Location) -> void - def initialize(keyword_loc, lparen_loc, arguments, rparen_loc, block, location) - @keyword_loc = keyword_loc - @lparen_loc = lparen_loc - @arguments = arguments - @rparen_loc = rparen_loc - @block = block - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_super_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [arguments, block] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { keyword_loc: keyword_loc, lparen_loc: lparen_loc, arguments: arguments, rparen_loc: rparen_loc, block: block, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - - # def lparen: () -> String? - def lparen - lparen_loc&.slice - end - - # def rparen: () -> String? - def rparen - rparen_loc&.slice - end - end - - # Represents a symbol literal or a symbol contained within a `%i` list. - # - # :foo - # ^^^^ - # - # %i[foo] - # ^^^ - class SymbolNode < Node - # attr_reader opening_loc: Location? - attr_reader :opening_loc - - # attr_reader value_loc: Location - attr_reader :value_loc - - # attr_reader closing_loc: Location? - attr_reader :closing_loc - - # attr_reader unescaped: String - attr_reader :unescaped - - # def initialize: (opening_loc: Location?, value_loc: Location, closing_loc: Location?, unescaped: String, location: Location) -> void - def initialize(opening_loc, value_loc, closing_loc, unescaped, location) - @opening_loc = opening_loc - @value_loc = value_loc - @closing_loc = closing_loc - @unescaped = unescaped - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_symbol_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { opening_loc: opening_loc, value_loc: value_loc, closing_loc: closing_loc, unescaped: unescaped, location: location } - end - - # def opening: () -> String? - def opening - opening_loc&.slice - end - - # def value: () -> String - def value - value_loc.slice - end - - # def closing: () -> String? - def closing - closing_loc&.slice - end - end - - # Represents the use of the literal `true` keyword. - # - # true - # ^^^^ - class TrueNode < Node - # def initialize: (location: Location) -> void - def initialize(location) - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_true_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { location: location } - end - end - - # Represents the use of the `undef` keyword. - # - # undef :foo, :bar, :baz - # ^^^^^^^^^^^^^^^^^^^^^^ - class UndefNode < Node - # attr_reader names: Array[Node] - attr_reader :names - - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # def initialize: (names: Array[Node], keyword_loc: Location, location: Location) -> void - def initialize(names, keyword_loc, location) - @names = names - @keyword_loc = keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_undef_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*names] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { names: names, keyword_loc: keyword_loc, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - end - - # Represents the use of the `unless` keyword, either in the block form or the modifier form. - # - # bar unless foo - # ^^^^^^^^^^^^^^ - # - # unless foo then bar end - # ^^^^^^^^^^^^^^^^^^^^^^^ - class UnlessNode < Node - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader predicate: Node - attr_reader :predicate - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader consequent: Node? - attr_reader :consequent - - # attr_reader end_keyword_loc: Location? - attr_reader :end_keyword_loc - - # def initialize: (keyword_loc: Location, predicate: Node, statements: Node?, consequent: Node?, end_keyword_loc: Location?, location: Location) -> void - def initialize(keyword_loc, predicate, statements, consequent, end_keyword_loc, location) - @keyword_loc = keyword_loc - @predicate = predicate - @statements = statements - @consequent = consequent - @end_keyword_loc = end_keyword_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_unless_node(self) - end - - def set_newline_flag(newline_marked) - predicate.set_newline_flag(newline_marked) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [predicate, statements, consequent] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { keyword_loc: keyword_loc, predicate: predicate, statements: statements, consequent: consequent, end_keyword_loc: end_keyword_loc, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - - # def end_keyword: () -> String? - def end_keyword - end_keyword_loc&.slice - end - end - - # Represents the use of the `until` keyword, either in the block form or the modifier form. - # - # bar until foo - # ^^^^^^^^^^^^^ - # - # until foo do bar end - # ^^^^^^^^^^^^^^^^^^^^ - class UntilNode < Node - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader predicate: Node - attr_reader :predicate - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader flags: Integer - attr_reader :flags - - # def initialize: (keyword_loc: Location, predicate: Node, statements: Node?, flags: Integer, location: Location) -> void - def initialize(keyword_loc, predicate, statements, flags, location) - @keyword_loc = keyword_loc - @predicate = predicate - @statements = statements - @flags = flags - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_until_node(self) - end - - def set_newline_flag(newline_marked) - predicate.set_newline_flag(newline_marked) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [predicate, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { keyword_loc: keyword_loc, predicate: predicate, statements: statements, flags: flags, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - - # def begin_modifier?: () -> bool - def begin_modifier? - flags.anybits?(LoopFlags::BEGIN_MODIFIER) - end - end - - # case true - # when true - # ^^^^^^^^^ - # end - class WhenNode < Node - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader conditions: Array[Node] - attr_reader :conditions - - # attr_reader statements: Node? - attr_reader :statements - - # def initialize: (keyword_loc: Location, conditions: Array[Node], statements: Node?, location: Location) -> void - def initialize(keyword_loc, conditions, statements, location) - @keyword_loc = keyword_loc - @conditions = conditions - @statements = statements - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_when_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [*conditions, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { keyword_loc: keyword_loc, conditions: conditions, statements: statements, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - end - - # Represents the use of the `while` keyword, either in the block form or the modifier form. - # - # bar while foo - # ^^^^^^^^^^^^^ - # - # while foo do bar end - # ^^^^^^^^^^^^^^^^^^^^ - class WhileNode < Node - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader predicate: Node - attr_reader :predicate - - # attr_reader statements: Node? - attr_reader :statements - - # attr_reader flags: Integer - attr_reader :flags - - # def initialize: (keyword_loc: Location, predicate: Node, statements: Node?, flags: Integer, location: Location) -> void - def initialize(keyword_loc, predicate, statements, flags, location) - @keyword_loc = keyword_loc - @predicate = predicate - @statements = statements - @flags = flags - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_while_node(self) - end - - def set_newline_flag(newline_marked) - predicate.set_newline_flag(newline_marked) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [predicate, statements] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { keyword_loc: keyword_loc, predicate: predicate, statements: statements, flags: flags, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - - # def begin_modifier?: () -> bool - def begin_modifier? - flags.anybits?(LoopFlags::BEGIN_MODIFIER) - end - end - - # Represents an xstring literal with no interpolation. - # - # `foo` - # ^^^^^ - class XStringNode < Node - # attr_reader opening_loc: Location - attr_reader :opening_loc - - # attr_reader content_loc: Location - attr_reader :content_loc - - # attr_reader closing_loc: Location - attr_reader :closing_loc - - # attr_reader unescaped: String - attr_reader :unescaped - - # def initialize: (opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String, location: Location) -> void - def initialize(opening_loc, content_loc, closing_loc, unescaped, location) - @opening_loc = opening_loc - @content_loc = content_loc - @closing_loc = closing_loc - @unescaped = unescaped - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_x_string_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { opening_loc: opening_loc, content_loc: content_loc, closing_loc: closing_loc, unescaped: unescaped, location: location } - end - - # def opening: () -> String - def opening - opening_loc.slice - end - - # def content: () -> String - def content - content_loc.slice - end - - # def closing: () -> String - def closing - closing_loc.slice - end - end - - # Represents the use of the `yield` keyword. - # - # yield 1 - # ^^^^^^^ - class YieldNode < Node - # attr_reader keyword_loc: Location - attr_reader :keyword_loc - - # attr_reader lparen_loc: Location? - attr_reader :lparen_loc - - # attr_reader arguments: Node? - attr_reader :arguments - - # attr_reader rparen_loc: Location? - attr_reader :rparen_loc - - # def initialize: (keyword_loc: Location, lparen_loc: Location?, arguments: Node?, rparen_loc: Location?, location: Location) -> void - def initialize(keyword_loc, lparen_loc, arguments, rparen_loc, location) - @keyword_loc = keyword_loc - @lparen_loc = lparen_loc - @arguments = arguments - @rparen_loc = rparen_loc - @location = location - end - - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_yield_node(self) - end - - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [arguments] - end - - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { keyword_loc: keyword_loc, lparen_loc: lparen_loc, arguments: arguments, rparen_loc: rparen_loc, location: location } - end - - # def keyword: () -> String - def keyword - keyword_loc.slice - end - - # def lparen: () -> String? - def lparen - lparen_loc&.slice - end - - # def rparen: () -> String? - def rparen - rparen_loc&.slice - end - end - - module CallNodeFlags - # &. operator - SAFE_NAVIGATION = 1 << 0 - - # a call that could have been a local variable - VARIABLE_CALL = 1 << 1 - end - - module LoopFlags - # a loop after a begin statement, so the body is executed first before the condition - BEGIN_MODIFIER = 1 << 0 - end - - module RangeFlags - # ... operator - EXCLUDE_END = 1 << 0 - end - - module RegularExpressionFlags - # i - ignores the case of characters when matching - IGNORE_CASE = 1 << 0 - - # m - allows $ to match the end of lines within strings - MULTI_LINE = 1 << 1 - - # x - ignores whitespace and allows comments in regular expressions - EXTENDED = 1 << 2 - - # e - forces the EUC-JP encoding - EUC_JP = 1 << 3 - - # n - forces the ASCII-8BIT encoding - ASCII_8BIT = 1 << 4 - - # s - forces the Windows-31J encoding - WINDOWS_31J = 1 << 5 - - # u - forces the UTF-8 encoding - UTF_8 = 1 << 6 - - # o - only interpolates values into the regular expression once - ONCE = 1 << 7 - end - - class Visitor < BasicVisitor - # Visit a AliasNode node - alias visit_alias_node visit_child_nodes - - # Visit a AlternationPatternNode node - alias visit_alternation_pattern_node visit_child_nodes - - # Visit a AndNode node - alias visit_and_node visit_child_nodes - - # Visit a ArgumentsNode node - alias visit_arguments_node visit_child_nodes - - # Visit a ArrayNode node - alias visit_array_node visit_child_nodes - - # Visit a ArrayPatternNode node - alias visit_array_pattern_node visit_child_nodes - - # Visit a AssocNode node - alias visit_assoc_node visit_child_nodes - - # Visit a AssocSplatNode node - alias visit_assoc_splat_node visit_child_nodes - - # Visit a BackReferenceReadNode node - alias visit_back_reference_read_node visit_child_nodes - - # Visit a BeginNode node - alias visit_begin_node visit_child_nodes - - # Visit a BlockArgumentNode node - alias visit_block_argument_node visit_child_nodes - - # Visit a BlockNode node - alias visit_block_node visit_child_nodes - - # Visit a BlockParameterNode node - alias visit_block_parameter_node visit_child_nodes - - # Visit a BlockParametersNode node - alias visit_block_parameters_node visit_child_nodes - - # Visit a BreakNode node - alias visit_break_node visit_child_nodes - - # Visit a CallNode node - alias visit_call_node visit_child_nodes - - # Visit a CallOperatorAndWriteNode node - alias visit_call_operator_and_write_node visit_child_nodes - - # Visit a CallOperatorOrWriteNode node - alias visit_call_operator_or_write_node visit_child_nodes - - # Visit a CallOperatorWriteNode node - alias visit_call_operator_write_node visit_child_nodes - - # Visit a CapturePatternNode node - alias visit_capture_pattern_node visit_child_nodes - - # Visit a CaseNode node - alias visit_case_node visit_child_nodes - - # Visit a ClassNode node - alias visit_class_node visit_child_nodes - - # Visit a ClassVariableOperatorAndWriteNode node - alias visit_class_variable_operator_and_write_node visit_child_nodes - - # Visit a ClassVariableOperatorOrWriteNode node - alias visit_class_variable_operator_or_write_node visit_child_nodes - - # Visit a ClassVariableOperatorWriteNode node - alias visit_class_variable_operator_write_node visit_child_nodes - - # Visit a ClassVariableReadNode node - alias visit_class_variable_read_node visit_child_nodes - - # Visit a ClassVariableWriteNode node - alias visit_class_variable_write_node visit_child_nodes - - # Visit a ConstantOperatorAndWriteNode node - alias visit_constant_operator_and_write_node visit_child_nodes - - # Visit a ConstantOperatorOrWriteNode node - alias visit_constant_operator_or_write_node visit_child_nodes - - # Visit a ConstantOperatorWriteNode node - alias visit_constant_operator_write_node visit_child_nodes - - # Visit a ConstantPathNode node - alias visit_constant_path_node visit_child_nodes - - # Visit a ConstantPathOperatorAndWriteNode node - alias visit_constant_path_operator_and_write_node visit_child_nodes - - # Visit a ConstantPathOperatorOrWriteNode node - alias visit_constant_path_operator_or_write_node visit_child_nodes - - # Visit a ConstantPathOperatorWriteNode node - alias visit_constant_path_operator_write_node visit_child_nodes - - # Visit a ConstantPathWriteNode node - alias visit_constant_path_write_node visit_child_nodes - - # Visit a ConstantReadNode node - alias visit_constant_read_node visit_child_nodes - - # Visit a ConstantWriteNode node - alias visit_constant_write_node visit_child_nodes - - # Visit a DefNode node - alias visit_def_node visit_child_nodes - - # Visit a DefinedNode node - alias visit_defined_node visit_child_nodes - - # Visit a ElseNode node - alias visit_else_node visit_child_nodes - - # Visit a EmbeddedStatementsNode node - alias visit_embedded_statements_node visit_child_nodes - - # Visit a EmbeddedVariableNode node - alias visit_embedded_variable_node visit_child_nodes - - # Visit a EnsureNode node - alias visit_ensure_node visit_child_nodes - - # Visit a FalseNode node - alias visit_false_node visit_child_nodes - - # Visit a FindPatternNode node - alias visit_find_pattern_node visit_child_nodes - - # Visit a FlipFlopNode node - alias visit_flip_flop_node visit_child_nodes - - # Visit a FloatNode node - alias visit_float_node visit_child_nodes - - # Visit a ForNode node - alias visit_for_node visit_child_nodes - - # Visit a ForwardingArgumentsNode node - alias visit_forwarding_arguments_node visit_child_nodes - - # Visit a ForwardingParameterNode node - alias visit_forwarding_parameter_node visit_child_nodes - - # Visit a ForwardingSuperNode node - alias visit_forwarding_super_node visit_child_nodes - - # Visit a GlobalVariableOperatorAndWriteNode node - alias visit_global_variable_operator_and_write_node visit_child_nodes - - # Visit a GlobalVariableOperatorOrWriteNode node - alias visit_global_variable_operator_or_write_node visit_child_nodes - - # Visit a GlobalVariableOperatorWriteNode node - alias visit_global_variable_operator_write_node visit_child_nodes - - # Visit a GlobalVariableReadNode node - alias visit_global_variable_read_node visit_child_nodes - - # Visit a GlobalVariableWriteNode node - alias visit_global_variable_write_node visit_child_nodes - - # Visit a HashNode node - alias visit_hash_node visit_child_nodes - - # Visit a HashPatternNode node - alias visit_hash_pattern_node visit_child_nodes - - # Visit a IfNode node - alias visit_if_node visit_child_nodes - - # Visit a ImaginaryNode node - alias visit_imaginary_node visit_child_nodes - - # Visit a InNode node - alias visit_in_node visit_child_nodes - - # Visit a InstanceVariableOperatorAndWriteNode node - alias visit_instance_variable_operator_and_write_node visit_child_nodes - - # Visit a InstanceVariableOperatorOrWriteNode node - alias visit_instance_variable_operator_or_write_node visit_child_nodes - - # Visit a InstanceVariableOperatorWriteNode node - alias visit_instance_variable_operator_write_node visit_child_nodes - - # Visit a InstanceVariableReadNode node - alias visit_instance_variable_read_node visit_child_nodes - - # Visit a InstanceVariableWriteNode node - alias visit_instance_variable_write_node visit_child_nodes - - # Visit a IntegerNode node - alias visit_integer_node visit_child_nodes - - # Visit a InterpolatedRegularExpressionNode node - alias visit_interpolated_regular_expression_node visit_child_nodes - - # Visit a InterpolatedStringNode node - alias visit_interpolated_string_node visit_child_nodes - - # Visit a InterpolatedSymbolNode node - alias visit_interpolated_symbol_node visit_child_nodes - - # Visit a InterpolatedXStringNode node - alias visit_interpolated_x_string_node visit_child_nodes - - # Visit a KeywordHashNode node - alias visit_keyword_hash_node visit_child_nodes - - # Visit a KeywordParameterNode node - alias visit_keyword_parameter_node visit_child_nodes - - # Visit a KeywordRestParameterNode node - alias visit_keyword_rest_parameter_node visit_child_nodes - - # Visit a LambdaNode node - alias visit_lambda_node visit_child_nodes - - # Visit a LocalVariableOperatorAndWriteNode node - alias visit_local_variable_operator_and_write_node visit_child_nodes - - # Visit a LocalVariableOperatorOrWriteNode node - alias visit_local_variable_operator_or_write_node visit_child_nodes - - # Visit a LocalVariableOperatorWriteNode node - alias visit_local_variable_operator_write_node visit_child_nodes - - # Visit a LocalVariableReadNode node - alias visit_local_variable_read_node visit_child_nodes - - # Visit a LocalVariableWriteNode node - alias visit_local_variable_write_node visit_child_nodes - - # Visit a MatchPredicateNode node - alias visit_match_predicate_node visit_child_nodes - - # Visit a MatchRequiredNode node - alias visit_match_required_node visit_child_nodes - - # Visit a MissingNode node - alias visit_missing_node visit_child_nodes - - # Visit a ModuleNode node - alias visit_module_node visit_child_nodes - - # Visit a MultiWriteNode node - alias visit_multi_write_node visit_child_nodes - - # Visit a NextNode node - alias visit_next_node visit_child_nodes - - # Visit a NilNode node - alias visit_nil_node visit_child_nodes - - # Visit a NoKeywordsParameterNode node - alias visit_no_keywords_parameter_node visit_child_nodes - - # Visit a NumberedReferenceReadNode node - alias visit_numbered_reference_read_node visit_child_nodes - - # Visit a OptionalParameterNode node - alias visit_optional_parameter_node visit_child_nodes - - # Visit a OrNode node - alias visit_or_node visit_child_nodes - - # Visit a ParametersNode node - alias visit_parameters_node visit_child_nodes - - # Visit a ParenthesesNode node - alias visit_parentheses_node visit_child_nodes - - # Visit a PinnedExpressionNode node - alias visit_pinned_expression_node visit_child_nodes - - # Visit a PinnedVariableNode node - alias visit_pinned_variable_node visit_child_nodes - - # Visit a PostExecutionNode node - alias visit_post_execution_node visit_child_nodes - - # Visit a PreExecutionNode node - alias visit_pre_execution_node visit_child_nodes - - # Visit a ProgramNode node - alias visit_program_node visit_child_nodes - - # Visit a RangeNode node - alias visit_range_node visit_child_nodes - - # Visit a RationalNode node - alias visit_rational_node visit_child_nodes - - # Visit a RedoNode node - alias visit_redo_node visit_child_nodes - - # Visit a RegularExpressionNode node - alias visit_regular_expression_node visit_child_nodes - - # Visit a RequiredDestructuredParameterNode node - alias visit_required_destructured_parameter_node visit_child_nodes - - # Visit a RequiredParameterNode node - alias visit_required_parameter_node visit_child_nodes - - # Visit a RescueModifierNode node - alias visit_rescue_modifier_node visit_child_nodes - - # Visit a RescueNode node - alias visit_rescue_node visit_child_nodes - - # Visit a RestParameterNode node - alias visit_rest_parameter_node visit_child_nodes - - # Visit a RetryNode node - alias visit_retry_node visit_child_nodes - - # Visit a ReturnNode node - alias visit_return_node visit_child_nodes - - # Visit a SelfNode node - alias visit_self_node visit_child_nodes - - # Visit a SingletonClassNode node - alias visit_singleton_class_node visit_child_nodes - - # Visit a SourceEncodingNode node - alias visit_source_encoding_node visit_child_nodes - - # Visit a SourceFileNode node - alias visit_source_file_node visit_child_nodes - - # Visit a SourceLineNode node - alias visit_source_line_node visit_child_nodes - - # Visit a SplatNode node - alias visit_splat_node visit_child_nodes - - # Visit a StatementsNode node - alias visit_statements_node visit_child_nodes - - # Visit a StringConcatNode node - alias visit_string_concat_node visit_child_nodes - - # Visit a StringNode node - alias visit_string_node visit_child_nodes - - # Visit a SuperNode node - alias visit_super_node visit_child_nodes - - # Visit a SymbolNode node - alias visit_symbol_node visit_child_nodes - - # Visit a TrueNode node - alias visit_true_node visit_child_nodes - - # Visit a UndefNode node - alias visit_undef_node visit_child_nodes - - # Visit a UnlessNode node - alias visit_unless_node visit_child_nodes - - # Visit a UntilNode node - alias visit_until_node visit_child_nodes - - # Visit a WhenNode node - alias visit_when_node visit_child_nodes - - # Visit a WhileNode node - alias visit_while_node visit_child_nodes - - # Visit a XStringNode node - alias visit_x_string_node visit_child_nodes - - # Visit a YieldNode node - alias visit_yield_node visit_child_nodes - end - - module DSL - private - - # Create a new Location object - def Location(source = nil, start_offset = 0, length = 0) - Location.new(source, start_offset, length) - end - - # Create a new AliasNode node - def AliasNode(new_name, old_name, keyword_loc, location = Location()) - AliasNode.new(new_name, old_name, keyword_loc, location) - end - - # Create a new AlternationPatternNode node - def AlternationPatternNode(left, right, operator_loc, location = Location()) - AlternationPatternNode.new(left, right, operator_loc, location) - end - - # Create a new AndNode node - def AndNode(left, right, operator_loc, location = Location()) - AndNode.new(left, right, operator_loc, location) - end - - # Create a new ArgumentsNode node - def ArgumentsNode(arguments, location = Location()) - ArgumentsNode.new(arguments, location) - end - - # Create a new ArrayNode node - def ArrayNode(elements, opening_loc, closing_loc, location = Location()) - ArrayNode.new(elements, opening_loc, closing_loc, location) - end - - # Create a new ArrayPatternNode node - def ArrayPatternNode(constant, requireds, rest, posts, opening_loc, closing_loc, location = Location()) - ArrayPatternNode.new(constant, requireds, rest, posts, opening_loc, closing_loc, location) - end - - # Create a new AssocNode node - def AssocNode(key, value, operator_loc, location = Location()) - AssocNode.new(key, value, operator_loc, location) - end - - # Create a new AssocSplatNode node - def AssocSplatNode(value, operator_loc, location = Location()) - AssocSplatNode.new(value, operator_loc, location) - end - - # Create a new BackReferenceReadNode node - def BackReferenceReadNode(location = Location()) - BackReferenceReadNode.new(location) - end - - # Create a new BeginNode node - def BeginNode(begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc, location = Location()) - BeginNode.new(begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc, location) - end - - # Create a new BlockArgumentNode node - def BlockArgumentNode(expression, operator_loc, location = Location()) - BlockArgumentNode.new(expression, operator_loc, location) - end - - # Create a new BlockNode node - def BlockNode(locals, parameters, statements, opening_loc, closing_loc, location = Location()) - BlockNode.new(locals, parameters, statements, opening_loc, closing_loc, location) - end - - # Create a new BlockParameterNode node - def BlockParameterNode(name_loc, operator_loc, location = Location()) - BlockParameterNode.new(name_loc, operator_loc, location) - end - - # Create a new BlockParametersNode node - def BlockParametersNode(parameters, locals, opening_loc, closing_loc, location = Location()) - BlockParametersNode.new(parameters, locals, opening_loc, closing_loc, location) - end - - # Create a new BreakNode node - def BreakNode(arguments, keyword_loc, location = Location()) - BreakNode.new(arguments, keyword_loc, location) - end - - # Create a new CallNode node - def CallNode(receiver, operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location = Location()) - CallNode.new(receiver, operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location) - end - - # Create a new CallOperatorAndWriteNode node - def CallOperatorAndWriteNode(target, operator_loc, value, location = Location()) - CallOperatorAndWriteNode.new(target, operator_loc, value, location) - end - - # Create a new CallOperatorOrWriteNode node - def CallOperatorOrWriteNode(target, value, operator_loc, location = Location()) - CallOperatorOrWriteNode.new(target, value, operator_loc, location) - end - - # Create a new CallOperatorWriteNode node - def CallOperatorWriteNode(target, operator_loc, value, operator_id, location = Location()) - CallOperatorWriteNode.new(target, operator_loc, value, operator_id, location) - end - - # Create a new CapturePatternNode node - def CapturePatternNode(value, target, operator_loc, location = Location()) - CapturePatternNode.new(value, target, operator_loc, location) - end - - # Create a new CaseNode node - def CaseNode(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location = Location()) - CaseNode.new(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location) - end - - # Create a new ClassNode node - def ClassNode(locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, statements, end_keyword_loc, location = Location()) - ClassNode.new(locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, statements, end_keyword_loc, location) - end - - # Create a new ClassVariableOperatorAndWriteNode node - def ClassVariableOperatorAndWriteNode(name_loc, operator_loc, value, location = Location()) - ClassVariableOperatorAndWriteNode.new(name_loc, operator_loc, value, location) - end - - # Create a new ClassVariableOperatorOrWriteNode node - def ClassVariableOperatorOrWriteNode(name_loc, operator_loc, value, location = Location()) - ClassVariableOperatorOrWriteNode.new(name_loc, operator_loc, value, location) - end - - # Create a new ClassVariableOperatorWriteNode node - def ClassVariableOperatorWriteNode(name_loc, operator_loc, value, operator, location = Location()) - ClassVariableOperatorWriteNode.new(name_loc, operator_loc, value, operator, location) - end - - # Create a new ClassVariableReadNode node - def ClassVariableReadNode(location = Location()) - ClassVariableReadNode.new(location) - end - - # Create a new ClassVariableWriteNode node - def ClassVariableWriteNode(name_loc, value, operator_loc, location = Location()) - ClassVariableWriteNode.new(name_loc, value, operator_loc, location) - end - - # Create a new ConstantOperatorAndWriteNode node - def ConstantOperatorAndWriteNode(name_loc, operator_loc, value, location = Location()) - ConstantOperatorAndWriteNode.new(name_loc, operator_loc, value, location) - end - - # Create a new ConstantOperatorOrWriteNode node - def ConstantOperatorOrWriteNode(name_loc, operator_loc, value, location = Location()) - ConstantOperatorOrWriteNode.new(name_loc, operator_loc, value, location) - end - - # Create a new ConstantOperatorWriteNode node - def ConstantOperatorWriteNode(name_loc, operator_loc, value, operator, location = Location()) - ConstantOperatorWriteNode.new(name_loc, operator_loc, value, operator, location) - end - - # Create a new ConstantPathNode node - def ConstantPathNode(parent, child, delimiter_loc, location = Location()) - ConstantPathNode.new(parent, child, delimiter_loc, location) - end - - # Create a new ConstantPathOperatorAndWriteNode node - def ConstantPathOperatorAndWriteNode(target, operator_loc, value, location = Location()) - ConstantPathOperatorAndWriteNode.new(target, operator_loc, value, location) - end - - # Create a new ConstantPathOperatorOrWriteNode node - def ConstantPathOperatorOrWriteNode(target, operator_loc, value, location = Location()) - ConstantPathOperatorOrWriteNode.new(target, operator_loc, value, location) - end - - # Create a new ConstantPathOperatorWriteNode node - def ConstantPathOperatorWriteNode(target, operator_loc, value, operator, location = Location()) - ConstantPathOperatorWriteNode.new(target, operator_loc, value, operator, location) - end - - # Create a new ConstantPathWriteNode node - def ConstantPathWriteNode(target, operator_loc, value, location = Location()) - ConstantPathWriteNode.new(target, operator_loc, value, location) - end - - # Create a new ConstantReadNode node - def ConstantReadNode(location = Location()) - ConstantReadNode.new(location) - end - - # Create a new ConstantWriteNode node - def ConstantWriteNode(name_loc, value, operator_loc, location = Location()) - ConstantWriteNode.new(name_loc, value, operator_loc, location) - end - - # Create a new DefNode node - def DefNode(name_loc, receiver, parameters, statements, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location = Location()) - DefNode.new(name_loc, receiver, parameters, statements, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location) - end - - # Create a new DefinedNode node - def DefinedNode(lparen_loc, value, rparen_loc, keyword_loc, location = Location()) - DefinedNode.new(lparen_loc, value, rparen_loc, keyword_loc, location) - end - - # Create a new ElseNode node - def ElseNode(else_keyword_loc, statements, end_keyword_loc, location = Location()) - ElseNode.new(else_keyword_loc, statements, end_keyword_loc, location) - end - - # Create a new EmbeddedStatementsNode node - def EmbeddedStatementsNode(opening_loc, statements, closing_loc, location = Location()) - EmbeddedStatementsNode.new(opening_loc, statements, closing_loc, location) - end - - # Create a new EmbeddedVariableNode node - def EmbeddedVariableNode(operator_loc, variable, location = Location()) - EmbeddedVariableNode.new(operator_loc, variable, location) - end - - # Create a new EnsureNode node - def EnsureNode(ensure_keyword_loc, statements, end_keyword_loc, location = Location()) - EnsureNode.new(ensure_keyword_loc, statements, end_keyword_loc, location) - end - - # Create a new FalseNode node - def FalseNode(location = Location()) - FalseNode.new(location) - end - - # Create a new FindPatternNode node - def FindPatternNode(constant, left, requireds, right, opening_loc, closing_loc, location = Location()) - FindPatternNode.new(constant, left, requireds, right, opening_loc, closing_loc, location) - end - - # Create a new FlipFlopNode node - def FlipFlopNode(left, right, operator_loc, flags, location = Location()) - FlipFlopNode.new(left, right, operator_loc, flags, location) - end - - # Create a new FloatNode node - def FloatNode(location = Location()) - FloatNode.new(location) - end - - # Create a new ForNode node - def ForNode(index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc, location = Location()) - ForNode.new(index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc, location) - end - - # Create a new ForwardingArgumentsNode node - def ForwardingArgumentsNode(location = Location()) - ForwardingArgumentsNode.new(location) - end - - # Create a new ForwardingParameterNode node - def ForwardingParameterNode(location = Location()) - ForwardingParameterNode.new(location) - end - - # Create a new ForwardingSuperNode node - def ForwardingSuperNode(block, location = Location()) - ForwardingSuperNode.new(block, location) - end - - # Create a new GlobalVariableOperatorAndWriteNode node - def GlobalVariableOperatorAndWriteNode(name_loc, operator_loc, value, location = Location()) - GlobalVariableOperatorAndWriteNode.new(name_loc, operator_loc, value, location) - end - - # Create a new GlobalVariableOperatorOrWriteNode node - def GlobalVariableOperatorOrWriteNode(name_loc, operator_loc, value, location = Location()) - GlobalVariableOperatorOrWriteNode.new(name_loc, operator_loc, value, location) - end - - # Create a new GlobalVariableOperatorWriteNode node - def GlobalVariableOperatorWriteNode(name_loc, operator_loc, value, operator, location = Location()) - GlobalVariableOperatorWriteNode.new(name_loc, operator_loc, value, operator, location) - end - - # Create a new GlobalVariableReadNode node - def GlobalVariableReadNode(location = Location()) - GlobalVariableReadNode.new(location) - end - - # Create a new GlobalVariableWriteNode node - def GlobalVariableWriteNode(name_loc, operator_loc, value, location = Location()) - GlobalVariableWriteNode.new(name_loc, operator_loc, value, location) - end - - # Create a new HashNode node - def HashNode(opening_loc, elements, closing_loc, location = Location()) - HashNode.new(opening_loc, elements, closing_loc, location) - end - - # Create a new HashPatternNode node - def HashPatternNode(constant, assocs, kwrest, opening_loc, closing_loc, location = Location()) - HashPatternNode.new(constant, assocs, kwrest, opening_loc, closing_loc, location) - end - - # Create a new IfNode node - def IfNode(if_keyword_loc, predicate, statements, consequent, end_keyword_loc, location = Location()) - IfNode.new(if_keyword_loc, predicate, statements, consequent, end_keyword_loc, location) - end - - # Create a new ImaginaryNode node - def ImaginaryNode(numeric, location = Location()) - ImaginaryNode.new(numeric, location) - end - - # Create a new InNode node - def InNode(pattern, statements, in_loc, then_loc, location = Location()) - InNode.new(pattern, statements, in_loc, then_loc, location) - end - - # Create a new InstanceVariableOperatorAndWriteNode node - def InstanceVariableOperatorAndWriteNode(name_loc, operator_loc, value, location = Location()) - InstanceVariableOperatorAndWriteNode.new(name_loc, operator_loc, value, location) - end - - # Create a new InstanceVariableOperatorOrWriteNode node - def InstanceVariableOperatorOrWriteNode(name_loc, operator_loc, value, location = Location()) - InstanceVariableOperatorOrWriteNode.new(name_loc, operator_loc, value, location) - end - - # Create a new InstanceVariableOperatorWriteNode node - def InstanceVariableOperatorWriteNode(name_loc, operator_loc, value, operator, location = Location()) - InstanceVariableOperatorWriteNode.new(name_loc, operator_loc, value, operator, location) - end - - # Create a new InstanceVariableReadNode node - def InstanceVariableReadNode(location = Location()) - InstanceVariableReadNode.new(location) - end - - # Create a new InstanceVariableWriteNode node - def InstanceVariableWriteNode(name_loc, value, operator_loc, location = Location()) - InstanceVariableWriteNode.new(name_loc, value, operator_loc, location) - end - - # Create a new IntegerNode node - def IntegerNode(location = Location()) - IntegerNode.new(location) - end - - # Create a new InterpolatedRegularExpressionNode node - def InterpolatedRegularExpressionNode(opening_loc, parts, closing_loc, flags, location = Location()) - InterpolatedRegularExpressionNode.new(opening_loc, parts, closing_loc, flags, location) - end - - # Create a new InterpolatedStringNode node - def InterpolatedStringNode(opening_loc, parts, closing_loc, location = Location()) - InterpolatedStringNode.new(opening_loc, parts, closing_loc, location) - end - - # Create a new InterpolatedSymbolNode node - def InterpolatedSymbolNode(opening_loc, parts, closing_loc, location = Location()) - InterpolatedSymbolNode.new(opening_loc, parts, closing_loc, location) - end - - # Create a new InterpolatedXStringNode node - def InterpolatedXStringNode(opening_loc, parts, closing_loc, location = Location()) - InterpolatedXStringNode.new(opening_loc, parts, closing_loc, location) - end - - # Create a new KeywordHashNode node - def KeywordHashNode(elements, location = Location()) - KeywordHashNode.new(elements, location) - end - - # Create a new KeywordParameterNode node - def KeywordParameterNode(name_loc, value, location = Location()) - KeywordParameterNode.new(name_loc, value, location) - end - - # Create a new KeywordRestParameterNode node - def KeywordRestParameterNode(operator_loc, name_loc, location = Location()) - KeywordRestParameterNode.new(operator_loc, name_loc, location) - end - - # Create a new LambdaNode node - def LambdaNode(locals, opening_loc, parameters, statements, location = Location()) - LambdaNode.new(locals, opening_loc, parameters, statements, location) - end - - # Create a new LocalVariableOperatorAndWriteNode node - def LocalVariableOperatorAndWriteNode(name_loc, operator_loc, value, constant_id, location = Location()) - LocalVariableOperatorAndWriteNode.new(name_loc, operator_loc, value, constant_id, location) - end - - # Create a new LocalVariableOperatorOrWriteNode node - def LocalVariableOperatorOrWriteNode(name_loc, operator_loc, value, constant_id, location = Location()) - LocalVariableOperatorOrWriteNode.new(name_loc, operator_loc, value, constant_id, location) - end - - # Create a new LocalVariableOperatorWriteNode node - def LocalVariableOperatorWriteNode(name_loc, operator_loc, value, constant_id, operator_id, location = Location()) - LocalVariableOperatorWriteNode.new(name_loc, operator_loc, value, constant_id, operator_id, location) - end - - # Create a new LocalVariableReadNode node - def LocalVariableReadNode(constant_id, depth, location = Location()) - LocalVariableReadNode.new(constant_id, depth, location) - end - - # Create a new LocalVariableWriteNode node - def LocalVariableWriteNode(constant_id, depth, value, name_loc, operator_loc, location = Location()) - LocalVariableWriteNode.new(constant_id, depth, value, name_loc, operator_loc, location) - end - - # Create a new MatchPredicateNode node - def MatchPredicateNode(value, pattern, operator_loc, location = Location()) - MatchPredicateNode.new(value, pattern, operator_loc, location) - end - - # Create a new MatchRequiredNode node - def MatchRequiredNode(value, pattern, operator_loc, location = Location()) - MatchRequiredNode.new(value, pattern, operator_loc, location) - end - - # Create a new MissingNode node - def MissingNode(location = Location()) - MissingNode.new(location) - end - - # Create a new ModuleNode node - def ModuleNode(locals, module_keyword_loc, constant_path, statements, end_keyword_loc, location = Location()) - ModuleNode.new(locals, module_keyword_loc, constant_path, statements, end_keyword_loc, location) - end - - # Create a new MultiWriteNode node - def MultiWriteNode(targets, operator_loc, value, lparen_loc, rparen_loc, location = Location()) - MultiWriteNode.new(targets, operator_loc, value, lparen_loc, rparen_loc, location) - end - - # Create a new NextNode node - def NextNode(arguments, keyword_loc, location = Location()) - NextNode.new(arguments, keyword_loc, location) - end - - # Create a new NilNode node - def NilNode(location = Location()) - NilNode.new(location) - end - - # Create a new NoKeywordsParameterNode node - def NoKeywordsParameterNode(operator_loc, keyword_loc, location = Location()) - NoKeywordsParameterNode.new(operator_loc, keyword_loc, location) - end - - # Create a new NumberedReferenceReadNode node - def NumberedReferenceReadNode(location = Location()) - NumberedReferenceReadNode.new(location) - end - - # Create a new OptionalParameterNode node - def OptionalParameterNode(constant_id, name_loc, operator_loc, value, location = Location()) - OptionalParameterNode.new(constant_id, name_loc, operator_loc, value, location) - end - - # Create a new OrNode node - def OrNode(left, right, operator_loc, location = Location()) - OrNode.new(left, right, operator_loc, location) - end - - # Create a new ParametersNode node - def ParametersNode(requireds, optionals, posts, rest, keywords, keyword_rest, block, location = Location()) - ParametersNode.new(requireds, optionals, posts, rest, keywords, keyword_rest, block, location) - end - - # Create a new ParenthesesNode node - def ParenthesesNode(statements, opening_loc, closing_loc, location = Location()) - ParenthesesNode.new(statements, opening_loc, closing_loc, location) - end - - # Create a new PinnedExpressionNode node - def PinnedExpressionNode(expression, operator_loc, lparen_loc, rparen_loc, location = Location()) - PinnedExpressionNode.new(expression, operator_loc, lparen_loc, rparen_loc, location) - end - - # Create a new PinnedVariableNode node - def PinnedVariableNode(variable, operator_loc, location = Location()) - PinnedVariableNode.new(variable, operator_loc, location) - end - - # Create a new PostExecutionNode node - def PostExecutionNode(statements, keyword_loc, opening_loc, closing_loc, location = Location()) - PostExecutionNode.new(statements, keyword_loc, opening_loc, closing_loc, location) - end - - # Create a new PreExecutionNode node - def PreExecutionNode(statements, keyword_loc, opening_loc, closing_loc, location = Location()) - PreExecutionNode.new(statements, keyword_loc, opening_loc, closing_loc, location) - end - - # Create a new ProgramNode node - def ProgramNode(locals, statements, location = Location()) - ProgramNode.new(locals, statements, location) - end - - # Create a new RangeNode node - def RangeNode(left, right, operator_loc, flags, location = Location()) - RangeNode.new(left, right, operator_loc, flags, location) - end - - # Create a new RationalNode node - def RationalNode(numeric, location = Location()) - RationalNode.new(numeric, location) - end - - # Create a new RedoNode node - def RedoNode(location = Location()) - RedoNode.new(location) - end - - # Create a new RegularExpressionNode node - def RegularExpressionNode(opening_loc, content_loc, closing_loc, unescaped, flags, location = Location()) - RegularExpressionNode.new(opening_loc, content_loc, closing_loc, unescaped, flags, location) - end - - # Create a new RequiredDestructuredParameterNode node - def RequiredDestructuredParameterNode(parameters, opening_loc, closing_loc, location = Location()) - RequiredDestructuredParameterNode.new(parameters, opening_loc, closing_loc, location) - end - - # Create a new RequiredParameterNode node - def RequiredParameterNode(constant_id, location = Location()) - RequiredParameterNode.new(constant_id, location) - end - - # Create a new RescueModifierNode node - def RescueModifierNode(expression, keyword_loc, rescue_expression, location = Location()) - RescueModifierNode.new(expression, keyword_loc, rescue_expression, location) - end - - # Create a new RescueNode node - def RescueNode(keyword_loc, exceptions, operator_loc, reference, statements, consequent, location = Location()) - RescueNode.new(keyword_loc, exceptions, operator_loc, reference, statements, consequent, location) - end - - # Create a new RestParameterNode node - def RestParameterNode(operator_loc, name_loc, location = Location()) - RestParameterNode.new(operator_loc, name_loc, location) - end - - # Create a new RetryNode node - def RetryNode(location = Location()) - RetryNode.new(location) - end - - # Create a new ReturnNode node - def ReturnNode(keyword_loc, arguments, location = Location()) - ReturnNode.new(keyword_loc, arguments, location) - end - - # Create a new SelfNode node - def SelfNode(location = Location()) - SelfNode.new(location) - end - - # Create a new SingletonClassNode node - def SingletonClassNode(locals, class_keyword_loc, operator_loc, expression, statements, end_keyword_loc, location = Location()) - SingletonClassNode.new(locals, class_keyword_loc, operator_loc, expression, statements, end_keyword_loc, location) - end - - # Create a new SourceEncodingNode node - def SourceEncodingNode(location = Location()) - SourceEncodingNode.new(location) - end - - # Create a new SourceFileNode node - def SourceFileNode(filepath, location = Location()) - SourceFileNode.new(filepath, location) - end - - # Create a new SourceLineNode node - def SourceLineNode(location = Location()) - SourceLineNode.new(location) - end - - # Create a new SplatNode node - def SplatNode(operator_loc, expression, location = Location()) - SplatNode.new(operator_loc, expression, location) - end - - # Create a new StatementsNode node - def StatementsNode(body, location = Location()) - StatementsNode.new(body, location) - end - - # Create a new StringConcatNode node - def StringConcatNode(left, right, location = Location()) - StringConcatNode.new(left, right, location) - end - - # Create a new StringNode node - def StringNode(opening_loc, content_loc, closing_loc, unescaped, location = Location()) - StringNode.new(opening_loc, content_loc, closing_loc, unescaped, location) - end - - # Create a new SuperNode node - def SuperNode(keyword_loc, lparen_loc, arguments, rparen_loc, block, location = Location()) - SuperNode.new(keyword_loc, lparen_loc, arguments, rparen_loc, block, location) - end - - # Create a new SymbolNode node - def SymbolNode(opening_loc, value_loc, closing_loc, unescaped, location = Location()) - SymbolNode.new(opening_loc, value_loc, closing_loc, unescaped, location) - end - - # Create a new TrueNode node - def TrueNode(location = Location()) - TrueNode.new(location) - end - - # Create a new UndefNode node - def UndefNode(names, keyword_loc, location = Location()) - UndefNode.new(names, keyword_loc, location) - end - - # Create a new UnlessNode node - def UnlessNode(keyword_loc, predicate, statements, consequent, end_keyword_loc, location = Location()) - UnlessNode.new(keyword_loc, predicate, statements, consequent, end_keyword_loc, location) - end - - # Create a new UntilNode node - def UntilNode(keyword_loc, predicate, statements, flags, location = Location()) - UntilNode.new(keyword_loc, predicate, statements, flags, location) - end - - # Create a new WhenNode node - def WhenNode(keyword_loc, conditions, statements, location = Location()) - WhenNode.new(keyword_loc, conditions, statements, location) - end - - # Create a new WhileNode node - def WhileNode(keyword_loc, predicate, statements, flags, location = Location()) - WhileNode.new(keyword_loc, predicate, statements, flags, location) - end - - # Create a new XStringNode node - def XStringNode(opening_loc, content_loc, closing_loc, unescaped, location = Location()) - XStringNode.new(opening_loc, content_loc, closing_loc, unescaped, location) - end - - # Create a new YieldNode node - def YieldNode(keyword_loc, lparen_loc, arguments, rparen_loc, location = Location()) - YieldNode.new(keyword_loc, lparen_loc, arguments, rparen_loc, location) - end - end -end diff --git a/lib/yarp/serialize.rb b/lib/yarp/serialize.rb deleted file mode 100644 index d6f7b7a0de157c..00000000000000 --- a/lib/yarp/serialize.rb +++ /dev/null @@ -1,582 +0,0 @@ -# frozen_string_literal: true -=begin -This file is generated by the bin/template script and should not be -modified manually. See templates/lib/yarp/serialize.rb.erb -if you are looking to modify the template -=end - -require "stringio" - -# Polyfill for String#unpack1 with the offset parameter. -if String.instance_method(:unpack1).parameters.none? { |_, name| name == :offset } - String.prepend( - Module.new { - def unpack1(format, offset: 0) - offset == 0 ? super(format) : self[offset..].unpack1(format) - end - } - ) -end - -module YARP - module Serialize - MAJOR_VERSION = 0 - MINOR_VERSION = 7 - PATCH_VERSION = 0 - - def self.load(input, serialized) - Loader.new(Source.new(input), serialized).load - end - - def self.load_tokens(source, serialized) - Loader.new(source, serialized).load_tokens - end - - class Loader - attr_reader :encoding, :input, :serialized, :io - attr_reader :constant_pool_offset, :constant_pool, :source - - def initialize(source, serialized) - @encoding = Encoding::UTF_8 - - @input = source.source.dup - @serialized = serialized - @io = StringIO.new(serialized) - @io.set_encoding(Encoding::BINARY) - - @constant_pool_offset = nil - @constant_pool = nil - - @source = source - end - - def load_tokens - tokens = [] - while type = TOKEN_TYPES.fetch(load_varint) - start = load_varint - length = load_varint - lex_state = load_varint - location = Location.new(@source, start, length) - tokens << [YARP::Token.new(type, location.slice, location), lex_state] - end - - comments = load_varint.times.map { Comment.new(Comment::TYPES.fetch(load_varint), load_location) } - errors = load_varint.times.map { ParseError.new(load_string, load_location) } - warnings = load_varint.times.map { ParseWarning.new(load_string, load_location) } - - raise "Expected to consume all bytes while deserializing" unless @io.eof? - - YARP::ParseResult.new(tokens, comments, errors, warnings, @source) - end - - def load - raise "Invalid serialization" if io.read(4) != "YARP" - raise "Invalid serialization" if io.read(3).unpack("C3") != [MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION] - - @encoding = Encoding.find(io.read(load_varint)) - @input = input.force_encoding(@encoding).freeze - - comments = load_varint.times.map { Comment.new(Comment::TYPES.fetch(io.getbyte), load_location) } - errors = load_varint.times.map { ParseError.new(load_string, load_location) } - warnings = load_varint.times.map { ParseWarning.new(load_string, load_location) } - - @constant_pool_offset = io.read(4).unpack1("L") - @constant_pool = Array.new(load_varint, nil) - - ast = load_node - - YARP::ParseResult.new(ast, comments, errors, warnings, @source) - end - - private - - # variable-length integer using https://en.wikipedia.org/wiki/LEB128 - # This is also what protobuf uses: https://protobuf.dev/programming-guides/encoding/#varints - def load_varint - n = io.getbyte - if n < 128 - n - else - n -= 128 - shift = 0 - while (b = io.getbyte) >= 128 - n += (b - 128) << (shift += 7) - end - n + (b << (shift + 7)) - end - end - - def load_serialized_length - io.read(4).unpack1("L") - end - - def load_optional_node - if io.getbyte != 0 - io.pos -= 1 - load_node - end - end - - def load_string - io.read(load_varint).force_encoding(encoding) - end - - def load_location - Location.new(source, load_varint, load_varint) - end - - def load_optional_location - load_location if io.getbyte != 0 - end - - def load_constant - index = load_varint - 1 - constant = constant_pool[index] - - unless constant - offset = constant_pool_offset + index * 8 - - start = serialized.unpack1("L", offset: offset) - length = serialized.unpack1("L", offset: offset + 4) - - constant = input.byteslice(start, length).to_sym - constant_pool[index] = constant - end - - constant - end - - def load_node - type = io.getbyte - location = load_location - - case type - when 1 then - AliasNode.new(load_node, load_node, load_location, location) - when 2 then - AlternationPatternNode.new(load_node, load_node, load_location, location) - when 3 then - AndNode.new(load_node, load_node, load_location, location) - when 4 then - ArgumentsNode.new(Array.new(load_varint) { load_node }, location) - when 5 then - ArrayNode.new(Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, location) - when 6 then - ArrayPatternNode.new(load_optional_node, Array.new(load_varint) { load_node }, load_optional_node, Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, location) - when 7 then - AssocNode.new(load_node, load_optional_node, load_optional_location, location) - when 8 then - AssocSplatNode.new(load_optional_node, load_location, location) - when 9 then - BackReferenceReadNode.new(location) - when 10 then - BeginNode.new(load_optional_location, load_optional_node, load_optional_node, load_optional_node, load_optional_node, load_optional_location, location) - when 11 then - BlockArgumentNode.new(load_optional_node, load_location, location) - when 12 then - BlockNode.new(Array.new(load_varint) { load_constant }, load_optional_node, load_optional_node, load_location, load_location, location) - when 13 then - BlockParameterNode.new(load_optional_location, load_location, location) - when 14 then - BlockParametersNode.new(load_optional_node, Array.new(load_varint) { load_location }, load_optional_location, load_optional_location, location) - when 15 then - BreakNode.new(load_optional_node, load_location, location) - when 16 then - CallNode.new(load_optional_node, load_optional_location, load_optional_location, load_optional_location, load_optional_node, load_optional_location, load_optional_node, load_varint, load_string, location) - when 17 then - CallOperatorAndWriteNode.new(load_node, load_location, load_node, location) - when 18 then - CallOperatorOrWriteNode.new(load_node, load_node, load_location, location) - when 19 then - CallOperatorWriteNode.new(load_node, load_location, load_node, load_constant, location) - when 20 then - CapturePatternNode.new(load_node, load_node, load_location, location) - when 21 then - CaseNode.new(load_optional_node, Array.new(load_varint) { load_node }, load_optional_node, load_location, load_location, location) - when 22 then - ClassNode.new(Array.new(load_varint) { load_constant }, load_location, load_node, load_optional_location, load_optional_node, load_optional_node, load_location, location) - when 23 then - ClassVariableOperatorAndWriteNode.new(load_location, load_location, load_node, location) - when 24 then - ClassVariableOperatorOrWriteNode.new(load_location, load_location, load_node, location) - when 25 then - ClassVariableOperatorWriteNode.new(load_location, load_location, load_node, load_constant, location) - when 26 then - ClassVariableReadNode.new(location) - when 27 then - ClassVariableWriteNode.new(load_location, load_optional_node, load_optional_location, location) - when 28 then - ConstantOperatorAndWriteNode.new(load_location, load_location, load_node, location) - when 29 then - ConstantOperatorOrWriteNode.new(load_location, load_location, load_node, location) - when 30 then - ConstantOperatorWriteNode.new(load_location, load_location, load_node, load_constant, location) - when 31 then - ConstantPathNode.new(load_optional_node, load_node, load_location, location) - when 32 then - ConstantPathOperatorAndWriteNode.new(load_node, load_location, load_node, location) - when 33 then - ConstantPathOperatorOrWriteNode.new(load_node, load_location, load_node, location) - when 34 then - ConstantPathOperatorWriteNode.new(load_node, load_location, load_node, load_constant, location) - when 35 then - ConstantPathWriteNode.new(load_node, load_optional_location, load_optional_node, location) - when 36 then - ConstantReadNode.new(location) - when 37 then - ConstantWriteNode.new(load_location, load_optional_node, load_optional_location, location) - when 38 then - load_serialized_length - DefNode.new(load_location, load_optional_node, load_optional_node, load_optional_node, Array.new(load_varint) { load_constant }, load_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, location) - when 39 then - DefinedNode.new(load_optional_location, load_node, load_optional_location, load_location, location) - when 40 then - ElseNode.new(load_location, load_optional_node, load_optional_location, location) - when 41 then - EmbeddedStatementsNode.new(load_location, load_optional_node, load_location, location) - when 42 then - EmbeddedVariableNode.new(load_location, load_node, location) - when 43 then - EnsureNode.new(load_location, load_optional_node, load_location, location) - when 44 then - FalseNode.new(location) - when 45 then - FindPatternNode.new(load_optional_node, load_node, Array.new(load_varint) { load_node }, load_node, load_optional_location, load_optional_location, location) - when 46 then - FlipFlopNode.new(load_optional_node, load_optional_node, load_location, load_varint, location) - when 47 then - FloatNode.new(location) - when 48 then - ForNode.new(load_node, load_node, load_optional_node, load_location, load_location, load_optional_location, load_location, location) - when 49 then - ForwardingArgumentsNode.new(location) - when 50 then - ForwardingParameterNode.new(location) - when 51 then - ForwardingSuperNode.new(load_optional_node, location) - when 52 then - GlobalVariableOperatorAndWriteNode.new(load_location, load_location, load_node, location) - when 53 then - GlobalVariableOperatorOrWriteNode.new(load_location, load_location, load_node, location) - when 54 then - GlobalVariableOperatorWriteNode.new(load_location, load_location, load_node, load_constant, location) - when 55 then - GlobalVariableReadNode.new(location) - when 56 then - GlobalVariableWriteNode.new(load_location, load_optional_location, load_optional_node, location) - when 57 then - HashNode.new(load_location, Array.new(load_varint) { load_node }, load_location, location) - when 58 then - HashPatternNode.new(load_optional_node, Array.new(load_varint) { load_node }, load_optional_node, load_optional_location, load_optional_location, location) - when 59 then - IfNode.new(load_optional_location, load_node, load_optional_node, load_optional_node, load_optional_location, location) - when 60 then - ImaginaryNode.new(load_node, location) - when 61 then - InNode.new(load_node, load_optional_node, load_location, load_optional_location, location) - when 62 then - InstanceVariableOperatorAndWriteNode.new(load_location, load_location, load_node, location) - when 63 then - InstanceVariableOperatorOrWriteNode.new(load_location, load_location, load_node, location) - when 64 then - InstanceVariableOperatorWriteNode.new(load_location, load_location, load_node, load_constant, location) - when 65 then - InstanceVariableReadNode.new(location) - when 66 then - InstanceVariableWriteNode.new(load_location, load_optional_node, load_optional_location, location) - when 67 then - IntegerNode.new(location) - when 68 then - InterpolatedRegularExpressionNode.new(load_location, Array.new(load_varint) { load_node }, load_location, load_varint, location) - when 69 then - InterpolatedStringNode.new(load_optional_location, Array.new(load_varint) { load_node }, load_optional_location, location) - when 70 then - InterpolatedSymbolNode.new(load_optional_location, Array.new(load_varint) { load_node }, load_optional_location, location) - when 71 then - InterpolatedXStringNode.new(load_location, Array.new(load_varint) { load_node }, load_location, location) - when 72 then - KeywordHashNode.new(Array.new(load_varint) { load_node }, location) - when 73 then - KeywordParameterNode.new(load_location, load_optional_node, location) - when 74 then - KeywordRestParameterNode.new(load_location, load_optional_location, location) - when 75 then - LambdaNode.new(Array.new(load_varint) { load_constant }, load_location, load_optional_node, load_optional_node, location) - when 76 then - LocalVariableOperatorAndWriteNode.new(load_location, load_location, load_node, load_constant, location) - when 77 then - LocalVariableOperatorOrWriteNode.new(load_location, load_location, load_node, load_constant, location) - when 78 then - LocalVariableOperatorWriteNode.new(load_location, load_location, load_node, load_constant, load_constant, location) - when 79 then - LocalVariableReadNode.new(load_constant, load_varint, location) - when 80 then - LocalVariableWriteNode.new(load_constant, load_varint, load_optional_node, load_location, load_optional_location, location) - when 81 then - MatchPredicateNode.new(load_node, load_node, load_location, location) - when 82 then - MatchRequiredNode.new(load_node, load_node, load_location, location) - when 83 then - MissingNode.new(location) - when 84 then - ModuleNode.new(Array.new(load_varint) { load_constant }, load_location, load_node, load_optional_node, load_location, location) - when 85 then - MultiWriteNode.new(Array.new(load_varint) { load_node }, load_optional_location, load_optional_node, load_optional_location, load_optional_location, location) - when 86 then - NextNode.new(load_optional_node, load_location, location) - when 87 then - NilNode.new(location) - when 88 then - NoKeywordsParameterNode.new(load_location, load_location, location) - when 89 then - NumberedReferenceReadNode.new(location) - when 90 then - OptionalParameterNode.new(load_constant, load_location, load_location, load_node, location) - when 91 then - OrNode.new(load_node, load_node, load_location, location) - when 92 then - ParametersNode.new(Array.new(load_varint) { load_node }, Array.new(load_varint) { load_node }, Array.new(load_varint) { load_node }, load_optional_node, Array.new(load_varint) { load_node }, load_optional_node, load_optional_node, location) - when 93 then - ParenthesesNode.new(load_optional_node, load_location, load_location, location) - when 94 then - PinnedExpressionNode.new(load_node, load_location, load_location, load_location, location) - when 95 then - PinnedVariableNode.new(load_node, load_location, location) - when 96 then - PostExecutionNode.new(load_optional_node, load_location, load_location, load_location, location) - when 97 then - PreExecutionNode.new(load_optional_node, load_location, load_location, load_location, location) - when 98 then - ProgramNode.new(Array.new(load_varint) { load_constant }, load_node, location) - when 99 then - RangeNode.new(load_optional_node, load_optional_node, load_location, load_varint, location) - when 100 then - RationalNode.new(load_node, location) - when 101 then - RedoNode.new(location) - when 102 then - RegularExpressionNode.new(load_location, load_location, load_location, load_string, load_varint, location) - when 103 then - RequiredDestructuredParameterNode.new(Array.new(load_varint) { load_node }, load_location, load_location, location) - when 104 then - RequiredParameterNode.new(load_constant, location) - when 105 then - RescueModifierNode.new(load_node, load_location, load_node, location) - when 106 then - RescueNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_location, load_optional_node, load_optional_node, load_optional_node, location) - when 107 then - RestParameterNode.new(load_location, load_optional_location, location) - when 108 then - RetryNode.new(location) - when 109 then - ReturnNode.new(load_location, load_optional_node, location) - when 110 then - SelfNode.new(location) - when 111 then - SingletonClassNode.new(Array.new(load_varint) { load_constant }, load_location, load_location, load_node, load_optional_node, load_location, location) - when 112 then - SourceEncodingNode.new(location) - when 113 then - SourceFileNode.new(load_string, location) - when 114 then - SourceLineNode.new(location) - when 115 then - SplatNode.new(load_location, load_optional_node, location) - when 116 then - StatementsNode.new(Array.new(load_varint) { load_node }, location) - when 117 then - StringConcatNode.new(load_node, load_node, location) - when 118 then - StringNode.new(load_optional_location, load_location, load_optional_location, load_string, location) - when 119 then - SuperNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, load_optional_node, location) - when 120 then - SymbolNode.new(load_optional_location, load_location, load_optional_location, load_string, location) - when 121 then - TrueNode.new(location) - when 122 then - UndefNode.new(Array.new(load_varint) { load_node }, load_location, location) - when 123 then - UnlessNode.new(load_location, load_node, load_optional_node, load_optional_node, load_optional_location, location) - when 124 then - UntilNode.new(load_location, load_node, load_optional_node, load_varint, location) - when 125 then - WhenNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_node, location) - when 126 then - WhileNode.new(load_location, load_node, load_optional_node, load_varint, location) - when 127 then - XStringNode.new(load_location, load_location, load_location, load_string, location) - when 128 then - YieldNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, location) - end - end - end - - TOKEN_TYPES = [ - nil, - :EOF, - :MISSING, - :NOT_PROVIDED, - :AMPERSAND, - :AMPERSAND_AMPERSAND, - :AMPERSAND_AMPERSAND_EQUAL, - :AMPERSAND_DOT, - :AMPERSAND_EQUAL, - :BACKTICK, - :BACK_REFERENCE, - :BANG, - :BANG_EQUAL, - :BANG_TILDE, - :BRACE_LEFT, - :BRACE_RIGHT, - :BRACKET_LEFT, - :BRACKET_LEFT_ARRAY, - :BRACKET_LEFT_RIGHT, - :BRACKET_LEFT_RIGHT_EQUAL, - :BRACKET_RIGHT, - :CARET, - :CARET_EQUAL, - :CHARACTER_LITERAL, - :CLASS_VARIABLE, - :COLON, - :COLON_COLON, - :COMMA, - :COMMENT, - :CONSTANT, - :DOT, - :DOT_DOT, - :DOT_DOT_DOT, - :EMBDOC_BEGIN, - :EMBDOC_END, - :EMBDOC_LINE, - :EMBEXPR_BEGIN, - :EMBEXPR_END, - :EMBVAR, - :EQUAL, - :EQUAL_EQUAL, - :EQUAL_EQUAL_EQUAL, - :EQUAL_GREATER, - :EQUAL_TILDE, - :FLOAT, - :FLOAT_IMAGINARY, - :FLOAT_RATIONAL, - :FLOAT_RATIONAL_IMAGINARY, - :GLOBAL_VARIABLE, - :GREATER, - :GREATER_EQUAL, - :GREATER_GREATER, - :GREATER_GREATER_EQUAL, - :HEREDOC_END, - :HEREDOC_START, - :IDENTIFIER, - :IGNORED_NEWLINE, - :INSTANCE_VARIABLE, - :INTEGER, - :INTEGER_IMAGINARY, - :INTEGER_RATIONAL, - :INTEGER_RATIONAL_IMAGINARY, - :KEYWORD_ALIAS, - :KEYWORD_AND, - :KEYWORD_BEGIN, - :KEYWORD_BEGIN_UPCASE, - :KEYWORD_BREAK, - :KEYWORD_CASE, - :KEYWORD_CLASS, - :KEYWORD_DEF, - :KEYWORD_DEFINED, - :KEYWORD_DO, - :KEYWORD_DO_LOOP, - :KEYWORD_ELSE, - :KEYWORD_ELSIF, - :KEYWORD_END, - :KEYWORD_END_UPCASE, - :KEYWORD_ENSURE, - :KEYWORD_FALSE, - :KEYWORD_FOR, - :KEYWORD_IF, - :KEYWORD_IF_MODIFIER, - :KEYWORD_IN, - :KEYWORD_MODULE, - :KEYWORD_NEXT, - :KEYWORD_NIL, - :KEYWORD_NOT, - :KEYWORD_OR, - :KEYWORD_REDO, - :KEYWORD_RESCUE, - :KEYWORD_RESCUE_MODIFIER, - :KEYWORD_RETRY, - :KEYWORD_RETURN, - :KEYWORD_SELF, - :KEYWORD_SUPER, - :KEYWORD_THEN, - :KEYWORD_TRUE, - :KEYWORD_UNDEF, - :KEYWORD_UNLESS, - :KEYWORD_UNLESS_MODIFIER, - :KEYWORD_UNTIL, - :KEYWORD_UNTIL_MODIFIER, - :KEYWORD_WHEN, - :KEYWORD_WHILE, - :KEYWORD_WHILE_MODIFIER, - :KEYWORD_YIELD, - :KEYWORD___ENCODING__, - :KEYWORD___FILE__, - :KEYWORD___LINE__, - :LABEL, - :LABEL_END, - :LAMBDA_BEGIN, - :LESS, - :LESS_EQUAL, - :LESS_EQUAL_GREATER, - :LESS_LESS, - :LESS_LESS_EQUAL, - :MINUS, - :MINUS_EQUAL, - :MINUS_GREATER, - :NEWLINE, - :NUMBERED_REFERENCE, - :PARENTHESIS_LEFT, - :PARENTHESIS_LEFT_PARENTHESES, - :PARENTHESIS_RIGHT, - :PERCENT, - :PERCENT_EQUAL, - :PERCENT_LOWER_I, - :PERCENT_LOWER_W, - :PERCENT_LOWER_X, - :PERCENT_UPPER_I, - :PERCENT_UPPER_W, - :PIPE, - :PIPE_EQUAL, - :PIPE_PIPE, - :PIPE_PIPE_EQUAL, - :PLUS, - :PLUS_EQUAL, - :QUESTION_MARK, - :REGEXP_BEGIN, - :REGEXP_END, - :SEMICOLON, - :SLASH, - :SLASH_EQUAL, - :STAR, - :STAR_EQUAL, - :STAR_STAR, - :STAR_STAR_EQUAL, - :STRING_BEGIN, - :STRING_CONTENT, - :STRING_END, - :SYMBOL_BEGIN, - :TILDE, - :UAMPERSAND, - :UCOLON_COLON, - :UDOT_DOT, - :UDOT_DOT_DOT, - :UMINUS, - :UMINUS_NUM, - :UPLUS, - :USTAR, - :USTAR_STAR, - :WORDS_SEP, - :__END__, - ] - end -end diff --git a/string.c b/string.c index 1d24f84664caa9..3979af641db798 100644 --- a/string.c +++ b/string.c @@ -422,7 +422,8 @@ rb_fstring(VALUE str) rb_ractor_classify_as_shareable(str); return str; } - if (FL_TEST_RAW(str, STR_NOEMBED|STR_SHARED_ROOT|STR_SHARED) == (STR_NOEMBED|STR_SHARED_ROOT)) { + + if (FL_TEST_RAW(str, STR_SHARED_ROOT | STR_SHARED) == STR_SHARED_ROOT) { assert(OBJ_FROZEN(str)); rb_ractor_classify_as_shareable(str); return str; diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb index 3f4b64bbcdf4cd..fd0e57b8a59a7a 100644 --- a/test/io/console/test_io_console.rb +++ b/test/io/console/test_io_console.rb @@ -241,7 +241,6 @@ def test_setecho2 end def test_getpass - omit unless IO.method_defined?("getpass") run_pty("p IO.console.getpass('> ')") do |r, w| assert_equal("> ", r.readpartial(10)) sleep 0.1 @@ -259,6 +258,15 @@ def test_getpass assert_equal("\r\n", r.gets) assert_equal("\"asdf\"", r.gets.chomp) end + + run_pty("$VERBOSE, $/ = nil, '.'; p IO.console.getpass('> ')") do |r, w| + assert_equal("> ", r.readpartial(10)) + sleep 0.1 + w.print "asdf\n" + sleep 0.1 + assert_equal("\r\n", r.gets) + assert_equal("\"asdf\"", r.gets.chomp) + end end def test_iflush diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb index 42f09003fc1308..42715df8ea7b9c 100644 --- a/test/rubygems/test_gem_commands_build_command.rb +++ b/test/rubygems/test_gem_commands_build_command.rb @@ -199,7 +199,8 @@ def test_execute_strict_with_warnings error = @ui.error.split "\n" assert_equal "WARNING: licenses is empty, but is recommended. Use a license identifier from", error.shift - assert_equal "http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.", error.shift + assert_equal "http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,", error.shift + assert_equal "or set it to nil if you don't want to specify a license.", error.shift assert_equal "WARNING: See https://guides.rubygems.org/specification-reference/ for help", error.shift assert_equal [], error diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index 1adb7801581753..4ca806efc323f3 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -946,6 +946,87 @@ def test_verify_corrupt tf.close! end + def test_verify_corrupt_tar_metadata_entry + gem = tar_file_header("metadata.gz", "", 0, 999, Time.now) + + File.open "corrupt.gem", "wb" do |io| + io.write gem + end + + package = Gem::Package.new "corrupt.gem" + + e = assert_raise Gem::Package::FormatError do + package.verify + end + + assert_match(/(EOFError|end of file reached) in corrupt.gem/i, e.message) + end + + def test_verify_corrupt_tar_checksums_entry + gem = tar_file_header("checksums.yaml.gz", "", 0, 100, Time.now) + + File.open "corrupt.gem", "wb" do |io| + io.write gem + end + + package = Gem::Package.new "corrupt.gem" + + e = assert_raise Gem::Package::FormatError do + package.verify + end + + assert_equal "not in gzip format in corrupt.gem", e.message + end + + def test_verify_corrupt_tar_data_entry + gem = tar_file_header("data.tar.gz", "", 0, 100, Time.now) + + File.open "corrupt.gem", "wb" do |io| + io.write gem + end + + package = Gem::Package.new "corrupt.gem" + + e = assert_raise Gem::Package::FormatError do + package.verify + end + + assert_match(/(EOFError|end of file reached) in corrupt.gem/i, e.message) + end + + def test_corrupt_data_tar_gz + data_tgz = util_gzip tar_file_header("lib/code.rb", "", 0, 100, Time.now) + metadata_gz = util_gzip @spec.to_yaml + + gem = util_tar do |tar| + tar.add_file "data.tar.gz", 0o444 do |io| + io.write data_tgz + end + + tar.add_file "metadata.gz", 0o644 do |io| + io.write metadata_gz + end + end + + File.open "corrupt.gem", "wb" do |io| + io.write gem.string + end + + package = Gem::Package.new "corrupt.gem" + + e = assert_raise Gem::Package::FormatError do + package.contents + end + + assert_match(/(EOFError|end of file reached) in corrupt.gem/i, e.message) + + e = assert_raise Gem::Package::FormatError do + package.extract_files @destination + end + + assert_match(/(EOFError|end of file reached) in corrupt.gem/i, e.message) + end + def test_verify_empty FileUtils.touch "empty.gem" diff --git a/test/rubygems/test_gem_package_tar_reader_entry.rb b/test/rubygems/test_gem_package_tar_reader_entry.rb index d8c9ba56652c19..7510e1d199427b 100644 --- a/test/rubygems/test_gem_package_tar_reader_entry.rb +++ b/test/rubygems/test_gem_package_tar_reader_entry.rb @@ -181,10 +181,15 @@ def test_read_remaining assert_equal @contents[100..-1], @entry.read end - def test_read_partial + def test_readpartial assert_equal @contents[0...100], @entry.readpartial(100) end + def test_readpartial_to_eof + assert_equal @contents, @entry.readpartial(4096) + assert @entry.eof? + end + def test_read_partial_buffer buffer = "".b @entry.readpartial(100, buffer) @@ -193,11 +198,38 @@ def test_read_partial_buffer def test_readpartial_past_eof @entry.readpartial(@contents.size) + assert @entry.eof? assert_raise(EOFError) do @entry.readpartial(1) end end + def test_read_corrupted_tar + corrupt_tar = String.new + corrupt_tar << tar_file_header("lib/foo", "", 0, 100, Time.now) + corrupt_tar << tar_file_contents("") + corrupt_entry = util_entry corrupt_tar + + assert_equal "", corrupt_entry.read(0) + assert_equal "", corrupt_entry.read, "IO.read without len should return empty string (even though it's at an unpexpected EOF)" + + corrupt_entry.rewind + + assert_nil corrupt_entry.read(100), "IO.read with len should return nil as per IO.read docs" + end + + def test_readpartial_corrupted_tar + corrupt_tar = String.new + corrupt_tar << tar_file_header("lib/foo", "", 0, 100, Time.now) + corrupt_tar << tar_file_contents("") + + corrupt_entry = util_entry corrupt_tar + + assert_raise EOFError do + corrupt_entry.readpartial(100) + end + end + def test_rewind char = @entry.getc @@ -303,4 +335,20 @@ def test_seek_in_gzip_io_with_non_zero_offset assert_equal contents2.size, entry.pos end end + + def test_seek_in_gzip_io_corrupted + @tar << tar_file_header("lib/bar", "", 0, 100, Time.now) + @tar << tar_file_contents("") + + tgz = util_gzip(@tar) + + Zlib::GzipReader.wrap StringIO.new(tgz) do |gzio| + util_entry(gzio).close # skip the first entry so io.pos is not 0 + entry = util_entry(gzio) + + assert_raise EOFError do + entry.seek(50) + end + end + end end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 6a893f09c96667..9e68c40b7cb87d 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -3086,10 +3086,22 @@ def test_validate_license assert_match <<-WARNING, @ui.error WARNING: licenses is empty, but is recommended. Use a license identifier from -http://spdx.org/licenses or 'Nonstandard' for a nonstandard license. +http://spdx.org/licenses or 'Nonstandard' for a nonstandard license, +or set it to nil if you don't want to specify a license. WARNING end + def test_validate_nil_license + util_setup_validate + + use_ui @ui do + @a1.license = nil + @a1.validate + end + + assert_empty @ui.error + end + def test_validate_license_in_a_non_packaging_context util_setup_validate @@ -3126,7 +3138,8 @@ def test_validate_license_values assert_match <<-WARNING, @ui.error WARNING: license value 'BSD' is invalid. Use a license identifier from -http://spdx.org/licenses or 'Nonstandard' for a nonstandard license. +http://spdx.org/licenses or 'Nonstandard' for a nonstandard license, +or set it to nil if you don't want to specify a license. WARNING end @@ -3184,11 +3197,13 @@ def test_validate_license_with_nonsense_suffix assert_match <<-WARNING, @ui.error WARNING: license value 'GPL-2.0+ FOO' is invalid. Use a license identifier from -http://spdx.org/licenses or 'Nonstandard' for a nonstandard license. +http://spdx.org/licenses or 'Nonstandard' for a nonstandard license, +or set it to nil if you don't want to specify a license. WARNING assert_match <<-WARNING, @ui.error WARNING: license value 'GPL-2.0 FOO' is invalid. Use a license identifier from -http://spdx.org/licenses or 'Nonstandard' for a nonstandard license. +http://spdx.org/licenses or 'Nonstandard' for a nonstandard license, +or set it to nil if you don't want to specify a license. WARNING end @@ -3202,7 +3217,8 @@ def test_validate_license_with_invalid_exception assert_match <<-WARNING, @ui.error WARNING: license value 'GPL-2.0+ WITH Autocofn-exception-2.0' is invalid. Use a license identifier from -http://spdx.org/licenses or 'Nonstandard' for a nonstandard license. +http://spdx.org/licenses or 'Nonstandard' for a nonstandard license, +or set it to nil if you don't want to specify a license. WARNING end @@ -3216,7 +3232,8 @@ def test_validate_license_gives_suggestions assert_match <<-WARNING, @ui.error WARNING: license value 'ruby' is invalid. Use a license identifier from -http://spdx.org/licenses or 'Nonstandard' for a nonstandard license. +http://spdx.org/licenses or 'Nonstandard' for a nonstandard license, +or set it to nil if you don't want to specify a license. Did you mean 'Ruby'? WARNING end diff --git a/test/snapshots/heredoc_with_escaped_newline_at_start.txt b/test/snapshots/heredoc_with_escaped_newline_at_start.txt new file mode 100644 index 00000000000000..43fa751526de80 --- /dev/null +++ b/test/snapshots/heredoc_with_escaped_newline_at_start.txt @@ -0,0 +1,45 @@ +ProgramNode(0...62)( + [], + StatementsNode(0...62)( + [CallNode(0...25)( + InterpolatedStringNode(0...9)((0...9), [], (27...34)), + (9...10), + (10...14), + nil, + ArgumentsNode(15...25)( + [RegularExpressionNode(15...21)( + (15...16), + (16...20), + (20...21), + "^ {", + 0 + ), + StringNode(23...25)((23...24), (24...24), (24...25), "")] + ), + nil, + nil, + 0, + "gsub" + ), + CallNode(37...62)( + InterpolatedStringNode(37...46)((37...46), [], (65...73)), + (46...47), + (47...51), + nil, + ArgumentsNode(52...62)( + [RegularExpressionNode(52...58)( + (52...53), + (53...57), + (57...58), + "^ {", + 0 + ), + StringNode(60...62)((60...61), (61...61), (61...62), "")] + ), + nil, + nil, + 0, + "gsub" + )] + ) +) diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index 3b880eda85746a..355e7a8aff298f 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -155,6 +155,13 @@ def test_unterminated_parenthesized_expression ] end + def test_unterminated_argument_expression + assert_errors expression('a %'), 'a %', [ + ["Unexpected end of input", 2..3], + ["Expected a value after the operator.", 3..3], + ] + end + def test_1_2_3 assert_errors expression("(1, 2, 3)"), "(1, 2, 3)", [ ["Expected to be able to parse an expression.", 2..2], diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb index dfe9d4ee00f396..242bbc07f2e95a 100755 --- a/tool/sync_default_gems.rb +++ b/tool/sync_default_gems.rb @@ -403,23 +403,18 @@ def sync_default_gems(gem) rm_rf(%w[test/yarp yarp]) # Run the YARP templating scripts - system("ruby #{upstream}/templates/template.rb") cp_r("#{upstream}/ext/yarp", "yarp") cp_r("#{upstream}/lib/.", "lib") cp_r("#{upstream}/test", "test/yarp") cp_r("#{upstream}/src/.", "yarp") - # Move all files in enc to be prefixed with yp_ in order - # to deconflict them from non-yarp enc files - (Dir.entries("yarp/enc/") - ["..", "."]).each do |f| - next if f.start_with?("yp_") - mv "yarp/enc/#{f}", "yarp/enc/yp_#{f}" - end - cp_r("#{upstream}/yarp.gemspec", "lib/yarp") cp_r("#{upstream}/include/yarp/.", "yarp") cp_r("#{upstream}/include/yarp.h", "yarp") + cp_r("#{upstream}/config.yml", "yarp/") + cp_r("#{upstream}/templates", "yarp/") + rm_f("yarp/config.h") File.write("yarp/config.h", "#include \"ruby/config.h\"\n") rm("yarp/extconf.rb") @@ -455,7 +450,7 @@ def sync_default_gems(gem) |bin\/.* |configure\.ac |rakelib\/.* - |templates\/.* + |rust\/.* |test\/lib\/.* |tasks\/.* |ext\/yarp\/extconf\.rb @@ -504,6 +499,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil) repo, default_branch = REPOSITORIES[gem.to_sym] puts "Sync #{repo} with commit history." + # Fetch the repository to be synchronized IO.popen(%W"git remote") do |f| unless f.read.split.include?(gem) `git remote add #{gem} git@github.com:#{repo}.git` @@ -511,12 +507,14 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil) end system(*%W"git fetch --no-tags #{gem}") + # If -a is given, discover all commits since the last picked commit if ranges == true pattern = "https://github\.com/#{Regexp.quote(repo)}/commit/([0-9a-f]+)$" log = IO.popen(%W"git log -E --grep=#{pattern} -n1 --format=%B", &:read) ranges = ["#{log[%r[#{pattern}\n\s*(?i:co-authored-by:.*)*\s*\Z], 1]}..#{gem}/#{default_branch}"] end + # Parse a given range with git log commits = ranges.flat_map do |range| unless range.include?("..") range = "#{range}~1..#{range}" @@ -527,7 +525,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil) end end - # Ignore Merge commit and insufficiency commit for ruby core repository. + # Ignore Merge commits and already-merged commits. case gem when "yarp" ignore_file_pattern = YARP_IGNORE_FILE_PATTERN @@ -559,6 +557,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil) commits.each do |sha, subject| puts "Pick #{sha} from #{repo}." + # Attempt to cherry-pick a commit skipped = false result = IO.popen(%W"git cherry-pick #{sha}", &:read) if result =~ /nothing\ to\ commit/ @@ -568,30 +567,54 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil) end next if skipped - case gem - when "rubygems" - %w[bundler/spec/support/artifice/vcr_cassettes].each do |rem| - if File.exist?(rem) - system("git", "reset", rem) - rm_rf(rem) - end - end - system(*%w[git add spec/bundler]) - end - + # Skip empty commits or deal with conflicts if result.empty? skipped = true elsif /^CONFLICT/ =~ result - result = pipe_readlines(%W"git status --porcelain -z") - result.map! {|line| line[/\A(?:.U|[UA]A) (.*)/, 1]} - result.compact! - ignore, conflict = result.partition {|name| ignore_file_pattern =~ name} + # Forcibly remove any files that we don't want to copy to this repository. + # We also ignore them as new `toplevels` even when they don't conflict. + case gem + when "rubygems" + # We don't copy any vcr_cassettes to this repository. Because the directory does not + # exist, rename detection doesn't work. So it starts with the original path `bundler/`. + %w[bundler/spec/support/artifice/vcr_cassettes].each do |rem| + if File.exist?(rem) + system("git", "reset", rem) + rm_rf(rem) + end + end + end + + # git has inexact rename detection, so they follow directory renames even for new files. + # However, new files are considered a `CONFLICT (file location)`, so you need to git-add them here. + # We hope that they are not other kinds of conflicts, assuming we don't modify them in this repository. + case gem + when "rubygems" + system(*%w[git add spec/bundler]) + when "yarp" + system(*%w[git add lib/yarp]) + system(*%w[git add test/yarp]) + system(*%w[git add yarp]) + end + + # Discover unmerged files + # AU: unmerged, added by us + # DU: unmerged, deleted by us + # UU: unmerged, both modified + # UA: unmerged, added by them + # AA: unmerged, both added + unmerged = pipe_readlines(%W"git status --porcelain -z") + unmerged.map! {|line| line[/\A(?:.U|[UA]A) (.*)/, 1]} + unmerged.compact! + ignore, conflict = unmerged.partition {|name| ignore_file_pattern =~ name} + # Reset ignored files if they conflict unless ignore.empty? system(*%W"git reset HEAD --", *ignore) File.unlink(*ignore) ignore = pipe_readlines(%W"git status --porcelain -z" + ignore).map! {|line| line[/\A.. (.*)/, 1]} system(*%W"git checkout HEAD --", *ignore) unless ignore.empty? end + # If -e option is given, open each conflicted file with an editor unless conflict.empty? if edit case @@ -603,9 +626,11 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil) end end end + # Attempt to commit the cherry-pick skipped = !system({"GIT_EDITOR"=>"true"}, *%W"git cherry-pick --no-edit --continue") end + # Skip the commit if it's empty or the cherry-pick attempt failed if skipped failed_commits << sha `git reset` && `git checkout .` && `git clean -fd` @@ -613,6 +638,8 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil) next end + # Forcibly remove any new top-level entries, and any changes under + # /test/fixtures, /test/lib, or /tool. changed = pipe_readlines(%W"git diff --name-only -z HEAD~..HEAD --") toplevels = changed.map {|f| f[%r[\A(?!tool/)[^/]+/?]]}.compact toplevels.delete_if do |top| @@ -646,6 +673,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil) end end + # Amend the commit if RDoc references need to be replaced head = `git log --format=%H -1 HEAD`.chomp system(*%w"git reset --quiet HEAD~ --") amend = replace_rdoc_ref_all @@ -656,6 +684,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil) puts "Update commit message: #{sha}" + # Run this script itself (tool/sync_default_gems.rb --message-filter) as a message filter IO.popen({"FILTER_BRANCH_SQUELCH_WARNING" => "1"}, %W[git filter-branch -f --msg-filter #{[filter, repo, sha].join(' ')} -- HEAD~1..HEAD], &:read) @@ -782,6 +811,9 @@ def update_default_gems(gem, release: false) \e[1mPick a commit range from the upstream repository\e[0m ruby #$0 rubygems 97e9768612..9e53702832 +\e[1mPick all commits since the last picked commit\e[0m + ruby #$0 rubygems -a + \e[1mList known libraries\e[0m ruby #$0 list diff --git a/yarp/api_node.c b/yarp/api_node.c deleted file mode 100644 index f15b92235cfc8c..00000000000000 --- a/yarp/api_node.c +++ /dev/null @@ -1,3712 +0,0 @@ -/******************************************************************************/ -/* This file is generated by the bin/template script and should not be */ -/* modified manually. See */ -/* templates/ext/yarp/api_node.c.erb */ -/* if you are looking to modify the */ -/* template */ -/******************************************************************************/ -#line 2 "api_node.c.erb" -#include "yarp/extension.h" - -extern VALUE rb_cYARP; -extern VALUE rb_cYARPNode; -extern VALUE rb_cYARPSource; -extern VALUE rb_cYARPToken; -extern VALUE rb_cYARPLocation; - -static VALUE rb_cYARPAliasNode; -static VALUE rb_cYARPAlternationPatternNode; -static VALUE rb_cYARPAndNode; -static VALUE rb_cYARPArgumentsNode; -static VALUE rb_cYARPArrayNode; -static VALUE rb_cYARPArrayPatternNode; -static VALUE rb_cYARPAssocNode; -static VALUE rb_cYARPAssocSplatNode; -static VALUE rb_cYARPBackReferenceReadNode; -static VALUE rb_cYARPBeginNode; -static VALUE rb_cYARPBlockArgumentNode; -static VALUE rb_cYARPBlockNode; -static VALUE rb_cYARPBlockParameterNode; -static VALUE rb_cYARPBlockParametersNode; -static VALUE rb_cYARPBreakNode; -static VALUE rb_cYARPCallNode; -static VALUE rb_cYARPCallOperatorAndWriteNode; -static VALUE rb_cYARPCallOperatorOrWriteNode; -static VALUE rb_cYARPCallOperatorWriteNode; -static VALUE rb_cYARPCapturePatternNode; -static VALUE rb_cYARPCaseNode; -static VALUE rb_cYARPClassNode; -static VALUE rb_cYARPClassVariableOperatorAndWriteNode; -static VALUE rb_cYARPClassVariableOperatorOrWriteNode; -static VALUE rb_cYARPClassVariableOperatorWriteNode; -static VALUE rb_cYARPClassVariableReadNode; -static VALUE rb_cYARPClassVariableWriteNode; -static VALUE rb_cYARPConstantOperatorAndWriteNode; -static VALUE rb_cYARPConstantOperatorOrWriteNode; -static VALUE rb_cYARPConstantOperatorWriteNode; -static VALUE rb_cYARPConstantPathNode; -static VALUE rb_cYARPConstantPathOperatorAndWriteNode; -static VALUE rb_cYARPConstantPathOperatorOrWriteNode; -static VALUE rb_cYARPConstantPathOperatorWriteNode; -static VALUE rb_cYARPConstantPathWriteNode; -static VALUE rb_cYARPConstantReadNode; -static VALUE rb_cYARPConstantWriteNode; -static VALUE rb_cYARPDefNode; -static VALUE rb_cYARPDefinedNode; -static VALUE rb_cYARPElseNode; -static VALUE rb_cYARPEmbeddedStatementsNode; -static VALUE rb_cYARPEmbeddedVariableNode; -static VALUE rb_cYARPEnsureNode; -static VALUE rb_cYARPFalseNode; -static VALUE rb_cYARPFindPatternNode; -static VALUE rb_cYARPFlipFlopNode; -static VALUE rb_cYARPFloatNode; -static VALUE rb_cYARPForNode; -static VALUE rb_cYARPForwardingArgumentsNode; -static VALUE rb_cYARPForwardingParameterNode; -static VALUE rb_cYARPForwardingSuperNode; -static VALUE rb_cYARPGlobalVariableOperatorAndWriteNode; -static VALUE rb_cYARPGlobalVariableOperatorOrWriteNode; -static VALUE rb_cYARPGlobalVariableOperatorWriteNode; -static VALUE rb_cYARPGlobalVariableReadNode; -static VALUE rb_cYARPGlobalVariableWriteNode; -static VALUE rb_cYARPHashNode; -static VALUE rb_cYARPHashPatternNode; -static VALUE rb_cYARPIfNode; -static VALUE rb_cYARPImaginaryNode; -static VALUE rb_cYARPInNode; -static VALUE rb_cYARPInstanceVariableOperatorAndWriteNode; -static VALUE rb_cYARPInstanceVariableOperatorOrWriteNode; -static VALUE rb_cYARPInstanceVariableOperatorWriteNode; -static VALUE rb_cYARPInstanceVariableReadNode; -static VALUE rb_cYARPInstanceVariableWriteNode; -static VALUE rb_cYARPIntegerNode; -static VALUE rb_cYARPInterpolatedRegularExpressionNode; -static VALUE rb_cYARPInterpolatedStringNode; -static VALUE rb_cYARPInterpolatedSymbolNode; -static VALUE rb_cYARPInterpolatedXStringNode; -static VALUE rb_cYARPKeywordHashNode; -static VALUE rb_cYARPKeywordParameterNode; -static VALUE rb_cYARPKeywordRestParameterNode; -static VALUE rb_cYARPLambdaNode; -static VALUE rb_cYARPLocalVariableOperatorAndWriteNode; -static VALUE rb_cYARPLocalVariableOperatorOrWriteNode; -static VALUE rb_cYARPLocalVariableOperatorWriteNode; -static VALUE rb_cYARPLocalVariableReadNode; -static VALUE rb_cYARPLocalVariableWriteNode; -static VALUE rb_cYARPMatchPredicateNode; -static VALUE rb_cYARPMatchRequiredNode; -static VALUE rb_cYARPMissingNode; -static VALUE rb_cYARPModuleNode; -static VALUE rb_cYARPMultiWriteNode; -static VALUE rb_cYARPNextNode; -static VALUE rb_cYARPNilNode; -static VALUE rb_cYARPNoKeywordsParameterNode; -static VALUE rb_cYARPNumberedReferenceReadNode; -static VALUE rb_cYARPOptionalParameterNode; -static VALUE rb_cYARPOrNode; -static VALUE rb_cYARPParametersNode; -static VALUE rb_cYARPParenthesesNode; -static VALUE rb_cYARPPinnedExpressionNode; -static VALUE rb_cYARPPinnedVariableNode; -static VALUE rb_cYARPPostExecutionNode; -static VALUE rb_cYARPPreExecutionNode; -static VALUE rb_cYARPProgramNode; -static VALUE rb_cYARPRangeNode; -static VALUE rb_cYARPRationalNode; -static VALUE rb_cYARPRedoNode; -static VALUE rb_cYARPRegularExpressionNode; -static VALUE rb_cYARPRequiredDestructuredParameterNode; -static VALUE rb_cYARPRequiredParameterNode; -static VALUE rb_cYARPRescueModifierNode; -static VALUE rb_cYARPRescueNode; -static VALUE rb_cYARPRestParameterNode; -static VALUE rb_cYARPRetryNode; -static VALUE rb_cYARPReturnNode; -static VALUE rb_cYARPSelfNode; -static VALUE rb_cYARPSingletonClassNode; -static VALUE rb_cYARPSourceEncodingNode; -static VALUE rb_cYARPSourceFileNode; -static VALUE rb_cYARPSourceLineNode; -static VALUE rb_cYARPSplatNode; -static VALUE rb_cYARPStatementsNode; -static VALUE rb_cYARPStringConcatNode; -static VALUE rb_cYARPStringNode; -static VALUE rb_cYARPSuperNode; -static VALUE rb_cYARPSymbolNode; -static VALUE rb_cYARPTrueNode; -static VALUE rb_cYARPUndefNode; -static VALUE rb_cYARPUnlessNode; -static VALUE rb_cYARPUntilNode; -static VALUE rb_cYARPWhenNode; -static VALUE rb_cYARPWhileNode; -static VALUE rb_cYARPXStringNode; -static VALUE rb_cYARPYieldNode; - -static VALUE -yp_location_new(yp_parser_t *parser, const char *start, const char *end, VALUE source) { - VALUE argv[] = { source, LONG2FIX(start - parser->start), LONG2FIX(end - start) }; - return rb_class_new_instance(3, argv, rb_cYARPLocation); -} - -VALUE -yp_token_new(yp_parser_t *parser, yp_token_t *token, rb_encoding *encoding, VALUE source) { - ID type = rb_intern(yp_token_type_to_str(token->type)); - VALUE location = yp_location_new(parser, token->start, token->end, source); - - VALUE argv[] = { - ID2SYM(type), - rb_enc_str_new(token->start, token->end - token->start, encoding), - location - }; - - return rb_class_new_instance(3, argv, rb_cYARPToken); -} - -static VALUE -yp_string_new(yp_string_t *string, rb_encoding *encoding) { - return rb_enc_str_new(yp_string_source(string), yp_string_length(string), encoding); -} - -// Create a YARP::Source object from the given parser. -VALUE -yp_source_new(yp_parser_t *parser) { - VALUE source = rb_str_new(parser->start, parser->end - parser->start); - VALUE offsets = rb_ary_new_capa(parser->newline_list.size); - - for (size_t index = 0; index < parser->newline_list.size; index++) { - rb_ary_push(offsets, INT2FIX(parser->newline_list.offsets[index])); - } - - VALUE source_argv[] = { source, offsets }; - return rb_class_new_instance(2, source_argv, rb_cYARPSource); -} - -typedef struct yp_node_stack_node { - struct yp_node_stack_node *prev; - yp_node_t *visit; - bool visited; -} yp_node_stack_node_t; - -static void -yp_node_stack_push(yp_node_stack_node_t **stack, yp_node_t *visit) { - yp_node_stack_node_t *node = malloc(sizeof(yp_node_stack_node_t)); - node->prev = *stack; - node->visit = visit; - node->visited = false; - *stack = node; -} - -static yp_node_t * -yp_node_stack_pop(yp_node_stack_node_t **stack) { - yp_node_stack_node_t *current = *stack; - yp_node_t *visit = current->visit; - - *stack = current->prev; - free(current); - - return visit; -} - -VALUE -yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) { - VALUE source = yp_source_new(parser); - ID *constants = calloc(parser->constant_pool.size, sizeof(ID)); - - for (size_t index = 0; index < parser->constant_pool.capacity; index++) { - yp_constant_t constant = parser->constant_pool.constants[index]; - - if (constant.id != 0) { - constants[constant.id - 1] = rb_intern3(constant.start, constant.length, encoding); - } - } - - yp_node_stack_node_t *node_stack = NULL; - yp_node_stack_push(&node_stack, node); - VALUE value_stack = rb_ary_new(); - - while (node_stack != NULL) { - if (!node_stack->visited) { - if (node_stack->visit == NULL) { - yp_node_stack_pop(&node_stack); - rb_ary_push(value_stack, Qnil); - continue; - } - - yp_node_t *node = node_stack->visit; - node_stack->visited = true; - - switch (YP_NODE_TYPE(node)) { -#line 111 "api_node.c.erb" - case YP_NODE_ALIAS_NODE: { - yp_alias_node_t *cast = (yp_alias_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->new_name); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->old_name); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_ALTERNATION_PATTERN_NODE: { - yp_alternation_pattern_node_t *cast = (yp_alternation_pattern_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->left); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->right); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_AND_NODE: { - yp_and_node_t *cast = (yp_and_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->left); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->right); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_ARGUMENTS_NODE: { - yp_arguments_node_t *cast = (yp_arguments_node_t *) node; - for (size_t index = 0; index < cast->arguments.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->arguments.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_ARRAY_NODE: { - yp_array_node_t *cast = (yp_array_node_t *) node; - for (size_t index = 0; index < cast->elements.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->elements.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_ARRAY_PATTERN_NODE: { - yp_array_pattern_node_t *cast = (yp_array_pattern_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->constant); - for (size_t index = 0; index < cast->requireds.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->requireds.nodes[index]); - } - yp_node_stack_push(&node_stack, (yp_node_t *) cast->rest); - for (size_t index = 0; index < cast->posts.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->posts.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_ASSOC_NODE: { - yp_assoc_node_t *cast = (yp_assoc_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->key); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_ASSOC_SPLAT_NODE: { - yp_assoc_splat_node_t *cast = (yp_assoc_splat_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_BEGIN_NODE: { - yp_begin_node_t *cast = (yp_begin_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->rescue_clause); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->else_clause); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->ensure_clause); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_BLOCK_ARGUMENT_NODE: { - yp_block_argument_node_t *cast = (yp_block_argument_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->expression); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_BLOCK_NODE: { - yp_block_node_t *cast = (yp_block_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->parameters); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_BLOCK_PARAMETERS_NODE: { - yp_block_parameters_node_t *cast = (yp_block_parameters_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->parameters); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_BREAK_NODE: { - yp_break_node_t *cast = (yp_break_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->arguments); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CALL_NODE: { - yp_call_node_t *cast = (yp_call_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->receiver); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->arguments); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->block); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CALL_OPERATOR_AND_WRITE_NODE: { - yp_call_operator_and_write_node_t *cast = (yp_call_operator_and_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->target); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CALL_OPERATOR_OR_WRITE_NODE: { - yp_call_operator_or_write_node_t *cast = (yp_call_operator_or_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->target); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CALL_OPERATOR_WRITE_NODE: { - yp_call_operator_write_node_t *cast = (yp_call_operator_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->target); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CAPTURE_PATTERN_NODE: { - yp_capture_pattern_node_t *cast = (yp_capture_pattern_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->target); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CASE_NODE: { - yp_case_node_t *cast = (yp_case_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->predicate); - for (size_t index = 0; index < cast->conditions.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->conditions.nodes[index]); - } - yp_node_stack_push(&node_stack, (yp_node_t *) cast->consequent); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CLASS_NODE: { - yp_class_node_t *cast = (yp_class_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->constant_path); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->superclass); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_class_variable_operator_and_write_node_t *cast = (yp_class_variable_operator_and_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_class_variable_operator_or_write_node_t *cast = (yp_class_variable_operator_or_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: { - yp_class_variable_operator_write_node_t *cast = (yp_class_variable_operator_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CLASS_VARIABLE_WRITE_NODE: { - yp_class_variable_write_node_t *cast = (yp_class_variable_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE: { - yp_constant_operator_and_write_node_t *cast = (yp_constant_operator_and_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE: { - yp_constant_operator_or_write_node_t *cast = (yp_constant_operator_or_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_WRITE_NODE: { - yp_constant_operator_write_node_t *cast = (yp_constant_operator_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CONSTANT_PATH_NODE: { - yp_constant_path_node_t *cast = (yp_constant_path_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->parent); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->child); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE: { - yp_constant_path_operator_and_write_node_t *cast = (yp_constant_path_operator_and_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->target); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE: { - yp_constant_path_operator_or_write_node_t *cast = (yp_constant_path_operator_or_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->target); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE: { - yp_constant_path_operator_write_node_t *cast = (yp_constant_path_operator_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->target); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CONSTANT_PATH_WRITE_NODE: { - yp_constant_path_write_node_t *cast = (yp_constant_path_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->target); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_CONSTANT_WRITE_NODE: { - yp_constant_write_node_t *cast = (yp_constant_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_DEF_NODE: { - yp_def_node_t *cast = (yp_def_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->receiver); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->parameters); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_DEFINED_NODE: { - yp_defined_node_t *cast = (yp_defined_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_ELSE_NODE: { - yp_else_node_t *cast = (yp_else_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_EMBEDDED_STATEMENTS_NODE: { - yp_embedded_statements_node_t *cast = (yp_embedded_statements_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_EMBEDDED_VARIABLE_NODE: { - yp_embedded_variable_node_t *cast = (yp_embedded_variable_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->variable); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_ENSURE_NODE: { - yp_ensure_node_t *cast = (yp_ensure_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_FIND_PATTERN_NODE: { - yp_find_pattern_node_t *cast = (yp_find_pattern_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->constant); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->left); - for (size_t index = 0; index < cast->requireds.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->requireds.nodes[index]); - } - yp_node_stack_push(&node_stack, (yp_node_t *) cast->right); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_FLIP_FLOP_NODE: { - yp_flip_flop_node_t *cast = (yp_flip_flop_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->left); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->right); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_FOR_NODE: { - yp_for_node_t *cast = (yp_for_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->index); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->collection); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_FORWARDING_SUPER_NODE: { - yp_forwarding_super_node_t *cast = (yp_forwarding_super_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->block); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_global_variable_operator_and_write_node_t *cast = (yp_global_variable_operator_and_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_global_variable_operator_or_write_node_t *cast = (yp_global_variable_operator_or_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: { - yp_global_variable_operator_write_node_t *cast = (yp_global_variable_operator_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: { - yp_global_variable_write_node_t *cast = (yp_global_variable_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_HASH_NODE: { - yp_hash_node_t *cast = (yp_hash_node_t *) node; - for (size_t index = 0; index < cast->elements.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->elements.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_HASH_PATTERN_NODE: { - yp_hash_pattern_node_t *cast = (yp_hash_pattern_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->constant); - for (size_t index = 0; index < cast->assocs.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->assocs.nodes[index]); - } - yp_node_stack_push(&node_stack, (yp_node_t *) cast->kwrest); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_IF_NODE: { - yp_if_node_t *cast = (yp_if_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->predicate); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->consequent); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_IMAGINARY_NODE: { - yp_imaginary_node_t *cast = (yp_imaginary_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->numeric); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_IN_NODE: { - yp_in_node_t *cast = (yp_in_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->pattern); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_instance_variable_operator_and_write_node_t *cast = (yp_instance_variable_operator_and_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_instance_variable_operator_or_write_node_t *cast = (yp_instance_variable_operator_or_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: { - yp_instance_variable_operator_write_node_t *cast = (yp_instance_variable_operator_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: { - yp_instance_variable_write_node_t *cast = (yp_instance_variable_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE: { - yp_interpolated_regular_expression_node_t *cast = (yp_interpolated_regular_expression_node_t *) node; - for (size_t index = 0; index < cast->parts.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->parts.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_INTERPOLATED_STRING_NODE: { - yp_interpolated_string_node_t *cast = (yp_interpolated_string_node_t *) node; - for (size_t index = 0; index < cast->parts.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->parts.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_INTERPOLATED_SYMBOL_NODE: { - yp_interpolated_symbol_node_t *cast = (yp_interpolated_symbol_node_t *) node; - for (size_t index = 0; index < cast->parts.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->parts.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_INTERPOLATED_X_STRING_NODE: { - yp_interpolated_x_string_node_t *cast = (yp_interpolated_x_string_node_t *) node; - for (size_t index = 0; index < cast->parts.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->parts.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_KEYWORD_HASH_NODE: { - yp_keyword_hash_node_t *cast = (yp_keyword_hash_node_t *) node; - for (size_t index = 0; index < cast->elements.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->elements.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_KEYWORD_PARAMETER_NODE: { - yp_keyword_parameter_node_t *cast = (yp_keyword_parameter_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_LAMBDA_NODE: { - yp_lambda_node_t *cast = (yp_lambda_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->parameters); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_local_variable_operator_and_write_node_t *cast = (yp_local_variable_operator_and_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_local_variable_operator_or_write_node_t *cast = (yp_local_variable_operator_or_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: { - yp_local_variable_operator_write_node_t *cast = (yp_local_variable_operator_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: { - yp_local_variable_write_node_t *cast = (yp_local_variable_write_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_MATCH_PREDICATE_NODE: { - yp_match_predicate_node_t *cast = (yp_match_predicate_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->pattern); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_MATCH_REQUIRED_NODE: { - yp_match_required_node_t *cast = (yp_match_required_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->pattern); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_MODULE_NODE: { - yp_module_node_t *cast = (yp_module_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->constant_path); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_MULTI_WRITE_NODE: { - yp_multi_write_node_t *cast = (yp_multi_write_node_t *) node; - for (size_t index = 0; index < cast->targets.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->targets.nodes[index]); - } - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_NEXT_NODE: { - yp_next_node_t *cast = (yp_next_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->arguments); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_OPTIONAL_PARAMETER_NODE: { - yp_optional_parameter_node_t *cast = (yp_optional_parameter_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->value); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_OR_NODE: { - yp_or_node_t *cast = (yp_or_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->left); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->right); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_PARAMETERS_NODE: { - yp_parameters_node_t *cast = (yp_parameters_node_t *) node; - for (size_t index = 0; index < cast->requireds.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->requireds.nodes[index]); - } - for (size_t index = 0; index < cast->optionals.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->optionals.nodes[index]); - } - for (size_t index = 0; index < cast->posts.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->posts.nodes[index]); - } - yp_node_stack_push(&node_stack, (yp_node_t *) cast->rest); - for (size_t index = 0; index < cast->keywords.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->keywords.nodes[index]); - } - yp_node_stack_push(&node_stack, (yp_node_t *) cast->keyword_rest); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->block); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_PARENTHESES_NODE: { - yp_parentheses_node_t *cast = (yp_parentheses_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_PINNED_EXPRESSION_NODE: { - yp_pinned_expression_node_t *cast = (yp_pinned_expression_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->expression); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_PINNED_VARIABLE_NODE: { - yp_pinned_variable_node_t *cast = (yp_pinned_variable_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->variable); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_POST_EXECUTION_NODE: { - yp_post_execution_node_t *cast = (yp_post_execution_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_PRE_EXECUTION_NODE: { - yp_pre_execution_node_t *cast = (yp_pre_execution_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_PROGRAM_NODE: { - yp_program_node_t *cast = (yp_program_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_RANGE_NODE: { - yp_range_node_t *cast = (yp_range_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->left); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->right); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_RATIONAL_NODE: { - yp_rational_node_t *cast = (yp_rational_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->numeric); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE: { - yp_required_destructured_parameter_node_t *cast = (yp_required_destructured_parameter_node_t *) node; - for (size_t index = 0; index < cast->parameters.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->parameters.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_RESCUE_MODIFIER_NODE: { - yp_rescue_modifier_node_t *cast = (yp_rescue_modifier_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->expression); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->rescue_expression); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_RESCUE_NODE: { - yp_rescue_node_t *cast = (yp_rescue_node_t *) node; - for (size_t index = 0; index < cast->exceptions.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->exceptions.nodes[index]); - } - yp_node_stack_push(&node_stack, (yp_node_t *) cast->reference); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->consequent); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_RETURN_NODE: { - yp_return_node_t *cast = (yp_return_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->arguments); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_SINGLETON_CLASS_NODE: { - yp_singleton_class_node_t *cast = (yp_singleton_class_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->expression); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_SPLAT_NODE: { - yp_splat_node_t *cast = (yp_splat_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->expression); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_STATEMENTS_NODE: { - yp_statements_node_t *cast = (yp_statements_node_t *) node; - for (size_t index = 0; index < cast->body.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->body.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_STRING_CONCAT_NODE: { - yp_string_concat_node_t *cast = (yp_string_concat_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->left); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->right); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_SUPER_NODE: { - yp_super_node_t *cast = (yp_super_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->arguments); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->block); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_UNDEF_NODE: { - yp_undef_node_t *cast = (yp_undef_node_t *) node; - for (size_t index = 0; index < cast->names.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->names.nodes[index]); - } - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_UNLESS_NODE: { - yp_unless_node_t *cast = (yp_unless_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->predicate); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->consequent); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_UNTIL_NODE: { - yp_until_node_t *cast = (yp_until_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->predicate); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_WHEN_NODE: { - yp_when_node_t *cast = (yp_when_node_t *) node; - for (size_t index = 0; index < cast->conditions.size; index++) { - yp_node_stack_push(&node_stack, (yp_node_t *) cast->conditions.nodes[index]); - } - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_WHILE_NODE: { - yp_while_node_t *cast = (yp_while_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->predicate); - yp_node_stack_push(&node_stack, (yp_node_t *) cast->statements); - break; - } -#line 111 "api_node.c.erb" - case YP_NODE_YIELD_NODE: { - yp_yield_node_t *cast = (yp_yield_node_t *) node; - yp_node_stack_push(&node_stack, (yp_node_t *) cast->arguments); - break; - } - default: - break; - } -#line 131 "api_node.c.erb" - } else { - yp_node_t *node = yp_node_stack_pop(&node_stack); - - switch (YP_NODE_TYPE(node)) { -#line 137 "api_node.c.erb" - case YP_NODE_ALIAS_NODE: { - yp_alias_node_t *cast = (yp_alias_node_t *) node; - VALUE argv[4]; - - // new_name - argv[0] = rb_ary_pop(value_stack); - - // old_name - argv[1] = rb_ary_pop(value_stack); - - // keyword_loc - argv[2] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPAliasNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_ALTERNATION_PATTERN_NODE: { - yp_alternation_pattern_node_t *cast = (yp_alternation_pattern_node_t *) node; - VALUE argv[4]; - - // left - argv[0] = rb_ary_pop(value_stack); - - // right - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPAlternationPatternNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_AND_NODE: { - yp_and_node_t *cast = (yp_and_node_t *) node; - VALUE argv[4]; - - // left - argv[0] = rb_ary_pop(value_stack); - - // right - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPAndNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_ARGUMENTS_NODE: { - yp_arguments_node_t *cast = (yp_arguments_node_t *) node; - VALUE argv[2]; - - // arguments - argv[0] = rb_ary_new_capa(cast->arguments.size); - for (size_t index = 0; index < cast->arguments.size; index++) { - rb_ary_push(argv[0], rb_ary_pop(value_stack)); - } - - // location - argv[1] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPArgumentsNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_ARRAY_NODE: { - yp_array_node_t *cast = (yp_array_node_t *) node; - VALUE argv[4]; - - // elements - argv[0] = rb_ary_new_capa(cast->elements.size); - for (size_t index = 0; index < cast->elements.size; index++) { - rb_ary_push(argv[0], rb_ary_pop(value_stack)); - } - - // opening_loc - argv[1] = cast->opening_loc.start == NULL ? Qnil : yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // closing_loc - argv[2] = cast->closing_loc.start == NULL ? Qnil : yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPArrayNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_ARRAY_PATTERN_NODE: { - yp_array_pattern_node_t *cast = (yp_array_pattern_node_t *) node; - VALUE argv[7]; - - // constant - argv[0] = rb_ary_pop(value_stack); - - // requireds - argv[1] = rb_ary_new_capa(cast->requireds.size); - for (size_t index = 0; index < cast->requireds.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // rest - argv[2] = rb_ary_pop(value_stack); - - // posts - argv[3] = rb_ary_new_capa(cast->posts.size); - for (size_t index = 0; index < cast->posts.size; index++) { - rb_ary_push(argv[3], rb_ary_pop(value_stack)); - } - - // opening_loc - argv[4] = cast->opening_loc.start == NULL ? Qnil : yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // closing_loc - argv[5] = cast->closing_loc.start == NULL ? Qnil : yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[6] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(7, argv, rb_cYARPArrayPatternNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_ASSOC_NODE: { - yp_assoc_node_t *cast = (yp_assoc_node_t *) node; - VALUE argv[4]; - - // key - argv[0] = rb_ary_pop(value_stack); - - // value - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPAssocNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_ASSOC_SPLAT_NODE: { - yp_assoc_splat_node_t *cast = (yp_assoc_splat_node_t *) node; - VALUE argv[3]; - - // value - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPAssocSplatNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_BACK_REFERENCE_READ_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPBackReferenceReadNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_BEGIN_NODE: { - yp_begin_node_t *cast = (yp_begin_node_t *) node; - VALUE argv[7]; - - // begin_keyword_loc - argv[0] = cast->begin_keyword_loc.start == NULL ? Qnil : yp_location_new(parser, cast->begin_keyword_loc.start, cast->begin_keyword_loc.end, source); - - // statements - argv[1] = rb_ary_pop(value_stack); - - // rescue_clause - argv[2] = rb_ary_pop(value_stack); - - // else_clause - argv[3] = rb_ary_pop(value_stack); - - // ensure_clause - argv[4] = rb_ary_pop(value_stack); - - // end_keyword_loc - argv[5] = cast->end_keyword_loc.start == NULL ? Qnil : yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[6] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(7, argv, rb_cYARPBeginNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_BLOCK_ARGUMENT_NODE: { - yp_block_argument_node_t *cast = (yp_block_argument_node_t *) node; - VALUE argv[3]; - - // expression - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPBlockArgumentNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_BLOCK_NODE: { - yp_block_node_t *cast = (yp_block_node_t *) node; - VALUE argv[6]; - - // locals - argv[0] = rb_ary_new_capa(cast->locals.size); - for (size_t index = 0; index < cast->locals.size; index++) { - rb_ary_push(argv[0], rb_id2sym(constants[cast->locals.ids[index] - 1])); - } - - // parameters - argv[1] = rb_ary_pop(value_stack); - - // statements - argv[2] = rb_ary_pop(value_stack); - - // opening_loc - argv[3] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // closing_loc - argv[4] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPBlockNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_BLOCK_PARAMETER_NODE: { - yp_block_parameter_node_t *cast = (yp_block_parameter_node_t *) node; - VALUE argv[3]; - - // name_loc - argv[0] = cast->name_loc.start == NULL ? Qnil : yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPBlockParameterNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_BLOCK_PARAMETERS_NODE: { - yp_block_parameters_node_t *cast = (yp_block_parameters_node_t *) node; - VALUE argv[5]; - - // parameters - argv[0] = rb_ary_pop(value_stack); - - // locals - argv[1] = rb_ary_new_capa(cast->locals.size); - for (size_t index = 0; index < cast->locals.size; index++) { - yp_location_t location = cast->locals.locations[index]; - rb_ary_push(argv[1], yp_location_new(parser, location.start, location.end, source)); - } - - // opening_loc - argv[2] = cast->opening_loc.start == NULL ? Qnil : yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // closing_loc - argv[3] = cast->closing_loc.start == NULL ? Qnil : yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPBlockParametersNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_BREAK_NODE: { - yp_break_node_t *cast = (yp_break_node_t *) node; - VALUE argv[3]; - - // arguments - argv[0] = rb_ary_pop(value_stack); - - // keyword_loc - argv[1] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPBreakNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CALL_NODE: { - yp_call_node_t *cast = (yp_call_node_t *) node; - VALUE argv[10]; - - // receiver - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // message_loc - argv[2] = cast->message_loc.start == NULL ? Qnil : yp_location_new(parser, cast->message_loc.start, cast->message_loc.end, source); - - // opening_loc - argv[3] = cast->opening_loc.start == NULL ? Qnil : yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // arguments - argv[4] = rb_ary_pop(value_stack); - - // closing_loc - argv[5] = cast->closing_loc.start == NULL ? Qnil : yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // block - argv[6] = rb_ary_pop(value_stack); - - // flags - argv[7] = ULONG2NUM(node->flags >> 1); - - // name - argv[8] = yp_string_new(&cast->name, encoding); - - // location - argv[9] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(10, argv, rb_cYARPCallNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CALL_OPERATOR_AND_WRITE_NODE: { - yp_call_operator_and_write_node_t *cast = (yp_call_operator_and_write_node_t *) node; - VALUE argv[4]; - - // target - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPCallOperatorAndWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CALL_OPERATOR_OR_WRITE_NODE: { - yp_call_operator_or_write_node_t *cast = (yp_call_operator_or_write_node_t *) node; - VALUE argv[4]; - - // target - argv[0] = rb_ary_pop(value_stack); - - // value - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPCallOperatorOrWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CALL_OPERATOR_WRITE_NODE: { - yp_call_operator_write_node_t *cast = (yp_call_operator_write_node_t *) node; - VALUE argv[5]; - - // target - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // operator_id - argv[3] = rb_id2sym(constants[cast->operator_id - 1]); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPCallOperatorWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CAPTURE_PATTERN_NODE: { - yp_capture_pattern_node_t *cast = (yp_capture_pattern_node_t *) node; - VALUE argv[4]; - - // value - argv[0] = rb_ary_pop(value_stack); - - // target - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPCapturePatternNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CASE_NODE: { - yp_case_node_t *cast = (yp_case_node_t *) node; - VALUE argv[6]; - - // predicate - argv[0] = rb_ary_pop(value_stack); - - // conditions - argv[1] = rb_ary_new_capa(cast->conditions.size); - for (size_t index = 0; index < cast->conditions.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // consequent - argv[2] = rb_ary_pop(value_stack); - - // case_keyword_loc - argv[3] = yp_location_new(parser, cast->case_keyword_loc.start, cast->case_keyword_loc.end, source); - - // end_keyword_loc - argv[4] = yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPCaseNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CLASS_NODE: { - yp_class_node_t *cast = (yp_class_node_t *) node; - VALUE argv[8]; - - // locals - argv[0] = rb_ary_new_capa(cast->locals.size); - for (size_t index = 0; index < cast->locals.size; index++) { - rb_ary_push(argv[0], rb_id2sym(constants[cast->locals.ids[index] - 1])); - } - - // class_keyword_loc - argv[1] = yp_location_new(parser, cast->class_keyword_loc.start, cast->class_keyword_loc.end, source); - - // constant_path - argv[2] = rb_ary_pop(value_stack); - - // inheritance_operator_loc - argv[3] = cast->inheritance_operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->inheritance_operator_loc.start, cast->inheritance_operator_loc.end, source); - - // superclass - argv[4] = rb_ary_pop(value_stack); - - // statements - argv[5] = rb_ary_pop(value_stack); - - // end_keyword_loc - argv[6] = yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[7] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(8, argv, rb_cYARPClassNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_class_variable_operator_and_write_node_t *cast = (yp_class_variable_operator_and_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPClassVariableOperatorAndWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_class_variable_operator_or_write_node_t *cast = (yp_class_variable_operator_or_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPClassVariableOperatorOrWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: { - yp_class_variable_operator_write_node_t *cast = (yp_class_variable_operator_write_node_t *) node; - VALUE argv[5]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // operator - argv[3] = rb_id2sym(constants[cast->operator - 1]); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPClassVariableOperatorWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CLASS_VARIABLE_READ_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPClassVariableReadNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CLASS_VARIABLE_WRITE_NODE: { - yp_class_variable_write_node_t *cast = (yp_class_variable_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // value - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPClassVariableWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE: { - yp_constant_operator_and_write_node_t *cast = (yp_constant_operator_and_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPConstantOperatorAndWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE: { - yp_constant_operator_or_write_node_t *cast = (yp_constant_operator_or_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPConstantOperatorOrWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_WRITE_NODE: { - yp_constant_operator_write_node_t *cast = (yp_constant_operator_write_node_t *) node; - VALUE argv[5]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // operator - argv[3] = rb_id2sym(constants[cast->operator - 1]); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPConstantOperatorWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CONSTANT_PATH_NODE: { - yp_constant_path_node_t *cast = (yp_constant_path_node_t *) node; - VALUE argv[4]; - - // parent - argv[0] = rb_ary_pop(value_stack); - - // child - argv[1] = rb_ary_pop(value_stack); - - // delimiter_loc - argv[2] = yp_location_new(parser, cast->delimiter_loc.start, cast->delimiter_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPConstantPathNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE: { - yp_constant_path_operator_and_write_node_t *cast = (yp_constant_path_operator_and_write_node_t *) node; - VALUE argv[4]; - - // target - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPConstantPathOperatorAndWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE: { - yp_constant_path_operator_or_write_node_t *cast = (yp_constant_path_operator_or_write_node_t *) node; - VALUE argv[4]; - - // target - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPConstantPathOperatorOrWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE: { - yp_constant_path_operator_write_node_t *cast = (yp_constant_path_operator_write_node_t *) node; - VALUE argv[5]; - - // target - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // operator - argv[3] = rb_id2sym(constants[cast->operator - 1]); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPConstantPathOperatorWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CONSTANT_PATH_WRITE_NODE: { - yp_constant_path_write_node_t *cast = (yp_constant_path_write_node_t *) node; - VALUE argv[4]; - - // target - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPConstantPathWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CONSTANT_READ_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPConstantReadNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_CONSTANT_WRITE_NODE: { - yp_constant_write_node_t *cast = (yp_constant_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // value - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPConstantWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_DEF_NODE: { - yp_def_node_t *cast = (yp_def_node_t *) node; - VALUE argv[12]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // receiver - argv[1] = rb_ary_pop(value_stack); - - // parameters - argv[2] = rb_ary_pop(value_stack); - - // statements - argv[3] = rb_ary_pop(value_stack); - - // locals - argv[4] = rb_ary_new_capa(cast->locals.size); - for (size_t index = 0; index < cast->locals.size; index++) { - rb_ary_push(argv[4], rb_id2sym(constants[cast->locals.ids[index] - 1])); - } - - // def_keyword_loc - argv[5] = yp_location_new(parser, cast->def_keyword_loc.start, cast->def_keyword_loc.end, source); - - // operator_loc - argv[6] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // lparen_loc - argv[7] = cast->lparen_loc.start == NULL ? Qnil : yp_location_new(parser, cast->lparen_loc.start, cast->lparen_loc.end, source); - - // rparen_loc - argv[8] = cast->rparen_loc.start == NULL ? Qnil : yp_location_new(parser, cast->rparen_loc.start, cast->rparen_loc.end, source); - - // equal_loc - argv[9] = cast->equal_loc.start == NULL ? Qnil : yp_location_new(parser, cast->equal_loc.start, cast->equal_loc.end, source); - - // end_keyword_loc - argv[10] = cast->end_keyword_loc.start == NULL ? Qnil : yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[11] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(12, argv, rb_cYARPDefNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_DEFINED_NODE: { - yp_defined_node_t *cast = (yp_defined_node_t *) node; - VALUE argv[5]; - - // lparen_loc - argv[0] = cast->lparen_loc.start == NULL ? Qnil : yp_location_new(parser, cast->lparen_loc.start, cast->lparen_loc.end, source); - - // value - argv[1] = rb_ary_pop(value_stack); - - // rparen_loc - argv[2] = cast->rparen_loc.start == NULL ? Qnil : yp_location_new(parser, cast->rparen_loc.start, cast->rparen_loc.end, source); - - // keyword_loc - argv[3] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPDefinedNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_ELSE_NODE: { - yp_else_node_t *cast = (yp_else_node_t *) node; - VALUE argv[4]; - - // else_keyword_loc - argv[0] = yp_location_new(parser, cast->else_keyword_loc.start, cast->else_keyword_loc.end, source); - - // statements - argv[1] = rb_ary_pop(value_stack); - - // end_keyword_loc - argv[2] = cast->end_keyword_loc.start == NULL ? Qnil : yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPElseNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_EMBEDDED_STATEMENTS_NODE: { - yp_embedded_statements_node_t *cast = (yp_embedded_statements_node_t *) node; - VALUE argv[4]; - - // opening_loc - argv[0] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // statements - argv[1] = rb_ary_pop(value_stack); - - // closing_loc - argv[2] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPEmbeddedStatementsNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_EMBEDDED_VARIABLE_NODE: { - yp_embedded_variable_node_t *cast = (yp_embedded_variable_node_t *) node; - VALUE argv[3]; - - // operator_loc - argv[0] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // variable - argv[1] = rb_ary_pop(value_stack); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPEmbeddedVariableNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_ENSURE_NODE: { - yp_ensure_node_t *cast = (yp_ensure_node_t *) node; - VALUE argv[4]; - - // ensure_keyword_loc - argv[0] = yp_location_new(parser, cast->ensure_keyword_loc.start, cast->ensure_keyword_loc.end, source); - - // statements - argv[1] = rb_ary_pop(value_stack); - - // end_keyword_loc - argv[2] = yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPEnsureNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_FALSE_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPFalseNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_FIND_PATTERN_NODE: { - yp_find_pattern_node_t *cast = (yp_find_pattern_node_t *) node; - VALUE argv[7]; - - // constant - argv[0] = rb_ary_pop(value_stack); - - // left - argv[1] = rb_ary_pop(value_stack); - - // requireds - argv[2] = rb_ary_new_capa(cast->requireds.size); - for (size_t index = 0; index < cast->requireds.size; index++) { - rb_ary_push(argv[2], rb_ary_pop(value_stack)); - } - - // right - argv[3] = rb_ary_pop(value_stack); - - // opening_loc - argv[4] = cast->opening_loc.start == NULL ? Qnil : yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // closing_loc - argv[5] = cast->closing_loc.start == NULL ? Qnil : yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[6] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(7, argv, rb_cYARPFindPatternNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_FLIP_FLOP_NODE: { - yp_flip_flop_node_t *cast = (yp_flip_flop_node_t *) node; - VALUE argv[5]; - - // left - argv[0] = rb_ary_pop(value_stack); - - // right - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // flags - argv[3] = ULONG2NUM(node->flags >> 1); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPFlipFlopNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_FLOAT_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPFloatNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_FOR_NODE: { - yp_for_node_t *cast = (yp_for_node_t *) node; - VALUE argv[8]; - - // index - argv[0] = rb_ary_pop(value_stack); - - // collection - argv[1] = rb_ary_pop(value_stack); - - // statements - argv[2] = rb_ary_pop(value_stack); - - // for_keyword_loc - argv[3] = yp_location_new(parser, cast->for_keyword_loc.start, cast->for_keyword_loc.end, source); - - // in_keyword_loc - argv[4] = yp_location_new(parser, cast->in_keyword_loc.start, cast->in_keyword_loc.end, source); - - // do_keyword_loc - argv[5] = cast->do_keyword_loc.start == NULL ? Qnil : yp_location_new(parser, cast->do_keyword_loc.start, cast->do_keyword_loc.end, source); - - // end_keyword_loc - argv[6] = yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[7] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(8, argv, rb_cYARPForNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_FORWARDING_ARGUMENTS_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPForwardingArgumentsNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_FORWARDING_PARAMETER_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPForwardingParameterNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_FORWARDING_SUPER_NODE: { - VALUE argv[2]; - - // block - argv[0] = rb_ary_pop(value_stack); - - // location - argv[1] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPForwardingSuperNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_global_variable_operator_and_write_node_t *cast = (yp_global_variable_operator_and_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPGlobalVariableOperatorAndWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_global_variable_operator_or_write_node_t *cast = (yp_global_variable_operator_or_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPGlobalVariableOperatorOrWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: { - yp_global_variable_operator_write_node_t *cast = (yp_global_variable_operator_write_node_t *) node; - VALUE argv[5]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // operator - argv[3] = rb_id2sym(constants[cast->operator - 1]); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPGlobalVariableOperatorWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPGlobalVariableReadNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: { - yp_global_variable_write_node_t *cast = (yp_global_variable_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPGlobalVariableWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_HASH_NODE: { - yp_hash_node_t *cast = (yp_hash_node_t *) node; - VALUE argv[4]; - - // opening_loc - argv[0] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // elements - argv[1] = rb_ary_new_capa(cast->elements.size); - for (size_t index = 0; index < cast->elements.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // closing_loc - argv[2] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPHashNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_HASH_PATTERN_NODE: { - yp_hash_pattern_node_t *cast = (yp_hash_pattern_node_t *) node; - VALUE argv[6]; - - // constant - argv[0] = rb_ary_pop(value_stack); - - // assocs - argv[1] = rb_ary_new_capa(cast->assocs.size); - for (size_t index = 0; index < cast->assocs.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // kwrest - argv[2] = rb_ary_pop(value_stack); - - // opening_loc - argv[3] = cast->opening_loc.start == NULL ? Qnil : yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // closing_loc - argv[4] = cast->closing_loc.start == NULL ? Qnil : yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPHashPatternNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_IF_NODE: { - yp_if_node_t *cast = (yp_if_node_t *) node; - VALUE argv[6]; - - // if_keyword_loc - argv[0] = cast->if_keyword_loc.start == NULL ? Qnil : yp_location_new(parser, cast->if_keyword_loc.start, cast->if_keyword_loc.end, source); - - // predicate - argv[1] = rb_ary_pop(value_stack); - - // statements - argv[2] = rb_ary_pop(value_stack); - - // consequent - argv[3] = rb_ary_pop(value_stack); - - // end_keyword_loc - argv[4] = cast->end_keyword_loc.start == NULL ? Qnil : yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPIfNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_IMAGINARY_NODE: { - VALUE argv[2]; - - // numeric - argv[0] = rb_ary_pop(value_stack); - - // location - argv[1] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPImaginaryNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_IN_NODE: { - yp_in_node_t *cast = (yp_in_node_t *) node; - VALUE argv[5]; - - // pattern - argv[0] = rb_ary_pop(value_stack); - - // statements - argv[1] = rb_ary_pop(value_stack); - - // in_loc - argv[2] = yp_location_new(parser, cast->in_loc.start, cast->in_loc.end, source); - - // then_loc - argv[3] = cast->then_loc.start == NULL ? Qnil : yp_location_new(parser, cast->then_loc.start, cast->then_loc.end, source); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPInNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_instance_variable_operator_and_write_node_t *cast = (yp_instance_variable_operator_and_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPInstanceVariableOperatorAndWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_instance_variable_operator_or_write_node_t *cast = (yp_instance_variable_operator_or_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPInstanceVariableOperatorOrWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: { - yp_instance_variable_operator_write_node_t *cast = (yp_instance_variable_operator_write_node_t *) node; - VALUE argv[5]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // operator - argv[3] = rb_id2sym(constants[cast->operator - 1]); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPInstanceVariableOperatorWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPInstanceVariableReadNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: { - yp_instance_variable_write_node_t *cast = (yp_instance_variable_write_node_t *) node; - VALUE argv[4]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // value - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPInstanceVariableWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_INTEGER_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPIntegerNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE: { - yp_interpolated_regular_expression_node_t *cast = (yp_interpolated_regular_expression_node_t *) node; - VALUE argv[5]; - - // opening_loc - argv[0] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // parts - argv[1] = rb_ary_new_capa(cast->parts.size); - for (size_t index = 0; index < cast->parts.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // closing_loc - argv[2] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // flags - argv[3] = ULONG2NUM(node->flags >> 1); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPInterpolatedRegularExpressionNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_INTERPOLATED_STRING_NODE: { - yp_interpolated_string_node_t *cast = (yp_interpolated_string_node_t *) node; - VALUE argv[4]; - - // opening_loc - argv[0] = cast->opening_loc.start == NULL ? Qnil : yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // parts - argv[1] = rb_ary_new_capa(cast->parts.size); - for (size_t index = 0; index < cast->parts.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // closing_loc - argv[2] = cast->closing_loc.start == NULL ? Qnil : yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPInterpolatedStringNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_INTERPOLATED_SYMBOL_NODE: { - yp_interpolated_symbol_node_t *cast = (yp_interpolated_symbol_node_t *) node; - VALUE argv[4]; - - // opening_loc - argv[0] = cast->opening_loc.start == NULL ? Qnil : yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // parts - argv[1] = rb_ary_new_capa(cast->parts.size); - for (size_t index = 0; index < cast->parts.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // closing_loc - argv[2] = cast->closing_loc.start == NULL ? Qnil : yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPInterpolatedSymbolNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_INTERPOLATED_X_STRING_NODE: { - yp_interpolated_x_string_node_t *cast = (yp_interpolated_x_string_node_t *) node; - VALUE argv[4]; - - // opening_loc - argv[0] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // parts - argv[1] = rb_ary_new_capa(cast->parts.size); - for (size_t index = 0; index < cast->parts.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // closing_loc - argv[2] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPInterpolatedXStringNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_KEYWORD_HASH_NODE: { - yp_keyword_hash_node_t *cast = (yp_keyword_hash_node_t *) node; - VALUE argv[2]; - - // elements - argv[0] = rb_ary_new_capa(cast->elements.size); - for (size_t index = 0; index < cast->elements.size; index++) { - rb_ary_push(argv[0], rb_ary_pop(value_stack)); - } - - // location - argv[1] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPKeywordHashNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_KEYWORD_PARAMETER_NODE: { - yp_keyword_parameter_node_t *cast = (yp_keyword_parameter_node_t *) node; - VALUE argv[3]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // value - argv[1] = rb_ary_pop(value_stack); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPKeywordParameterNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_KEYWORD_REST_PARAMETER_NODE: { - yp_keyword_rest_parameter_node_t *cast = (yp_keyword_rest_parameter_node_t *) node; - VALUE argv[3]; - - // operator_loc - argv[0] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // name_loc - argv[1] = cast->name_loc.start == NULL ? Qnil : yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPKeywordRestParameterNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_LAMBDA_NODE: { - yp_lambda_node_t *cast = (yp_lambda_node_t *) node; - VALUE argv[5]; - - // locals - argv[0] = rb_ary_new_capa(cast->locals.size); - for (size_t index = 0; index < cast->locals.size; index++) { - rb_ary_push(argv[0], rb_id2sym(constants[cast->locals.ids[index] - 1])); - } - - // opening_loc - argv[1] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // parameters - argv[2] = rb_ary_pop(value_stack); - - // statements - argv[3] = rb_ary_pop(value_stack); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPLambdaNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_local_variable_operator_and_write_node_t *cast = (yp_local_variable_operator_and_write_node_t *) node; - VALUE argv[5]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // constant_id - argv[3] = rb_id2sym(constants[cast->constant_id - 1]); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPLocalVariableOperatorAndWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_local_variable_operator_or_write_node_t *cast = (yp_local_variable_operator_or_write_node_t *) node; - VALUE argv[5]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // constant_id - argv[3] = rb_id2sym(constants[cast->constant_id - 1]); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPLocalVariableOperatorOrWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: { - yp_local_variable_operator_write_node_t *cast = (yp_local_variable_operator_write_node_t *) node; - VALUE argv[6]; - - // name_loc - argv[0] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // constant_id - argv[3] = rb_id2sym(constants[cast->constant_id - 1]); - - // operator_id - argv[4] = rb_id2sym(constants[cast->operator_id - 1]); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPLocalVariableOperatorWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_LOCAL_VARIABLE_READ_NODE: { - yp_local_variable_read_node_t *cast = (yp_local_variable_read_node_t *) node; - VALUE argv[3]; - - // constant_id - argv[0] = rb_id2sym(constants[cast->constant_id - 1]); - - // depth - argv[1] = ULONG2NUM(cast->depth); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPLocalVariableReadNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: { - yp_local_variable_write_node_t *cast = (yp_local_variable_write_node_t *) node; - VALUE argv[6]; - - // constant_id - argv[0] = rb_id2sym(constants[cast->constant_id - 1]); - - // depth - argv[1] = ULONG2NUM(cast->depth); - - // value - argv[2] = rb_ary_pop(value_stack); - - // name_loc - argv[3] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[4] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPLocalVariableWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_MATCH_PREDICATE_NODE: { - yp_match_predicate_node_t *cast = (yp_match_predicate_node_t *) node; - VALUE argv[4]; - - // value - argv[0] = rb_ary_pop(value_stack); - - // pattern - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPMatchPredicateNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_MATCH_REQUIRED_NODE: { - yp_match_required_node_t *cast = (yp_match_required_node_t *) node; - VALUE argv[4]; - - // value - argv[0] = rb_ary_pop(value_stack); - - // pattern - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPMatchRequiredNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_MISSING_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPMissingNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_MODULE_NODE: { - yp_module_node_t *cast = (yp_module_node_t *) node; - VALUE argv[6]; - - // locals - argv[0] = rb_ary_new_capa(cast->locals.size); - for (size_t index = 0; index < cast->locals.size; index++) { - rb_ary_push(argv[0], rb_id2sym(constants[cast->locals.ids[index] - 1])); - } - - // module_keyword_loc - argv[1] = yp_location_new(parser, cast->module_keyword_loc.start, cast->module_keyword_loc.end, source); - - // constant_path - argv[2] = rb_ary_pop(value_stack); - - // statements - argv[3] = rb_ary_pop(value_stack); - - // end_keyword_loc - argv[4] = yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPModuleNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_MULTI_WRITE_NODE: { - yp_multi_write_node_t *cast = (yp_multi_write_node_t *) node; - VALUE argv[6]; - - // targets - argv[0] = rb_ary_new_capa(cast->targets.size); - for (size_t index = 0; index < cast->targets.size; index++) { - rb_ary_push(argv[0], rb_ary_pop(value_stack)); - } - - // operator_loc - argv[1] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[2] = rb_ary_pop(value_stack); - - // lparen_loc - argv[3] = cast->lparen_loc.start == NULL ? Qnil : yp_location_new(parser, cast->lparen_loc.start, cast->lparen_loc.end, source); - - // rparen_loc - argv[4] = cast->rparen_loc.start == NULL ? Qnil : yp_location_new(parser, cast->rparen_loc.start, cast->rparen_loc.end, source); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPMultiWriteNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_NEXT_NODE: { - yp_next_node_t *cast = (yp_next_node_t *) node; - VALUE argv[3]; - - // arguments - argv[0] = rb_ary_pop(value_stack); - - // keyword_loc - argv[1] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPNextNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_NIL_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPNilNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_NO_KEYWORDS_PARAMETER_NODE: { - yp_no_keywords_parameter_node_t *cast = (yp_no_keywords_parameter_node_t *) node; - VALUE argv[3]; - - // operator_loc - argv[0] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // keyword_loc - argv[1] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPNoKeywordsParameterNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPNumberedReferenceReadNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_OPTIONAL_PARAMETER_NODE: { - yp_optional_parameter_node_t *cast = (yp_optional_parameter_node_t *) node; - VALUE argv[5]; - - // constant_id - argv[0] = rb_id2sym(constants[cast->constant_id - 1]); - - // name_loc - argv[1] = yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // value - argv[3] = rb_ary_pop(value_stack); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPOptionalParameterNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_OR_NODE: { - yp_or_node_t *cast = (yp_or_node_t *) node; - VALUE argv[4]; - - // left - argv[0] = rb_ary_pop(value_stack); - - // right - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPOrNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_PARAMETERS_NODE: { - yp_parameters_node_t *cast = (yp_parameters_node_t *) node; - VALUE argv[8]; - - // requireds - argv[0] = rb_ary_new_capa(cast->requireds.size); - for (size_t index = 0; index < cast->requireds.size; index++) { - rb_ary_push(argv[0], rb_ary_pop(value_stack)); - } - - // optionals - argv[1] = rb_ary_new_capa(cast->optionals.size); - for (size_t index = 0; index < cast->optionals.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // posts - argv[2] = rb_ary_new_capa(cast->posts.size); - for (size_t index = 0; index < cast->posts.size; index++) { - rb_ary_push(argv[2], rb_ary_pop(value_stack)); - } - - // rest - argv[3] = rb_ary_pop(value_stack); - - // keywords - argv[4] = rb_ary_new_capa(cast->keywords.size); - for (size_t index = 0; index < cast->keywords.size; index++) { - rb_ary_push(argv[4], rb_ary_pop(value_stack)); - } - - // keyword_rest - argv[5] = rb_ary_pop(value_stack); - - // block - argv[6] = rb_ary_pop(value_stack); - - // location - argv[7] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(8, argv, rb_cYARPParametersNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_PARENTHESES_NODE: { - yp_parentheses_node_t *cast = (yp_parentheses_node_t *) node; - VALUE argv[4]; - - // statements - argv[0] = rb_ary_pop(value_stack); - - // opening_loc - argv[1] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // closing_loc - argv[2] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPParenthesesNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_PINNED_EXPRESSION_NODE: { - yp_pinned_expression_node_t *cast = (yp_pinned_expression_node_t *) node; - VALUE argv[5]; - - // expression - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // lparen_loc - argv[2] = yp_location_new(parser, cast->lparen_loc.start, cast->lparen_loc.end, source); - - // rparen_loc - argv[3] = yp_location_new(parser, cast->rparen_loc.start, cast->rparen_loc.end, source); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPPinnedExpressionNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_PINNED_VARIABLE_NODE: { - yp_pinned_variable_node_t *cast = (yp_pinned_variable_node_t *) node; - VALUE argv[3]; - - // variable - argv[0] = rb_ary_pop(value_stack); - - // operator_loc - argv[1] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPPinnedVariableNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_POST_EXECUTION_NODE: { - yp_post_execution_node_t *cast = (yp_post_execution_node_t *) node; - VALUE argv[5]; - - // statements - argv[0] = rb_ary_pop(value_stack); - - // keyword_loc - argv[1] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // opening_loc - argv[2] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // closing_loc - argv[3] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPPostExecutionNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_PRE_EXECUTION_NODE: { - yp_pre_execution_node_t *cast = (yp_pre_execution_node_t *) node; - VALUE argv[5]; - - // statements - argv[0] = rb_ary_pop(value_stack); - - // keyword_loc - argv[1] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // opening_loc - argv[2] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // closing_loc - argv[3] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPPreExecutionNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_PROGRAM_NODE: { - yp_program_node_t *cast = (yp_program_node_t *) node; - VALUE argv[3]; - - // locals - argv[0] = rb_ary_new_capa(cast->locals.size); - for (size_t index = 0; index < cast->locals.size; index++) { - rb_ary_push(argv[0], rb_id2sym(constants[cast->locals.ids[index] - 1])); - } - - // statements - argv[1] = rb_ary_pop(value_stack); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPProgramNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_RANGE_NODE: { - yp_range_node_t *cast = (yp_range_node_t *) node; - VALUE argv[5]; - - // left - argv[0] = rb_ary_pop(value_stack); - - // right - argv[1] = rb_ary_pop(value_stack); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // flags - argv[3] = ULONG2NUM(node->flags >> 1); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPRangeNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_RATIONAL_NODE: { - VALUE argv[2]; - - // numeric - argv[0] = rb_ary_pop(value_stack); - - // location - argv[1] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPRationalNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_REDO_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPRedoNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_REGULAR_EXPRESSION_NODE: { - yp_regular_expression_node_t *cast = (yp_regular_expression_node_t *) node; - VALUE argv[6]; - - // opening_loc - argv[0] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // content_loc - argv[1] = yp_location_new(parser, cast->content_loc.start, cast->content_loc.end, source); - - // closing_loc - argv[2] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // unescaped - argv[3] = yp_string_new(&cast->unescaped, encoding); - - // flags - argv[4] = ULONG2NUM(node->flags >> 1); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPRegularExpressionNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE: { - yp_required_destructured_parameter_node_t *cast = (yp_required_destructured_parameter_node_t *) node; - VALUE argv[4]; - - // parameters - argv[0] = rb_ary_new_capa(cast->parameters.size); - for (size_t index = 0; index < cast->parameters.size; index++) { - rb_ary_push(argv[0], rb_ary_pop(value_stack)); - } - - // opening_loc - argv[1] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // closing_loc - argv[2] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPRequiredDestructuredParameterNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_REQUIRED_PARAMETER_NODE: { - yp_required_parameter_node_t *cast = (yp_required_parameter_node_t *) node; - VALUE argv[2]; - - // constant_id - argv[0] = rb_id2sym(constants[cast->constant_id - 1]); - - // location - argv[1] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPRequiredParameterNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_RESCUE_MODIFIER_NODE: { - yp_rescue_modifier_node_t *cast = (yp_rescue_modifier_node_t *) node; - VALUE argv[4]; - - // expression - argv[0] = rb_ary_pop(value_stack); - - // keyword_loc - argv[1] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // rescue_expression - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPRescueModifierNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_RESCUE_NODE: { - yp_rescue_node_t *cast = (yp_rescue_node_t *) node; - VALUE argv[7]; - - // keyword_loc - argv[0] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // exceptions - argv[1] = rb_ary_new_capa(cast->exceptions.size); - for (size_t index = 0; index < cast->exceptions.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // operator_loc - argv[2] = cast->operator_loc.start == NULL ? Qnil : yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // reference - argv[3] = rb_ary_pop(value_stack); - - // statements - argv[4] = rb_ary_pop(value_stack); - - // consequent - argv[5] = rb_ary_pop(value_stack); - - // location - argv[6] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(7, argv, rb_cYARPRescueNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_REST_PARAMETER_NODE: { - yp_rest_parameter_node_t *cast = (yp_rest_parameter_node_t *) node; - VALUE argv[3]; - - // operator_loc - argv[0] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // name_loc - argv[1] = cast->name_loc.start == NULL ? Qnil : yp_location_new(parser, cast->name_loc.start, cast->name_loc.end, source); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPRestParameterNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_RETRY_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPRetryNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_RETURN_NODE: { - yp_return_node_t *cast = (yp_return_node_t *) node; - VALUE argv[3]; - - // keyword_loc - argv[0] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // arguments - argv[1] = rb_ary_pop(value_stack); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPReturnNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_SELF_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPSelfNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_SINGLETON_CLASS_NODE: { - yp_singleton_class_node_t *cast = (yp_singleton_class_node_t *) node; - VALUE argv[7]; - - // locals - argv[0] = rb_ary_new_capa(cast->locals.size); - for (size_t index = 0; index < cast->locals.size; index++) { - rb_ary_push(argv[0], rb_id2sym(constants[cast->locals.ids[index] - 1])); - } - - // class_keyword_loc - argv[1] = yp_location_new(parser, cast->class_keyword_loc.start, cast->class_keyword_loc.end, source); - - // operator_loc - argv[2] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // expression - argv[3] = rb_ary_pop(value_stack); - - // statements - argv[4] = rb_ary_pop(value_stack); - - // end_keyword_loc - argv[5] = yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[6] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(7, argv, rb_cYARPSingletonClassNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_SOURCE_ENCODING_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPSourceEncodingNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_SOURCE_FILE_NODE: { - yp_source_file_node_t *cast = (yp_source_file_node_t *) node; - VALUE argv[2]; - - // filepath - argv[0] = yp_string_new(&cast->filepath, encoding); - - // location - argv[1] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPSourceFileNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_SOURCE_LINE_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPSourceLineNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_SPLAT_NODE: { - yp_splat_node_t *cast = (yp_splat_node_t *) node; - VALUE argv[3]; - - // operator_loc - argv[0] = yp_location_new(parser, cast->operator_loc.start, cast->operator_loc.end, source); - - // expression - argv[1] = rb_ary_pop(value_stack); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPSplatNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_STATEMENTS_NODE: { - yp_statements_node_t *cast = (yp_statements_node_t *) node; - VALUE argv[2]; - - // body - argv[0] = rb_ary_new_capa(cast->body.size); - for (size_t index = 0; index < cast->body.size; index++) { - rb_ary_push(argv[0], rb_ary_pop(value_stack)); - } - - // location - argv[1] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(2, argv, rb_cYARPStatementsNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_STRING_CONCAT_NODE: { - VALUE argv[3]; - - // left - argv[0] = rb_ary_pop(value_stack); - - // right - argv[1] = rb_ary_pop(value_stack); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPStringConcatNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_STRING_NODE: { - yp_string_node_t *cast = (yp_string_node_t *) node; - VALUE argv[5]; - - // opening_loc - argv[0] = cast->opening_loc.start == NULL ? Qnil : yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // content_loc - argv[1] = yp_location_new(parser, cast->content_loc.start, cast->content_loc.end, source); - - // closing_loc - argv[2] = cast->closing_loc.start == NULL ? Qnil : yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // unescaped - argv[3] = yp_string_new(&cast->unescaped, encoding); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPStringNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_SUPER_NODE: { - yp_super_node_t *cast = (yp_super_node_t *) node; - VALUE argv[6]; - - // keyword_loc - argv[0] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // lparen_loc - argv[1] = cast->lparen_loc.start == NULL ? Qnil : yp_location_new(parser, cast->lparen_loc.start, cast->lparen_loc.end, source); - - // arguments - argv[2] = rb_ary_pop(value_stack); - - // rparen_loc - argv[3] = cast->rparen_loc.start == NULL ? Qnil : yp_location_new(parser, cast->rparen_loc.start, cast->rparen_loc.end, source); - - // block - argv[4] = rb_ary_pop(value_stack); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPSuperNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_SYMBOL_NODE: { - yp_symbol_node_t *cast = (yp_symbol_node_t *) node; - VALUE argv[5]; - - // opening_loc - argv[0] = cast->opening_loc.start == NULL ? Qnil : yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // value_loc - argv[1] = yp_location_new(parser, cast->value_loc.start, cast->value_loc.end, source); - - // closing_loc - argv[2] = cast->closing_loc.start == NULL ? Qnil : yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // unescaped - argv[3] = yp_string_new(&cast->unescaped, encoding); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPSymbolNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_TRUE_NODE: { - VALUE argv[1]; - - // location - argv[0] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(1, argv, rb_cYARPTrueNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_UNDEF_NODE: { - yp_undef_node_t *cast = (yp_undef_node_t *) node; - VALUE argv[3]; - - // names - argv[0] = rb_ary_new_capa(cast->names.size); - for (size_t index = 0; index < cast->names.size; index++) { - rb_ary_push(argv[0], rb_ary_pop(value_stack)); - } - - // keyword_loc - argv[1] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // location - argv[2] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(3, argv, rb_cYARPUndefNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_UNLESS_NODE: { - yp_unless_node_t *cast = (yp_unless_node_t *) node; - VALUE argv[6]; - - // keyword_loc - argv[0] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // predicate - argv[1] = rb_ary_pop(value_stack); - - // statements - argv[2] = rb_ary_pop(value_stack); - - // consequent - argv[3] = rb_ary_pop(value_stack); - - // end_keyword_loc - argv[4] = cast->end_keyword_loc.start == NULL ? Qnil : yp_location_new(parser, cast->end_keyword_loc.start, cast->end_keyword_loc.end, source); - - // location - argv[5] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(6, argv, rb_cYARPUnlessNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_UNTIL_NODE: { - yp_until_node_t *cast = (yp_until_node_t *) node; - VALUE argv[5]; - - // keyword_loc - argv[0] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // predicate - argv[1] = rb_ary_pop(value_stack); - - // statements - argv[2] = rb_ary_pop(value_stack); - - // flags - argv[3] = ULONG2NUM(node->flags >> 1); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPUntilNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_WHEN_NODE: { - yp_when_node_t *cast = (yp_when_node_t *) node; - VALUE argv[4]; - - // keyword_loc - argv[0] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // conditions - argv[1] = rb_ary_new_capa(cast->conditions.size); - for (size_t index = 0; index < cast->conditions.size; index++) { - rb_ary_push(argv[1], rb_ary_pop(value_stack)); - } - - // statements - argv[2] = rb_ary_pop(value_stack); - - // location - argv[3] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(4, argv, rb_cYARPWhenNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_WHILE_NODE: { - yp_while_node_t *cast = (yp_while_node_t *) node; - VALUE argv[5]; - - // keyword_loc - argv[0] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // predicate - argv[1] = rb_ary_pop(value_stack); - - // statements - argv[2] = rb_ary_pop(value_stack); - - // flags - argv[3] = ULONG2NUM(node->flags >> 1); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPWhileNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_X_STRING_NODE: { - yp_x_string_node_t *cast = (yp_x_string_node_t *) node; - VALUE argv[5]; - - // opening_loc - argv[0] = yp_location_new(parser, cast->opening_loc.start, cast->opening_loc.end, source); - - // content_loc - argv[1] = yp_location_new(parser, cast->content_loc.start, cast->content_loc.end, source); - - // closing_loc - argv[2] = yp_location_new(parser, cast->closing_loc.start, cast->closing_loc.end, source); - - // unescaped - argv[3] = yp_string_new(&cast->unescaped, encoding); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPXStringNode)); - break; - } -#line 137 "api_node.c.erb" - case YP_NODE_YIELD_NODE: { - yp_yield_node_t *cast = (yp_yield_node_t *) node; - VALUE argv[5]; - - // keyword_loc - argv[0] = yp_location_new(parser, cast->keyword_loc.start, cast->keyword_loc.end, source); - - // lparen_loc - argv[1] = cast->lparen_loc.start == NULL ? Qnil : yp_location_new(parser, cast->lparen_loc.start, cast->lparen_loc.end, source); - - // arguments - argv[2] = rb_ary_pop(value_stack); - - // rparen_loc - argv[3] = cast->rparen_loc.start == NULL ? Qnil : yp_location_new(parser, cast->rparen_loc.start, cast->rparen_loc.end, source); - - // location - argv[4] = yp_location_new(parser, node->location.start, node->location.end, source); - - rb_ary_push(value_stack, rb_class_new_instance(5, argv, rb_cYARPYieldNode)); - break; - } - default: - rb_raise(rb_eRuntimeError, "unknown node type: %d", YP_NODE_TYPE(node)); - } - } - } - - VALUE result = rb_ary_pop(value_stack); - free(constants); - return result; -} - -void -Init_yarp_api_node(void) { - rb_cYARPAliasNode = rb_define_class_under(rb_cYARP, "AliasNode", rb_cYARPNode); - rb_cYARPAlternationPatternNode = rb_define_class_under(rb_cYARP, "AlternationPatternNode", rb_cYARPNode); - rb_cYARPAndNode = rb_define_class_under(rb_cYARP, "AndNode", rb_cYARPNode); - rb_cYARPArgumentsNode = rb_define_class_under(rb_cYARP, "ArgumentsNode", rb_cYARPNode); - rb_cYARPArrayNode = rb_define_class_under(rb_cYARP, "ArrayNode", rb_cYARPNode); - rb_cYARPArrayPatternNode = rb_define_class_under(rb_cYARP, "ArrayPatternNode", rb_cYARPNode); - rb_cYARPAssocNode = rb_define_class_under(rb_cYARP, "AssocNode", rb_cYARPNode); - rb_cYARPAssocSplatNode = rb_define_class_under(rb_cYARP, "AssocSplatNode", rb_cYARPNode); - rb_cYARPBackReferenceReadNode = rb_define_class_under(rb_cYARP, "BackReferenceReadNode", rb_cYARPNode); - rb_cYARPBeginNode = rb_define_class_under(rb_cYARP, "BeginNode", rb_cYARPNode); - rb_cYARPBlockArgumentNode = rb_define_class_under(rb_cYARP, "BlockArgumentNode", rb_cYARPNode); - rb_cYARPBlockNode = rb_define_class_under(rb_cYARP, "BlockNode", rb_cYARPNode); - rb_cYARPBlockParameterNode = rb_define_class_under(rb_cYARP, "BlockParameterNode", rb_cYARPNode); - rb_cYARPBlockParametersNode = rb_define_class_under(rb_cYARP, "BlockParametersNode", rb_cYARPNode); - rb_cYARPBreakNode = rb_define_class_under(rb_cYARP, "BreakNode", rb_cYARPNode); - rb_cYARPCallNode = rb_define_class_under(rb_cYARP, "CallNode", rb_cYARPNode); - rb_cYARPCallOperatorAndWriteNode = rb_define_class_under(rb_cYARP, "CallOperatorAndWriteNode", rb_cYARPNode); - rb_cYARPCallOperatorOrWriteNode = rb_define_class_under(rb_cYARP, "CallOperatorOrWriteNode", rb_cYARPNode); - rb_cYARPCallOperatorWriteNode = rb_define_class_under(rb_cYARP, "CallOperatorWriteNode", rb_cYARPNode); - rb_cYARPCapturePatternNode = rb_define_class_under(rb_cYARP, "CapturePatternNode", rb_cYARPNode); - rb_cYARPCaseNode = rb_define_class_under(rb_cYARP, "CaseNode", rb_cYARPNode); - rb_cYARPClassNode = rb_define_class_under(rb_cYARP, "ClassNode", rb_cYARPNode); - rb_cYARPClassVariableOperatorAndWriteNode = rb_define_class_under(rb_cYARP, "ClassVariableOperatorAndWriteNode", rb_cYARPNode); - rb_cYARPClassVariableOperatorOrWriteNode = rb_define_class_under(rb_cYARP, "ClassVariableOperatorOrWriteNode", rb_cYARPNode); - rb_cYARPClassVariableOperatorWriteNode = rb_define_class_under(rb_cYARP, "ClassVariableOperatorWriteNode", rb_cYARPNode); - rb_cYARPClassVariableReadNode = rb_define_class_under(rb_cYARP, "ClassVariableReadNode", rb_cYARPNode); - rb_cYARPClassVariableWriteNode = rb_define_class_under(rb_cYARP, "ClassVariableWriteNode", rb_cYARPNode); - rb_cYARPConstantOperatorAndWriteNode = rb_define_class_under(rb_cYARP, "ConstantOperatorAndWriteNode", rb_cYARPNode); - rb_cYARPConstantOperatorOrWriteNode = rb_define_class_under(rb_cYARP, "ConstantOperatorOrWriteNode", rb_cYARPNode); - rb_cYARPConstantOperatorWriteNode = rb_define_class_under(rb_cYARP, "ConstantOperatorWriteNode", rb_cYARPNode); - rb_cYARPConstantPathNode = rb_define_class_under(rb_cYARP, "ConstantPathNode", rb_cYARPNode); - rb_cYARPConstantPathOperatorAndWriteNode = rb_define_class_under(rb_cYARP, "ConstantPathOperatorAndWriteNode", rb_cYARPNode); - rb_cYARPConstantPathOperatorOrWriteNode = rb_define_class_under(rb_cYARP, "ConstantPathOperatorOrWriteNode", rb_cYARPNode); - rb_cYARPConstantPathOperatorWriteNode = rb_define_class_under(rb_cYARP, "ConstantPathOperatorWriteNode", rb_cYARPNode); - rb_cYARPConstantPathWriteNode = rb_define_class_under(rb_cYARP, "ConstantPathWriteNode", rb_cYARPNode); - rb_cYARPConstantReadNode = rb_define_class_under(rb_cYARP, "ConstantReadNode", rb_cYARPNode); - rb_cYARPConstantWriteNode = rb_define_class_under(rb_cYARP, "ConstantWriteNode", rb_cYARPNode); - rb_cYARPDefNode = rb_define_class_under(rb_cYARP, "DefNode", rb_cYARPNode); - rb_cYARPDefinedNode = rb_define_class_under(rb_cYARP, "DefinedNode", rb_cYARPNode); - rb_cYARPElseNode = rb_define_class_under(rb_cYARP, "ElseNode", rb_cYARPNode); - rb_cYARPEmbeddedStatementsNode = rb_define_class_under(rb_cYARP, "EmbeddedStatementsNode", rb_cYARPNode); - rb_cYARPEmbeddedVariableNode = rb_define_class_under(rb_cYARP, "EmbeddedVariableNode", rb_cYARPNode); - rb_cYARPEnsureNode = rb_define_class_under(rb_cYARP, "EnsureNode", rb_cYARPNode); - rb_cYARPFalseNode = rb_define_class_under(rb_cYARP, "FalseNode", rb_cYARPNode); - rb_cYARPFindPatternNode = rb_define_class_under(rb_cYARP, "FindPatternNode", rb_cYARPNode); - rb_cYARPFlipFlopNode = rb_define_class_under(rb_cYARP, "FlipFlopNode", rb_cYARPNode); - rb_cYARPFloatNode = rb_define_class_under(rb_cYARP, "FloatNode", rb_cYARPNode); - rb_cYARPForNode = rb_define_class_under(rb_cYARP, "ForNode", rb_cYARPNode); - rb_cYARPForwardingArgumentsNode = rb_define_class_under(rb_cYARP, "ForwardingArgumentsNode", rb_cYARPNode); - rb_cYARPForwardingParameterNode = rb_define_class_under(rb_cYARP, "ForwardingParameterNode", rb_cYARPNode); - rb_cYARPForwardingSuperNode = rb_define_class_under(rb_cYARP, "ForwardingSuperNode", rb_cYARPNode); - rb_cYARPGlobalVariableOperatorAndWriteNode = rb_define_class_under(rb_cYARP, "GlobalVariableOperatorAndWriteNode", rb_cYARPNode); - rb_cYARPGlobalVariableOperatorOrWriteNode = rb_define_class_under(rb_cYARP, "GlobalVariableOperatorOrWriteNode", rb_cYARPNode); - rb_cYARPGlobalVariableOperatorWriteNode = rb_define_class_under(rb_cYARP, "GlobalVariableOperatorWriteNode", rb_cYARPNode); - rb_cYARPGlobalVariableReadNode = rb_define_class_under(rb_cYARP, "GlobalVariableReadNode", rb_cYARPNode); - rb_cYARPGlobalVariableWriteNode = rb_define_class_under(rb_cYARP, "GlobalVariableWriteNode", rb_cYARPNode); - rb_cYARPHashNode = rb_define_class_under(rb_cYARP, "HashNode", rb_cYARPNode); - rb_cYARPHashPatternNode = rb_define_class_under(rb_cYARP, "HashPatternNode", rb_cYARPNode); - rb_cYARPIfNode = rb_define_class_under(rb_cYARP, "IfNode", rb_cYARPNode); - rb_cYARPImaginaryNode = rb_define_class_under(rb_cYARP, "ImaginaryNode", rb_cYARPNode); - rb_cYARPInNode = rb_define_class_under(rb_cYARP, "InNode", rb_cYARPNode); - rb_cYARPInstanceVariableOperatorAndWriteNode = rb_define_class_under(rb_cYARP, "InstanceVariableOperatorAndWriteNode", rb_cYARPNode); - rb_cYARPInstanceVariableOperatorOrWriteNode = rb_define_class_under(rb_cYARP, "InstanceVariableOperatorOrWriteNode", rb_cYARPNode); - rb_cYARPInstanceVariableOperatorWriteNode = rb_define_class_under(rb_cYARP, "InstanceVariableOperatorWriteNode", rb_cYARPNode); - rb_cYARPInstanceVariableReadNode = rb_define_class_under(rb_cYARP, "InstanceVariableReadNode", rb_cYARPNode); - rb_cYARPInstanceVariableWriteNode = rb_define_class_under(rb_cYARP, "InstanceVariableWriteNode", rb_cYARPNode); - rb_cYARPIntegerNode = rb_define_class_under(rb_cYARP, "IntegerNode", rb_cYARPNode); - rb_cYARPInterpolatedRegularExpressionNode = rb_define_class_under(rb_cYARP, "InterpolatedRegularExpressionNode", rb_cYARPNode); - rb_cYARPInterpolatedStringNode = rb_define_class_under(rb_cYARP, "InterpolatedStringNode", rb_cYARPNode); - rb_cYARPInterpolatedSymbolNode = rb_define_class_under(rb_cYARP, "InterpolatedSymbolNode", rb_cYARPNode); - rb_cYARPInterpolatedXStringNode = rb_define_class_under(rb_cYARP, "InterpolatedXStringNode", rb_cYARPNode); - rb_cYARPKeywordHashNode = rb_define_class_under(rb_cYARP, "KeywordHashNode", rb_cYARPNode); - rb_cYARPKeywordParameterNode = rb_define_class_under(rb_cYARP, "KeywordParameterNode", rb_cYARPNode); - rb_cYARPKeywordRestParameterNode = rb_define_class_under(rb_cYARP, "KeywordRestParameterNode", rb_cYARPNode); - rb_cYARPLambdaNode = rb_define_class_under(rb_cYARP, "LambdaNode", rb_cYARPNode); - rb_cYARPLocalVariableOperatorAndWriteNode = rb_define_class_under(rb_cYARP, "LocalVariableOperatorAndWriteNode", rb_cYARPNode); - rb_cYARPLocalVariableOperatorOrWriteNode = rb_define_class_under(rb_cYARP, "LocalVariableOperatorOrWriteNode", rb_cYARPNode); - rb_cYARPLocalVariableOperatorWriteNode = rb_define_class_under(rb_cYARP, "LocalVariableOperatorWriteNode", rb_cYARPNode); - rb_cYARPLocalVariableReadNode = rb_define_class_under(rb_cYARP, "LocalVariableReadNode", rb_cYARPNode); - rb_cYARPLocalVariableWriteNode = rb_define_class_under(rb_cYARP, "LocalVariableWriteNode", rb_cYARPNode); - rb_cYARPMatchPredicateNode = rb_define_class_under(rb_cYARP, "MatchPredicateNode", rb_cYARPNode); - rb_cYARPMatchRequiredNode = rb_define_class_under(rb_cYARP, "MatchRequiredNode", rb_cYARPNode); - rb_cYARPMissingNode = rb_define_class_under(rb_cYARP, "MissingNode", rb_cYARPNode); - rb_cYARPModuleNode = rb_define_class_under(rb_cYARP, "ModuleNode", rb_cYARPNode); - rb_cYARPMultiWriteNode = rb_define_class_under(rb_cYARP, "MultiWriteNode", rb_cYARPNode); - rb_cYARPNextNode = rb_define_class_under(rb_cYARP, "NextNode", rb_cYARPNode); - rb_cYARPNilNode = rb_define_class_under(rb_cYARP, "NilNode", rb_cYARPNode); - rb_cYARPNoKeywordsParameterNode = rb_define_class_under(rb_cYARP, "NoKeywordsParameterNode", rb_cYARPNode); - rb_cYARPNumberedReferenceReadNode = rb_define_class_under(rb_cYARP, "NumberedReferenceReadNode", rb_cYARPNode); - rb_cYARPOptionalParameterNode = rb_define_class_under(rb_cYARP, "OptionalParameterNode", rb_cYARPNode); - rb_cYARPOrNode = rb_define_class_under(rb_cYARP, "OrNode", rb_cYARPNode); - rb_cYARPParametersNode = rb_define_class_under(rb_cYARP, "ParametersNode", rb_cYARPNode); - rb_cYARPParenthesesNode = rb_define_class_under(rb_cYARP, "ParenthesesNode", rb_cYARPNode); - rb_cYARPPinnedExpressionNode = rb_define_class_under(rb_cYARP, "PinnedExpressionNode", rb_cYARPNode); - rb_cYARPPinnedVariableNode = rb_define_class_under(rb_cYARP, "PinnedVariableNode", rb_cYARPNode); - rb_cYARPPostExecutionNode = rb_define_class_under(rb_cYARP, "PostExecutionNode", rb_cYARPNode); - rb_cYARPPreExecutionNode = rb_define_class_under(rb_cYARP, "PreExecutionNode", rb_cYARPNode); - rb_cYARPProgramNode = rb_define_class_under(rb_cYARP, "ProgramNode", rb_cYARPNode); - rb_cYARPRangeNode = rb_define_class_under(rb_cYARP, "RangeNode", rb_cYARPNode); - rb_cYARPRationalNode = rb_define_class_under(rb_cYARP, "RationalNode", rb_cYARPNode); - rb_cYARPRedoNode = rb_define_class_under(rb_cYARP, "RedoNode", rb_cYARPNode); - rb_cYARPRegularExpressionNode = rb_define_class_under(rb_cYARP, "RegularExpressionNode", rb_cYARPNode); - rb_cYARPRequiredDestructuredParameterNode = rb_define_class_under(rb_cYARP, "RequiredDestructuredParameterNode", rb_cYARPNode); - rb_cYARPRequiredParameterNode = rb_define_class_under(rb_cYARP, "RequiredParameterNode", rb_cYARPNode); - rb_cYARPRescueModifierNode = rb_define_class_under(rb_cYARP, "RescueModifierNode", rb_cYARPNode); - rb_cYARPRescueNode = rb_define_class_under(rb_cYARP, "RescueNode", rb_cYARPNode); - rb_cYARPRestParameterNode = rb_define_class_under(rb_cYARP, "RestParameterNode", rb_cYARPNode); - rb_cYARPRetryNode = rb_define_class_under(rb_cYARP, "RetryNode", rb_cYARPNode); - rb_cYARPReturnNode = rb_define_class_under(rb_cYARP, "ReturnNode", rb_cYARPNode); - rb_cYARPSelfNode = rb_define_class_under(rb_cYARP, "SelfNode", rb_cYARPNode); - rb_cYARPSingletonClassNode = rb_define_class_under(rb_cYARP, "SingletonClassNode", rb_cYARPNode); - rb_cYARPSourceEncodingNode = rb_define_class_under(rb_cYARP, "SourceEncodingNode", rb_cYARPNode); - rb_cYARPSourceFileNode = rb_define_class_under(rb_cYARP, "SourceFileNode", rb_cYARPNode); - rb_cYARPSourceLineNode = rb_define_class_under(rb_cYARP, "SourceLineNode", rb_cYARPNode); - rb_cYARPSplatNode = rb_define_class_under(rb_cYARP, "SplatNode", rb_cYARPNode); - rb_cYARPStatementsNode = rb_define_class_under(rb_cYARP, "StatementsNode", rb_cYARPNode); - rb_cYARPStringConcatNode = rb_define_class_under(rb_cYARP, "StringConcatNode", rb_cYARPNode); - rb_cYARPStringNode = rb_define_class_under(rb_cYARP, "StringNode", rb_cYARPNode); - rb_cYARPSuperNode = rb_define_class_under(rb_cYARP, "SuperNode", rb_cYARPNode); - rb_cYARPSymbolNode = rb_define_class_under(rb_cYARP, "SymbolNode", rb_cYARPNode); - rb_cYARPTrueNode = rb_define_class_under(rb_cYARP, "TrueNode", rb_cYARPNode); - rb_cYARPUndefNode = rb_define_class_under(rb_cYARP, "UndefNode", rb_cYARPNode); - rb_cYARPUnlessNode = rb_define_class_under(rb_cYARP, "UnlessNode", rb_cYARPNode); - rb_cYARPUntilNode = rb_define_class_under(rb_cYARP, "UntilNode", rb_cYARPNode); - rb_cYARPWhenNode = rb_define_class_under(rb_cYARP, "WhenNode", rb_cYARPNode); - rb_cYARPWhileNode = rb_define_class_under(rb_cYARP, "WhileNode", rb_cYARPNode); - rb_cYARPXStringNode = rb_define_class_under(rb_cYARP, "XStringNode", rb_cYARPNode); - rb_cYARPYieldNode = rb_define_class_under(rb_cYARP, "YieldNode", rb_cYARPNode); -} diff --git a/yarp/ast.h b/yarp/ast.h deleted file mode 100644 index 0e0d320f4dd29a..00000000000000 --- a/yarp/ast.h +++ /dev/null @@ -1,1416 +0,0 @@ -/******************************************************************************/ -/* This file is generated by the bin/template script and should not be */ -/* modified manually. See */ -/* templates/include/yarp/ast.h.erb */ -/* if you are looking to modify the */ -/* template */ -/******************************************************************************/ -#ifndef YARP_AST_H -#define YARP_AST_H - -#include "yarp/defines.h" -#include "yarp/util/yp_constant_pool.h" -#include "yarp/util/yp_string.h" - -#include -#include -#include - -// This enum represents every type of token in the Ruby source. -typedef enum yp_token_type { - YP_TOKEN_EOF = 1, // final token in the file - YP_TOKEN_MISSING, // a token that was expected but not found - YP_TOKEN_NOT_PROVIDED, // a token that was not present but it is okay - YP_TOKEN_AMPERSAND, // & - YP_TOKEN_AMPERSAND_AMPERSAND, // && - YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL, // &&= - YP_TOKEN_AMPERSAND_DOT, // &. - YP_TOKEN_AMPERSAND_EQUAL, // &= - YP_TOKEN_BACKTICK, // ` - YP_TOKEN_BACK_REFERENCE, // a back reference - YP_TOKEN_BANG, // ! or !@ - YP_TOKEN_BANG_EQUAL, // != - YP_TOKEN_BANG_TILDE, // !~ - YP_TOKEN_BRACE_LEFT, // { - YP_TOKEN_BRACE_RIGHT, // } - YP_TOKEN_BRACKET_LEFT, // [ - YP_TOKEN_BRACKET_LEFT_ARRAY, // [ for the beginning of an array - YP_TOKEN_BRACKET_LEFT_RIGHT, // [] - YP_TOKEN_BRACKET_LEFT_RIGHT_EQUAL, // []= - YP_TOKEN_BRACKET_RIGHT, // ] - YP_TOKEN_CARET, // ^ - YP_TOKEN_CARET_EQUAL, // ^= - YP_TOKEN_CHARACTER_LITERAL, // a character literal - YP_TOKEN_CLASS_VARIABLE, // a class variable - YP_TOKEN_COLON, // : - YP_TOKEN_COLON_COLON, // :: - YP_TOKEN_COMMA, // , - YP_TOKEN_COMMENT, // a comment - YP_TOKEN_CONSTANT, // a constant - YP_TOKEN_DOT, // . - YP_TOKEN_DOT_DOT, // .. - YP_TOKEN_DOT_DOT_DOT, // ... - YP_TOKEN_EMBDOC_BEGIN, // =begin - YP_TOKEN_EMBDOC_END, // =end - YP_TOKEN_EMBDOC_LINE, // a line inside of embedded documentation - YP_TOKEN_EMBEXPR_BEGIN, // #{ - YP_TOKEN_EMBEXPR_END, // } - YP_TOKEN_EMBVAR, // # - YP_TOKEN_EQUAL, // = - YP_TOKEN_EQUAL_EQUAL, // == - YP_TOKEN_EQUAL_EQUAL_EQUAL, // === - YP_TOKEN_EQUAL_GREATER, // => - YP_TOKEN_EQUAL_TILDE, // =~ - YP_TOKEN_FLOAT, // a floating point number - YP_TOKEN_FLOAT_IMAGINARY, // a floating pointer number with an imaginary suffix - YP_TOKEN_FLOAT_RATIONAL, // a floating pointer number with a rational suffix - YP_TOKEN_FLOAT_RATIONAL_IMAGINARY, // a floating pointer number with a rational and imaginary suffix - YP_TOKEN_GLOBAL_VARIABLE, // a global variable - YP_TOKEN_GREATER, // > - YP_TOKEN_GREATER_EQUAL, // >= - YP_TOKEN_GREATER_GREATER, // >> - YP_TOKEN_GREATER_GREATER_EQUAL, // >>= - YP_TOKEN_HEREDOC_END, // the end of a heredoc - YP_TOKEN_HEREDOC_START, // the start of a heredoc - YP_TOKEN_IDENTIFIER, // an identifier - YP_TOKEN_IGNORED_NEWLINE, // an ignored newline - YP_TOKEN_INSTANCE_VARIABLE, // an instance variable - YP_TOKEN_INTEGER, // an integer (any base) - YP_TOKEN_INTEGER_IMAGINARY, // an integer with an imaginary suffix - YP_TOKEN_INTEGER_RATIONAL, // an integer with a rational suffix - YP_TOKEN_INTEGER_RATIONAL_IMAGINARY, // an integer with a rational and imaginary suffix - YP_TOKEN_KEYWORD_ALIAS, // alias - YP_TOKEN_KEYWORD_AND, // and - YP_TOKEN_KEYWORD_BEGIN, // begin - YP_TOKEN_KEYWORD_BEGIN_UPCASE, // BEGIN - YP_TOKEN_KEYWORD_BREAK, // break - YP_TOKEN_KEYWORD_CASE, // case - YP_TOKEN_KEYWORD_CLASS, // class - YP_TOKEN_KEYWORD_DEF, // def - YP_TOKEN_KEYWORD_DEFINED, // defined? - YP_TOKEN_KEYWORD_DO, // do - YP_TOKEN_KEYWORD_DO_LOOP, // do keyword for a predicate in a while, until, or for loop - YP_TOKEN_KEYWORD_ELSE, // else - YP_TOKEN_KEYWORD_ELSIF, // elsif - YP_TOKEN_KEYWORD_END, // end - YP_TOKEN_KEYWORD_END_UPCASE, // END - YP_TOKEN_KEYWORD_ENSURE, // ensure - YP_TOKEN_KEYWORD_FALSE, // false - YP_TOKEN_KEYWORD_FOR, // for - YP_TOKEN_KEYWORD_IF, // if - YP_TOKEN_KEYWORD_IF_MODIFIER, // if in the modifier form - YP_TOKEN_KEYWORD_IN, // in - YP_TOKEN_KEYWORD_MODULE, // module - YP_TOKEN_KEYWORD_NEXT, // next - YP_TOKEN_KEYWORD_NIL, // nil - YP_TOKEN_KEYWORD_NOT, // not - YP_TOKEN_KEYWORD_OR, // or - YP_TOKEN_KEYWORD_REDO, // redo - YP_TOKEN_KEYWORD_RESCUE, // rescue - YP_TOKEN_KEYWORD_RESCUE_MODIFIER, // rescue in the modifier form - YP_TOKEN_KEYWORD_RETRY, // retry - YP_TOKEN_KEYWORD_RETURN, // return - YP_TOKEN_KEYWORD_SELF, // self - YP_TOKEN_KEYWORD_SUPER, // super - YP_TOKEN_KEYWORD_THEN, // then - YP_TOKEN_KEYWORD_TRUE, // true - YP_TOKEN_KEYWORD_UNDEF, // undef - YP_TOKEN_KEYWORD_UNLESS, // unless - YP_TOKEN_KEYWORD_UNLESS_MODIFIER, // unless in the modifier form - YP_TOKEN_KEYWORD_UNTIL, // until - YP_TOKEN_KEYWORD_UNTIL_MODIFIER, // until in the modifier form - YP_TOKEN_KEYWORD_WHEN, // when - YP_TOKEN_KEYWORD_WHILE, // while - YP_TOKEN_KEYWORD_WHILE_MODIFIER, // while in the modifier form - YP_TOKEN_KEYWORD_YIELD, // yield - YP_TOKEN_KEYWORD___ENCODING__, // __ENCODING__ - YP_TOKEN_KEYWORD___FILE__, // __FILE__ - YP_TOKEN_KEYWORD___LINE__, // __LINE__ - YP_TOKEN_LABEL, // a label - YP_TOKEN_LABEL_END, // the end of a label - YP_TOKEN_LAMBDA_BEGIN, // { - YP_TOKEN_LESS, // < - YP_TOKEN_LESS_EQUAL, // <= - YP_TOKEN_LESS_EQUAL_GREATER, // <=> - YP_TOKEN_LESS_LESS, // << - YP_TOKEN_LESS_LESS_EQUAL, // <<= - YP_TOKEN_MINUS, // - - YP_TOKEN_MINUS_EQUAL, // -= - YP_TOKEN_MINUS_GREATER, // -> - YP_TOKEN_NEWLINE, // a newline character outside of other tokens - YP_TOKEN_NUMBERED_REFERENCE, // a numbered reference to a capture group in the previous regular expression match - YP_TOKEN_PARENTHESIS_LEFT, // ( - YP_TOKEN_PARENTHESIS_LEFT_PARENTHESES, // ( for a parentheses node - YP_TOKEN_PARENTHESIS_RIGHT, // ) - YP_TOKEN_PERCENT, // % - YP_TOKEN_PERCENT_EQUAL, // %= - YP_TOKEN_PERCENT_LOWER_I, // %i - YP_TOKEN_PERCENT_LOWER_W, // %w - YP_TOKEN_PERCENT_LOWER_X, // %x - YP_TOKEN_PERCENT_UPPER_I, // %I - YP_TOKEN_PERCENT_UPPER_W, // %W - YP_TOKEN_PIPE, // | - YP_TOKEN_PIPE_EQUAL, // |= - YP_TOKEN_PIPE_PIPE, // || - YP_TOKEN_PIPE_PIPE_EQUAL, // ||= - YP_TOKEN_PLUS, // + - YP_TOKEN_PLUS_EQUAL, // += - YP_TOKEN_QUESTION_MARK, // ? - YP_TOKEN_REGEXP_BEGIN, // the beginning of a regular expression - YP_TOKEN_REGEXP_END, // the end of a regular expression - YP_TOKEN_SEMICOLON, // ; - YP_TOKEN_SLASH, // / - YP_TOKEN_SLASH_EQUAL, // /= - YP_TOKEN_STAR, // * - YP_TOKEN_STAR_EQUAL, // *= - YP_TOKEN_STAR_STAR, // ** - YP_TOKEN_STAR_STAR_EQUAL, // **= - YP_TOKEN_STRING_BEGIN, // the beginning of a string - YP_TOKEN_STRING_CONTENT, // the contents of a string - YP_TOKEN_STRING_END, // the end of a string - YP_TOKEN_SYMBOL_BEGIN, // the beginning of a symbol - YP_TOKEN_TILDE, // ~ or ~@ - YP_TOKEN_UAMPERSAND, // unary & - YP_TOKEN_UCOLON_COLON, // unary :: - YP_TOKEN_UDOT_DOT, // unary .. - YP_TOKEN_UDOT_DOT_DOT, // unary ... - YP_TOKEN_UMINUS, // -@ - YP_TOKEN_UMINUS_NUM, // -@ for a number - YP_TOKEN_UPLUS, // +@ - YP_TOKEN_USTAR, // unary * - YP_TOKEN_USTAR_STAR, // unary ** - YP_TOKEN_WORDS_SEP, // a separator between words in a list - YP_TOKEN___END__, // marker for the point in the file at which the parser should stop - YP_TOKEN_MAXIMUM, // the maximum token value -} yp_token_type_t; - -// This struct represents a token in the Ruby source. We use it to track both -// type and location information. -typedef struct { - yp_token_type_t type; - const char *start; - const char *end; -} yp_token_t; - -// This represents a range of bytes in the source string to which a node or -// token corresponds. -typedef struct { - const char *start; - const char *end; -} yp_location_t; - -typedef struct { - yp_location_t *locations; - size_t size; - size_t capacity; -} yp_location_list_t; - -struct yp_node; - -typedef struct yp_node_list { - struct yp_node **nodes; - size_t size; - size_t capacity; -} yp_node_list_t; - -enum yp_node_type { - YP_NODE_ALIAS_NODE = 1, - YP_NODE_ALTERNATION_PATTERN_NODE = 2, - YP_NODE_AND_NODE = 3, - YP_NODE_ARGUMENTS_NODE = 4, - YP_NODE_ARRAY_NODE = 5, - YP_NODE_ARRAY_PATTERN_NODE = 6, - YP_NODE_ASSOC_NODE = 7, - YP_NODE_ASSOC_SPLAT_NODE = 8, - YP_NODE_BACK_REFERENCE_READ_NODE = 9, - YP_NODE_BEGIN_NODE = 10, - YP_NODE_BLOCK_ARGUMENT_NODE = 11, - YP_NODE_BLOCK_NODE = 12, - YP_NODE_BLOCK_PARAMETER_NODE = 13, - YP_NODE_BLOCK_PARAMETERS_NODE = 14, - YP_NODE_BREAK_NODE = 15, - YP_NODE_CALL_NODE = 16, - YP_NODE_CALL_OPERATOR_AND_WRITE_NODE = 17, - YP_NODE_CALL_OPERATOR_OR_WRITE_NODE = 18, - YP_NODE_CALL_OPERATOR_WRITE_NODE = 19, - YP_NODE_CAPTURE_PATTERN_NODE = 20, - YP_NODE_CASE_NODE = 21, - YP_NODE_CLASS_NODE = 22, - YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE = 23, - YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE = 24, - YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE = 25, - YP_NODE_CLASS_VARIABLE_READ_NODE = 26, - YP_NODE_CLASS_VARIABLE_WRITE_NODE = 27, - YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE = 28, - YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE = 29, - YP_NODE_CONSTANT_OPERATOR_WRITE_NODE = 30, - YP_NODE_CONSTANT_PATH_NODE = 31, - YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE = 32, - YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE = 33, - YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE = 34, - YP_NODE_CONSTANT_PATH_WRITE_NODE = 35, - YP_NODE_CONSTANT_READ_NODE = 36, - YP_NODE_CONSTANT_WRITE_NODE = 37, - YP_NODE_DEF_NODE = 38, - YP_NODE_DEFINED_NODE = 39, - YP_NODE_ELSE_NODE = 40, - YP_NODE_EMBEDDED_STATEMENTS_NODE = 41, - YP_NODE_EMBEDDED_VARIABLE_NODE = 42, - YP_NODE_ENSURE_NODE = 43, - YP_NODE_FALSE_NODE = 44, - YP_NODE_FIND_PATTERN_NODE = 45, - YP_NODE_FLIP_FLOP_NODE = 46, - YP_NODE_FLOAT_NODE = 47, - YP_NODE_FOR_NODE = 48, - YP_NODE_FORWARDING_ARGUMENTS_NODE = 49, - YP_NODE_FORWARDING_PARAMETER_NODE = 50, - YP_NODE_FORWARDING_SUPER_NODE = 51, - YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 52, - YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 53, - YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE = 54, - YP_NODE_GLOBAL_VARIABLE_READ_NODE = 55, - YP_NODE_GLOBAL_VARIABLE_WRITE_NODE = 56, - YP_NODE_HASH_NODE = 57, - YP_NODE_HASH_PATTERN_NODE = 58, - YP_NODE_IF_NODE = 59, - YP_NODE_IMAGINARY_NODE = 60, - YP_NODE_IN_NODE = 61, - YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE = 62, - YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE = 63, - YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE = 64, - YP_NODE_INSTANCE_VARIABLE_READ_NODE = 65, - YP_NODE_INSTANCE_VARIABLE_WRITE_NODE = 66, - YP_NODE_INTEGER_NODE = 67, - YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE = 68, - YP_NODE_INTERPOLATED_STRING_NODE = 69, - YP_NODE_INTERPOLATED_SYMBOL_NODE = 70, - YP_NODE_INTERPOLATED_X_STRING_NODE = 71, - YP_NODE_KEYWORD_HASH_NODE = 72, - YP_NODE_KEYWORD_PARAMETER_NODE = 73, - YP_NODE_KEYWORD_REST_PARAMETER_NODE = 74, - YP_NODE_LAMBDA_NODE = 75, - YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 76, - YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 77, - YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE = 78, - YP_NODE_LOCAL_VARIABLE_READ_NODE = 79, - YP_NODE_LOCAL_VARIABLE_WRITE_NODE = 80, - YP_NODE_MATCH_PREDICATE_NODE = 81, - YP_NODE_MATCH_REQUIRED_NODE = 82, - YP_NODE_MISSING_NODE = 83, - YP_NODE_MODULE_NODE = 84, - YP_NODE_MULTI_WRITE_NODE = 85, - YP_NODE_NEXT_NODE = 86, - YP_NODE_NIL_NODE = 87, - YP_NODE_NO_KEYWORDS_PARAMETER_NODE = 88, - YP_NODE_NUMBERED_REFERENCE_READ_NODE = 89, - YP_NODE_OPTIONAL_PARAMETER_NODE = 90, - YP_NODE_OR_NODE = 91, - YP_NODE_PARAMETERS_NODE = 92, - YP_NODE_PARENTHESES_NODE = 93, - YP_NODE_PINNED_EXPRESSION_NODE = 94, - YP_NODE_PINNED_VARIABLE_NODE = 95, - YP_NODE_POST_EXECUTION_NODE = 96, - YP_NODE_PRE_EXECUTION_NODE = 97, - YP_NODE_PROGRAM_NODE = 98, - YP_NODE_RANGE_NODE = 99, - YP_NODE_RATIONAL_NODE = 100, - YP_NODE_REDO_NODE = 101, - YP_NODE_REGULAR_EXPRESSION_NODE = 102, - YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE = 103, - YP_NODE_REQUIRED_PARAMETER_NODE = 104, - YP_NODE_RESCUE_MODIFIER_NODE = 105, - YP_NODE_RESCUE_NODE = 106, - YP_NODE_REST_PARAMETER_NODE = 107, - YP_NODE_RETRY_NODE = 108, - YP_NODE_RETURN_NODE = 109, - YP_NODE_SELF_NODE = 110, - YP_NODE_SINGLETON_CLASS_NODE = 111, - YP_NODE_SOURCE_ENCODING_NODE = 112, - YP_NODE_SOURCE_FILE_NODE = 113, - YP_NODE_SOURCE_LINE_NODE = 114, - YP_NODE_SPLAT_NODE = 115, - YP_NODE_STATEMENTS_NODE = 116, - YP_NODE_STRING_CONCAT_NODE = 117, - YP_NODE_STRING_NODE = 118, - YP_NODE_SUPER_NODE = 119, - YP_NODE_SYMBOL_NODE = 120, - YP_NODE_TRUE_NODE = 121, - YP_NODE_UNDEF_NODE = 122, - YP_NODE_UNLESS_NODE = 123, - YP_NODE_UNTIL_NODE = 124, - YP_NODE_WHEN_NODE = 125, - YP_NODE_WHILE_NODE = 126, - YP_NODE_X_STRING_NODE = 127, - YP_NODE_YIELD_NODE = 128, -}; - -typedef uint16_t yp_node_type_t; -typedef uint16_t yp_node_flags_t; - -// We store the flags enum in every node in the tree. Some flags are common to -// all nodes (the ones listed below). Others are specific to certain node types. -static const yp_node_flags_t YP_NODE_FLAG_NEWLINE = 0x1; - -// For easy access, we define some macros to check node type -#define YP_NODE_TYPE(node) ((enum yp_node_type)node->type) -#define YP_NODE_TYPE_P(node, type) (YP_NODE_TYPE(node) == (type)) - -// This is the overall tagged union representing a node in the syntax tree. -typedef struct yp_node { - // This represents the type of the node. It somewhat maps to the nodes that - // existed in the original grammar and ripper, but it's not a 1:1 mapping. - yp_node_type_t type; - - // This represents any flags on the node. Currently, this is only a newline - // flag - yp_node_flags_t flags; - - // This is the location of the node in the source. It's a range of bytes - // containing a start and an end. - yp_location_t location; -} yp_node_t; - -// AliasNode -typedef struct yp_alias_node { - yp_node_t base; - struct yp_node *new_name; - struct yp_node *old_name; - yp_location_t keyword_loc; -} yp_alias_node_t; - -// AlternationPatternNode -typedef struct yp_alternation_pattern_node { - yp_node_t base; - struct yp_node *left; - struct yp_node *right; - yp_location_t operator_loc; -} yp_alternation_pattern_node_t; - -// AndNode -typedef struct yp_and_node { - yp_node_t base; - struct yp_node *left; - struct yp_node *right; - yp_location_t operator_loc; -} yp_and_node_t; - -// ArgumentsNode -typedef struct yp_arguments_node { - yp_node_t base; - struct yp_node_list arguments; -} yp_arguments_node_t; - -// ArrayNode -typedef struct yp_array_node { - yp_node_t base; - struct yp_node_list elements; - yp_location_t opening_loc; - yp_location_t closing_loc; -} yp_array_node_t; - -// ArrayPatternNode -typedef struct yp_array_pattern_node { - yp_node_t base; - struct yp_node *constant; - struct yp_node_list requireds; - struct yp_node *rest; - struct yp_node_list posts; - yp_location_t opening_loc; - yp_location_t closing_loc; -} yp_array_pattern_node_t; - -// AssocNode -typedef struct yp_assoc_node { - yp_node_t base; - struct yp_node *key; - struct yp_node *value; - yp_location_t operator_loc; -} yp_assoc_node_t; - -// AssocSplatNode -typedef struct yp_assoc_splat_node { - yp_node_t base; - struct yp_node *value; - yp_location_t operator_loc; -} yp_assoc_splat_node_t; - -// BackReferenceReadNode -typedef struct yp_back_reference_read_node { - yp_node_t base; -} yp_back_reference_read_node_t; - -// BeginNode -typedef struct yp_begin_node { - yp_node_t base; - yp_location_t begin_keyword_loc; - struct yp_statements_node *statements; - struct yp_rescue_node *rescue_clause; - struct yp_else_node *else_clause; - struct yp_ensure_node *ensure_clause; - yp_location_t end_keyword_loc; -} yp_begin_node_t; - -// BlockArgumentNode -typedef struct yp_block_argument_node { - yp_node_t base; - struct yp_node *expression; - yp_location_t operator_loc; -} yp_block_argument_node_t; - -// BlockNode -typedef struct yp_block_node { - yp_node_t base; - yp_constant_id_list_t locals; - struct yp_block_parameters_node *parameters; - struct yp_node *statements; - yp_location_t opening_loc; - yp_location_t closing_loc; -} yp_block_node_t; - -// BlockParameterNode -typedef struct yp_block_parameter_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; -} yp_block_parameter_node_t; - -// BlockParametersNode -typedef struct yp_block_parameters_node { - yp_node_t base; - struct yp_parameters_node *parameters; - yp_location_list_t locals; - yp_location_t opening_loc; - yp_location_t closing_loc; -} yp_block_parameters_node_t; - -// BreakNode -typedef struct yp_break_node { - yp_node_t base; - struct yp_arguments_node *arguments; - yp_location_t keyword_loc; -} yp_break_node_t; - -// CallNode -typedef struct yp_call_node { - yp_node_t base; - struct yp_node *receiver; - yp_location_t operator_loc; - yp_location_t message_loc; - yp_location_t opening_loc; - struct yp_arguments_node *arguments; - yp_location_t closing_loc; - struct yp_block_node *block; - yp_string_t name; -} yp_call_node_t; - -// CallOperatorAndWriteNode -typedef struct yp_call_operator_and_write_node { - yp_node_t base; - struct yp_call_node *target; - yp_location_t operator_loc; - struct yp_node *value; -} yp_call_operator_and_write_node_t; - -// CallOperatorOrWriteNode -typedef struct yp_call_operator_or_write_node { - yp_node_t base; - struct yp_call_node *target; - struct yp_node *value; - yp_location_t operator_loc; -} yp_call_operator_or_write_node_t; - -// CallOperatorWriteNode -typedef struct yp_call_operator_write_node { - yp_node_t base; - struct yp_call_node *target; - yp_location_t operator_loc; - struct yp_node *value; - yp_constant_id_t operator_id; -} yp_call_operator_write_node_t; - -// CapturePatternNode -typedef struct yp_capture_pattern_node { - yp_node_t base; - struct yp_node *value; - struct yp_node *target; - yp_location_t operator_loc; -} yp_capture_pattern_node_t; - -// CaseNode -typedef struct yp_case_node { - yp_node_t base; - struct yp_node *predicate; - struct yp_node_list conditions; - struct yp_else_node *consequent; - yp_location_t case_keyword_loc; - yp_location_t end_keyword_loc; -} yp_case_node_t; - -// ClassNode -typedef struct yp_class_node { - yp_node_t base; - yp_constant_id_list_t locals; - yp_location_t class_keyword_loc; - struct yp_node *constant_path; - yp_location_t inheritance_operator_loc; - struct yp_node *superclass; - struct yp_node *statements; - yp_location_t end_keyword_loc; -} yp_class_node_t; - -// ClassVariableOperatorAndWriteNode -typedef struct yp_class_variable_operator_and_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; -} yp_class_variable_operator_and_write_node_t; - -// ClassVariableOperatorOrWriteNode -typedef struct yp_class_variable_operator_or_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; -} yp_class_variable_operator_or_write_node_t; - -// ClassVariableOperatorWriteNode -typedef struct yp_class_variable_operator_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; - yp_constant_id_t operator; -} yp_class_variable_operator_write_node_t; - -// ClassVariableReadNode -typedef struct yp_class_variable_read_node { - yp_node_t base; -} yp_class_variable_read_node_t; - -// ClassVariableWriteNode -typedef struct yp_class_variable_write_node { - yp_node_t base; - yp_location_t name_loc; - struct yp_node *value; - yp_location_t operator_loc; -} yp_class_variable_write_node_t; - -// ConstantOperatorAndWriteNode -typedef struct yp_constant_operator_and_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; -} yp_constant_operator_and_write_node_t; - -// ConstantOperatorOrWriteNode -typedef struct yp_constant_operator_or_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; -} yp_constant_operator_or_write_node_t; - -// ConstantOperatorWriteNode -typedef struct yp_constant_operator_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; - yp_constant_id_t operator; -} yp_constant_operator_write_node_t; - -// ConstantPathNode -typedef struct yp_constant_path_node { - yp_node_t base; - struct yp_node *parent; - struct yp_node *child; - yp_location_t delimiter_loc; -} yp_constant_path_node_t; - -// ConstantPathOperatorAndWriteNode -typedef struct yp_constant_path_operator_and_write_node { - yp_node_t base; - struct yp_constant_path_node *target; - yp_location_t operator_loc; - struct yp_node *value; -} yp_constant_path_operator_and_write_node_t; - -// ConstantPathOperatorOrWriteNode -typedef struct yp_constant_path_operator_or_write_node { - yp_node_t base; - struct yp_constant_path_node *target; - yp_location_t operator_loc; - struct yp_node *value; -} yp_constant_path_operator_or_write_node_t; - -// ConstantPathOperatorWriteNode -typedef struct yp_constant_path_operator_write_node { - yp_node_t base; - struct yp_constant_path_node *target; - yp_location_t operator_loc; - struct yp_node *value; - yp_constant_id_t operator; -} yp_constant_path_operator_write_node_t; - -// ConstantPathWriteNode -typedef struct yp_constant_path_write_node { - yp_node_t base; - struct yp_constant_path_node *target; - yp_location_t operator_loc; - struct yp_node *value; -} yp_constant_path_write_node_t; - -// ConstantReadNode -typedef struct yp_constant_read_node { - yp_node_t base; -} yp_constant_read_node_t; - -// ConstantWriteNode -typedef struct yp_constant_write_node { - yp_node_t base; - yp_location_t name_loc; - struct yp_node *value; - yp_location_t operator_loc; -} yp_constant_write_node_t; - -// DefNode -typedef struct yp_def_node { - yp_node_t base; - yp_location_t name_loc; - struct yp_node *receiver; - struct yp_parameters_node *parameters; - struct yp_node *statements; - yp_constant_id_list_t locals; - yp_location_t def_keyword_loc; - yp_location_t operator_loc; - yp_location_t lparen_loc; - yp_location_t rparen_loc; - yp_location_t equal_loc; - yp_location_t end_keyword_loc; -} yp_def_node_t; - -// DefinedNode -typedef struct yp_defined_node { - yp_node_t base; - yp_location_t lparen_loc; - struct yp_node *value; - yp_location_t rparen_loc; - yp_location_t keyword_loc; -} yp_defined_node_t; - -// ElseNode -typedef struct yp_else_node { - yp_node_t base; - yp_location_t else_keyword_loc; - struct yp_statements_node *statements; - yp_location_t end_keyword_loc; -} yp_else_node_t; - -// EmbeddedStatementsNode -typedef struct yp_embedded_statements_node { - yp_node_t base; - yp_location_t opening_loc; - struct yp_statements_node *statements; - yp_location_t closing_loc; -} yp_embedded_statements_node_t; - -// EmbeddedVariableNode -typedef struct yp_embedded_variable_node { - yp_node_t base; - yp_location_t operator_loc; - struct yp_node *variable; -} yp_embedded_variable_node_t; - -// EnsureNode -typedef struct yp_ensure_node { - yp_node_t base; - yp_location_t ensure_keyword_loc; - struct yp_statements_node *statements; - yp_location_t end_keyword_loc; -} yp_ensure_node_t; - -// FalseNode -typedef struct yp_false_node { - yp_node_t base; -} yp_false_node_t; - -// FindPatternNode -typedef struct yp_find_pattern_node { - yp_node_t base; - struct yp_node *constant; - struct yp_node *left; - struct yp_node_list requireds; - struct yp_node *right; - yp_location_t opening_loc; - yp_location_t closing_loc; -} yp_find_pattern_node_t; - -// FlipFlopNode -typedef struct yp_flip_flop_node { - yp_node_t base; - struct yp_node *left; - struct yp_node *right; - yp_location_t operator_loc; -} yp_flip_flop_node_t; - -// FloatNode -typedef struct yp_float_node { - yp_node_t base; -} yp_float_node_t; - -// ForNode -typedef struct yp_for_node { - yp_node_t base; - struct yp_node *index; - struct yp_node *collection; - struct yp_statements_node *statements; - yp_location_t for_keyword_loc; - yp_location_t in_keyword_loc; - yp_location_t do_keyword_loc; - yp_location_t end_keyword_loc; -} yp_for_node_t; - -// ForwardingArgumentsNode -typedef struct yp_forwarding_arguments_node { - yp_node_t base; -} yp_forwarding_arguments_node_t; - -// ForwardingParameterNode -typedef struct yp_forwarding_parameter_node { - yp_node_t base; -} yp_forwarding_parameter_node_t; - -// ForwardingSuperNode -typedef struct yp_forwarding_super_node { - yp_node_t base; - struct yp_block_node *block; -} yp_forwarding_super_node_t; - -// GlobalVariableOperatorAndWriteNode -typedef struct yp_global_variable_operator_and_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; -} yp_global_variable_operator_and_write_node_t; - -// GlobalVariableOperatorOrWriteNode -typedef struct yp_global_variable_operator_or_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; -} yp_global_variable_operator_or_write_node_t; - -// GlobalVariableOperatorWriteNode -typedef struct yp_global_variable_operator_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; - yp_constant_id_t operator; -} yp_global_variable_operator_write_node_t; - -// GlobalVariableReadNode -typedef struct yp_global_variable_read_node { - yp_node_t base; -} yp_global_variable_read_node_t; - -// GlobalVariableWriteNode -typedef struct yp_global_variable_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; -} yp_global_variable_write_node_t; - -// HashNode -typedef struct yp_hash_node { - yp_node_t base; - yp_location_t opening_loc; - struct yp_node_list elements; - yp_location_t closing_loc; -} yp_hash_node_t; - -// HashPatternNode -typedef struct yp_hash_pattern_node { - yp_node_t base; - struct yp_node *constant; - struct yp_node_list assocs; - struct yp_node *kwrest; - yp_location_t opening_loc; - yp_location_t closing_loc; -} yp_hash_pattern_node_t; - -// IfNode -typedef struct yp_if_node { - yp_node_t base; - yp_location_t if_keyword_loc; - struct yp_node *predicate; - struct yp_statements_node *statements; - struct yp_node *consequent; - yp_location_t end_keyword_loc; -} yp_if_node_t; - -// ImaginaryNode -typedef struct yp_imaginary_node { - yp_node_t base; - struct yp_node *numeric; -} yp_imaginary_node_t; - -// InNode -typedef struct yp_in_node { - yp_node_t base; - struct yp_node *pattern; - struct yp_statements_node *statements; - yp_location_t in_loc; - yp_location_t then_loc; -} yp_in_node_t; - -// InstanceVariableOperatorAndWriteNode -typedef struct yp_instance_variable_operator_and_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; -} yp_instance_variable_operator_and_write_node_t; - -// InstanceVariableOperatorOrWriteNode -typedef struct yp_instance_variable_operator_or_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; -} yp_instance_variable_operator_or_write_node_t; - -// InstanceVariableOperatorWriteNode -typedef struct yp_instance_variable_operator_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; - yp_constant_id_t operator; -} yp_instance_variable_operator_write_node_t; - -// InstanceVariableReadNode -typedef struct yp_instance_variable_read_node { - yp_node_t base; -} yp_instance_variable_read_node_t; - -// InstanceVariableWriteNode -typedef struct yp_instance_variable_write_node { - yp_node_t base; - yp_location_t name_loc; - struct yp_node *value; - yp_location_t operator_loc; -} yp_instance_variable_write_node_t; - -// IntegerNode -typedef struct yp_integer_node { - yp_node_t base; -} yp_integer_node_t; - -// InterpolatedRegularExpressionNode -typedef struct yp_interpolated_regular_expression_node { - yp_node_t base; - yp_location_t opening_loc; - struct yp_node_list parts; - yp_location_t closing_loc; -} yp_interpolated_regular_expression_node_t; - -// InterpolatedStringNode -typedef struct yp_interpolated_string_node { - yp_node_t base; - yp_location_t opening_loc; - struct yp_node_list parts; - yp_location_t closing_loc; -} yp_interpolated_string_node_t; - -// InterpolatedSymbolNode -typedef struct yp_interpolated_symbol_node { - yp_node_t base; - yp_location_t opening_loc; - struct yp_node_list parts; - yp_location_t closing_loc; -} yp_interpolated_symbol_node_t; - -// InterpolatedXStringNode -typedef struct yp_interpolated_x_string_node { - yp_node_t base; - yp_location_t opening_loc; - struct yp_node_list parts; - yp_location_t closing_loc; -} yp_interpolated_x_string_node_t; - -// KeywordHashNode -typedef struct yp_keyword_hash_node { - yp_node_t base; - struct yp_node_list elements; -} yp_keyword_hash_node_t; - -// KeywordParameterNode -typedef struct yp_keyword_parameter_node { - yp_node_t base; - yp_location_t name_loc; - struct yp_node *value; -} yp_keyword_parameter_node_t; - -// KeywordRestParameterNode -typedef struct yp_keyword_rest_parameter_node { - yp_node_t base; - yp_location_t operator_loc; - yp_location_t name_loc; -} yp_keyword_rest_parameter_node_t; - -// LambdaNode -typedef struct yp_lambda_node { - yp_node_t base; - yp_constant_id_list_t locals; - yp_location_t opening_loc; - struct yp_block_parameters_node *parameters; - struct yp_node *statements; -} yp_lambda_node_t; - -// LocalVariableOperatorAndWriteNode -typedef struct yp_local_variable_operator_and_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; - yp_constant_id_t constant_id; -} yp_local_variable_operator_and_write_node_t; - -// LocalVariableOperatorOrWriteNode -typedef struct yp_local_variable_operator_or_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; - yp_constant_id_t constant_id; -} yp_local_variable_operator_or_write_node_t; - -// LocalVariableOperatorWriteNode -typedef struct yp_local_variable_operator_write_node { - yp_node_t base; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; - yp_constant_id_t constant_id; - yp_constant_id_t operator_id; -} yp_local_variable_operator_write_node_t; - -// LocalVariableReadNode -typedef struct yp_local_variable_read_node { - yp_node_t base; - yp_constant_id_t constant_id; - uint32_t depth; -} yp_local_variable_read_node_t; - -// LocalVariableWriteNode -typedef struct yp_local_variable_write_node { - yp_node_t base; - yp_constant_id_t constant_id; - uint32_t depth; - struct yp_node *value; - yp_location_t name_loc; - yp_location_t operator_loc; -} yp_local_variable_write_node_t; - -// MatchPredicateNode -typedef struct yp_match_predicate_node { - yp_node_t base; - struct yp_node *value; - struct yp_node *pattern; - yp_location_t operator_loc; -} yp_match_predicate_node_t; - -// MatchRequiredNode -typedef struct yp_match_required_node { - yp_node_t base; - struct yp_node *value; - struct yp_node *pattern; - yp_location_t operator_loc; -} yp_match_required_node_t; - -// MissingNode -typedef struct yp_missing_node { - yp_node_t base; -} yp_missing_node_t; - -// ModuleNode -typedef struct yp_module_node { - yp_node_t base; - yp_constant_id_list_t locals; - yp_location_t module_keyword_loc; - struct yp_node *constant_path; - struct yp_node *statements; - yp_location_t end_keyword_loc; -} yp_module_node_t; - -// MultiWriteNode -typedef struct yp_multi_write_node { - yp_node_t base; - struct yp_node_list targets; - yp_location_t operator_loc; - struct yp_node *value; - yp_location_t lparen_loc; - yp_location_t rparen_loc; -} yp_multi_write_node_t; - -// NextNode -typedef struct yp_next_node { - yp_node_t base; - struct yp_arguments_node *arguments; - yp_location_t keyword_loc; -} yp_next_node_t; - -// NilNode -typedef struct yp_nil_node { - yp_node_t base; -} yp_nil_node_t; - -// NoKeywordsParameterNode -typedef struct yp_no_keywords_parameter_node { - yp_node_t base; - yp_location_t operator_loc; - yp_location_t keyword_loc; -} yp_no_keywords_parameter_node_t; - -// NumberedReferenceReadNode -typedef struct yp_numbered_reference_read_node { - yp_node_t base; -} yp_numbered_reference_read_node_t; - -// OptionalParameterNode -typedef struct yp_optional_parameter_node { - yp_node_t base; - yp_constant_id_t constant_id; - yp_location_t name_loc; - yp_location_t operator_loc; - struct yp_node *value; -} yp_optional_parameter_node_t; - -// OrNode -typedef struct yp_or_node { - yp_node_t base; - struct yp_node *left; - struct yp_node *right; - yp_location_t operator_loc; -} yp_or_node_t; - -// ParametersNode -typedef struct yp_parameters_node { - yp_node_t base; - struct yp_node_list requireds; - struct yp_node_list optionals; - struct yp_node_list posts; - struct yp_rest_parameter_node *rest; - struct yp_node_list keywords; - struct yp_node *keyword_rest; - struct yp_block_parameter_node *block; -} yp_parameters_node_t; - -// ParenthesesNode -typedef struct yp_parentheses_node { - yp_node_t base; - struct yp_node *statements; - yp_location_t opening_loc; - yp_location_t closing_loc; -} yp_parentheses_node_t; - -// PinnedExpressionNode -typedef struct yp_pinned_expression_node { - yp_node_t base; - struct yp_node *expression; - yp_location_t operator_loc; - yp_location_t lparen_loc; - yp_location_t rparen_loc; -} yp_pinned_expression_node_t; - -// PinnedVariableNode -typedef struct yp_pinned_variable_node { - yp_node_t base; - struct yp_node *variable; - yp_location_t operator_loc; -} yp_pinned_variable_node_t; - -// PostExecutionNode -typedef struct yp_post_execution_node { - yp_node_t base; - struct yp_statements_node *statements; - yp_location_t keyword_loc; - yp_location_t opening_loc; - yp_location_t closing_loc; -} yp_post_execution_node_t; - -// PreExecutionNode -typedef struct yp_pre_execution_node { - yp_node_t base; - struct yp_statements_node *statements; - yp_location_t keyword_loc; - yp_location_t opening_loc; - yp_location_t closing_loc; -} yp_pre_execution_node_t; - -// ProgramNode -typedef struct yp_program_node { - yp_node_t base; - yp_constant_id_list_t locals; - struct yp_statements_node *statements; -} yp_program_node_t; - -// RangeNode -typedef struct yp_range_node { - yp_node_t base; - struct yp_node *left; - struct yp_node *right; - yp_location_t operator_loc; -} yp_range_node_t; - -// RationalNode -typedef struct yp_rational_node { - yp_node_t base; - struct yp_node *numeric; -} yp_rational_node_t; - -// RedoNode -typedef struct yp_redo_node { - yp_node_t base; -} yp_redo_node_t; - -// RegularExpressionNode -typedef struct yp_regular_expression_node { - yp_node_t base; - yp_location_t opening_loc; - yp_location_t content_loc; - yp_location_t closing_loc; - yp_string_t unescaped; -} yp_regular_expression_node_t; - -// RequiredDestructuredParameterNode -typedef struct yp_required_destructured_parameter_node { - yp_node_t base; - struct yp_node_list parameters; - yp_location_t opening_loc; - yp_location_t closing_loc; -} yp_required_destructured_parameter_node_t; - -// RequiredParameterNode -typedef struct yp_required_parameter_node { - yp_node_t base; - yp_constant_id_t constant_id; -} yp_required_parameter_node_t; - -// RescueModifierNode -typedef struct yp_rescue_modifier_node { - yp_node_t base; - struct yp_node *expression; - yp_location_t keyword_loc; - struct yp_node *rescue_expression; -} yp_rescue_modifier_node_t; - -// RescueNode -typedef struct yp_rescue_node { - yp_node_t base; - yp_location_t keyword_loc; - struct yp_node_list exceptions; - yp_location_t operator_loc; - struct yp_node *reference; - struct yp_statements_node *statements; - struct yp_rescue_node *consequent; -} yp_rescue_node_t; - -// RestParameterNode -typedef struct yp_rest_parameter_node { - yp_node_t base; - yp_location_t operator_loc; - yp_location_t name_loc; -} yp_rest_parameter_node_t; - -// RetryNode -typedef struct yp_retry_node { - yp_node_t base; -} yp_retry_node_t; - -// ReturnNode -typedef struct yp_return_node { - yp_node_t base; - yp_location_t keyword_loc; - struct yp_arguments_node *arguments; -} yp_return_node_t; - -// SelfNode -typedef struct yp_self_node { - yp_node_t base; -} yp_self_node_t; - -// SingletonClassNode -typedef struct yp_singleton_class_node { - yp_node_t base; - yp_constant_id_list_t locals; - yp_location_t class_keyword_loc; - yp_location_t operator_loc; - struct yp_node *expression; - struct yp_node *statements; - yp_location_t end_keyword_loc; -} yp_singleton_class_node_t; - -// SourceEncodingNode -typedef struct yp_source_encoding_node { - yp_node_t base; -} yp_source_encoding_node_t; - -// SourceFileNode -typedef struct yp_source_file_node { - yp_node_t base; - yp_string_t filepath; -} yp_source_file_node_t; - -// SourceLineNode -typedef struct yp_source_line_node { - yp_node_t base; -} yp_source_line_node_t; - -// SplatNode -typedef struct yp_splat_node { - yp_node_t base; - yp_location_t operator_loc; - struct yp_node *expression; -} yp_splat_node_t; - -// StatementsNode -typedef struct yp_statements_node { - yp_node_t base; - struct yp_node_list body; -} yp_statements_node_t; - -// StringConcatNode -typedef struct yp_string_concat_node { - yp_node_t base; - struct yp_node *left; - struct yp_node *right; -} yp_string_concat_node_t; - -// StringNode -typedef struct yp_string_node { - yp_node_t base; - yp_location_t opening_loc; - yp_location_t content_loc; - yp_location_t closing_loc; - yp_string_t unescaped; -} yp_string_node_t; - -// SuperNode -typedef struct yp_super_node { - yp_node_t base; - yp_location_t keyword_loc; - yp_location_t lparen_loc; - struct yp_arguments_node *arguments; - yp_location_t rparen_loc; - struct yp_block_node *block; -} yp_super_node_t; - -// SymbolNode -typedef struct yp_symbol_node { - yp_node_t base; - yp_location_t opening_loc; - yp_location_t value_loc; - yp_location_t closing_loc; - yp_string_t unescaped; -} yp_symbol_node_t; - -// TrueNode -typedef struct yp_true_node { - yp_node_t base; -} yp_true_node_t; - -// UndefNode -typedef struct yp_undef_node { - yp_node_t base; - struct yp_node_list names; - yp_location_t keyword_loc; -} yp_undef_node_t; - -// UnlessNode -typedef struct yp_unless_node { - yp_node_t base; - yp_location_t keyword_loc; - struct yp_node *predicate; - struct yp_statements_node *statements; - struct yp_else_node *consequent; - yp_location_t end_keyword_loc; -} yp_unless_node_t; - -// UntilNode -typedef struct yp_until_node { - yp_node_t base; - yp_location_t keyword_loc; - struct yp_node *predicate; - struct yp_statements_node *statements; -} yp_until_node_t; - -// WhenNode -typedef struct yp_when_node { - yp_node_t base; - yp_location_t keyword_loc; - struct yp_node_list conditions; - struct yp_statements_node *statements; -} yp_when_node_t; - -// WhileNode -typedef struct yp_while_node { - yp_node_t base; - yp_location_t keyword_loc; - struct yp_node *predicate; - struct yp_statements_node *statements; -} yp_while_node_t; - -// XStringNode -typedef struct yp_x_string_node { - yp_node_t base; - yp_location_t opening_loc; - yp_location_t content_loc; - yp_location_t closing_loc; - yp_string_t unescaped; -} yp_x_string_node_t; - -// YieldNode -typedef struct yp_yield_node { - yp_node_t base; - yp_location_t keyword_loc; - yp_location_t lparen_loc; - struct yp_arguments_node *arguments; - yp_location_t rparen_loc; -} yp_yield_node_t; - -// CallNodeFlags -typedef enum { - YP_CALL_NODE_FLAGS_SAFE_NAVIGATION = 1 << 1, - YP_CALL_NODE_FLAGS_VARIABLE_CALL = 1 << 2, -} yp_call_node_flags_t; - -// LoopFlags -typedef enum { - YP_LOOP_FLAGS_BEGIN_MODIFIER = 1 << 1, -} yp_loop_flags_t; - -// RangeFlags -typedef enum { - YP_RANGE_FLAGS_EXCLUDE_END = 1 << 1, -} yp_range_flags_t; - -// RegularExpressionFlags -typedef enum { - YP_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE = 1 << 1, - YP_REGULAR_EXPRESSION_FLAGS_MULTI_LINE = 1 << 2, - YP_REGULAR_EXPRESSION_FLAGS_EXTENDED = 1 << 3, - YP_REGULAR_EXPRESSION_FLAGS_EUC_JP = 1 << 4, - YP_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT = 1 << 5, - YP_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J = 1 << 6, - YP_REGULAR_EXPRESSION_FLAGS_UTF_8 = 1 << 7, - YP_REGULAR_EXPRESSION_FLAGS_ONCE = 1 << 8, -} yp_regular_expression_flags_t; - -#endif // YARP_AST_H diff --git a/yarp/config.yml b/yarp/config.yml new file mode 100644 index 00000000000000..8b33b6675d4233 --- /dev/null +++ b/yarp/config.yml @@ -0,0 +1,2171 @@ +tokens: + - name: EOF + value: 1 + comment: final token in the file + - name: MISSING + comment: "a token that was expected but not found" + - name: NOT_PROVIDED + comment: "a token that was not present but it is okay" + - name: AMPERSAND + comment: "&" + - name: AMPERSAND_AMPERSAND + comment: "&&" + - name: AMPERSAND_AMPERSAND_EQUAL + comment: "&&=" + - name: AMPERSAND_DOT + comment: "&." + - name: AMPERSAND_EQUAL + comment: "&=" + - name: BACKTICK + comment: "`" + - name: BACK_REFERENCE + comment: "a back reference" + - name: BANG + comment: "! or !@" + - name: BANG_EQUAL + comment: "!=" + - name: BANG_TILDE + comment: "!~" + - name: BRACE_LEFT + comment: "{" + - name: BRACE_RIGHT + comment: "}" + - name: BRACKET_LEFT + comment: "[" + - name: BRACKET_LEFT_ARRAY + comment: "[ for the beginning of an array" + - name: BRACKET_LEFT_RIGHT + comment: "[]" + - name: BRACKET_LEFT_RIGHT_EQUAL + comment: "[]=" + - name: BRACKET_RIGHT + comment: "]" + - name: CARET + comment: "^" + - name: CARET_EQUAL + comment: "^=" + - name: CHARACTER_LITERAL + comment: "a character literal" + - name: CLASS_VARIABLE + comment: "a class variable" + - name: COLON + comment: ":" + - name: COLON_COLON + comment: "::" + - name: COMMA + comment: "," + - name: COMMENT + comment: "a comment" + - name: CONSTANT + comment: "a constant" + - name: DOT + comment: "." + - name: DOT_DOT + comment: ".." + - name: DOT_DOT_DOT + comment: "..." + - name: EMBDOC_BEGIN + comment: "=begin" + - name: EMBDOC_END + comment: "=end" + - name: EMBDOC_LINE + comment: "a line inside of embedded documentation" + - name: EMBEXPR_BEGIN + comment: "#{" + - name: EMBEXPR_END + comment: "}" + - name: EMBVAR + comment: "#" + - name: EQUAL + comment: "=" + - name: EQUAL_EQUAL + comment: "==" + - name: EQUAL_EQUAL_EQUAL + comment: "===" + - name: EQUAL_GREATER + comment: "=>" + - name: EQUAL_TILDE + comment: "=~" + - name: FLOAT + comment: "a floating point number" + - name: FLOAT_IMAGINARY + comment: "a floating pointer number with an imaginary suffix" + - name: FLOAT_RATIONAL + comment: "a floating pointer number with a rational suffix" + - name: FLOAT_RATIONAL_IMAGINARY + comment: "a floating pointer number with a rational and imaginary suffix" + - name: GLOBAL_VARIABLE + comment: "a global variable" + - name: GREATER + comment: ">" + - name: GREATER_EQUAL + comment: ">=" + - name: GREATER_GREATER + comment: ">>" + - name: GREATER_GREATER_EQUAL + comment: ">>=" + - name: HEREDOC_END + comment: "the end of a heredoc" + - name: HEREDOC_START + comment: "the start of a heredoc" + - name: IDENTIFIER + comment: "an identifier" + - name: IGNORED_NEWLINE + comment: "an ignored newline" + - name: INSTANCE_VARIABLE + comment: "an instance variable" + - name: INTEGER + comment: "an integer (any base)" + - name: INTEGER_IMAGINARY + comment: "an integer with an imaginary suffix" + - name: INTEGER_RATIONAL + comment: "an integer with a rational suffix" + - name: INTEGER_RATIONAL_IMAGINARY + comment: "an integer with a rational and imaginary suffix" + - name: KEYWORD_ALIAS + comment: "alias" + - name: KEYWORD_AND + comment: "and" + - name: KEYWORD_BEGIN + comment: "begin" + - name: KEYWORD_BEGIN_UPCASE + comment: "BEGIN" + - name: KEYWORD_BREAK + comment: "break" + - name: KEYWORD_CASE + comment: "case" + - name: KEYWORD_CLASS + comment: "class" + - name: KEYWORD_DEF + comment: "def" + - name: KEYWORD_DEFINED + comment: "defined?" + - name: KEYWORD_DO + comment: "do" + - name: KEYWORD_DO_LOOP + comment: "do keyword for a predicate in a while, until, or for loop" + - name: KEYWORD_ELSE + comment: "else" + - name: KEYWORD_ELSIF + comment: "elsif" + - name: KEYWORD_END + comment: "end" + - name: KEYWORD_END_UPCASE + comment: "END" + - name: KEYWORD_ENSURE + comment: "ensure" + - name: KEYWORD_FALSE + comment: "false" + - name: KEYWORD_FOR + comment: "for" + - name: KEYWORD_IF + comment: "if" + - name: KEYWORD_IF_MODIFIER + comment: "if in the modifier form" + - name: KEYWORD_IN + comment: "in" + - name: KEYWORD_MODULE + comment: "module" + - name: KEYWORD_NEXT + comment: "next" + - name: KEYWORD_NIL + comment: "nil" + - name: KEYWORD_NOT + comment: "not" + - name: KEYWORD_OR + comment: "or" + - name: KEYWORD_REDO + comment: "redo" + - name: KEYWORD_RESCUE + comment: "rescue" + - name: KEYWORD_RESCUE_MODIFIER + comment: "rescue in the modifier form" + - name: KEYWORD_RETRY + comment: "retry" + - name: KEYWORD_RETURN + comment: "return" + - name: KEYWORD_SELF + comment: "self" + - name: KEYWORD_SUPER + comment: "super" + - name: KEYWORD_THEN + comment: "then" + - name: KEYWORD_TRUE + comment: "true" + - name: KEYWORD_UNDEF + comment: "undef" + - name: KEYWORD_UNLESS + comment: "unless" + - name: KEYWORD_UNLESS_MODIFIER + comment: "unless in the modifier form" + - name: KEYWORD_UNTIL + comment: "until" + - name: KEYWORD_UNTIL_MODIFIER + comment: "until in the modifier form" + - name: KEYWORD_WHEN + comment: "when" + - name: KEYWORD_WHILE + comment: "while" + - name: KEYWORD_WHILE_MODIFIER + comment: "while in the modifier form" + - name: KEYWORD_YIELD + comment: "yield" + - name: KEYWORD___ENCODING__ + comment: "__ENCODING__" + - name: KEYWORD___FILE__ + comment: "__FILE__" + - name: KEYWORD___LINE__ + comment: "__LINE__" + - name: LABEL + comment: "a label" + - name: LABEL_END + comment: "the end of a label" + - name: LAMBDA_BEGIN + comment: "{" + - name: LESS + comment: "<" + - name: LESS_EQUAL + comment: "<=" + - name: LESS_EQUAL_GREATER + comment: "<=>" + - name: LESS_LESS + comment: "<<" + - name: LESS_LESS_EQUAL + comment: "<<=" + - name: MINUS + comment: "-" + - name: MINUS_EQUAL + comment: "-=" + - name: MINUS_GREATER + comment: "->" + - name: NEWLINE + comment: "a newline character outside of other tokens" + - name: NUMBERED_REFERENCE + comment: "a numbered reference to a capture group in the previous regular expression match" + - name: PARENTHESIS_LEFT + comment: "(" + - name: PARENTHESIS_LEFT_PARENTHESES + comment: "( for a parentheses node" + - name: PARENTHESIS_RIGHT + comment: ")" + - name: PERCENT + comment: "%" + - name: PERCENT_EQUAL + comment: "%=" + - name: PERCENT_LOWER_I + comment: "%i" + - name: PERCENT_LOWER_W + comment: "%w" + - name: PERCENT_LOWER_X + comment: "%x" + - name: PERCENT_UPPER_I + comment: "%I" + - name: PERCENT_UPPER_W + comment: "%W" + - name: PIPE + comment: "|" + - name: PIPE_EQUAL + comment: "|=" + - name: PIPE_PIPE + comment: "||" + - name: PIPE_PIPE_EQUAL + comment: "||=" + - name: PLUS + comment: "+" + - name: PLUS_EQUAL + comment: "+=" + - name: QUESTION_MARK + comment: "?" + - name: REGEXP_BEGIN + comment: "the beginning of a regular expression" + - name: REGEXP_END + comment: "the end of a regular expression" + - name: SEMICOLON + comment: ";" + - name: SLASH + comment: "/" + - name: SLASH_EQUAL + comment: "/=" + - name: STAR + comment: "*" + - name: STAR_EQUAL + comment: "*=" + - name: STAR_STAR + comment: "**" + - name: STAR_STAR_EQUAL + comment: "**=" + - name: STRING_BEGIN + comment: "the beginning of a string" + - name: STRING_CONTENT + comment: "the contents of a string" + - name: STRING_END + comment: "the end of a string" + - name: SYMBOL_BEGIN + comment: "the beginning of a symbol" + - name: TILDE + comment: "~ or ~@" + - name: UAMPERSAND + comment: "unary &" + - name: UCOLON_COLON + comment: "unary ::" + - name: UDOT_DOT + comment: "unary .." + - name: UDOT_DOT_DOT + comment: "unary ..." + - name: UMINUS + comment: "-@" + - name: UMINUS_NUM + comment: "-@ for a number" + - name: UPLUS + comment: "+@" + - name: USTAR + comment: "unary *" + - name: USTAR_STAR + comment: "unary **" + - name: WORDS_SEP + comment: "a separator between words in a list" + - name: __END__ + comment: "marker for the point in the file at which the parser should stop" +flags: + - name: CallNodeFlags + values: + - name: SAFE_NAVIGATION + comment: "&. operator" + - name: VARIABLE_CALL + comment: "a call that could have been a local variable" + - name: LoopFlags + values: + - name: BEGIN_MODIFIER + comment: "a loop after a begin statement, so the body is executed first before the condition" + - name: RangeFlags + values: + - name: EXCLUDE_END + comment: "... operator" + - name: RegularExpressionFlags + values: + - name: IGNORE_CASE + comment: "i - ignores the case of characters when matching" + - name: MULTI_LINE + comment: "m - allows $ to match the end of lines within strings" + - name: EXTENDED + comment: "x - ignores whitespace and allows comments in regular expressions" + - name: EUC_JP + comment: "e - forces the EUC-JP encoding" + - name: ASCII_8BIT + comment: "n - forces the ASCII-8BIT encoding" + - name: WINDOWS_31J + comment: "s - forces the Windows-31J encoding" + - name: UTF_8 + comment: "u - forces the UTF-8 encoding" + - name: ONCE + comment: "o - only interpolates values into the regular expression once" +nodes: + - name: AliasNode + child_nodes: + - name: new_name + type: node + - name: old_name + type: node + - name: keyword_loc + type: location + comment: | + Represents the use of the `alias` keyword. + + alias foo bar + ^^^^^^^^^^^^^ + - name: AlternationPatternNode + child_nodes: + - name: left + type: node + - name: right + type: node + - name: operator_loc + type: location + comment: | + Represents an alternation pattern in pattern matching. + + foo => bar | baz + ^^^^^^^^^ + - name: AndNode + child_nodes: + - name: left + type: node + - name: right + type: node + - name: operator_loc + type: location + comment: | + Represents the use of the `&&` operator or the `and` keyword. + + left and right + ^^^^^^^^^^^^^^ + - name: ArgumentsNode + child_nodes: + - name: arguments + type: node[] + comment: | + Represents a set of arguments to a method or a keyword. + + return foo, bar, baz + ^^^^^^^^^^^^^ + - name: ArrayNode + child_nodes: + - name: elements + type: node[] + - name: opening_loc + type: location? + - name: closing_loc + type: location? + comment: | + Represents an array literal. This can be a regular array using brackets or + a special array using % like %w or %i. + + [1, 2, 3] + ^^^^^^^^^ + - name: ArrayPatternNode + child_nodes: + - name: constant + type: node? + - name: requireds + type: node[] + - name: rest + type: node? + - name: posts + type: node[] + - name: opening_loc + type: location? + - name: closing_loc + type: location? + comment: | + Represents an array pattern in pattern matching. + + foo in 1, 2 + ^^^^^^^^^^^ + + foo in [1, 2] + ^^^^^^^^^^^^^ + + foo in *1 + ^^^^^^^^^ + + foo in Bar[] + ^^^^^^^^^^^^ + + foo in Bar[1, 2, 3] + ^^^^^^^^^^^^^^^^^^^ + - name: AssocNode + child_nodes: + - name: key + type: node + - name: value + type: node? + - name: operator_loc + type: location? + comment: | + Represents a hash key/value pair. + + { a => b } + ^^^^^^ + - name: AssocSplatNode + child_nodes: + - name: value + type: node? + - name: operator_loc + type: location + comment: | + Represents a splat in a hash literal. + + { **foo } + ^^^^^ + - name: BackReferenceReadNode + comment: | + Represents reading a reference to a field in the previous match. + + $' + ^^ + - name: BeginNode + child_nodes: + - name: begin_keyword_loc + type: location? + - name: statements + type: node? + kind: StatementsNode + - name: rescue_clause + type: node? + kind: RescueNode + - name: else_clause + type: node? + kind: ElseNode + - name: ensure_clause + type: node? + kind: EnsureNode + - name: end_keyword_loc + type: location? + newline: false + comment: | + Represents a begin statement. + + begin + foo + end + ^^^^^ + - name: BlockArgumentNode + child_nodes: + - name: expression + type: node? + - name: operator_loc + type: location + comment: | + Represents block method arguments. + + bar(&args) + ^^^^^^^^^^ + - name: BlockNode + child_nodes: + - name: locals + type: constant[] + - name: parameters + type: node? + kind: BlockParametersNode + - name: statements + type: node? + - name: opening_loc + type: location + - name: closing_loc + type: location + comment: | + Represents a block of ruby code. + + [1, 2, 3].each { |i| puts x } + ^^^^^^^^^^^^^^ + - name: BlockParameterNode + child_nodes: + - name: name_loc + type: location? + - name: operator_loc + type: location + comment: | + Represents a block parameter to a method, block, or lambda definition. + + def a(&b) + ^^ + end + - name: BlockParametersNode + child_nodes: + - name: parameters + type: node? + kind: ParametersNode + - name: locals + type: location[] + - name: opening_loc + type: location? + - name: closing_loc + type: location? + comment: | + Represents a block's parameters declaration. + + -> (a, b = 1; local) { } + ^^^^^^^^^^^^^^^^^ + + foo do |a, b = 1; local| + ^^^^^^^^^^^^^^^^^ + end + - name: BreakNode + child_nodes: + - name: arguments + type: node? + kind: ArgumentsNode + - name: keyword_loc + type: location + comment: | + Represents the use of the `break` keyword. + + break foo + ^^^^^^^^^ + - name: CallNode + child_nodes: + - name: receiver + type: node? + - name: operator_loc + type: location? + - name: message_loc + type: location? + - name: opening_loc + type: location? + - name: arguments + type: node? + kind: ArgumentsNode + - name: closing_loc + type: location? + - name: block + type: node? + kind: BlockNode + - name: flags + type: flags + kind: CallNodeFlags + - name: name + type: string + comment: | + Represents a method call, in all of the various forms that can take. + + foo + ^^^ + + foo() + ^^^^^ + + +foo + ^^^^ + + foo + bar + ^^^^^^^^^ + + foo.bar + ^^^^^^^ + + foo&.bar + ^^^^^^^^ + - name: CallOperatorAndWriteNode + child_nodes: + - name: target + type: node + kind: CallNode + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `&&=` operator on a call. + + foo.bar &&= value + ^^^^^^^^^^^^^^^^^ + - name: CallOperatorOrWriteNode + child_nodes: + - name: target + type: node + kind: CallNode + - name: value + type: node + - name: operator_loc + type: location + comment: | + Represents the use of the `||=` operator on a call. + + foo.bar ||= value + ^^^^^^^^^^^^^^^^^ + - name: CallOperatorWriteNode + child_nodes: + - name: target + type: node + kind: CallNode + - name: operator_loc + type: location + - name: value + type: node + - name: operator_id + type: constant + comment: | + Represents the use of an assignment operator on a call. + + foo.bar += baz + ^^^^^^^^^^^^^^ + - name: CapturePatternNode + child_nodes: + - name: value + type: node + - name: target + type: node + - name: operator_loc + type: location + comment: | + Represents assigning to a local variable in pattern matching. + + foo => [bar => baz] + ^^^^^^^^^^^^ + - name: CaseNode + child_nodes: + - name: predicate + type: node? + - name: conditions + type: node[] + - name: consequent + type: node? + kind: ElseNode + - name: case_keyword_loc + type: location + - name: end_keyword_loc + type: location + comment: | + Represents the use of a case statement. + + case true + ^^^^^^^^^ + when false + end + - name: ClassNode + child_nodes: + - name: locals + type: constant[] + - name: class_keyword_loc + type: location + - name: constant_path + type: node + - name: inheritance_operator_loc + type: location? + - name: superclass + type: node? + - name: statements + type: node? + - name: end_keyword_loc + type: location + comment: | + Represents a class declaration involving the `class` keyword. + + class Foo end + ^^^^^^^^^^^^^ + - name: ClassVariableOperatorAndWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `&&=` operator for assignment to a class variable. + + @@target &&= value + ^^^^^^^^^^^^^^^^ + - name: ClassVariableOperatorOrWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `||=` operator for assignment to a class variable. + + @@target ||= value + ^^^^^^^^^^^^^^^^^^ + - name: ClassVariableOperatorWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + - name: operator + type: constant + comment: | + Represents assigning to a class variable using an operator that isn't `=`. + + @@target += value + ^^^^^^^^^^^^^^^^^ + - name: ClassVariableReadNode + comment: | + Represents referencing a class variable. + + @@foo + ^^^^^ + - name: ClassVariableWriteNode + child_nodes: + - name: name_loc + type: location + - name: value + type: node? + - name: operator_loc + type: location? + comment: | + Represents writing to a class variable. + + @@foo = 1 + ^^^^^^^^^ + - name: ConstantOperatorAndWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `&&=` operator for assignment to a constant. + + Target &&= value + ^^^^^^^^^^^^^^^^ + - name: ConstantOperatorOrWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `||=` operator for assignment to a constant. + + Target ||= value + ^^^^^^^^^^^^^^^^ + - name: ConstantOperatorWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + - name: operator + type: constant + comment: | + Represents assigning to a constant using an operator that isn't `=`. + + Target += value + ^^^^^^^^^^^^^^^ + - name: ConstantPathNode + child_nodes: + - name: parent + type: node? + - name: child + type: node + - name: delimiter_loc + type: location + comment: | + Represents accessing a constant through a path of `::` operators. + + Foo::Bar + ^^^^^^^^ + - name: ConstantPathOperatorAndWriteNode + child_nodes: + - name: target + type: node + kind: ConstantPathNode + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `&&=` operator for assignment to a constant path. + + Parent::Child &&= value + ^^^^^^^^^^^^^^^^^^^^^^^ + - name: ConstantPathOperatorOrWriteNode + child_nodes: + - name: target + type: node + kind: ConstantPathNode + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `||=` operator for assignment to a constant path. + + Parent::Child ||= value + ^^^^^^^^^^^^^^^^^^^^^^^ + - name: ConstantPathOperatorWriteNode + child_nodes: + - name: target + type: node + kind: ConstantPathNode + - name: operator_loc + type: location + - name: value + type: node + - name: operator + type: constant + comment: | + Represents assigning to a constant path using an operator that isn't `=`. + + Parent::Child += value + ^^^^^^^^^^^^^^^^^^^^^^ + - name: ConstantPathWriteNode + child_nodes: + - name: target + type: node + kind: ConstantPathNode + - name: operator_loc + type: location? + - name: value + type: node? + comment: | + Represents writing to a constant path. + + ::Foo = 1 + ^^^^^^^^^ + + Foo::Bar = 1 + ^^^^^^^^^^^^ + + ::Foo::Bar = 1 + ^^^^^^^^^^^^^^ + - name: ConstantReadNode + comment: | + Represents referencing a constant. + + Foo + ^^^ + - name: ConstantWriteNode + child_nodes: + - name: name_loc + type: location + - name: value + type: node? + - name: operator_loc + type: location? + comment: | + Represents writing to a constant. + + Foo = 1 + ^^^^^^^ + - name: DefNode + child_nodes: + - name: name_loc + type: location + - name: receiver + type: node? + - name: parameters + type: node? + kind: ParametersNode + - name: statements + type: node? + - name: locals + type: constant[] + - name: def_keyword_loc + type: location + - name: operator_loc + type: location? + - name: lparen_loc + type: location? + - name: rparen_loc + type: location? + - name: equal_loc + type: location? + - name: end_keyword_loc + type: location? + comment: | + Represents a method definition. + + def method + end + ^^^^^^^^^^ + - name: DefinedNode + child_nodes: + - name: lparen_loc + type: location? + - name: value + type: node + - name: rparen_loc + type: location? + - name: keyword_loc + type: location + comment: | + Represents the use of the `defined?` keyword. + + defined?(a) + ^^^^^^^^^^^ + - name: ElseNode + child_nodes: + - name: else_keyword_loc + type: location + - name: statements + type: node? + kind: StatementsNode + - name: end_keyword_loc + type: location? + comment: | + Represents an `else` clause in a `case`, `if`, or `unless` statement. + + if a then b else c end + ^^^^^^^^^^ + - name: EmbeddedStatementsNode + child_nodes: + - name: opening_loc + type: location + - name: statements + type: node? + kind: StatementsNode + - name: closing_loc + type: location + comment: | + Represents an interpolated set of statements. + + "foo #{bar}" + ^^^^^^ + - name: EmbeddedVariableNode + child_nodes: + - name: operator_loc + type: location + - name: variable + type: node + comment: | + Represents an interpolated variable. + + "foo #@bar" + ^^^^^ + - name: EnsureNode + child_nodes: + - name: ensure_keyword_loc + type: location + - name: statements + type: node? + kind: StatementsNode + - name: end_keyword_loc + type: location + comment: | + Represents an `ensure` clause in a `begin` statement. + + begin + foo + ensure + ^^^^^^ + bar + end + - name: FalseNode + comment: | + Represents the use of the literal `false` keyword. + + false + ^^^^^ + - name: FindPatternNode + child_nodes: + - name: constant + type: node? + - name: left + type: node + - name: requireds + type: node[] + - name: right + type: node + - name: opening_loc + type: location? + - name: closing_loc + type: location? + comment: | + Represents a find pattern in pattern matching. + + foo in *bar, baz, *qux + ^^^^^^^^^^^^^^^^^^^^^^ + + foo in [*bar, baz, *qux] + ^^^^^^^^^^^^^^^^^^^^^^^^ + + foo in Foo(*bar, baz, *qux) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + - name: FlipFlopNode + child_nodes: + - name: left + type: node? + - name: right + type: node? + - name: operator_loc + type: location + - name: flags + type: flags + kind: RangeFlags + comment: | + Represents the use of the `..` or `...` operators to create flip flops. + + baz if foo .. bar + ^^^^^^^^^^ + - name: FloatNode + comment: | + Represents a floating point number literal. + + 1.0 + ^^^ + - name: ForNode + child_nodes: + - name: index + type: node + - name: collection + type: node + - name: statements + type: node? + kind: StatementsNode + - name: for_keyword_loc + type: location + - name: in_keyword_loc + type: location + - name: do_keyword_loc + type: location? + - name: end_keyword_loc + type: location + comment: | + Represents the use of the `for` keyword. + + for i in a end + ^^^^^^^^^^^^^^ + - name: ForwardingArgumentsNode + comment: | + Represents forwarding all arguments to this method to another method. + + def foo(...) + bar(...) + ^^^^^^^^ + end + - name: ForwardingParameterNode + comment: | + Represents the use of the forwarding parameter in a method, block, or lambda declaration. + + def foo(...) + ^^^ + end + - name: ForwardingSuperNode + child_nodes: + - name: block + type: node? + kind: BlockNode + comment: | + Represents the use of the `super` keyword without parentheses or arguments. + + super + ^^^^^ + - name: GlobalVariableOperatorAndWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `&&=` operator for assignment to a global variable. + + $target &&= value + ^^^^^^^^^^^^^^^^^ + - name: GlobalVariableOperatorOrWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `||=` operator for assignment to a global variable. + + $target ||= value + ^^^^^^^^^^^^^^^^^ + - name: GlobalVariableOperatorWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + - name: operator + type: constant + comment: | + Represents assigning to a global variable using an operator that isn't `=`. + + $target += value + ^^^^^^^^^^^^^^^^ + - name: GlobalVariableReadNode + comment: | + Represents referencing a global variable. + + $foo + ^^^^ + - name: GlobalVariableWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location? + - name: value + type: node? + comment: | + Represents writing to a global variable. + + $foo = 1 + ^^^^^^^^ + - name: HashNode + child_nodes: + - name: opening_loc + type: location + - name: elements + type: node[] + - name: closing_loc + type: location + comment: | + Represents a hash literal. + + { a => b } + ^^^^^^^^^^ + - name: HashPatternNode + child_nodes: + - name: constant + type: node? + - name: assocs + type: node[] + - name: kwrest + type: node? + - name: opening_loc + type: location? + - name: closing_loc + type: location? + comment: | + Represents a hash pattern in pattern matching. + + foo => { a: 1, b: 2 } + ^^^^^^^^^^^^^^ + + foo => { a: 1, b: 2, **c } + ^^^^^^^^^^^^^^^^^^^ + - name: IfNode + child_nodes: + - name: if_keyword_loc + type: location? + - name: predicate + type: node + - name: statements + type: node? + kind: StatementsNode + - name: consequent + type: node? + - name: end_keyword_loc + type: location? + newline: predicate + comment: | + Represents the use of the `if` keyword, either in the block form or the modifier form. + + bar if foo + ^^^^^^^^^^ + + if foo then bar end + ^^^^^^^^^^^^^^^^^^^ + - name: ImaginaryNode + child_nodes: + - name: numeric + type: node + comment: | + Represents an imaginary number literal. + + 1.0i + ^^^^ + - name: InNode + child_nodes: + - name: pattern + type: node + - name: statements + type: node? + kind: StatementsNode + - name: in_loc + type: location + - name: then_loc + type: location? + comment: | + Represents the use of the `in` keyword in a case statement. + + case a; in b then c end + ^^^^^^^^^^^ + - name: InstanceVariableOperatorAndWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `&&=` operator for assignment to an instance variable. + + @target &&= value + ^^^^^^^^^^^^^^^^^ + - name: InstanceVariableOperatorOrWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `||=` operator for assignment to an instance variable. + + @target ||= value + ^^^^^^^^^^^^^^^^^ + - name: InstanceVariableOperatorWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + - name: operator + type: constant + comment: | + Represents assigning to an instance variable using an operator that isn't `=`. + + @target += value + ^^^^^^^^^^^^^^^^ + - name: InstanceVariableReadNode + comment: | + Represents referencing an instance variable. + + @foo + ^^^^ + - name: InstanceVariableWriteNode + child_nodes: + - name: name_loc + type: location + - name: value + type: node? + - name: operator_loc + type: location? + comment: | + Represents writing to an instance variable. + + @foo = 1 + ^^^^^^^^ + - name: IntegerNode + comment: | + Represents an integer number literal. + + 1 + ^ + - name: InterpolatedRegularExpressionNode + child_nodes: + - name: opening_loc + type: location + - name: parts + type: node[] + - name: closing_loc + type: location + - name: flags + type: flags + kind: RegularExpressionFlags + newline: parts + comment: | + Represents a regular expression literal that contains interpolation. + + /foo #{bar} baz/ + ^^^^^^^^^^^^^^^^ + - name: InterpolatedStringNode + child_nodes: + - name: opening_loc + type: location? + - name: parts + type: node[] + - name: closing_loc + type: location? + newline: parts + comment: | + Represents a string literal that contains interpolation. + + "foo #{bar} baz" + ^^^^^^^^^^^^^^^^ + - name: InterpolatedSymbolNode + child_nodes: + - name: opening_loc + type: location? + - name: parts + type: node[] + - name: closing_loc + type: location? + newline: parts + comment: | + Represents a symbol literal that contains interpolation. + + :"foo #{bar} baz" + ^^^^^^^^^^^^^^^^^ + - name: InterpolatedXStringNode + child_nodes: + - name: opening_loc + type: location + - name: parts + type: node[] + - name: closing_loc + type: location + newline: parts + comment: | + Represents an xstring literal that contains interpolation. + + `foo #{bar} baz` + ^^^^^^^^^^^^^^^^ + - name: KeywordHashNode + child_nodes: + - name: elements + type: node[] + comment: | + Represents a hash literal without opening and closing braces. + + foo(a: b) + ^^^^ + - name: KeywordParameterNode + child_nodes: + - name: name_loc + type: location + - name: value + type: node? + comment: | + Represents a keyword parameter to a method, block, or lambda definition. + + def a(b:) + ^^ + end + + def a(b: 1) + ^^^^ + end + - name: KeywordRestParameterNode + child_nodes: + - name: operator_loc + type: location + - name: name_loc + type: location? + comment: | + Represents a keyword rest parameter to a method, block, or lambda definition. + + def a(**b) + ^^^ + end + - name: LambdaNode + child_nodes: + - name: locals + type: constant[] + - name: opening_loc + type: location + - name: parameters + type: node? + kind: BlockParametersNode + - name: statements + type: node? + comment: | + Represents using a lambda literal (not the lambda method call). + + ->(value) { value * 2 } + ^^^^^^^^^^^^^^^^^^^^^^^ + - name: LocalVariableOperatorAndWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + - name: constant_id + type: constant + comment: | + Represents the use of the `&&=` operator for assignment to a local variable. + + target &&= value + ^^^^^^^^^^^^^^^^ + - name: LocalVariableOperatorOrWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + - name: constant_id + type: constant + comment: | + Represents the use of the `||=` operator for assignment to a local variable. + + target ||= value + ^^^^^^^^^^^^^^^^ + - name: LocalVariableOperatorWriteNode + child_nodes: + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + - name: constant_id + type: constant + - name: operator_id + type: constant + comment: | + Represents assigning to a local variable using an operator that isn't `=`. + + target += value + ^^^^^^^^^^^^^^^ + - name: LocalVariableReadNode + child_nodes: + - name: constant_id + type: constant + - name: depth + type: uint32 + comment: | + Represents reading a local variable. Note that this requires that a local + variable of the same name has already been written to in the same scope, + otherwise it is parsed as a method call. + + foo + ^^^ + - name: LocalVariableWriteNode + child_nodes: + - name: constant_id + type: constant + - name: depth + type: uint32 + - name: value + type: node? + - name: name_loc + type: location + - name: operator_loc + type: location? + comment: | + Represents writing to a local variable. + + foo = 1 + ^^^^^^^ + - name: MatchPredicateNode + child_nodes: + - name: value + type: node + - name: pattern + type: node + - name: operator_loc + type: location + comment: | + Represents the use of the modifier `in` operator. + + foo in bar + ^^^^^^^^^^ + - name: MatchRequiredNode + child_nodes: + - name: value + type: node + - name: pattern + type: node + - name: operator_loc + type: location + comment: | + Represents the use of the `=>` operator. + + foo => bar + ^^^^^^^^^^ + - name: MissingNode + comment: | + Represents a node that is missing from the source and results in a syntax + error. + - name: ModuleNode + child_nodes: + - name: locals + type: constant[] + - name: module_keyword_loc + type: location + - name: constant_path + type: node + - name: statements + type: node? + - name: end_keyword_loc + type: location + comment: | + Represents a module declaration involving the `module` keyword. + + module Foo end + ^^^^^^^^^^^^^^ + - name: MultiWriteNode + child_nodes: + - name: targets + type: node[] + - name: operator_loc + type: location? + - name: value + type: node? + - name: lparen_loc + type: location? + - name: rparen_loc + type: location? + comment: | + Represents a multi-target expression. + + a, b, c = 1, 2, 3 + ^^^^^^^^^^^^^^^^^ + - name: NextNode + child_nodes: + - name: arguments + type: node? + kind: ArgumentsNode + - name: keyword_loc + type: location + comment: | + Represents the use of the `next` keyword. + + next 1 + ^^^^^^ + - name: NilNode + comment: | + Represents the use of the `nil` keyword. + + nil + ^^^ + - name: NoKeywordsParameterNode + child_nodes: + - name: operator_loc + type: location + - name: keyword_loc + type: location + comment: | + Represents the use of `**nil` inside method arguments. + + def a(**nil) + ^^^^^ + end + - name: NumberedReferenceReadNode + comment: | + Represents reading a numbered reference to a capture in the previous match. + + $1 + ^^ + - name: OptionalParameterNode + child_nodes: + - name: constant_id + type: constant + - name: name_loc + type: location + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents an optional parameter to a method, block, or lambda definition. + + def a(b = 1) + ^^^^^ + end + - name: OrNode + child_nodes: + - name: left + type: node + - name: right + type: node + - name: operator_loc + type: location + comment: | + Represents the use of the `||` operator or the `or` keyword. + + left or right + ^^^^^^^^^^^^^ + - name: ParametersNode + child_nodes: + - name: requireds + type: node[] + - name: optionals + type: node[] + - name: posts + type: node[] + - name: rest + type: node? + kind: RestParameterNode + - name: keywords + type: node[] + - name: keyword_rest + type: node? + - name: block + type: node? + kind: BlockParameterNode + comment: | + Represents the list of parameters on a method, block, or lambda definition. + + def a(b, c, d) + ^^^^^^^ + end + - name: ParenthesesNode + child_nodes: + - name: statements + type: node? + - name: opening_loc + type: location + - name: closing_loc + type: location + newline: false + comment: | + Represents a parenthesized expression + + (10 + 34) + ^^^^^^^^^ + - name: PinnedExpressionNode + child_nodes: + - name: expression + type: node + - name: operator_loc + type: location + - name: lparen_loc + type: location + - name: rparen_loc + type: location + comment: | + Represents the use of the `^` operator for pinning an expression in a + pattern matching expression. + + foo in ^(bar) + ^^^^^^ + - name: PinnedVariableNode + child_nodes: + - name: variable + type: node + - name: operator_loc + type: location + comment: | + Represents the use of the `^` operator for pinning a variable in a pattern + matching expression. + + foo in ^bar + ^^^^ + - name: PostExecutionNode + child_nodes: + - name: statements + type: node? + kind: StatementsNode + - name: keyword_loc + type: location + - name: opening_loc + type: location + - name: closing_loc + type: location + comment: | + Represents the use of the `END` keyword. + + END { foo } + ^^^^^^^^^^^ + - name: PreExecutionNode + child_nodes: + - name: statements + type: node? + kind: StatementsNode + - name: keyword_loc + type: location + - name: opening_loc + type: location + - name: closing_loc + type: location + comment: | + Represents the use of the `BEGIN` keyword. + + BEGIN { foo } + ^^^^^^^^^^^^^ + - name: ProgramNode + child_nodes: + - name: locals + type: constant[] + - name: statements + type: node + kind: StatementsNode + comment: The top level node of any parse tree. + - name: RangeNode + child_nodes: + - name: left + type: node? + - name: right + type: node? + - name: operator_loc + type: location + - name: flags + type: flags + kind: RangeFlags + comment: | + Represents the use of the `..` or `...` operators. + + 1..2 + ^^^^ + + c if a =~ /left/ ... b =~ /right/ + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + - name: RationalNode + child_nodes: + - name: numeric + type: node + comment: | + Represents a rational number literal. + + 1.0r + ^^^^ + - name: RedoNode + comment: | + Represents the use of the `redo` keyword. + + redo + ^^^^ + - name: RegularExpressionNode + child_nodes: + - name: opening_loc + type: location + - name: content_loc + type: location + - name: closing_loc + type: location + - name: unescaped + type: string + - name: flags + type: flags + kind: RegularExpressionFlags + comment: | + Represents a regular expression literal with no interpolation. + + /foo/i + ^^^^^^ + - name: RequiredDestructuredParameterNode + child_nodes: + - name: parameters + type: node[] + - name: opening_loc + type: location + - name: closing_loc + type: location + comment: | + Represents a destructured required parameter node. + + def foo((bar, baz)) + ^^^^^^^^^^ + end + - name: RequiredParameterNode + child_nodes: + - name: constant_id + type: constant + comment: | + Represents a required parameter to a method, block, or lambda definition. + + def a(b) + ^ + end + - name: RescueModifierNode + child_nodes: + - name: expression + type: node + - name: keyword_loc + type: location + - name: rescue_expression + type: node + newline: expression + comment: | + Represents an expression modified with a rescue. + + foo rescue nil + ^^^^^^^^^^^^^^ + - name: RescueNode + child_nodes: + - name: keyword_loc + type: location + - name: exceptions + type: node[] + - name: operator_loc + type: location? + - name: reference + type: node? + - name: statements + type: node? + kind: StatementsNode + - name: consequent + type: node? + kind: RescueNode + comment: | + Represents a rescue statement. + + begin + rescue Foo, *splat, Bar => ex + ^^^^^^ + foo + end + + `Foo, *splat, Bar` are in the `exceptions` field. + `ex` is in the `exception` field. + - name: RestParameterNode + child_nodes: + - name: operator_loc + type: location + - name: name_loc + type: location? + comment: | + Represents a rest parameter to a method, block, or lambda definition. + + def a(*b) + ^^ + end + - name: RetryNode + comment: | + Represents the use of the `retry` keyword. + + retry + ^^^^^ + - name: ReturnNode + child_nodes: + - name: keyword_loc + type: location + - name: arguments + type: node? + kind: ArgumentsNode + comment: | + Represents the use of the `return` keyword. + + return 1 + ^^^^^^^^ + - name: SelfNode + comment: | + Represents the `self` keyword. + + self + ^^^^ + - name: SingletonClassNode + child_nodes: + - name: locals + type: constant[] + - name: class_keyword_loc + type: location + - name: operator_loc + type: location + - name: expression + type: node + - name: statements + type: node? + - name: end_keyword_loc + type: location + comment: | + Represents a singleton class declaration involving the `class` keyword. + + class << self end + ^^^^^^^^^^^^^^^^^ + - name: SourceEncodingNode + comment: | + Represents the use of the `__ENCODING__` keyword. + + __ENCODING__ + ^^^^^^^^^^^^ + - name: SourceFileNode + is_migrated: true + child_nodes: + - name: filepath + type: string + comment: | + Represents the use of the `__FILE__` keyword. + + __FILE__ + ^^^^^^^^ + - name: SourceLineNode + comment: | + Represents the use of the `__LINE__` keyword. + + __LINE__ + ^^^^^^^^ + - name: SplatNode + child_nodes: + - name: operator_loc + type: location + - name: expression + type: node? + comment: | + Represents the use of the splat operator. + + [*a] + ^^ + - name: StatementsNode + child_nodes: + - name: body + type: node[] + comment: | + Represents a set of statements contained within some scope. + + foo; bar; baz + ^^^^^^^^^^^^^ + - name: StringConcatNode + child_nodes: + - name: left + type: node + - name: right + type: node + comment: | + Represents the use of compile-time string concatenation. + + "foo" "bar" + ^^^^^^^^^^^ + - name: StringNode + child_nodes: + - name: opening_loc + type: location? + - name: content_loc + type: location + - name: closing_loc + type: location? + - name: unescaped + type: string + comment: | + Represents a string literal, a string contained within a `%w` list, or + plain string content within an interpolated string. + + "foo" + ^^^^^ + + %w[foo] + ^^^ + + "foo #{bar} baz" + ^^^^ ^^^^ + - name: SuperNode + child_nodes: + - name: keyword_loc + type: location + - name: lparen_loc + type: location? + - name: arguments + type: node? + kind: ArgumentsNode + - name: rparen_loc + type: location? + - name: block + type: node? + kind: BlockNode + comment: | + Represents the use of the `super` keyword with parentheses or arguments. + + super() + ^^^^^^^ + + super foo, bar + ^^^^^^^^^^^^^^ + - name: SymbolNode + child_nodes: + - name: opening_loc + type: location? + - name: value_loc + type: location + - name: closing_loc + type: location? + - name: unescaped + type: string + comment: | + Represents a symbol literal or a symbol contained within a `%i` list. + + :foo + ^^^^ + + %i[foo] + ^^^ + - name: TrueNode + comment: | + Represents the use of the literal `true` keyword. + + true + ^^^^ + - name: UndefNode + child_nodes: + - name: names + type: node[] + - name: keyword_loc + type: location + comment: | + Represents the use of the `undef` keyword. + + undef :foo, :bar, :baz + ^^^^^^^^^^^^^^^^^^^^^^ + - name: UnlessNode + child_nodes: + - name: keyword_loc + type: location + - name: predicate + type: node + - name: statements + type: node? + kind: StatementsNode + - name: consequent + type: node? + kind: ElseNode + - name: end_keyword_loc + type: location? + newline: predicate + comment: | + Represents the use of the `unless` keyword, either in the block form or the modifier form. + + bar unless foo + ^^^^^^^^^^^^^^ + + unless foo then bar end + ^^^^^^^^^^^^^^^^^^^^^^^ + - name: UntilNode + child_nodes: + - name: keyword_loc + type: location + - name: predicate + type: node + - name: statements + type: node? + kind: StatementsNode + - name: flags + type: flags + kind: LoopFlags + newline: predicate + comment: | + Represents the use of the `until` keyword, either in the block form or the modifier form. + + bar until foo + ^^^^^^^^^^^^^ + + until foo do bar end + ^^^^^^^^^^^^^^^^^^^^ + - name: WhenNode + child_nodes: + - name: keyword_loc + type: location + - name: conditions + type: node[] + - name: statements + type: node? + kind: StatementsNode + comment: | + Represents the use of the `when` keyword within a case statement. + + case true + when true + ^^^^^^^^^ + end + - name: WhileNode + child_nodes: + - name: keyword_loc + type: location + - name: predicate + type: node + - name: statements + type: node? + kind: StatementsNode + - name: flags + type: flags + kind: LoopFlags + newline: predicate + comment: | + Represents the use of the `while` keyword, either in the block form or the modifier form. + + bar while foo + ^^^^^^^^^^^^^ + + while foo do bar end + ^^^^^^^^^^^^^^^^^^^^ + - name: XStringNode + child_nodes: + - name: opening_loc + type: location + - name: content_loc + type: location + - name: closing_loc + type: location + - name: unescaped + type: string + comment: | + Represents an xstring literal with no interpolation. + + `foo` + ^^^^^ + - name: YieldNode + child_nodes: + - name: keyword_loc + type: location + - name: lparen_loc + type: location? + - name: arguments + type: node? + kind: ArgumentsNode + - name: rparen_loc + type: location? + comment: | + Represents the use of the `yield` keyword. + + yield 1 + ^^^^^^^ diff --git a/yarp/node.c b/yarp/node.c deleted file mode 100644 index 46e24d1ee7ffa8..00000000000000 --- a/yarp/node.c +++ /dev/null @@ -1,2033 +0,0 @@ -/******************************************************************************/ -/* This file is generated by the bin/template script and should not be */ -/* modified manually. See */ -/* templates/src/node.c.erb */ -/* if you are looking to modify the */ -/* template */ -/******************************************************************************/ -#line 2 "node.c.erb" -#include "yarp/node.h" - -// Clear the node but preserves the location. -void yp_node_clear(yp_node_t *node) { - yp_location_t location = node->location; - memset(node, 0, sizeof(yp_node_t)); - node->location = location; -} - -// Calculate the size of the token list in bytes. -static size_t -yp_location_list_memsize(yp_location_list_t *list) { - return sizeof(yp_location_list_t) + (list->capacity * sizeof(yp_location_t)); -} - -// Append a token to the given list. -void -yp_location_list_append(yp_location_list_t *list, const yp_token_t *token) { - if (list->size == list->capacity) { - list->capacity = list->capacity == 0 ? 2 : list->capacity * 2; - list->locations = (yp_location_t *) realloc(list->locations, sizeof(yp_location_t) * list->capacity); - } - list->locations[list->size++] = (yp_location_t) { .start = token->start, .end = token->end }; -} - -// Free the memory associated with the token list. -static void -yp_location_list_free(yp_location_list_t *list) { - if (list->locations != NULL) { - free(list->locations); - } -} - -static void -yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize); - -// Calculate the size of the node list in bytes. -static size_t -yp_node_list_memsize(yp_node_list_t *node_list, yp_memsize_t *memsize) { - size_t size = sizeof(yp_node_list_t) + (node_list->capacity * sizeof(yp_node_t *)); - for (size_t index = 0; index < node_list->size; index++) { - yp_node_memsize_node(node_list->nodes[index], memsize); - } - return size; -} - -// Append a new node onto the end of the node list. -void -yp_node_list_append(yp_node_list_t *list, yp_node_t *node) { - if (list->size == list->capacity) { - list->capacity = list->capacity == 0 ? 4 : list->capacity * 2; - list->nodes = (yp_node_t **) realloc(list->nodes, sizeof(yp_node_t *) * list->capacity); - } - list->nodes[list->size++] = node; -} - -YP_EXPORTED_FUNCTION void -yp_node_destroy(yp_parser_t *parser, yp_node_t *node); - -// Deallocate the inner memory of a list of nodes. The parser argument is not -// used, but is here for the future possibility of pre-allocating memory pools. -static void -yp_node_list_free(yp_parser_t *parser, yp_node_list_t *list) { - if (list->capacity > 0) { - for (size_t index = 0; index < list->size; index++) { - yp_node_destroy(parser, list->nodes[index]); - } - free(list->nodes); - } -} - -// Deallocate the space for a yp_node_t. Similarly to yp_node_alloc, we're not -// using the parser argument, but it's there to allow for the future possibility -// of pre-allocating larger memory pools. -YP_EXPORTED_FUNCTION void -yp_node_destroy(yp_parser_t *parser, yp_node_t *node) { - switch (YP_NODE_TYPE(node)) { -#line 81 "node.c.erb" - case YP_NODE_ALIAS_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_alias_node_t *)node)->new_name); - yp_node_destroy(parser, (yp_node_t *)((yp_alias_node_t *)node)->old_name); - break; -#line 81 "node.c.erb" - case YP_NODE_ALTERNATION_PATTERN_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_alternation_pattern_node_t *)node)->left); - yp_node_destroy(parser, (yp_node_t *)((yp_alternation_pattern_node_t *)node)->right); - break; -#line 81 "node.c.erb" - case YP_NODE_AND_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_and_node_t *)node)->left); - yp_node_destroy(parser, (yp_node_t *)((yp_and_node_t *)node)->right); - break; -#line 81 "node.c.erb" - case YP_NODE_ARGUMENTS_NODE: - yp_node_list_free(parser, &((yp_arguments_node_t *)node)->arguments); - break; -#line 81 "node.c.erb" - case YP_NODE_ARRAY_NODE: - yp_node_list_free(parser, &((yp_array_node_t *)node)->elements); - break; -#line 81 "node.c.erb" - case YP_NODE_ARRAY_PATTERN_NODE: - if (((yp_array_pattern_node_t *)node)->constant != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_array_pattern_node_t *)node)->constant); - } - yp_node_list_free(parser, &((yp_array_pattern_node_t *)node)->requireds); - if (((yp_array_pattern_node_t *)node)->rest != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_array_pattern_node_t *)node)->rest); - } - yp_node_list_free(parser, &((yp_array_pattern_node_t *)node)->posts); - break; -#line 81 "node.c.erb" - case YP_NODE_ASSOC_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_assoc_node_t *)node)->key); - if (((yp_assoc_node_t *)node)->value != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_assoc_node_t *)node)->value); - } - break; -#line 81 "node.c.erb" - case YP_NODE_ASSOC_SPLAT_NODE: - if (((yp_assoc_splat_node_t *)node)->value != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_assoc_splat_node_t *)node)->value); - } - break; -#line 81 "node.c.erb" - case YP_NODE_BACK_REFERENCE_READ_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_BEGIN_NODE: - if (((yp_begin_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_begin_node_t *)node)->statements); - } - if (((yp_begin_node_t *)node)->rescue_clause != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_begin_node_t *)node)->rescue_clause); - } - if (((yp_begin_node_t *)node)->else_clause != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_begin_node_t *)node)->else_clause); - } - if (((yp_begin_node_t *)node)->ensure_clause != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_begin_node_t *)node)->ensure_clause); - } - break; -#line 81 "node.c.erb" - case YP_NODE_BLOCK_ARGUMENT_NODE: - if (((yp_block_argument_node_t *)node)->expression != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_block_argument_node_t *)node)->expression); - } - break; -#line 81 "node.c.erb" - case YP_NODE_BLOCK_NODE: - yp_constant_id_list_free(&((yp_block_node_t *)node)->locals); - if (((yp_block_node_t *)node)->parameters != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_block_node_t *)node)->parameters); - } - if (((yp_block_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_block_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_BLOCK_PARAMETER_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_BLOCK_PARAMETERS_NODE: - if (((yp_block_parameters_node_t *)node)->parameters != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_block_parameters_node_t *)node)->parameters); - } - yp_location_list_free(&((yp_block_parameters_node_t *)node)->locals); - break; -#line 81 "node.c.erb" - case YP_NODE_BREAK_NODE: - if (((yp_break_node_t *)node)->arguments != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_break_node_t *)node)->arguments); - } - break; -#line 81 "node.c.erb" - case YP_NODE_CALL_NODE: - if (((yp_call_node_t *)node)->receiver != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_call_node_t *)node)->receiver); - } - if (((yp_call_node_t *)node)->arguments != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_call_node_t *)node)->arguments); - } - if (((yp_call_node_t *)node)->block != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_call_node_t *)node)->block); - } - yp_string_free(&((yp_call_node_t *)node)->name); - break; -#line 81 "node.c.erb" - case YP_NODE_CALL_OPERATOR_AND_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_call_operator_and_write_node_t *)node)->target); - yp_node_destroy(parser, (yp_node_t *)((yp_call_operator_and_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CALL_OPERATOR_OR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_call_operator_or_write_node_t *)node)->target); - yp_node_destroy(parser, (yp_node_t *)((yp_call_operator_or_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CALL_OPERATOR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->target); - yp_node_destroy(parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CAPTURE_PATTERN_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_capture_pattern_node_t *)node)->value); - yp_node_destroy(parser, (yp_node_t *)((yp_capture_pattern_node_t *)node)->target); - break; -#line 81 "node.c.erb" - case YP_NODE_CASE_NODE: - if (((yp_case_node_t *)node)->predicate != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_case_node_t *)node)->predicate); - } - yp_node_list_free(parser, &((yp_case_node_t *)node)->conditions); - if (((yp_case_node_t *)node)->consequent != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_case_node_t *)node)->consequent); - } - break; -#line 81 "node.c.erb" - case YP_NODE_CLASS_NODE: - yp_constant_id_list_free(&((yp_class_node_t *)node)->locals); - yp_node_destroy(parser, (yp_node_t *)((yp_class_node_t *)node)->constant_path); - if (((yp_class_node_t *)node)->superclass != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_class_node_t *)node)->superclass); - } - if (((yp_class_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_class_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_class_variable_operator_and_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_class_variable_operator_or_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_class_variable_operator_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CLASS_VARIABLE_READ_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_CLASS_VARIABLE_WRITE_NODE: - if (((yp_class_variable_write_node_t *)node)->value != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_class_variable_write_node_t *)node)->value); - } - break; -#line 81 "node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_constant_operator_and_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_constant_operator_or_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_constant_operator_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CONSTANT_PATH_NODE: - if (((yp_constant_path_node_t *)node)->parent != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_constant_path_node_t *)node)->parent); - } - yp_node_destroy(parser, (yp_node_t *)((yp_constant_path_node_t *)node)->child); - break; -#line 81 "node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->target); - yp_node_destroy(parser, (yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->target); - yp_node_destroy(parser, (yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->target); - yp_node_destroy(parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_CONSTANT_PATH_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->target); - if (((yp_constant_path_write_node_t *)node)->value != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->value); - } - break; -#line 81 "node.c.erb" - case YP_NODE_CONSTANT_READ_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_CONSTANT_WRITE_NODE: - if (((yp_constant_write_node_t *)node)->value != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_constant_write_node_t *)node)->value); - } - break; -#line 81 "node.c.erb" - case YP_NODE_DEF_NODE: - if (((yp_def_node_t *)node)->receiver != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_def_node_t *)node)->receiver); - } - if (((yp_def_node_t *)node)->parameters != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_def_node_t *)node)->parameters); - } - if (((yp_def_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_def_node_t *)node)->statements); - } - yp_constant_id_list_free(&((yp_def_node_t *)node)->locals); - break; -#line 81 "node.c.erb" - case YP_NODE_DEFINED_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_defined_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_ELSE_NODE: - if (((yp_else_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_else_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_EMBEDDED_STATEMENTS_NODE: - if (((yp_embedded_statements_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_embedded_statements_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_EMBEDDED_VARIABLE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_embedded_variable_node_t *)node)->variable); - break; -#line 81 "node.c.erb" - case YP_NODE_ENSURE_NODE: - if (((yp_ensure_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_ensure_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_FALSE_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_FIND_PATTERN_NODE: - if (((yp_find_pattern_node_t *)node)->constant != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_find_pattern_node_t *)node)->constant); - } - yp_node_destroy(parser, (yp_node_t *)((yp_find_pattern_node_t *)node)->left); - yp_node_list_free(parser, &((yp_find_pattern_node_t *)node)->requireds); - yp_node_destroy(parser, (yp_node_t *)((yp_find_pattern_node_t *)node)->right); - break; -#line 81 "node.c.erb" - case YP_NODE_FLIP_FLOP_NODE: - if (((yp_flip_flop_node_t *)node)->left != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->left); - } - if (((yp_flip_flop_node_t *)node)->right != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->right); - } - break; -#line 81 "node.c.erb" - case YP_NODE_FLOAT_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_FOR_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_for_node_t *)node)->index); - yp_node_destroy(parser, (yp_node_t *)((yp_for_node_t *)node)->collection); - if (((yp_for_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_for_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_FORWARDING_ARGUMENTS_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_FORWARDING_PARAMETER_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_FORWARDING_SUPER_NODE: - if (((yp_forwarding_super_node_t *)node)->block != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_forwarding_super_node_t *)node)->block); - } - break; -#line 81 "node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_global_variable_operator_and_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_global_variable_operator_or_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_global_variable_operator_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: - if (((yp_global_variable_write_node_t *)node)->value != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_global_variable_write_node_t *)node)->value); - } - break; -#line 81 "node.c.erb" - case YP_NODE_HASH_NODE: - yp_node_list_free(parser, &((yp_hash_node_t *)node)->elements); - break; -#line 81 "node.c.erb" - case YP_NODE_HASH_PATTERN_NODE: - if (((yp_hash_pattern_node_t *)node)->constant != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_hash_pattern_node_t *)node)->constant); - } - yp_node_list_free(parser, &((yp_hash_pattern_node_t *)node)->assocs); - if (((yp_hash_pattern_node_t *)node)->kwrest != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_hash_pattern_node_t *)node)->kwrest); - } - break; -#line 81 "node.c.erb" - case YP_NODE_IF_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_if_node_t *)node)->predicate); - if (((yp_if_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_if_node_t *)node)->statements); - } - if (((yp_if_node_t *)node)->consequent != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_if_node_t *)node)->consequent); - } - break; -#line 81 "node.c.erb" - case YP_NODE_IMAGINARY_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_imaginary_node_t *)node)->numeric); - break; -#line 81 "node.c.erb" - case YP_NODE_IN_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_in_node_t *)node)->pattern); - if (((yp_in_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_in_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_instance_variable_operator_and_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_instance_variable_operator_or_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_instance_variable_operator_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: - if (((yp_instance_variable_write_node_t *)node)->value != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_instance_variable_write_node_t *)node)->value); - } - break; -#line 81 "node.c.erb" - case YP_NODE_INTEGER_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE: - yp_node_list_free(parser, &((yp_interpolated_regular_expression_node_t *)node)->parts); - break; -#line 81 "node.c.erb" - case YP_NODE_INTERPOLATED_STRING_NODE: - yp_node_list_free(parser, &((yp_interpolated_string_node_t *)node)->parts); - break; -#line 81 "node.c.erb" - case YP_NODE_INTERPOLATED_SYMBOL_NODE: - yp_node_list_free(parser, &((yp_interpolated_symbol_node_t *)node)->parts); - break; -#line 81 "node.c.erb" - case YP_NODE_INTERPOLATED_X_STRING_NODE: - yp_node_list_free(parser, &((yp_interpolated_x_string_node_t *)node)->parts); - break; -#line 81 "node.c.erb" - case YP_NODE_KEYWORD_HASH_NODE: - yp_node_list_free(parser, &((yp_keyword_hash_node_t *)node)->elements); - break; -#line 81 "node.c.erb" - case YP_NODE_KEYWORD_PARAMETER_NODE: - if (((yp_keyword_parameter_node_t *)node)->value != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_keyword_parameter_node_t *)node)->value); - } - break; -#line 81 "node.c.erb" - case YP_NODE_KEYWORD_REST_PARAMETER_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_LAMBDA_NODE: - yp_constant_id_list_free(&((yp_lambda_node_t *)node)->locals); - if (((yp_lambda_node_t *)node)->parameters != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_lambda_node_t *)node)->parameters); - } - if (((yp_lambda_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_lambda_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_local_variable_operator_and_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_local_variable_operator_or_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_local_variable_operator_write_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_LOCAL_VARIABLE_READ_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: - if (((yp_local_variable_write_node_t *)node)->value != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_local_variable_write_node_t *)node)->value); - } - break; -#line 81 "node.c.erb" - case YP_NODE_MATCH_PREDICATE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_match_predicate_node_t *)node)->value); - yp_node_destroy(parser, (yp_node_t *)((yp_match_predicate_node_t *)node)->pattern); - break; -#line 81 "node.c.erb" - case YP_NODE_MATCH_REQUIRED_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_match_required_node_t *)node)->value); - yp_node_destroy(parser, (yp_node_t *)((yp_match_required_node_t *)node)->pattern); - break; -#line 81 "node.c.erb" - case YP_NODE_MISSING_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_MODULE_NODE: - yp_constant_id_list_free(&((yp_module_node_t *)node)->locals); - yp_node_destroy(parser, (yp_node_t *)((yp_module_node_t *)node)->constant_path); - if (((yp_module_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_module_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_MULTI_WRITE_NODE: - yp_node_list_free(parser, &((yp_multi_write_node_t *)node)->targets); - if (((yp_multi_write_node_t *)node)->value != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_multi_write_node_t *)node)->value); - } - break; -#line 81 "node.c.erb" - case YP_NODE_NEXT_NODE: - if (((yp_next_node_t *)node)->arguments != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_next_node_t *)node)->arguments); - } - break; -#line 81 "node.c.erb" - case YP_NODE_NIL_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_NO_KEYWORDS_PARAMETER_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_OPTIONAL_PARAMETER_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_optional_parameter_node_t *)node)->value); - break; -#line 81 "node.c.erb" - case YP_NODE_OR_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_or_node_t *)node)->left); - yp_node_destroy(parser, (yp_node_t *)((yp_or_node_t *)node)->right); - break; -#line 81 "node.c.erb" - case YP_NODE_PARAMETERS_NODE: - yp_node_list_free(parser, &((yp_parameters_node_t *)node)->requireds); - yp_node_list_free(parser, &((yp_parameters_node_t *)node)->optionals); - yp_node_list_free(parser, &((yp_parameters_node_t *)node)->posts); - if (((yp_parameters_node_t *)node)->rest != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_parameters_node_t *)node)->rest); - } - yp_node_list_free(parser, &((yp_parameters_node_t *)node)->keywords); - if (((yp_parameters_node_t *)node)->keyword_rest != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_parameters_node_t *)node)->keyword_rest); - } - if (((yp_parameters_node_t *)node)->block != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_parameters_node_t *)node)->block); - } - break; -#line 81 "node.c.erb" - case YP_NODE_PARENTHESES_NODE: - if (((yp_parentheses_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_parentheses_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_PINNED_EXPRESSION_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_pinned_expression_node_t *)node)->expression); - break; -#line 81 "node.c.erb" - case YP_NODE_PINNED_VARIABLE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_pinned_variable_node_t *)node)->variable); - break; -#line 81 "node.c.erb" - case YP_NODE_POST_EXECUTION_NODE: - if (((yp_post_execution_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_post_execution_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_PRE_EXECUTION_NODE: - if (((yp_pre_execution_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_pre_execution_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_PROGRAM_NODE: - yp_constant_id_list_free(&((yp_program_node_t *)node)->locals); - yp_node_destroy(parser, (yp_node_t *)((yp_program_node_t *)node)->statements); - break; -#line 81 "node.c.erb" - case YP_NODE_RANGE_NODE: - if (((yp_range_node_t *)node)->left != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_range_node_t *)node)->left); - } - if (((yp_range_node_t *)node)->right != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_range_node_t *)node)->right); - } - break; -#line 81 "node.c.erb" - case YP_NODE_RATIONAL_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_rational_node_t *)node)->numeric); - break; -#line 81 "node.c.erb" - case YP_NODE_REDO_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_REGULAR_EXPRESSION_NODE: - yp_string_free(&((yp_regular_expression_node_t *)node)->unescaped); - break; -#line 81 "node.c.erb" - case YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE: - yp_node_list_free(parser, &((yp_required_destructured_parameter_node_t *)node)->parameters); - break; -#line 81 "node.c.erb" - case YP_NODE_REQUIRED_PARAMETER_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_RESCUE_MODIFIER_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_rescue_modifier_node_t *)node)->expression); - yp_node_destroy(parser, (yp_node_t *)((yp_rescue_modifier_node_t *)node)->rescue_expression); - break; -#line 81 "node.c.erb" - case YP_NODE_RESCUE_NODE: - yp_node_list_free(parser, &((yp_rescue_node_t *)node)->exceptions); - if (((yp_rescue_node_t *)node)->reference != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_rescue_node_t *)node)->reference); - } - if (((yp_rescue_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_rescue_node_t *)node)->statements); - } - if (((yp_rescue_node_t *)node)->consequent != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_rescue_node_t *)node)->consequent); - } - break; -#line 81 "node.c.erb" - case YP_NODE_REST_PARAMETER_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_RETRY_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_RETURN_NODE: - if (((yp_return_node_t *)node)->arguments != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_return_node_t *)node)->arguments); - } - break; -#line 81 "node.c.erb" - case YP_NODE_SELF_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_SINGLETON_CLASS_NODE: - yp_constant_id_list_free(&((yp_singleton_class_node_t *)node)->locals); - yp_node_destroy(parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->expression); - if (((yp_singleton_class_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_SOURCE_ENCODING_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_SOURCE_FILE_NODE: - yp_string_free(&((yp_source_file_node_t *)node)->filepath); - break; -#line 81 "node.c.erb" - case YP_NODE_SOURCE_LINE_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_SPLAT_NODE: - if (((yp_splat_node_t *)node)->expression != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_splat_node_t *)node)->expression); - } - break; -#line 81 "node.c.erb" - case YP_NODE_STATEMENTS_NODE: - yp_node_list_free(parser, &((yp_statements_node_t *)node)->body); - break; -#line 81 "node.c.erb" - case YP_NODE_STRING_CONCAT_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_string_concat_node_t *)node)->left); - yp_node_destroy(parser, (yp_node_t *)((yp_string_concat_node_t *)node)->right); - break; -#line 81 "node.c.erb" - case YP_NODE_STRING_NODE: - yp_string_free(&((yp_string_node_t *)node)->unescaped); - break; -#line 81 "node.c.erb" - case YP_NODE_SUPER_NODE: - if (((yp_super_node_t *)node)->arguments != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_super_node_t *)node)->arguments); - } - if (((yp_super_node_t *)node)->block != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_super_node_t *)node)->block); - } - break; -#line 81 "node.c.erb" - case YP_NODE_SYMBOL_NODE: - yp_string_free(&((yp_symbol_node_t *)node)->unescaped); - break; -#line 81 "node.c.erb" - case YP_NODE_TRUE_NODE: - break; -#line 81 "node.c.erb" - case YP_NODE_UNDEF_NODE: - yp_node_list_free(parser, &((yp_undef_node_t *)node)->names); - break; -#line 81 "node.c.erb" - case YP_NODE_UNLESS_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_unless_node_t *)node)->predicate); - if (((yp_unless_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_unless_node_t *)node)->statements); - } - if (((yp_unless_node_t *)node)->consequent != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_unless_node_t *)node)->consequent); - } - break; -#line 81 "node.c.erb" - case YP_NODE_UNTIL_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_until_node_t *)node)->predicate); - if (((yp_until_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_until_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_WHEN_NODE: - yp_node_list_free(parser, &((yp_when_node_t *)node)->conditions); - if (((yp_when_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_when_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_WHILE_NODE: - yp_node_destroy(parser, (yp_node_t *)((yp_while_node_t *)node)->predicate); - if (((yp_while_node_t *)node)->statements != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_while_node_t *)node)->statements); - } - break; -#line 81 "node.c.erb" - case YP_NODE_X_STRING_NODE: - yp_string_free(&((yp_x_string_node_t *)node)->unescaped); - break; -#line 81 "node.c.erb" - case YP_NODE_YIELD_NODE: - if (((yp_yield_node_t *)node)->arguments != NULL) { - yp_node_destroy(parser, (yp_node_t *)((yp_yield_node_t *)node)->arguments); - } - break; -#line 106 "node.c.erb" - default: - assert(false && "unreachable"); - break; - } - free(node); -} - -static void -yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize) { - memsize->node_count++; - - switch (YP_NODE_TYPE(node)) { -#line 120 "node.c.erb" - case YP_NODE_ALIAS_NODE: { - memsize->memsize += sizeof(yp_alias_node_t); - yp_node_memsize_node((yp_node_t *)((yp_alias_node_t *)node)->new_name, memsize); - yp_node_memsize_node((yp_node_t *)((yp_alias_node_t *)node)->old_name, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_ALTERNATION_PATTERN_NODE: { - memsize->memsize += sizeof(yp_alternation_pattern_node_t); - yp_node_memsize_node((yp_node_t *)((yp_alternation_pattern_node_t *)node)->left, memsize); - yp_node_memsize_node((yp_node_t *)((yp_alternation_pattern_node_t *)node)->right, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_AND_NODE: { - memsize->memsize += sizeof(yp_and_node_t); - yp_node_memsize_node((yp_node_t *)((yp_and_node_t *)node)->left, memsize); - yp_node_memsize_node((yp_node_t *)((yp_and_node_t *)node)->right, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_ARGUMENTS_NODE: { - memsize->memsize += sizeof(yp_arguments_node_t); - yp_node_list_memsize(&((yp_arguments_node_t *)node)->arguments, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_ARRAY_NODE: { - memsize->memsize += sizeof(yp_array_node_t); - yp_node_list_memsize(&((yp_array_node_t *)node)->elements, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_ARRAY_PATTERN_NODE: { - memsize->memsize += sizeof(yp_array_pattern_node_t); - if (((yp_array_pattern_node_t *)node)->constant != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_array_pattern_node_t *)node)->constant, memsize); - } - yp_node_list_memsize(&((yp_array_pattern_node_t *)node)->requireds, memsize); - if (((yp_array_pattern_node_t *)node)->rest != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_array_pattern_node_t *)node)->rest, memsize); - } - yp_node_list_memsize(&((yp_array_pattern_node_t *)node)->posts, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_ASSOC_NODE: { - memsize->memsize += sizeof(yp_assoc_node_t); - yp_node_memsize_node((yp_node_t *)((yp_assoc_node_t *)node)->key, memsize); - if (((yp_assoc_node_t *)node)->value != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_assoc_node_t *)node)->value, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_ASSOC_SPLAT_NODE: { - memsize->memsize += sizeof(yp_assoc_splat_node_t); - if (((yp_assoc_splat_node_t *)node)->value != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_assoc_splat_node_t *)node)->value, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_BACK_REFERENCE_READ_NODE: { - memsize->memsize += sizeof(yp_back_reference_read_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_BEGIN_NODE: { - memsize->memsize += sizeof(yp_begin_node_t); - if (((yp_begin_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_begin_node_t *)node)->statements, memsize); - } - if (((yp_begin_node_t *)node)->rescue_clause != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_begin_node_t *)node)->rescue_clause, memsize); - } - if (((yp_begin_node_t *)node)->else_clause != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_begin_node_t *)node)->else_clause, memsize); - } - if (((yp_begin_node_t *)node)->ensure_clause != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_begin_node_t *)node)->ensure_clause, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_BLOCK_ARGUMENT_NODE: { - memsize->memsize += sizeof(yp_block_argument_node_t); - if (((yp_block_argument_node_t *)node)->expression != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_block_argument_node_t *)node)->expression, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_BLOCK_NODE: { - memsize->memsize += sizeof(yp_block_node_t); - memsize->memsize += yp_constant_id_list_memsize(&((yp_block_node_t *)node)->locals); - if (((yp_block_node_t *)node)->parameters != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_block_node_t *)node)->parameters, memsize); - } - if (((yp_block_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_block_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_BLOCK_PARAMETER_NODE: { - memsize->memsize += sizeof(yp_block_parameter_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_BLOCK_PARAMETERS_NODE: { - memsize->memsize += sizeof(yp_block_parameters_node_t); - if (((yp_block_parameters_node_t *)node)->parameters != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_block_parameters_node_t *)node)->parameters, memsize); - } - memsize->memsize += yp_location_list_memsize(&((yp_block_parameters_node_t *)node)->locals); - break; - } -#line 120 "node.c.erb" - case YP_NODE_BREAK_NODE: { - memsize->memsize += sizeof(yp_break_node_t); - if (((yp_break_node_t *)node)->arguments != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_break_node_t *)node)->arguments, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_CALL_NODE: { - memsize->memsize += sizeof(yp_call_node_t); - if (((yp_call_node_t *)node)->receiver != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_call_node_t *)node)->receiver, memsize); - } - if (((yp_call_node_t *)node)->arguments != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_call_node_t *)node)->arguments, memsize); - } - if (((yp_call_node_t *)node)->block != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_call_node_t *)node)->block, memsize); - } - memsize->memsize += yp_string_memsize(&((yp_call_node_t *)node)->name); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CALL_OPERATOR_AND_WRITE_NODE: { - memsize->memsize += sizeof(yp_call_operator_and_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_call_operator_and_write_node_t *)node)->target, memsize); - yp_node_memsize_node((yp_node_t *)((yp_call_operator_and_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CALL_OPERATOR_OR_WRITE_NODE: { - memsize->memsize += sizeof(yp_call_operator_or_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_call_operator_or_write_node_t *)node)->target, memsize); - yp_node_memsize_node((yp_node_t *)((yp_call_operator_or_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CALL_OPERATOR_WRITE_NODE: { - memsize->memsize += sizeof(yp_call_operator_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_call_operator_write_node_t *)node)->target, memsize); - yp_node_memsize_node((yp_node_t *)((yp_call_operator_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CAPTURE_PATTERN_NODE: { - memsize->memsize += sizeof(yp_capture_pattern_node_t); - yp_node_memsize_node((yp_node_t *)((yp_capture_pattern_node_t *)node)->value, memsize); - yp_node_memsize_node((yp_node_t *)((yp_capture_pattern_node_t *)node)->target, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CASE_NODE: { - memsize->memsize += sizeof(yp_case_node_t); - if (((yp_case_node_t *)node)->predicate != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_case_node_t *)node)->predicate, memsize); - } - yp_node_list_memsize(&((yp_case_node_t *)node)->conditions, memsize); - if (((yp_case_node_t *)node)->consequent != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_case_node_t *)node)->consequent, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_CLASS_NODE: { - memsize->memsize += sizeof(yp_class_node_t); - memsize->memsize += yp_constant_id_list_memsize(&((yp_class_node_t *)node)->locals); - yp_node_memsize_node((yp_node_t *)((yp_class_node_t *)node)->constant_path, memsize); - if (((yp_class_node_t *)node)->superclass != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_class_node_t *)node)->superclass, memsize); - } - if (((yp_class_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_class_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE: { - memsize->memsize += sizeof(yp_class_variable_operator_and_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_class_variable_operator_and_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE: { - memsize->memsize += sizeof(yp_class_variable_operator_or_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_class_variable_operator_or_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: { - memsize->memsize += sizeof(yp_class_variable_operator_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_class_variable_operator_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CLASS_VARIABLE_READ_NODE: { - memsize->memsize += sizeof(yp_class_variable_read_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CLASS_VARIABLE_WRITE_NODE: { - memsize->memsize += sizeof(yp_class_variable_write_node_t); - if (((yp_class_variable_write_node_t *)node)->value != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_class_variable_write_node_t *)node)->value, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE: { - memsize->memsize += sizeof(yp_constant_operator_and_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_constant_operator_and_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE: { - memsize->memsize += sizeof(yp_constant_operator_or_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_constant_operator_or_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CONSTANT_OPERATOR_WRITE_NODE: { - memsize->memsize += sizeof(yp_constant_operator_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_constant_operator_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CONSTANT_PATH_NODE: { - memsize->memsize += sizeof(yp_constant_path_node_t); - if (((yp_constant_path_node_t *)node)->parent != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_constant_path_node_t *)node)->parent, memsize); - } - yp_node_memsize_node((yp_node_t *)((yp_constant_path_node_t *)node)->child, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE: { - memsize->memsize += sizeof(yp_constant_path_operator_and_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->target, memsize); - yp_node_memsize_node((yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE: { - memsize->memsize += sizeof(yp_constant_path_operator_or_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->target, memsize); - yp_node_memsize_node((yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE: { - memsize->memsize += sizeof(yp_constant_path_operator_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->target, memsize); - yp_node_memsize_node((yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CONSTANT_PATH_WRITE_NODE: { - memsize->memsize += sizeof(yp_constant_path_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_constant_path_write_node_t *)node)->target, memsize); - if (((yp_constant_path_write_node_t *)node)->value != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_constant_path_write_node_t *)node)->value, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_CONSTANT_READ_NODE: { - memsize->memsize += sizeof(yp_constant_read_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_CONSTANT_WRITE_NODE: { - memsize->memsize += sizeof(yp_constant_write_node_t); - if (((yp_constant_write_node_t *)node)->value != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_constant_write_node_t *)node)->value, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_DEF_NODE: { - memsize->memsize += sizeof(yp_def_node_t); - if (((yp_def_node_t *)node)->receiver != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_def_node_t *)node)->receiver, memsize); - } - if (((yp_def_node_t *)node)->parameters != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_def_node_t *)node)->parameters, memsize); - } - if (((yp_def_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_def_node_t *)node)->statements, memsize); - } - memsize->memsize += yp_constant_id_list_memsize(&((yp_def_node_t *)node)->locals); - break; - } -#line 120 "node.c.erb" - case YP_NODE_DEFINED_NODE: { - memsize->memsize += sizeof(yp_defined_node_t); - yp_node_memsize_node((yp_node_t *)((yp_defined_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_ELSE_NODE: { - memsize->memsize += sizeof(yp_else_node_t); - if (((yp_else_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_else_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_EMBEDDED_STATEMENTS_NODE: { - memsize->memsize += sizeof(yp_embedded_statements_node_t); - if (((yp_embedded_statements_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_embedded_statements_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_EMBEDDED_VARIABLE_NODE: { - memsize->memsize += sizeof(yp_embedded_variable_node_t); - yp_node_memsize_node((yp_node_t *)((yp_embedded_variable_node_t *)node)->variable, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_ENSURE_NODE: { - memsize->memsize += sizeof(yp_ensure_node_t); - if (((yp_ensure_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_ensure_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_FALSE_NODE: { - memsize->memsize += sizeof(yp_false_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_FIND_PATTERN_NODE: { - memsize->memsize += sizeof(yp_find_pattern_node_t); - if (((yp_find_pattern_node_t *)node)->constant != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_find_pattern_node_t *)node)->constant, memsize); - } - yp_node_memsize_node((yp_node_t *)((yp_find_pattern_node_t *)node)->left, memsize); - yp_node_list_memsize(&((yp_find_pattern_node_t *)node)->requireds, memsize); - yp_node_memsize_node((yp_node_t *)((yp_find_pattern_node_t *)node)->right, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_FLIP_FLOP_NODE: { - memsize->memsize += sizeof(yp_flip_flop_node_t); - if (((yp_flip_flop_node_t *)node)->left != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_flip_flop_node_t *)node)->left, memsize); - } - if (((yp_flip_flop_node_t *)node)->right != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_flip_flop_node_t *)node)->right, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_FLOAT_NODE: { - memsize->memsize += sizeof(yp_float_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_FOR_NODE: { - memsize->memsize += sizeof(yp_for_node_t); - yp_node_memsize_node((yp_node_t *)((yp_for_node_t *)node)->index, memsize); - yp_node_memsize_node((yp_node_t *)((yp_for_node_t *)node)->collection, memsize); - if (((yp_for_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_for_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_FORWARDING_ARGUMENTS_NODE: { - memsize->memsize += sizeof(yp_forwarding_arguments_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_FORWARDING_PARAMETER_NODE: { - memsize->memsize += sizeof(yp_forwarding_parameter_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_FORWARDING_SUPER_NODE: { - memsize->memsize += sizeof(yp_forwarding_super_node_t); - if (((yp_forwarding_super_node_t *)node)->block != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_forwarding_super_node_t *)node)->block, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE: { - memsize->memsize += sizeof(yp_global_variable_operator_and_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_global_variable_operator_and_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE: { - memsize->memsize += sizeof(yp_global_variable_operator_or_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_global_variable_operator_or_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: { - memsize->memsize += sizeof(yp_global_variable_operator_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_global_variable_operator_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { - memsize->memsize += sizeof(yp_global_variable_read_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: { - memsize->memsize += sizeof(yp_global_variable_write_node_t); - if (((yp_global_variable_write_node_t *)node)->value != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_global_variable_write_node_t *)node)->value, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_HASH_NODE: { - memsize->memsize += sizeof(yp_hash_node_t); - yp_node_list_memsize(&((yp_hash_node_t *)node)->elements, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_HASH_PATTERN_NODE: { - memsize->memsize += sizeof(yp_hash_pattern_node_t); - if (((yp_hash_pattern_node_t *)node)->constant != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_hash_pattern_node_t *)node)->constant, memsize); - } - yp_node_list_memsize(&((yp_hash_pattern_node_t *)node)->assocs, memsize); - if (((yp_hash_pattern_node_t *)node)->kwrest != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_hash_pattern_node_t *)node)->kwrest, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_IF_NODE: { - memsize->memsize += sizeof(yp_if_node_t); - yp_node_memsize_node((yp_node_t *)((yp_if_node_t *)node)->predicate, memsize); - if (((yp_if_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_if_node_t *)node)->statements, memsize); - } - if (((yp_if_node_t *)node)->consequent != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_if_node_t *)node)->consequent, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_IMAGINARY_NODE: { - memsize->memsize += sizeof(yp_imaginary_node_t); - yp_node_memsize_node((yp_node_t *)((yp_imaginary_node_t *)node)->numeric, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_IN_NODE: { - memsize->memsize += sizeof(yp_in_node_t); - yp_node_memsize_node((yp_node_t *)((yp_in_node_t *)node)->pattern, memsize); - if (((yp_in_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_in_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE: { - memsize->memsize += sizeof(yp_instance_variable_operator_and_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_instance_variable_operator_and_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE: { - memsize->memsize += sizeof(yp_instance_variable_operator_or_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_instance_variable_operator_or_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: { - memsize->memsize += sizeof(yp_instance_variable_operator_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_instance_variable_operator_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: { - memsize->memsize += sizeof(yp_instance_variable_read_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: { - memsize->memsize += sizeof(yp_instance_variable_write_node_t); - if (((yp_instance_variable_write_node_t *)node)->value != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_instance_variable_write_node_t *)node)->value, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_INTEGER_NODE: { - memsize->memsize += sizeof(yp_integer_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE: { - memsize->memsize += sizeof(yp_interpolated_regular_expression_node_t); - yp_node_list_memsize(&((yp_interpolated_regular_expression_node_t *)node)->parts, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_INTERPOLATED_STRING_NODE: { - memsize->memsize += sizeof(yp_interpolated_string_node_t); - yp_node_list_memsize(&((yp_interpolated_string_node_t *)node)->parts, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_INTERPOLATED_SYMBOL_NODE: { - memsize->memsize += sizeof(yp_interpolated_symbol_node_t); - yp_node_list_memsize(&((yp_interpolated_symbol_node_t *)node)->parts, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_INTERPOLATED_X_STRING_NODE: { - memsize->memsize += sizeof(yp_interpolated_x_string_node_t); - yp_node_list_memsize(&((yp_interpolated_x_string_node_t *)node)->parts, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_KEYWORD_HASH_NODE: { - memsize->memsize += sizeof(yp_keyword_hash_node_t); - yp_node_list_memsize(&((yp_keyword_hash_node_t *)node)->elements, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_KEYWORD_PARAMETER_NODE: { - memsize->memsize += sizeof(yp_keyword_parameter_node_t); - if (((yp_keyword_parameter_node_t *)node)->value != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_keyword_parameter_node_t *)node)->value, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_KEYWORD_REST_PARAMETER_NODE: { - memsize->memsize += sizeof(yp_keyword_rest_parameter_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_LAMBDA_NODE: { - memsize->memsize += sizeof(yp_lambda_node_t); - memsize->memsize += yp_constant_id_list_memsize(&((yp_lambda_node_t *)node)->locals); - if (((yp_lambda_node_t *)node)->parameters != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_lambda_node_t *)node)->parameters, memsize); - } - if (((yp_lambda_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_lambda_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE: { - memsize->memsize += sizeof(yp_local_variable_operator_and_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_local_variable_operator_and_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE: { - memsize->memsize += sizeof(yp_local_variable_operator_or_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_local_variable_operator_or_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: { - memsize->memsize += sizeof(yp_local_variable_operator_write_node_t); - yp_node_memsize_node((yp_node_t *)((yp_local_variable_operator_write_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_LOCAL_VARIABLE_READ_NODE: { - memsize->memsize += sizeof(yp_local_variable_read_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: { - memsize->memsize += sizeof(yp_local_variable_write_node_t); - if (((yp_local_variable_write_node_t *)node)->value != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_local_variable_write_node_t *)node)->value, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_MATCH_PREDICATE_NODE: { - memsize->memsize += sizeof(yp_match_predicate_node_t); - yp_node_memsize_node((yp_node_t *)((yp_match_predicate_node_t *)node)->value, memsize); - yp_node_memsize_node((yp_node_t *)((yp_match_predicate_node_t *)node)->pattern, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_MATCH_REQUIRED_NODE: { - memsize->memsize += sizeof(yp_match_required_node_t); - yp_node_memsize_node((yp_node_t *)((yp_match_required_node_t *)node)->value, memsize); - yp_node_memsize_node((yp_node_t *)((yp_match_required_node_t *)node)->pattern, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_MISSING_NODE: { - memsize->memsize += sizeof(yp_missing_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_MODULE_NODE: { - memsize->memsize += sizeof(yp_module_node_t); - memsize->memsize += yp_constant_id_list_memsize(&((yp_module_node_t *)node)->locals); - yp_node_memsize_node((yp_node_t *)((yp_module_node_t *)node)->constant_path, memsize); - if (((yp_module_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_module_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_MULTI_WRITE_NODE: { - memsize->memsize += sizeof(yp_multi_write_node_t); - yp_node_list_memsize(&((yp_multi_write_node_t *)node)->targets, memsize); - if (((yp_multi_write_node_t *)node)->value != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_multi_write_node_t *)node)->value, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_NEXT_NODE: { - memsize->memsize += sizeof(yp_next_node_t); - if (((yp_next_node_t *)node)->arguments != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_next_node_t *)node)->arguments, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_NIL_NODE: { - memsize->memsize += sizeof(yp_nil_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_NO_KEYWORDS_PARAMETER_NODE: { - memsize->memsize += sizeof(yp_no_keywords_parameter_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: { - memsize->memsize += sizeof(yp_numbered_reference_read_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_OPTIONAL_PARAMETER_NODE: { - memsize->memsize += sizeof(yp_optional_parameter_node_t); - yp_node_memsize_node((yp_node_t *)((yp_optional_parameter_node_t *)node)->value, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_OR_NODE: { - memsize->memsize += sizeof(yp_or_node_t); - yp_node_memsize_node((yp_node_t *)((yp_or_node_t *)node)->left, memsize); - yp_node_memsize_node((yp_node_t *)((yp_or_node_t *)node)->right, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_PARAMETERS_NODE: { - memsize->memsize += sizeof(yp_parameters_node_t); - yp_node_list_memsize(&((yp_parameters_node_t *)node)->requireds, memsize); - yp_node_list_memsize(&((yp_parameters_node_t *)node)->optionals, memsize); - yp_node_list_memsize(&((yp_parameters_node_t *)node)->posts, memsize); - if (((yp_parameters_node_t *)node)->rest != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_parameters_node_t *)node)->rest, memsize); - } - yp_node_list_memsize(&((yp_parameters_node_t *)node)->keywords, memsize); - if (((yp_parameters_node_t *)node)->keyword_rest != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_parameters_node_t *)node)->keyword_rest, memsize); - } - if (((yp_parameters_node_t *)node)->block != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_parameters_node_t *)node)->block, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_PARENTHESES_NODE: { - memsize->memsize += sizeof(yp_parentheses_node_t); - if (((yp_parentheses_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_parentheses_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_PINNED_EXPRESSION_NODE: { - memsize->memsize += sizeof(yp_pinned_expression_node_t); - yp_node_memsize_node((yp_node_t *)((yp_pinned_expression_node_t *)node)->expression, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_PINNED_VARIABLE_NODE: { - memsize->memsize += sizeof(yp_pinned_variable_node_t); - yp_node_memsize_node((yp_node_t *)((yp_pinned_variable_node_t *)node)->variable, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_POST_EXECUTION_NODE: { - memsize->memsize += sizeof(yp_post_execution_node_t); - if (((yp_post_execution_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_post_execution_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_PRE_EXECUTION_NODE: { - memsize->memsize += sizeof(yp_pre_execution_node_t); - if (((yp_pre_execution_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_pre_execution_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_PROGRAM_NODE: { - memsize->memsize += sizeof(yp_program_node_t); - memsize->memsize += yp_constant_id_list_memsize(&((yp_program_node_t *)node)->locals); - yp_node_memsize_node((yp_node_t *)((yp_program_node_t *)node)->statements, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_RANGE_NODE: { - memsize->memsize += sizeof(yp_range_node_t); - if (((yp_range_node_t *)node)->left != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_range_node_t *)node)->left, memsize); - } - if (((yp_range_node_t *)node)->right != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_range_node_t *)node)->right, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_RATIONAL_NODE: { - memsize->memsize += sizeof(yp_rational_node_t); - yp_node_memsize_node((yp_node_t *)((yp_rational_node_t *)node)->numeric, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_REDO_NODE: { - memsize->memsize += sizeof(yp_redo_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_REGULAR_EXPRESSION_NODE: { - memsize->memsize += sizeof(yp_regular_expression_node_t); - memsize->memsize += yp_string_memsize(&((yp_regular_expression_node_t *)node)->unescaped); - break; - } -#line 120 "node.c.erb" - case YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE: { - memsize->memsize += sizeof(yp_required_destructured_parameter_node_t); - yp_node_list_memsize(&((yp_required_destructured_parameter_node_t *)node)->parameters, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_REQUIRED_PARAMETER_NODE: { - memsize->memsize += sizeof(yp_required_parameter_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_RESCUE_MODIFIER_NODE: { - memsize->memsize += sizeof(yp_rescue_modifier_node_t); - yp_node_memsize_node((yp_node_t *)((yp_rescue_modifier_node_t *)node)->expression, memsize); - yp_node_memsize_node((yp_node_t *)((yp_rescue_modifier_node_t *)node)->rescue_expression, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_RESCUE_NODE: { - memsize->memsize += sizeof(yp_rescue_node_t); - yp_node_list_memsize(&((yp_rescue_node_t *)node)->exceptions, memsize); - if (((yp_rescue_node_t *)node)->reference != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_rescue_node_t *)node)->reference, memsize); - } - if (((yp_rescue_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_rescue_node_t *)node)->statements, memsize); - } - if (((yp_rescue_node_t *)node)->consequent != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_rescue_node_t *)node)->consequent, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_REST_PARAMETER_NODE: { - memsize->memsize += sizeof(yp_rest_parameter_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_RETRY_NODE: { - memsize->memsize += sizeof(yp_retry_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_RETURN_NODE: { - memsize->memsize += sizeof(yp_return_node_t); - if (((yp_return_node_t *)node)->arguments != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_return_node_t *)node)->arguments, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_SELF_NODE: { - memsize->memsize += sizeof(yp_self_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_SINGLETON_CLASS_NODE: { - memsize->memsize += sizeof(yp_singleton_class_node_t); - memsize->memsize += yp_constant_id_list_memsize(&((yp_singleton_class_node_t *)node)->locals); - yp_node_memsize_node((yp_node_t *)((yp_singleton_class_node_t *)node)->expression, memsize); - if (((yp_singleton_class_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_singleton_class_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_SOURCE_ENCODING_NODE: { - memsize->memsize += sizeof(yp_source_encoding_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_SOURCE_FILE_NODE: { - memsize->memsize += sizeof(yp_source_file_node_t); - memsize->memsize += yp_string_memsize(&((yp_source_file_node_t *)node)->filepath); - break; - } -#line 120 "node.c.erb" - case YP_NODE_SOURCE_LINE_NODE: { - memsize->memsize += sizeof(yp_source_line_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_SPLAT_NODE: { - memsize->memsize += sizeof(yp_splat_node_t); - if (((yp_splat_node_t *)node)->expression != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_splat_node_t *)node)->expression, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_STATEMENTS_NODE: { - memsize->memsize += sizeof(yp_statements_node_t); - yp_node_list_memsize(&((yp_statements_node_t *)node)->body, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_STRING_CONCAT_NODE: { - memsize->memsize += sizeof(yp_string_concat_node_t); - yp_node_memsize_node((yp_node_t *)((yp_string_concat_node_t *)node)->left, memsize); - yp_node_memsize_node((yp_node_t *)((yp_string_concat_node_t *)node)->right, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_STRING_NODE: { - memsize->memsize += sizeof(yp_string_node_t); - memsize->memsize += yp_string_memsize(&((yp_string_node_t *)node)->unescaped); - break; - } -#line 120 "node.c.erb" - case YP_NODE_SUPER_NODE: { - memsize->memsize += sizeof(yp_super_node_t); - if (((yp_super_node_t *)node)->arguments != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_super_node_t *)node)->arguments, memsize); - } - if (((yp_super_node_t *)node)->block != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_super_node_t *)node)->block, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_SYMBOL_NODE: { - memsize->memsize += sizeof(yp_symbol_node_t); - memsize->memsize += yp_string_memsize(&((yp_symbol_node_t *)node)->unescaped); - break; - } -#line 120 "node.c.erb" - case YP_NODE_TRUE_NODE: { - memsize->memsize += sizeof(yp_true_node_t); - break; - } -#line 120 "node.c.erb" - case YP_NODE_UNDEF_NODE: { - memsize->memsize += sizeof(yp_undef_node_t); - yp_node_list_memsize(&((yp_undef_node_t *)node)->names, memsize); - break; - } -#line 120 "node.c.erb" - case YP_NODE_UNLESS_NODE: { - memsize->memsize += sizeof(yp_unless_node_t); - yp_node_memsize_node((yp_node_t *)((yp_unless_node_t *)node)->predicate, memsize); - if (((yp_unless_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_unless_node_t *)node)->statements, memsize); - } - if (((yp_unless_node_t *)node)->consequent != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_unless_node_t *)node)->consequent, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_UNTIL_NODE: { - memsize->memsize += sizeof(yp_until_node_t); - yp_node_memsize_node((yp_node_t *)((yp_until_node_t *)node)->predicate, memsize); - if (((yp_until_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_until_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_WHEN_NODE: { - memsize->memsize += sizeof(yp_when_node_t); - yp_node_list_memsize(&((yp_when_node_t *)node)->conditions, memsize); - if (((yp_when_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_when_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_WHILE_NODE: { - memsize->memsize += sizeof(yp_while_node_t); - yp_node_memsize_node((yp_node_t *)((yp_while_node_t *)node)->predicate, memsize); - if (((yp_while_node_t *)node)->statements != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_while_node_t *)node)->statements, memsize); - } - break; - } -#line 120 "node.c.erb" - case YP_NODE_X_STRING_NODE: { - memsize->memsize += sizeof(yp_x_string_node_t); - memsize->memsize += yp_string_memsize(&((yp_x_string_node_t *)node)->unescaped); - break; - } -#line 120 "node.c.erb" - case YP_NODE_YIELD_NODE: { - memsize->memsize += sizeof(yp_yield_node_t); - if (((yp_yield_node_t *)node)->arguments != NULL) { - yp_node_memsize_node((yp_node_t *)((yp_yield_node_t *)node)->arguments, memsize); - } - break; - } -#line 147 "node.c.erb" - } -} - -// Calculates the memory footprint of a given node. -YP_EXPORTED_FUNCTION void -yp_node_memsize(yp_node_t *node, yp_memsize_t *memsize) { - *memsize = (yp_memsize_t) { .memsize = 0, .node_count = 0 }; - yp_node_memsize_node(node, memsize); -} - -// Returns a string representation of the given node type. -YP_EXPORTED_FUNCTION const char * -yp_node_type_to_str(yp_node_type_t node_type) -{ - switch (node_type) { - case YP_NODE_ALIAS_NODE: - return "YP_NODE_ALIAS_NODE"; - case YP_NODE_ALTERNATION_PATTERN_NODE: - return "YP_NODE_ALTERNATION_PATTERN_NODE"; - case YP_NODE_AND_NODE: - return "YP_NODE_AND_NODE"; - case YP_NODE_ARGUMENTS_NODE: - return "YP_NODE_ARGUMENTS_NODE"; - case YP_NODE_ARRAY_NODE: - return "YP_NODE_ARRAY_NODE"; - case YP_NODE_ARRAY_PATTERN_NODE: - return "YP_NODE_ARRAY_PATTERN_NODE"; - case YP_NODE_ASSOC_NODE: - return "YP_NODE_ASSOC_NODE"; - case YP_NODE_ASSOC_SPLAT_NODE: - return "YP_NODE_ASSOC_SPLAT_NODE"; - case YP_NODE_BACK_REFERENCE_READ_NODE: - return "YP_NODE_BACK_REFERENCE_READ_NODE"; - case YP_NODE_BEGIN_NODE: - return "YP_NODE_BEGIN_NODE"; - case YP_NODE_BLOCK_ARGUMENT_NODE: - return "YP_NODE_BLOCK_ARGUMENT_NODE"; - case YP_NODE_BLOCK_NODE: - return "YP_NODE_BLOCK_NODE"; - case YP_NODE_BLOCK_PARAMETER_NODE: - return "YP_NODE_BLOCK_PARAMETER_NODE"; - case YP_NODE_BLOCK_PARAMETERS_NODE: - return "YP_NODE_BLOCK_PARAMETERS_NODE"; - case YP_NODE_BREAK_NODE: - return "YP_NODE_BREAK_NODE"; - case YP_NODE_CALL_NODE: - return "YP_NODE_CALL_NODE"; - case YP_NODE_CALL_OPERATOR_AND_WRITE_NODE: - return "YP_NODE_CALL_OPERATOR_AND_WRITE_NODE"; - case YP_NODE_CALL_OPERATOR_OR_WRITE_NODE: - return "YP_NODE_CALL_OPERATOR_OR_WRITE_NODE"; - case YP_NODE_CALL_OPERATOR_WRITE_NODE: - return "YP_NODE_CALL_OPERATOR_WRITE_NODE"; - case YP_NODE_CAPTURE_PATTERN_NODE: - return "YP_NODE_CAPTURE_PATTERN_NODE"; - case YP_NODE_CASE_NODE: - return "YP_NODE_CASE_NODE"; - case YP_NODE_CLASS_NODE: - return "YP_NODE_CLASS_NODE"; - case YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE: - return "YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE"; - case YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE: - return "YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE"; - case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: - return "YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE"; - case YP_NODE_CLASS_VARIABLE_READ_NODE: - return "YP_NODE_CLASS_VARIABLE_READ_NODE"; - case YP_NODE_CLASS_VARIABLE_WRITE_NODE: - return "YP_NODE_CLASS_VARIABLE_WRITE_NODE"; - case YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE: - return "YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE"; - case YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE: - return "YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE"; - case YP_NODE_CONSTANT_OPERATOR_WRITE_NODE: - return "YP_NODE_CONSTANT_OPERATOR_WRITE_NODE"; - case YP_NODE_CONSTANT_PATH_NODE: - return "YP_NODE_CONSTANT_PATH_NODE"; - case YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE: - return "YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE"; - case YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE: - return "YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE"; - case YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE: - return "YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE"; - case YP_NODE_CONSTANT_PATH_WRITE_NODE: - return "YP_NODE_CONSTANT_PATH_WRITE_NODE"; - case YP_NODE_CONSTANT_READ_NODE: - return "YP_NODE_CONSTANT_READ_NODE"; - case YP_NODE_CONSTANT_WRITE_NODE: - return "YP_NODE_CONSTANT_WRITE_NODE"; - case YP_NODE_DEF_NODE: - return "YP_NODE_DEF_NODE"; - case YP_NODE_DEFINED_NODE: - return "YP_NODE_DEFINED_NODE"; - case YP_NODE_ELSE_NODE: - return "YP_NODE_ELSE_NODE"; - case YP_NODE_EMBEDDED_STATEMENTS_NODE: - return "YP_NODE_EMBEDDED_STATEMENTS_NODE"; - case YP_NODE_EMBEDDED_VARIABLE_NODE: - return "YP_NODE_EMBEDDED_VARIABLE_NODE"; - case YP_NODE_ENSURE_NODE: - return "YP_NODE_ENSURE_NODE"; - case YP_NODE_FALSE_NODE: - return "YP_NODE_FALSE_NODE"; - case YP_NODE_FIND_PATTERN_NODE: - return "YP_NODE_FIND_PATTERN_NODE"; - case YP_NODE_FLIP_FLOP_NODE: - return "YP_NODE_FLIP_FLOP_NODE"; - case YP_NODE_FLOAT_NODE: - return "YP_NODE_FLOAT_NODE"; - case YP_NODE_FOR_NODE: - return "YP_NODE_FOR_NODE"; - case YP_NODE_FORWARDING_ARGUMENTS_NODE: - return "YP_NODE_FORWARDING_ARGUMENTS_NODE"; - case YP_NODE_FORWARDING_PARAMETER_NODE: - return "YP_NODE_FORWARDING_PARAMETER_NODE"; - case YP_NODE_FORWARDING_SUPER_NODE: - return "YP_NODE_FORWARDING_SUPER_NODE"; - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE: - return "YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE"; - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE: - return "YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE"; - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: - return "YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE"; - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: - return "YP_NODE_GLOBAL_VARIABLE_READ_NODE"; - case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: - return "YP_NODE_GLOBAL_VARIABLE_WRITE_NODE"; - case YP_NODE_HASH_NODE: - return "YP_NODE_HASH_NODE"; - case YP_NODE_HASH_PATTERN_NODE: - return "YP_NODE_HASH_PATTERN_NODE"; - case YP_NODE_IF_NODE: - return "YP_NODE_IF_NODE"; - case YP_NODE_IMAGINARY_NODE: - return "YP_NODE_IMAGINARY_NODE"; - case YP_NODE_IN_NODE: - return "YP_NODE_IN_NODE"; - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE: - return "YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE"; - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE: - return "YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE"; - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: - return "YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE"; - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: - return "YP_NODE_INSTANCE_VARIABLE_READ_NODE"; - case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: - return "YP_NODE_INSTANCE_VARIABLE_WRITE_NODE"; - case YP_NODE_INTEGER_NODE: - return "YP_NODE_INTEGER_NODE"; - case YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE: - return "YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE"; - case YP_NODE_INTERPOLATED_STRING_NODE: - return "YP_NODE_INTERPOLATED_STRING_NODE"; - case YP_NODE_INTERPOLATED_SYMBOL_NODE: - return "YP_NODE_INTERPOLATED_SYMBOL_NODE"; - case YP_NODE_INTERPOLATED_X_STRING_NODE: - return "YP_NODE_INTERPOLATED_X_STRING_NODE"; - case YP_NODE_KEYWORD_HASH_NODE: - return "YP_NODE_KEYWORD_HASH_NODE"; - case YP_NODE_KEYWORD_PARAMETER_NODE: - return "YP_NODE_KEYWORD_PARAMETER_NODE"; - case YP_NODE_KEYWORD_REST_PARAMETER_NODE: - return "YP_NODE_KEYWORD_REST_PARAMETER_NODE"; - case YP_NODE_LAMBDA_NODE: - return "YP_NODE_LAMBDA_NODE"; - case YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE: - return "YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE"; - case YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE: - return "YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE"; - case YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: - return "YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE"; - case YP_NODE_LOCAL_VARIABLE_READ_NODE: - return "YP_NODE_LOCAL_VARIABLE_READ_NODE"; - case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: - return "YP_NODE_LOCAL_VARIABLE_WRITE_NODE"; - case YP_NODE_MATCH_PREDICATE_NODE: - return "YP_NODE_MATCH_PREDICATE_NODE"; - case YP_NODE_MATCH_REQUIRED_NODE: - return "YP_NODE_MATCH_REQUIRED_NODE"; - case YP_NODE_MISSING_NODE: - return "YP_NODE_MISSING_NODE"; - case YP_NODE_MODULE_NODE: - return "YP_NODE_MODULE_NODE"; - case YP_NODE_MULTI_WRITE_NODE: - return "YP_NODE_MULTI_WRITE_NODE"; - case YP_NODE_NEXT_NODE: - return "YP_NODE_NEXT_NODE"; - case YP_NODE_NIL_NODE: - return "YP_NODE_NIL_NODE"; - case YP_NODE_NO_KEYWORDS_PARAMETER_NODE: - return "YP_NODE_NO_KEYWORDS_PARAMETER_NODE"; - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: - return "YP_NODE_NUMBERED_REFERENCE_READ_NODE"; - case YP_NODE_OPTIONAL_PARAMETER_NODE: - return "YP_NODE_OPTIONAL_PARAMETER_NODE"; - case YP_NODE_OR_NODE: - return "YP_NODE_OR_NODE"; - case YP_NODE_PARAMETERS_NODE: - return "YP_NODE_PARAMETERS_NODE"; - case YP_NODE_PARENTHESES_NODE: - return "YP_NODE_PARENTHESES_NODE"; - case YP_NODE_PINNED_EXPRESSION_NODE: - return "YP_NODE_PINNED_EXPRESSION_NODE"; - case YP_NODE_PINNED_VARIABLE_NODE: - return "YP_NODE_PINNED_VARIABLE_NODE"; - case YP_NODE_POST_EXECUTION_NODE: - return "YP_NODE_POST_EXECUTION_NODE"; - case YP_NODE_PRE_EXECUTION_NODE: - return "YP_NODE_PRE_EXECUTION_NODE"; - case YP_NODE_PROGRAM_NODE: - return "YP_NODE_PROGRAM_NODE"; - case YP_NODE_RANGE_NODE: - return "YP_NODE_RANGE_NODE"; - case YP_NODE_RATIONAL_NODE: - return "YP_NODE_RATIONAL_NODE"; - case YP_NODE_REDO_NODE: - return "YP_NODE_REDO_NODE"; - case YP_NODE_REGULAR_EXPRESSION_NODE: - return "YP_NODE_REGULAR_EXPRESSION_NODE"; - case YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE: - return "YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE"; - case YP_NODE_REQUIRED_PARAMETER_NODE: - return "YP_NODE_REQUIRED_PARAMETER_NODE"; - case YP_NODE_RESCUE_MODIFIER_NODE: - return "YP_NODE_RESCUE_MODIFIER_NODE"; - case YP_NODE_RESCUE_NODE: - return "YP_NODE_RESCUE_NODE"; - case YP_NODE_REST_PARAMETER_NODE: - return "YP_NODE_REST_PARAMETER_NODE"; - case YP_NODE_RETRY_NODE: - return "YP_NODE_RETRY_NODE"; - case YP_NODE_RETURN_NODE: - return "YP_NODE_RETURN_NODE"; - case YP_NODE_SELF_NODE: - return "YP_NODE_SELF_NODE"; - case YP_NODE_SINGLETON_CLASS_NODE: - return "YP_NODE_SINGLETON_CLASS_NODE"; - case YP_NODE_SOURCE_ENCODING_NODE: - return "YP_NODE_SOURCE_ENCODING_NODE"; - case YP_NODE_SOURCE_FILE_NODE: - return "YP_NODE_SOURCE_FILE_NODE"; - case YP_NODE_SOURCE_LINE_NODE: - return "YP_NODE_SOURCE_LINE_NODE"; - case YP_NODE_SPLAT_NODE: - return "YP_NODE_SPLAT_NODE"; - case YP_NODE_STATEMENTS_NODE: - return "YP_NODE_STATEMENTS_NODE"; - case YP_NODE_STRING_CONCAT_NODE: - return "YP_NODE_STRING_CONCAT_NODE"; - case YP_NODE_STRING_NODE: - return "YP_NODE_STRING_NODE"; - case YP_NODE_SUPER_NODE: - return "YP_NODE_SUPER_NODE"; - case YP_NODE_SYMBOL_NODE: - return "YP_NODE_SYMBOL_NODE"; - case YP_NODE_TRUE_NODE: - return "YP_NODE_TRUE_NODE"; - case YP_NODE_UNDEF_NODE: - return "YP_NODE_UNDEF_NODE"; - case YP_NODE_UNLESS_NODE: - return "YP_NODE_UNLESS_NODE"; - case YP_NODE_UNTIL_NODE: - return "YP_NODE_UNTIL_NODE"; - case YP_NODE_WHEN_NODE: - return "YP_NODE_WHEN_NODE"; - case YP_NODE_WHILE_NODE: - return "YP_NODE_WHILE_NODE"; - case YP_NODE_X_STRING_NODE: - return "YP_NODE_X_STRING_NODE"; - case YP_NODE_YIELD_NODE: - return "YP_NODE_YIELD_NODE"; - } - return "\0"; -} diff --git a/yarp/prettyprint.c b/yarp/prettyprint.c deleted file mode 100644 index 04a666dc8f72e9..00000000000000 --- a/yarp/prettyprint.c +++ /dev/null @@ -1,1801 +0,0 @@ -/******************************************************************************/ -/* This file is generated by the bin/template script and should not be */ -/* modified manually. See */ -/* templates/src/prettyprint.c.erb */ -/* if you are looking to modify the */ -/* template */ -/******************************************************************************/ -#include "yarp/defines.h" - -#include - -#include "yarp/ast.h" -#include "yarp/parser.h" -#include "yarp/util/yp_buffer.h" - -static void -prettyprint_location(yp_buffer_t *buffer, yp_parser_t *parser, yp_location_t *location) { - char printed[] = "[0000-0000]"; - snprintf(printed, sizeof(printed), "[%04ld-%04ld]", (long int)(location->start - parser->start), (long int)(location->end - parser->start)); - yp_buffer_append_str(buffer, printed, strlen(printed)); -} - -static void -prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) { - switch (YP_NODE_TYPE(node)) { - case YP_NODE_ALIAS_NODE: { - yp_buffer_append_str(buffer, "AliasNode(", 10); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_alias_node_t *)node)->new_name); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_alias_node_t *)node)->old_name); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_alias_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_ALTERNATION_PATTERN_NODE: { - yp_buffer_append_str(buffer, "AlternationPatternNode(", 23); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_alternation_pattern_node_t *)node)->left); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_alternation_pattern_node_t *)node)->right); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_alternation_pattern_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_AND_NODE: { - yp_buffer_append_str(buffer, "AndNode(", 8); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_and_node_t *)node)->left); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_and_node_t *)node)->right); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_and_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_ARGUMENTS_NODE: { - yp_buffer_append_str(buffer, "ArgumentsNode(", 14); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_arguments_node_t *)node)->arguments.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_arguments_node_t *) node)->arguments.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_ARRAY_NODE: { - yp_buffer_append_str(buffer, "ArrayNode(", 10); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_array_node_t *)node)->elements.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_array_node_t *) node)->elements.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_array_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_array_node_t *)node)->opening_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_array_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_array_node_t *)node)->closing_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_ARRAY_PATTERN_NODE: { - yp_buffer_append_str(buffer, "ArrayPatternNode(", 17); - if (((yp_array_pattern_node_t *)node)->constant == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_array_pattern_node_t *)node)->constant); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_array_pattern_node_t *)node)->requireds.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_array_pattern_node_t *) node)->requireds.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_array_pattern_node_t *)node)->rest == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_array_pattern_node_t *)node)->rest); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_array_pattern_node_t *)node)->posts.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_array_pattern_node_t *) node)->posts.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_array_pattern_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_array_pattern_node_t *)node)->opening_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_array_pattern_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_array_pattern_node_t *)node)->closing_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_ASSOC_NODE: { - yp_buffer_append_str(buffer, "AssocNode(", 10); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_assoc_node_t *)node)->key); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_assoc_node_t *)node)->value == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_assoc_node_t *)node)->value); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_assoc_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_assoc_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_ASSOC_SPLAT_NODE: { - yp_buffer_append_str(buffer, "AssocSplatNode(", 15); - if (((yp_assoc_splat_node_t *)node)->value == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_assoc_splat_node_t *)node)->value); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_assoc_splat_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_BACK_REFERENCE_READ_NODE: { - yp_buffer_append_str(buffer, "BackReferenceReadNode(", 22); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_BEGIN_NODE: { - yp_buffer_append_str(buffer, "BeginNode(", 10); - if (((yp_begin_node_t *)node)->begin_keyword_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_begin_node_t *)node)->begin_keyword_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_begin_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_begin_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_begin_node_t *)node)->rescue_clause == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_begin_node_t *)node)->rescue_clause); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_begin_node_t *)node)->else_clause == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_begin_node_t *)node)->else_clause); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_begin_node_t *)node)->ensure_clause == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_begin_node_t *)node)->ensure_clause); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_begin_node_t *)node)->end_keyword_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_begin_node_t *)node)->end_keyword_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_BLOCK_ARGUMENT_NODE: { - yp_buffer_append_str(buffer, "BlockArgumentNode(", 18); - if (((yp_block_argument_node_t *)node)->expression == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_block_argument_node_t *)node)->expression); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_block_argument_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_BLOCK_NODE: { - yp_buffer_append_str(buffer, "BlockNode(", 10); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_block_node_t *)node)->locals.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - char locals_buffer[12]; - snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_block_node_t *)node)->locals.ids[index]); - yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer)); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_block_node_t *)node)->parameters == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_block_node_t *)node)->parameters); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_block_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_block_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_block_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_block_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_BLOCK_PARAMETER_NODE: { - yp_buffer_append_str(buffer, "BlockParameterNode(", 19); - if (((yp_block_parameter_node_t *)node)->name_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_block_parameter_node_t *)node)->name_loc); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_block_parameter_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_BLOCK_PARAMETERS_NODE: { - yp_buffer_append_str(buffer, "BlockParametersNode(", 20); - if (((yp_block_parameters_node_t *)node)->parameters == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_block_parameters_node_t *)node)->parameters); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_block_parameters_node_t *)node)->locals.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_location(buffer, parser, &((yp_block_parameters_node_t *)node)->locals.locations[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_block_parameters_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_block_parameters_node_t *)node)->opening_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_block_parameters_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_block_parameters_node_t *)node)->closing_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_BREAK_NODE: { - yp_buffer_append_str(buffer, "BreakNode(", 10); - if (((yp_break_node_t *)node)->arguments == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_break_node_t *)node)->arguments); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_break_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CALL_NODE: { - yp_buffer_append_str(buffer, "CallNode(", 9); - if (((yp_call_node_t *)node)->receiver == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_node_t *)node)->receiver); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_call_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_call_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_call_node_t *)node)->message_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_call_node_t *)node)->message_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_call_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_call_node_t *)node)->opening_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_call_node_t *)node)->arguments == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_node_t *)node)->arguments); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_call_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_call_node_t *)node)->closing_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_call_node_t *)node)->block == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_node_t *)node)->block); - } - yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12]; - snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1); - yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer)); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, yp_string_source(&((yp_call_node_t *)node)->name), yp_string_length(&((yp_call_node_t *)node)->name)); - yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CALL_OPERATOR_AND_WRITE_NODE: { - yp_buffer_append_str(buffer, "CallOperatorAndWriteNode(", 25); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_operator_and_write_node_t *)node)->target); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_call_operator_and_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_operator_and_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CALL_OPERATOR_OR_WRITE_NODE: { - yp_buffer_append_str(buffer, "CallOperatorOrWriteNode(", 24); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_operator_or_write_node_t *)node)->target); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_operator_or_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_call_operator_or_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CALL_OPERATOR_WRITE_NODE: { - yp_buffer_append_str(buffer, "CallOperatorWriteNode(", 22); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->target); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_call_operator_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); char operator_id_buffer[12]; - snprintf(operator_id_buffer, sizeof(operator_id_buffer), "%u", ((yp_call_operator_write_node_t *)node)->operator_id); - yp_buffer_append_str(buffer, operator_id_buffer, strlen(operator_id_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CAPTURE_PATTERN_NODE: { - yp_buffer_append_str(buffer, "CapturePatternNode(", 19); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_capture_pattern_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_capture_pattern_node_t *)node)->target); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_capture_pattern_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CASE_NODE: { - yp_buffer_append_str(buffer, "CaseNode(", 9); - if (((yp_case_node_t *)node)->predicate == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_case_node_t *)node)->predicate); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_case_node_t *)node)->conditions.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_case_node_t *) node)->conditions.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_case_node_t *)node)->consequent == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_case_node_t *)node)->consequent); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_case_node_t *)node)->case_keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_case_node_t *)node)->end_keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CLASS_NODE: { - yp_buffer_append_str(buffer, "ClassNode(", 10); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_class_node_t *)node)->locals.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - char locals_buffer[12]; - snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_class_node_t *)node)->locals.ids[index]); - yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer)); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_node_t *)node)->class_keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_node_t *)node)->constant_path); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_class_node_t *)node)->inheritance_operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_class_node_t *)node)->inheritance_operator_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_class_node_t *)node)->superclass == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_node_t *)node)->superclass); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_class_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_node_t *)node)->end_keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_buffer_append_str(buffer, "ClassVariableOperatorAndWriteNode(", 34); - prettyprint_location(buffer, parser, &((yp_class_variable_operator_and_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_operator_and_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_variable_operator_and_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_buffer_append_str(buffer, "ClassVariableOperatorOrWriteNode(", 33); - prettyprint_location(buffer, parser, &((yp_class_variable_operator_or_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_operator_or_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_variable_operator_or_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: { - yp_buffer_append_str(buffer, "ClassVariableOperatorWriteNode(", 31); - prettyprint_location(buffer, parser, &((yp_class_variable_operator_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_operator_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_variable_operator_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12]; - snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_class_variable_operator_write_node_t *)node)->operator); - yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CLASS_VARIABLE_READ_NODE: { - yp_buffer_append_str(buffer, "ClassVariableReadNode(", 22); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CLASS_VARIABLE_WRITE_NODE: { - yp_buffer_append_str(buffer, "ClassVariableWriteNode(", 23); - prettyprint_location(buffer, parser, &((yp_class_variable_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_class_variable_write_node_t *)node)->value == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_variable_write_node_t *)node)->value); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_class_variable_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_class_variable_write_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE: { - yp_buffer_append_str(buffer, "ConstantOperatorAndWriteNode(", 29); - prettyprint_location(buffer, parser, &((yp_constant_operator_and_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_constant_operator_and_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_operator_and_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE: { - yp_buffer_append_str(buffer, "ConstantOperatorOrWriteNode(", 28); - prettyprint_location(buffer, parser, &((yp_constant_operator_or_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_constant_operator_or_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_operator_or_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CONSTANT_OPERATOR_WRITE_NODE: { - yp_buffer_append_str(buffer, "ConstantOperatorWriteNode(", 26); - prettyprint_location(buffer, parser, &((yp_constant_operator_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_constant_operator_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_operator_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12]; - snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_constant_operator_write_node_t *)node)->operator); - yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CONSTANT_PATH_NODE: { - yp_buffer_append_str(buffer, "ConstantPathNode(", 17); - if (((yp_constant_path_node_t *)node)->parent == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_node_t *)node)->parent); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_node_t *)node)->child); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_constant_path_node_t *)node)->delimiter_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE: { - yp_buffer_append_str(buffer, "ConstantPathOperatorAndWriteNode(", 33); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->target); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_constant_path_operator_and_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE: { - yp_buffer_append_str(buffer, "ConstantPathOperatorOrWriteNode(", 32); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->target); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_constant_path_operator_or_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE: { - yp_buffer_append_str(buffer, "ConstantPathOperatorWriteNode(", 30); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->target); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_constant_path_operator_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12]; - snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_constant_path_operator_write_node_t *)node)->operator); - yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CONSTANT_PATH_WRITE_NODE: { - yp_buffer_append_str(buffer, "ConstantPathWriteNode(", 22); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->target); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_constant_path_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_constant_path_write_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_constant_path_write_node_t *)node)->value == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->value); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CONSTANT_READ_NODE: { - yp_buffer_append_str(buffer, "ConstantReadNode(", 17); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_CONSTANT_WRITE_NODE: { - yp_buffer_append_str(buffer, "ConstantWriteNode(", 18); - prettyprint_location(buffer, parser, &((yp_constant_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_constant_write_node_t *)node)->value == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_write_node_t *)node)->value); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_constant_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_constant_write_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_DEF_NODE: { - yp_buffer_append_str(buffer, "DefNode(", 8); - prettyprint_location(buffer, parser, &((yp_def_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_def_node_t *)node)->receiver == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_def_node_t *)node)->receiver); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_def_node_t *)node)->parameters == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_def_node_t *)node)->parameters); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_def_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_def_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_def_node_t *)node)->locals.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - char locals_buffer[12]; - snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_def_node_t *)node)->locals.ids[index]); - yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer)); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_def_node_t *)node)->def_keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_def_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_def_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_def_node_t *)node)->lparen_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_def_node_t *)node)->lparen_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_def_node_t *)node)->rparen_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_def_node_t *)node)->rparen_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_def_node_t *)node)->equal_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_def_node_t *)node)->equal_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_def_node_t *)node)->end_keyword_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_def_node_t *)node)->end_keyword_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_DEFINED_NODE: { - yp_buffer_append_str(buffer, "DefinedNode(", 12); - if (((yp_defined_node_t *)node)->lparen_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_defined_node_t *)node)->lparen_loc); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_defined_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_defined_node_t *)node)->rparen_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_defined_node_t *)node)->rparen_loc); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_defined_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_ELSE_NODE: { - yp_buffer_append_str(buffer, "ElseNode(", 9); - prettyprint_location(buffer, parser, &((yp_else_node_t *)node)->else_keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_else_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_else_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_else_node_t *)node)->end_keyword_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_else_node_t *)node)->end_keyword_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_EMBEDDED_STATEMENTS_NODE: { - yp_buffer_append_str(buffer, "EmbeddedStatementsNode(", 23); - prettyprint_location(buffer, parser, &((yp_embedded_statements_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_embedded_statements_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_embedded_statements_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_embedded_statements_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_EMBEDDED_VARIABLE_NODE: { - yp_buffer_append_str(buffer, "EmbeddedVariableNode(", 21); - prettyprint_location(buffer, parser, &((yp_embedded_variable_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_embedded_variable_node_t *)node)->variable); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_ENSURE_NODE: { - yp_buffer_append_str(buffer, "EnsureNode(", 11); - prettyprint_location(buffer, parser, &((yp_ensure_node_t *)node)->ensure_keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_ensure_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_ensure_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_ensure_node_t *)node)->end_keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_FALSE_NODE: { - yp_buffer_append_str(buffer, "FalseNode(", 10); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_FIND_PATTERN_NODE: { - yp_buffer_append_str(buffer, "FindPatternNode(", 16); - if (((yp_find_pattern_node_t *)node)->constant == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_find_pattern_node_t *)node)->constant); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_find_pattern_node_t *)node)->left); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_find_pattern_node_t *)node)->requireds.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_find_pattern_node_t *) node)->requireds.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_find_pattern_node_t *)node)->right); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_find_pattern_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_find_pattern_node_t *)node)->opening_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_find_pattern_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_find_pattern_node_t *)node)->closing_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_FLIP_FLOP_NODE: { - yp_buffer_append_str(buffer, "FlipFlopNode(", 13); - if (((yp_flip_flop_node_t *)node)->left == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->left); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_flip_flop_node_t *)node)->right == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->right); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_flip_flop_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12]; - snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1); - yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_FLOAT_NODE: { - yp_buffer_append_str(buffer, "FloatNode(", 10); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_FOR_NODE: { - yp_buffer_append_str(buffer, "ForNode(", 8); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_for_node_t *)node)->index); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_for_node_t *)node)->collection); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_for_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_for_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_for_node_t *)node)->for_keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_for_node_t *)node)->in_keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_for_node_t *)node)->do_keyword_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_for_node_t *)node)->do_keyword_loc); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_for_node_t *)node)->end_keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_FORWARDING_ARGUMENTS_NODE: { - yp_buffer_append_str(buffer, "ForwardingArgumentsNode(", 24); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_FORWARDING_PARAMETER_NODE: { - yp_buffer_append_str(buffer, "ForwardingParameterNode(", 24); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_FORWARDING_SUPER_NODE: { - yp_buffer_append_str(buffer, "ForwardingSuperNode(", 20); - if (((yp_forwarding_super_node_t *)node)->block == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_forwarding_super_node_t *)node)->block); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_buffer_append_str(buffer, "GlobalVariableOperatorAndWriteNode(", 35); - prettyprint_location(buffer, parser, &((yp_global_variable_operator_and_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_global_variable_operator_and_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_global_variable_operator_and_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_buffer_append_str(buffer, "GlobalVariableOperatorOrWriteNode(", 34); - prettyprint_location(buffer, parser, &((yp_global_variable_operator_or_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_global_variable_operator_or_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_global_variable_operator_or_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: { - yp_buffer_append_str(buffer, "GlobalVariableOperatorWriteNode(", 32); - prettyprint_location(buffer, parser, &((yp_global_variable_operator_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_global_variable_operator_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_global_variable_operator_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12]; - snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_global_variable_operator_write_node_t *)node)->operator); - yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { - yp_buffer_append_str(buffer, "GlobalVariableReadNode(", 23); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: { - yp_buffer_append_str(buffer, "GlobalVariableWriteNode(", 24); - prettyprint_location(buffer, parser, &((yp_global_variable_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_global_variable_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_global_variable_write_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_global_variable_write_node_t *)node)->value == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_global_variable_write_node_t *)node)->value); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_HASH_NODE: { - yp_buffer_append_str(buffer, "HashNode(", 9); - prettyprint_location(buffer, parser, &((yp_hash_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_hash_node_t *)node)->elements.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_hash_node_t *) node)->elements.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_hash_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_HASH_PATTERN_NODE: { - yp_buffer_append_str(buffer, "HashPatternNode(", 16); - if (((yp_hash_pattern_node_t *)node)->constant == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_hash_pattern_node_t *)node)->constant); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_hash_pattern_node_t *)node)->assocs.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_hash_pattern_node_t *) node)->assocs.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_hash_pattern_node_t *)node)->kwrest == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_hash_pattern_node_t *)node)->kwrest); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_hash_pattern_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_hash_pattern_node_t *)node)->opening_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_hash_pattern_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_hash_pattern_node_t *)node)->closing_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_IF_NODE: { - yp_buffer_append_str(buffer, "IfNode(", 7); - if (((yp_if_node_t *)node)->if_keyword_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_if_node_t *)node)->if_keyword_loc); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_if_node_t *)node)->predicate); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_if_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_if_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_if_node_t *)node)->consequent == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_if_node_t *)node)->consequent); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_if_node_t *)node)->end_keyword_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_if_node_t *)node)->end_keyword_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_IMAGINARY_NODE: { - yp_buffer_append_str(buffer, "ImaginaryNode(", 14); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_imaginary_node_t *)node)->numeric); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_IN_NODE: { - yp_buffer_append_str(buffer, "InNode(", 7); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_in_node_t *)node)->pattern); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_in_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_in_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_in_node_t *)node)->in_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_in_node_t *)node)->then_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_in_node_t *)node)->then_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_buffer_append_str(buffer, "InstanceVariableOperatorAndWriteNode(", 37); - prettyprint_location(buffer, parser, &((yp_instance_variable_operator_and_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_operator_and_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_instance_variable_operator_and_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_buffer_append_str(buffer, "InstanceVariableOperatorOrWriteNode(", 36); - prettyprint_location(buffer, parser, &((yp_instance_variable_operator_or_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_operator_or_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_instance_variable_operator_or_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: { - yp_buffer_append_str(buffer, "InstanceVariableOperatorWriteNode(", 34); - prettyprint_location(buffer, parser, &((yp_instance_variable_operator_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_operator_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_instance_variable_operator_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12]; - snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_instance_variable_operator_write_node_t *)node)->operator); - yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: { - yp_buffer_append_str(buffer, "InstanceVariableReadNode(", 25); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: { - yp_buffer_append_str(buffer, "InstanceVariableWriteNode(", 26); - prettyprint_location(buffer, parser, &((yp_instance_variable_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_instance_variable_write_node_t *)node)->value == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_instance_variable_write_node_t *)node)->value); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_instance_variable_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_instance_variable_write_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_INTEGER_NODE: { - yp_buffer_append_str(buffer, "IntegerNode(", 12); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE: { - yp_buffer_append_str(buffer, "InterpolatedRegularExpressionNode(", 34); - prettyprint_location(buffer, parser, &((yp_interpolated_regular_expression_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_interpolated_regular_expression_node_t *)node)->parts.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_interpolated_regular_expression_node_t *) node)->parts.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_interpolated_regular_expression_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12]; - snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1); - yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_INTERPOLATED_STRING_NODE: { - yp_buffer_append_str(buffer, "InterpolatedStringNode(", 23); - if (((yp_interpolated_string_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_interpolated_string_node_t *)node)->opening_loc); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_interpolated_string_node_t *)node)->parts.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_interpolated_string_node_t *) node)->parts.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_interpolated_string_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_interpolated_string_node_t *)node)->closing_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_INTERPOLATED_SYMBOL_NODE: { - yp_buffer_append_str(buffer, "InterpolatedSymbolNode(", 23); - if (((yp_interpolated_symbol_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_interpolated_symbol_node_t *)node)->opening_loc); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_interpolated_symbol_node_t *)node)->parts.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_interpolated_symbol_node_t *) node)->parts.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_interpolated_symbol_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_interpolated_symbol_node_t *)node)->closing_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_INTERPOLATED_X_STRING_NODE: { - yp_buffer_append_str(buffer, "InterpolatedXStringNode(", 24); - prettyprint_location(buffer, parser, &((yp_interpolated_x_string_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_interpolated_x_string_node_t *)node)->parts.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_interpolated_x_string_node_t *) node)->parts.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_interpolated_x_string_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_KEYWORD_HASH_NODE: { - yp_buffer_append_str(buffer, "KeywordHashNode(", 16); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_keyword_hash_node_t *)node)->elements.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_keyword_hash_node_t *) node)->elements.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_KEYWORD_PARAMETER_NODE: { - yp_buffer_append_str(buffer, "KeywordParameterNode(", 21); - prettyprint_location(buffer, parser, &((yp_keyword_parameter_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_keyword_parameter_node_t *)node)->value == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_keyword_parameter_node_t *)node)->value); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_KEYWORD_REST_PARAMETER_NODE: { - yp_buffer_append_str(buffer, "KeywordRestParameterNode(", 25); - prettyprint_location(buffer, parser, &((yp_keyword_rest_parameter_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_keyword_rest_parameter_node_t *)node)->name_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_keyword_rest_parameter_node_t *)node)->name_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_LAMBDA_NODE: { - yp_buffer_append_str(buffer, "LambdaNode(", 11); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_lambda_node_t *)node)->locals.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - char locals_buffer[12]; - snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_lambda_node_t *)node)->locals.ids[index]); - yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer)); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_lambda_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_lambda_node_t *)node)->parameters == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_lambda_node_t *)node)->parameters); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_lambda_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_lambda_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE: { - yp_buffer_append_str(buffer, "LocalVariableOperatorAndWriteNode(", 34); - prettyprint_location(buffer, parser, &((yp_local_variable_operator_and_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_operator_and_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_operator_and_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); char constant_id_buffer[12]; - snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_operator_and_write_node_t *)node)->constant_id); - yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE: { - yp_buffer_append_str(buffer, "LocalVariableOperatorOrWriteNode(", 33); - prettyprint_location(buffer, parser, &((yp_local_variable_operator_or_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_operator_or_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_operator_or_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); char constant_id_buffer[12]; - snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_operator_or_write_node_t *)node)->constant_id); - yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: { - yp_buffer_append_str(buffer, "LocalVariableOperatorWriteNode(", 31); - prettyprint_location(buffer, parser, &((yp_local_variable_operator_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_operator_write_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_operator_write_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); char constant_id_buffer[12]; - snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_operator_write_node_t *)node)->constant_id); - yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer)); - yp_buffer_append_str(buffer, ", ", 2); char operator_id_buffer[12]; - snprintf(operator_id_buffer, sizeof(operator_id_buffer), "%u", ((yp_local_variable_operator_write_node_t *)node)->operator_id); - yp_buffer_append_str(buffer, operator_id_buffer, strlen(operator_id_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_LOCAL_VARIABLE_READ_NODE: { - yp_buffer_append_str(buffer, "LocalVariableReadNode(", 22); - char constant_id_buffer[12]; - snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_read_node_t *)node)->constant_id); - yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer)); - yp_buffer_append_str(buffer, ", ", 2); char depth_buffer[12]; - snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_read_node_t *)node)->depth); - yp_buffer_append_str(buffer, depth_buffer, strlen(depth_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: { - yp_buffer_append_str(buffer, "LocalVariableWriteNode(", 23); - char constant_id_buffer[12]; - snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_write_node_t *)node)->constant_id); - yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer)); - yp_buffer_append_str(buffer, ", ", 2); char depth_buffer[12]; - snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_write_node_t *)node)->depth); - yp_buffer_append_str(buffer, depth_buffer, strlen(depth_buffer)); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_local_variable_write_node_t *)node)->value == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_write_node_t *)node)->value); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_write_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_local_variable_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_local_variable_write_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_MATCH_PREDICATE_NODE: { - yp_buffer_append_str(buffer, "MatchPredicateNode(", 19); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_match_predicate_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_match_predicate_node_t *)node)->pattern); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_match_predicate_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_MATCH_REQUIRED_NODE: { - yp_buffer_append_str(buffer, "MatchRequiredNode(", 18); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_match_required_node_t *)node)->value); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_match_required_node_t *)node)->pattern); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_match_required_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_MISSING_NODE: { - yp_buffer_append_str(buffer, "MissingNode(", 12); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_MODULE_NODE: { - yp_buffer_append_str(buffer, "ModuleNode(", 11); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_module_node_t *)node)->locals.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - char locals_buffer[12]; - snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_module_node_t *)node)->locals.ids[index]); - yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer)); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_module_node_t *)node)->module_keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_module_node_t *)node)->constant_path); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_module_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_module_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_module_node_t *)node)->end_keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_MULTI_WRITE_NODE: { - yp_buffer_append_str(buffer, "MultiWriteNode(", 15); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_multi_write_node_t *)node)->targets.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_multi_write_node_t *) node)->targets.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_multi_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_multi_write_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_multi_write_node_t *)node)->value == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_multi_write_node_t *)node)->value); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_multi_write_node_t *)node)->lparen_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_multi_write_node_t *)node)->lparen_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_multi_write_node_t *)node)->rparen_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_multi_write_node_t *)node)->rparen_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_NEXT_NODE: { - yp_buffer_append_str(buffer, "NextNode(", 9); - if (((yp_next_node_t *)node)->arguments == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_next_node_t *)node)->arguments); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_next_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_NIL_NODE: { - yp_buffer_append_str(buffer, "NilNode(", 8); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_NO_KEYWORDS_PARAMETER_NODE: { - yp_buffer_append_str(buffer, "NoKeywordsParameterNode(", 24); - prettyprint_location(buffer, parser, &((yp_no_keywords_parameter_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_no_keywords_parameter_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: { - yp_buffer_append_str(buffer, "NumberedReferenceReadNode(", 26); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_OPTIONAL_PARAMETER_NODE: { - yp_buffer_append_str(buffer, "OptionalParameterNode(", 22); - char constant_id_buffer[12]; - snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_optional_parameter_node_t *)node)->constant_id); - yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer)); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_optional_parameter_node_t *)node)->name_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_optional_parameter_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_optional_parameter_node_t *)node)->value); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_OR_NODE: { - yp_buffer_append_str(buffer, "OrNode(", 7); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_or_node_t *)node)->left); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_or_node_t *)node)->right); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_or_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_PARAMETERS_NODE: { - yp_buffer_append_str(buffer, "ParametersNode(", 15); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_parameters_node_t *)node)->requireds.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_parameters_node_t *) node)->requireds.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_parameters_node_t *)node)->optionals.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_parameters_node_t *) node)->optionals.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_parameters_node_t *)node)->posts.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_parameters_node_t *) node)->posts.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_parameters_node_t *)node)->rest == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_parameters_node_t *)node)->rest); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_parameters_node_t *)node)->keywords.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_parameters_node_t *) node)->keywords.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_parameters_node_t *)node)->keyword_rest == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_parameters_node_t *)node)->keyword_rest); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_parameters_node_t *)node)->block == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_parameters_node_t *)node)->block); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_PARENTHESES_NODE: { - yp_buffer_append_str(buffer, "ParenthesesNode(", 16); - if (((yp_parentheses_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_parentheses_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_parentheses_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_parentheses_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_PINNED_EXPRESSION_NODE: { - yp_buffer_append_str(buffer, "PinnedExpressionNode(", 21); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_pinned_expression_node_t *)node)->expression); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_pinned_expression_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_pinned_expression_node_t *)node)->lparen_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_pinned_expression_node_t *)node)->rparen_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_PINNED_VARIABLE_NODE: { - yp_buffer_append_str(buffer, "PinnedVariableNode(", 19); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_pinned_variable_node_t *)node)->variable); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_pinned_variable_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_POST_EXECUTION_NODE: { - yp_buffer_append_str(buffer, "PostExecutionNode(", 18); - if (((yp_post_execution_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_post_execution_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_post_execution_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_post_execution_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_post_execution_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_PRE_EXECUTION_NODE: { - yp_buffer_append_str(buffer, "PreExecutionNode(", 17); - if (((yp_pre_execution_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_pre_execution_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_pre_execution_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_pre_execution_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_pre_execution_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_PROGRAM_NODE: { - yp_buffer_append_str(buffer, "ProgramNode(", 12); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_program_node_t *)node)->locals.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - char locals_buffer[12]; - snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_program_node_t *)node)->locals.ids[index]); - yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer)); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_program_node_t *)node)->statements); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_RANGE_NODE: { - yp_buffer_append_str(buffer, "RangeNode(", 10); - if (((yp_range_node_t *)node)->left == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_range_node_t *)node)->left); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_range_node_t *)node)->right == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_range_node_t *)node)->right); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_range_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12]; - snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1); - yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_RATIONAL_NODE: { - yp_buffer_append_str(buffer, "RationalNode(", 13); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_rational_node_t *)node)->numeric); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_REDO_NODE: { - yp_buffer_append_str(buffer, "RedoNode(", 9); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_REGULAR_EXPRESSION_NODE: { - yp_buffer_append_str(buffer, "RegularExpressionNode(", 22); - prettyprint_location(buffer, parser, &((yp_regular_expression_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_regular_expression_node_t *)node)->content_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_regular_expression_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, yp_string_source(&((yp_regular_expression_node_t *)node)->unescaped), yp_string_length(&((yp_regular_expression_node_t *)node)->unescaped)); - yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12]; - snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1); - yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE: { - yp_buffer_append_str(buffer, "RequiredDestructuredParameterNode(", 34); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_required_destructured_parameter_node_t *)node)->parameters.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_required_destructured_parameter_node_t *) node)->parameters.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_required_destructured_parameter_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_required_destructured_parameter_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_REQUIRED_PARAMETER_NODE: { - yp_buffer_append_str(buffer, "RequiredParameterNode(", 22); - char constant_id_buffer[12]; - snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_required_parameter_node_t *)node)->constant_id); - yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_RESCUE_MODIFIER_NODE: { - yp_buffer_append_str(buffer, "RescueModifierNode(", 19); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_rescue_modifier_node_t *)node)->expression); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_rescue_modifier_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_rescue_modifier_node_t *)node)->rescue_expression); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_RESCUE_NODE: { - yp_buffer_append_str(buffer, "RescueNode(", 11); - prettyprint_location(buffer, parser, &((yp_rescue_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_rescue_node_t *)node)->exceptions.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_rescue_node_t *) node)->exceptions.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_rescue_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_rescue_node_t *)node)->operator_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_rescue_node_t *)node)->reference == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_rescue_node_t *)node)->reference); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_rescue_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_rescue_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_rescue_node_t *)node)->consequent == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_rescue_node_t *)node)->consequent); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_REST_PARAMETER_NODE: { - yp_buffer_append_str(buffer, "RestParameterNode(", 18); - prettyprint_location(buffer, parser, &((yp_rest_parameter_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_rest_parameter_node_t *)node)->name_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_rest_parameter_node_t *)node)->name_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_RETRY_NODE: { - yp_buffer_append_str(buffer, "RetryNode(", 10); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_RETURN_NODE: { - yp_buffer_append_str(buffer, "ReturnNode(", 11); - prettyprint_location(buffer, parser, &((yp_return_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_return_node_t *)node)->arguments == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_return_node_t *)node)->arguments); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_SELF_NODE: { - yp_buffer_append_str(buffer, "SelfNode(", 9); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_SINGLETON_CLASS_NODE: { - yp_buffer_append_str(buffer, "SingletonClassNode(", 19); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_singleton_class_node_t *)node)->locals.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - char locals_buffer[12]; - snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_singleton_class_node_t *)node)->locals.ids[index]); - yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer)); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_singleton_class_node_t *)node)->class_keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_singleton_class_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->expression); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_singleton_class_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_singleton_class_node_t *)node)->end_keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_SOURCE_ENCODING_NODE: { - yp_buffer_append_str(buffer, "SourceEncodingNode(", 19); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_SOURCE_FILE_NODE: { - yp_buffer_append_str(buffer, "SourceFileNode(", 15); - yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, yp_string_source(&((yp_source_file_node_t *)node)->filepath), yp_string_length(&((yp_source_file_node_t *)node)->filepath)); - yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_SOURCE_LINE_NODE: { - yp_buffer_append_str(buffer, "SourceLineNode(", 15); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_SPLAT_NODE: { - yp_buffer_append_str(buffer, "SplatNode(", 10); - prettyprint_location(buffer, parser, &((yp_splat_node_t *)node)->operator_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_splat_node_t *)node)->expression == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_splat_node_t *)node)->expression); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_STATEMENTS_NODE: { - yp_buffer_append_str(buffer, "StatementsNode(", 15); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_statements_node_t *)node)->body.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_statements_node_t *) node)->body.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_STRING_CONCAT_NODE: { - yp_buffer_append_str(buffer, "StringConcatNode(", 17); - prettyprint_node(buffer, parser, (yp_node_t *)((yp_string_concat_node_t *)node)->left); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_string_concat_node_t *)node)->right); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_STRING_NODE: { - yp_buffer_append_str(buffer, "StringNode(", 11); - if (((yp_string_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_string_node_t *)node)->opening_loc); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_string_node_t *)node)->content_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_string_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_string_node_t *)node)->closing_loc); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, yp_string_source(&((yp_string_node_t *)node)->unescaped), yp_string_length(&((yp_string_node_t *)node)->unescaped)); - yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_SUPER_NODE: { - yp_buffer_append_str(buffer, "SuperNode(", 10); - prettyprint_location(buffer, parser, &((yp_super_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_super_node_t *)node)->lparen_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_super_node_t *)node)->lparen_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_super_node_t *)node)->arguments == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_super_node_t *)node)->arguments); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_super_node_t *)node)->rparen_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_super_node_t *)node)->rparen_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_super_node_t *)node)->block == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_super_node_t *)node)->block); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_SYMBOL_NODE: { - yp_buffer_append_str(buffer, "SymbolNode(", 11); - if (((yp_symbol_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_symbol_node_t *)node)->opening_loc); - } - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_symbol_node_t *)node)->value_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_symbol_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_symbol_node_t *)node)->closing_loc); - } - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, yp_string_source(&((yp_symbol_node_t *)node)->unescaped), yp_string_length(&((yp_symbol_node_t *)node)->unescaped)); - yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_TRUE_NODE: { - yp_buffer_append_str(buffer, "TrueNode(", 9); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_UNDEF_NODE: { - yp_buffer_append_str(buffer, "UndefNode(", 10); - yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_undef_node_t *)node)->names.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_undef_node_t *) node)->names.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_undef_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_UNLESS_NODE: { - yp_buffer_append_str(buffer, "UnlessNode(", 11); - prettyprint_location(buffer, parser, &((yp_unless_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_unless_node_t *)node)->predicate); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_unless_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_unless_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_unless_node_t *)node)->consequent == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_unless_node_t *)node)->consequent); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_unless_node_t *)node)->end_keyword_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_unless_node_t *)node)->end_keyword_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_UNTIL_NODE: { - yp_buffer_append_str(buffer, "UntilNode(", 10); - prettyprint_location(buffer, parser, &((yp_until_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_until_node_t *)node)->predicate); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_until_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_until_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12]; - snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1); - yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_WHEN_NODE: { - yp_buffer_append_str(buffer, "WhenNode(", 9); - prettyprint_location(buffer, parser, &((yp_when_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "[", 1); - for (uint32_t index = 0; index < ((yp_when_node_t *)node)->conditions.size; index++) { - if (index != 0) yp_buffer_append_str(buffer, ", ", 2); - prettyprint_node(buffer, parser, (yp_node_t *) ((yp_when_node_t *) node)->conditions.nodes[index]); - } - yp_buffer_append_str(buffer, "]", 1); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_when_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_when_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_WHILE_NODE: { - yp_buffer_append_str(buffer, "WhileNode(", 10); - prettyprint_location(buffer, parser, &((yp_while_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_while_node_t *)node)->predicate); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_while_node_t *)node)->statements == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_while_node_t *)node)->statements); - } - yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12]; - snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1); - yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer)); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_X_STRING_NODE: { - yp_buffer_append_str(buffer, "XStringNode(", 12); - prettyprint_location(buffer, parser, &((yp_x_string_node_t *)node)->opening_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_x_string_node_t *)node)->content_loc); - yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_x_string_node_t *)node)->closing_loc); - yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, yp_string_source(&((yp_x_string_node_t *)node)->unescaped), yp_string_length(&((yp_x_string_node_t *)node)->unescaped)); - yp_buffer_append_str(buffer, "\"", 1); - yp_buffer_append_str(buffer, ")", 1); - break; - } - case YP_NODE_YIELD_NODE: { - yp_buffer_append_str(buffer, "YieldNode(", 10); - prettyprint_location(buffer, parser, &((yp_yield_node_t *)node)->keyword_loc); - yp_buffer_append_str(buffer, ", ", 2); if (((yp_yield_node_t *)node)->lparen_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_yield_node_t *)node)->lparen_loc); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_yield_node_t *)node)->arguments == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_node(buffer, parser, (yp_node_t *)((yp_yield_node_t *)node)->arguments); - } - yp_buffer_append_str(buffer, ", ", 2); if (((yp_yield_node_t *)node)->rparen_loc.start == NULL) { - yp_buffer_append_str(buffer, "nil", 3); - } else { - prettyprint_location(buffer, parser, &((yp_yield_node_t *)node)->rparen_loc); - } - yp_buffer_append_str(buffer, ")", 1); - break; - } - } -} - -void -yp_print_node(yp_parser_t *parser, yp_node_t *node) { - yp_buffer_t buffer; - if (!yp_buffer_init(&buffer)) return; - - prettyprint_node(&buffer, parser, node); - printf("%.*s\n", (int) buffer.length, buffer.value); - - yp_buffer_free(&buffer); -} - -// Pretty-prints the AST represented by the given node to the given buffer. -YP_EXPORTED_FUNCTION void -yp_prettyprint(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) { - prettyprint_node(buffer, parser, node); -} diff --git a/yarp/serialize.c b/yarp/serialize.c deleted file mode 100644 index 1960cd1fa9f533..00000000000000 --- a/yarp/serialize.c +++ /dev/null @@ -1,1649 +0,0 @@ -/******************************************************************************/ -/* This file is generated by the bin/template script and should not be */ -/* modified manually. See */ -/* templates/src/serialize.c.erb */ -/* if you are looking to modify the */ -/* template */ -/******************************************************************************/ -#include "yarp.h" - -#include - -static inline uint32_t -yp_ptrdifft_to_u32(ptrdiff_t value) { - assert(value >= 0 && ((unsigned long) value) < UINT32_MAX); - return (uint32_t) value; -} - -static inline uint32_t -yp_sizet_to_u32(size_t value) { - assert(value < UINT32_MAX); - return (uint32_t) value; -} - -static void -serialize_location(yp_parser_t *parser, yp_location_t *location, yp_buffer_t *buffer) { - assert(location->start); - assert(location->end); - assert(location->start <= location->end); - - yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(location->start - parser->start)); - yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(location->end - location->start)); -} - -void -yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) { - yp_buffer_append_u8(buffer, (uint8_t) YP_NODE_TYPE(node)); - - size_t offset = buffer->length; - - serialize_location(parser, &node->location, buffer); - - switch (YP_NODE_TYPE(node)) { - case YP_NODE_ALIAS_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_alias_node_t *)node)->new_name, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_alias_node_t *)node)->old_name, buffer); - serialize_location(parser, &((yp_alias_node_t *)node)->keyword_loc, buffer); - break; - } - case YP_NODE_ALTERNATION_PATTERN_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_alternation_pattern_node_t *)node)->left, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_alternation_pattern_node_t *)node)->right, buffer); - serialize_location(parser, &((yp_alternation_pattern_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_AND_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_and_node_t *)node)->left, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_and_node_t *)node)->right, buffer); - serialize_location(parser, &((yp_and_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_ARGUMENTS_NODE: { - uint32_t arguments_size = yp_sizet_to_u32(((yp_arguments_node_t *)node)->arguments.size); - yp_buffer_append_u32(buffer, arguments_size); - for (uint32_t index = 0; index < arguments_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_arguments_node_t *)node)->arguments.nodes[index], buffer); - } - break; - } - case YP_NODE_ARRAY_NODE: { - uint32_t elements_size = yp_sizet_to_u32(((yp_array_node_t *)node)->elements.size); - yp_buffer_append_u32(buffer, elements_size); - for (uint32_t index = 0; index < elements_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_array_node_t *)node)->elements.nodes[index], buffer); - } - if (((yp_array_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_array_node_t *)node)->opening_loc, buffer); - } - if (((yp_array_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_array_node_t *)node)->closing_loc, buffer); - } - break; - } - case YP_NODE_ARRAY_PATTERN_NODE: { - if (((yp_array_pattern_node_t *)node)->constant == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_array_pattern_node_t *)node)->constant, buffer); - } - uint32_t requireds_size = yp_sizet_to_u32(((yp_array_pattern_node_t *)node)->requireds.size); - yp_buffer_append_u32(buffer, requireds_size); - for (uint32_t index = 0; index < requireds_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_array_pattern_node_t *)node)->requireds.nodes[index], buffer); - } - if (((yp_array_pattern_node_t *)node)->rest == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_array_pattern_node_t *)node)->rest, buffer); - } - uint32_t posts_size = yp_sizet_to_u32(((yp_array_pattern_node_t *)node)->posts.size); - yp_buffer_append_u32(buffer, posts_size); - for (uint32_t index = 0; index < posts_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_array_pattern_node_t *)node)->posts.nodes[index], buffer); - } - if (((yp_array_pattern_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_array_pattern_node_t *)node)->opening_loc, buffer); - } - if (((yp_array_pattern_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_array_pattern_node_t *)node)->closing_loc, buffer); - } - break; - } - case YP_NODE_ASSOC_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_assoc_node_t *)node)->key, buffer); - if (((yp_assoc_node_t *)node)->value == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_assoc_node_t *)node)->value, buffer); - } - if (((yp_assoc_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_assoc_node_t *)node)->operator_loc, buffer); - } - break; - } - case YP_NODE_ASSOC_SPLAT_NODE: { - if (((yp_assoc_splat_node_t *)node)->value == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_assoc_splat_node_t *)node)->value, buffer); - } - serialize_location(parser, &((yp_assoc_splat_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_BACK_REFERENCE_READ_NODE: { - break; - } - case YP_NODE_BEGIN_NODE: { - if (((yp_begin_node_t *)node)->begin_keyword_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_begin_node_t *)node)->begin_keyword_loc, buffer); - } - if (((yp_begin_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_begin_node_t *)node)->statements, buffer); - } - if (((yp_begin_node_t *)node)->rescue_clause == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_begin_node_t *)node)->rescue_clause, buffer); - } - if (((yp_begin_node_t *)node)->else_clause == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_begin_node_t *)node)->else_clause, buffer); - } - if (((yp_begin_node_t *)node)->ensure_clause == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_begin_node_t *)node)->ensure_clause, buffer); - } - if (((yp_begin_node_t *)node)->end_keyword_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_begin_node_t *)node)->end_keyword_loc, buffer); - } - break; - } - case YP_NODE_BLOCK_ARGUMENT_NODE: { - if (((yp_block_argument_node_t *)node)->expression == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_block_argument_node_t *)node)->expression, buffer); - } - serialize_location(parser, &((yp_block_argument_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_BLOCK_NODE: { - uint32_t locals_size = yp_sizet_to_u32(((yp_block_node_t *)node)->locals.size); - yp_buffer_append_u32(buffer, locals_size); - for (uint32_t index = 0; index < locals_size; index++) { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_block_node_t *)node)->locals.ids[index])); - } - if (((yp_block_node_t *)node)->parameters == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_block_node_t *)node)->parameters, buffer); - } - if (((yp_block_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_block_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_block_node_t *)node)->opening_loc, buffer); - serialize_location(parser, &((yp_block_node_t *)node)->closing_loc, buffer); - break; - } - case YP_NODE_BLOCK_PARAMETER_NODE: { - if (((yp_block_parameter_node_t *)node)->name_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_block_parameter_node_t *)node)->name_loc, buffer); - } - serialize_location(parser, &((yp_block_parameter_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_BLOCK_PARAMETERS_NODE: { - if (((yp_block_parameters_node_t *)node)->parameters == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_block_parameters_node_t *)node)->parameters, buffer); - } - uint32_t locals_size = yp_sizet_to_u32(((yp_block_parameters_node_t *)node)->locals.size); - yp_buffer_append_u32(buffer, locals_size); - for (uint32_t index = 0; index < locals_size; index++) { - serialize_location(parser, &((yp_block_parameters_node_t *)node)->locals.locations[index], buffer); - } - if (((yp_block_parameters_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_block_parameters_node_t *)node)->opening_loc, buffer); - } - if (((yp_block_parameters_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_block_parameters_node_t *)node)->closing_loc, buffer); - } - break; - } - case YP_NODE_BREAK_NODE: { - if (((yp_break_node_t *)node)->arguments == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_break_node_t *)node)->arguments, buffer); - } - serialize_location(parser, &((yp_break_node_t *)node)->keyword_loc, buffer); - break; - } - case YP_NODE_CALL_NODE: { - if (((yp_call_node_t *)node)->receiver == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_call_node_t *)node)->receiver, buffer); - } - if (((yp_call_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_call_node_t *)node)->operator_loc, buffer); - } - if (((yp_call_node_t *)node)->message_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_call_node_t *)node)->message_loc, buffer); - } - if (((yp_call_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_call_node_t *)node)->opening_loc, buffer); - } - if (((yp_call_node_t *)node)->arguments == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_call_node_t *)node)->arguments, buffer); - } - if (((yp_call_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_call_node_t *)node)->closing_loc, buffer); - } - if (((yp_call_node_t *)node)->block == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_call_node_t *)node)->block, buffer); - } - yp_buffer_append_u32(buffer, node->flags >> 1); - uint32_t name_length = yp_sizet_to_u32(yp_string_length(&((yp_call_node_t *)node)->name)); - yp_buffer_append_u32(buffer, name_length); - yp_buffer_append_str(buffer, yp_string_source(&((yp_call_node_t *)node)->name), name_length); - break; - } - case YP_NODE_CALL_OPERATOR_AND_WRITE_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_and_write_node_t *)node)->target, buffer); - serialize_location(parser, &((yp_call_operator_and_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_and_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_CALL_OPERATOR_OR_WRITE_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_or_write_node_t *)node)->target, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_or_write_node_t *)node)->value, buffer); - serialize_location(parser, &((yp_call_operator_or_write_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_CALL_OPERATOR_WRITE_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->target, buffer); - serialize_location(parser, &((yp_call_operator_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->value, buffer); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_call_operator_write_node_t *)node)->operator_id)); - break; - } - case YP_NODE_CAPTURE_PATTERN_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_capture_pattern_node_t *)node)->value, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_capture_pattern_node_t *)node)->target, buffer); - serialize_location(parser, &((yp_capture_pattern_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_CASE_NODE: { - if (((yp_case_node_t *)node)->predicate == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_case_node_t *)node)->predicate, buffer); - } - uint32_t conditions_size = yp_sizet_to_u32(((yp_case_node_t *)node)->conditions.size); - yp_buffer_append_u32(buffer, conditions_size); - for (uint32_t index = 0; index < conditions_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_case_node_t *)node)->conditions.nodes[index], buffer); - } - if (((yp_case_node_t *)node)->consequent == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_case_node_t *)node)->consequent, buffer); - } - serialize_location(parser, &((yp_case_node_t *)node)->case_keyword_loc, buffer); - serialize_location(parser, &((yp_case_node_t *)node)->end_keyword_loc, buffer); - break; - } - case YP_NODE_CLASS_NODE: { - uint32_t locals_size = yp_sizet_to_u32(((yp_class_node_t *)node)->locals.size); - yp_buffer_append_u32(buffer, locals_size); - for (uint32_t index = 0; index < locals_size; index++) { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_node_t *)node)->locals.ids[index])); - } - serialize_location(parser, &((yp_class_node_t *)node)->class_keyword_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_class_node_t *)node)->constant_path, buffer); - if (((yp_class_node_t *)node)->inheritance_operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_class_node_t *)node)->inheritance_operator_loc, buffer); - } - if (((yp_class_node_t *)node)->superclass == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_class_node_t *)node)->superclass, buffer); - } - if (((yp_class_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_class_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_class_node_t *)node)->end_keyword_loc, buffer); - break; - } - case YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE: { - serialize_location(parser, &((yp_class_variable_operator_and_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_class_variable_operator_and_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_operator_and_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE: { - serialize_location(parser, &((yp_class_variable_operator_or_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_class_variable_operator_or_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_operator_or_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: { - serialize_location(parser, &((yp_class_variable_operator_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_class_variable_operator_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_operator_write_node_t *)node)->value, buffer); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_variable_operator_write_node_t *)node)->operator)); - break; - } - case YP_NODE_CLASS_VARIABLE_READ_NODE: { - break; - } - case YP_NODE_CLASS_VARIABLE_WRITE_NODE: { - serialize_location(parser, &((yp_class_variable_write_node_t *)node)->name_loc, buffer); - if (((yp_class_variable_write_node_t *)node)->value == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_write_node_t *)node)->value, buffer); - } - if (((yp_class_variable_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_class_variable_write_node_t *)node)->operator_loc, buffer); - } - break; - } - case YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE: { - serialize_location(parser, &((yp_constant_operator_and_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_constant_operator_and_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_constant_operator_and_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE: { - serialize_location(parser, &((yp_constant_operator_or_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_constant_operator_or_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_constant_operator_or_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_CONSTANT_OPERATOR_WRITE_NODE: { - serialize_location(parser, &((yp_constant_operator_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_constant_operator_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_constant_operator_write_node_t *)node)->value, buffer); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_constant_operator_write_node_t *)node)->operator)); - break; - } - case YP_NODE_CONSTANT_PATH_NODE: { - if (((yp_constant_path_node_t *)node)->parent == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_node_t *)node)->parent, buffer); - } - yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_node_t *)node)->child, buffer); - serialize_location(parser, &((yp_constant_path_node_t *)node)->delimiter_loc, buffer); - break; - } - case YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->target, buffer); - serialize_location(parser, &((yp_constant_path_operator_and_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->target, buffer); - serialize_location(parser, &((yp_constant_path_operator_or_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->target, buffer); - serialize_location(parser, &((yp_constant_path_operator_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->value, buffer); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_constant_path_operator_write_node_t *)node)->operator)); - break; - } - case YP_NODE_CONSTANT_PATH_WRITE_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->target, buffer); - if (((yp_constant_path_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_constant_path_write_node_t *)node)->operator_loc, buffer); - } - if (((yp_constant_path_write_node_t *)node)->value == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->value, buffer); - } - break; - } - case YP_NODE_CONSTANT_READ_NODE: { - break; - } - case YP_NODE_CONSTANT_WRITE_NODE: { - serialize_location(parser, &((yp_constant_write_node_t *)node)->name_loc, buffer); - if (((yp_constant_write_node_t *)node)->value == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_constant_write_node_t *)node)->value, buffer); - } - if (((yp_constant_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_constant_write_node_t *)node)->operator_loc, buffer); - } - break; - } - case YP_NODE_DEF_NODE: { - // serialize length - // encoding of location u32s make us need to save this offset. - size_t length_offset = buffer->length; - yp_buffer_append_str(buffer, "\0\0\0\0", 4); /* consume 4 bytes, updated below */ - serialize_location(parser, &((yp_def_node_t *)node)->name_loc, buffer); - if (((yp_def_node_t *)node)->receiver == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_def_node_t *)node)->receiver, buffer); - } - if (((yp_def_node_t *)node)->parameters == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_def_node_t *)node)->parameters, buffer); - } - if (((yp_def_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_def_node_t *)node)->statements, buffer); - } - uint32_t locals_size = yp_sizet_to_u32(((yp_def_node_t *)node)->locals.size); - yp_buffer_append_u32(buffer, locals_size); - for (uint32_t index = 0; index < locals_size; index++) { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_def_node_t *)node)->locals.ids[index])); - } - serialize_location(parser, &((yp_def_node_t *)node)->def_keyword_loc, buffer); - if (((yp_def_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_def_node_t *)node)->operator_loc, buffer); - } - if (((yp_def_node_t *)node)->lparen_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_def_node_t *)node)->lparen_loc, buffer); - } - if (((yp_def_node_t *)node)->rparen_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_def_node_t *)node)->rparen_loc, buffer); - } - if (((yp_def_node_t *)node)->equal_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_def_node_t *)node)->equal_loc, buffer); - } - if (((yp_def_node_t *)node)->end_keyword_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_def_node_t *)node)->end_keyword_loc, buffer); - } - // serialize length - uint32_t length = yp_sizet_to_u32(buffer->length - offset - sizeof(uint32_t)); - memcpy(buffer->value + length_offset, &length, sizeof(uint32_t)); - break; - } - case YP_NODE_DEFINED_NODE: { - if (((yp_defined_node_t *)node)->lparen_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_defined_node_t *)node)->lparen_loc, buffer); - } - yp_serialize_node(parser, (yp_node_t *)((yp_defined_node_t *)node)->value, buffer); - if (((yp_defined_node_t *)node)->rparen_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_defined_node_t *)node)->rparen_loc, buffer); - } - serialize_location(parser, &((yp_defined_node_t *)node)->keyword_loc, buffer); - break; - } - case YP_NODE_ELSE_NODE: { - serialize_location(parser, &((yp_else_node_t *)node)->else_keyword_loc, buffer); - if (((yp_else_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_else_node_t *)node)->statements, buffer); - } - if (((yp_else_node_t *)node)->end_keyword_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_else_node_t *)node)->end_keyword_loc, buffer); - } - break; - } - case YP_NODE_EMBEDDED_STATEMENTS_NODE: { - serialize_location(parser, &((yp_embedded_statements_node_t *)node)->opening_loc, buffer); - if (((yp_embedded_statements_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_embedded_statements_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_embedded_statements_node_t *)node)->closing_loc, buffer); - break; - } - case YP_NODE_EMBEDDED_VARIABLE_NODE: { - serialize_location(parser, &((yp_embedded_variable_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_embedded_variable_node_t *)node)->variable, buffer); - break; - } - case YP_NODE_ENSURE_NODE: { - serialize_location(parser, &((yp_ensure_node_t *)node)->ensure_keyword_loc, buffer); - if (((yp_ensure_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_ensure_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_ensure_node_t *)node)->end_keyword_loc, buffer); - break; - } - case YP_NODE_FALSE_NODE: { - break; - } - case YP_NODE_FIND_PATTERN_NODE: { - if (((yp_find_pattern_node_t *)node)->constant == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_find_pattern_node_t *)node)->constant, buffer); - } - yp_serialize_node(parser, (yp_node_t *)((yp_find_pattern_node_t *)node)->left, buffer); - uint32_t requireds_size = yp_sizet_to_u32(((yp_find_pattern_node_t *)node)->requireds.size); - yp_buffer_append_u32(buffer, requireds_size); - for (uint32_t index = 0; index < requireds_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_find_pattern_node_t *)node)->requireds.nodes[index], buffer); - } - yp_serialize_node(parser, (yp_node_t *)((yp_find_pattern_node_t *)node)->right, buffer); - if (((yp_find_pattern_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_find_pattern_node_t *)node)->opening_loc, buffer); - } - if (((yp_find_pattern_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_find_pattern_node_t *)node)->closing_loc, buffer); - } - break; - } - case YP_NODE_FLIP_FLOP_NODE: { - if (((yp_flip_flop_node_t *)node)->left == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->left, buffer); - } - if (((yp_flip_flop_node_t *)node)->right == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->right, buffer); - } - serialize_location(parser, &((yp_flip_flop_node_t *)node)->operator_loc, buffer); - yp_buffer_append_u32(buffer, node->flags >> 1); - break; - } - case YP_NODE_FLOAT_NODE: { - break; - } - case YP_NODE_FOR_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_for_node_t *)node)->index, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_for_node_t *)node)->collection, buffer); - if (((yp_for_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_for_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_for_node_t *)node)->for_keyword_loc, buffer); - serialize_location(parser, &((yp_for_node_t *)node)->in_keyword_loc, buffer); - if (((yp_for_node_t *)node)->do_keyword_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_for_node_t *)node)->do_keyword_loc, buffer); - } - serialize_location(parser, &((yp_for_node_t *)node)->end_keyword_loc, buffer); - break; - } - case YP_NODE_FORWARDING_ARGUMENTS_NODE: { - break; - } - case YP_NODE_FORWARDING_PARAMETER_NODE: { - break; - } - case YP_NODE_FORWARDING_SUPER_NODE: { - if (((yp_forwarding_super_node_t *)node)->block == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_forwarding_super_node_t *)node)->block, buffer); - } - break; - } - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE: { - serialize_location(parser, &((yp_global_variable_operator_and_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_global_variable_operator_and_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_operator_and_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE: { - serialize_location(parser, &((yp_global_variable_operator_or_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_global_variable_operator_or_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_operator_or_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: { - serialize_location(parser, &((yp_global_variable_operator_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_global_variable_operator_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_operator_write_node_t *)node)->value, buffer); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_global_variable_operator_write_node_t *)node)->operator)); - break; - } - case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { - break; - } - case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: { - serialize_location(parser, &((yp_global_variable_write_node_t *)node)->name_loc, buffer); - if (((yp_global_variable_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_global_variable_write_node_t *)node)->operator_loc, buffer); - } - if (((yp_global_variable_write_node_t *)node)->value == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_write_node_t *)node)->value, buffer); - } - break; - } - case YP_NODE_HASH_NODE: { - serialize_location(parser, &((yp_hash_node_t *)node)->opening_loc, buffer); - uint32_t elements_size = yp_sizet_to_u32(((yp_hash_node_t *)node)->elements.size); - yp_buffer_append_u32(buffer, elements_size); - for (uint32_t index = 0; index < elements_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_hash_node_t *)node)->elements.nodes[index], buffer); - } - serialize_location(parser, &((yp_hash_node_t *)node)->closing_loc, buffer); - break; - } - case YP_NODE_HASH_PATTERN_NODE: { - if (((yp_hash_pattern_node_t *)node)->constant == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_hash_pattern_node_t *)node)->constant, buffer); - } - uint32_t assocs_size = yp_sizet_to_u32(((yp_hash_pattern_node_t *)node)->assocs.size); - yp_buffer_append_u32(buffer, assocs_size); - for (uint32_t index = 0; index < assocs_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_hash_pattern_node_t *)node)->assocs.nodes[index], buffer); - } - if (((yp_hash_pattern_node_t *)node)->kwrest == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_hash_pattern_node_t *)node)->kwrest, buffer); - } - if (((yp_hash_pattern_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_hash_pattern_node_t *)node)->opening_loc, buffer); - } - if (((yp_hash_pattern_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_hash_pattern_node_t *)node)->closing_loc, buffer); - } - break; - } - case YP_NODE_IF_NODE: { - if (((yp_if_node_t *)node)->if_keyword_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_if_node_t *)node)->if_keyword_loc, buffer); - } - yp_serialize_node(parser, (yp_node_t *)((yp_if_node_t *)node)->predicate, buffer); - if (((yp_if_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_if_node_t *)node)->statements, buffer); - } - if (((yp_if_node_t *)node)->consequent == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_if_node_t *)node)->consequent, buffer); - } - if (((yp_if_node_t *)node)->end_keyword_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_if_node_t *)node)->end_keyword_loc, buffer); - } - break; - } - case YP_NODE_IMAGINARY_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_imaginary_node_t *)node)->numeric, buffer); - break; - } - case YP_NODE_IN_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_in_node_t *)node)->pattern, buffer); - if (((yp_in_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_in_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_in_node_t *)node)->in_loc, buffer); - if (((yp_in_node_t *)node)->then_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_in_node_t *)node)->then_loc, buffer); - } - break; - } - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE: { - serialize_location(parser, &((yp_instance_variable_operator_and_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_instance_variable_operator_and_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_operator_and_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE: { - serialize_location(parser, &((yp_instance_variable_operator_or_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_instance_variable_operator_or_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_operator_or_write_node_t *)node)->value, buffer); - break; - } - case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: { - serialize_location(parser, &((yp_instance_variable_operator_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_instance_variable_operator_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_operator_write_node_t *)node)->value, buffer); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_instance_variable_operator_write_node_t *)node)->operator)); - break; - } - case YP_NODE_INSTANCE_VARIABLE_READ_NODE: { - break; - } - case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: { - serialize_location(parser, &((yp_instance_variable_write_node_t *)node)->name_loc, buffer); - if (((yp_instance_variable_write_node_t *)node)->value == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_write_node_t *)node)->value, buffer); - } - if (((yp_instance_variable_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_instance_variable_write_node_t *)node)->operator_loc, buffer); - } - break; - } - case YP_NODE_INTEGER_NODE: { - break; - } - case YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE: { - serialize_location(parser, &((yp_interpolated_regular_expression_node_t *)node)->opening_loc, buffer); - uint32_t parts_size = yp_sizet_to_u32(((yp_interpolated_regular_expression_node_t *)node)->parts.size); - yp_buffer_append_u32(buffer, parts_size); - for (uint32_t index = 0; index < parts_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_interpolated_regular_expression_node_t *)node)->parts.nodes[index], buffer); - } - serialize_location(parser, &((yp_interpolated_regular_expression_node_t *)node)->closing_loc, buffer); - yp_buffer_append_u32(buffer, node->flags >> 1); - break; - } - case YP_NODE_INTERPOLATED_STRING_NODE: { - if (((yp_interpolated_string_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_interpolated_string_node_t *)node)->opening_loc, buffer); - } - uint32_t parts_size = yp_sizet_to_u32(((yp_interpolated_string_node_t *)node)->parts.size); - yp_buffer_append_u32(buffer, parts_size); - for (uint32_t index = 0; index < parts_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_interpolated_string_node_t *)node)->parts.nodes[index], buffer); - } - if (((yp_interpolated_string_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_interpolated_string_node_t *)node)->closing_loc, buffer); - } - break; - } - case YP_NODE_INTERPOLATED_SYMBOL_NODE: { - if (((yp_interpolated_symbol_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_interpolated_symbol_node_t *)node)->opening_loc, buffer); - } - uint32_t parts_size = yp_sizet_to_u32(((yp_interpolated_symbol_node_t *)node)->parts.size); - yp_buffer_append_u32(buffer, parts_size); - for (uint32_t index = 0; index < parts_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_interpolated_symbol_node_t *)node)->parts.nodes[index], buffer); - } - if (((yp_interpolated_symbol_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_interpolated_symbol_node_t *)node)->closing_loc, buffer); - } - break; - } - case YP_NODE_INTERPOLATED_X_STRING_NODE: { - serialize_location(parser, &((yp_interpolated_x_string_node_t *)node)->opening_loc, buffer); - uint32_t parts_size = yp_sizet_to_u32(((yp_interpolated_x_string_node_t *)node)->parts.size); - yp_buffer_append_u32(buffer, parts_size); - for (uint32_t index = 0; index < parts_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_interpolated_x_string_node_t *)node)->parts.nodes[index], buffer); - } - serialize_location(parser, &((yp_interpolated_x_string_node_t *)node)->closing_loc, buffer); - break; - } - case YP_NODE_KEYWORD_HASH_NODE: { - uint32_t elements_size = yp_sizet_to_u32(((yp_keyword_hash_node_t *)node)->elements.size); - yp_buffer_append_u32(buffer, elements_size); - for (uint32_t index = 0; index < elements_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_keyword_hash_node_t *)node)->elements.nodes[index], buffer); - } - break; - } - case YP_NODE_KEYWORD_PARAMETER_NODE: { - serialize_location(parser, &((yp_keyword_parameter_node_t *)node)->name_loc, buffer); - if (((yp_keyword_parameter_node_t *)node)->value == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_keyword_parameter_node_t *)node)->value, buffer); - } - break; - } - case YP_NODE_KEYWORD_REST_PARAMETER_NODE: { - serialize_location(parser, &((yp_keyword_rest_parameter_node_t *)node)->operator_loc, buffer); - if (((yp_keyword_rest_parameter_node_t *)node)->name_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_keyword_rest_parameter_node_t *)node)->name_loc, buffer); - } - break; - } - case YP_NODE_LAMBDA_NODE: { - uint32_t locals_size = yp_sizet_to_u32(((yp_lambda_node_t *)node)->locals.size); - yp_buffer_append_u32(buffer, locals_size); - for (uint32_t index = 0; index < locals_size; index++) { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_lambda_node_t *)node)->locals.ids[index])); - } - serialize_location(parser, &((yp_lambda_node_t *)node)->opening_loc, buffer); - if (((yp_lambda_node_t *)node)->parameters == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_lambda_node_t *)node)->parameters, buffer); - } - if (((yp_lambda_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_lambda_node_t *)node)->statements, buffer); - } - break; - } - case YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE: { - serialize_location(parser, &((yp_local_variable_operator_and_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_local_variable_operator_and_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_operator_and_write_node_t *)node)->value, buffer); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_and_write_node_t *)node)->constant_id)); - break; - } - case YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE: { - serialize_location(parser, &((yp_local_variable_operator_or_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_local_variable_operator_or_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_operator_or_write_node_t *)node)->value, buffer); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_or_write_node_t *)node)->constant_id)); - break; - } - case YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: { - serialize_location(parser, &((yp_local_variable_operator_write_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_local_variable_operator_write_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_operator_write_node_t *)node)->value, buffer); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_write_node_t *)node)->constant_id)); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_write_node_t *)node)->operator_id)); - break; - } - case YP_NODE_LOCAL_VARIABLE_READ_NODE: { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_read_node_t *)node)->constant_id)); - yp_buffer_append_u32(buffer, ((yp_local_variable_read_node_t *)node)->depth); - break; - } - case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_write_node_t *)node)->constant_id)); - yp_buffer_append_u32(buffer, ((yp_local_variable_write_node_t *)node)->depth); - if (((yp_local_variable_write_node_t *)node)->value == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_write_node_t *)node)->value, buffer); - } - serialize_location(parser, &((yp_local_variable_write_node_t *)node)->name_loc, buffer); - if (((yp_local_variable_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_local_variable_write_node_t *)node)->operator_loc, buffer); - } - break; - } - case YP_NODE_MATCH_PREDICATE_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_match_predicate_node_t *)node)->value, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_match_predicate_node_t *)node)->pattern, buffer); - serialize_location(parser, &((yp_match_predicate_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_MATCH_REQUIRED_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_match_required_node_t *)node)->value, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_match_required_node_t *)node)->pattern, buffer); - serialize_location(parser, &((yp_match_required_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_MISSING_NODE: { - break; - } - case YP_NODE_MODULE_NODE: { - uint32_t locals_size = yp_sizet_to_u32(((yp_module_node_t *)node)->locals.size); - yp_buffer_append_u32(buffer, locals_size); - for (uint32_t index = 0; index < locals_size; index++) { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_module_node_t *)node)->locals.ids[index])); - } - serialize_location(parser, &((yp_module_node_t *)node)->module_keyword_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_module_node_t *)node)->constant_path, buffer); - if (((yp_module_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_module_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_module_node_t *)node)->end_keyword_loc, buffer); - break; - } - case YP_NODE_MULTI_WRITE_NODE: { - uint32_t targets_size = yp_sizet_to_u32(((yp_multi_write_node_t *)node)->targets.size); - yp_buffer_append_u32(buffer, targets_size); - for (uint32_t index = 0; index < targets_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_multi_write_node_t *)node)->targets.nodes[index], buffer); - } - if (((yp_multi_write_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_multi_write_node_t *)node)->operator_loc, buffer); - } - if (((yp_multi_write_node_t *)node)->value == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_multi_write_node_t *)node)->value, buffer); - } - if (((yp_multi_write_node_t *)node)->lparen_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_multi_write_node_t *)node)->lparen_loc, buffer); - } - if (((yp_multi_write_node_t *)node)->rparen_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_multi_write_node_t *)node)->rparen_loc, buffer); - } - break; - } - case YP_NODE_NEXT_NODE: { - if (((yp_next_node_t *)node)->arguments == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_next_node_t *)node)->arguments, buffer); - } - serialize_location(parser, &((yp_next_node_t *)node)->keyword_loc, buffer); - break; - } - case YP_NODE_NIL_NODE: { - break; - } - case YP_NODE_NO_KEYWORDS_PARAMETER_NODE: { - serialize_location(parser, &((yp_no_keywords_parameter_node_t *)node)->operator_loc, buffer); - serialize_location(parser, &((yp_no_keywords_parameter_node_t *)node)->keyword_loc, buffer); - break; - } - case YP_NODE_NUMBERED_REFERENCE_READ_NODE: { - break; - } - case YP_NODE_OPTIONAL_PARAMETER_NODE: { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_optional_parameter_node_t *)node)->constant_id)); - serialize_location(parser, &((yp_optional_parameter_node_t *)node)->name_loc, buffer); - serialize_location(parser, &((yp_optional_parameter_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_optional_parameter_node_t *)node)->value, buffer); - break; - } - case YP_NODE_OR_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_or_node_t *)node)->left, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_or_node_t *)node)->right, buffer); - serialize_location(parser, &((yp_or_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_PARAMETERS_NODE: { - uint32_t requireds_size = yp_sizet_to_u32(((yp_parameters_node_t *)node)->requireds.size); - yp_buffer_append_u32(buffer, requireds_size); - for (uint32_t index = 0; index < requireds_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_parameters_node_t *)node)->requireds.nodes[index], buffer); - } - uint32_t optionals_size = yp_sizet_to_u32(((yp_parameters_node_t *)node)->optionals.size); - yp_buffer_append_u32(buffer, optionals_size); - for (uint32_t index = 0; index < optionals_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_parameters_node_t *)node)->optionals.nodes[index], buffer); - } - uint32_t posts_size = yp_sizet_to_u32(((yp_parameters_node_t *)node)->posts.size); - yp_buffer_append_u32(buffer, posts_size); - for (uint32_t index = 0; index < posts_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_parameters_node_t *)node)->posts.nodes[index], buffer); - } - if (((yp_parameters_node_t *)node)->rest == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_parameters_node_t *)node)->rest, buffer); - } - uint32_t keywords_size = yp_sizet_to_u32(((yp_parameters_node_t *)node)->keywords.size); - yp_buffer_append_u32(buffer, keywords_size); - for (uint32_t index = 0; index < keywords_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_parameters_node_t *)node)->keywords.nodes[index], buffer); - } - if (((yp_parameters_node_t *)node)->keyword_rest == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_parameters_node_t *)node)->keyword_rest, buffer); - } - if (((yp_parameters_node_t *)node)->block == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_parameters_node_t *)node)->block, buffer); - } - break; - } - case YP_NODE_PARENTHESES_NODE: { - if (((yp_parentheses_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_parentheses_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_parentheses_node_t *)node)->opening_loc, buffer); - serialize_location(parser, &((yp_parentheses_node_t *)node)->closing_loc, buffer); - break; - } - case YP_NODE_PINNED_EXPRESSION_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_pinned_expression_node_t *)node)->expression, buffer); - serialize_location(parser, &((yp_pinned_expression_node_t *)node)->operator_loc, buffer); - serialize_location(parser, &((yp_pinned_expression_node_t *)node)->lparen_loc, buffer); - serialize_location(parser, &((yp_pinned_expression_node_t *)node)->rparen_loc, buffer); - break; - } - case YP_NODE_PINNED_VARIABLE_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_pinned_variable_node_t *)node)->variable, buffer); - serialize_location(parser, &((yp_pinned_variable_node_t *)node)->operator_loc, buffer); - break; - } - case YP_NODE_POST_EXECUTION_NODE: { - if (((yp_post_execution_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_post_execution_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_post_execution_node_t *)node)->keyword_loc, buffer); - serialize_location(parser, &((yp_post_execution_node_t *)node)->opening_loc, buffer); - serialize_location(parser, &((yp_post_execution_node_t *)node)->closing_loc, buffer); - break; - } - case YP_NODE_PRE_EXECUTION_NODE: { - if (((yp_pre_execution_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_pre_execution_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_pre_execution_node_t *)node)->keyword_loc, buffer); - serialize_location(parser, &((yp_pre_execution_node_t *)node)->opening_loc, buffer); - serialize_location(parser, &((yp_pre_execution_node_t *)node)->closing_loc, buffer); - break; - } - case YP_NODE_PROGRAM_NODE: { - uint32_t locals_size = yp_sizet_to_u32(((yp_program_node_t *)node)->locals.size); - yp_buffer_append_u32(buffer, locals_size); - for (uint32_t index = 0; index < locals_size; index++) { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_program_node_t *)node)->locals.ids[index])); - } - yp_serialize_node(parser, (yp_node_t *)((yp_program_node_t *)node)->statements, buffer); - break; - } - case YP_NODE_RANGE_NODE: { - if (((yp_range_node_t *)node)->left == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_range_node_t *)node)->left, buffer); - } - if (((yp_range_node_t *)node)->right == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_range_node_t *)node)->right, buffer); - } - serialize_location(parser, &((yp_range_node_t *)node)->operator_loc, buffer); - yp_buffer_append_u32(buffer, node->flags >> 1); - break; - } - case YP_NODE_RATIONAL_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_rational_node_t *)node)->numeric, buffer); - break; - } - case YP_NODE_REDO_NODE: { - break; - } - case YP_NODE_REGULAR_EXPRESSION_NODE: { - serialize_location(parser, &((yp_regular_expression_node_t *)node)->opening_loc, buffer); - serialize_location(parser, &((yp_regular_expression_node_t *)node)->content_loc, buffer); - serialize_location(parser, &((yp_regular_expression_node_t *)node)->closing_loc, buffer); - uint32_t unescaped_length = yp_sizet_to_u32(yp_string_length(&((yp_regular_expression_node_t *)node)->unescaped)); - yp_buffer_append_u32(buffer, unescaped_length); - yp_buffer_append_str(buffer, yp_string_source(&((yp_regular_expression_node_t *)node)->unescaped), unescaped_length); - yp_buffer_append_u32(buffer, node->flags >> 1); - break; - } - case YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE: { - uint32_t parameters_size = yp_sizet_to_u32(((yp_required_destructured_parameter_node_t *)node)->parameters.size); - yp_buffer_append_u32(buffer, parameters_size); - for (uint32_t index = 0; index < parameters_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_required_destructured_parameter_node_t *)node)->parameters.nodes[index], buffer); - } - serialize_location(parser, &((yp_required_destructured_parameter_node_t *)node)->opening_loc, buffer); - serialize_location(parser, &((yp_required_destructured_parameter_node_t *)node)->closing_loc, buffer); - break; - } - case YP_NODE_REQUIRED_PARAMETER_NODE: { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_required_parameter_node_t *)node)->constant_id)); - break; - } - case YP_NODE_RESCUE_MODIFIER_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_rescue_modifier_node_t *)node)->expression, buffer); - serialize_location(parser, &((yp_rescue_modifier_node_t *)node)->keyword_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_rescue_modifier_node_t *)node)->rescue_expression, buffer); - break; - } - case YP_NODE_RESCUE_NODE: { - serialize_location(parser, &((yp_rescue_node_t *)node)->keyword_loc, buffer); - uint32_t exceptions_size = yp_sizet_to_u32(((yp_rescue_node_t *)node)->exceptions.size); - yp_buffer_append_u32(buffer, exceptions_size); - for (uint32_t index = 0; index < exceptions_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_rescue_node_t *)node)->exceptions.nodes[index], buffer); - } - if (((yp_rescue_node_t *)node)->operator_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_rescue_node_t *)node)->operator_loc, buffer); - } - if (((yp_rescue_node_t *)node)->reference == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_rescue_node_t *)node)->reference, buffer); - } - if (((yp_rescue_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_rescue_node_t *)node)->statements, buffer); - } - if (((yp_rescue_node_t *)node)->consequent == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_rescue_node_t *)node)->consequent, buffer); - } - break; - } - case YP_NODE_REST_PARAMETER_NODE: { - serialize_location(parser, &((yp_rest_parameter_node_t *)node)->operator_loc, buffer); - if (((yp_rest_parameter_node_t *)node)->name_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_rest_parameter_node_t *)node)->name_loc, buffer); - } - break; - } - case YP_NODE_RETRY_NODE: { - break; - } - case YP_NODE_RETURN_NODE: { - serialize_location(parser, &((yp_return_node_t *)node)->keyword_loc, buffer); - if (((yp_return_node_t *)node)->arguments == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_return_node_t *)node)->arguments, buffer); - } - break; - } - case YP_NODE_SELF_NODE: { - break; - } - case YP_NODE_SINGLETON_CLASS_NODE: { - uint32_t locals_size = yp_sizet_to_u32(((yp_singleton_class_node_t *)node)->locals.size); - yp_buffer_append_u32(buffer, locals_size); - for (uint32_t index = 0; index < locals_size; index++) { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_singleton_class_node_t *)node)->locals.ids[index])); - } - serialize_location(parser, &((yp_singleton_class_node_t *)node)->class_keyword_loc, buffer); - serialize_location(parser, &((yp_singleton_class_node_t *)node)->operator_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->expression, buffer); - if (((yp_singleton_class_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->statements, buffer); - } - serialize_location(parser, &((yp_singleton_class_node_t *)node)->end_keyword_loc, buffer); - break; - } - case YP_NODE_SOURCE_ENCODING_NODE: { - break; - } - case YP_NODE_SOURCE_FILE_NODE: { - uint32_t filepath_length = yp_sizet_to_u32(yp_string_length(&((yp_source_file_node_t *)node)->filepath)); - yp_buffer_append_u32(buffer, filepath_length); - yp_buffer_append_str(buffer, yp_string_source(&((yp_source_file_node_t *)node)->filepath), filepath_length); - break; - } - case YP_NODE_SOURCE_LINE_NODE: { - break; - } - case YP_NODE_SPLAT_NODE: { - serialize_location(parser, &((yp_splat_node_t *)node)->operator_loc, buffer); - if (((yp_splat_node_t *)node)->expression == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_splat_node_t *)node)->expression, buffer); - } - break; - } - case YP_NODE_STATEMENTS_NODE: { - uint32_t body_size = yp_sizet_to_u32(((yp_statements_node_t *)node)->body.size); - yp_buffer_append_u32(buffer, body_size); - for (uint32_t index = 0; index < body_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_statements_node_t *)node)->body.nodes[index], buffer); - } - break; - } - case YP_NODE_STRING_CONCAT_NODE: { - yp_serialize_node(parser, (yp_node_t *)((yp_string_concat_node_t *)node)->left, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_string_concat_node_t *)node)->right, buffer); - break; - } - case YP_NODE_STRING_NODE: { - if (((yp_string_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_string_node_t *)node)->opening_loc, buffer); - } - serialize_location(parser, &((yp_string_node_t *)node)->content_loc, buffer); - if (((yp_string_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_string_node_t *)node)->closing_loc, buffer); - } - uint32_t unescaped_length = yp_sizet_to_u32(yp_string_length(&((yp_string_node_t *)node)->unescaped)); - yp_buffer_append_u32(buffer, unescaped_length); - yp_buffer_append_str(buffer, yp_string_source(&((yp_string_node_t *)node)->unescaped), unescaped_length); - break; - } - case YP_NODE_SUPER_NODE: { - serialize_location(parser, &((yp_super_node_t *)node)->keyword_loc, buffer); - if (((yp_super_node_t *)node)->lparen_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_super_node_t *)node)->lparen_loc, buffer); - } - if (((yp_super_node_t *)node)->arguments == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_super_node_t *)node)->arguments, buffer); - } - if (((yp_super_node_t *)node)->rparen_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_super_node_t *)node)->rparen_loc, buffer); - } - if (((yp_super_node_t *)node)->block == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_super_node_t *)node)->block, buffer); - } - break; - } - case YP_NODE_SYMBOL_NODE: { - if (((yp_symbol_node_t *)node)->opening_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_symbol_node_t *)node)->opening_loc, buffer); - } - serialize_location(parser, &((yp_symbol_node_t *)node)->value_loc, buffer); - if (((yp_symbol_node_t *)node)->closing_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_symbol_node_t *)node)->closing_loc, buffer); - } - uint32_t unescaped_length = yp_sizet_to_u32(yp_string_length(&((yp_symbol_node_t *)node)->unescaped)); - yp_buffer_append_u32(buffer, unescaped_length); - yp_buffer_append_str(buffer, yp_string_source(&((yp_symbol_node_t *)node)->unescaped), unescaped_length); - break; - } - case YP_NODE_TRUE_NODE: { - break; - } - case YP_NODE_UNDEF_NODE: { - uint32_t names_size = yp_sizet_to_u32(((yp_undef_node_t *)node)->names.size); - yp_buffer_append_u32(buffer, names_size); - for (uint32_t index = 0; index < names_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_undef_node_t *)node)->names.nodes[index], buffer); - } - serialize_location(parser, &((yp_undef_node_t *)node)->keyword_loc, buffer); - break; - } - case YP_NODE_UNLESS_NODE: { - serialize_location(parser, &((yp_unless_node_t *)node)->keyword_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_unless_node_t *)node)->predicate, buffer); - if (((yp_unless_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_unless_node_t *)node)->statements, buffer); - } - if (((yp_unless_node_t *)node)->consequent == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_unless_node_t *)node)->consequent, buffer); - } - if (((yp_unless_node_t *)node)->end_keyword_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_unless_node_t *)node)->end_keyword_loc, buffer); - } - break; - } - case YP_NODE_UNTIL_NODE: { - serialize_location(parser, &((yp_until_node_t *)node)->keyword_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_until_node_t *)node)->predicate, buffer); - if (((yp_until_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_until_node_t *)node)->statements, buffer); - } - yp_buffer_append_u32(buffer, node->flags >> 1); - break; - } - case YP_NODE_WHEN_NODE: { - serialize_location(parser, &((yp_when_node_t *)node)->keyword_loc, buffer); - uint32_t conditions_size = yp_sizet_to_u32(((yp_when_node_t *)node)->conditions.size); - yp_buffer_append_u32(buffer, conditions_size); - for (uint32_t index = 0; index < conditions_size; index++) { - yp_serialize_node(parser, (yp_node_t *) ((yp_when_node_t *)node)->conditions.nodes[index], buffer); - } - if (((yp_when_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_when_node_t *)node)->statements, buffer); - } - break; - } - case YP_NODE_WHILE_NODE: { - serialize_location(parser, &((yp_while_node_t *)node)->keyword_loc, buffer); - yp_serialize_node(parser, (yp_node_t *)((yp_while_node_t *)node)->predicate, buffer); - if (((yp_while_node_t *)node)->statements == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_while_node_t *)node)->statements, buffer); - } - yp_buffer_append_u32(buffer, node->flags >> 1); - break; - } - case YP_NODE_X_STRING_NODE: { - serialize_location(parser, &((yp_x_string_node_t *)node)->opening_loc, buffer); - serialize_location(parser, &((yp_x_string_node_t *)node)->content_loc, buffer); - serialize_location(parser, &((yp_x_string_node_t *)node)->closing_loc, buffer); - uint32_t unescaped_length = yp_sizet_to_u32(yp_string_length(&((yp_x_string_node_t *)node)->unescaped)); - yp_buffer_append_u32(buffer, unescaped_length); - yp_buffer_append_str(buffer, yp_string_source(&((yp_x_string_node_t *)node)->unescaped), unescaped_length); - break; - } - case YP_NODE_YIELD_NODE: { - serialize_location(parser, &((yp_yield_node_t *)node)->keyword_loc, buffer); - if (((yp_yield_node_t *)node)->lparen_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_yield_node_t *)node)->lparen_loc, buffer); - } - if (((yp_yield_node_t *)node)->arguments == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_serialize_node(parser, (yp_node_t *)((yp_yield_node_t *)node)->arguments, buffer); - } - if (((yp_yield_node_t *)node)->rparen_loc.start == NULL) { - yp_buffer_append_u8(buffer, 0); - } else { - yp_buffer_append_u8(buffer, 1); - serialize_location(parser, &((yp_yield_node_t *)node)->rparen_loc, buffer); - } - break; - } - } -} - -void yp_serialize_comment(yp_parser_t *parser, yp_comment_t *comment, yp_buffer_t *buffer) { - // serialize type - yp_buffer_append_u8(buffer, (uint8_t) comment->type); - - // serialize location - yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(comment->start - parser->start)); - yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(comment->end - comment->start)); -} - -void yp_serialize_comment_list(yp_parser_t *parser, yp_list_t list, yp_buffer_t *buffer) { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_list_size(&list))); - - yp_comment_t *comment; - for (comment = (yp_comment_t *) list.head; comment != NULL; comment = (yp_comment_t *) comment->node.next) { - yp_serialize_comment(parser, comment, buffer); - } -} - -void yp_serialize_diagnostic(yp_parser_t *parser, yp_diagnostic_t *diagnostic, yp_buffer_t *buffer) { - // serialize message - size_t message_length = strlen(diagnostic->message); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(message_length)); - yp_buffer_append_str(buffer, diagnostic->message, message_length); - - // serialize location - yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(diagnostic->start - parser->start)); - yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(diagnostic->end - diagnostic->start)); -} - -void yp_serialize_diagnostic_list(yp_parser_t *parser, yp_list_t list, yp_buffer_t *buffer) { - yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_list_size(&list))); - - yp_diagnostic_t *diagnostic; - for (diagnostic = (yp_diagnostic_t *) list.head; diagnostic != NULL; diagnostic = (yp_diagnostic_t *) diagnostic->node.next) { - yp_serialize_diagnostic(parser, diagnostic, buffer); - } -} - -#line 145 "serialize.c.erb" -void -yp_serialize_content(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) { - // First, serialize the encoding of the parser. - size_t encoding_length = strlen(parser->encoding.name); - yp_buffer_append_u32(buffer, yp_sizet_to_u32(encoding_length)); - yp_buffer_append_str(buffer, parser->encoding.name, encoding_length); - - // Serialize the comments - yp_serialize_comment_list(parser, parser->comment_list, buffer); - - // Serialize the errors - yp_serialize_diagnostic_list(parser, parser->error_list, buffer); - - // Serialize the warnings - yp_serialize_diagnostic_list(parser, parser->warning_list, buffer); - - // Here we're going to leave space for the offset of the constant pool in - // the buffer. - size_t offset = buffer->length; - yp_buffer_append_zeroes(buffer, 4); - - // Next, encode the length of the constant pool. - yp_buffer_append_u32(buffer, yp_sizet_to_u32(parser->constant_pool.size)); - - // Now we're going to serialize the content of the node. - yp_serialize_node(parser, node, buffer); - - // Now we're going to serialize the offset of the constant pool back where - // we left space for it. - uint32_t length = yp_sizet_to_u32(buffer->length); - memcpy(buffer->value + offset, &length, sizeof(uint32_t)); - - // Now we're going to serialize the constant pool. - offset = buffer->length; - yp_buffer_append_zeroes(buffer, parser->constant_pool.size * 8); - - yp_constant_t *constant; - for (size_t index = 0; index < parser->constant_pool.capacity; index++) { - constant = &parser->constant_pool.constants[index]; - - // If we find a constant at this index, serialize it at the correct - // index in the buffer. - if (constant->id != 0) { - size_t buffer_offset = offset + ((constant->id - 1) * 8); - - uint32_t source_offset = yp_ptrdifft_to_u32(constant->start - parser->start); - uint32_t constant_length = yp_sizet_to_u32(constant->length); - - memcpy(buffer->value + buffer_offset, &source_offset, 4); - memcpy(buffer->value + buffer_offset + 4, &constant_length, 4); - } - } -} - -static void -serialize_token(void *data, yp_parser_t *parser, yp_token_t *token) { - yp_buffer_t *buffer = (yp_buffer_t *) data; - - yp_buffer_append_u32(buffer, token->type); - yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(token->start - parser->start)); - yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(token->end - token->start)); - yp_buffer_append_u32(buffer, parser->lex_state); -} - -YP_EXPORTED_FUNCTION void -yp_lex_serialize(const char *source, size_t size, const char *filepath, yp_buffer_t *buffer) { - yp_parser_t parser; - yp_parser_init(&parser, source, size, filepath); - - yp_lex_callback_t lex_callback = (yp_lex_callback_t) { - .data = (void *) buffer, - .callback = serialize_token, - }; - - parser.lex_callback = &lex_callback; - yp_node_t *node = yp_parse(&parser); - - // Append 0 to mark end of tokens - yp_buffer_append_u32(buffer, 0); - - // Serialize the comments - yp_serialize_comment_list(&parser, parser.comment_list, buffer); - - // Serialize the errors - yp_serialize_diagnostic_list(&parser, parser.error_list, buffer); - - // Serialize the warnings - yp_serialize_diagnostic_list(&parser, parser.warning_list, buffer); - - yp_node_destroy(&parser, node); - yp_parser_free(&parser); -} diff --git a/yarp/templates/ext/yarp/api_node.c.erb b/yarp/templates/ext/yarp/api_node.c.erb new file mode 100644 index 00000000000000..599bf2e9ffb2b7 --- /dev/null +++ b/yarp/templates/ext/yarp/api_node.c.erb @@ -0,0 +1,204 @@ +#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" +#include "yarp/extension.h" + +extern VALUE rb_cYARP; +extern VALUE rb_cYARPNode; +extern VALUE rb_cYARPSource; +extern VALUE rb_cYARPToken; +extern VALUE rb_cYARPLocation; + +<%- nodes.each do |node| -%> +static VALUE rb_cYARP<%= node.name %>; +<%- end -%> + +static VALUE +yp_location_new(yp_parser_t *parser, const char *start, const char *end, VALUE source) { + VALUE argv[] = { source, LONG2FIX(start - parser->start), LONG2FIX(end - start) }; + return rb_class_new_instance(3, argv, rb_cYARPLocation); +} + +VALUE +yp_token_new(yp_parser_t *parser, yp_token_t *token, rb_encoding *encoding, VALUE source) { + ID type = rb_intern(yp_token_type_to_str(token->type)); + VALUE location = yp_location_new(parser, token->start, token->end, source); + + VALUE argv[] = { + ID2SYM(type), + rb_enc_str_new(token->start, token->end - token->start, encoding), + location + }; + + return rb_class_new_instance(3, argv, rb_cYARPToken); +} + +static VALUE +yp_string_new(yp_string_t *string, rb_encoding *encoding) { + return rb_enc_str_new(yp_string_source(string), yp_string_length(string), encoding); +} + +// Create a YARP::Source object from the given parser. +VALUE +yp_source_new(yp_parser_t *parser) { + VALUE source = rb_str_new(parser->start, parser->end - parser->start); + VALUE offsets = rb_ary_new_capa(parser->newline_list.size); + + for (size_t index = 0; index < parser->newline_list.size; index++) { + rb_ary_push(offsets, INT2FIX(parser->newline_list.offsets[index])); + } + + VALUE source_argv[] = { source, offsets }; + return rb_class_new_instance(2, source_argv, rb_cYARPSource); +} + +typedef struct yp_node_stack_node { + struct yp_node_stack_node *prev; + yp_node_t *visit; + bool visited; +} yp_node_stack_node_t; + +static void +yp_node_stack_push(yp_node_stack_node_t **stack, yp_node_t *visit) { + yp_node_stack_node_t *node = malloc(sizeof(yp_node_stack_node_t)); + node->prev = *stack; + node->visit = visit; + node->visited = false; + *stack = node; +} + +static yp_node_t * +yp_node_stack_pop(yp_node_stack_node_t **stack) { + yp_node_stack_node_t *current = *stack; + yp_node_t *visit = current->visit; + + *stack = current->prev; + free(current); + + return visit; +} + +VALUE +yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) { + VALUE source = yp_source_new(parser); + ID *constants = calloc(parser->constant_pool.size, sizeof(ID)); + + for (size_t index = 0; index < parser->constant_pool.capacity; index++) { + yp_constant_t constant = parser->constant_pool.constants[index]; + + if (constant.id != 0) { + constants[constant.id - 1] = rb_intern3(constant.start, constant.length, encoding); + } + } + + yp_node_stack_node_t *node_stack = NULL; + yp_node_stack_push(&node_stack, node); + VALUE value_stack = rb_ary_new(); + + while (node_stack != NULL) { + if (!node_stack->visited) { + if (node_stack->visit == NULL) { + yp_node_stack_pop(&node_stack); + rb_ary_push(value_stack, Qnil); + continue; + } + + yp_node_t *node = node_stack->visit; + node_stack->visited = true; + + switch (YP_NODE_TYPE(node)) { + <%- nodes.each do |node| -%> + <%- if node.params.any? { |param| [NodeParam, OptionalNodeParam, NodeListParam].include?(param.class) } -%> +#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" + case <%= node.type %>: { + yp_<%= node.human %>_t *cast = (yp_<%= node.human %>_t *) node; + <%- node.params.each do |param| -%> + <%- case param -%> + <%- when NodeParam, OptionalNodeParam -%> + yp_node_stack_push(&node_stack, (yp_node_t *) cast-><%= param.name %>); + <%- when NodeListParam -%> + for (size_t index = 0; index < cast-><%= param.name %>.size; index++) { + yp_node_stack_push(&node_stack, (yp_node_t *) cast-><%= param.name %>.nodes[index]); + } + <%- end -%> + <%- end -%> + break; + } + <%- end -%> + <%- end -%> + default: + break; + } +#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" + } else { + yp_node_t *node = yp_node_stack_pop(&node_stack); + + switch (YP_NODE_TYPE(node)) { + <%- nodes.each do |node| -%> +#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" + case <%= node.type %>: { + <%- if node.params.any? { |param| ![NodeParam, OptionalNodeParam].include?(param.class) } -%> + yp_<%= node.human %>_t *cast = (yp_<%= node.human %>_t *) node; + <%- end -%> + VALUE argv[<%= node.params.length + 1 %>]; + <%- node.params.each_with_index do |param, index| -%> + + // <%= param.name %> + <%- case param -%> + <%- when NodeParam, OptionalNodeParam -%> + argv[<%= index %>] = rb_ary_pop(value_stack); + <%- when NodeListParam -%> + argv[<%= index %>] = rb_ary_new_capa(cast-><%= param.name %>.size); + for (size_t index = 0; index < cast-><%= param.name %>.size; index++) { + rb_ary_push(argv[<%= index %>], rb_ary_pop(value_stack)); + } + <%- when StringParam -%> + argv[<%= index %>] = yp_string_new(&cast-><%= param.name %>, encoding); + <%- when LocationListParam -%> + argv[<%= index %>] = rb_ary_new_capa(cast-><%= param.name %>.size); + for (size_t index = 0; index < cast-><%= param.name %>.size; index++) { + yp_location_t location = cast-><%= param.name %>.locations[index]; + rb_ary_push(argv[<%= index %>], yp_location_new(parser, location.start, location.end, source)); + } + <%- when ConstantParam -%> + argv[<%= index %>] = rb_id2sym(constants[cast-><%= param.name %> - 1]); + <%- when ConstantListParam -%> + argv[<%= index %>] = rb_ary_new_capa(cast-><%= param.name %>.size); + for (size_t index = 0; index < cast-><%= param.name %>.size; index++) { + rb_ary_push(argv[<%= index %>], rb_id2sym(constants[cast-><%= param.name %>.ids[index] - 1])); + } + <%- when LocationParam -%> + argv[<%= index %>] = yp_location_new(parser, cast-><%= param.name %>.start, cast-><%= param.name %>.end, source); + <%- when OptionalLocationParam -%> + argv[<%= index %>] = cast-><%= param.name %>.start == NULL ? Qnil : yp_location_new(parser, cast-><%= param.name %>.start, cast-><%= param.name %>.end, source); + <%- when UInt32Param -%> + argv[<%= index %>] = ULONG2NUM(cast-><%= param.name %>); + <%- when FlagsParam -%> + argv[<%= index %>] = ULONG2NUM(node->flags >> <%= COMMON_FLAGS %>); + <%- else -%> + <%- raise -%> + <%- end -%> + <%- end -%> + + // location + argv[<%= node.params.length %>] = yp_location_new(parser, node->location.start, node->location.end, source); + + rb_ary_push(value_stack, rb_class_new_instance(<%= node.params.length + 1 %>, argv, rb_cYARP<%= node.name %>)); + break; + } + <%- end -%> + default: + rb_raise(rb_eRuntimeError, "unknown node type: %d", YP_NODE_TYPE(node)); + } + } + } + + VALUE result = rb_ary_pop(value_stack); + free(constants); + return result; +} + +void +Init_yarp_api_node(void) { + <%- nodes.each do |node| -%> + rb_cYARP<%= node.name %> = rb_define_class_under(rb_cYARP, "<%= node.name %>", rb_cYARPNode); + <%- end -%> +} diff --git a/yarp/templates/include/yarp/ast.h.erb b/yarp/templates/include/yarp/ast.h.erb new file mode 100644 index 00000000000000..5b69c0c8b16231 --- /dev/null +++ b/yarp/templates/include/yarp/ast.h.erb @@ -0,0 +1,111 @@ +#ifndef YARP_AST_H +#define YARP_AST_H + +#include "yarp/defines.h" +#include "yarp/util/yp_constant_pool.h" +#include "yarp/util/yp_string.h" + +#include +#include +#include + +// This enum represents every type of token in the Ruby source. +typedef enum yp_token_type { +<%- tokens.each do |token| -%> + <%= token.declaration %> +<%- end -%> + YP_TOKEN_MAXIMUM, // the maximum token value +} yp_token_type_t; + +// This struct represents a token in the Ruby source. We use it to track both +// type and location information. +typedef struct { + yp_token_type_t type; + const char *start; + const char *end; +} yp_token_t; + +// This represents a range of bytes in the source string to which a node or +// token corresponds. +typedef struct { + const char *start; + const char *end; +} yp_location_t; + +typedef struct { + yp_location_t *locations; + size_t size; + size_t capacity; +} yp_location_list_t; + +struct yp_node; + +typedef struct yp_node_list { + struct yp_node **nodes; + size_t size; + size_t capacity; +} yp_node_list_t; + +enum yp_node_type { +<%- nodes.each_with_index do |node, index| -%> + <%= node.type %> = <%= index + 1 %>, +<%- end -%> +}; + +typedef uint16_t yp_node_type_t; +typedef uint16_t yp_node_flags_t; + +// We store the flags enum in every node in the tree. Some flags are common to +// all nodes (the ones listed below). Others are specific to certain node types. +static const yp_node_flags_t YP_NODE_FLAG_NEWLINE = 0x1; + +// For easy access, we define some macros to check node type +#define YP_NODE_TYPE(node) ((enum yp_node_type)node->type) +#define YP_NODE_TYPE_P(node, type) (YP_NODE_TYPE(node) == (type)) + +// This is the overall tagged union representing a node in the syntax tree. +typedef struct yp_node { + // This represents the type of the node. It somewhat maps to the nodes that + // existed in the original grammar and ripper, but it's not a 1:1 mapping. + yp_node_type_t type; + + // This represents any flags on the node. Currently, this is only a newline + // flag + yp_node_flags_t flags; + + // This is the location of the node in the source. It's a range of bytes + // containing a start and an end. + yp_location_t location; +} yp_node_t; +<%- nodes.each do |node| -%> + +// <%= node.name %> +typedef struct yp_<%= node.human %> { + yp_node_t base; +<%- node.params.grep_v(FlagsParam).each do |param| -%> + <%= case param + when NodeParam, OptionalNodeParam then "struct #{param.c_type} *#{param.name}" + when NodeListParam then "struct yp_node_list #{param.name}" + when LocationListParam then "yp_location_list_t #{param.name}" + when ConstantParam then "yp_constant_id_t #{param.name}" + when ConstantListParam then "yp_constant_id_list_t #{param.name}" + when StringParam then "yp_string_t #{param.name}" + when LocationParam, OptionalLocationParam then "yp_location_t #{param.name}" + when UInt32Param then "uint32_t #{param.name}" + else raise param.class.name + end + %>; +<%- end -%> +} yp_<%= node.human %>_t; +<%- end -%> +<%- flags.each do |flag| -%> + +// <%= flag.name %> +typedef enum { + <%- flag.values.each.with_index(COMMON_FLAGS) do |value, index| -%> + YP_<%= flag.human.upcase %>_<%= value.name %> = 1 << <%= index %>, + <%- end -%> +} yp_<%= flag.human %>_t; +<%- end -%> + +#endif // YARP_AST_H diff --git a/yarp/templates/java/org/yarp/AbstractNodeVisitor.java.erb b/yarp/templates/java/org/yarp/AbstractNodeVisitor.java.erb new file mode 100644 index 00000000000000..fa9f65a84acbcb --- /dev/null +++ b/yarp/templates/java/org/yarp/AbstractNodeVisitor.java.erb @@ -0,0 +1,14 @@ +package org.yarp; + +// GENERATED BY <%= File.basename(__FILE__) %> +public abstract class AbstractNodeVisitor { + + protected abstract T defaultVisit(Nodes.Node node); + + <%- nodes.each do |node| -%> + public T visit<%= node.name -%>(Nodes.<%= node.name -%> node) { + return defaultVisit(node); + } + + <%- end -%> +} diff --git a/yarp/templates/java/org/yarp/Loader.java.erb b/yarp/templates/java/org/yarp/Loader.java.erb new file mode 100644 index 00000000000000..f78770508afeac --- /dev/null +++ b/yarp/templates/java/org/yarp/Loader.java.erb @@ -0,0 +1,282 @@ +package org.yarp; + +import org.yarp.ParseResult; + +import java.lang.Short; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.charset.StandardCharsets; + +// GENERATED BY <%= File.basename(__FILE__) %> +// @formatter:off +public class Loader { + + public static ParseResult load(byte[] serialized, Nodes.Source source) { + return new Loader(serialized, source).load(); + } + + private static final class ConstantPool { + + private final byte[] source; + private final int bufferOffset; + private final byte[][] cache; + + ConstantPool(byte[] source, int bufferOffset, int length) { + this.source = source; + this.bufferOffset = bufferOffset; + cache = new byte[length][]; + } + + byte[] get(ByteBuffer buffer, int oneBasedIndex) { + int index = oneBasedIndex - 1; + byte[] constant = cache[index]; + if (constant == null) { + int offset = bufferOffset + index * 8; + int start = buffer.getInt(offset); + int length = buffer.getInt(offset + 4); + + constant = new byte[length]; + System.arraycopy(source, start, constant, 0, length); + cache[index] = constant; + } + return constant; + } + + } + + private final ByteBuffer buffer; + private ConstantPool constantPool; + private final Nodes.Source source; + + private byte MAJOR_VERSION = (byte) 0; + private byte MINOR_VERSION = (byte) 7; + private byte PATCH_VERSION = (byte) 0; + + private Loader(byte[] serialized, Nodes.Source source) { + this.buffer = ByteBuffer.wrap(serialized).order(ByteOrder.nativeOrder()); + this.source = source; + } + + private ParseResult load() { + expect((byte) 'Y'); + expect((byte) 'A'); + expect((byte) 'R'); + expect((byte) 'P'); + + expect(MAJOR_VERSION); + expect(MINOR_VERSION); + expect(PATCH_VERSION); + + // This loads the name of the encoding. We don't actually do anything + // with it just yet. + int encodingLength = loadVarInt(); + byte[] encodingName = new byte[encodingLength]; + buffer.get(encodingName); + + ParseResult.Comment[] comments = loadComments(); + ParseResult.Error[] errors = loadSyntaxErrors(); + ParseResult.Warning[] warnings = loadWarnings(); + + int constantPoolBufferOffset = buffer.getInt(); + int constantPoolLength = loadVarInt(); + this.constantPool = new ConstantPool(source.bytes, constantPoolBufferOffset, constantPoolLength); + + Nodes.Node node = loadNode(); + + int left = constantPoolBufferOffset - buffer.position(); + if (left != 0) { + throw new Error("Expected to consume all bytes while deserializing but there were " + left + " bytes left"); + } + + boolean[] newlineMarked = new boolean[1 + source.getLineCount()]; + MarkNewlinesVisitor visitor = new MarkNewlinesVisitor(source, newlineMarked); + node.accept(visitor); + + return new ParseResult(node, comments, errors, warnings); + } + + private byte[] loadString() { + int length = loadVarInt(); + byte[] string = new byte[length]; + buffer.get(string); + return string; + } + + private ParseResult.Comment[] loadComments() { + int count = loadVarInt(); + ParseResult.Comment[] comments = new ParseResult.Comment[count]; + + for (int i = 0; i < count; i++) { + ParseResult.CommentType type = ParseResult.CommentType.VALUES[buffer.get()]; + Nodes.Location location = loadLocation(); + + ParseResult.Comment comment = new ParseResult.Comment(type, location); + comments[i] = comment; + } + + return comments; + } + + private ParseResult.Error[] loadSyntaxErrors() { + int count = loadVarInt(); + ParseResult.Error[] errors = new ParseResult.Error[count]; + + // error messages only contain ASCII characters + for (int i = 0; i < count; i++) { + byte[] bytes = loadString(); + String message = new String(bytes, StandardCharsets.US_ASCII); + Nodes.Location location = loadLocation(); + + ParseResult.Error error = new ParseResult.Error(message, location); + errors[i] = error; + } + + return errors; + } + + private ParseResult.Warning[] loadWarnings() { + int count = loadVarInt(); + ParseResult.Warning[] warnings = new ParseResult.Warning[count]; + + // warning messages only contain ASCII characters + for (int i = 0; i < count; i++) { + byte[] bytes = loadString(); + String message = new String(bytes, StandardCharsets.US_ASCII); + Nodes.Location location = loadLocation(); + + ParseResult.Warning warning = new ParseResult.Warning(message, location); + warnings[i] = warning; + } + + return warnings; + } + + private Nodes.Node loadOptionalNode() { + if (buffer.get(buffer.position()) != 0) { + return loadNode(); + } else { + buffer.position(buffer.position() + 1); // continue after the 0 byte + return null; + } + } + + private Nodes.Location[] loadLocations() { + int length = loadVarInt(); + if (length == 0) { + return Nodes.Location.EMPTY_ARRAY; + } + Nodes.Location[] locations = new Nodes.Location[length]; + for (int i = 0; i < length; i++) { + locations[i] = loadLocation(); + } + return locations; + } + + private byte[] loadConstant() { + return constantPool.get(buffer, loadVarInt()); + } + + private byte[][] loadConstants() { + int length = loadVarInt(); + if (length == 0) { + return Nodes.EMPTY_BYTE_ARRAY_ARRAY; + } + byte[][] constants = new byte[length][]; + for (int i = 0; i < length; i++) { + constants[i] = constantPool.get(buffer, loadVarInt()); + } + return constants; + } + + private Nodes.Node[] loadNodes() { + int length = loadVarInt(); + if (length == 0) { + return Nodes.Node.EMPTY_ARRAY; + } + Nodes.Node[] nodes = new Nodes.Node[length]; + for (int i = 0; i < length; i++) { + nodes[i] = loadNode(); + } + return nodes; + } + + private Nodes.Location loadLocation() { + return new Nodes.Location(loadVarInt(), loadVarInt()); + } + + private Nodes.Location loadOptionalLocation() { + if (buffer.get() != 0) { + return loadLocation(); + } else { + return null; + } + } + + // From https://github.com/protocolbuffers/protobuf/blob/v23.1/java/core/src/main/java/com/google/protobuf/BinaryReader.java#L1507 + private int loadVarInt() { + int x; + if ((x = buffer.get()) >= 0) { + return x; + } else if ((x ^= (buffer.get() << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (buffer.get() << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (buffer.get() << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + x ^= buffer.get() << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + } + return x; + } + + private short loadFlags() { + int flags = loadVarInt(); + assert flags >= 0 && flags <= Short.MAX_VALUE; + return (short) flags; + } + + private Nodes.Node loadNode() { + int type = buffer.get() & 0xFF; + int startOffset = loadVarInt(); + int length = loadVarInt(); + + switch (type) { + <%- nodes.each_with_index do |node, index| -%> + case <%= index + 1 %>: + <%- + params = node.needs_serialized_length? ? ["buffer.getInt()"] : [] + params.concat node.params.map { |param| + case param + when NodeParam then "#{param.java_cast}loadNode()" + when OptionalNodeParam then "#{param.java_cast}loadOptionalNode()" + when StringParam then "loadString()" + when NodeListParam then "loadNodes()" + when LocationListParam then "loadLocations()" + when ConstantParam then "loadConstant()" + when ConstantListParam then "loadConstants()" + when LocationParam then "loadLocation()" + when OptionalLocationParam then "loadOptionalLocation()" + when UInt32Param then "loadVarInt()" + when FlagsParam then "loadFlags()" + else raise + end + } + params.concat ["startOffset", "length"] + -%> + return new Nodes.<%= node.name %>(<%= params.join(", ") -%>); + <%- end -%> + default: + throw new Error("Unknown node type: " + type); + } + } + + private void expect(byte value) { + byte b = buffer.get(); + if (b != value) { + throw new Error("Expected " + value + " but was " + b + " at position " + buffer.position()); + } + } + +} +// @formatter:on diff --git a/yarp/templates/java/org/yarp/Nodes.java.erb b/yarp/templates/java/org/yarp/Nodes.java.erb new file mode 100644 index 00000000000000..aa16f4729d3c1e --- /dev/null +++ b/yarp/templates/java/org/yarp/Nodes.java.erb @@ -0,0 +1,291 @@ +package org.yarp; + +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.util.ArrayList; +import java.util.Arrays; + +// GENERATED BY <%= File.basename(__FILE__) %> +// @formatter:off +public abstract class Nodes { + + public static final byte[][] EMPTY_BYTE_ARRAY_ARRAY = {}; + + public static final class Location { + + public static final Location[] EMPTY_ARRAY = {}; + + public final int startOffset; + public final int length; + + public Location(int startOffset, int length) { + this.startOffset = startOffset; + this.length = length; + } + + public int endOffset() { + return startOffset + length; + } + } + + public static final class Source { + public final byte[] bytes; + private final int[] lineOffsets; + + public Source(byte[] bytes) { + this(bytes, computeLineOffsets(bytes)); + } + + public Source(byte[] bytes, int[] lineOffsets) { + assert lineOffsets[0] == 0; + this.bytes = bytes; + this.lineOffsets = lineOffsets; + } + + public static int[] computeLineOffsets(byte[] bytes) { + int[] lineOffsets = new int[8]; + int lineOffsetsSize = 0; + lineOffsets[lineOffsetsSize++] = 0; + + for (int i = 0; i < bytes.length; i++) { + if (bytes[i] == '\n') { + if (lineOffsetsSize == lineOffsets.length) { + lineOffsets = Arrays.copyOf(lineOffsets, lineOffsets.length * 2); + } + lineOffsets[lineOffsetsSize++] = i + 1; + } + } + return Arrays.copyOf(lineOffsets, lineOffsetsSize); + } + + public int line(int byteOffset) { + assert byteOffset >= 0 && byteOffset < bytes.length : byteOffset; + int index = Arrays.binarySearch(lineOffsets, byteOffset); + int line; + if (index < 0) { + line = -index - 1; + } else { + line = index + 1; + } + assert line >= 1 && line <= getLineCount() : line; + return line; + } + + public int getLineCount() { + return lineOffsets.length; + } + } + + public static abstract class Node { + + public static final Node[] EMPTY_ARRAY = {}; + + public final int startOffset; + public final int length; + private boolean newLineFlag = false; + + public Node(int startOffset, int length) { + this.startOffset = startOffset; + this.length = length; + } + + public final int endOffset() { + return startOffset + length; + } + + public final boolean hasNewLineFlag() { + return newLineFlag; + } + + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + int line = source.line(this.startOffset); + if (!newlineMarked[line]) { + newlineMarked[line] = true; + this.newLineFlag = true; + } + } + + public abstract T accept(AbstractNodeVisitor visitor); + + public abstract void visitChildNodes(AbstractNodeVisitor visitor); + + public abstract Node[] childNodes(); + + @Override + public String toString() { + return toString(""); + } + + private String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(indent).append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + for (Node child : childNodes()) { + if (child != null) { + builder.append(child.toString(indent + " ")); + } + } + return builder.toString(); + } + } +<%# FLAGS -%> + <%- flags.each do |group| -%> + + public static final class <%= group.name %> implements Comparable<<%= group.name %>> { + <%- group.values.each_with_index do |value, index| -%> + + // <%= value.comment %> + public static final short <%= value.name %> = 1 << <%= index %>; + <%- end -%> + + <%- group.values.each do |value| -%> + public static boolean is<%= value.camelcase %>(short flags) { + return (flags & <%= value.name %>) != 0; + } + + <%- end -%> + private final short flags; + + public <%= group.name %>(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof <%= group.name %>)) { + return false; + } + + return flags == ((<%= group.name %>) other).flags; + } + + @Override + public int compareTo(<%= group.name %> other) { + return flags - other.flags; + } + + <%- group.values.each do |value| -%> + public boolean is<%= value.camelcase %>() { + return (flags & <%= value.name %>) != 0; + } + + <%- end -%> + } +<%- end -%> +<%# NODES -%> + <%- nodes.each do |node| -%> + + <%= "#{node.comment.split("\n").map { |line| "// #{line}" }.join("\n ")}\n" if node.comment -%> + public static final class <%= node.name -%> extends Node { + <%- if node.needs_serialized_length? -%> + public final int serializedLength; + <%- end -%> + <%- node.params.each do |param| -%> + public final <%= param.java_type %> <%= param.name %>;<%= ' // optional' if param.class.name.start_with?('Optional') %> + <%- end -%> + + <%- + params = node.needs_serialized_length? ? ["int serializedLength"] : [] + params.concat node.params.map { "#{_1.java_type} #{_1.name}" } + params.concat ["int startOffset", "int length"] + -%> + public <%=node.name -%>(<%= params.join(", ") %>) { + super(startOffset, length); + <%- if node.needs_serialized_length? -%> + this.serializedLength = serializedLength; + <%- end -%> + <%- node.params.each do |param| -%> + this.<%= param.name %> = <%= param.name %>; + <%- end -%> + } + <%# methods for flags -%> + <%- node.params.each do |param| -%> + <%- if param.is_a?(FlagsParam) -%> + <%- flags.find { |flag| flag.name == param.kind }.tap { raise "Expected to find #{param.kind}" unless _1 }.values.each do |value| -%> + + public boolean is<%= value.camelcase %>() { + return <%= param.kind %>.is<%= value.camelcase %>(this.<%= param.name %>); + } + <%- end -%> + <%- end -%> + <%- end -%> + <%# potential override of setNewLineFlag() -%> + <%- if node.newline == false -%> + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + // Never mark <%= node.name %> with a newline flag, mark children instead + } + <%- elsif node.newline.is_a?(String) -%> + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + <%- param = node.params.find { |p| p.name == node.newline } or raise node.newline -%> + <%- case param -%> + <%- when SingleNodeParam -%> + this.<%= param.name %>.setNewLineFlag(source, newlineMarked); + <%- when NodeListParam -%> + Node first = this.<%= param.name %>.length > 0 ? this.<%= param.name %>[0] : null; + if (first != null) { + first.setNewLineFlag(source, newlineMarked); + } + <%- else raise param.class.name -%> + <%- end -%> + } + <%- end -%> + + public void visitChildNodes(AbstractNodeVisitor visitor) { + <%- node.params.each do |param| -%> + <%- case param -%> + <%- when NodeListParam -%> + for (Nodes.Node child : this.<%= param.name %>) { + child.accept(visitor); + } + <%- when NodeParam -%> + this.<%= param.name %>.accept(visitor); + <%- when OptionalNodeParam -%> + if (this.<%= param.name %> != null) { + this.<%= param.name %>.accept(visitor); + } + <%- end -%> + <%- end -%> + } + + public Node[] childNodes() { + <%- if node.params.none?(NodeListParam) and node.params.none?(SingleNodeParam) -%> + return EMPTY_ARRAY; + <%- elsif node.params.one?(NodeListParam) and node.params.none?(SingleNodeParam) -%> + return this.<%= node.params.grep(NodeListParam).first.name %>; + <%- elsif node.params.none?(NodeListParam) -%> + return new Node[] { <%= node.params.grep(SingleNodeParam).map { "this.#{_1.name}" }.join(', ') %> }; + <%- else -%> + ArrayList childNodes = new ArrayList<>(); + <%- node.params.each do |param| -%> + <%- case param -%> + <%- when SingleNodeParam -%> + childNodes.add(this.<%= param.name %>); + <%- when NodeListParam -%> + childNodes.addAll(Arrays.asList(this.<%= param.name %>)); + <%- end -%> + <%- end -%> + return childNodes.toArray(EMPTY_ARRAY); + <%- end -%> + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visit<%= node.name -%>(this); + } + } + <%- end -%> + +} +// @formatter:on diff --git a/yarp/templates/lib/yarp/node.rb.erb b/yarp/templates/lib/yarp/node.rb.erb new file mode 100644 index 00000000000000..c1f14f537af9ec --- /dev/null +++ b/yarp/templates/lib/yarp/node.rb.erb @@ -0,0 +1,122 @@ +module YARP + <%- nodes.each do |node| -%> + <%= "#{node.comment.split("\n").map { |line| line.empty? ? "#" : "# #{line}" }.join("\n ")}\n " if node.comment %>class <%= node.name -%> < Node + <%- node.params.each do |param| -%> + # attr_reader <%= param.name %>: <%= param.rbs_class %> + attr_reader :<%= param.name %> + + <%- end -%> + # def initialize: (<%= (node.params.map { |param| "#{param.name}: #{param.rbs_class}" } + ["location: Location"]).join(", ") %>) -> void + def initialize(<%= (node.params.map(&:name) + ["location"]).join(", ") %>) + <%- node.params.each do |param| -%> + @<%= param.name %> = <%= param.name %> + <%- end -%> + @location = location + end + + # def accept: (visitor: Visitor) -> void + def accept(visitor) + visitor.visit_<%= node.human %>(self) + end + <%- if node.newline == false -%> + + def set_newline_flag(newline_marked) + # Never mark <%= node.name %> with a newline flag, mark children instead + end + <%- elsif node.newline.is_a?(String) -%> + + def set_newline_flag(newline_marked) + <%- param = node.params.find { |p| p.name == node.newline } or raise node.newline -%> + <%- case param -%> + <%- when SingleNodeParam -%> + <%= param.name %>.set_newline_flag(newline_marked) + <%- when NodeListParam -%> + first = <%= param.name %>.first + first.set_newline_flag(newline_marked) if first + <%- else raise param.class.name -%> + <%- end -%> + end + <%- end -%> + + # def child_nodes: () -> Array[nil | Node] + def child_nodes + [<%= node.params.map { |param| + case param + when SingleNodeParam then param.name + when NodeListParam then "*#{param.name}" + end + }.compact.join(", ") %>] + end + + # def deconstruct: () -> Array[nil | Node] + alias deconstruct child_nodes + + # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] + def deconstruct_keys(keys) + { <%= (node.params.map { |param| "#{param.name}: #{param.name}" } + ["location: location"]).join(", ") %> } + end + <%- node.params.each do |param| -%> + <%- case param -%> + <%- when LocationParam -%> + <%- raise unless param.name.end_with?("_loc") -%> + <%- next if node.params.any? { |other| other.name == param.name.delete_suffix("_loc") } -%> + + # def <%= param.name.delete_suffix("_loc") %>: () -> String + def <%= param.name.delete_suffix("_loc") %> + <%= param.name %>.slice + end + <%- when OptionalLocationParam -%> + <%- raise unless param.name.end_with?("_loc") -%> + <%- next if node.params.any? { |other| other.name == param.name.delete_suffix("_loc") } -%> + + # def <%= param.name.delete_suffix("_loc") %>: () -> String? + def <%= param.name.delete_suffix("_loc") %> + <%= param.name %>&.slice + end + <%- when FlagsParam -%> + <%- flags.find { |flag| flag.name == param.kind }.tap { |flag| raise "Expected to find #{param.kind}" unless flag }.values.each do |value| -%> + + # def <%= value.name.downcase %>?: () -> bool + def <%= value.name.downcase %>? + <%= param.name %>.anybits?(<%= param.kind %>::<%= value.name %>) + end + <%- end -%> + <%- end -%> + <%- end -%> + end + + <%- end -%> + <%- flags.each do |flag| -%> + module <%= flag.name %> + <%- flag.values.each_with_index do |value, index| -%> + # <%= value.comment %> + <%= value.name %> = 1 << <%= index %> +<%= "\n" if value != flag.values.last -%> + <%- end -%> + end + + <%- end -%> + class Visitor < BasicVisitor + <%- nodes.each do |node| -%> + # Visit a <%= node.name %> node + alias visit_<%= node.human %> visit_child_nodes +<%= "\n" if node != nodes.last -%> + <%- end -%> + end + + module DSL + private + + # Create a new Location object + def Location(source = nil, start_offset = 0, length = 0) + Location.new(source, start_offset, length) + end + <%- nodes.each do |node| -%> + + # Create a new <%= node.name %> node + def <%= node.name %>(<%= (node.params.map(&:name) + ["location = Location()"]).join(", ") %>) + <%= node.name %>.new(<%= (node.params.map(&:name) + ["location"]).join(", ") %>) + end + <%- end -%> + end +end diff --git a/yarp/templates/lib/yarp/serialize.rb.erb b/yarp/templates/lib/yarp/serialize.rb.erb new file mode 100644 index 00000000000000..4194025c32b977 --- /dev/null +++ b/yarp/templates/lib/yarp/serialize.rb.erb @@ -0,0 +1,179 @@ +require "stringio" + +# Polyfill for String#unpack1 with the offset parameter. +if String.instance_method(:unpack1).parameters.none? { |_, name| name == :offset } + String.prepend( + Module.new { + def unpack1(format, offset: 0) + offset == 0 ? super(format) : self[offset..].unpack1(format) + end + } + ) +end + +module YARP + module Serialize + MAJOR_VERSION = 0 + MINOR_VERSION = 7 + PATCH_VERSION = 0 + + def self.load(input, serialized) + Loader.new(Source.new(input), serialized).load + end + + def self.load_tokens(source, serialized) + Loader.new(source, serialized).load_tokens + end + + class Loader + attr_reader :encoding, :input, :serialized, :io + attr_reader :constant_pool_offset, :constant_pool, :source + + def initialize(source, serialized) + @encoding = Encoding::UTF_8 + + @input = source.source.dup + @serialized = serialized + @io = StringIO.new(serialized) + @io.set_encoding(Encoding::BINARY) + + @constant_pool_offset = nil + @constant_pool = nil + + @source = source + end + + def load_tokens + tokens = [] + while type = TOKEN_TYPES.fetch(load_varint) + start = load_varint + length = load_varint + lex_state = load_varint + location = Location.new(@source, start, length) + tokens << [YARP::Token.new(type, location.slice, location), lex_state] + end + + comments = load_varint.times.map { Comment.new(Comment::TYPES.fetch(load_varint), load_location) } + errors = load_varint.times.map { ParseError.new(load_string, load_location) } + warnings = load_varint.times.map { ParseWarning.new(load_string, load_location) } + + raise "Expected to consume all bytes while deserializing" unless @io.eof? + + YARP::ParseResult.new(tokens, comments, errors, warnings, @source) + end + + def load + raise "Invalid serialization" if io.read(4) != "YARP" + raise "Invalid serialization" if io.read(3).unpack("C3") != [MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION] + + @encoding = Encoding.find(io.read(load_varint)) + @input = input.force_encoding(@encoding).freeze + + comments = load_varint.times.map { Comment.new(Comment::TYPES.fetch(io.getbyte), load_location) } + errors = load_varint.times.map { ParseError.new(load_string, load_location) } + warnings = load_varint.times.map { ParseWarning.new(load_string, load_location) } + + @constant_pool_offset = io.read(4).unpack1("L") + @constant_pool = Array.new(load_varint, nil) + + ast = load_node + + YARP::ParseResult.new(ast, comments, errors, warnings, @source) + end + + private + + # variable-length integer using https://en.wikipedia.org/wiki/LEB128 + # This is also what protobuf uses: https://protobuf.dev/programming-guides/encoding/#varints + def load_varint + n = io.getbyte + if n < 128 + n + else + n -= 128 + shift = 0 + while (b = io.getbyte) >= 128 + n += (b - 128) << (shift += 7) + end + n + (b << (shift + 7)) + end + end + + def load_serialized_length + io.read(4).unpack1("L") + end + + def load_optional_node + if io.getbyte != 0 + io.pos -= 1 + load_node + end + end + + def load_string + io.read(load_varint).force_encoding(encoding) + end + + def load_location + Location.new(source, load_varint, load_varint) + end + + def load_optional_location + load_location if io.getbyte != 0 + end + + def load_constant + index = load_varint - 1 + constant = constant_pool[index] + + unless constant + offset = constant_pool_offset + index * 8 + + start = serialized.unpack1("L", offset: offset) + length = serialized.unpack1("L", offset: offset + 4) + + constant = input.byteslice(start, length).to_sym + constant_pool[index] = constant + end + + constant + end + + def load_node + type = io.getbyte + location = load_location + + case type + <%- nodes.each_with_index do |node, index| -%> + when <%= index + 1 %> then + <%- if node.needs_serialized_length? -%> + load_serialized_length + <%- end -%> + <%= node.name %>.new(<%= (node.params.map { |param| + case param + when NodeParam then "load_node" + when OptionalNodeParam then "load_optional_node" + when StringParam then "load_string" + when NodeListParam then "Array.new(load_varint) { load_node }" + when LocationListParam then "Array.new(load_varint) { load_location }" + when ConstantParam then "load_constant" + when ConstantListParam then "Array.new(load_varint) { load_constant }" + when LocationParam then "load_location" + when OptionalLocationParam then "load_optional_location" + when UInt32Param, FlagsParam then "load_varint" + else raise + end + } + ["location"]).join(", ") -%>) + <%- end -%> + end + end + end + + TOKEN_TYPES = [ + nil, + <%- tokens.each do |token| -%> + <%= token.name.to_sym.inspect %>, + <%- end -%> + ] + end +end diff --git a/yarp/templates/src/node.c.erb b/yarp/templates/src/node.c.erb new file mode 100644 index 00000000000000..371655fdb5fc57 --- /dev/null +++ b/yarp/templates/src/node.c.erb @@ -0,0 +1,168 @@ +#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" +#include "yarp/node.h" + +// Clear the node but preserves the location. +void yp_node_clear(yp_node_t *node) { + yp_location_t location = node->location; + memset(node, 0, sizeof(yp_node_t)); + node->location = location; +} + +// Calculate the size of the token list in bytes. +static size_t +yp_location_list_memsize(yp_location_list_t *list) { + return sizeof(yp_location_list_t) + (list->capacity * sizeof(yp_location_t)); +} + +// Append a token to the given list. +void +yp_location_list_append(yp_location_list_t *list, const yp_token_t *token) { + if (list->size == list->capacity) { + list->capacity = list->capacity == 0 ? 2 : list->capacity * 2; + list->locations = (yp_location_t *) realloc(list->locations, sizeof(yp_location_t) * list->capacity); + } + list->locations[list->size++] = (yp_location_t) { .start = token->start, .end = token->end }; +} + +// Free the memory associated with the token list. +static void +yp_location_list_free(yp_location_list_t *list) { + if (list->locations != NULL) { + free(list->locations); + } +} + +static void +yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize); + +// Calculate the size of the node list in bytes. +static size_t +yp_node_list_memsize(yp_node_list_t *node_list, yp_memsize_t *memsize) { + size_t size = sizeof(yp_node_list_t) + (node_list->capacity * sizeof(yp_node_t *)); + for (size_t index = 0; index < node_list->size; index++) { + yp_node_memsize_node(node_list->nodes[index], memsize); + } + return size; +} + +// Append a new node onto the end of the node list. +void +yp_node_list_append(yp_node_list_t *list, yp_node_t *node) { + if (list->size == list->capacity) { + list->capacity = list->capacity == 0 ? 4 : list->capacity * 2; + list->nodes = (yp_node_t **) realloc(list->nodes, sizeof(yp_node_t *) * list->capacity); + } + list->nodes[list->size++] = node; +} + +YP_EXPORTED_FUNCTION void +yp_node_destroy(yp_parser_t *parser, yp_node_t *node); + +// Deallocate the inner memory of a list of nodes. The parser argument is not +// used, but is here for the future possibility of pre-allocating memory pools. +static void +yp_node_list_free(yp_parser_t *parser, yp_node_list_t *list) { + if (list->capacity > 0) { + for (size_t index = 0; index < list->size; index++) { + yp_node_destroy(parser, list->nodes[index]); + } + free(list->nodes); + } +} + +// Deallocate the space for a yp_node_t. Similarly to yp_node_alloc, we're not +// using the parser argument, but it's there to allow for the future possibility +// of pre-allocating larger memory pools. +YP_EXPORTED_FUNCTION void +yp_node_destroy(yp_parser_t *parser, yp_node_t *node) { + switch (YP_NODE_TYPE(node)) { + <%- nodes.each do |node| -%> +#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" + case <%= node.type %>: + <%- node.params.each do |param| -%> + <%- case param -%> + <%- when LocationParam, OptionalLocationParam, UInt32Param, FlagsParam, ConstantParam -%> + <%- when NodeParam -%> + yp_node_destroy(parser, (yp_node_t *)((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- when OptionalNodeParam -%> + if (((yp_<%= node.human %>_t *)node)-><%= param.name %> != NULL) { + yp_node_destroy(parser, (yp_node_t *)((yp_<%= node.human %>_t *)node)-><%= param.name %>); + } + <%- when StringParam -%> + yp_string_free(&((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- when NodeListParam -%> + yp_node_list_free(parser, &((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- when LocationListParam -%> + yp_location_list_free(&((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- when ConstantListParam -%> + yp_constant_id_list_free(&((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- else -%> + <%- raise -%> + <%- end -%> + <%- end -%> + break; + <%- end -%> +#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" + default: + assert(false && "unreachable"); + break; + } + free(node); +} + +static void +yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize) { + memsize->node_count++; + + switch (YP_NODE_TYPE(node)) { + <%- nodes.each do |node| -%> +#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" + case <%= node.type %>: { + memsize->memsize += sizeof(yp_<%= node.human %>_t); + <%- node.params.each do |param| -%> + <%- case param -%> + <%- when ConstantParam, UInt32Param, FlagsParam, LocationParam, OptionalLocationParam -%> + <%- when NodeParam -%> + yp_node_memsize_node((yp_node_t *)((yp_<%= node.human %>_t *)node)-><%= param.name %>, memsize); + <%- when OptionalNodeParam -%> + if (((yp_<%= node.human %>_t *)node)-><%= param.name %> != NULL) { + yp_node_memsize_node((yp_node_t *)((yp_<%= node.human %>_t *)node)-><%= param.name %>, memsize); + } + <%- when StringParam -%> + memsize->memsize += yp_string_memsize(&((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- when NodeListParam -%> + yp_node_list_memsize(&((yp_<%= node.human %>_t *)node)-><%= param.name %>, memsize); + <%- when LocationListParam -%> + memsize->memsize += yp_location_list_memsize(&((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- when ConstantListParam -%> + memsize->memsize += yp_constant_id_list_memsize(&((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- else -%> + <%- raise -%> + <%- end -%> + <%- end -%> + break; + } + <%- end -%> +#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" + } +} + +// Calculates the memory footprint of a given node. +YP_EXPORTED_FUNCTION void +yp_node_memsize(yp_node_t *node, yp_memsize_t *memsize) { + *memsize = (yp_memsize_t) { .memsize = 0, .node_count = 0 }; + yp_node_memsize_node(node, memsize); +} + +// Returns a string representation of the given node type. +YP_EXPORTED_FUNCTION const char * +yp_node_type_to_str(yp_node_type_t node_type) +{ + switch (node_type) { +<%- nodes.each do |node| -%> + case <%= node.type %>: + return "<%= node.type %>"; +<%- end -%> + } + return "\0"; +} diff --git a/yarp/templates/src/prettyprint.c.erb b/yarp/templates/src/prettyprint.c.erb new file mode 100644 index 00000000000000..29d0194dca2bfd --- /dev/null +++ b/yarp/templates/src/prettyprint.c.erb @@ -0,0 +1,106 @@ +#include "yarp/defines.h" + +#include + +#include "yarp/ast.h" +#include "yarp/parser.h" +#include "yarp/util/yp_buffer.h" + +static void +prettyprint_location(yp_buffer_t *buffer, yp_parser_t *parser, yp_location_t *location) { + char printed[] = "[0000-0000]"; + snprintf(printed, sizeof(printed), "[%04ld-%04ld]", (long int)(location->start - parser->start), (long int)(location->end - parser->start)); + yp_buffer_append_str(buffer, printed, strlen(printed)); +} + +static void +prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) { + switch (YP_NODE_TYPE(node)) { + <%- nodes.each do |node| -%> + case <%= node.type %>: { + yp_buffer_append_str(buffer, "<%= node.name %>(", <%= node.name.length + 1 %>); + <%- node.params.each_with_index do |param, index| -%> + <%= "yp_buffer_append_str(buffer, \", \", 2);" if index != 0 -%> + <%- case param -%> + <%- when NodeParam -%> + prettyprint_node(buffer, parser, (yp_node_t *)((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- when OptionalNodeParam -%> + if (((yp_<%= node.human %>_t *)node)-><%= param.name %> == NULL) { + yp_buffer_append_str(buffer, "nil", 3); + } else { + prettyprint_node(buffer, parser, (yp_node_t *)((yp_<%= node.human %>_t *)node)-><%= param.name %>); + } + <%- when StringParam -%> + yp_buffer_append_str(buffer, "\"", 1); + yp_buffer_append_str(buffer, yp_string_source(&((yp_<%= node.human %>_t *)node)-><%= param.name %>), yp_string_length(&((yp_<%= node.human %>_t *)node)-><%= param.name %>)); + yp_buffer_append_str(buffer, "\"", 1); + <%- when NodeListParam -%> + yp_buffer_append_str(buffer, "[", 1); + for (uint32_t index = 0; index < ((yp_<%= node.human %>_t *)node)-><%= param.name %>.size; index++) { + if (index != 0) yp_buffer_append_str(buffer, ", ", 2); + prettyprint_node(buffer, parser, (yp_node_t *) ((yp_<%= node.human %>_t *) node)-><%= param.name %>.nodes[index]); + } + yp_buffer_append_str(buffer, "]", 1); + <%- when LocationListParam -%> + yp_buffer_append_str(buffer, "[", 1); + for (uint32_t index = 0; index < ((yp_<%= node.human %>_t *)node)-><%= param.name %>.size; index++) { + if (index != 0) yp_buffer_append_str(buffer, ", ", 2); + prettyprint_location(buffer, parser, &((yp_<%= node.human %>_t *)node)-><%= param.name %>.locations[index]); + } + yp_buffer_append_str(buffer, "]", 1); + <%- when ConstantParam -%> + char <%= param.name %>_buffer[12]; + snprintf(<%= param.name %>_buffer, sizeof(<%= param.name %>_buffer), "%u", ((yp_<%= node.human %>_t *)node)-><%= param.name %>); + yp_buffer_append_str(buffer, <%= param.name %>_buffer, strlen(<%= param.name %>_buffer)); + <%- when ConstantListParam -%> + yp_buffer_append_str(buffer, "[", 1); + for (uint32_t index = 0; index < ((yp_<%= node.human %>_t *)node)-><%= param.name %>.size; index++) { + if (index != 0) yp_buffer_append_str(buffer, ", ", 2); + char <%= param.name %>_buffer[12]; + snprintf(<%= param.name %>_buffer, sizeof(<%= param.name %>_buffer), "%u", ((yp_<%= node.human %>_t *)node)-><%= param.name %>.ids[index]); + yp_buffer_append_str(buffer, <%= param.name %>_buffer, strlen(<%= param.name %>_buffer)); + } + yp_buffer_append_str(buffer, "]", 1); + <%- when LocationParam -%> + prettyprint_location(buffer, parser, &((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- when OptionalLocationParam -%> + if (((yp_<%= node.human %>_t *)node)-><%= param.name %>.start == NULL) { + yp_buffer_append_str(buffer, "nil", 3); + } else { + prettyprint_location(buffer, parser, &((yp_<%= node.human %>_t *)node)-><%= param.name %>); + } + <%- when UInt32Param -%> + char <%= param.name %>_buffer[12]; + snprintf(<%= param.name %>_buffer, sizeof(<%= param.name %>_buffer), "+%d", ((yp_<%= node.human %>_t *)node)-><%= param.name %>); + yp_buffer_append_str(buffer, <%= param.name %>_buffer, strlen(<%= param.name %>_buffer)); + <%- when FlagsParam -%> + char <%= param.name %>_buffer[12]; + snprintf(<%= param.name %>_buffer, sizeof(<%= param.name %>_buffer), "+%d", node->flags >> <%= COMMON_FLAGS %>); + yp_buffer_append_str(buffer, <%= param.name %>_buffer, strlen(<%= param.name %>_buffer)); + <%- else -%> + <%- raise -%> + <%- end -%> + <%- end -%> + yp_buffer_append_str(buffer, ")", 1); + break; + } + <%- end -%> + } +} + +void +yp_print_node(yp_parser_t *parser, yp_node_t *node) { + yp_buffer_t buffer; + if (!yp_buffer_init(&buffer)) return; + + prettyprint_node(&buffer, parser, node); + printf("%.*s\n", (int) buffer.length, buffer.value); + + yp_buffer_free(&buffer); +} + +// Pretty-prints the AST represented by the given node to the given buffer. +YP_EXPORTED_FUNCTION void +yp_prettyprint(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) { + prettyprint_node(buffer, parser, node); +} diff --git a/yarp/templates/src/serialize.c.erb b/yarp/templates/src/serialize.c.erb new file mode 100644 index 00000000000000..63a43f282a687b --- /dev/null +++ b/yarp/templates/src/serialize.c.erb @@ -0,0 +1,236 @@ +#include "yarp.h" + +#include + +static inline uint32_t +yp_ptrdifft_to_u32(ptrdiff_t value) { + assert(value >= 0 && ((unsigned long) value) < UINT32_MAX); + return (uint32_t) value; +} + +static inline uint32_t +yp_sizet_to_u32(size_t value) { + assert(value < UINT32_MAX); + return (uint32_t) value; +} + +static void +serialize_location(yp_parser_t *parser, yp_location_t *location, yp_buffer_t *buffer) { + assert(location->start); + assert(location->end); + assert(location->start <= location->end); + + yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(location->start - parser->start)); + yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(location->end - location->start)); +} + +void +yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) { + yp_buffer_append_u8(buffer, (uint8_t) YP_NODE_TYPE(node)); + + size_t offset = buffer->length; + + serialize_location(parser, &node->location, buffer); + + switch (YP_NODE_TYPE(node)) { + <%- nodes.each do |node| -%> + case <%= node.type %>: { + <%- if node.needs_serialized_length? -%> + // serialize length + // encoding of location u32s make us need to save this offset. + size_t length_offset = buffer->length; + yp_buffer_append_str(buffer, "\0\0\0\0", 4); /* consume 4 bytes, updated below */ + <%- end -%> + <%- node.params.each do |param| -%> + <%- case param -%> + <%- when NodeParam -%> + yp_serialize_node(parser, (yp_node_t *)((yp_<%= node.human %>_t *)node)-><%= param.name %>, buffer); + <%- when OptionalNodeParam -%> + if (((yp_<%= node.human %>_t *)node)-><%= param.name %> == NULL) { + yp_buffer_append_u8(buffer, 0); + } else { + yp_serialize_node(parser, (yp_node_t *)((yp_<%= node.human %>_t *)node)-><%= param.name %>, buffer); + } + <%- when StringParam -%> + uint32_t <%= param.name %>_length = yp_sizet_to_u32(yp_string_length(&((yp_<%= node.human %>_t *)node)-><%= param.name %>)); + yp_buffer_append_u32(buffer, <%= param.name %>_length); + yp_buffer_append_str(buffer, yp_string_source(&((yp_<%= node.human %>_t *)node)-><%= param.name %>), <%= param.name %>_length); + <%- when NodeListParam -%> + uint32_t <%= param.name %>_size = yp_sizet_to_u32(((yp_<%= node.human %>_t *)node)-><%= param.name %>.size); + yp_buffer_append_u32(buffer, <%= param.name %>_size); + for (uint32_t index = 0; index < <%= param.name %>_size; index++) { + yp_serialize_node(parser, (yp_node_t *) ((yp_<%= node.human %>_t *)node)-><%= param.name %>.nodes[index], buffer); + } + <%- when LocationListParam -%> + uint32_t <%= param.name %>_size = yp_sizet_to_u32(((yp_<%= node.human %>_t *)node)-><%= param.name %>.size); + yp_buffer_append_u32(buffer, <%= param.name %>_size); + for (uint32_t index = 0; index < <%= param.name %>_size; index++) { + serialize_location(parser, &((yp_<%= node.human %>_t *)node)-><%= param.name %>.locations[index], buffer); + } + <%- when ConstantParam -%> + yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_<%= node.human %>_t *)node)-><%= param.name %>)); + <%- when ConstantListParam -%> + uint32_t <%= param.name %>_size = yp_sizet_to_u32(((yp_<%= node.human %>_t *)node)-><%= param.name %>.size); + yp_buffer_append_u32(buffer, <%= param.name %>_size); + for (uint32_t index = 0; index < <%= param.name %>_size; index++) { + yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_<%= node.human %>_t *)node)-><%= param.name %>.ids[index])); + } + <%- when LocationParam -%> + serialize_location(parser, &((yp_<%= node.human %>_t *)node)-><%= param.name %>, buffer); + <%- when OptionalLocationParam -%> + if (((yp_<%= node.human %>_t *)node)-><%= param.name %>.start == NULL) { + yp_buffer_append_u8(buffer, 0); + } else { + yp_buffer_append_u8(buffer, 1); + serialize_location(parser, &((yp_<%= node.human %>_t *)node)-><%= param.name %>, buffer); + } + <%- when UInt32Param -%> + yp_buffer_append_u32(buffer, ((yp_<%= node.human %>_t *)node)-><%= param.name %>); + <%- when FlagsParam -%> + yp_buffer_append_u32(buffer, node->flags >> <%= COMMON_FLAGS %>); + <%- else -%> + <%- raise -%> + <%- end -%> + <%- end -%> + <%- if node.needs_serialized_length? -%> + // serialize length + uint32_t length = yp_sizet_to_u32(buffer->length - offset - sizeof(uint32_t)); + memcpy(buffer->value + length_offset, &length, sizeof(uint32_t)); + <%- end -%> + break; + } + <%- end -%> + } +} + +void yp_serialize_comment(yp_parser_t *parser, yp_comment_t *comment, yp_buffer_t *buffer) { + // serialize type + yp_buffer_append_u8(buffer, (uint8_t) comment->type); + + // serialize location + yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(comment->start - parser->start)); + yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(comment->end - comment->start)); +} + +void yp_serialize_comment_list(yp_parser_t *parser, yp_list_t list, yp_buffer_t *buffer) { + yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_list_size(&list))); + + yp_comment_t *comment; + for (comment = (yp_comment_t *) list.head; comment != NULL; comment = (yp_comment_t *) comment->node.next) { + yp_serialize_comment(parser, comment, buffer); + } +} + +void yp_serialize_diagnostic(yp_parser_t *parser, yp_diagnostic_t *diagnostic, yp_buffer_t *buffer) { + // serialize message + size_t message_length = strlen(diagnostic->message); + yp_buffer_append_u32(buffer, yp_sizet_to_u32(message_length)); + yp_buffer_append_str(buffer, diagnostic->message, message_length); + + // serialize location + yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(diagnostic->start - parser->start)); + yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(diagnostic->end - diagnostic->start)); +} + +void yp_serialize_diagnostic_list(yp_parser_t *parser, yp_list_t list, yp_buffer_t *buffer) { + yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_list_size(&list))); + + yp_diagnostic_t *diagnostic; + for (diagnostic = (yp_diagnostic_t *) list.head; diagnostic != NULL; diagnostic = (yp_diagnostic_t *) diagnostic->node.next) { + yp_serialize_diagnostic(parser, diagnostic, buffer); + } +} + +#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>" +void +yp_serialize_content(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) { + // First, serialize the encoding of the parser. + size_t encoding_length = strlen(parser->encoding.name); + yp_buffer_append_u32(buffer, yp_sizet_to_u32(encoding_length)); + yp_buffer_append_str(buffer, parser->encoding.name, encoding_length); + + // Serialize the comments + yp_serialize_comment_list(parser, parser->comment_list, buffer); + + // Serialize the errors + yp_serialize_diagnostic_list(parser, parser->error_list, buffer); + + // Serialize the warnings + yp_serialize_diagnostic_list(parser, parser->warning_list, buffer); + + // Here we're going to leave space for the offset of the constant pool in + // the buffer. + size_t offset = buffer->length; + yp_buffer_append_zeroes(buffer, 4); + + // Next, encode the length of the constant pool. + yp_buffer_append_u32(buffer, yp_sizet_to_u32(parser->constant_pool.size)); + + // Now we're going to serialize the content of the node. + yp_serialize_node(parser, node, buffer); + + // Now we're going to serialize the offset of the constant pool back where + // we left space for it. + uint32_t length = yp_sizet_to_u32(buffer->length); + memcpy(buffer->value + offset, &length, sizeof(uint32_t)); + + // Now we're going to serialize the constant pool. + offset = buffer->length; + yp_buffer_append_zeroes(buffer, parser->constant_pool.size * 8); + + yp_constant_t *constant; + for (size_t index = 0; index < parser->constant_pool.capacity; index++) { + constant = &parser->constant_pool.constants[index]; + + // If we find a constant at this index, serialize it at the correct + // index in the buffer. + if (constant->id != 0) { + size_t buffer_offset = offset + ((constant->id - 1) * 8); + + uint32_t source_offset = yp_ptrdifft_to_u32(constant->start - parser->start); + uint32_t constant_length = yp_sizet_to_u32(constant->length); + + memcpy(buffer->value + buffer_offset, &source_offset, 4); + memcpy(buffer->value + buffer_offset + 4, &constant_length, 4); + } + } +} + +static void +serialize_token(void *data, yp_parser_t *parser, yp_token_t *token) { + yp_buffer_t *buffer = (yp_buffer_t *) data; + + yp_buffer_append_u32(buffer, token->type); + yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(token->start - parser->start)); + yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(token->end - token->start)); + yp_buffer_append_u32(buffer, parser->lex_state); +} + +YP_EXPORTED_FUNCTION void +yp_lex_serialize(const char *source, size_t size, const char *filepath, yp_buffer_t *buffer) { + yp_parser_t parser; + yp_parser_init(&parser, source, size, filepath); + + yp_lex_callback_t lex_callback = (yp_lex_callback_t) { + .data = (void *) buffer, + .callback = serialize_token, + }; + + parser.lex_callback = &lex_callback; + yp_node_t *node = yp_parse(&parser); + + // Append 0 to mark end of tokens + yp_buffer_append_u32(buffer, 0); + + // Serialize the comments + yp_serialize_comment_list(&parser, parser.comment_list, buffer); + + // Serialize the errors + yp_serialize_diagnostic_list(&parser, parser.error_list, buffer); + + // Serialize the warnings + yp_serialize_diagnostic_list(&parser, parser.warning_list, buffer); + + yp_node_destroy(&parser, node); + yp_parser_free(&parser); +} diff --git a/yarp/templates/src/token_type.c.erb b/yarp/templates/src/token_type.c.erb new file mode 100644 index 00000000000000..d861352eec9a9c --- /dev/null +++ b/yarp/templates/src/token_type.c.erb @@ -0,0 +1,18 @@ +#include + +#include "yarp/ast.h" + +// Returns a string representation of the given token type. +YP_EXPORTED_FUNCTION const char * +yp_token_type_to_str(yp_token_type_t token_type) +{ + switch (token_type) { +<%- tokens.each do |token| -%> + case YP_TOKEN_<%= token.name %>: + return "<%= token.name %>"; +<%- end -%> + case YP_TOKEN_MAXIMUM: + return "MAXIMUM"; + } + return "\0"; +} diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb new file mode 100755 index 00000000000000..68df4524f74c8b --- /dev/null +++ b/yarp/templates/template.rb @@ -0,0 +1,329 @@ +#!/usr/bin/env ruby + +require "erb" +require "fileutils" +require "yaml" + +COMMON_FLAGS = 1 + +class Param + attr_reader :name, :options + + def initialize(name:, type:, **options) + @name, @type, @options = name, type, options + end +end + +module KindTypes + def c_type + if options[:kind] + "yp_#{options[:kind].gsub(/(?<=.)[A-Z]/, "_\\0").downcase}" + else + "yp_node" + end + end + + def java_type + options[:kind] || "Node" + end + + def java_cast + if options[:kind] + "(Nodes.#{options[:kind]}) " + else + "" + end + end +end + +# This represents a parameter to a node that is itself a node. We pass them as +# references and store them as references. +class NodeParam < Param + include KindTypes + + def rbs_class + "Node" + end +end + +# This represents a parameter to a node that is itself a node and can be +# optionally null. We pass them as references and store them as references. +class OptionalNodeParam < Param + include KindTypes + + def rbs_class + "Node?" + end +end + +SingleNodeParam = -> (node) { NodeParam === node or OptionalNodeParam === node } + +# This represents a parameter to a node that is a list of nodes. We pass them as +# references and store them as references. +class NodeListParam < Param + def rbs_class + "Array[Node]" + end + + def java_type + "Node[]" + end +end + +# This represents a parameter to a node that is a list of locations. +class LocationListParam < Param + def rbs_class + "Array[Location]" + end + + def java_type + "Location[]" + end +end + +# This represents a parameter to a node that is the ID of a string interned +# through the parser's constant pool. +class ConstantParam < Param + def rbs_class + "Symbol" + end + + def java_type + "byte[]" + end +end + +# This represents a parameter to a node that is a list of IDs that are +# associated with strings interned through the parser's constant pool. +class ConstantListParam < Param + def rbs_class + "Array[Symbol]" + end + + def java_type + "byte[][]" + end +end + +# This represents a parameter to a node that is a string. +class StringParam < Param + def rbs_class + "String" + end + + def java_type + "byte[]" + end +end + +# This represents a parameter to a node that is a location. +class LocationParam < Param + def rbs_class + "Location" + end + + def java_type + "Location" + end +end + +# This represents a parameter to a node that is a location that is optional. +class OptionalLocationParam < Param + def rbs_class + "Location?" + end + + def java_type + "Location" + end +end + +# This represents an integer parameter. +class UInt32Param < Param + def rbs_class + "Integer" + end + + def java_type + "int" + end +end + +# This represents a set of flags. It is very similar to the UInt32Param, but can +# be directly embedded into the flags field on the struct and provides +# convenient methods for checking if a flag is set. +class FlagsParam < Param + def rbs_class + "Integer" + end + + def java_type + "short" + end + + def kind + options.fetch(:kind) + end +end + +PARAM_TYPES = { + "node" => NodeParam, + "node?" => OptionalNodeParam, + "node[]" => NodeListParam, + "string" => StringParam, + "location[]" => LocationListParam, + "constant" => ConstantParam, + "constant[]" => ConstantListParam, + "location" => LocationParam, + "location?" => OptionalLocationParam, + "uint32" => UInt32Param, + "flags" => FlagsParam +} + +# This class represents a node in the tree, configured by the config.yml file in +# YAML format. It contains information about the name of the node and the +# various child nodes it contains. +class NodeType + attr_reader :name, :type, :human, :params, :newline, :comment + + def initialize(config) + @name = config.fetch("name") + + type = @name.gsub(/(?<=.)[A-Z]/, "_\\0") + @type = "YP_NODE_#{type.upcase}" + @human = type.downcase + @params = config.fetch("child_nodes", []).map do |param| + param_type = PARAM_TYPES[param.fetch("type")] || + raise("Unknown param type: #{param["type"].inspect}") + param_type.new(**param.transform_keys(&:to_sym)) + end + @newline = config.fetch("newline", true) + @comment = config.fetch("comment") + end + + # Should emit serialized length of node so implementations can skip + # the node to enable lazy parsing. + def needs_serialized_length? + @name == "DefNode" + end +end + +# This represents a token in the lexer. They are configured through the +# config.yml file for now, but this will probably change as we transition to +# storing semantic strings instead of the lexer tokens. +class Token + attr_reader :name, :value, :comment + + def initialize(config) + @name = config.fetch("name") + @value = config["value"] + @comment = config.fetch("comment") + end + + def declaration + output = [] + output << "YP_TOKEN_#{name}" + output << " = #{value}" if value + output << ", // #{comment}" + output.join + end +end + +# Represents a set of flags that should be internally represented with an enum. +class Flags + attr_reader :name, :human, :values + + def initialize(config) + @name = config.fetch("name") + @human = @name.gsub(/(?<=.)[A-Z]/, "_\\0").downcase + @values = config.fetch("values").map { |flag| Flag.new(flag) } + end +end + +class Flag + attr_reader :name, :camelcase, :comment + + def initialize(config) + @name = config.fetch("name") + @camelcase = @name.split("_").map(&:capitalize).join + @comment = config.fetch("comment") + end +end + +# This templates out a file using ERB with the given locals. The locals are +# derived from the config.yml file. +def template(name, locals, write_to: nil) + filepath = "templates/#{name}.erb" + template = File.expand_path("../#{filepath}", __dir__) + write_to ||= File.expand_path("../#{name}", __dir__) + + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ + erb = ERB.new(File.read(template), trim_mode: "-") + else + erb = ERB.new(File.read(template), nil, "-") + end + erb.filename = template + + non_ruby_heading = <<~HEADING + /******************************************************************************/ + /* This file is generated by the bin/template script and should not be */ + /* modified manually. See */ + /* #{filepath + " " * (74 - filepath.size) } */ + /* if you are looking to modify the */ + /* template */ + /******************************************************************************/ + HEADING + + ruby_heading = <<~HEADING + # frozen_string_literal: true + =begin + This file is generated by the bin/template script and should not be + modified manually. See #{filepath} + if you are looking to modify the template + =end + + HEADING + + heading = if File.extname(filepath.gsub(".erb", "")) == ".rb" + ruby_heading + else + non_ruby_heading + end + + contents = heading + erb.result_with_hash(locals) + FileUtils.mkdir_p(File.dirname(write_to)) + File.write(write_to, contents) +end + +def locals + config = YAML.load_file(File.expand_path("../config.yml", __dir__)) + + { + nodes: config.fetch("nodes").map { |node| NodeType.new(node) }.sort_by(&:name), + tokens: config.fetch("tokens").map { |token| Token.new(token) }, + flags: config.fetch("flags").map { |flags| Flags.new(flags) } + } +end + +TEMPLATES = [ + "ext/yarp/api_node.c", + "include/yarp/ast.h", + "java/org/yarp/Loader.java", + "java/org/yarp/Nodes.java", + "java/org/yarp/AbstractNodeVisitor.java", + "lib/yarp/node.rb", + "lib/yarp/serialize.rb", + "src/node.c", + "src/prettyprint.c", + "src/serialize.c", + "src/token_type.c" +] + +if __FILE__ == $0 + if ARGV.empty? + TEMPLATES.each { |f| template(f, locals) } + else + name, write_to = ARGV + template(name, locals, write_to: write_to) + end +end diff --git a/yarp/token_type.c b/yarp/token_type.c deleted file mode 100644 index 23b884749d8c88..00000000000000 --- a/yarp/token_type.c +++ /dev/null @@ -1,347 +0,0 @@ -/******************************************************************************/ -/* This file is generated by the bin/template script and should not be */ -/* modified manually. See */ -/* templates/src/token_type.c.erb */ -/* if you are looking to modify the */ -/* template */ -/******************************************************************************/ -#include - -#include "yarp/ast.h" - -// Returns a string representation of the given token type. -YP_EXPORTED_FUNCTION const char * -yp_token_type_to_str(yp_token_type_t token_type) -{ - switch (token_type) { - case YP_TOKEN_EOF: - return "EOF"; - case YP_TOKEN_MISSING: - return "MISSING"; - case YP_TOKEN_NOT_PROVIDED: - return "NOT_PROVIDED"; - case YP_TOKEN_AMPERSAND: - return "AMPERSAND"; - case YP_TOKEN_AMPERSAND_AMPERSAND: - return "AMPERSAND_AMPERSAND"; - case YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL: - return "AMPERSAND_AMPERSAND_EQUAL"; - case YP_TOKEN_AMPERSAND_DOT: - return "AMPERSAND_DOT"; - case YP_TOKEN_AMPERSAND_EQUAL: - return "AMPERSAND_EQUAL"; - case YP_TOKEN_BACKTICK: - return "BACKTICK"; - case YP_TOKEN_BACK_REFERENCE: - return "BACK_REFERENCE"; - case YP_TOKEN_BANG: - return "BANG"; - case YP_TOKEN_BANG_EQUAL: - return "BANG_EQUAL"; - case YP_TOKEN_BANG_TILDE: - return "BANG_TILDE"; - case YP_TOKEN_BRACE_LEFT: - return "BRACE_LEFT"; - case YP_TOKEN_BRACE_RIGHT: - return "BRACE_RIGHT"; - case YP_TOKEN_BRACKET_LEFT: - return "BRACKET_LEFT"; - case YP_TOKEN_BRACKET_LEFT_ARRAY: - return "BRACKET_LEFT_ARRAY"; - case YP_TOKEN_BRACKET_LEFT_RIGHT: - return "BRACKET_LEFT_RIGHT"; - case YP_TOKEN_BRACKET_LEFT_RIGHT_EQUAL: - return "BRACKET_LEFT_RIGHT_EQUAL"; - case YP_TOKEN_BRACKET_RIGHT: - return "BRACKET_RIGHT"; - case YP_TOKEN_CARET: - return "CARET"; - case YP_TOKEN_CARET_EQUAL: - return "CARET_EQUAL"; - case YP_TOKEN_CHARACTER_LITERAL: - return "CHARACTER_LITERAL"; - case YP_TOKEN_CLASS_VARIABLE: - return "CLASS_VARIABLE"; - case YP_TOKEN_COLON: - return "COLON"; - case YP_TOKEN_COLON_COLON: - return "COLON_COLON"; - case YP_TOKEN_COMMA: - return "COMMA"; - case YP_TOKEN_COMMENT: - return "COMMENT"; - case YP_TOKEN_CONSTANT: - return "CONSTANT"; - case YP_TOKEN_DOT: - return "DOT"; - case YP_TOKEN_DOT_DOT: - return "DOT_DOT"; - case YP_TOKEN_DOT_DOT_DOT: - return "DOT_DOT_DOT"; - case YP_TOKEN_EMBDOC_BEGIN: - return "EMBDOC_BEGIN"; - case YP_TOKEN_EMBDOC_END: - return "EMBDOC_END"; - case YP_TOKEN_EMBDOC_LINE: - return "EMBDOC_LINE"; - case YP_TOKEN_EMBEXPR_BEGIN: - return "EMBEXPR_BEGIN"; - case YP_TOKEN_EMBEXPR_END: - return "EMBEXPR_END"; - case YP_TOKEN_EMBVAR: - return "EMBVAR"; - case YP_TOKEN_EQUAL: - return "EQUAL"; - case YP_TOKEN_EQUAL_EQUAL: - return "EQUAL_EQUAL"; - case YP_TOKEN_EQUAL_EQUAL_EQUAL: - return "EQUAL_EQUAL_EQUAL"; - case YP_TOKEN_EQUAL_GREATER: - return "EQUAL_GREATER"; - case YP_TOKEN_EQUAL_TILDE: - return "EQUAL_TILDE"; - case YP_TOKEN_FLOAT: - return "FLOAT"; - case YP_TOKEN_FLOAT_IMAGINARY: - return "FLOAT_IMAGINARY"; - case YP_TOKEN_FLOAT_RATIONAL: - return "FLOAT_RATIONAL"; - case YP_TOKEN_FLOAT_RATIONAL_IMAGINARY: - return "FLOAT_RATIONAL_IMAGINARY"; - case YP_TOKEN_GLOBAL_VARIABLE: - return "GLOBAL_VARIABLE"; - case YP_TOKEN_GREATER: - return "GREATER"; - case YP_TOKEN_GREATER_EQUAL: - return "GREATER_EQUAL"; - case YP_TOKEN_GREATER_GREATER: - return "GREATER_GREATER"; - case YP_TOKEN_GREATER_GREATER_EQUAL: - return "GREATER_GREATER_EQUAL"; - case YP_TOKEN_HEREDOC_END: - return "HEREDOC_END"; - case YP_TOKEN_HEREDOC_START: - return "HEREDOC_START"; - case YP_TOKEN_IDENTIFIER: - return "IDENTIFIER"; - case YP_TOKEN_IGNORED_NEWLINE: - return "IGNORED_NEWLINE"; - case YP_TOKEN_INSTANCE_VARIABLE: - return "INSTANCE_VARIABLE"; - case YP_TOKEN_INTEGER: - return "INTEGER"; - case YP_TOKEN_INTEGER_IMAGINARY: - return "INTEGER_IMAGINARY"; - case YP_TOKEN_INTEGER_RATIONAL: - return "INTEGER_RATIONAL"; - case YP_TOKEN_INTEGER_RATIONAL_IMAGINARY: - return "INTEGER_RATIONAL_IMAGINARY"; - case YP_TOKEN_KEYWORD_ALIAS: - return "KEYWORD_ALIAS"; - case YP_TOKEN_KEYWORD_AND: - return "KEYWORD_AND"; - case YP_TOKEN_KEYWORD_BEGIN: - return "KEYWORD_BEGIN"; - case YP_TOKEN_KEYWORD_BEGIN_UPCASE: - return "KEYWORD_BEGIN_UPCASE"; - case YP_TOKEN_KEYWORD_BREAK: - return "KEYWORD_BREAK"; - case YP_TOKEN_KEYWORD_CASE: - return "KEYWORD_CASE"; - case YP_TOKEN_KEYWORD_CLASS: - return "KEYWORD_CLASS"; - case YP_TOKEN_KEYWORD_DEF: - return "KEYWORD_DEF"; - case YP_TOKEN_KEYWORD_DEFINED: - return "KEYWORD_DEFINED"; - case YP_TOKEN_KEYWORD_DO: - return "KEYWORD_DO"; - case YP_TOKEN_KEYWORD_DO_LOOP: - return "KEYWORD_DO_LOOP"; - case YP_TOKEN_KEYWORD_ELSE: - return "KEYWORD_ELSE"; - case YP_TOKEN_KEYWORD_ELSIF: - return "KEYWORD_ELSIF"; - case YP_TOKEN_KEYWORD_END: - return "KEYWORD_END"; - case YP_TOKEN_KEYWORD_END_UPCASE: - return "KEYWORD_END_UPCASE"; - case YP_TOKEN_KEYWORD_ENSURE: - return "KEYWORD_ENSURE"; - case YP_TOKEN_KEYWORD_FALSE: - return "KEYWORD_FALSE"; - case YP_TOKEN_KEYWORD_FOR: - return "KEYWORD_FOR"; - case YP_TOKEN_KEYWORD_IF: - return "KEYWORD_IF"; - case YP_TOKEN_KEYWORD_IF_MODIFIER: - return "KEYWORD_IF_MODIFIER"; - case YP_TOKEN_KEYWORD_IN: - return "KEYWORD_IN"; - case YP_TOKEN_KEYWORD_MODULE: - return "KEYWORD_MODULE"; - case YP_TOKEN_KEYWORD_NEXT: - return "KEYWORD_NEXT"; - case YP_TOKEN_KEYWORD_NIL: - return "KEYWORD_NIL"; - case YP_TOKEN_KEYWORD_NOT: - return "KEYWORD_NOT"; - case YP_TOKEN_KEYWORD_OR: - return "KEYWORD_OR"; - case YP_TOKEN_KEYWORD_REDO: - return "KEYWORD_REDO"; - case YP_TOKEN_KEYWORD_RESCUE: - return "KEYWORD_RESCUE"; - case YP_TOKEN_KEYWORD_RESCUE_MODIFIER: - return "KEYWORD_RESCUE_MODIFIER"; - case YP_TOKEN_KEYWORD_RETRY: - return "KEYWORD_RETRY"; - case YP_TOKEN_KEYWORD_RETURN: - return "KEYWORD_RETURN"; - case YP_TOKEN_KEYWORD_SELF: - return "KEYWORD_SELF"; - case YP_TOKEN_KEYWORD_SUPER: - return "KEYWORD_SUPER"; - case YP_TOKEN_KEYWORD_THEN: - return "KEYWORD_THEN"; - case YP_TOKEN_KEYWORD_TRUE: - return "KEYWORD_TRUE"; - case YP_TOKEN_KEYWORD_UNDEF: - return "KEYWORD_UNDEF"; - case YP_TOKEN_KEYWORD_UNLESS: - return "KEYWORD_UNLESS"; - case YP_TOKEN_KEYWORD_UNLESS_MODIFIER: - return "KEYWORD_UNLESS_MODIFIER"; - case YP_TOKEN_KEYWORD_UNTIL: - return "KEYWORD_UNTIL"; - case YP_TOKEN_KEYWORD_UNTIL_MODIFIER: - return "KEYWORD_UNTIL_MODIFIER"; - case YP_TOKEN_KEYWORD_WHEN: - return "KEYWORD_WHEN"; - case YP_TOKEN_KEYWORD_WHILE: - return "KEYWORD_WHILE"; - case YP_TOKEN_KEYWORD_WHILE_MODIFIER: - return "KEYWORD_WHILE_MODIFIER"; - case YP_TOKEN_KEYWORD_YIELD: - return "KEYWORD_YIELD"; - case YP_TOKEN_KEYWORD___ENCODING__: - return "KEYWORD___ENCODING__"; - case YP_TOKEN_KEYWORD___FILE__: - return "KEYWORD___FILE__"; - case YP_TOKEN_KEYWORD___LINE__: - return "KEYWORD___LINE__"; - case YP_TOKEN_LABEL: - return "LABEL"; - case YP_TOKEN_LABEL_END: - return "LABEL_END"; - case YP_TOKEN_LAMBDA_BEGIN: - return "LAMBDA_BEGIN"; - case YP_TOKEN_LESS: - return "LESS"; - case YP_TOKEN_LESS_EQUAL: - return "LESS_EQUAL"; - case YP_TOKEN_LESS_EQUAL_GREATER: - return "LESS_EQUAL_GREATER"; - case YP_TOKEN_LESS_LESS: - return "LESS_LESS"; - case YP_TOKEN_LESS_LESS_EQUAL: - return "LESS_LESS_EQUAL"; - case YP_TOKEN_MINUS: - return "MINUS"; - case YP_TOKEN_MINUS_EQUAL: - return "MINUS_EQUAL"; - case YP_TOKEN_MINUS_GREATER: - return "MINUS_GREATER"; - case YP_TOKEN_NEWLINE: - return "NEWLINE"; - case YP_TOKEN_NUMBERED_REFERENCE: - return "NUMBERED_REFERENCE"; - case YP_TOKEN_PARENTHESIS_LEFT: - return "PARENTHESIS_LEFT"; - case YP_TOKEN_PARENTHESIS_LEFT_PARENTHESES: - return "PARENTHESIS_LEFT_PARENTHESES"; - case YP_TOKEN_PARENTHESIS_RIGHT: - return "PARENTHESIS_RIGHT"; - case YP_TOKEN_PERCENT: - return "PERCENT"; - case YP_TOKEN_PERCENT_EQUAL: - return "PERCENT_EQUAL"; - case YP_TOKEN_PERCENT_LOWER_I: - return "PERCENT_LOWER_I"; - case YP_TOKEN_PERCENT_LOWER_W: - return "PERCENT_LOWER_W"; - case YP_TOKEN_PERCENT_LOWER_X: - return "PERCENT_LOWER_X"; - case YP_TOKEN_PERCENT_UPPER_I: - return "PERCENT_UPPER_I"; - case YP_TOKEN_PERCENT_UPPER_W: - return "PERCENT_UPPER_W"; - case YP_TOKEN_PIPE: - return "PIPE"; - case YP_TOKEN_PIPE_EQUAL: - return "PIPE_EQUAL"; - case YP_TOKEN_PIPE_PIPE: - return "PIPE_PIPE"; - case YP_TOKEN_PIPE_PIPE_EQUAL: - return "PIPE_PIPE_EQUAL"; - case YP_TOKEN_PLUS: - return "PLUS"; - case YP_TOKEN_PLUS_EQUAL: - return "PLUS_EQUAL"; - case YP_TOKEN_QUESTION_MARK: - return "QUESTION_MARK"; - case YP_TOKEN_REGEXP_BEGIN: - return "REGEXP_BEGIN"; - case YP_TOKEN_REGEXP_END: - return "REGEXP_END"; - case YP_TOKEN_SEMICOLON: - return "SEMICOLON"; - case YP_TOKEN_SLASH: - return "SLASH"; - case YP_TOKEN_SLASH_EQUAL: - return "SLASH_EQUAL"; - case YP_TOKEN_STAR: - return "STAR"; - case YP_TOKEN_STAR_EQUAL: - return "STAR_EQUAL"; - case YP_TOKEN_STAR_STAR: - return "STAR_STAR"; - case YP_TOKEN_STAR_STAR_EQUAL: - return "STAR_STAR_EQUAL"; - case YP_TOKEN_STRING_BEGIN: - return "STRING_BEGIN"; - case YP_TOKEN_STRING_CONTENT: - return "STRING_CONTENT"; - case YP_TOKEN_STRING_END: - return "STRING_END"; - case YP_TOKEN_SYMBOL_BEGIN: - return "SYMBOL_BEGIN"; - case YP_TOKEN_TILDE: - return "TILDE"; - case YP_TOKEN_UAMPERSAND: - return "UAMPERSAND"; - case YP_TOKEN_UCOLON_COLON: - return "UCOLON_COLON"; - case YP_TOKEN_UDOT_DOT: - return "UDOT_DOT"; - case YP_TOKEN_UDOT_DOT_DOT: - return "UDOT_DOT_DOT"; - case YP_TOKEN_UMINUS: - return "UMINUS"; - case YP_TOKEN_UMINUS_NUM: - return "UMINUS_NUM"; - case YP_TOKEN_UPLUS: - return "UPLUS"; - case YP_TOKEN_USTAR: - return "USTAR"; - case YP_TOKEN_USTAR_STAR: - return "USTAR_STAR"; - case YP_TOKEN_WORDS_SEP: - return "WORDS_SEP"; - case YP_TOKEN___END__: - return "__END__"; - case YP_TOKEN_MAXIMUM: - return "MAXIMUM"; - } - return "\0"; -} diff --git a/yarp/yarp.c b/yarp/yarp.c index 67402541301928..715c2819491d62 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -5653,13 +5653,23 @@ parser_lex(yp_parser_t *parser) { break; case '\\': if (peek_at(parser, 1) == '\n') { - yp_newline_list_append(&parser->newline_list, parser->current.end + 1); - parser->current.end += 2; - space_seen = true; - } else if (parser->current.end + 2 < parser->end && peek_at(parser, 1) == '\r' && peek_at(parser, 2) == '\n') { - yp_newline_list_append(&parser->newline_list, parser->current.end + 2); - parser->current.end += 3; - space_seen = true; + if (parser->heredoc_end) { + parser->current.end = parser->heredoc_end; + parser->heredoc_end = NULL; + } else { + yp_newline_list_append(&parser->newline_list, parser->current.end + 1); + parser->current.end += 2; + space_seen = true; + } + } else if (peek_at(parser, 1) == '\r' && peek_at(parser, 2) == '\n') { + if (parser->heredoc_end) { + parser->current.end = parser->heredoc_end; + parser->heredoc_end = NULL; + } else { + yp_newline_list_append(&parser->newline_list, parser->current.end + 2); + parser->current.end += 3; + space_seen = true; + } } else if (yp_char_is_inline_whitespace(*parser->current.end)) { parser->current.end += 2; } else { @@ -6494,13 +6504,11 @@ parser_lex(yp_parser_t *parser) { // % %= %i %I %q %Q %w %W case '%': { - // In a BEG state, if you encounter a % then you must be - // starting something. In this case if there is no - // subsequent character then we have an invalid token. We're - // going to say it's the percent operator because we don't - // want to move into the string lex mode unnecessarily. - if (lex_state_beg_p(parser) && (parser->current.end >= parser->end)) { - yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, "unexpected end of input"); + // If there is no subsequent character then we have an invalid token. We're + // going to say it's the percent operator because we don't want to move into the + // string lex mode unnecessarily. + if ((lex_state_beg_p(parser) || lex_state_arg_p(parser)) && (parser->current.end >= parser->end)) { + yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, "Unexpected end of input"); LEX(YP_TOKEN_PERCENT); } diff --git a/yjit/src/asm/arm64/inst/mod.rs b/yjit/src/asm/arm64/inst/mod.rs index 665ebef57c2e0b..bfffd914efe29a 100644 --- a/yjit/src/asm/arm64/inst/mod.rs +++ b/yjit/src/asm/arm64/inst/mod.rs @@ -17,6 +17,7 @@ mod load_store_exclusive; mod logical_imm; mod logical_reg; mod madd; +mod smulh; mod mov; mod nop; mod pc_rel; @@ -42,6 +43,7 @@ pub use load_store_exclusive::LoadStoreExclusive; pub use logical_imm::LogicalImm; pub use logical_reg::LogicalReg; pub use madd::MAdd; +pub use smulh::SMulH; pub use mov::Mov; pub use nop::Nop; pub use pc_rel::PCRelative; diff --git a/yjit/src/asm/arm64/inst/smulh.rs b/yjit/src/asm/arm64/inst/smulh.rs new file mode 100644 index 00000000000000..796a19433fb362 --- /dev/null +++ b/yjit/src/asm/arm64/inst/smulh.rs @@ -0,0 +1,60 @@ +/// The struct that represents an A64 signed multipy high instruction +/// +/// +-------------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+ +/// | 31 30 29 28 | 27 26 25 24 | 23 22 21 20 | 19 18 17 16 | 15 14 13 12 | 11 10 09 08 | 07 06 05 04 | 03 02 01 00 | +/// | 1 0 0 1 1 0 1 1 0 1 0 0 | +/// | rm.............. ra.............. rn.............. rd.............. | +/// +-------------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+ +/// +pub struct SMulH { + /// The number of the general-purpose destination register. + rd: u8, + + /// The number of the first general-purpose source register. + rn: u8, + + /// The number of the third general-purpose source register. + ra: u8, + + /// The number of the second general-purpose source register. + rm: u8, +} + +impl SMulH { + /// SMULH + /// https://developer.arm.com/documentation/ddi0602/2023-06/Base-Instructions/SMULH--Signed-Multiply-High- + pub fn smulh(rd: u8, rn: u8, rm: u8) -> Self { + Self { rd, rn, ra: 0b11111, rm } + } +} + +impl From for u32 { + /// Convert an instruction into a 32-bit value. + fn from(inst: SMulH) -> Self { + 0 + | (0b10011011010 << 21) + | ((inst.rm as u32) << 16) + | ((inst.ra as u32) << 10) + | ((inst.rn as u32) << 5) + | (inst.rd as u32) + } +} + +impl From for [u8; 4] { + /// Convert an instruction into a 4 byte array. + fn from(inst: SMulH) -> [u8; 4] { + let result: u32 = inst.into(); + result.to_le_bytes() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_smulh() { + let result: u32 = SMulH::smulh(0, 1, 2).into(); + assert_eq!(0x9b427c20, result); + } +} diff --git a/yjit/src/asm/arm64/mod.rs b/yjit/src/asm/arm64/mod.rs index bcdbda8dc06433..eb99c00ba7cba1 100644 --- a/yjit/src/asm/arm64/mod.rs +++ b/yjit/src/asm/arm64/mod.rs @@ -186,7 +186,7 @@ pub fn asr(cb: &mut CodeBlock, rd: A64Opnd, rn: A64Opnd, shift: A64Opnd) { SBFM::asr(rd.reg_no, rn.reg_no, shift.try_into().unwrap(), rd.num_bits).into() }, - _ => panic!("Invalid operand combination to asr instruction."), + _ => panic!("Invalid operand combination to asr instruction: asr {:?}, {:?}, {:?}", rd, rn, shift), }; cb.write_bytes(&bytes); @@ -713,6 +713,21 @@ pub fn mul(cb: &mut CodeBlock, rd: A64Opnd, rn: A64Opnd, rm: A64Opnd) { cb.write_bytes(&bytes); } +/// SMULH - multiply two 64-bit registers to produce a 128-bit result, put the high 64-bits of the result into rd +pub fn smulh(cb: &mut CodeBlock, rd: A64Opnd, rn: A64Opnd, rm: A64Opnd) { + let bytes: [u8; 4] = match (rd, rn, rm) { + (A64Opnd::Reg(rd), A64Opnd::Reg(rn), A64Opnd::Reg(rm)) => { + assert!(rd.num_bits == rn.num_bits && rn.num_bits == rm.num_bits, "Expected registers to be the same size"); + assert!(rd.num_bits == 64, "smulh only applicable to 64-bit registers"); + + SMulH::smulh(rd.reg_no, rn.reg_no, rm.reg_no).into() + }, + _ => panic!("Invalid operand combination to mul instruction") + }; + + cb.write_bytes(&bytes); +} + /// MVN - move a value in a register to another register, negating it pub fn mvn(cb: &mut CodeBlock, rd: A64Opnd, rm: A64Opnd) { let bytes: [u8; 4] = match (rd, rm) { diff --git a/yjit/src/backend/arm64/mod.rs b/yjit/src/backend/arm64/mod.rs index a991a4b2151c02..1007df9cf8ee6d 100644 --- a/yjit/src/backend/arm64/mod.rs +++ b/yjit/src/backend/arm64/mod.rs @@ -612,6 +612,19 @@ impl Assembler asm.not(opnd0); }, + Insn::LShift { opnd, shift, .. } | + Insn::RShift { opnd, shift, .. } | + Insn::URShift { opnd, shift, .. } => { + // The operand must be in a register, so + // if we get anything else we need to load it first. + let opnd0 = match opnd { + Opnd::Mem(_) => split_load_operand(asm, *opnd), + _ => *opnd + }; + + *opnd = opnd0; + asm.push_insn(insn); + }, Insn::Store { dest, src } => { // The value being stored must be in a register, so if it's // not already one we'll load it first. @@ -811,6 +824,7 @@ impl Assembler let start_write_pos = cb.get_write_pos(); let mut insn_idx: usize = 0; while let Some(insn) = self.insns.get(insn_idx) { + let mut next_insn_idx = insn_idx + 1; let src_ptr = cb.get_write_ptr(); let had_dropped_bytes = cb.has_dropped_bytes(); let old_label_state = cb.get_label_state(); @@ -863,7 +877,32 @@ impl Assembler subs(cb, out.into(), left.into(), right.into()); }, Insn::Mul { left, right, out } => { - mul(cb, out.into(), left.into(), right.into()); + // If the next instruction is jo (jump on overflow) + match self.insns.get(insn_idx + 1) { + Some(Insn::Jo(target)) => { + // Compute the high 64 bits + smulh(cb, Self::SCRATCH0, left.into(), right.into()); + + // Compute the low 64 bits + // This may clobber one of the input registers, + // so we do it after smulh + mul(cb, out.into(), left.into(), right.into()); + + // Produce a register that is all zeros or all ones + // Based on the sign bit of the 64-bit mul result + asr(cb, Self::SCRATCH1, out.into(), A64Opnd::UImm(63)); + + // If the high 64-bits are not all zeros or all ones, + // matching the sign bit, then we have an overflow + cmp(cb, Self::SCRATCH0, Self::SCRATCH1); + emit_conditional_jump::<{Condition::NE}>(cb, compile_side_exit(*target, self, ocb)); + + next_insn_idx += 1; + } + _ => { + mul(cb, out.into(), left.into(), right.into()); + } + } }, Insn::And { left, right, out } => { and(cb, out.into(), left.into(), right.into()); @@ -1158,7 +1197,7 @@ impl Assembler return Err(()); } } else { - insn_idx += 1; + insn_idx = next_insn_idx; gc_offsets.append(&mut insn_gc_offsets); } } diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 88c567755142c9..8e83f128af733f 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -3398,8 +3398,42 @@ fn gen_opt_mult( asm: &mut Assembler, ocb: &mut OutlinedCb, ) -> Option { - // Delegate to send, call the method on the recv - gen_opt_send_without_block(jit, asm, ocb) + let two_fixnums = match asm.ctx.two_fixnums_on_stack(jit) { + Some(two_fixnums) => two_fixnums, + None => { + defer_compilation(jit, asm, ocb); + return Some(EndBlock); + } + }; + + if two_fixnums { + if !assume_bop_not_redefined(jit, asm, ocb, INTEGER_REDEFINED_OP_FLAG, BOP_MULT) { + return None; + } + + // Check that both operands are fixnums + guard_two_fixnums(jit, asm, ocb); + + // Get the operands from the stack + let arg1 = asm.stack_pop(1); + let arg0 = asm.stack_pop(1); + + // Do some bitwise gymnastics to handle tag bits + // x * y is translated to (x >> 1) * (y - 1) + 1 + let arg0_untag = asm.rshift(arg0, Opnd::UImm(1)); + let arg1_untag = asm.sub(arg1, Opnd::UImm(1)); + let out_val = asm.mul(arg0_untag, arg1_untag); + asm.jo(Target::side_exit(Counter::opt_mult_overflow)); + let out_val = asm.add(out_val, Opnd::UImm(1)); + + // Push the output on the stack + let dst = asm.stack_push(Type::Fixnum); + asm.mov(dst, out_val); + + Some(KeepCompiling) + } else { + gen_opt_send_without_block(jit, asm, ocb) + } } fn gen_opt_div( @@ -4497,6 +4531,9 @@ fn jit_rb_int_div( } guard_two_fixnums(jit, asm, ocb); + // rb_fix_div_fix may GC-allocate for Bignum + jit_prepare_routine_call(jit, asm); + asm.comment("Integer#/"); let obj = asm.stack_pop(1); let recv = asm.stack_pop(1); @@ -4507,7 +4544,7 @@ fn jit_rb_int_div( let ret = asm.ccall(rb_fix_div_fix as *const u8, vec![recv, obj]); - let ret_opnd = asm.stack_push(Type::Fixnum); + let ret_opnd = asm.stack_push(Type::Unknown); asm.mov(ret_opnd, ret); true } @@ -4764,7 +4801,7 @@ fn jit_rb_str_concat( asm.spill_temps(); // for ccall let ret_opnd = asm.ccall(rb_yjit_str_simple_append as *const u8, vec![recv, concat_arg]); let ret_label = asm.new_label("func_return"); - let stack_ret = asm.stack_push(Type::CString); + let stack_ret = asm.stack_push(Type::TString); asm.mov(stack_ret, ret_opnd); asm.stack_pop(1); // forget stack_ret to re-push after ccall asm.jmp(ret_label); @@ -4773,7 +4810,7 @@ fn jit_rb_str_concat( asm.write_label(enc_mismatch); asm.spill_temps(); // for ccall let ret_opnd = asm.ccall(rb_str_buf_append as *const u8, vec![recv, concat_arg]); - let stack_ret = asm.stack_push(Type::CString); + let stack_ret = asm.stack_push(Type::TString); asm.mov(stack_ret, ret_opnd); // Drop through to return @@ -4885,20 +4922,28 @@ fn jit_obj_respond_to( }; let result = match (visibility, allow_priv) { - (METHOD_VISI_UNDEF, _) => Qfalse, // No method => false - (METHOD_VISI_PUBLIC, _) => Qtrue, // Public method => true regardless of include_all - (_, Some(true)) => Qtrue, // include_all => always true + (METHOD_VISI_UNDEF, _) => { + // No method, we can return false given respond_to_missing? hasn't been overridden. + // In the future, we might want to jit the call to respond_to_missing? + if !assume_method_basic_definition(jit, asm, ocb, recv_class, idRespond_to_missing.into()) { + return false; + } + Qfalse + } + (METHOD_VISI_PUBLIC, _) | // Public method => fine regardless of include_all + (_, Some(true)) => { // include_all => all visibility are acceptable + // Method exists and has acceptable visibility + if cme_def_type == VM_METHOD_TYPE_NOTIMPLEMENTED { + // C method with rb_f_notimplement(). `respond_to?` returns false + // without consulting `respond_to_missing?`. See also: rb_add_method_cfunc() + Qfalse + } else { + Qtrue + } + } (_, _) => return false // not public and include_all not known, can't compile }; - if result != Qtrue { - // Only if respond_to_missing? hasn't been overridden - // In the future, we might want to jit the call to respond_to_missing? - if !assume_method_basic_definition(jit, asm, ocb, recv_class, idRespond_to_missing.into()) { - return false; - } - } - // Invalidate this block if method lookup changes for the method being queried. This works // both for the case where a method does or does not exist, as for the latter we asked for a // "negative CME" earlier. diff --git a/yjit/src/stats.rs b/yjit/src/stats.rs index c6b0ea4e184a84..9ef3e8e94ce6d2 100644 --- a/yjit/src/stats.rs +++ b/yjit/src/stats.rs @@ -343,6 +343,7 @@ make_counters! { opt_plus_overflow, opt_minus_overflow, + opt_mult_overflow, opt_mod_zero, opt_div_zero,