Class: Rubber::C_Module

Inherits:
Object
  • Object
show all
Includes:
RegisterChildren
Defined in:
lib/rubber/codegen/module.rb

Direct Known Subclasses

C_Class

Instance Attribute Summary collapse

Attributes included from RegisterChildren

#source_file, #source_line

Instance Method Summary collapse

Methods included from RegisterChildren

#cname, #register_children

Instance Attribute Details

#child_namesObject

Returns the value of attribute child_names


5
6
7
# File 'lib/rubber/codegen/module.rb', line 5

def child_names
  @child_names
end

#docObject

Returns the value of attribute doc


5
6
7
# File 'lib/rubber/codegen/module.rb', line 5

def doc
  @doc
end

Instance Method Details

#add_alias(from, to) ⇒ Object


41
42
43
# File 'lib/rubber/codegen/module.rb', line 41

def add_alias(from, to)
	(@aliases ||= []) << [from, to]
end

#code(io) ⇒ Object


9
10
11
# File 'lib/rubber/codegen/module.rb', line 9

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

#contentsObject


6
7
8
# File 'lib/rubber/codegen/module.rb', line 6

def contents()
  (functions + methods + classes)
end

#declare(io) ⇒ Object


12
13
14
15
# File 'lib/rubber/codegen/module.rb', line 12

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

#default_cnameObject


17
18
19
# File 'lib/rubber/codegen/module.rb', line 17

def default_cname
  "m"+name
end

#doc_rd(io) ⇒ Object


20
21
22
23
24
25
# File 'lib/rubber/codegen/module.rb', line 20

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

#external?Boolean

ie. defined externally…

Returns:

  • (Boolean)

38
39
40
# File 'lib/rubber/codegen/module.rb', line 38

def external? # ie. *defined* externally...
  cname == 'mGtk' || cname == 'mGdk' || cname == "mGLib"
end

#fullnameObject


30
31
32
33
34
35
36
37
# File 'lib/rubber/codegen/module.rb', line 30

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

#get_rootObject


26
# File 'lib/rubber/codegen/module.rb', line 26

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

#is_root?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/rubber/codegen/module.rb', line 27

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

#register(io, already_defined = false) ⇒ Object


51
52
53
54
55
56
57
58
59
60
# File 'lib/rubber/codegen/module.rb', line 51

def register(io, already_defined=false)
  unless external?
    if parent and not parent.kind_of?(C_RootModule)
      io.puts "  #{cname} = rb_define_module_under(#{parent.cname}, #{name.inspect});"
    else
      io.puts "  #{cname} = rb_define_module(#{name.inspect});"
    end
  end
  register_children(io)
end

#register_aliases(io) ⇒ Object


44
45
46
47
48
49
50
# File 'lib/rubber/codegen/module.rb', line 44

def register_aliases(io)
  if @aliases
    @aliases.each do |from,to|
      io.puts "  rb_define_alias(#{cname},#{from.inspect},#{to.inspect});"
    end
  end
end