adlint 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. data/ChangeLog +389 -37
  2. data/INSTALL +3 -0
  3. data/MANIFEST +7 -0
  4. data/NEWS +50 -10
  5. data/etc/conf.d/i686-mingw/cinit-gcc_4.6.1.erb +1 -1
  6. data/etc/mesg.d/en_US/messages.yml +7 -7
  7. data/etc/mesg.d/ja_JP/messages.yml +4 -4
  8. data/lib/adlint/c/branch.rb +4 -4
  9. data/lib/adlint/c/code.rb +11 -13
  10. data/lib/adlint/c/enum.rb +0 -2
  11. data/lib/adlint/c/environ.rb +13 -7
  12. data/lib/adlint/c/expr.rb +5 -1
  13. data/lib/adlint/c/interp.rb +10 -6
  14. data/lib/adlint/c/mediator.rb +1 -0
  15. data/lib/adlint/c/message.rb +294 -111
  16. data/lib/adlint/c/message_shima.rb +63 -0
  17. data/lib/adlint/c/metric.rb +25 -13
  18. data/lib/adlint/c/object.rb +168 -31
  19. data/lib/adlint/c/parser.rb +3 -3
  20. data/lib/adlint/c/phase.rb +20 -3
  21. data/lib/adlint/c/syntax.rb +175 -17
  22. data/lib/adlint/c/value.rb +199 -126
  23. data/lib/adlint/cpp/asm.rb +4 -4
  24. data/lib/adlint/cpp/constexpr.rb +1 -1
  25. data/lib/adlint/cpp/eval.rb +6 -4
  26. data/lib/adlint/cpp/message.rb +100 -7
  27. data/lib/adlint/cpp/phase.rb +12 -1
  28. data/lib/adlint/cpp/source.rb +2 -2
  29. data/lib/adlint/cpp/subst.rb +2 -4
  30. data/lib/adlint/lang.rb +5 -3
  31. data/lib/adlint/ld/metric.rb +1 -1
  32. data/lib/adlint/version.rb +2 -2
  33. data/share/demo/Makefile +5 -0
  34. data/share/demo/bad_include/bad_include.c +13 -0
  35. data/share/demo/bad_include/test'1'.h +0 -0
  36. data/share/demo/bad_include/test'2'.h +0 -0
  37. data/share/demo/incomplete_ifelse/incomplete_ifelse.c +29 -0
  38. data/share/demo/inline_asm/inline_asm.c +25 -0
  39. data/share/demo/invalid_call/invalid_call.c +12 -4
  40. data/share/demo/logical_expr/logical_expr.c +73 -0
  41. data/share/demo/register_vars/register_vars.c +12 -0
  42. data/share/demo/typedef_each_src/typedef_each_src.c +9 -0
  43. data/share/demo/wrap_around/wrap_around.c +17 -0
  44. data/share/doc/developers_guide_ja.html +3 -3
  45. data/share/doc/developers_guide_ja.texi +1 -1
  46. data/share/doc/users_guide_en.html +137 -102
  47. data/share/doc/users_guide_en.texi +121 -86
  48. data/share/doc/users_guide_ja.html +118 -91
  49. data/share/doc/users_guide_ja.texi +103 -76
  50. metadata +10 -3
@@ -31,7 +31,6 @@
31
31
 
32
32
  require "adlint/symbol"
33
33
  require "adlint/util"
34
- require "adlint/c/enum"
35
34
  require "adlint/c/seqp"
36
35
 
37
36
  module AdLint #:nodoc:
@@ -226,6 +225,17 @@ module C #:nodoc:
226
225
  end
227
226
  module_function :collect_identifier_declarators
228
227
 
228
+ def collect_typedef_type_specifiers(node)
229
+ if node
230
+ TypedefTypeSpecifierCollector.new.tap { |collector|
231
+ node.accept(collector)
232
+ }.typedef_type_specifiers
233
+ else
234
+ []
235
+ end
236
+ end
237
+ module_function :collect_typedef_type_specifiers
238
+
229
239
  def collect_function_declarators(node)
