3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/furnace-avm2/source/declaration_tokens/token_with_traits.rb', line 3
def transform_traits(origin, options)
tokens = []
vars, methods = origin.traits.partition do |trait|
[:Class, :Slot, :Const].include? trait.kind
end
if options[:environment] == :class && options[:static]
if origin.initializer_body
initializer_decompiler = Furnace::AVM2::Decompiler.new(
origin.initializer_body, options.merge(global_code: true))
begin
properties = initializer_decompiler.decompose_static_initializer
rescue Exception => e
end
static_initialization = initializer_decompiler.decompile
options = options.merge(property_values: properties)
end
end
tokens += vars.map { |trait| transform_trait trait, options }
if tokens.any?
tokens << Furnace::Code::NewlineToken.new(origin, options)
end
if static_initialization && static_initialization.children.any?
tokens << CommentToken.new(origin,
"Method ##{origin.initializer_body.method_idx}",
options) if options[:debug_funids]
tokens << static_initialization
tokens << Furnace::Code::NewlineToken.new(origin, options)
end
if options[:environment] == :class && !options[:static]
tokens << ConstructorToken.new(origin, options)
end
tokens += methods.map { |trait| transform_trait trait, options }
tokens
end
|