Class: Mirah::JVM::Types::StringType

Inherits:
Type show all
Defined in:
lib/mirah/jvm/types/intrinsics.rb

Constant Summary

Constants inherited from AST::TypeReference

AST::TypeReference::BlockType, AST::TypeReference::ErrorType, AST::TypeReference::NoType, AST::TypeReference::NullType, AST::TypeReference::UnreachableType

Instance Attribute Summary

Attributes inherited from Type

#inner_class

Attributes inherited from AST::TypeReference

#array, #meta

Attributes included from AST::Named

#name

Attributes inherited from AST::Node

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

Instance Method Summary collapse

Methods inherited from Type

#add_compiled_macro, #add_enumerable_macros, #add_macro, #add_method, #aload, #array?, #array_type, #assignable_from?, #astore, #basic_type, #compatible?, #component_type, #constructor, #declared_class_methods, #declared_constructors, #declared_instance_methods, #declared_intrinsics, #dynamic?, #expand_each, #field_getter, #field_setter, #full_name, #get_method, #include, #init_value, #initialize, #inner_class?, #inner_class_getter, #inspect, #interface?, #interfaces, #intrinsics, #is_parent, #iterable?, #java_method, #jvm_type, #load, #load_extensions, #log, #meta, #meta?, #newarray, #pop, #prefix, #primitive?, #return, #store, #superclass, #to_source, #unmeta, #void?, #wide?, #wrap_with_scoped_body

Methods included from MethodLookup

#each_is_exact, #each_is_exact_or_subtype_or_convertible, #field_lookup, #find_jls, #find_method, #inner_class, #is_more_specific?, #log, #phase1, #phase2, #phase3, #primitive_convertible?

Methods inherited from AST::TypeReference

#==, #_dump, _load, #basic_type, #block?, #compatible?, #component_type, #eql?, #error?, #full_name, #hash, #initialize, #is_parent, #iterable?, #meta?, #narrow, #null?, #primitive?, #to_s, #type_reference, #unmeta, #unreachable?, #void?

Methods included from AST::Named

#string_value, #to_s, #validate_name

Methods inherited from AST::Node

#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #expr?, #inferred_type!, #initialize, #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

This class inherits a constructor from Mirah::JVM::Types::Type

Instance Method Details

#add_intrinsicsObject



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/mirah/jvm/types/intrinsics.rb', line 297

def add_intrinsics
  super
  add_method('+', [String], String) do |compiler, call, expression|
    if expression
      java_method('concat', String).call(compiler, call, expression)
    end
  end
  add_method('+', [Boolean], String) do |compiler, call, expression|
    if expression
      call.target.compile(compiler, true)
      call.parameters[0].compile(compiler, true)
      compiler.method.invokestatic String, "valueOf", [String, Boolean]
      compiler.method.invokevirtual String, "concat", [String, String]
    end
  end
  add_method('+', [Char], String) do |compiler, call, expression|
    if expression
      call.target.compile(compiler, true)
      call.parameters[0].compile(compiler, true)
      compiler.method.invokestatic String, "valueOf", [String, Char]
      compiler.method.invokevirtual String, "concat", [String, String]
    end
  end
  add_method('+', [Int], String) do |compiler, call, expression|
    if expression
      call.target.compile(compiler, true)
      call.parameters[0].compile(compiler, true)
      compiler.method.invokestatic String, "valueOf", [String, Int]
      compiler.method.invokevirtual String, "concat", [String, String]
    end
  end
  add_method('+', [Long], String) do |compiler, call, expression|
    if expression
      call.target.compile(compiler, true)
      call.parameters[0].compile(compiler, true)
      compiler.method.invokestatic String, "valueOf", [String, Long]
      compiler.method.invokevirtual String, "concat", [String, String]
    end
  end
  add_method('+', [Float], String) do |compiler, call, expression|
    if expression
      call.target.compile(compiler, true)
      call.parameters[0].compile(compiler, true)
      compiler.method.invokestatic String, "valueOf", [String, Float]
      compiler.method.invokevirtual String, "concat", [String, String]
    end
  end
  add_method('+', [Double], String) do |compiler, call, expression|
    if expression
      call.target.compile(compiler, true)
      call.parameters[0].compile(compiler, true)
      compiler.method.invokestatic String, "valueOf", [String, Double]
      compiler.method.invokevirtual String, "concat", [String, String]
    end
  end
  add_method('[]', [Int], Char) do |compiler, call, expression|
    if expression
      call.target.compile(compiler, true)
      call.parameters[0].compile(compiler, true)
      compiler.method.invokevirtual String, "charAt", [Char, Int]
    end
  end
  add_method('[]', [Int, Int], String) do |compiler, call, expression|
    if expression
      call.target.compile(compiler, true)
      call.parameters[0].compile(compiler, true)
      compiler.method.dup
      call.parameters[1].compile(compiler, true)
      compiler.method.iadd
      compiler.method.invokevirtual String, "substring", [String, Int, Int]
    end
  end
end