230
240
  if node
231
241
  FunctionDeclaratorCollector.new.tap { |collector|
@@ -424,6 +434,10 @@ module C #:nodoc:
424
434
  }.object_specifiers
425
435
  end
426
436
 
437
+ def logical?
438
+ subclass_responsibility
439
+ end
440
+
427
441
  def to_s
428
442
  subclass_responsibility
429
443
  end
@@ -443,6 +457,10 @@ module C #:nodoc:
443
457
  true
444
458
  end
445
459
 
460
+ def logical?
461
+ false
462
+ end
463
+
446
464
  def to_s
447
465
  @error_token.value
448
466
  end
@@ -457,6 +475,10 @@ module C #:nodoc:
457
475
  def have_side_effect?
458
476
  false
459
477
  end
478
+
479
+ def logical?
480
+ false
481
+ end
460
482
  end
461
483
 
462
484
  class ObjectSpecifier < PrimaryExpression
@@ -471,6 +493,10 @@ module C #:nodoc:
471
493
  @identifier.location
472
494
  end
473
495
 
496
+ def logical?
497
+ false
498
+ end
499
+
474
500
  def to_s
475
501
  @identifier.value
476
502
  end
@@ -505,6 +531,10 @@ module C #:nodoc:
505
531
  @constant.value =~ /'.*'/
506
532
  end
507
533
 
534
+ def logical?
535
+ false
536
+ end
537
+
508
538
  def to_s
509
539
  @constant.value
510
540
  end
@@ -531,6 +561,10 @@ module C #:nodoc:
531
561
  @literal.value.scan(/\AL/i).first
532
562
  end
533
563
 
564
+ def logical?
565
+ false
566
+ end
567
+
534
568
  def to_s
535
569
  @literal.value
536
570
  end
@@ -553,6 +587,10 @@ module C #:nodoc:
553
587
  @token.location
554
588
  end
555
589
 
590
+ def logical?
591
+ false
592
+ end
593
+
556
594
  def to_s
557
595
  @token.value
558
596
  end
@@ -579,6 +617,10 @@ module C #:nodoc:
579
617
  @expression.have_side_effect?
580
618
  end
581
619
 
620
+ def logical?
621
+ @expression.logical?
622
+ end
623
+
582
624
  def to_s
583
625
  "(#{expression.to_s})"
584
626
  end
@@ -599,6 +641,10 @@ module C #:nodoc:
599
641
  def location
600
642
  @operator.location
601
643
  end
644
+
645
+ def logical?
646
+ false
647
+ end
602
648
  end
603
649
 
604
650
  class ArraySubscriptExpression < PostfixExpression
@@ -849,21 +895,45 @@ module C #:nodoc:
849
895
  def have_side_effect?
850
896
  true
851
897
  end
898
+
899
+ def logical?
900
+ false
901
+ end
852
902
  end
853
903
 
854
904
  class PrefixDecrementExpression < UnaryExpression
855
905
  def have_side_effect?
856
906
  true
857
907
  end
908
+
909
+ def logical?
910
+ false
911
+ end
858
912
  end
859
913
 
860
- class AddressExpression < UnaryExpression; end
914
+ class AddressExpression < UnaryExpression
915
+ def logical?
916
+ false
917
+ end
918
+ end
861
919
 
862
- class IndirectionExpression < UnaryExpression; end
920
+ class IndirectionExpression < UnaryExpression
921
+ def logical?
922
+ false
923
+ end
924
+ end
863
925
 
864
- class UnaryArithmeticExpression < UnaryExpression; end
926
+ class UnaryArithmeticExpression < UnaryExpression
927
+ def logical?
928
+ @operator.type == "!"
929
+ end
930
+ end
865
931
 
866
932
  class SizeofExpression < UnaryExpression
