class RCGTK::Module::GlobalCollection

This class is used to access a module’s global variables.

Public Class Methods

new(mod) click to toggle source

@param [Module] mod Module for which this is a proxy.

# File lib/rcgtk/module.rb, line 369
def initialize(mod)
        @module = mod
end

Public Instance Methods

[](key) click to toggle source

Retreive a GlobalVariable object.

@param [String, Symbol, Integer] key Global variable identifier. Either the name of the variable or its index.

@return [GlobalVariable]

# File lib/rcgtk/module.rb, line 378
def [](key)
        case key
        when String, Symbol
                self.named(key)

        when Integer
                (1...key).inject(self.first) { |global| if global then self.next(global) else break end }
        end
end
add(type, name) click to toggle source

Add a global variable to a module.

@param [Type] type Type of the global variable. @param [String] name Name of the global variable in LLVM IR.

# File lib/rcgtk/module.rb, line 392
def add(type, name)
        GlobalVariable.new(Bindings.add_global(@module, type, name))
end
delete(global) click to toggle source

Remove a global variable from the module.

@param [GlobalVariable] global Global variable to remove.

@return [void]

# File lib/rcgtk/module.rb, line 401
def delete(global)
        Bindings.delete_global(global)
end
each() { |global| ... } click to toggle source

An iterator for each global variable inside this collection.

@yieldparam fun [GlobalVariable]

@return [Enumerator] Returns an Enumerator if no block is given.

# File lib/rcgtk/module.rb, line 410
def each
        return to_enum(:each) unless block_given?

        global = self.first

        while global
                yield global
                global = self.next(global)
        end
end
first() click to toggle source

@return [GlobalVariable, nil] The module’s first global variable if one has been added.

# File lib/rcgtk/module.rb, line 422
def first
        if (ptr = Bindings.get_first_global(@module)).null? then nil else GlobalValue.new(ptr) end
end
last() click to toggle source

@return [GlobalVariable, nil] The module’s last global variable if one has been added.

# File lib/rcgtk/module.rb, line 427
def last
        if (ptr = Bindings.get_last_global(@module)).null? then nil else GlobalValue.new(ptr) end
end
named(name) click to toggle source

@param [String, Symbol] name Name of the desired global variable.

@return [GlobalVariable, nil] The global variable with the given name.

# File lib/rcgtk/module.rb, line 434
def named(name)
        if (ptr = Bindings.get_named_global(@module, name)).null? then nil else GlobalValue.new(ptr) end
end
next(global) click to toggle source

@param [GlobalVariable] global Global variable you want the successor for.

@return [GlobalVariable, nil] Next global variable in the collection.

# File lib/rcgtk/module.rb, line 441
def next(global)
        if (ptr = Bindings.get_next_global(global)).null? then nil else GlobalValue.new(ptr) end
end
previous(global) click to toggle source

@param [GlobalVariable] global Global variable you want the predecessor for.

@return [GlobalVariable, nil] Previous global variable in the collection.

# File lib/rcgtk/module.rb, line 448
def previous(global)
        if (ptr = Bindings.get_previous_global(global)).null? then nil else GlobalValue.new(ptr) end
end