Class: Rubber::C_Class

Inherits:
C_Module show all
Includes:
RegisterChildren
Defined in:
lib/rubber/codegen/class.rb

Direct Known Subclasses

C_GBoxed, C_GInterface, C_GObject, C_Struct

Instance Attribute Summary collapse

Attributes included from RegisterChildren

#source_file, #source_line

Instance Method Summary collapse

Methods included from RegisterChildren

#cname, #register_children

Methods inherited from C_Module

#add_alias, #contents, #external?, #register_aliases

Instance Attribute Details

#child_namesObject (readonly)

Returns the value of attribute child_names


8
9
10
# File 'lib/rubber/codegen/class.rb', line 8

def child_names
  @child_names
end

#docObject

Returns the value of attribute doc


7
8
9
# File 'lib/rubber/codegen/class.rb', line 7

def doc
  @doc
end

#post_exceptObject

Returns the value of attribute post_except


7
8
9
# File 'lib/rubber/codegen/class.rb', line 7

def post_except
  @post_except
end

#post_func(io, func) ⇒ Object

Returns the value of attribute post_func


7
8
9
# File 'lib/rubber/codegen/class.rb', line 7

def post_func
  @post_func
end

#post_onlyObject

Returns the value of attribute post_only


7
8
9
# File 'lib/rubber/codegen/class.rb', line 7

def post_only
  @post_only
end

#pre_exceptObject

Returns the value of attribute pre_except


7
8
9
# File 'lib/rubber/codegen/class.rb', line 7

def pre_except
  @pre_except
end

#pre_func(io, func) ⇒ Object

Returns the value of attribute pre_func


7
8
9
# File 'lib/rubber/codegen/class.rb', line 7

def pre_func
  @pre_func
end

#pre_onlyObject

Returns the value of attribute pre_only


7
8
9
# File 'lib/rubber/codegen/class.rb', line 7

def pre_only
  @pre_only
end

Instance Method Details

#check_wrap_ok(io, fn, where) ⇒ Object


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rubber/codegen/class.rb', line 52

def check_wrap_ok(io, fn, where)
  case where
  when :pre
 code   = @pre_func
 only   = @pre_only
 except = @pre_except
	when :post
 code   = @post_func
 only   = @post_only
 except = @post_except
	end
	if code && ! fn.singleton
return if only && ! only.empty? && ! only.include?(fn.name)
return if except && except.include?(fn.name)
io.puts code
	end
end

#code(io) ⇒ Object


29
30
31
# File 'lib/rubber/codegen/class.rb', line 29

def code(io)
  contents .each { |f| f.code(io) }
end

#declare(io) ⇒ Object


32
33
34
35
# File 'lib/rubber/codegen/class.rb', line 32

def declare(io)
  io.puts "static VALUE #{cname};";
  contents .each { |f| f.declare(io) }
end

#default_cnameObject


49
50
51
# File 'lib/rubber/codegen/class.rb', line 49

def default_cname
  "c#{name}"
end

#doc_rd(io) ⇒ Object


17
18
19
20
21
22
23
24
# File 'lib/rubber/codegen/class.rb', line 17

def doc_rd(io)
  id = fullname()
  id += " < #{superclass}" if superclass
  depth = (fullname.gsub(/[^:]/,'').size >> 1)
  io.puts "=#{'=' * depth} class #{id}"
  io.puts @doc if @doc
  contents.each { |f| f.doc_rd(io) }
end

#fullnameObject


10
11
12
13
14
15
16
# File 'lib/rubber/codegen/class.rb', line 10

def fullname()
  if parent and parent.respond_to?(:fullname)
    "#{parent.fullname}::#{name}"
  else
    name
  end
end

#get_rootObject


25
# File 'lib/rubber/codegen/class.rb', line 25

def get_root(); is_root? ? self : parent.get_root; end

#is_root?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/rubber/codegen/class.rb', line 26

def is_root?()
  not parent.respond_to?(:fullname)
end

#register(io, already_defined = false) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rubber/codegen/class.rb', line 36

def register(io, already_defined=false)
  if parent.child_names && parent.child_names[name]
    	io.puts "  c#{name} = #{cname};"
  else
   if parent and parent.cname
     io.puts "  #{cname} = rb_define_class_under(#{parent.cname}, #{name.inspect}, #{Rubber.find_class(superclass) || 'rb_cObject'});"
   else
     io.puts "  #{cname} = rb_define_class(#{name.inspect}, #{Rubber.find_class(superclass) || 'rb_cObject'});"
   end
  end
  register_children(io)
end