adlint 3.0.4 → 3.0.8

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 (73) hide show
  1. data/ChangeLog +374 -13
  2. data/INSTALL +1 -3
  3. data/MANIFEST +12 -0
  4. data/NEWS +30 -4
  5. data/README +0 -4
  6. data/TODO +2 -1
  7. data/etc/mesg.d/c_builtin/en_US/messages.yml +2 -2
  8. data/etc/mesg.d/c_builtin/ja_JP/messages.yml +2 -2
  9. data/etc/mesg.d/core/en_US/messages.yml +5 -1
  10. data/etc/mesg.d/core/ja_JP/messages.yml +5 -1
  11. data/features/code_check/W0422.feature +128 -0
  12. data/features/code_check/W0491.feature +57 -0
  13. data/features/code_check/W0492.feature +80 -0
  14. data/features/code_check/W0542.feature +20 -0
  15. data/features/code_check/W0580.feature +25 -0
  16. data/features/code_check/W0610.feature +36 -0
  17. data/features/code_check/W0642.feature +67 -0
  18. data/features/code_check/W0786.feature +39 -0
  19. data/features/code_check/W0830.feature +27 -0
  20. data/features/code_check/W1047.feature +72 -0
  21. data/features/code_check/W9003.feature +22 -0
  22. data/features/code_extraction/TODO +1 -0
  23. data/features/metric_measurement/TODO +1 -0
  24. data/lib/adlint/analyzer.rb +2 -2
  25. data/lib/adlint/cc1/ctrlexpr.rb +27 -6
  26. data/lib/adlint/cc1/domain.rb +72 -12
  27. data/lib/adlint/cc1/enum.rb +4 -0
  28. data/lib/adlint/cc1/expr.rb +31 -29
  29. data/lib/adlint/cc1/interp.rb +45 -56
  30. data/lib/adlint/cc1/lexer.rb +26 -5
  31. data/lib/adlint/cc1/mediator.rb +35 -6
  32. data/lib/adlint/cc1/object.rb +62 -19
  33. data/lib/adlint/cc1/parser.rb +948 -904
  34. data/lib/adlint/cc1/parser.y +59 -29
  35. data/lib/adlint/cc1/phase.rb +6 -8
  36. data/lib/adlint/cc1/syntax.rb +70 -17
  37. data/lib/adlint/cc1/util.rb +4 -4
  38. data/lib/adlint/code.rb +16 -6
  39. data/lib/adlint/cpp/eval.rb +31 -25
  40. data/lib/adlint/cpp/lexer.rb +11 -5
  41. data/lib/adlint/cpp/macro.rb +34 -7
  42. data/lib/adlint/cpp/phase.rb +8 -8
  43. data/lib/adlint/error.rb +6 -0
  44. data/lib/adlint/exam/c_builtin/cc1_check.rb +557 -594
  45. data/lib/adlint/exam/c_builtin/cc1_check_shima.rb +72 -72
  46. data/lib/adlint/exam/c_builtin/cc1_code.rb +72 -52
  47. data/lib/adlint/exam/c_builtin/cc1_metric.rb +131 -131
  48. data/lib/adlint/exam/c_builtin/cpp_check.rb +48 -48
  49. data/lib/adlint/exam/c_builtin/cpp_check_shima.rb +2 -2
  50. data/lib/adlint/exam/c_builtin/cpp_code.rb +21 -21
  51. data/lib/adlint/exam/c_builtin/ld_check.rb +88 -87
  52. data/lib/adlint/exam/c_builtin/ld_metric.rb +4 -5
  53. data/lib/adlint/exam/c_builtin.rb +6 -6
  54. data/lib/adlint/ld/object.rb +269 -186
  55. data/lib/adlint/ld/phase.rb +19 -19
  56. data/lib/adlint/ld/typedef.rb +7 -7
  57. data/lib/adlint/ld/util.rb +25 -17
  58. data/lib/adlint/location.rb +6 -1
  59. data/lib/adlint/memo.rb +66 -13
  60. data/lib/adlint/prelude.rb +2 -2
  61. data/lib/adlint/report.rb +13 -14
  62. data/lib/adlint/util.rb +1 -1
  63. data/lib/adlint/version.rb +2 -2
  64. data/share/doc/Makefile +6 -2
  65. data/share/doc/c99gram.dot +502 -0
  66. data/share/doc/c99gram.pdf +0 -0
  67. data/share/doc/developers_guide_ja.html +4 -3
  68. data/share/doc/developers_guide_ja.texi +2 -1
  69. data/share/doc/users_guide_en.html +9 -9
  70. data/share/doc/users_guide_en.texi +7 -7
  71. data/share/doc/users_guide_ja.html +9 -9
  72. data/share/doc/users_guide_ja.texi +7 -7
  73. metadata +14 -2
