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

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

Constant Summary

Constants included from Logging::Logged

Logging::Logged::VLEVELS

Instance Attribute Summary

Attributes inherited from Type

#inner_class, #name, #type_system

Instance Method Summary collapse

Methods inherited from Type

#abstract?, #add_compiled_macro, #add_enumerable_macros, #add_method, #add_method_listener, #aload, #ancestors_and_interfaces, #array?, #array_type, #assignableFrom, #assignable_from?, #astore, #basic_type, #compatible?, #component_type, #constructor, #declared_class_methods, #declared_constructors, #declared_instance_methods, #declared_intrinsics, #declared_macros, #dynamic?, #error?, #expand_each, #field_getter, #field_setter, #find_callable_macros, #find_callable_macros2, #find_callable_methods, #find_callable_methods2, #full_name, #generic, #generic?, #get_method, #include, #init_value, #initialize, #inner_class?, #inner_class_getter, #inspect, #interface?, #interfaces, #intrinsics, #isArray, #isBlock, #isError, #isGeneric, #isMeta, #is_parent, #iterable?, #java_method, #jvm_type, #load, #load_extensions, #macro, #macros, #matchesAnything, #meta, #meta?, #method_listeners, #method_updated, #newarray, #pop, #prefix, #primitive?, #read_macrodef_annotation, #return, #store, #superclass, #to_s, #type_parameters, #ungeneric, #unmeta, #void?, #wide?, #widen

Methods included from Logging::Logged

#error, #info, #log, #logger, #logger_name, #logging?, #vlog, #warning

Methods included from MethodLookup

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

Constructor Details

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

Instance Method Details

#add_intrinsicsObject



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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/mirah/jvm/types/intrinsics.rb', line 317

def add_intrinsics
  super
  string_type = @type_system.type(nil, 'java.lang.String')
  bool_type = @type_system.type(nil, 'boolean')
  int_type = @type_system.type(nil, 'int')
  long_type = @type_system.type(nil, 'long')
  char_type = @type_system.type(nil, 'char')
  float_type = @type_system.type(nil, 'float')
  double_type = @type_system.type(nil, 'double')
  add_method('+', [string_type], string_type) do |compiler, call, expression|
    if expression
      java_method('concat', string_type).call(compiler, call, expression)
    end
  end
  add_method('+', [bool_type], string_type) do |compiler, call, expression|
    if expression
      compiler.visit(call.target, true)
      compiler.visit(call.parameters(0), true)
      compiler.method.invokestatic string_type, "valueOf", [string_type, bool_type]
      compiler.method.invokevirtual string_type, "concat", [string_type, string_type]
    end
  end
  add_method('+', [char_type], string_type) do |compiler, call, expression|
    if expression
      compiler.visit(call.target, true)
      compiler.visit(call.parameters(0), true)
      compiler.method.invokestatic string_type, "valueOf", [string_type, char_type]
      compiler.method.invokevirtual string_type, "concat", [string_type, string_type]
    end
  end
  add_method('+', [int_type], string_type) do |compiler, call, expression|
    if expression
      compiler.visit(call.target, true)
      compiler.visit(call.parameters(0), true)
      compiler.method.invokestatic string_type, "valueOf", [string_type, int_type]
      compiler.method.invokevirtual string_type, "concat", [string_type, string_type]
    end
  end
  add_method('+', [long_type], string_type) do |compiler, call, expression|
    if expression
      compiler.visit(call.target, true)
      compiler.visit(call.parameters(0), true)
      compiler.method.invokestatic string_type, "valueOf", [string_type, long_type]
      compiler.method.invokevirtual string_type, "concat", [string_type, string_type]
    end
  end
  add_method('+', [float_type], string_type) do |compiler, call, expression|
    if expression
      compiler.visit(call.target, true)
      compiler.visit(call.parameters(0), true)
      compiler.method.invokestatic string_type, "valueOf", [string_type, float_type]
      compiler.method.invokevirtual string_type, "concat", [string_type, string_type]
    end
  end
  add_method('+', [double_type], string_type) do |compiler, call, expression|
    if expression
      compiler.visit(call.target, true)
      compiler.visit(call.parameters(0), true)
      compiler.method.invokestatic string_type, "valueOf", [string_type, double_type]
      compiler.method.invokevirtual string_type, "concat", [string_type, string_type]
    end
  end
  add_method('[]', [int_type], char_type) do |compiler, call, expression|
    if expression
      compiler.visit(call.target, true)
      compiler.visit(call.parameters(0), true)
      compiler.method.invokevirtual string_type, "charAt", [char_type, int_type]
    end
  end
  add_method('[]', [int_type, int_type], string_type) do |compiler, call, expression|
    if expression
      compiler.visit(call.target, true)
      compiler.visit(call.parameters(0), true)
      compiler.method.dup
      compiler.visit(call.parameters[1], true)
      compiler.method.iadd
      compiler.method.invokevirtual string_type, "substring", [string_type, int_type, int_type]
    end
  end
end