Class: StringVal

Inherits:
BaseVal show all
Defined in:
lib/tecsgen/core/value.rb

Overview

文字列リテラルを扱うクラス

Instance Method Summary collapse

Methods inherited from BaseVal

#%, #&, #*, #+, #+@, #-, #-@, #/, #<, #<<, #<=, #>, #>=, #>>, #^, #eq, #lAND, #lOR, #neq, #not, #to_b, #to_f, #to_i, #unsupport, #|, #~@

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(str, spec = :NORMAL) ⇒ StringVal

@specifier

Symbol: :WIDE, :NORMAL


621
622
623
624
625
# File 'lib/tecsgen/core/value.rb', line 621

def initialize(str, spec = :NORMAL)
  super()
  @str = str
  @specifier = spec # mikan L"str" wide 文字列未対応
end

Instance Method Details

#cast(type) ⇒ Object

string の cast はできない mikan ポインタ型への cast はできるべき


630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/tecsgen/core/value.rb', line 630

def cast(type)
  t = type.get_original_type # typedef の元を得る
  if t.is_a? IntType
    cdl_error("V1022 string cannot cast to integer")
  elsif t.is_a? FloatType
    cdl_error("V1023 string cannot cast to float")
  elsif t.is_a? PtrType
    cdl_error("V1024 string cannot cast to pointer")
  else
    cdl_error("V1025 string cannot cast to $1", type)
  end
end

#to_sObject


643
644
645
# File 'lib/tecsgen/core/value.rb', line 643

def to_s
  @str.to_s
end

#valObject


647
648
649
# File 'lib/tecsgen/core/value.rb', line 647

def val
  @str.to_s # Token で扱われていた名残 (val を取り出す)
end