Class: Mirah::AST::Raise
- Includes:
- Valued
- Defined in:
- lib/mirah/ast/flow.rb,
lib/mirah/compiler/flow.rb,
lib/mirah/jvm/source_generator/precompile.rb
Instance Attribute Summary
Attributes included from Valued
Attributes included from Typed
Attributes inherited from Node
#children, #inferred_type, #newline, #parent, #position
Instance Method Summary collapse
- #compile(compiler, expression) ⇒ Object
- #expr?(compiler) ⇒ Boolean
- #infer(typer, expression) ⇒ Object
-
#initialize(parent, line_number, &block) ⇒ Raise
constructor
A new instance of Raise.
Methods inherited from Node
#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #inferred_type!, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #string_value, #temp, #to_s, #top_level?, #validate_child, #validate_children
Constructor Details
#initialize(parent, line_number, &block) ⇒ Raise
Returns a new instance of Raise.
225 226 227 |
# File 'lib/mirah/ast/flow.rb', line 225 def initialize(parent, line_number, &block) super(parent, line_number, &block) end |
Instance Method Details
#compile(compiler, expression) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/mirah/compiler/flow.rb', line 83 def compile(compiler, expression) compiler.line(line_number) compiler._raise(exception) rescue Exception => ex raise Mirah::InternalCompilerError.wrap(ex, self) end |
#expr?(compiler) ⇒ Boolean
182 183 184 |
# File 'lib/mirah/jvm/source_generator/precompile.rb', line 182 def expr?(compiler) false end |
#infer(typer, expression) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/mirah/ast/flow.rb', line 229 def infer(typer, expression) unless resolved? @inferred_type = AST.unreachable_type throwable = AST.type(nil, 'java.lang.Throwable') if children.size == 1 arg_type = typer.infer(self.exception, true) unless arg_type typer.defer(self) return end if throwable.compatible?(arg_type) && !arg_type. resolved! return @inferred_type end end arg_types = children.map {|c| typer.infer(c, true)} if arg_types.any? {|c| c.nil?} typer.defer(self) else if arg_types[0] && throwable.compatible?(arg_types[0]) klass = children.shift else klass = Constant.new(self, position, 'RuntimeException') end exception = Call.new(self, position, 'new') do [klass, children, nil] end resolved! @children = [exception] typer.infer(exception, true) end end @inferred_type end |