Class: RbPlusPlus::Builders::ModuleNode

Inherits:
Base
  • Object
show all
Includes:
ClassHelpers, EnumerationHelpers, ModuleHelpers
Defined in:
lib/rbplusplus/builders/module.rb

Overview

Handles code generation dealing with user-defined modules.

Direct Known Subclasses

ExtensionNode

Instance Attribute Summary collapse

Attributes inherited from Base

#code, #declarations, #global_nodes, #includes, #nodes, #parent, #registrations, #rice_variable, #rice_variable_type

Instance Method Summary collapse

Methods included from ClassHelpers

#implicit_casting?, #with_classes, #with_constants, #with_constructors, #with_variables

Methods included from EnumerationHelpers

#with_enumerations

Methods included from ModuleHelpers

#with_module_functions, #with_modules

Methods inherited from Base

#has_children?, #sort

Constructor Details

#initialize(code, parent = nil) ⇒ ModuleNode

Node is the RbModule object, it proxies any unknown calls off to it’s internal Node object



18
19
20
21
22
23
# File 'lib/rbplusplus/builders/module.rb', line 18

def initialize(code, parent = nil)
  super

  @name ||= code.name
  @modules ||= code.modules
end

Instance Attribute Details

#modulesObject

And needs to specially handle any other nexted modules



14
15
16
# File 'lib/rbplusplus/builders/module.rb', line 14

def modules
  @modules
end

#nameObject

Has a name



11
12
13
# File 'lib/rbplusplus/builders/module.rb', line 11

def name
  @name
end

Instance Method Details

#buildObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rbplusplus/builders/module.rb', line 29

def build
  with_modules

  add_child IncludeNode.new(self, "rice/Module.hpp", :system)

  # Make sure we ignore anything from the :: namespace
  if self.code && self.code.name != "::"
    with_module_functions
    with_enumerations
    with_classes
  end

  nodes.flatten!

  self.rice_variable_type = "Rice::Module"
  self.rice_variable = "rb_m#{self.qualified_name.as_variable}"
end

#qualified_nameObject



25
26
27
# File 'lib/rbplusplus/builders/module.rb', line 25

def qualified_name
  self.code.qualified_name
end

#writeObject



47
48
49
50
51
52
53
54
55
# File 'lib/rbplusplus/builders/module.rb', line 47

def write
  prefix = "\t#{rice_variable_type} #{rice_variable} = "

  if parent.rice_variable
    registrations << "#{prefix} Rice::define_module_under(#{parent.rice_variable}, \"#{@name}\");"
  else
    registrations << "#{prefix} Rice::define_module(\"#{@name}\");"
  end
end