adlint 2.4.0 → 2.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +63 -0
- data/MANIFEST +1 -0
- data/NEWS +12 -4
- data/etc/mesg.d/c_builtin/en_US/messages.yml +1 -1
- data/etc/mesg.d/c_builtin/ja_JP/messages.yml +1 -1
- data/etc/mesg.d/core/en_US/messages.yml +1 -1
- data/etc/mesg.d/core/ja_JP/messages.yml +1 -1
- data/features/code_check/W0635.feature +57 -0
- data/features/code_check/W0644.feature +4 -0
- data/features/code_check/W1071.feature +1 -1
- data/features/code_check/W1074.feature +5 -5
- data/lib/adlint/c/branch.rb +1 -1
- data/lib/adlint/c/builtin.rb +1 -1
- data/lib/adlint/c/ctrlexpr.rb +4 -2
- data/lib/adlint/c/format.rb +12 -11
- data/lib/adlint/c/interp.rb +114 -114
- data/lib/adlint/c/object.rb +6 -22
- data/lib/adlint/c/operator.rb +4 -0
- data/lib/adlint/c/option.rb +1 -1
- data/lib/adlint/c/parser.rb +1 -1
- data/lib/adlint/c/parser.y +1 -1
- data/lib/adlint/c/syntax.rb +566 -31
- data/lib/adlint/c/type.rb +21 -1
- data/lib/adlint/c/value.rb +0 -68
- data/lib/adlint/cpp/eval.rb +2 -2
- data/lib/adlint/version.rb +2 -2
- data/share/doc/developers_guide_ja.html +3 -3
- data/share/doc/developers_guide_ja.texi +1 -1
- data/share/doc/users_guide_en.html +10 -10
- data/share/doc/users_guide_en.texi +8 -8
- data/share/doc/users_guide_ja.html +10 -10
- data/share/doc/users_guide_ja.texi +8 -8
- data/spec/adlint/c/type_spec.rb +104 -5
- metadata +3 -2
data/lib/adlint/c/syntax.rb
CHANGED
@@ -32,6 +32,7 @@
|
|
32
32
|
require "adlint/symbol"
|
33
33
|
require "adlint/util"
|
34
34
|
require "adlint/c/seqp"
|
35
|
+
require "adlint/c/operator"
|
35
36
|
|
36
37
|
module AdLint #:nodoc:
|
37
38
|
module C #:nodoc:
|
@@ -434,9 +435,9 @@ module C #:nodoc:
|
|
434
435
|
end
|
435
436
|
|
436
437
|
def constant?(enumerator_table)
|
437
|
-
object_specifiers.all?
|
438
|
+
object_specifiers.all? do |object_specifier|
|
438
439
|
enumerator_table.lookup(object_specifier.identifier.value)
|
439
|
-
|
440
|
+
end
|
440
441
|
end
|
441
442
|
|
442
443
|
def logical?
|
@@ -457,9 +458,25 @@ module C #:nodoc:
|
|
457
458
|
}.object_specifiers
|
458
459
|
end
|
459
460
|
|
461
|
+
def to_normalized_logical(parent_expression = nil)
|
462
|
+
subclass_responsibility
|
463
|
+
end
|
464
|
+
|
465
|
+
def to_complemental_logical
|
466
|
+
# NOTE: This method must be invoked on a normalized expression.
|
467
|
+
subclass_responsibility
|
468
|
+
end
|
469
|
+
|
460
470
|
def to_s
|
461
471
|
subclass_responsibility
|
462
472
|
end
|
473
|
+
|
474
|
+
private
|
475
|
+
def create_normalized_logical_of(expression)
|
476
|
+
EqualityExpression.new(Token.new("!=", "!=", expression.location),
|
477
|
+
GroupedExpression.new(expression),
|
478
|
+
ConstantSpecifier.of_zero(expression.location))
|
479
|
+
end
|
463
480
|
end
|
464
481
|
|
465
482
|
class ErrorExpression < Expression
|
@@ -488,6 +505,14 @@ module C #:nodoc:
|
|
488
505
|
false
|
489
506
|
end
|
490
507
|
|
508
|
+
def to_normalized_logical(parent_expression = nil)
|
509
|
+
self
|
510
|
+
end
|
511
|
+
|
512
|
+
def to_complemental_logical
|
513
|
+
self
|
514
|
+
end
|
515
|
+
|
491
516
|
def to_s
|
492
517
|
@error_token.value
|
493
518
|
end
|
@@ -528,6 +553,19 @@ module C #:nodoc:
|
|
528
553
|
false
|
529
554
|
end
|
530
555
|
|
556
|
+
def to_normalized_logical(parent_expression = nil)
|
557
|
+
case parent_expression
|
558
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
559
|
+
create_normalized_logical_of(self)
|
560
|
+
else
|
561
|
+
self
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
def to_complemental_logical
|
566
|
+
self
|
567
|
+
end
|
568
|
+
|
531
569
|
def to_s
|
532
570
|
@identifier.value
|
533
571
|
end
|
@@ -539,6 +577,10 @@ module C #:nodoc:
|
|
539
577
|
end
|
540
578
|
|
541
579
|
class ConstantSpecifier < PrimaryExpression
|
580
|
+
def self.of_zero(location = nil)
|
581
|
+
self.new(Token.new(:CONSTANT, "0", location || Location.new))
|
582
|
+
end
|
583
|
+
|
542
584
|
def initialize(constant)
|
543
585
|
super()
|
544
586
|
@constant = constant
|
@@ -578,6 +620,19 @@ module C #:nodoc:
|
|
578
620
|
false
|
579
621
|
end
|
580
622
|
|
623
|
+
def to_normalized_logical(parent_expression = nil)
|
624
|
+
case parent_expression
|
625
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
626
|
+
create_normalized_logical_of(self)
|
627
|
+
else
|
628
|
+
self
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
def to_complemental_logical
|
633
|
+
self
|
634
|
+
end
|
635
|
+
|
581
636
|
def to_s
|
582
637
|
@constant.value
|
583
638
|
end
|
@@ -620,6 +675,19 @@ module C #:nodoc:
|
|
620
675
|
false
|
621
676
|
end
|
622
677
|
|
678
|
+
def to_normalized_logical(parent_expression = nil)
|
679
|
+
case parent_expression
|
680
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
681
|
+
create_normalized_logical_of(self)
|
682
|
+
else
|
683
|
+
self
|
684
|
+
end
|
685
|
+
end
|
686
|
+
|
687
|
+
def to_complemental_logical
|
688
|
+
self
|
689
|
+
end
|
690
|
+
|
623
691
|
def to_s
|
624
692
|
@literal.value
|
625
693
|
end
|
@@ -658,6 +726,19 @@ module C #:nodoc:
|
|
658
726
|
false
|
659
727
|
end
|
660
728
|
|
729
|
+
def to_normalized_logical(parent_expression = nil)
|
730
|
+
case parent_expression
|
731
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
732
|
+
create_normalized_logical_of(self)
|
733
|
+
else
|
734
|
+
self
|
735
|
+
end
|
736
|
+
end
|
737
|
+
|
738
|
+
def to_complemental_logical
|
739
|
+
self
|
740
|
+
end
|
741
|
+
|
661
742
|
def to_s
|
662
743
|
@token.value
|
663
744
|
end
|
@@ -672,6 +753,8 @@ module C #:nodoc:
|
|
672
753
|
def initialize(expression)
|
673
754
|
super()
|
674
755
|
@expression = expression
|
756
|
+
self.head_token = expression.head_token
|
757
|
+
self.tail_token = expression.tail_token
|
675
758
|
end
|
676
759
|
|
677
760
|
attr_reader :expression
|
@@ -696,6 +779,20 @@ module C #:nodoc:
|
|
696
779
|
@expression.bitwise?
|
697
780
|
end
|
698
781
|
|
782
|
+
def to_normalized_logical(parent_expression = nil)
|
783
|
+
case parent_expression
|
784
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
785
|
+
GroupedExpression.new(
|
786
|
+
@expression.to_normalized_logical(parent_expression))
|
787
|
+
else
|
788
|
+
self
|
789
|
+
end
|
790
|
+
end
|
791
|
+
|
792
|
+
def to_complemental_logical
|
793
|
+
GroupedExpression.new(@expression.to_complemental_logical)
|
794
|
+
end
|
795
|
+
|
699
796
|
def to_s
|
700
797
|
"(#{expression.to_s})"
|
701
798
|
end
|
@@ -744,6 +841,19 @@ module C #:nodoc:
|
|
744
841
|
false
|
745
842
|
end
|
746
843
|
|
844
|
+
def to_normalized_logical(parent_expression = nil)
|
845
|
+
case parent_expression
|
846
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
847
|
+
create_normalized_logical_of(self)
|
848
|
+
else
|
849
|
+
self
|
850
|
+
end
|
851
|
+
end
|
852
|
+
|
853
|
+
def to_complemental_logical
|
854
|
+
self
|
855
|
+
end
|
856
|
+
|
747
857
|
def to_s
|
748
858
|
"#{@expression.to_s}[#{@array_subscript.to_s}]"
|
749
859
|
end
|
@@ -781,6 +891,19 @@ module C #:nodoc:
|
|
781
891
|
false
|
782
892
|
end
|
783
893
|
|
894
|
+
def to_normalized_logical(parent_expression = nil)
|
895
|
+
case parent_expression
|
896
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
897
|
+
create_normalized_logical_of(self)
|
898
|
+
else
|
899
|
+
self
|
900
|
+
end
|
901
|
+
end
|
902
|
+
|
903
|
+
def to_complemental_logical
|
904
|
+
self
|
905
|
+
end
|
906
|
+
|
784
907
|
def to_s
|
785
908
|
"#{@expression.to_s}(" +
|
786
909
|
@argument_expressions.map { |expr| expr.to_s }.join(",") + ")"
|
@@ -819,6 +942,19 @@ module C #:nodoc:
|
|
819
942
|
false
|
820
943
|
end
|
821
944
|
|
945
|
+
def to_normalized_logical(parent_expression = nil)
|
946
|
+
case parent_expression
|
947
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
948
|
+
create_normalized_logical_of(self)
|
949
|
+
else
|
950
|
+
self
|
951
|
+
end
|
952
|
+
end
|
953
|
+
|
954
|
+
def to_complemental_logical
|
955
|
+
self
|
956
|
+
end
|
957
|
+
|
822
958
|
def to_s
|
823
959
|
"#{@expression.to_s}.#{@identifier.value}"
|
824
960
|
end
|
@@ -855,6 +991,19 @@ module C #:nodoc:
|
|
855
991
|
false
|
856
992
|
end
|
857
993
|
|
994
|
+
def to_normalized_logical(parent_expression = nil)
|
995
|
+
case parent_expression
|
996
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
997
|
+
create_normalized_logical_of(self)
|
998
|
+
else
|
999
|
+
self
|
1000
|
+
end
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
def to_complemental_logical
|
1004
|
+
self
|
1005
|
+
end
|
1006
|
+
|
858
1007
|
def to_s
|
859
1008
|
"#{@expression.to_s}->#{@identifier.value}"
|
860
1009
|
end
|
@@ -891,6 +1040,19 @@ module C #:nodoc:
|
|
891
1040
|
false
|
892
1041
|
end
|
893
1042
|
|
1043
|
+
def to_normalized_logical(parent_expression = nil)
|
1044
|
+
case parent_expression
|
1045
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1046
|
+
create_normalized_logical_of(self)
|
1047
|
+
else
|
1048
|
+
self
|
1049
|
+
end
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
def to_complemental_logical
|
1053
|
+
self
|
1054
|
+
end
|
1055
|
+
|
894
1056
|
def to_s
|
895
1057
|
"#{@expression.to_s}.#{@constant.value}"
|
896
1058
|
end
|
@@ -927,6 +1089,19 @@ module C #:nodoc:
|
|
927
1089
|
false
|
928
1090
|
end
|
929
1091
|
|
1092
|
+
def to_normalized_logical(parent_expression = nil)
|
1093
|
+
case parent_expression
|
1094
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1095
|
+
create_normalized_logical_of(self)
|
1096
|
+
else
|
1097
|
+
self
|
1098
|
+
end
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
def to_complemental_logical
|
1102
|
+
self
|
1103
|
+
end
|
1104
|
+
|
930
1105
|
def to_s
|
931
1106
|
"#{@expression.to_s}->#{@constant.value}"
|
932
1107
|
end
|
@@ -961,6 +1136,19 @@ module C #:nodoc:
|
|
961
1136
|
false
|
962
1137
|
end
|
963
1138
|
|
1139
|
+
def to_normalized_logical(parent_expression = nil)
|
1140
|
+
case parent_expression
|
1141
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1142
|
+
create_normalized_logical_of(self)
|
1143
|
+
else
|
1144
|
+
self
|
1145
|
+
end
|
1146
|
+
end
|
1147
|
+
|
1148
|
+
def to_complemental_logical
|
1149
|
+
self
|
1150
|
+
end
|
1151
|
+
|
964
1152
|
def to_s
|
965
1153
|
"#{@operand.to_s}++"
|
966
1154
|
end
|
@@ -995,6 +1183,19 @@ module C #:nodoc:
|
|
995
1183
|
false
|
996
1184
|
end
|
997
1185
|
|
1186
|
+
def to_normalized_logical(parent_expression = nil)
|
1187
|
+
case parent_expression
|
1188
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1189
|
+
create_normalized_logical_of(self)
|
1190
|
+
else
|
1191
|
+
self
|
1192
|
+
end
|
1193
|
+
end
|
1194
|
+
|
1195
|
+
def to_complemental_logical
|
1196
|
+
self
|
1197
|
+
end
|
1198
|
+
|
998
1199
|
def to_s
|
999
1200
|
"#{@operand.to_s}--"
|
1000
1201
|
end
|
@@ -1031,6 +1232,19 @@ module C #:nodoc:
|
|
1031
1232
|
false
|
1032
1233
|
end
|
1033
1234
|
|
1235
|
+
def to_normalized_logical(parent_expression = nil)
|
1236
|
+
case parent_expression
|
1237
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1238
|
+
create_normalized_logical_of(self)
|
1239
|
+
else
|
1240
|
+
self
|
1241
|
+
end
|
1242
|
+
end
|
1243
|
+
|
1244
|
+
def to_complemental_logical
|
1245
|
+
self
|
1246
|
+
end
|
1247
|
+
|
1034
1248
|
def to_s
|
1035
1249
|
"(#{@type_name.to_s}){" +
|
1036
1250
|
@initializers.map { |ini| ini.to_s }.join(",") + "}"
|
@@ -1082,6 +1296,19 @@ module C #:nodoc:
|
|
1082
1296
|
def bitwise?
|
1083
1297
|
false
|
1084
1298
|
end
|
1299
|
+
|
1300
|
+
def to_normalized_logical(parent_expression = nil)
|
1301
|
+
case parent_expression
|
1302
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1303
|
+
create_normalized_logical_of(self)
|
1304
|
+
else
|
1305
|
+
self
|
1306
|
+
end
|
1307
|
+
end
|
1308
|
+
|
1309
|
+
def to_complemental_logical
|
1310
|
+
self
|
1311
|
+
end
|
1085
1312
|
end
|
1086
1313
|
|
1087
1314
|
class PrefixDecrementExpression < UnaryExpression
|
@@ -1100,6 +1327,19 @@ module C #:nodoc:
|
|
1100
1327
|
def bitwise?
|
1101
1328
|
false
|
1102
1329
|
end
|
1330
|
+
|
1331
|
+
def to_normalized_logical(parent_expression = nil)
|
1332
|
+
case parent_expression
|
1333
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1334
|
+
create_normalized_logical_of(self)
|
1335
|
+
else
|
1336
|
+
self
|
1337
|
+
end
|
1338
|
+
end
|
1339
|
+
|
1340
|
+
def to_complemental_logical
|
1341
|
+
self
|
1342
|
+
end
|
1103
1343
|
end
|
1104
1344
|
|
1105
1345
|
class AddressExpression < UnaryExpression
|
@@ -1118,6 +1358,19 @@ module C #:nodoc:
|
|
1118
1358
|
def bitwise?
|
1119
1359
|
false
|
1120
1360
|
end
|
1361
|
+
|
1362
|
+
def to_normalized_logical(parent_expression = nil)
|
1363
|
+
case parent_expression
|
1364
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1365
|
+
create_normalized_logical_of(self)
|
1366
|
+
else
|
1367
|
+
self
|
1368
|
+
end
|
1369
|
+
end
|
1370
|
+
|
1371
|
+
def to_complemental_logical
|
1372
|
+
self
|
1373
|
+
end
|
1121
1374
|
end
|
1122
1375
|
|
1123
1376
|
class IndirectionExpression < UnaryExpression
|
@@ -1136,6 +1389,19 @@ module C #:nodoc:
|
|
1136
1389
|
def bitwise?
|
1137
1390
|
false
|
1138
1391
|
end
|
1392
|
+
|
1393
|
+
def to_normalized_logical(parent_expression = nil)
|
1394
|
+
case parent_expression
|
1395
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1396
|
+
create_normalized_logical_of(self)
|
1397
|
+
else
|
1398
|
+
self
|
1399
|
+
end
|
1400
|
+
end
|
1401
|
+
|
1402
|
+
def to_complemental_logical
|
1403
|
+
self
|
1404
|
+
end
|
1139
1405
|
end
|
1140
1406
|
|
1141
1407
|
class UnaryArithmeticExpression < UnaryExpression
|
@@ -1154,6 +1420,30 @@ module C #:nodoc:
|
|
1154
1420
|
def bitwise?
|
1155
1421
|
operator.type == "~"
|
1156
1422
|
end
|
1423
|
+
|
1424
|
+
def to_normalized_logical(parent_expression = nil)
|
1425
|
+
if operator.type == "!"
|
1426
|
+
normalized_operand = @operand.to_normalized_logical
|
1427
|
+
GroupedExpression.new(normalized_operand.to_complemental_logical)
|
1428
|
+
else
|
1429
|
+
case parent_expression
|
1430
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1431
|
+
create_normalized_logical_of(self)
|
1432
|
+
else
|
1433
|
+
self
|
1434
|
+
end
|
1435
|
+
end
|
1436
|
+
end
|
1437
|
+
|
1438
|
+
def to_complemental_logical
|
1439
|
+
if operator.type == "!"
|
1440
|
+
# NOTE: `!' expression should be normalized into an equality-expression
|
1441
|
+
# before invoking #to_complemental_logical.
|
1442
|
+
__NOTREACHED__
|
1443
|
+
else
|
1444
|
+
self
|
1445
|
+
end
|
1446
|
+
end
|
1157
1447
|
end
|
1158
1448
|
|
1159
1449
|
class SizeofExpression < UnaryExpression
|
@@ -1173,6 +1463,19 @@ module C #:nodoc:
|
|
1173
1463
|
false
|
1174
1464
|
end
|
1175
1465
|
|
1466
|
+
def to_normalized_logical(parent_expression = nil)
|
1467
|
+
case parent_expression
|
1468
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1469
|
+
create_normalized_logical_of(self)
|
1470
|
+
else
|
1471
|
+
self
|
1472
|
+
end
|
1473
|
+
end
|
1474
|
+
|
1475
|
+
def to_complemental_logical
|
1476
|
+
self
|
1477
|
+
end
|
1478
|
+
|
1176
1479
|
def to_s
|
1177
1480
|
"sizeof(#{@operand.to_s})"
|
1178
1481
|
end
|
@@ -1195,6 +1498,19 @@ module C #:nodoc:
|
|
1195
1498
|
false
|
1196
1499
|
end
|
1197
1500
|
|
1501
|
+
def to_normalized_logical(parent_expression = nil)
|
1502
|
+
case parent_expression
|
1503
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1504
|
+
create_normalized_logical_of(self)
|
1505
|
+
else
|
1506
|
+
self
|
1507
|
+
end
|
1508
|
+
end
|
1509
|
+
|
1510
|
+
def to_complemental_logical
|
1511
|
+
self
|
1512
|
+
end
|
1513
|
+
|
1198
1514
|
def to_s
|
1199
1515
|
"sizeof(#{@operand.to_s})"
|
1200
1516
|
end
|
@@ -1217,6 +1533,19 @@ module C #:nodoc:
|
|
1217
1533
|
false
|
1218
1534
|
end
|
1219
1535
|
|
1536
|
+
def to_normalized_logical(parent_expression = nil)
|
1537
|
+
case parent_expression
|
1538
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1539
|
+
create_normalized_logical_of(self)
|
1540
|
+
else
|
1541
|
+
self
|
1542
|
+
end
|
1543
|
+
end
|
1544
|
+
|
1545
|
+
def to_complemental_logical
|
1546
|
+
self
|
1547
|
+
end
|
1548
|
+
|
1220
1549
|
def to_s
|
1221
1550
|
"alignof(#{@operand.to_s})"
|
1222
1551
|
end
|
@@ -1239,6 +1568,19 @@ module C #:nodoc:
|
|
1239
1568
|
false
|
1240
1569
|
end
|
1241
1570
|
|
1571
|
+
def to_normalized_logical(parent_expression = nil)
|
1572
|
+
case parent_expression
|
1573
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1574
|
+
create_normalized_logical_of(self)
|
1575
|
+
else
|
1576
|
+
self
|
1577
|
+
end
|
1578
|
+
end
|
1579
|
+
|
1580
|
+
def to_complemental_logical
|
1581
|
+
self
|
1582
|
+
end
|
1583
|
+
|
1242
1584
|
def to_s
|
1243
1585
|
"alignof(#{@operand.to_s})"
|
1244
1586
|
end
|
@@ -1274,6 +1616,19 @@ module C #:nodoc:
|
|
1274
1616
|
@operand.bitwise?
|
1275
1617
|
end
|
1276
1618
|
|
1619
|
+
def to_normalized_logical(parent_expression = nil)
|
1620
|
+
case parent_expression
|
1621
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1622
|
+
create_normalized_logical_of(self)
|
1623
|
+
else
|
1624
|
+
self
|
1625
|
+
end
|
1626
|
+
end
|
1627
|
+
|
1628
|
+
def to_complemental_logical
|
1629
|
+
self
|
1630
|
+
end
|
1631
|
+
|
1277
1632
|
def to_s
|
1278
1633
|
"(#{@type_name.to_s}) #{@operand.to_s}"
|
1279
1634
|
end
|
@@ -1326,6 +1681,19 @@ module C #:nodoc:
|
|
1326
1681
|
def bitwise?
|
1327
1682
|
false
|
1328
1683
|
end
|
1684
|
+
|
1685
|
+
def to_normalized_logical(parent_expression = nil)
|
1686
|
+
case parent_expression
|
1687
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1688
|
+
create_normalized_logical_of(self)
|
1689
|
+
else
|
1690
|
+
self
|
1691
|
+
end
|
1692
|
+
end
|
1693
|
+
|
1694
|
+
def to_complemental_logical
|
1695
|
+
self
|
1696
|
+
end
|
1329
1697
|
end
|
1330
1698
|
|
1331
1699
|
class AdditiveExpression < BinaryExpression
|
@@ -1344,6 +1712,19 @@ module C #:nodoc:
|
|
1344
1712
|
def bitwise?
|
1345
1713
|
false
|
1346
1714
|
end
|
1715
|
+
|
1716
|
+
def to_normalized_logical(parent_expression = nil)
|
1717
|
+
case parent_expression
|
1718
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1719
|
+
create_normalized_logical_of(self)
|
1720
|
+
else
|
1721
|
+
self
|
1722
|
+
end
|
1723
|
+
end
|
1724
|
+
|
1725
|
+
def to_complemental_logical
|
1726
|
+
self
|
1727
|
+
end
|
1347
1728
|
end
|
1348
1729
|
|
1349
1730
|
class ShiftExpression < BinaryExpression
|
@@ -1362,6 +1743,19 @@ module C #:nodoc:
|
|
1362
1743
|
def bitwise?
|
1363
1744
|
true
|
1364
1745
|
end
|
1746
|
+
|
1747
|
+
def to_normalized_logical(parent_expression = nil)
|
1748
|
+
case parent_expression
|
1749
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1750
|
+
create_normalized_logical_of(self)
|
1751
|
+
else
|
1752
|
+
self
|
1753
|
+
end
|
1754
|
+
end
|
1755
|
+
|
1756
|
+
def to_complemental_logical
|
1757
|
+
self
|
1758
|
+
end
|
1365
1759
|
end
|
1366
1760
|
|
1367
1761
|
class RelationalExpression < BinaryExpression
|
@@ -1380,6 +1774,16 @@ module C #:nodoc:
|
|
1380
1774
|
def bitwise?
|
1381
1775
|
false
|
1382
1776
|
end
|
1777
|
+
|
1778
|
+
def to_normalized_logical(parent_expression = nil)
|
1779
|
+
self
|
1780
|
+
end
|
1781
|
+
|
1782
|
+
def to_complemental_logical
|
1783
|
+
operator = ComparisonOperator.new(@operator).for_complement.to_s
|
1784
|
+
operator_token = Token.new(operator, operator, @operator.location)
|
1785
|
+
RelationalExpression.new(operator_token, @lhs_operand, @rhs_operand)
|
1786
|
+
end
|
1383
1787
|
end
|
1384
1788
|
|
1385
1789
|
class EqualityExpression < BinaryExpression
|
@@ -1398,6 +1802,16 @@ module C #:nodoc:
|
|
1398
1802
|
def bitwise?
|
1399
1803
|
false
|
1400
1804
|
end
|
1805
|
+
|
1806
|
+
def to_normalized_logical(parent_expression = nil)
|
1807
|
+
self
|
1808
|
+
end
|
1809
|
+
|
1810
|
+
def to_complemental_logical
|
1811
|
+
operator = ComparisonOperator.new(@operator).for_complement.to_s
|
1812
|
+
operator_token = Token.new(operator, operator, @operator.location)
|
1813
|
+
EqualityExpression.new(operator_token, @lhs_operand, @rhs_operand)
|
1814
|
+
end
|
1401
1815
|
end
|
1402
1816
|
|
1403
1817
|
class AndExpression < BinaryExpression
|
@@ -1416,6 +1830,19 @@ module C #:nodoc:
|
|
1416
1830
|
def bitwise?
|
1417
1831
|
true
|
1418
1832
|
end
|
1833
|
+
|
1834
|
+
def to_normalized_logical(parent_expression = nil)
|
1835
|
+
case parent_expression
|
1836
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1837
|
+
create_normalized_logical_of(self)
|
1838
|
+
else
|
1839
|
+
self
|
1840
|
+
end
|
1841
|
+
end
|
1842
|
+
|
1843
|
+
def to_complemental_logical
|
1844
|
+
self
|
1845
|
+
end
|
1419
1846
|
end
|
1420
1847
|
|
1421
1848
|
class ExclusiveOrExpression < BinaryExpression
|
@@ -1434,6 +1861,19 @@ module C #:nodoc:
|
|
1434
1861
|
def bitwise?
|
1435
1862
|
true
|
1436
1863
|
end
|
1864
|
+
|
1865
|
+
def to_normalized_logical(parent_expression = nil)
|
1866
|
+
case parent_expression
|
1867
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1868
|
+
create_normalized_logical_of(self)
|
1869
|
+
else
|
1870
|
+
self
|
1871
|
+
end
|
1872
|
+
end
|
1873
|
+
|
1874
|
+
def to_complemental_logical
|
1875
|
+
self
|
1876
|
+
end
|
1437
1877
|
end
|
1438
1878
|
|
1439
1879
|
class InclusiveOrExpression < BinaryExpression
|
@@ -1452,6 +1892,19 @@ module C #:nodoc:
|
|
1452
1892
|
def bitwise?
|
1453
1893
|
true
|
1454
1894
|
end
|
1895
|
+
|
1896
|
+
def to_normalized_logical(parent_expression = nil)
|
1897
|
+
case parent_expression
|
1898
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
1899
|
+
create_normalized_logical_of(self)
|
1900
|
+
else
|
1901
|
+
self
|
1902
|
+
end
|
1903
|
+
end
|
1904
|
+
|
1905
|
+
def to_complemental_logical
|
1906
|
+
self
|
1907
|
+
end
|
1455
1908
|
end
|
1456
1909
|
|
1457
1910
|
class LogicalAndExpression < BinaryExpression
|
@@ -1489,6 +1942,18 @@ module C #:nodoc:
|
|
1489
1942
|
def bitwise?
|
1490
1943
|
false
|
1491
1944
|
end
|
1945
|
+
|
1946
|
+
def to_normalized_logical(parent_expression = nil)
|
1947
|
+
LogicalAndExpression.new(@operator,
|
1948
|
+
@lhs_operand.to_normalized_logical(self),
|
1949
|
+
@rhs_operand.to_normalized_logical(self))
|
1950
|
+
end
|
1951
|
+
|
1952
|
+
def to_complemental_logical
|
1953
|
+
LogicalOrExpression.new(Token.new("||", "||", @operator.location),
|
1954
|
+
@lhs_operand.to_complemental_logical,
|
1955
|
+
@rhs_operand.to_complemental_logical)
|
1956
|
+
end
|
1492
1957
|
end
|
1493
1958
|
|
1494
1959
|
class LogicalOrExpression < BinaryExpression
|
@@ -1526,6 +1991,18 @@ module C #:nodoc:
|
|
1526
1991
|
def bitwise?
|
1527
1992
|
false
|
1528
1993
|
end
|
1994
|
+
|
1995
|
+
def to_normalized_logical(parent_expression = nil)
|
1996
|
+
LogicalOrExpression.new(@operator,
|
1997
|
+
@lhs_operand.to_normalized_logical(self),
|
1998
|
+
@rhs_operand.to_normalized_logical(self))
|
1999
|
+
end
|
2000
|
+
|
2001
|
+
def to_complemental_logical
|
2002
|
+
LogicalAndExpression.new(Token.new("&&", "&&", @operator.location),
|
2003
|
+
@lhs_operand.to_complemental_logical,
|
2004
|
+
@rhs_operand.to_complemental_logical)
|
2005
|
+
end
|
1529
2006
|
end
|
1530
2007
|
|
1531
2008
|
class ConditionalExpression < Expression
|
@@ -1585,6 +2062,19 @@ module C #:nodoc:
|
|
1585
2062
|
@then_expression.bitwise? || @else_expression.bitwise?
|
1586
2063
|
end
|
1587
2064
|
|
2065
|
+
def to_normalized_logical(parent_expression = nil)
|
2066
|
+
case parent_expression
|
2067
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
2068
|
+
create_normalized_logical_of(self)
|
2069
|
+
else
|
2070
|
+
self
|
2071
|
+
end
|
2072
|
+
end
|
2073
|
+
|
2074
|
+
def to_complemental_logical
|
2075
|
+
self
|
2076
|
+
end
|
2077
|
+
|
1588
2078
|
def to_s
|
1589
2079
|
"#{@condition.to_s} ? " +
|
1590
2080
|
"#{@then_expression.to_s} : #{@else_expression.to_s}"
|
@@ -1614,6 +2104,19 @@ module C #:nodoc:
|
|
1614
2104
|
def bitwise?
|
1615
2105
|
rhs_operand.bitwise?
|
1616
2106
|
end
|
2107
|
+
|
2108
|
+
def to_normalized_logical(parent_expression = nil)
|
2109
|
+
case parent_expression
|
2110
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
2111
|
+
create_normalized_logical_of(self)
|
2112
|
+
else
|
2113
|
+
self
|
2114
|
+
end
|
2115
|
+
end
|
2116
|
+
|
2117
|
+
def to_complemental_logical
|
2118
|
+
self
|
2119
|
+
end
|
1617
2120
|
end
|
1618
2121
|
|
1619
2122
|
class CompoundAssignmentExpression < BinaryExpression
|
@@ -1632,6 +2135,19 @@ module C #:nodoc:
|
|
1632
2135
|
def bitwise?
|
1633
2136
|
["<<=", ">>=", "&=", "^=", "|="].include?(operator.type)
|
1634
2137
|
end
|
2138
|
+
|
2139
|
+
def to_normalized_logical(parent_expression = nil)
|
2140
|
+
case parent_expression
|
2141
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
2142
|
+
create_normalized_logical_of(self)
|
2143
|
+
else
|
2144
|
+
self
|
2145
|
+
end
|
2146
|
+
end
|
2147
|
+
|
2148
|
+
def to_complemental_logical
|
2149
|
+
self
|
2150
|
+
end
|
1635
2151
|
end
|
1636
2152
|
|
1637
2153
|
class CommaSeparatedExpression < Expression
|
@@ -1663,6 +2179,19 @@ module C #:nodoc:
|
|
1663
2179
|
@expressions.last.bitwise?
|
1664
2180
|
end
|
1665
2181
|
|
2182
|
+
def to_normalized_logical(parent_expression = nil)
|
2183
|
+
case parent_expression
|
2184
|
+
when nil, LogicalAndExpression, LogicalOrExpression
|
2185
|
+
create_normalized_logical_of(@expressions.last)
|
2186
|
+
else
|
2187
|
+
self
|
2188
|
+
end
|
2189
|
+
end
|
2190
|
+
|
2191
|
+
def to_complemental_logical
|
2192
|
+
@expressions.last.to_complemental_logical
|
2193
|
+
end
|
2194
|
+
|
1666
2195
|
def to_s
|
1667
2196
|
@expressions.map { |expr| expr.to_s }.join(",")
|
1668
2197
|
end
|
@@ -3067,10 +3596,10 @@ module C #:nodoc:
|
|
3067
3596
|
end
|
3068
3597
|
|
3069
3598
|
private
|
3070
|
-
def deduct_controlling_expression_candidates(
|
3599
|
+
def deduct_controlling_expression_candidates(rough_candidates)
|
3071
3600
|
varying_var_names = varying_variable_names
|
3072
|
-
|
3073
|
-
collect_object_specifiers(
|
3601
|
+
rough_candidates.select do |expr_pair|
|
3602
|
+
collect_object_specifiers(expr_pair.first).any? do |os|
|
3074
3603
|
varying_var_names.include?(os.identifier.value)
|
3075
3604
|
end
|
3076
3605
|
end
|
@@ -3172,18 +3701,20 @@ module C #:nodoc:
|
|
3172
3701
|
end
|
3173
3702
|
|
3174
3703
|
def deduct_controlling_expression
|
3175
|
-
|
3176
|
-
|
3177
|
-
@expression,
|
3178
|
-
|
3179
|
-
|
3704
|
+
selections = collect_loop_breaking_selection_statements(@statement)
|
3705
|
+
rough_candidates = [
|
3706
|
+
[@expression, @expression]
|
3707
|
+
] + selections.map { |stmt|
|
3708
|
+
[stmt.expression,
|
3709
|
+
stmt.expression.to_normalized_logical.to_complemental_logical]
|
3710
|
+
}
|
3180
3711
|
|
3181
3712
|
# FIXME: When many loop breaking selection-statements are found, how can
|
3182
3713
|
# I select one selection-statement?
|
3183
3714
|
# FIXME: When the loop breaking selection-statement is a
|
3184
3715
|
# if-else-statement and the loop breaking is in the else branch,
|
3185
3716
|
# the controlling expression should be inverted.
|
3186
|
-
deduct_controlling_expression_candidates(
|
3717
|
+
deduct_controlling_expression_candidates(rough_candidates).first
|
3187
3718
|
end
|
3188
3719
|
|
3189
3720
|
def inspect(indent = 0)
|
@@ -3212,18 +3743,20 @@ module C #:nodoc:
|
|
3212
3743
|
end
|
3213
3744
|
|
3214
3745
|
def deduct_controlling_expression
|
3215
|
-
|
3216
|
-
|
3217
|
-
@expression,
|
3218
|
-
|
3219
|
-
|
3746
|
+
selections = collect_loop_breaking_selection_statements(@statement)
|
3747
|
+
rough_candidates = [
|
3748
|
+
[@expression, @expression]
|
3749
|
+
] + selections.map { |stmt|
|
3750
|
+
[stmt.expression,
|
3751
|
+
stmt.expression.to_normalized_logical.to_complemental_logical]
|
3752
|
+
}
|
3220
3753
|
|
3221
3754
|
# FIXME: When many loop breaking selection-statements are found, how can
|
3222
3755
|
# I select one selection-statement?
|
3223
3756
|
# FIXME: When the loop breaking selection-statement is a
|
3224
3757
|
# if-else-statement and the loop breaking is in the else branch,
|
3225
3758
|
# the controlling expression should be inverted.
|
3226
|
-
deduct_controlling_expression_candidates(
|
3759
|
+
deduct_controlling_expression_candidates(rough_candidates).first
|
3227
3760
|
end
|
3228
3761
|
|
3229
3762
|
def inspect(indent = 0)
|
@@ -3255,19 +3788,20 @@ module C #:nodoc:
|
|
3255
3788
|
end
|
3256
3789
|
|
3257
3790
|
def deduct_controlling_expression
|
3258
|
-
|
3259
|
-
|
3260
|
-
|
3261
|
-
|
3262
|
-
|
3263
|
-
|
3791
|
+
selections = collect_loop_breaking_selection_statements(@body_statement)
|
3792
|
+
rough_candidates = [
|
3793
|
+
[@condition_statement.expression, @condition_statement.expression]
|
3794
|
+
] + selections.map { |stmt|
|
3795
|
+
[stmt.expression,
|
3796
|
+
stmt.expression.to_normalized_logical.to_complemental_logical]
|
3797
|
+
}
|
3264
3798
|
|
3265
3799
|
# FIXME: When many loop breaking selection-statements are found, how can
|
3266
3800
|
# I select one selection-statement?
|
3267
3801
|
# FIXME: When the loop breaking selection-statement is a
|
3268
3802
|
# if-else-statement and the loop breaking is in the else branch,
|
3269
3803
|
# the controlling expression should be inverted.
|
3270
|
-
deduct_controlling_expression_candidates(
|
3804
|
+
deduct_controlling_expression_candidates(rough_candidates).first
|
3271
3805
|
end
|
3272
3806
|
|
3273
3807
|
def inspect(indent = 0)
|
@@ -3301,19 +3835,20 @@ module C #:nodoc:
|
|
3301
3835
|
end
|
3302
3836
|
|
3303
3837
|
def deduct_controlling_expression
|
3304
|
-
|
3305
|
-
|
3306
|
-
|
3307
|
-
|
3308
|
-
|
3309
|
-
|
3838
|
+
selections = collect_loop_breaking_selection_statements(@body_statement)
|
3839
|
+
rough_candidates = [
|
3840
|
+
[@condition_statement.expression, @condition_statement.expression]
|
3841
|
+
] + selections.map { |stmt|
|
3842
|
+
[stmt.expression,
|
3843
|
+
stmt.expression.to_normalized_logical.to_complemental_logical]
|
3844
|
+
}
|
3310
3845
|
|
3311
3846
|
# FIXME: When many loop breaking selection-statements are found, how can
|
3312
3847
|
# I select one selection-statement?
|
3313
3848
|
# FIXME: When the loop breaking selection-statement is a
|
3314
3849
|
# if-else-statement and the loop breaking is in the else branch,
|
3315
3850
|
# the controlling expression should be inverted.
|
3316
|
-
deduct_controlling_expression_candidates(
|
3851
|
+
deduct_controlling_expression_candidates(rough_candidates).first
|
3317
3852
|
end
|
3318
3853
|
|
3319
3854
|
def inspect(indent = 0)
|