933
+ def logical?
934
+ false
935
+ end
936
+
867
937
  def to_s
868
938
  "sizeof(#{@operand.to_s})"
869
939
  end
@@ -874,12 +944,20 @@ module C #:nodoc:
874
944
  false
875
945
  end
876
946
 
947
+ def logical?
948
+ false
949
+ end
950
+
877
951
  def to_s
878
952
  "sizeof(#{@operand.to_s})"
879
953
  end
880
954
  end
881
955
 
882
956
  class AlignofExpression < UnaryExpression
957
+ def logical?
958
+ false
959
+ end
960
+
883
961
  def to_s
884
962
  "alignof(#{@operand.to_s})"
885
963
  end
@@ -890,6 +968,10 @@ module C #:nodoc:
890
968
  false
891
969
  end
892
970
 
971
+ def logical?
972
+ false
973
+ end
974
+
893
975
  def to_s
894
976
  "alignof(#{@operand.to_s})"
895
977
  end
@@ -913,6 +995,10 @@ module C #:nodoc:
913
995
  @operand.have_side_effect?
914
996
  end
915
997
 
998
+ def logical?
999
+ false
1000
+ end
1001
+
916
1002
  def to_s
917
1003
  "(#{@type_name.to_s}) #{@operand.to_s}"
918
1004
  end
@@ -953,21 +1039,53 @@ module C #:nodoc:
953
1039
  end
954
1040
  end
955
1041
 
956
- class MultiplicativeExpression < BinaryExpression; end
1042
+ class MultiplicativeExpression < BinaryExpression
1043
+ def logical?
1044
+ false
1045
+ end
1046
+ end
957
1047
 
958
- class AdditiveExpression < BinaryExpression; end
1048
+ class AdditiveExpression < BinaryExpression
1049
+ def logical?
1050
+ false
1051
+ end
1052
+ end
959
1053
 
960
- class ShiftExpression < BinaryExpression; end
1054
+ class ShiftExpression < BinaryExpression
1055
+ def logical?
1056
+ false
1057
+ end
1058
+ end
961
1059
 
962
- class RelationalExpression < BinaryExpression; end
1060
+ class RelationalExpression < BinaryExpression
1061
+ def logical?
1062
+ true
1063
+ end
1064
+ end
963
1065
 
964
- class EqualityExpression < BinaryExpression; end
1066
+ class EqualityExpression < BinaryExpression
1067
+ def logical?
1068
+ true
1069
+ end
1070
+ end
965
1071
 
966
- class AndExpression < BinaryExpression; end
1072
+ class AndExpression < BinaryExpression
1073
+ def logical?
1074
+ false
1075
+ end
1076
+ end
967
1077
 
968
- class ExclusiveOrExpression < BinaryExpression; end
1078
+ class ExclusiveOrExpression < BinaryExpression
1079
+ def logical?
1080
+ false
1081
+ end
1082
+ end
969
1083
 
970
- class InclusiveOrExpression < BinaryExpression; end
1084
+ class InclusiveOrExpression < BinaryExpression
1085
+ def logical?
1086
+ false
1087
+ end
1088
+ end
971
1089
 
972
1090
  class LogicalAndExpression < BinaryExpression
973
1091
  def initialize(operator, lhs_operand, rhs_operand)
@@ -985,6 +1103,10 @@ module C #:nodoc:
985
1103
  # to 0, the second operand is not evaluated.
986
1104
  @lhs_operand.append_sequence_point!
987
1105
  end
1106
+
1107
+ def logical?
1108
+ true
1109
+ end
988
1110
  end
989
1111
 
990
1112
  class LogicalOrExpression < BinaryExpression
@@ -1003,6 +1125,10 @@ module C #:nodoc:
1003
1125
  # unequal to 0, the second operand is not evaluated.
1004
1126
  @lhs_operand.append_sequence_point!
1005
1127
  end
1128
+
1129
+ def logical?
1130
+ true
1131
+ end
1006
1132
  end
1007
1133
 
