Class: SystemNavigation::CompiledMethod

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

Overview

Since:

  • 0.1.0

Constant Summary collapse

IVAR =

Since:

  • 0.1.0

/\A@[^@]/
CVAR =

Since:

  • 0.1.0

/\A@@/
GVAR =

Since:

  • 0.1.0

/\A\$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method) ⇒ CompiledMethod

Returns a new instance of CompiledMethod.

Since:

  • 0.1.0



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/system_navigation/compiled_method.rb', line 13

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

Since:

  • 0.1.0



37
38
39
# File 'lib/system_navigation/compiled_method.rb', line 37

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

Instance Attribute Details

#sourceObject (readonly)

Since:

  • 0.1.0



11
12
13
# File 'lib/system_navigation/compiled_method.rb', line 11

def source
  @source
end

Class Method Details

.compile(method) ⇒ Object

Since:

  • 0.1.0



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)

Since:

  • 0.1.0



93
94
95
# File 'lib/system_navigation/compiled_method.rb', line 93

def c_method?
  @method.source_location.nil?
end

#compileObject

Since:

  • 0.1.0



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

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)

Since:

  • 0.1.0



48
49
50
51
52
53
54
# File 'lib/system_navigation/compiled_method.rb', line 48

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)

Since:

  • 0.1.0



97
98
99
# File 'lib/system_navigation/compiled_method.rb', line 97

def rb_method?
  !self.c_method?
end

#reads_field?(var) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/system_navigation/compiled_method.rb', line 56

def reads_field?(var)
  case var
  when IVAR
    self.scan_for { @decoder.ivar_read_scan(var) }
  when CVAR
    self.scan_for { @decoder.cvar_read_scan(var) }
  when GVAR
    self.scan_for { @decoder.gvar_read_scan(var) }
  else
    raise ArgumentError, "unknown argument #{var}"
  end
end

#sends_message?(message) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



82
83
84
# File 'lib/system_navigation/compiled_method.rb', line 82

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

#sent_messagesObject

Since:

  • 0.1.0



101
102
103
# File 'lib/system_navigation/compiled_method.rb', line 101

def sent_messages
  @decoder.scan_for_sent_messages
end

#source_contains?(string, match_case) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



86
87
88
89
90
91
# File 'lib/system_navigation/compiled_method.rb', line 86

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

Since:

  • 0.1.0



41
42
43
# File 'lib/system_navigation/compiled_method.rb', line 41

def unwrap
  @method
end

#writes_field?(var) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/system_navigation/compiled_method.rb', line 69

def writes_field?(var)
  case var
  when IVAR
    self.scan_for { @decoder.ivar_write_scan(var) }
  when CVAR
    self.scan_for { @decoder.cvar_write_scan(var) }
  when GVAR
    self.scan_for { @decoder.gvar_write_scan(var) }
  else
    raise ArgumentError, "unknown argument #{var}"
  end
end