Class: IntegerVal
Overview
Instance Method Summary
collapse
Methods inherited from BaseVal
#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(val, str = nil, sign = :SIGNED, size = :NORMAL) ⇒ IntegerVal
- @size
-
Symbol: :NORMAL | :SHORT | :LONG | :LONGLONG
226
227
228
229
230
231
232
|
# File 'lib/tecsgen/core/value.rb', line 226
def initialize(val, str = nil, sign = :SIGNED, size = :NORMAL)
super()
@val = val.to_i
@str = str
@sign = sign
@size = size
end
|
Instance Method Details
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# File 'lib/tecsgen/core/value.rb', line 276
def %(val)
if val.is_a? FloatVal
v2 = val.to_f if v2 == 0.0
cdl_error("V1011 % : divieded by zero")
return FloatVal.new(1.0)
end
return FloatVal.new(@val.to_f % v2)
else
v2 = val.to_i if v2 == 0
cdl_error("V1012 % : divieded by zero")
return IntegerVal.new(1)
end
return IntegerVal.new(@val % v2)
end
end
|
366
367
368
|
# File 'lib/tecsgen/core/value.rb', line 366
def &(val)
IntegerVal.new(@val & val.to_i)
end
|
250
251
252
253
254
255
256
|
# File 'lib/tecsgen/core/value.rb', line 250
def *(val)
if val.is_a? FloatVal
return FloatVal.new(@val.to_f * val.to_f)
else
return IntegerVal.new(@val * val.to_i)
end
end
|
294
295
296
297
298
299
300
|
# File 'lib/tecsgen/core/value.rb', line 294
def +(val)
if val.is_a? FloatVal
return FloatVal.new(@val.to_f + val.to_f)
else
return IntegerVal.new(@val + val.to_i)
end
end
|
242
243
244
|
# File 'lib/tecsgen/core/value.rb', line 242
def +@
self
end
|
302
303
304
305
306
307
308
|
# File 'lib/tecsgen/core/value.rb', line 302
def -(val)
if val.is_a? FloatVal
return FloatVal.new(@val.to_f - val.to_f)
else
return IntegerVal.new(@val - val.to_i)
end
end
|
238
239
240
|
# File 'lib/tecsgen/core/value.rb', line 238
def -@
IntegerVal.new(- @val)
end
|
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/tecsgen/core/value.rb', line 258
def /(val)
if val.is_a? FloatVal
v2 = val.to_f if v2 == 0.0
cdl_error("V1009 / : divieded by zero")
return FloatVal.new(1.0)
end
return FloatVal.new(@val.to_f / v2)
else
v2 = val.to_i if v2 == 0
cdl_error("V1010 / : divieded by zero")
return IntegerVal.new(1)
end
return IntegerVal.new(@val / v2)
end
end
|
326
327
328
329
330
331
332
|
# File 'lib/tecsgen/core/value.rb', line 326
def <(val)
if val.is_a? FloatVal
return BoolVal.new(@val.to_f < val.to_f)
else
return BoolVal.new(@val < val.to_i)
end
end
|
310
311
312
|
# File 'lib/tecsgen/core/value.rb', line 310
def <<(val)
return IntegerVal.new(@val << val.to_i)
end
|
342
343
344
345
346
347
348
|
# File 'lib/tecsgen/core/value.rb', line 342
def <=(val)
if val.is_a? FloatVal
return BoolVal.new(@val.to_f <= val.to_f)
else
return BoolVal.new(@val <= val.to_i)
end
end
|
318
319
320
321
322
323
324
|
# File 'lib/tecsgen/core/value.rb', line 318
def >(val)
if val.is_a? FloatVal
return BoolVal.new(@val.to_f > val.to_f)
else
return BoolVal.new(@val > val.to_i)
end
end
|
334
335
336
337
338
339
340
|
# File 'lib/tecsgen/core/value.rb', line 334
def >=(val)
if val.is_a? FloatVal
return BoolVal.new(@val.to_f >= val.to_f)
else
return BoolVal.new(@val >= val.to_i)
end
end
|
314
315
316
|
# File 'lib/tecsgen/core/value.rb', line 314
def >>(val)
return IntegerVal.new(@val >> val.to_i)
end
|
370
371
372
|
# File 'lib/tecsgen/core/value.rb', line 370
def ^(val)
IntegerVal.new(@val ^ val.to_i)
end
|
#cast(type) ⇒ Object
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
# File 'lib/tecsgen/core/value.rb', line 386
def cast(type)
t = type.get_original_type if t.is_a? IntType
val = t.check_and_clip(@val, :IntType)
return IntegerVal.new(val)
elsif t.is_a? FloatType
return FloatVal.new(@val)
elsif t.is_a? PtrType
return PointerVal.new(@val, type)
elsif t.is_a? BoolType
return BoolVal.new(@val.to_b)
else
cdl_error("V1013 integer value cannot cast to $1", type.class)
return nil
end
end
|
350
351
352
353
354
355
356
|
# File 'lib/tecsgen/core/value.rb', line 350
def eq(val) if val.is_a? FloatVal
return BoolVal.new(@val.to_f == val.to_f)
else
return BoolVal.new(@val == val.to_i)
end
end
|
#lAND(val) ⇒ Object
378
379
380
|
# File 'lib/tecsgen/core/value.rb', line 378
def lAND(val) BoolVal.new(self.to_b && val.to_b)
end
|
382
383
384
|
# File 'lib/tecsgen/core/value.rb', line 382
def lOR(val) BoolVal.new(self.to_b || val.to_b)
end
|
358
359
360
361
362
363
364
|
# File 'lib/tecsgen/core/value.rb', line 358
def neq(val) if val.is_a? FloatVal
return BoolVal.new(@val.to_f != val.to_f)
else
return BoolVal.new(@val != val.to_i)
end
end
|
246
247
248
|
# File 'lib/tecsgen/core/value.rb', line 246
def not BoolVal.new(self.to_b)
end
|
411
412
413
|
# File 'lib/tecsgen/core/value.rb', line 411
def to_b
@val != 0
end
|
419
420
421
|
# File 'lib/tecsgen/core/value.rb', line 419
def to_f
@val.to_f
end
|
415
416
417
|
# File 'lib/tecsgen/core/value.rb', line 415
def to_i
@val
end
|
403
404
405
406
407
408
409
|
# File 'lib/tecsgen/core/value.rb', line 403
def to_s
if @str
@str
else
@val.to_s
end
end
|
374
375
376
|
# File 'lib/tecsgen/core/value.rb', line 374
def |(val)
IntegerVal.new(@val | val.to_i)
end
|
234
235
236
|
# File 'lib/tecsgen/core/value.rb', line 234
def ~@
IntegerVal.new(~ @val)
end
|