Class: BoolVal
Overview
BoolVal: bool 値を扱うクラス
Instance Attribute Summary collapse
-
#val ⇒ Object
readonly
Returns the value of attribute val.
Instance Method Summary collapse
- #cast(type) ⇒ Object
-
#eq(val) ⇒ Object
val.
-
#initialize(val) ⇒ BoolVal
constructor
- @val
-
bool: true, false.
-
#lAND(val) ⇒ Object
&& val.
-
#lOR(val) ⇒ Object
|| val.
-
#neq(val) ⇒ Object
!= val.
-
#not ⇒ Object
! val.
- #to_b ⇒ Object
- #to_f ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
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) ⇒ BoolVal
- @val
-
bool: true, false
428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/tecsgen/core/value.rb', line 428 def initialize(val) super() if val == true || val == false @val = val elsif val.to_i != 0 @val = true else @val = false end # raise "No boolean val" if val != true && val != false end |
Instance Attribute Details
#val ⇒ Object (readonly)
Returns the value of attribute val.
511 512 513 |
# File 'lib/tecsgen/core/value.rb', line 511 def val @val end |
Instance Method Details
#cast(type) ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/tecsgen/core/value.rb', line 470 def cast(type) t = type.get_original_type # typedef の元を得る if @val val = 1 else val = 0 end if t.is_a? IntType return IntegerVal.new(val) elsif t.is_a? FloatType return FloatVal.new(val) elsif t.is_a? BoolType return self else cdl_error("V1016 bool value cannot cast to $1", type.class) return nil end end |
#eq(val) ⇒ Object
val
444 445 446 447 448 449 450 451 |
# File 'lib/tecsgen/core/value.rb', line 444 def eq(val) # == val if val.is_a? BoolVal return BoolVal.new(self.to_i == val.to_i) else cdl_error("V1014 comparing bool value with \'$1\'", val.class) return BoolVal.new(false) end end |
#lAND(val) ⇒ Object
&& val
462 463 464 |
# File 'lib/tecsgen/core/value.rb', line 462 def lAND(val) # && val BoolVal.new(self.to_b && val.to_b) end |
#lOR(val) ⇒ Object
|| val
466 467 468 |
# File 'lib/tecsgen/core/value.rb', line 466 def lOR(val) # || val BoolVal.new(self.to_b || val.to_b) end |
#neq(val) ⇒ Object
!= val
453 454 455 456 457 458 459 460 |
# File 'lib/tecsgen/core/value.rb', line 453 def neq(val) # != val if val.is_a? BoolVal return BoolVal.new(self.to_i != val.to_i) else cdl_error("V1015 comparing bool value with \'$1\'", val.class) return BoolVal.new(false) end end |
#not ⇒ Object
! val
440 441 442 |
# File 'lib/tecsgen/core/value.rb', line 440 def not # ! val BoolVal.new(!@val) end |
#to_b ⇒ Object
497 498 499 |
# File 'lib/tecsgen/core/value.rb', line 497 def to_b @val end |
#to_f ⇒ Object
506 507 508 509 |
# File 'lib/tecsgen/core/value.rb', line 506 def to_f return 0.0 if @val == false return 1.0 end |
#to_i ⇒ Object
501 502 503 504 |
# File 'lib/tecsgen/core/value.rb', line 501 def to_i return 0 if @val == false return 1 end |
#to_s ⇒ Object
489 490 491 492 493 494 495 |
# File 'lib/tecsgen/core/value.rb', line 489 def to_s if @val return "true" else return "false" end end |