Class: SystemNavigation::CompiledMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/system_navigation/compiled_method.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method) ⇒ CompiledMethod

Returns a new instance of CompiledMethod.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/system_navigation/compiled_method.rb', line 7

def initialize(method)
  @method = method
  @scanner = SystemNavigation::InstructionStream.on(method)
  @decoder = InstructionStream::Decoder.new(@scanner)

  begin
    @source = FastMethodSource.source_for(@method)
  rescue FastMethodSource::SourceNotFoundError, IOError
    @source = ''
  end

  begin
    @comment = FastMethodSource.comment_for(@method)
  rescue FastMethodSource::SourceNotFoundError, IOError
    @comment = ''
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



31
32
33
# File 'lib/system_navigation/compiled_method.rb', line 31

def method_missing(method_name, *args, &block)
  @method.send(method_name, *args, &block)
end

Class Method Details

.compile(method) ⇒ Object



3
4
5
# File 'lib/system_navigation/compiled_method.rb', line 3

def self.compile(method)
  self.new(method).compile
end

Instance Method Details

#c_method?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/system_navigation/compiled_method.rb', line 69

def c_method?
  @method.source_location.nil?
end

#compileObject



25
26
27
28
29
# File 'lib/system_navigation/compiled_method.rb', line 25

def compile
  @scanner.decode

  self
end

#has_literal?(literal) ⇒ Boolean

Literals that are referenced by the receiver as described in ‘doc/syntax/literals.rdoc` in your Ruby, installation minus procs and backticks.

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/system_navigation/compiled_method.rb', line 42

def has_literal?(literal)
  return true if self.scan_for { @decoder.literal_scan(literal) }
  return false if self.c_method?

  exptree = ExpressionTree.of(method: @method, source: @source)
  exptree.includes?(literal)
end

#rb_method?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/system_navigation/compiled_method.rb', line 73

def rb_method?
  !self.c_method?
end

#reads_field?(ivar) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/system_navigation/compiled_method.rb', line 50

def reads_field?(ivar)
  self.scan_for { @decoder.ivar_read_scan(ivar) }
end

#sends_message?(message) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/system_navigation/compiled_method.rb', line 58

def sends_message?(message)
  self.scan_for { @decoder.msg_send_scan(message) }
end

#sent_messagesObject



77
78
79
# File 'lib/system_navigation/compiled_method.rb', line 77

def sent_messages
  @decoder.scan_for_sent_messages
end

#source_contains?(string, match_case) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
# File 'lib/system_navigation/compiled_method.rb', line 62

def source_contains?(string, match_case)
  string = string.dup
  code_and_comment = @source + @comment
  code_and_comment.downcase! && string.downcase! unless match_case
  !!code_and_comment.match(string)
end

#unwrapObject



35
36
37
# File 'lib/system_navigation/compiled_method.rb', line 35

def unwrap
  @method
end

#writes_field?(ivar) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/system_navigation/compiled_method.rb', line 54

def writes_field?(ivar)
  self.scan_for { @decoder.ivar_write_scan(ivar) }
end