Module: RMasm::DirectiveContainer
Overview
A Directive Container is the root class for Directive containers:
-
section
-
the top assembler
Instance Method Summary collapse
- #<<(arg) ⇒ Object
-
#accept(directive) ⇒ Object
Add.
- #add_directive(directive) ⇒ Object
- #add_directive_core(directive, accept) ⇒ Object
- #container_block_begin ⇒ Object
- #container_block_end ⇒ Object
- #init_container ⇒ Object
- #parent ⇒ Object
- #parent=(arg) ⇒ Object
Instance Method Details
#<<(arg) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/rmasm/directive.rb', line 109 def <<(arg) _context = $rmasm.context # Cache the current context directive = arg block = nil # If arg is an array => [directive, block], a block is supplied with this directive if arg.is_a?(Array) directive, block = arg end # If the current context accept the directive, add it to it accept = _context.accept(directive) case accept when :accept, :process # If directive is an array, this is a directive and a block evaluation if !block.nil? # Add the extracted directive container _context.add_directive_core directive, accept # If a block is supplied, then evaluate the block if !block.nil? begin directive.container_block_begin # eval the block inside the new structure directive.instance_eval &block rescue => ex directive.container_block_end # restore back the context $rmasm.context = _context raise ex end directive.container_block_end # restore back the context $rmasm.context = _context end else _context.add_directive_core directive, accept end when :parent # send directive to parent $rmasm.context = _context.parent $rmasm.context << arg # If the directive is a container, then leave the context to this directive # unless the directive has a block if ! directive.is_a?(DirectiveContainer) || ( directive.is_a?(DirectiveContainer) && !block.nil? ) $rmasm.context = _context end when :reject arg_name = directive.respond_to?(:name) ? directive.name : nil directive_id = directive.respond_to?(:id) ? directive.id : "" nested_class_name = directive.class.name.sub(/.*::/,'') top_class_name = _context.class.name.sub(/.*::/,'') if arg_name.nil? arg_name = directive_id directive_id = "" else directive_id = ":#{directive_id}" end return Report.error(:R0053, "#{nested_class_name}#{directive_id}", arg_name, top_class_name ) end arg end |
#accept(directive) ⇒ Object
Add
69 70 71 |
# File 'lib/rmasm/directive.rb', line 69 def accept(directive) raise NotImplementedError.new end |
#add_directive(directive) ⇒ Object
73 74 75 |
# File 'lib/rmasm/directive.rb', line 73 def add_directive(directive) raise NotImplementedError.new end |
#add_directive_core(directive, accept) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rmasm/directive.rb', line 77 def add_directive_core(directive,accept) #Add the directive to the context # Only add the directive when it is different from the last one if (accept == :accept) add_directive directive end # If the directive is a container then if directive.is_a?(DirectiveContainer) # Set the directive parent container to the context directive.parent = self # Set the current container to the new directive container $rmasm.context = directive end end |
#container_block_begin ⇒ Object
103 104 |
# File 'lib/rmasm/directive.rb', line 103 def container_block_begin() end |
#container_block_end ⇒ Object
106 107 |
# File 'lib/rmasm/directive.rb', line 106 def container_block_end() end |
#init_container ⇒ Object
64 65 66 |
# File 'lib/rmasm/directive.rb', line 64 def init_container @parent_container = nil end |
#parent ⇒ Object
95 96 97 |
# File 'lib/rmasm/directive.rb', line 95 def parent() @parent_container end |
#parent=(arg) ⇒ Object
99 100 101 |
# File 'lib/rmasm/directive.rb', line 99 def parent=(arg) @parent_container = arg end |