Class: Furnace::AVM2::Tokens::CalleeToken
- Inherits:
-
Code::SurroundedToken
- Object
- Code::SurroundedToken
- Furnace::AVM2::Tokens::CalleeToken
- Defined in:
- lib/furnace-avm2/source/declaration_tokens/callee_token.rb
Direct Known Subclasses
Instance Method Summary collapse
- #declaration(origin, options) ⇒ Object
-
#initialize(origin, header, method, body, options = {}) ⇒ CalleeToken
constructor
A new instance of CalleeToken.
- #text_after ⇒ Object
Constructor Details
#initialize(origin, header, method, body, options = {}) ⇒ CalleeToken
Returns a new instance of CalleeToken.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/furnace-avm2/source/declaration_tokens/callee_token.rb', line 3 def initialize(origin, header, method, body, ={}) @method, @body = method, body super(origin, [ *header, *declaration(origin, ), (Furnace::AVM2::Decompiler.new(@body, ).decompile if @body), (Furnace::Code::NewlineToken.new(origin, ) if @body && ![:closure]) ], ) if [:debug_funids] && ![:closure] @children.unshift \ CommentToken.new(origin, "Method ##{[:index]}", ) end end |
Instance Method Details
#declaration(origin, options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/furnace-avm2/source/declaration_tokens/callee_token.rb', line 29 def declaration(origin, ) if @method.has_defaults? defaults = [nil] * (@method.param_count - @method.default_count) + @method.defaults end args = @method.param_count.times.map do |num| if @method.has_param_names? name = @method.param_names[num] else name = "param#{num}" end if defaults default = defaults[num] end ArgumentDeclarationToken.new(@origin, [ VariableNameToken.new(origin, name, ), (TypeToken.new(origin, [ MultinameToken.new(origin, @method.param_types[num], ) ], ) if @method.param_types[num]), (InitializationToken.new(origin, [ ImmediateToken.new(origin, default.printable_value, ) ], ) if default && default.printable_value) ], ) end if @method.needs_rest? args << ArgumentDeclarationToken.new(origin, [ RestArgumentToken.new(origin, "local0", ) ], ) end tokens = [] tokens << ArgumentsToken.new(origin, args, ) if @method.return_type && ![:closure] tokens << TypeToken.new(origin, [ MultinameToken.new(origin, @method.return_type, ) ], ) end tokens end |
#text_after ⇒ Object
23 24 25 26 27 |
# File 'lib/furnace-avm2/source/declaration_tokens/callee_token.rb', line 23 def text_after if @body.nil? ";\n" # no bodies end end |