Class: Rubber::C_Struct
Instance Attribute Summary collapse
#source_file, #source_line
Attributes inherited from C_Class
#doc, #post_except, #post_func, #post_only, #pre_except, #pre_func, #pre_only
Attributes inherited from C_Module
#doc
Instance Method Summary
collapse
#cname, #register_children
Methods inherited from C_Class
#check_wrap_ok, #code
Methods inherited from C_Module
#add_alias, #code, #contents, #external?, #register_aliases
Instance Attribute Details
#child_names ⇒ Object
Returns the value of attribute child_names.
7
8
9
|
# File 'lib/rubber/codegen/struct.rb', line 7
def child_names
@child_names
end
|
Instance Method Details
#declare(io) ⇒ Object
13
14
15
|
# File 'lib/rubber/codegen/struct.rb', line 13
def declare(io)
io.puts "static VALUE #{cname};"
end
|
#default_cname ⇒ Object
17
18
19
|
# File 'lib/rubber/codegen/struct.rb', line 17
def default_cname
"struct"+name
end
|
#doc_rd(io) ⇒ Object
20
21
22
23
|
# File 'lib/rubber/codegen/struct.rb', line 20
def doc_rd(io)
depth = (fullname.gsub(/[^:]/,'').size >> 1)
io.puts "=#{'=' * depth} enum #{fullname}"
end
|
#fullname ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/rubber/codegen/struct.rb', line 27
def fullname()
if parent and parent.respond_to?(:fullname)
"#{parent.fullname}::#{name}"
else
name
end
end
|
#get_root ⇒ Object
24
|
# File 'lib/rubber/codegen/struct.rb', line 24
def get_root(); is_root? ? self : parent.get_root; end
|
#init ⇒ Object
8
9
10
11
12
|
# File 'lib/rubber/codegen/struct.rb', line 8
def init
@functions = []
@classes = []
@methods = []
end
|
#is_root? ⇒ Boolean
24
25
26
|
# File 'lib/rubber/codegen/struct.rb', line 24
def is_root?()
not parent.respond_to?(:fullname)
end
|
#register(io, already_defined = false) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/rubber/codegen/struct.rb', line 52
def register(io, already_defined=false)
io.puts " #{cname} = rb_struct_define(#{name.inspect}, #{args.map{|m|m[0]==?" && m || m.inspect}.join(', ')}, NULL);"
if parent
io.puts " rb_define_const(#{parent.cname}, #{name.inspect}, #{cname});"
else
end
register_children(io)
end
|
#same_prefix(arr) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/rubber/codegen/struct.rb', line 34
def same_prefix(arr)
for i in arr
return false if arr.first.first != i.first
end
return true
end
|
#strip_prefixes(arr) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/rubber/codegen/struct.rb', line 40
def strip_prefixes(arr)
splits = arr.collect { |i| i.strip.split(/_/) }
while (same_prefix(splits))
splits.each { |i| i.shift }
end
splits.collect!{|i| i.join('_') }
splits
end
|