Class: PointerVal

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

Overview

Pointer 値 (IntegerVal の Pointer 版)

ポインタ値は、CDL で直接生成されることはない 整数値のキャスト演算により生成される

Instance Method Summary collapse

Methods inherited from BaseVal

#%, #&, #*, #+, #+@, #-, #-@, #/, #<, #<<, #<=, #>, #>=, #>>, #^, #eq, #lAND, #lOR, #neq, #not, #to_f, #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(int_val, ptr_type) ⇒ PointerVal

@ptr_type

PtrType: ポインタの指す先の型



176
177
178
179
180
# File 'lib/tecsgen/core/value.rb', line 176

def initialize(int_val, ptr_type)
  super()
  @int_val = int_val
  @ptr_type = ptr_type
end

Instance Method Details

#cast(type) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/tecsgen/core/value.rb', line 188

def cast(type)
  t = type.get_original_type # typedef の元を得る
  if t.is_a? IntType
    val = t.check_and_clip(@int_val, :IntType)
    return IntegerVal.new(val)
  elsif t.is_a? FloatType
    cdl_error("V1005 Cannot cast pointer to float")
    return FloatVal.new(@int_val)
  elsif t.is_a? PtrType
    return PointerVal.new(@int_val, type)
  else
    cdl_error("V1006 pointer value cannot cast to $1", type.class)
    return nil
  end
end

#get_typeObject

ポインタの指す先の型を得る

PointerVal 専用のメソッド



184
185
186
# File 'lib/tecsgen/core/value.rb', line 184

def get_type
  @ptr_type
end

#to_bObject



208
209
210
211
# File 'lib/tecsgen/core/value.rb', line 208

def to_b
  cdl_error("V1007 convert pointer value to bool")
  false
end

#to_iObject



213
214
215
216
# File 'lib/tecsgen/core/value.rb', line 213

def to_i
  cdl_error("V1008 convert pointer value to integer without cast")
  @val.to_i
end

#to_sObject



204
205
206
# File 'lib/tecsgen/core/value.rb', line 204

def to_s
  "(#{@ptr_type.get_type_str}#{@ptr_type.get_type_str_post})#{sprintf("0x%X", @int_val)}"
end