Class: FloatType

Inherits:
Type show all
Defined in:
lib/tecsgen/core/types.rb

Direct Known Subclasses

CFloatType

Instance Method Summary collapse

Methods inherited from Type

#cast, #check_struct_tag, #clear_max, #equal?, #get_ID_str, #get_original_type, #has_pointer?, #has_sized_pointer?, #has_unsized_string?, #is_const?, #is_void?, #is_volatile?, #print_info, print_info_post, #print_info_post, reset_print_info, #set_qualifier, #set_scs

Methods inherited from Node

#cdl_error, #cdl_error2, #cdl_error3, #cdl_info, #cdl_info2, #cdl_warning, #cdl_warning2, #get_locale, #locale_str, #set_locale

Constructor Details

#initialize(bit_size) ⇒ FloatType

@bit_size

32, 64, (80), -32, -64, -128

[View source]

630
631
632
633
# File 'lib/tecsgen/core/types.rb', line 630

def initialize(bit_size)
  super()
  @bit_size = bit_size
end

Instance Method Details

#checkObject

意味的誤りがあれば、文字列を返す

[View source]

635
636
637
# File 'lib/tecsgen/core/types.rb', line 635

def check # 意味的誤りがあれば、文字列を返す
  nil
end

#check_init(locale, ident, initializer, kind, attribute = nil) ⇒ Object

mikan Float 型の C_EXP 対応 (generate.rb にも変更必要)

[View source]

640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File 'lib/tecsgen/core/types.rb', line 640

def check_init(locale, ident, initializer, kind, attribute = nil)
  # 型に対する初期値に誤りがあれば、エラー文字列を返す
  val = initializer
  if val.instance_of?(Expression)
    val = val.eval_const2(nil, attribute)
    # 評価の結果 C_EXP や Array となる可能性がある
  end

  if val.instance_of? Token
    # val が Token の場合 == の右辺が String だとエラーを起こす
    cdl_error2(locale, "T1018 $1: $2: not number", ident, val)
    return
  elsif val.instance_of? Array
    cdl_error2(locale, "T1020 $1: unsuitable initializer for scalar type", ident)
    return
  elsif val.instance_of? C_EXP
    return
  elsif val.nil?
    cdl_error2(locale, "T1019 $1: initializer is not constant", ident)
    return
  elsif !val.is_a?(IntegerVal) && !val.is_a?(FloatVal)
    cdl_error2(locale, "T1037 $1: not number", ident)
    return
  end
  # else
  #   cdl_error2( locale, "T1020 $1: unsuitable initializer for scalar type" , ident )
  #   return
  # end
  return
end

#get_bit_sizeObject

[View source]

693
694
695
# File 'lib/tecsgen/core/types.rb', line 693

def get_bit_size
  @bit_size
end

#get_type_strObject

[View source]

671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'lib/tecsgen/core/types.rb', line 671

def get_type_str
  str = super

  case @bit_size
  when 32
    str = "#{str}float32_t"
  when 64
    str = "#{str}double64_t"
  when -32
    str = "#{str}float"
  when -64
    str = "#{str}double"
  when -128
    str = "#{str}long double"
  end
  return str
end

#get_type_str_postObject

[View source]

689
690
691
# File 'lib/tecsgen/core/types.rb', line 689

def get_type_str_post
  ""
end

#show_tree(indent) ⇒ Object

[View source]

697
698
699
700
701
# File 'lib/tecsgen/core/types.rb', line 697

def show_tree(indent)
  indent.times { print "  " }
  puts "FloatType bit_size=#{@bit_size} qualifier=#{@qualifier} #{locale_str}"
  super(indent + 1)
end