Debian Codegraph @

core/miku/to_ruby/compiled_code.rb

raw symbols SCIP
1 # frozen_string_literal: true
2
3 require 'delegate'
4
5 require_relative 'type'
6
7 module MIKU::ToRuby
8 class CompiledCode < SimpleDelegator
9 attr_reader :type, :priority
10
11 # @params [Boolean] taint Scopeを変化させる
12 # @params [Boolean] affect Scopeに影響を受けて実行結果が変化する
13 # @params [Array[Class]|ANY] type 式の評価結果の型
14 def initialize(str, taint:, affect:, type: ANY, priority: -1)
15 super(str.to_s.freeze)
16 @type = type
17 @priority = priority.to_i
18 @taint = taint
19 @affect = affect
20 end
21
22 def indent
23 __setobj__(each_line.map { " #{_1.chomp}" }.join("\n").freeze)
24 self
25 end
26
27 def attach_paren
28 if @priority > -1
29 @priority = -1
30 __setobj__("(#{self})")
31 end
32 self
33 end
34
35 def single_line?
36 each_line.take(2).size == 1
37 end
38
39 def taint?
40 @taint
41 end
42
43 def affect?
44 @affect
45 end
46
47 def pure?
48 !(taint? || affect?)
49 end
50
51 def deconstruct_keys(_keys)
52 {
53 taint: @taint,
54 affect: @affect,
55 pure: pure?,
56 priority: @priority,
57 type: @type
58 }
59 end
60
61 def inspect
62 x = ["p=#{@priority}", "t=#{@type}"]
63 x << 'taint' if taint?
64 x << 'affect' if affect?
65 x << 'pure' if pure?
66 "#{super}<#{x.join(',')}>"
67 end
68 end
69 end