Class: Mirah::AST::Raise

Inherits:
Node
  • Object
show all
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

#value

Attributes included from Typed

#type

Attributes inherited from Node

#children, #inferred_type, #newline, #parent, #position

Instance Method Summary collapse

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.



224
225
226
# File 'lib/mirah/ast/flow.rb', line 224

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

Returns:



182
183
184
# File 'lib/mirah/jvm/source_generator/precompile.rb', line 182

def expr?(compiler)
  false
end

#infer(typer, expression) ⇒ Object



228
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
# File 'lib/mirah/ast/flow.rb', line 228

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.meta?
        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