1008
1134
  class ConditionalExpression < Expression
@@ -1044,6 +1170,10 @@ module C #:nodoc:
1044
1170
  @else_expression.have_side_effect?
1045
1171
  end
1046
1172
 
1173
+ def logical?
1174
+ @then_expression.logical? || @else_expression.logical?
1175
+ end
1176
+
1047
1177
  def to_s
1048
1178
  "#{@condition.to_s} ? " +
1049
1179
  "#{@then_expression.to_s} : #{@else_expression.to_s}"
@@ -1061,12 +1191,20 @@ module C #:nodoc:
1061
1191
  def have_side_effect?
1062
1192
  true
1063
1193
  end
1194
+
1195
+ def logical?
1196
+ @rhs_operand.logical?
1197
+ end
1064
1198
  end
1065
1199
 
1066
1200
  class CompoundAssignmentExpression < BinaryExpression
1067
1201
  def have_side_effect?
1068
1202
  true
1069
1203
  end
1204
+
1205
+ def logical?
1206
+ false
1207
+ end
1070
1208
  end
1071
1209
 
1072
1210
  class CommaSeparatedExpression < Expression
@@ -1086,6 +1224,10 @@ module C #:nodoc:
1086
1224
  @expressions.any? { |expr| expr.have_side_effect? }
1087
1225
  end
1088
1226
 
1227
+ def logical?
1228
+ @expressions.last.logical?
1229
+ end
1230
+
1089
1231
  def to_s
1090
1232
  @expressions.map { |expr| expr.to_s }.join(",")
1091
1233
  end
@@ -1285,7 +1427,7 @@ module C #:nodoc:
1285
1427
  end
1286
1428
 
1287
1429
  def signature
1288
- FunctionSignature.new(identifier, @type)
1430
+ FunctionSignature.new(identifier.value, @type)
1289
1431
  end
1290
1432
 
1291
1433
  def function_declarator
@@ -2804,7 +2946,7 @@ module C #:nodoc:
2804
2946
  end
2805
2947
 
2806
2948
  def signature
2807
- FunctionSignature.new(identifier, @type)
2949
+ FunctionSignature.new(identifier.value, @type)
2808
2950
  end
2809
2951
 
2810
2952
  def function_declarator
@@ -3195,14 +3337,14 @@ module C #:nodoc:
3195
3337
 
3196
3338
  def ==(rhs)
3197
3339
  if @type.parameter_types.empty? || rhs.type.parameter_types.empty?
3198
- @name.value == rhs.name.value
3340
+ @name == rhs.name
3199
3341
  else
3200
- @name.value == rhs.name.value && @type == rhs.type
3342
+ @name == rhs.name && @type == rhs.type
3201
3343
  end
3202
3344
  end
3203
3345
 
3204
3346
  def to_s
3205
- "#{@type.return_type.brief_image} #{@name.value}(" +
3347
+ "#{@type.return_type.brief_image} #{@name}(" +
3206
3348
  @type.parameter_types.map { |t| t.brief_image }.join(",") +
3207
3349
  (@type.have_va_list? ? ",...)" : ")")
3208
3350
  end
@@ -4294,6 +4436,22 @@ module C #:nodoc:
4294
4436
  end
4295
4437
  end
4296
4438
 
4439
+ class TypedefTypeSpecifierCollector < SyntaxTreeVisitor
4440
+ def initialize
4441
+ @typedef_type_specifiers = []
4442
+ end
4443
+
4444
+ attr_reader :typedef_type_specifiers
4445
+
4446
+ def visit_variable_definition(node)
4447
+ end
4448
+
4449
+ def visit_typedef_type_specifier(node)
4450
+ super
4451
+ @typedef_type_specifiers.push(node)
4452
+ end
4453
+ end
4454
+
4297
4455
  class FunctionDeclaratorCollector < SyntaxTreeVisitor
4298
4456
  def initialize
4299
4457
  @function_declarators = []