Class: Furnace::AVM2::Tokens::CalleeToken

Inherits:
Code::SurroundedToken
  • Object
show all
Defined in:
lib/furnace-avm2/source/declaration_tokens/callee_token.rb

Direct Known Subclasses

ClosureToken, ConstructorToken, MethodToken

Instance Method Summary collapse

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, options={})
  @method, @body = method, body

  super(origin, [
    *header,
    *declaration(origin, options),
    (Furnace::AVM2::Decompiler.new(@body,
            options).decompile if @body),
    (Furnace::Code::NewlineToken.new(origin,
            options) if @body && !options[:closure])
  ], options)

  if options[:debug_funids] && !options[:closure]
    @children.unshift \
      CommentToken.new(origin,
        "Method ##{options[:index]}",
      options)
  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, options)
  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, options),
      (TypeToken.new(origin, [
        MultinameToken.new(origin, @method.param_types[num], options)
      ], options) if @method.param_types[num]),
      (InitializationToken.new(origin, [
        ImmediateToken.new(origin, default.printable_value, options)
      ], options) if default && default.printable_value)
    ], options)
  end

  if @method.needs_rest?
    args << ArgumentDeclarationToken.new(origin, [
      RestArgumentToken.new(origin, "local0", options)
    ], options)
  end

  tokens = []

  tokens << ArgumentsToken.new(origin, args, options)

  if @method.return_type && !options[:closure]
    tokens << TypeToken.new(origin, [
      MultinameToken.new(origin, @method.return_type, options)
    ], options)
  end

  tokens
end

#text_afterObject



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