Class: Cplus2Ruby::CodeGenerator
- Inherits:
-
Object
- Object
- Cplus2Ruby::CodeGenerator
show all
- Defined in:
- lib/cplus2ruby/code_generator.rb
Instance Method Summary
collapse
Constructor Details
#initialize(model = Cplus2Ruby.model) ⇒ CodeGenerator
Returns a new instance of CodeGenerator.
4
5
6
|
# File 'lib/cplus2ruby/code_generator.rb', line 4
def initialize(model=Cplus2Ruby.model)
@model = model
end
|
Instance Method Details
#all_methods_of(klass) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/cplus2ruby/code_generator.rb', line 35
def all_methods_of(klass)
klass.local_annotations.each do |name, options|
next if options[:class] != Cplus2Ruby::Method
yield name, options
end
end
|
#all_properties_of(klass) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/cplus2ruby/code_generator.rb', line 27
def all_properties_of(klass)
klass.local_annotations.sort_by {|name, options| options[:order] || 0}.
each do |name, options|
next if options[:class] != Cplus2Ruby::Property
yield name, options
end
end
|
#args_convertable?(args) ⇒ Boolean
42
43
44
45
46
47
|
# File 'lib/cplus2ruby/code_generator.rb', line 42
def args_convertable?(args)
args.each {|_, type| return false unless @model.typing.can_convert?(type) }
return true
end
|
#arity(args) ⇒ Object
49
50
51
52
53
|
# File 'lib/cplus2ruby/code_generator.rb', line 49
def arity(args)
args.size - ((args.has_key?('returns') || args.has_key?(:returns)) ? 1 : 0)
end
|
#no_wrap?(klass) ⇒ Boolean
19
20
21
|
# File 'lib/cplus2ruby/code_generator.rb', line 19
def no_wrap?(klass)
(klass.local_annotations[:__options__] || {})[:no_wrap]
end
|
#wrap?(klass) ⇒ Boolean
23
24
25
|
# File 'lib/cplus2ruby/code_generator.rb', line 23
def wrap?(klass)
not no_wrap?(klass)
end
|
#write_out(file, str) ⇒ Object
Allows preprocessing of generated code.
11
12
13
14
15
16
17
|
# File 'lib/cplus2ruby/code_generator.rb', line 11
def write_out(file, str)
if @model.settings()[:substitute_iv_ats]
str.gsub!('@', 'this->')
end
FileUtils.mkdir_p(File.dirname(file))
File.open(file, 'w+') {|out| out.puts str}
end
|