@@ -547,7 +547,7 @@ declaration
547
547
  : declaration_specifiers ";"
548
548
  {
549
549
  checkpoint(val[0].location)
550
- @lexer.start_identifier_translation
550
+ @lexer.enable_identifier_translation
551
551
  result = Declaration.new(val[0], [], @sym_tbl)
552
552
  result.head_token = val[0].head_token
553
553
  result.tail_token = val[1]
@@ -555,6 +555,7 @@ declaration
555
555
  | declaration_specifiers init_declarator_list ";"
556
556
  {
557
557
  checkpoint(val[0].location)
558
+ @lexer.enable_identifier_translation
558
559
  result = Declaration.new(val[0], val[1], @sym_tbl)
559
560
  result.head_token = val[0].head_token
560
561
  result.tail_token = val[2]
@@ -598,7 +599,6 @@ declaration_specifiers
598
599
  | type_specifier
599
600
  {
600
601
  checkpoint(val[0].location)
601
- @lexer.stop_identifier_translation
602
602
  result = DeclarationSpecifiers.new
603
603
  result.type_specifiers.push(val[0])
604
604
  result.head_token = val[0].head_token
@@ -607,7 +607,6 @@ declaration_specifiers
607
607
  | declaration_specifiers type_specifier
608
608
  {
609
609
  checkpoint(val[0].location)
610
- @lexer.stop_identifier_translation
611
610
  result = val[0]
612
611
  result.type_specifiers.push(val[1])
613
612
  result.tail_token = val[1].tail_token
@@ -684,86 +683,110 @@ type_specifier
684
683
  : VOID
685
684
  {
686
685
  checkpoint(val[0].location)
686
+ @lexer.disable_identifier_translation
687
687
  result = StandardTypeSpecifier.new(val[0])
688
688
  result.head_token = result.tail_token = val[0]
689
689
  }
690
690
  | CHAR
691
691
  {
692
692
  checkpoint(val[0].location)
693
+ @lexer.disable_identifier_translation
693
694
  result = StandardTypeSpecifier.new(val[0])
694
695
  result.head_token = result.tail_token = val[0]
695
696
  }
696
697
  | SHORT
697
698
  {
698
699
  checkpoint(val[0].location)
700
+ @lexer.disable_identifier_translation
699
701
  result = StandardTypeSpecifier.new(val[0])
700
702
  result.head_token = result.tail_token = val[0]
701
703
  }
702
704
  | INT
703
705
  {
704
706
  checkpoint(val[0].location)
707
+ @lexer.disable_identifier_translation
705
708
  result = StandardTypeSpecifier.new(val[0])
706
709
  result.head_token = result.tail_token = val[0]
707
710
  }
708
711
  | LONG
709
712
  {
710
713
  checkpoint(val[0].location)
714
+ @lexer.disable_identifier_translation
711
715
  result = StandardTypeSpecifier.new(val[0])
712
716
  result.head_token = result.tail_token = val[0]
713
717
  }
714
718
  | FLOAT
715
719
  {
716
720
  checkpoint(val[0].location)
721
+ @lexer.disable_identifier_translation
717
722
  result = StandardTypeSpecifier.new(val[0])
718
723
  result.head_token = result.tail_token = val[0]
719
724
  }
720
725
  | DOUBLE
721
726
  {
722
727
  checkpoint(val[0].location)
728
+ @lexer.disable_identifier_translation
723
729
  result = StandardTypeSpecifier.new(val[0])
724
730
  result.head_token = result.tail_token = val[0]
725
731
  }
726
732
  | SIGNED
727
733
  {
728
734
  checkpoint(val[0].location)
735
+ @lexer.disable_identifier_translation
729
736
  result = StandardTypeSpecifier.new(val[0])
730
737
  result.head_token = result.tail_token = val[0]
731
738
  }
732
739
  | UNSIGNED
733
740
  {
734
741
  checkpoint(val[0].location)
742
+ @lexer.disable_identifier_translation
735
743
  result = StandardTypeSpecifier.new(val[0])
736
744
  result.head_token = result.tail_token = val[0]
737
745
  }
738
746
  | BOOL
739
747
  {
740
748
  checkpoint(val[0].location)
749
+ @lexer.disable_identifier_translation
741
750
  result = StandardTypeSpecifier.new(val[0])
742
751
  result.head_token = result.tail_token = val[0]
743
752
  }
744
753
  | COMPLEX
745
754
  {
746
755
  checkpoint(val[0].location)
756
+ @lexer.disable_identifier_translation
747
757
  result = StandardTypeSpecifier.new(val[0])
748
758
  result.head_token = result.tail_token = val[0]
749
759
  }
750
760
  | IMAGINARY
751
761
  {
752
762
  checkpoint(val[0].location)
763
+ @lexer.disable_identifier_translation
753
764
  result = StandardTypeSpecifier.new(val[0])
754
765
  result.head_token = result.tail_token = val[0]
755
766
  }
756
767
  | TYPEDEF_NAME
757
768
  {
758
769
  checkpoint(val[0].location)
770
+ @lexer.disable_identifier_translation
759
771
  result = TypedefTypeSpecifier.new(val[0])
760
772
  result.head_token = result.tail_token = val[0]
761
773
  }
762
774
  | struct_or_union_specifier
775
+ {
776
+ checkpoint(val[0].location)
777
+ @lexer.disable_identifier_translation
778
+ result = val[0]
779
+ }
763
780
  | enum_specifier
781
+ {
782
+ checkpoint(val[0].location)
783
+ @lexer.disable_identifier_translation
784
+ result = val[0]
785
+ }
764
786
  | TYPEOF "(" constant_expression ")"
765
787
  {
766
788
  checkpoint(val[0].location)
789
+ @lexer.disable_identifier_translation
767
790
  val[2].full = true
768
791
  result = TypeofTypeSpecifier.new(val[2], nil)
769
792
  result.head_token = val[0]
@@ -772,6 +795,7 @@ type_specifier
772
795
  | TYPEOF "(" type_name ")"
773
796
  {
774
797
  checkpoint(val[0].location)
798
+ @lexer.disable_identifier_translation
775
799
  result = TypeofTypeSpecifier.new(nil, val[2])
776
800
  result.head_token = val[0]
777
801
  result.tail_token = val[3]
@@ -855,11 +879,13 @@ struct_declaration_list
855
879
  : struct_declaration
856
880
  {
857
881
  checkpoint(val[0].location)
882
+ @lexer.enable_identifier_translation
858
883
  result = val
859
884
  }
860
885
  | struct_declaration_list struct_declaration
861
886
  {
862
887
  checkpoint(val[0].first.location)
888
+ @lexer.enable_identifier_translation
863
889
  result = val[0].push(val[1])
864
890
  }
865
891
  ;
@@ -868,18 +894,16 @@ struct_declaration
868
894
  : specifier_qualifier_list ";"
869
895
  {
870
896
  checkpoint(val[0].location)
871
- @lexer.start_identifier_translation
872
897
  result = StructDeclaration.new(val[0], [])
873
898
  result.head_token = val[0].head_token
874
899
  result.tail_token = val[1]
875
900
  }
876
- | specifier_qualifier_list { @lexer.stop_identifier_translation }
877
- struct_declarator_list ";"
901
+ | specifier_qualifier_list struct_declarator_list ";"
878
902
  {
879
903
  checkpoint(val[0].location)
880
- result = StructDeclaration.new(val[0], val[2])
904
+ result = StructDeclaration.new(val[0], val[1])
881
905
  result.head_token = val[0].head_token
882
- result.tail_token = val[3]
906
+ result.tail_token = val[2]
883
907
  }
884
908
  ;
885
909
 
@@ -887,7 +911,6 @@ specifier_qualifier_list
887
911
  : specifier_qualifier_list type_specifier
888
912
  {
889
913
  checkpoint(val[0].location)
890
- @lexer.stop_identifier_translation
891
914
  result = val[0]
892
915
  result.type_specifiers.push(val[1])
893
916
  result.tail_token = val[1].tail_token
@@ -895,7 +918,6 @@ specifier_qualifier_list
895
918
  | type_specifier
896
919
  {
897
920
  checkpoint(val[0].location)
898
- @lexer.stop_identifier_translation
899
921
  result = SpecifierQualifierList.new
900
922
  result.type_specifiers.push(val[0])
901
923
  result.head_token = val[0].head_token
@@ -1058,7 +1080,7 @@ direct_declarator
1058
1080
  : IDENTIFIER
1059
1081
  {
1060
1082
  checkpoint(val[0].location)
1061
- @lexer.start_identifier_translation
1083
+ @lexer.enable_identifier_translation
1062
1084
  result = IdentifierDeclarator.new(val[0])
1063
1085
  result.head_token = result.tail_token = val[0]
1064
1086
  }
@@ -1131,12 +1153,13 @@ direct_declarator
1131
1153
  result.head_token = val[0].head_token
1132
1154
  result.tail_token = val[2]
1133
1155
  }
1134
- | direct_declarator "(" parameter_type_list ")"
1156
+ | direct_declarator "(" { @lexer.enable_identifier_translation }
1157
+ parameter_type_list ")"
1135
1158
  {
1136
1159
  checkpoint(val[0].location)
1137
- result = AnsiFunctionDeclarator.new(val[0], val[2])
1160
+ result = AnsiFunctionDeclarator.new(val[0], val[3])
1138
1161
  result.head_token = val[0].head_token
1139
- result.tail_token = val[3]
1162
+ result.tail_token = val[4]
1140
1163
  }
1141
1164
  | direct_declarator "(" identifier_list ")"
1142
1165
  {
@@ -1224,6 +1247,7 @@ parameter_declaration
1224
1247
  : declaration_specifiers declarator
1225
1248
  {
1226
1249
  checkpoint(val[0].location)
1250
+ @lexer.enable_identifier_translation
1227
1251
  result = ParameterDeclaration.new(val[0], val[1])
1228
1252
  result.head_token = val[0].head_token
1229
1253
  result.tail_token = val[1].tail_token
@@ -1231,6 +1255,7 @@ parameter_declaration
1231
1255
  | declaration_specifiers abstract_declarator
1232
1256
  {
1233
1257
  checkpoint(val[0].location)
1258
+ @lexer.enable_identifier_translation
1234
1259
  result = ParameterDeclaration.new(val[0], val[1])
1235
1260
  result.head_token = val[0].head_token
1236
1261
  result.tail_token = val[1].tail_token
@@ -1238,7 +1263,7 @@ parameter_declaration
1238
1263
  | declaration_specifiers
1239
1264
  {
1240
1265
  checkpoint(val[0].location)
1241
- @lexer.start_identifier_translation
1266
+ @lexer.enable_identifier_translation
1242
1267
  result = ParameterDeclaration.new(val[0], nil)
1243
1268
  result.head_token = val[0].head_token
1244
1269
  result.tail_token = val[0].tail_token
@@ -1262,7 +1287,7 @@ type_name
1262
1287
  : specifier_qualifier_list
1263
1288
  {
1264
1289
  checkpoint(val[0].location)
1265
- @lexer.start_identifier_translation
1290
+ @lexer.enable_identifier_translation
1266
1291
  result = TypeName.new(val[0], nil, @sym_tbl)
1267
1292
  result.head_token = val[0].head_token
1268
1293
  result.tail_token = val[0].tail_token
@@ -1270,6 +1295,7 @@ type_name
1270
1295
  | specifier_qualifier_list abstract_declarator
1271
1296
  {
1272
1297
  checkpoint(val[0].location)
1298
+ @lexer.enable_identifier_translation
1273
1299
  result = TypeName.new(val[0], val[1], @sym_tbl)
1274
1300
  result.head_token = val[0].head_token
1275
1301
  result.tail_token = val[1].tail_token
@@ -1280,7 +1306,7 @@ abstract_declarator
1280
1306
  : pointer
1281
1307
  {
1282
1308
  checkpoint(val[0].first.location)
1283
- @lexer.start_identifier_translation
1309
+ @lexer.enable_identifier_translation
1284
1310
  result = PointerAbstractDeclarator.new(nil, val[0])
1285
1311
  result.head_token = val[0].first
1286
1312
  result.tail_token = val[0].last
@@ -1289,6 +1315,7 @@ abstract_declarator
1289
1315
  | pointer direct_abstract_declarator
1290
1316
  {
1291
1317
  checkpoint(val[0].first.location)
1318
+ @lexer.enable_identifier_translation
1292
1319
  result = PointerAbstractDeclarator.new(val[1], val[0])
1293
1320
  result.head_token = val[0].first
1294
1321
  result.tail_token = val[1].tail_token
@@ -1306,7 +1333,6 @@ direct_abstract_declarator
1306
1333
  : "(" abstract_declarator ")"
1307
1334
  {
1308
1335
  checkpoint(val[0].location)
1309
- @lexer.start_identifier_translation
1310
1336
  result = GroupedAbstractDeclarator.new(val[1])
1311
1337
  result.head_token = val[0]
1312
1338
  result.tail_token = val[2]
@@ -1314,7 +1340,6 @@ direct_abstract_declarator
1314
1340
  | "[" "]"
1315
1341
  {
1316
1342
  checkpoint(val[0].location)
1317
- @lexer.start_identifier_translation
1318
1343
  result = ArrayAbstractDeclarator.new(nil, nil)
1319
1344
  result.head_token = val[0]
1320
1345
  result.tail_token = val[1]
@@ -1322,7 +1347,6 @@ direct_abstract_declarator
1322
1347
  | "[" assignment_expression "]"
1323
1348
  {
1324
1349
  checkpoint(val[0].location)
1325
- @lexer.start_identifier_translation
1326
1350
  val[1].full = true
1327
1351
  result = ArrayAbstractDeclarator.new(nil, val[1])
1328
1352
  result.head_token = val[0]
@@ -1346,7 +1370,6 @@ direct_abstract_declarator
1346
1370
  | "[" "*" "]"
1347
1371
  {
1348
1372
  checkpoint(val[0].location)
1349
- @lexer.start_identifier_translation
1350
1373
  result = ArrayAbstractDeclarator.new(nil, nil)
1351
1374
  result.head_token = val[0]
1352
1375
  result.tail_token = val[2]
@@ -1361,12 +1384,11 @@ direct_abstract_declarator
1361
1384
  | "(" ")"
1362
1385
  {
1363
1386
  checkpoint(val[0].location)
1364
- @lexer.start_identifier_translation
1365
1387
  result = FunctionAbstractDeclarator.new(nil, nil)
1366
1388
  result.head_token = val[0]
1367
1389
  result.tail_token = val[1]
1368
1390
  }
1369
- | "(" { @lexer.start_identifier_translation } parameter_type_list ")"
1391
+ | "(" { @lexer.enable_identifier_translation } parameter_type_list ")"
1370
1392
  {
1371
1393
  checkpoint(val[0].location)
1372
1394
  result = FunctionAbstractDeclarator.new(nil, val[2])
@@ -1376,17 +1398,17 @@ direct_abstract_declarator
1376
1398
  | direct_abstract_declarator "(" ")"
1377
1399
  {
1378
1400
  checkpoint(val[0].location)
1379
- @lexer.start_identifier_translation
1380
1401
  result = FunctionAbstractDeclarator.new(val[0], nil)
1381
1402
  result.head_token = val[0].head_token
1382
1403
  result.tail_token = val[2]
1383
1404
  }
1384
- | direct_abstract_declarator "(" parameter_type_list ")"
1405
+ | direct_abstract_declarator "(" { @lexer.enable_identifier_translation }
1406
+ parameter_type_list ")"
1385
1407
  {
1386
1408
  checkpoint(val[0].location)
1387
- result = FunctionAbstractDeclarator.new(val[0], val[2])
1409
+ result = FunctionAbstractDeclarator.new(val[0], val[3])
1388
1410
  result.head_token = val[0].head_token
1389
- result.tail_token = val[3]
1411
+ result.tail_token = val[4]
1390
1412
  }
1391
1413
  ;
1392
1414
 
@@ -1472,7 +1494,7 @@ statement
1472
1494
  ;
1473
1495
 
1474
1496
  labeled_statement
1475
- : IDENTIFIER ":" statement
1497
+ : label_name ":" statement
1476
1498
  {
1477
1499
  checkpoint(val[0].location)
1478
1500
  result = GenericLabeledStatement.new(val[0], val[2])
@@ -1496,6 +1518,14 @@ labeled_statement
1496
1518
  }
1497
1519
  ;
1498
1520
 
1521
+ label_name
1522
+ : IDENTIFIER
1523
+ | TYPEDEF_NAME
1524
+ {
1525
+ result = val[0].class.new(:IDENTIFIER, val[0].value, val[0].location)
1526
+ }
1527
+ ;
1528
+
1499
1529
  compound_statement
1500
1530
  : "{" "}"
1501
1531
  {
@@ -1627,7 +1657,7 @@ iteration_statement
1627
1657
  ;
1628
1658
 
1629
1659
  jump_statement
1630
- : GOTO IDENTIFIER ";"
1660
+ : GOTO label_name ";"
1631
1661
  {
1632
1662
  checkpoint(val[0].location)
1633
1663
  result = GotoStatement.new(val[1])
@@ -53,7 +53,7 @@ module Cc1 #:nodoc:
53
53
 
54
54
  private
55
55
  def do_execute(phase_ctxt, *)
56
- phase_ctxt[:cc1_visitor] = SyntaxTreeMulticastVisitor.new
56
+ phase_ctxt[:cc1_ast_traversal] = SyntaxTreeMulticastVisitor.new
57
57
  phase_ctxt[:cc1_parser] = Parser.new(phase_ctxt)
58
58
  end
59
59
  end
@@ -65,9 +65,9 @@ module Cc1 #:nodoc:
65
65
 
66
66
  private
67
67
  def do_execute(phase_ctxt, *)
68
- phase_ctxt[:cc1_syntax_tree] = phase_ctxt[:cc1_parser].execute
68
+ phase_ctxt[:cc1_ast] = phase_ctxt[:cc1_parser].execute
69
69
  ensure
70
- phase_ctxt[:cc1_token_array] = phase_ctxt[:cc1_parser].token_array
70
+ phase_ctxt[:cc1_tokens] = phase_ctxt[:cc1_parser].token_array
71
71
  DebugUtil.dump_token_array(phase_ctxt)
72
72
  end
73
73
  end
@@ -80,8 +80,7 @@ module Cc1 #:nodoc:
80
80
  private
81
81
  def do_execute(phase_ctxt, *)
82
82
  resolver = StaticTypeResolver.new(TypeTable.new(traits, monitor, logger))
83
- phase_ctxt[:cc1_type_table] =
84
- resolver.resolve(phase_ctxt[:cc1_syntax_tree])
83
+ phase_ctxt[:cc1_type_table] = resolver.resolve(phase_ctxt[:cc1_ast])
85
84
  end
86
85
  end
87
86
 
@@ -104,8 +103,7 @@ module Cc1 #:nodoc:
104
103
 
105
104
  private
106
105
  def do_execute(phase_ctxt, *)
107
- Program.new(phase_ctxt[:cc1_interpreter],
108
- phase_ctxt[:cc1_syntax_tree]).execute
106
+ Program.new(phase_ctxt[:cc1_interpreter], phase_ctxt[:cc1_ast]).execute
109
107
  ValueDomain.clear_memos
110
108
  ensure
111
109
  DebugUtil.dump_syntax_tree(phase_ctxt)
@@ -119,7 +117,7 @@ module Cc1 #:nodoc:
119
117
 
120
118
  private
121
119
  def do_execute(phase_ctxt, *)
122
- phase_ctxt[:cc1_syntax_tree].accept(phase_ctxt[:cc1_visitor])
120
+ phase_ctxt[:cc1_ast].accept(phase_ctxt[:cc1_ast_traversal])
123
121
  end
124
122
  end
125
123
 
@@ -439,6 +439,19 @@ module Cc1 #:nodoc:
439
439
  module_function :collect_constant_specifiers
440
440
  end
441
441
 
442
+ module InterpSyntaxBridge
443
+ # NOTE: InterpreterMediator includes this module to bridge constant
444
+ # designator collector to this layer.
445
+
446
+ def _interp_syntax_bridge_
447
+ {
448
+ enumerator_designators: method(:enumerator_designators),
449
+ function_designators: method(:function_designators),
450
+ variable_designators: method(:variable_designators)
451
+ }
452
+ end
453
+ end
454
+
442
455
  class Expression < SyntaxNode
443
456
  def initialize
444
457
  super
@@ -470,8 +483,8 @@ module Cc1 #:nodoc:
470
483
  subclass_responsibility
471
484
  end
472
485
 
473
- def constant?(enum_tbl)
474
- object_specifiers.all? { |os| enum_tbl.lookup(os.identifier.value) }
486
+ def constant?(interp_bridge)
487
+ ExpressionConstancy.new(interp_bridge).check(self)
475
488
  end
476
489
 
477
490
  def logical?
@@ -2321,9 +2334,9 @@ module Cc1 #:nodoc:
2321
2334
  type_dcls = []
2322
2335
 
2323
2336
  dcl_specs.type_specifiers.each do |type_spec|
2324
- visitor = TypeDeclarationBuilder.new(sym_tbl)
2325
- type_spec.accept(visitor)
2326
- type_dcls.concat(visitor.type_declarations)
2337
+ builder = TypeDeclarationBuilder.new(sym_tbl)
2338
+ type_spec.accept(builder)
2339
+ type_dcls.concat(builder.type_declarations)
2327
2340
  end
2328
2341
 
2329
2342
  if sc = dcl_specs.storage_class_specifier and sc.type == :TYPEDEF
@@ -3991,10 +4004,10 @@ module Cc1 #:nodoc:
3991
4004
  def build_type_declaration(dcl_specs, sym_tbl)
3992
4005
  return nil unless dcl_specs
3993
4006
  dcl_specs.type_specifiers.each do |type_spec|
3994
- visitor = TypeDeclarationBuilder.new(sym_tbl)
3995
- type_spec.accept(visitor)
3996
- unless visitor.type_declarations.empty?
3997
- return visitor.type_declarations.first
4007
+ builder = TypeDeclarationBuilder.new(sym_tbl)
4008
+ type_spec.accept(builder)
4009
+ unless builder.type_declarations.empty?
4010
+ return builder.type_declarations.first
3998
4011
  end
3999
4012
  end
4000
4013
  nil
@@ -4191,10 +4204,10 @@ module Cc1 #:nodoc:
4191
4204
  private
4192
4205
  def build_type_declaration(spec_qual_list, sym_tbl)
4193
4206
  spec_qual_list.type_specifiers.each do |type_spec|
4194
- visitor = TypeDeclarationBuilder.new(sym_tbl)
4195
- type_spec.accept(visitor)
4196
- unless visitor.type_declarations.empty?
4197
- return visitor.type_declarations.first
4207
+ builder = TypeDeclarationBuilder.new(sym_tbl)
4208
+ type_spec.accept(builder)
4209
+ unless builder.type_declarations.empty?
4210
+ return builder.type_declarations.first
4198
4211
  end
4199
4212
  end
4200
4213
  nil
@@ -5470,10 +5483,16 @@ module Cc1 #:nodoc:
5470
5483
 
5471
5484
  attr_reader :expressions
5472
5485
 
5473
- def push_expression(expression)
5474
- @expressions.push(expression)
5486
+ def push_expression(expr)
5487
+ @expressions.push(expr)
5475
5488
  end
5489
+ private :push_expression
5476
5490
 
5491
+ alias :visit_error_expression :push_expression
5492
+ alias :visit_object_specifier :push_expression
5493
+ alias :visit_constant_specifier :push_expression
5494
+ alias :visit_string_literal_specifier :push_expression
5495
+ alias :visit_null_constant_specifier :push_expression
5477
5496
  alias :visit_grouped_expression :push_expression
5478
5497
  alias :visit_array_subscript_expression :push_expression
5479
5498
  alias :visit_function_call_expression :push_expression
@@ -5490,7 +5509,9 @@ module Cc1 #:nodoc:
5490
5509
  alias :visit_indirection_expression :push_expression
5491
5510
  alias :visit_unary_arithmetic_expression :push_expression
5492
5511
  alias :visit_sizeof_expression :push_expression
5512
+ alias :visit_sizeof_type_expression :push_expression
5493
5513
  alias :visit_alignof_expression :push_expression
5514
+ alias :visit_alignof_type_expression :push_expression
5494
5515
  alias :visit_cast_expression :push_expression
5495
5516
  alias :visit_multiplicative_expression :push_expression
5496
5517
  alias :visit_additive_expression :push_expression
@@ -5505,8 +5526,6 @@ module Cc1 #:nodoc:
5505
5526
  alias :visit_conditional_expression :push_expression
5506
5527
  alias :visit_simple_assignment_expression :push_expression
5507
5528
  alias :visit_compound_assignment_expression :push_expression
5508
-
5509
- private :push_expression
5510
5529
  end
5511
5530
 
5512
5531
  class ConditionalExpressionExtractor < SyntaxTreeVisitor
@@ -5521,5 +5540,39 @@ module Cc1 #:nodoc:
5521
5540
  end
5522
5541
  end
5523
5542
 
5543
+ class ExpressionConstancy < SyntaxTreeVisitor
5544
+ def initialize(interp_bridge)
5545
+ @interp_bridge = interp_bridge
5546
+ end
5547
+
5548
+ def check(expr)
5549
+ catch(:constancy) { expr.accept(self); true }
5550
+ end
5551
+
5552
+ def visit_object_specifier(node)
5553
+ var_designators = @interp_bridge[:variable_designators][]
5554
+ if var_designators.include?(node.identifier.value)
5555
+ break_as_inconstant
5556
+ end
5557
+ end
5558
+
5559
+ def visit_address_expression(node)
5560
+ # NOTE: To treat address of variables as an address-constant.
5561
+ end
5562
+
5563
+ def break_as_inconstant(*)
5564
+ throw(:constancy, false)
5565
+ end
5566
+ private :break_as_inconstant
5567
+
5568
+ alias :visit_function_call_expression :break_as_inconstant
5569
+ alias :visit_postfix_increment_expression :break_as_inconstant
5570
+ alias :visit_postfix_decrement_expression :break_as_inconstant
5571
+ alias :visit_prefix_increment_expression :break_as_inconstant
5572
+ alias :visit_prefix_decrement_expression :break_as_inconstant
5573
+ alias :visit_simple_assignment_expression :break_as_inconstant
5574
+ alias :visit_compound_assignment_expression :break_as_inconstant
5575
+ end
5576
+
5524
5577
  end
5525
5578
  end
@@ -72,8 +72,8 @@ module Cc1 #:nodoc:
72
72
  ast_fpath = ast_fname.expand_path(phase_ctxt.msg_fpath.dirname)
73
73
 
74
74
  File.open(ast_fpath, "w") do |io|
75
- if phase_ctxt[:cc1_syntax_tree]
76
- PP.pp(phase_ctxt[:cc1_syntax_tree], io)
75
+ if phase_ctxt[:cc1_ast]
76
+ PP.pp(phase_ctxt[:cc1_ast], io)
77
77
  end
78
78
  end
79
79
  end
@@ -86,8 +86,8 @@ module Cc1 #:nodoc:
86
86
  tok_fpath = tok_fname.expand_path(phase_ctxt.msg_fpath.dirname)
87
87
 
88
88
  File.open(tok_fpath, "w") do |io|
89
- if phase_ctxt[:cc1_token_array]
90
- phase_ctxt[:cc1_token_array].each { |tok| io.puts(tok.inspect) }
89
+ if phase_ctxt[:cc1_tokens]
90
+ phase_ctxt[:cc1_tokens].each { |tok| io.puts(tok.inspect) }
91
91
  end
92
92
  end
93
93
  end
data/lib/adlint/code.rb CHANGED
@@ -123,7 +123,7 @@ module AdLint #:nodoc:
123
123
 
124
124
  # == DESCRIPTION
125
125
  # Function declaration information.
126
- class FuncDcl < CodeStructure
126
+ class FunDcl < CodeStructure
127
127
  # === DESCRIPTION
128
128
  # Constructs the function declaration information.
129
129
  #
@@ -188,7 +188,7 @@ module AdLint #:nodoc:
188
188
 
189
189
  # == DESCRIPTION
190
190
  # Function definition information.
191
- class FuncDef < CodeStructure
191
+ class FunDef < CodeStructure
192
192
  # === DESCRIPTION
193
193
  # Constructs the function definition information.
194
194
  #
@@ -350,7 +350,7 @@ module AdLint #:nodoc:
350
350
 
351
351
  # == DESCRIPTION
352
352
  # Function call information.
353
- class Call < CodeStructure
353
+ class Funcall < CodeStructure
354
354
  # === DESCRIPTION
355
355
  # Constructs the function call informatin.
356
356
  #
@@ -404,7 +404,7 @@ module AdLint #:nodoc:
404
404
  end
405
405
  end
406
406
 
407
- class XRefFunc < CodeStructure
407
+ class XRefFun < CodeStructure
408
408
  # === DESCRIPTION
409
409
  # Constructs the cross reference information.
410
410
  #
@@ -460,13 +460,23 @@ module AdLint #:nodoc:
460
460
  end
461
461
 
462
462
  class FunctionId
463
- def initialize(name, sig)
464
- @name, @signature = name, sig
463
+ def self.of_ctors_section
464
+ # NOTE: To represent an object referrer of non-function in case of global
465
+ # function table initialization.
466
+ self.new(nil, nil)
467
+ end
468
+
469
+ def initialize(name, sig_str)
470
+ @name, @signature = name, sig_str
465
471
  end
466
472
 
467
473
  attr_reader :name
468
474
  attr_reader :signature
469
475
 
476
+ def named?
477
+ !@name.nil?
478
+ end
479
+
470
480
  def to_a
471
481
  [@name, @signature]
472
482
  end