Class: Duby::AST::Raise
- Includes:
- Valued
- Defined in:
- lib/duby/ast/flow.rb,
lib/duby/compiler.rb,
lib/duby/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) ⇒ Object
-
#initialize(parent, line_number, &block) ⇒ Raise
constructor
A new instance of Raise.
Methods inherited from Node
#<<, ===, #[], #_set_parent, child, child_name, #each, #empty?, #initialize_copy, #insert, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s
Constructor Details
#initialize(parent, line_number, &block) ⇒ Raise
Returns a new instance of Raise.
229 230 231 |
# File 'lib/duby/ast/flow.rb', line 229 def initialize(parent, line_number, &block) super(parent, line_number, &block) end |
Instance Method Details
#compile(compiler, expression) ⇒ Object
299 300 301 302 |
# File 'lib/duby/compiler.rb', line 299 def compile(compiler, expression) compiler.line(line_number) compiler._raise(exception) end |
#expr?(compiler) ⇒ Boolean
158 159 160 |
# File 'lib/duby/jvm/source_generator/precompile.rb', line 158 def expr?(compiler) false end |
#infer(typer) ⇒ Object
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 264 265 266 267 |
# File 'lib/duby/ast/flow.rb', line 233 def infer(typer) unless resolved? @inferred_type = AST.unreachable_type throwable = AST.type('java.lang.Throwable') if children.size == 1 arg_type = typer.infer(self.exception) unless arg_type typer.defer(self) return end if throwable.assignable_from?(arg_type) && !arg_type. resolved! return @inferred_type end end arg_types = children.map {|c| typer.infer(c)} if arg_types.any? {|c| c.nil?} typer.defer(self) else if arg_types[0] && throwable.assignable_from?(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) end end @inferred_type end |