Class: C::Preprocessor

Inherits:
Object
  • Object
show all
Defined in:
lib/cast/preprocessor.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

INCLUDE_REGEX =
/(?:[^ ]|\\ )+\.h/i
COMPILER =
RbConfig::CONFIG["CC"]

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePreprocessor

Returns a new instance of Preprocessor.



24
25
26
27
# File 'lib/cast/preprocessor.rb', line 24

def initialize
  @include_path = []
  @macros = {}
end

Class Attribute Details

.commandObject

Returns the value of attribute command.



19
20
21
# File 'lib/cast/preprocessor.rb', line 19

def command
  @command
end

Instance Attribute Details

#include_pathObject

Returns the value of attribute include_path.



22
23
24
# File 'lib/cast/preprocessor.rb', line 22

def include_path
  @include_path
end

#macrosObject

Returns the value of attribute macros.



22
23
24
# File 'lib/cast/preprocessor.rb', line 22

def macros
  @macros
end

#pwdObject

Returns the value of attribute pwd.



22
23
24
# File 'lib/cast/preprocessor.rb', line 22

def pwd
  @pwd
end

Instance Method Details

#get_all_includes(text) ⇒ Object

if clean_gnu_artifacts output.gsub!(/\b__asm((?:"[^"]"|[^)"])*)/, '') output.gsub!(/\b__attribute__(((?:[^()]|([^()]+))+))/, '') output.gsub!(/ __inline /, ' ') end



40
41
42
43
# File 'lib/cast/preprocessor.rb', line 40

def get_all_includes(text)
  args = %w{-E -M}
  split_includes run(args, text)
end

#get_project_includes(text) ⇒ Object



47
48
49
50
# File 'lib/cast/preprocessor.rb', line 47

def get_project_includes(text)
  args = %w{-E -MM}
  split_includes run(args, text)
end

#get_system_includes(text) ⇒ Object



44
45
46
# File 'lib/cast/preprocessor.rb', line 44

def get_system_includes(text)
  get_all_includes(text) - get_project_includes(text)
end

#preprocess(text, line_markers = false) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cast/preprocessor.rb', line 28

def preprocess(text, line_markers = false)
  args = %w{-E}
  args << "-P" unless line_markers
  run args, text
=begin
  if clean_gnu_artifacts
    output.gsub!(/\b__asm\((?:"[^"]*"|[^)"]*)*\)/, '')
    output.gsub!(/\b__attribute__\(\((?:[^()]|\([^()]+\))+\)\)/, '')
    output.gsub!(/ __inline /, ' ')
  end
=end
end

#preprocess_file(file_name) ⇒ Object



51
52
53
# File 'lib/cast/preprocessor.rb', line 51

def preprocess_file(file_name)
  preprocess(File.read(file_name))
end