Class: AdLint::Cc1::CompositeValue

Inherits:
SingleValue show all
Defined in:
lib/adlint/cc1/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SingleValue

#multiple?, #test_may_be_undefined, #test_must_be_undefined, #to_single_value

Methods inherited from Value

#multiple?, #test_may_be_undefined, #test_must_be_undefined, #to_single_value

Methods included from BuggyValueSampler

#unique_sample

Constructor Details

#initialize(vals) ⇒ CompositeValue



1390
1391
1392
# File 'lib/adlint/cc1/value.rb', line 1390

def initialize(vals)
  @values = vals
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



1394
1395
1396
# File 'lib/adlint/cc1/value.rb', line 1394

def values
  @values
end

Instance Method Details

#!Object



1574
1575
1576
1577
1578
# File 'lib/adlint/cc1/value.rb', line 1574

def !
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  scalar_value_of_false # NOTREACHED
end

#!=(rhs_val) ⇒ Object



1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
# File 'lib/adlint/cc1/value.rb', line 1634

def !=(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  case rhs_sval = rhs_val.to_single_value
  when CompositeValue
    if @values.size == rhs_sval.values.size
      zipped = @values.zip(rhs_sval.values)
      zipped.reduce(scalar_value_of_nil) do |rslt_val, (lhs, rhs)|
        rslt_val.single_value_unified_with(lhs != rhs)
      end
    else
      scalar_value_of_false
    end
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#%(rhs_val) ⇒ Object



1538
1539
1540
1541
1542
# File 'lib/adlint/cc1/value.rb', line 1538

def %(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#&(rhs_val) ⇒ Object



1544
1545
1546
1547
1548
# File 'lib/adlint/cc1/value.rb', line 1544

def &(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#*(rhs_val) ⇒ Object



1526
1527
1528
1529
1530
# File 'lib/adlint/cc1/value.rb', line 1526

def *(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#+(rhs_val) ⇒ Object



1514
1515
1516
1517
1518
# File 'lib/adlint/cc1/value.rb', line 1514

def +(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#+@Object



1502
1503
1504
1505
1506
# File 'lib/adlint/cc1/value.rb', line 1502

def +@
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#-(rhs_val) ⇒ Object



1520
1521
1522
1523
1524
# File 'lib/adlint/cc1/value.rb', line 1520

def -(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#-@Object



1508
1509
1510
1511
1512
# File 'lib/adlint/cc1/value.rb', line 1508

def -@
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#/(rhs_val) ⇒ Object



1532
1533
1534
1535
1536
# File 'lib/adlint/cc1/value.rb', line 1532

def /(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#<(rhs_val) ⇒ Object



1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
# File 'lib/adlint/cc1/value.rb', line 1580

def <(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  case rhs_sval = rhs_val.to_single_value
  when CompositeValue
    if @values.size == rhs_sval.values.size
      zipped = @values.zip(rhs_sval.values)
      zipped.reduce(scalar_value_of_nil) do |rslt_val, (lhs, rhs)|
        rslt_val.single_value_unified_with(lhs < rhs)
      end
    else
      scalar_value_of_false
    end
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#<<(rhs_val) ⇒ Object



1562
1563
1564
1565
1566
# File 'lib/adlint/cc1/value.rb', line 1562

def <<(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#<=(rhs_val) ⇒ Object



1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
# File 'lib/adlint/cc1/value.rb', line 1652

def <=(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  case rhs_sval = rhs_val.to_single_value
  when CompositeValue
    if @values.size == rhs_sval.values.size
      zipped = @values.zip(rhs_sval.values)
      zipped.reduce(scalar_value_of_nil) do |rslt_val, (lhs, rhs)|
        rslt_val.single_value_unified_with(lhs <= rhs)
      end
    else
      scalar_value_of_false
    end
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#==(rhs_val) ⇒ Object



1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
# File 'lib/adlint/cc1/value.rb', line 1616

def ==(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  case rhs_sval = rhs_val.to_single_value
  when CompositeValue
    if @values.size == rhs_sval.values.size
      zipped = @values.zip(rhs_sval.values)
      zipped.reduce(scalar_value_of_nil) do |rslt_val, (lhs, rhs)|
        rslt_val.single_value_unified_with(lhs == rhs)
      end
    else
      scalar_value_of_false
    end
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#>(rhs_val) ⇒ Object



1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
# File 'lib/adlint/cc1/value.rb', line 1598

def >(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  case rhs_sval = rhs_val.to_single_value
  when CompositeValue
    if @values.size == rhs_sval.values.size
      zipped = @values.zip(rhs_sval.values)
      zipped.reduce(scalar_value_of_nil) do |rslt_val, (lhs, rhs)|
        rslt_val.single_value_unified_with(lhs > rhs)
      end
    else
      scalar_value_of_false
    end
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#>=(rhs_val) ⇒ Object



1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
# File 'lib/adlint/cc1/value.rb', line 1670

def >=(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  case rhs_sval = rhs_val.to_single_value
  when CompositeValue
    if @values.size == rhs_sval.values.size
      zipped = @values.zip(rhs_sval.values)
      zipped.reduce(scalar_value_of_nil) do |rslt_val, (lhs, rhs)|
        rslt_val.single_value_unified_with(lhs >= rhs)
      end
    else
      scalar_value_of_false
    end
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#>>(rhs_val) ⇒ Object



1568
1569
1570
1571
1572
# File 'lib/adlint/cc1/value.rb', line 1568

def >>(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#^(rhs_val) ⇒ Object



1556
1557
1558
1559
1560
# File 'lib/adlint/cc1/value.rb', line 1556

def ^(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#ambiguous?Boolean



1433
1434
1435
# File 'lib/adlint/cc1/value.rb', line 1433

def ambiguous?
  @values.empty? ? false : @values.all? { |val| val.ambiguous? }
end

#array?Boolean



1400
1401
1402
# File 'lib/adlint/cc1/value.rb', line 1400

def array?
  false
end

#coerce_to(type) ⇒ Object



1829
1830
1831
# File 'lib/adlint/cc1/value.rb', line 1829

def coerce_to(type)
  type.coerce_composite_value(self)
end

#composite?Boolean



1404
1405
1406
# File 'lib/adlint/cc1/value.rb', line 1404

def composite?
  true
end

#contain?(val) ⇒ Boolean



1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
# File 'lib/adlint/cc1/value.rb', line 1416

def contain?(val)
  case sval = val.to_single_value
  when CompositeValue
    if @values.size == sval.values.size
      @values.zip(sval.values).all? { |lhs, rhs| lhs.contain?(rhs) }
    else
      false
    end
  else
    false
  end
end

#definite?Boolean



1412
1413
1414
# File 'lib/adlint/cc1/value.rb', line 1412

def definite?
  @values.empty? ? true : @values.all? { |val| val.definite? }
end

#dupObject



1850
1851
1852
# File 'lib/adlint/cc1/value.rb', line 1850

def dup
  CompositeValue.new(@values.map { |val| val.dup })
end

#eql?(rhs_val) ⇒ Boolean



1842
1843
1844
# File 'lib/adlint/cc1/value.rb', line 1842

def eql?(rhs_val)
  rhs_val.kind_of?(CompositeValue) && @values.eql?(rhs_val.values)
end

#exist?Boolean



1408
1409
1410
# File 'lib/adlint/cc1/value.rb', line 1408

def exist?
  @values.empty? ? true : @values.all? { |val| val.exist? }
end

#hashObject



1846
1847
1848
# File 'lib/adlint/cc1/value.rb', line 1846

def hash
  @values.hash
end

#invert_domain!Object



1480
1481
1482
# File 'lib/adlint/cc1/value.rb', line 1480

def invert_domain!
  @values.each { |val| val.invert_domain! }
end

#logical_and(rhs_val) ⇒ Object



1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
# File 'lib/adlint/cc1/value.rb', line 1688

def logical_and(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  case rhs_sval = rhs_val.to_single_value
  when CompositeValue
    if @values.size == rhs_sval.values.size
      zipped = @values.zip(rhs_sval.values)
      zipped.reduce(scalar_value_of_nil) do |rslt_val, (lhs, rhs)|
        rslt_val.single_value_unified_with(lhs.logical_and(rhs))
      end
    else
      scalar_value_of_false
    end
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#logical_or(rhs_val) ⇒ Object



1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
# File 'lib/adlint/cc1/value.rb', line 1706

def logical_or(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  case rhs_sval = rhs_val.to_single_value
  when CompositeValue
    if @values.size == rhs_sval.values.size
      zipped = @values.zip(rhs_sval.values)
      zipped.reduce(scalar_value_of_nil) do |rslt_val, (lhs, rhs)|
        rslt_val.single_value_unified_with(lhs.logical_or(rhs))
      end
    else
      scalar_value_of_false
    end
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#narrow_domain!(op, ope_val) ⇒ Object



1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
# File 'lib/adlint/cc1/value.rb', line 1448

def narrow_domain!(op, ope_val)
  case ope_sval = ope_val.to_single_value
  when CompositeValue
    @values.zip(ope_sval.values).each do |lhs, rhs|
      if rhs
        lhs.narrow_domain!(op, rhs)
      else
        next
      end
    end
  else
    raise TypeError,
      "cannot narrow composite value domain with non-composite."
  end
end

#overwrite!(val, tag) ⇒ Object



1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
# File 'lib/adlint/cc1/value.rb', line 1437

def overwrite!(val, tag)
  case sval = val.to_single_value
  when CompositeValue
    @values.zip(sval.values).each do |lhs, rhs|
      rhs && lhs.overwrite!(rhs, tag)
    end
  else
    raise TypeError, "cannot overwrite composite with non-composite."
  end
end

#scalar?Boolean



1396
1397
1398
# File 'lib/adlint/cc1/value.rb', line 1396

def scalar?
  false
end

#single_value_unified_with(rhs_val) ⇒ Object



1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
# File 'lib/adlint/cc1/value.rb', line 1484

def single_value_unified_with(rhs_val)
  case rhs_sval = rhs_val.to_single_value
  when CompositeValue
    CompositeValue.new(
      @values.zip(rhs_sval.values).map { |lhs, rhs|
        lhs.single_value_unified_with(rhs)
      })
  else
    raise TypeError, "cannot unify composite value with non-composite."
  end
end

#test_may_be_equal_to(val) ⇒ Object



1733
1734
1735
1736
1737
1738
1739
1740
# File 'lib/adlint/cc1/value.rb', line 1733

def test_may_be_equal_to(val)
  case sval = val.to_single_value
  when CompositeValue
    TrivialValueTest.new((self == sval).test_may_be_true.result)
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#test_may_be_falseObject



1823
1824
1825
1826
1827
# File 'lib/adlint/cc1/value.rb', line 1823

def test_may_be_false
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  TrivialValueTest.new(@values.all? { |val| val.test_may_be_false.result })
end

#test_may_be_greater_than(val) ⇒ Object



1787
1788
1789
1790
1791
1792
1793
1794
# File 'lib/adlint/cc1/value.rb', line 1787

def test_may_be_greater_than(val)
  case sval = val.to_single_value
  when CompositeValue
    TrivialValueTest.new((self > sval).test_may_be_true.result)
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#test_may_be_less_than(val) ⇒ Object



1769
1770
1771
1772
1773
1774
1775
1776
# File 'lib/adlint/cc1/value.rb', line 1769

def test_may_be_less_than(val)
  case sval = val.to_single_value
  when CompositeValue
    TrivialValueTest.new((self < sval).test_may_be_true.result)
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#test_may_be_nullObject



1800
1801
1802
# File 'lib/adlint/cc1/value.rb', line 1800

def test_may_be_null
  TrivialValueTest.new(@values.all? { |val| val.test_may_be_null.result })
end

#test_may_be_trueObject



1810
1811
1812
1813
1814
# File 'lib/adlint/cc1/value.rb', line 1810

def test_may_be_true
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  TrivialValueTest.new(@values.all? { |val| val.test_may_be_true.result })
end

#test_may_not_be_equal_to(val) ⇒ Object



1751
1752
1753
1754
1755
1756
1757
1758
# File 'lib/adlint/cc1/value.rb', line 1751

def test_may_not_be_equal_to(val)
  case sval = val.to_single_value
  when CompositeValue
    TrivialValueTest.new((self != sval).test_may_be_true.result)
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#test_must_be_equal_to(val) ⇒ Object



1724
1725
1726
1727
1728
1729
1730
1731
# File 'lib/adlint/cc1/value.rb', line 1724

def test_must_be_equal_to(val)
  case sval = val.to_single_value
  when CompositeValue
    TrivialValueTest.new((self == sval).test_must_be_true.result)
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#test_must_be_falseObject



1816
1817
1818
1819
1820
1821
# File 'lib/adlint/cc1/value.rb', line 1816

def test_must_be_false
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  TrivialValueTest.new(
    @values.all? { |val| val.test_must_be_false.result })
end

#test_must_be_greater_than(val) ⇒ Object



1778
1779
1780
1781
1782
1783
1784
1785
# File 'lib/adlint/cc1/value.rb', line 1778

def test_must_be_greater_than(val)
  case sval = val.to_single_value
  when CompositeValue
    TrivialValueTest.new((self > sval).test_must_be_true.result)
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#test_must_be_less_than(val) ⇒ Object



1760
1761
1762
1763
1764
1765
1766
1767
# File 'lib/adlint/cc1/value.rb', line 1760

def test_must_be_less_than(val)
  case sval = val.to_single_value
  when CompositeValue
    TrivialValueTest.new((self < sval).test_must_be_true.result)
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#test_must_be_nullObject



1796
1797
1798
# File 'lib/adlint/cc1/value.rb', line 1796

def test_must_be_null
  TrivialValueTest.new(@values.all? { |val| val.test_must_be_null.result })
end

#test_must_be_trueObject



1804
1805
1806
1807
1808
# File 'lib/adlint/cc1/value.rb', line 1804

def test_must_be_true
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  TrivialValueTest.new(@values.all? { |val| val.test_must_be_true.result })
end

#test_must_not_be_equal_to(val) ⇒ Object



1742
1743
1744
1745
1746
1747
1748
1749
# File 'lib/adlint/cc1/value.rb', line 1742

def test_must_not_be_equal_to(val)
  case sval = val.to_single_value
  when CompositeValue
    TrivialValueTest.new((self != sval).test_must_be_true.result)
  else
    raise TypeError, "comparison between composite and non-composite."
  end
end

#to_defined_valueObject



1838
1839
1840
# File 'lib/adlint/cc1/value.rb', line 1838

def to_defined_value
  CompositeValue.new(@values.map { |val| val.to_defined_value })
end

#to_enumObject



1833
1834
1835
1836
# File 'lib/adlint/cc1/value.rb', line 1833

def to_enum
  # FIXME: This method generates only one of sample values.
  @values.map { |val| val.to_enum.first }
end

#undefined?Boolean



1429
1430
1431
# File 'lib/adlint/cc1/value.rb', line 1429

def undefined?
  @values.empty? ? false : @values.all? { |val| val.undefined? }
end

#widen_domain!(op, ope_val) ⇒ Object



1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
# File 'lib/adlint/cc1/value.rb', line 1464

def widen_domain!(op, ope_val)
  case ope_sval = ope_val.to_single_value
  when CompositeValue
    @values.zip(ope_sval.values).each do |lhs, rhs|
      if rhs
        lhs.widen_domain!(op, rhs)
      else
        next
      end
    end
  else
    raise TypeError,
      "cannot widen composite value domain with non-composite."
  end
end

#|(rhs_val) ⇒ Object



1550
1551
1552
1553
1554
# File 'lib/adlint/cc1/value.rb', line 1550

def |(rhs_val)
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end

#~Object



1496
1497
1498
1499
1500
# File 'lib/adlint/cc1/value.rb', line 1496

def ~
  # NOTE: A composite variable cannot appear in expressions except the
  #       primary-expression(object-specifier followed by `.').
  dup # NOTREACHED
end