adlint 3.0.4 → 3.0.8

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -96,8 +96,8 @@ module CBuiltin #:nodoc:
96
96
 
97
97
  def initialize(phase_ctxt)
98
98
  super
99
- visitor = phase_ctxt[:cc1_visitor]
100
- visitor.enter_union_type_declaration += T(:check)
99
+ traversal = phase_ctxt[:cc1_ast_traversal]
100
+ traversal.enter_union_type_declaration += T(:check)
101
101
  end
102
102
 
103
103
  private
@@ -122,8 +122,8 @@ module CBuiltin #:nodoc:
122
122
 
123
123
  def initialize(phase_ctxt)
124
124
  super
125
- visitor = phase_ctxt[:cc1_visitor]
126
- visitor.enter_kandr_function_definition += T(:check)
125
+ traversal = phase_ctxt[:cc1_ast_traversal]
126
+ traversal.enter_kandr_function_definition += T(:check)
127
127
  end
128
128
 
129
129
  def check(node)
@@ -222,12 +222,12 @@ module CBuiltin #:nodoc:
222
222
 
223
223
  def initialize(phase_ctxt)
224
224
  super
225
- visitor = phase_ctxt[:cc1_visitor]
226
- visitor.enter_ansi_function_definition += T(:start_function)
227
- visitor.enter_kandr_function_definition += T(:start_function)
228
- visitor.leave_ansi_function_definition += T(:end_function)
229
- visitor.leave_kandr_function_definition += T(:end_function)
230
- visitor.enter_return_statement += T(:check)
225
+ traversal = phase_ctxt[:cc1_ast_traversal]
226
+ traversal.enter_ansi_function_definition += T(:start_function)
227
+ traversal.enter_kandr_function_definition += T(:start_function)
228
+ traversal.leave_ansi_function_definition += T(:end_function)
229
+ traversal.leave_kandr_function_definition += T(:end_function)
230
+ traversal.enter_return_statement += T(:check)
231
231
  @cur_fun = nil
232
232
  end
233
233
 
@@ -320,8 +320,8 @@ module CBuiltin #:nodoc:
320
320
 
321
321
  def initialize(phase_ctxt)
322
322
  super
323
- visitor = phase_ctxt[:cc1_visitor]
324
- visitor.enter_relational_expression += T(:check)
323
+ traversal = phase_ctxt[:cc1_ast_traversal]
324
+ traversal.enter_relational_expression += T(:check)
325
325
  end
326
326
 
327
327
  private
@@ -371,8 +371,8 @@ module CBuiltin #:nodoc:
371
371
 
372
372
  def initialize(phase_ctxt)
373
373
  super
374
- visitor = phase_ctxt[:cc1_visitor]
375
- visitor.enter_and_expression += T(:check)
374
+ traversal = phase_ctxt[:cc1_ast_traversal]
375
+ traversal.enter_and_expression += T(:check)
376
376
  end
377
377
 
378
378
  private
@@ -392,8 +392,8 @@ module CBuiltin #:nodoc:
392
392
 
393
393
  def initialize(phase_ctxt)
394
394
  super
395
- visitor = phase_ctxt[:cc1_visitor]
396
- visitor.enter_inclusive_or_expression += T(:check)
395
+ traversal = phase_ctxt[:cc1_ast_traversal]
396
+ traversal.enter_inclusive_or_expression += T(:check)
397
397
  end
398
398
 
399
399
  private
@@ -413,14 +413,14 @@ module CBuiltin #:nodoc:
413
413
 
414
414
  def initialize(phase_ctxt)
415
415
  super
416
- visitor = phase_ctxt[:cc1_visitor]
417
- visitor.enter_additive_expression += T(:check)
418
- visitor.enter_multiplicative_expression += T(:check)
419
- visitor.enter_shift_expression += T(:check)
420
- visitor.enter_and_expression += T(:check)
421
- visitor.enter_exclusive_or_expression += T(:check)
422
- visitor.enter_inclusive_or_expression += T(:check)
423
- visitor.enter_compound_assignment_expression += T(:check)
416
+ traversal = phase_ctxt[:cc1_ast_traversal]
417
+ traversal.enter_additive_expression += T(:check)
418
+ traversal.enter_multiplicative_expression += T(:check)
419
+ traversal.enter_shift_expression += T(:check)
420
+ traversal.enter_and_expression += T(:check)
421
+ traversal.enter_exclusive_or_expression += T(:check)
422
+ traversal.enter_inclusive_or_expression += T(:check)
423
+ traversal.enter_compound_assignment_expression += T(:check)
424
424
  end
425
425
 
426
426
  private
@@ -489,8 +489,8 @@ module CBuiltin #:nodoc:
489
489
 
490
490
  def initialize(phase_ctxt)
491
491
  super
492
- visitor = phase_ctxt[:cc1_visitor]
493
- visitor.enter_logical_and_expression += T(:check)
492
+ traversal = phase_ctxt[:cc1_ast_traversal]
493
+ traversal.enter_logical_and_expression += T(:check)
494
494
  end
495
495
 
496
496
  private
@@ -512,8 +512,8 @@ module CBuiltin #:nodoc:
512
512
 
513
513
  def initialize(phase_ctxt)
514
514
  super
515
- visitor = phase_ctxt[:cc1_visitor]
516
- visitor.enter_logical_or_expression += T(:check)
515
+ traversal = phase_ctxt[:cc1_ast_traversal]
516
+ traversal.enter_logical_or_expression += T(:check)
517
517
  end
518
518
 
519
519
  private
@@ -535,9 +535,9 @@ module CBuiltin #:nodoc:
535
535
 
536
536
  def initialize(phase_ctxt)
537
537
  super
538
- visitor = phase_ctxt[:cc1_visitor]
539
- visitor.enter_logical_and_expression += T(:check)
540
- visitor.enter_logical_or_expression += T(:check)
538
+ traversal = phase_ctxt[:cc1_ast_traversal]
539
+ traversal.enter_logical_and_expression += T(:check)
540
+ traversal.enter_logical_or_expression += T(:check)
541
541
  end
542
542
 
543
543
  private
@@ -576,11 +576,11 @@ module CBuiltin #:nodoc:
576
576
 
577
577
  def initialize(phase_ctxt)
578
578
  super
579
- visitor = phase_ctxt[:cc1_visitor]
580
- visitor.enter_switch_statement += T(:enter_switch_statement)
581
- visitor.leave_switch_statement += T(:check)
582
- visitor.enter_case_labeled_statement += T(:add_exec_path)
583
- visitor.enter_default_labeled_statement += T(:add_exec_path)
579
+ traversal = phase_ctxt[:cc1_ast_traversal]
580
+ traversal.enter_switch_statement += T(:enter_switch_statement)
581
+ traversal.leave_switch_statement += T(:check)
582
+ traversal.enter_case_labeled_statement += T(:add_exec_path)
583
+ traversal.enter_default_labeled_statement += T(:add_exec_path)
584
584
  @exec_path_nums = []
585
585
  end
586
586
 
@@ -610,9 +610,9 @@ module CBuiltin #:nodoc:
610
610
 
611
611
  def initialize(phase_ctxt)
612
612
  super
613
- visitor = phase_ctxt[:cc1_visitor]
614
- visitor.enter_struct_type_declaration += T(:check)
615
- visitor.enter_union_type_declaration += T(:check)
613
+ traversal = phase_ctxt[:cc1_ast_traversal]
614
+ traversal.enter_struct_type_declaration += T(:check)
615
+ traversal.enter_union_type_declaration += T(:check)
616
616
  end
617
617
 
618
618
  private
@@ -630,20 +630,20 @@ module CBuiltin #:nodoc:
630
630
 
631
631
  def initialize(phase_ctxt)
632
632
  super
633
- visitor = phase_ctxt[:cc1_visitor]
634
- visitor.enter_function_declaration += T(:check_function_name)
635
- visitor.enter_variable_declaration += T(:check_variable_name)
636
- visitor.enter_variable_definition += T(:check_variable_name)
637
- visitor.enter_parameter_definition += T(:check_variable_name)
638
- visitor.enter_typedef_declaration += T(:check_typedef_name)
639
- visitor.enter_struct_type_declaration += T(:check_tag_name)
640
- visitor.enter_union_type_declaration += T(:check_tag_name)
641
- visitor.enter_enum_type_declaration += T(:check_tag_name)
642
- visitor.enter_enumerator += T(:check_enumerator_name)
643
- visitor.enter_kandr_function_definition += T(:enter_function)
644
- visitor.enter_ansi_function_definition += T(:enter_function)
645
- visitor.leave_kandr_function_definition += T(:leave_function)
646
- visitor.leave_ansi_function_definition += T(:leave_function)
633
+ traversal = phase_ctxt[:cc1_ast_traversal]
634
+ traversal.enter_function_declaration += T(:check_function_name)
635
+ traversal.enter_variable_declaration += T(:check_variable_name)
636
+ traversal.enter_variable_definition += T(:check_variable_name)
637
+ traversal.enter_parameter_definition += T(:check_variable_name)
638
+ traversal.enter_typedef_declaration += T(:check_typedef_name)
639
+ traversal.enter_struct_type_declaration += T(:check_tag_name)
640
+ traversal.enter_union_type_declaration += T(:check_tag_name)
641
+ traversal.enter_enum_type_declaration += T(:check_tag_name)
642
+ traversal.enter_enumerator += T(:check_enumerator_name)
643
+ traversal.enter_kandr_function_definition += T(:enter_function)
644
+ traversal.enter_ansi_function_definition += T(:enter_function)
645
+ traversal.leave_kandr_function_definition += T(:leave_function)
646
+ traversal.leave_ansi_function_definition += T(:leave_function)
647
647
  @function_def_level = 0
648
648
  end
649
649
 
@@ -725,12 +725,12 @@ module CBuiltin #:nodoc:
725
725
 
726
726
  def initialize(phase_ctxt)
727
727
  super
728
- visitor = phase_ctxt[:cc1_visitor]
729
- visitor.enter_generic_labeled_statement += T(:check)
730
- visitor.enter_ansi_function_definition += T(:enter_function)
731
- visitor.leave_ansi_function_definition += T(:leave_function)
732
- visitor.enter_kandr_function_definition += T(:enter_function)
733
- visitor.leave_kandr_function_definition += T(:leave_function)
728
+ traversal = phase_ctxt[:cc1_ast_traversal]
729
+ traversal.enter_generic_labeled_statement += T(:check)
730
+ traversal.enter_ansi_function_definition += T(:enter_function)
731
+ traversal.leave_ansi_function_definition += T(:leave_function)
732
+ traversal.enter_kandr_function_definition += T(:enter_function)
733
+ traversal.leave_kandr_function_definition += T(:leave_function)
734
734
  @labels = nil
735
735
  end
736
736
 
@@ -763,10 +763,10 @@ module CBuiltin #:nodoc:
763
763
 
764
764
  def initialize(phase_ctxt)
765
765
  super
766
- visitor = phase_ctxt[:cc1_visitor]
767
- visitor.enter_ansi_function_definition += T(:check)
768
- visitor.enter_kandr_function_definition += T(:check)
769
- visitor.enter_function_declaration += T(:check)
766
+ traversal = phase_ctxt[:cc1_ast_traversal]
767
+ traversal.enter_ansi_function_definition += T(:check)
768
+ traversal.enter_kandr_function_definition += T(:check)
769
+ traversal.enter_function_declaration += T(:check)
770
770
  end
771
771
 
772
772
  private
@@ -878,13 +878,13 @@ module CBuiltin #:nodoc:
878
878
 
879
879
  def initialize(phase_ctxt)
880
880
  super
881
- visitor = phase_ctxt[:cc1_visitor]
882
- visitor.enter_ansi_function_definition += T(:enter_function)
883
- visitor.enter_kandr_function_definition += T(:enter_function)
884
- visitor.enter_compound_statement += T(:enter_compound_stmt)
885
- visitor.leave_compound_statement += T(:leave_compound_stmt)
886
- visitor.enter_if_else_statement += T(:enter_if_else_stmt)
887
- visitor.leave_if_else_statement += T(:leave_if_else_stmt)
881
+ traversal = phase_ctxt[:cc1_ast_traversal]
882
+ traversal.enter_ansi_function_definition += T(:enter_function)
883
+ traversal.enter_kandr_function_definition += T(:enter_function)
884
+ traversal.enter_compound_statement += T(:enter_compound_stmt)
885
+ traversal.leave_compound_statement += T(:leave_compound_stmt)
886
+ traversal.enter_if_else_statement += T(:enter_if_else_stmt)
887
+ traversal.leave_if_else_statement += T(:leave_if_else_stmt)
888
888
  @if_else_stmt_chain_stack = []
889
889
  end
890
890
 
@@ -942,8 +942,8 @@ module CBuiltin #:nodoc:
942
942
 
943
943
  def initialize(phase_ctxt)
944
944
  super
945
- visitor = phase_ctxt[:cc1_visitor]
946
- visitor.enter_goto_statement += T(:warn_goto)
945
+ traversal = phase_ctxt[:cc1_ast_traversal]
946
+ traversal.enter_goto_statement += T(:warn_goto)
947
947
  end
948
948
 
949
949
  private
@@ -43,11 +43,11 @@ module CBuiltin #:nodoc:
43
43
 
44
44
  def initialize(phase_ctxt)
45
45
  super
46
- visitor = phase_ctxt[:cc1_visitor]
47
- visitor.enter_typedef_declaration += T(:extract_typedef)
48
- visitor.enter_struct_type_declaration += T(:extract_struct)
49
- visitor.enter_union_type_declaration += T(:extract_union)
50
- visitor.enter_enum_type_declaration += T(:extract_enum)
46
+ traversal = phase_ctxt[:cc1_ast_traversal]
47
+ traversal.enter_typedef_declaration += T(:extract_typedef)
48
+ traversal.enter_struct_type_declaration += T(:extract_struct)
49
+ traversal.enter_union_type_declaration += T(:extract_union)
50
+ traversal.enter_enum_type_declaration += T(:extract_enum)
51
51
  end
52
52
 
53
53
  private
@@ -96,7 +96,7 @@ module CBuiltin #:nodoc:
96
96
  end
97
97
  end
98
98
 
99
- class FuncDeclExtraction < CodeExtraction
99
+ class FunDclExtraction < CodeExtraction
100
100
  def_registrant_phase Cc1::Prepare2Phase
101
101
 
102
102
  def initialize(phase_ctxt)
@@ -115,22 +115,22 @@ module CBuiltin #:nodoc:
115
115
 
116
116
  def extract_explicit_dcl(fun_dcl, fun)
117
117
  if fun.declared_as_extern?
118
- FUNCDCL(fun_dcl.identifier.location, "X",
119
- @block_level == 0 ? "F" : "B", "E",
120
- FunctionId.new(fun_dcl.identifier.value,
121
- fun_dcl.signature.to_s))
118
+ FUNDCL(fun_dcl.identifier.location, "X",
119
+ @block_level == 0 ? "F" : "B", "E",
120
+ FunctionId.new(fun_dcl.identifier.value,
121
+ fun_dcl.signature.to_s))
122
122
  else
123
- FUNCDCL(fun_dcl.identifier.location, "I",
124
- @block_level == 0 ? "F" : "B", "E",
125
- FunctionId.new(fun_dcl.identifier.value,
126
- fun_dcl.signature.to_s))
123
+ FUNDCL(fun_dcl.identifier.location, "I",
124
+ @block_level == 0 ? "F" : "B", "E",
125
+ FunctionId.new(fun_dcl.identifier.value,
126
+ fun_dcl.signature.to_s))
127
127
  end
128
128
  end
129
129
 
130
130
  def extract_implicit_dcl(expr, fun)
131
131
  if fun.named?
132
- FUNCDCL(expr.location, "X", "F", "I",
133
- FunctionId.new(fun.name, fun.signature.to_s))
132
+ FUNDCL(expr.location, "X", "F", "I",
133
+ FunctionId.new(fun.name, fun.signature.to_s))
134
134
  end
135
135
  end
136
136
 
@@ -217,7 +217,7 @@ module CBuiltin #:nodoc:
217
217
  end
218
218
  end
219
219
 
220
- class FuncDefExtraction < CodeExtraction
220
+ class FunDefExtraction < CodeExtraction
221
221
  def_registrant_phase Cc1::Prepare2Phase
222
222
 
223
223
  def initialize(phase_ctxt)
@@ -234,9 +234,9 @@ module CBuiltin #:nodoc:
234
234
  fun_id = FunctionId.new(fun_def.identifier.value, fun_def.signature.to_s)
235
235
  case
236
236
  when fun.declared_as_extern?
237
- FUNCDEF(fun_def.identifier.location, "X", "F", fun_id, fun_def.lines)
237
+ FUNDEF(fun_def.identifier.location, "X", "F", fun_id, fun_def.lines)
238
238
  when fun.declared_as_static?
239
- FUNCDEF(fun_def.identifier.location, "I", "F", fun_id, fun_def.lines)
239
+ FUNDEF(fun_def.identifier.location, "I", "F", fun_id, fun_def.lines)
240
240
  end
241
241
  end
242
242
  end
@@ -246,8 +246,8 @@ module CBuiltin #:nodoc:
246
246
 
247
247
  def initialize(phase_ctxt)
248
248
  super
249
- visitor = phase_ctxt[:cc1_visitor]
250
- visitor.enter_generic_labeled_statement += T(:extract)
249
+ traversal = phase_ctxt[:cc1_ast_traversal]
250
+ traversal.enter_generic_labeled_statement += T(:extract)
251
251
  end
252
252
 
253
253
  private
@@ -264,8 +264,8 @@ module CBuiltin #:nodoc:
264
264
 
265
265
  def initialize(phase_ctxt)
266
266
  super
267
- visitor = phase_ctxt[:cc1_visitor]
268
- visitor.enter_variable_definition += T(:extract)
267
+ traversal = phase_ctxt[:cc1_ast_traversal]
268
+ traversal.enter_variable_definition += T(:extract)
269
269
  end
270
270
 
271
271
  private
@@ -285,9 +285,9 @@ module CBuiltin #:nodoc:
285
285
 
286
286
  def initialize(phase_ctxt)
287
287
  super
288
- visitor = phase_ctxt[:cc1_visitor]
289
- visitor.enter_simple_assignment_expression += T(:extract)
290
- visitor.enter_compound_assignment_expression += T(:extract)
288
+ traversal = phase_ctxt[:cc1_ast_traversal]
289
+ traversal.enter_simple_assignment_expression += T(:extract)
290
+ traversal.enter_compound_assignment_expression += T(:extract)
291
291
  end
292
292
 
293
293
  private
@@ -304,13 +304,14 @@ module CBuiltin #:nodoc:
304
304
  end
305
305
  end
306
306
 
307
- class FuncCallExtraction < CodeExtraction
307
+ class FuncallExtraction < CodeExtraction
308
308
  def_registrant_phase Cc1::Prepare2Phase
309
309
 
310
310
  def initialize(phase_ctxt)
311
311
  super
312
312
  @interp = phase_ctxt[:cc1_interpreter]
313
313
  @interp.on_function_started += T(:update_caller)
314
+ @interp.on_function_ended += T(:clear_caller)
314
315
  @interp.on_function_call_expr_evaled += T(:extract_function_call)
315
316
  @caller = nil
316
317
  end
@@ -323,16 +324,24 @@ module CBuiltin #:nodoc:
323
324
  @caller = fun
324
325
  end
325
326
 
327
+ def clear_caller(*)
328
+ @caller = nil
329
+ end
330
+
326
331
  def extract_function_call(funcall_expr, fun, *)
327
- if @caller && fun.named?
328
- CALL(funcall_expr.location,
329
- FunctionId.new(@caller.name, @caller.signature.to_s),
330
- FunctionId.new(fun.name, fun.signature.to_s))
332
+ if fun.named?
333
+ if @caller
334
+ referrer = FunctionId.new(@caller.name, @caller.signature.to_s)
335
+ else
336
+ referrer = FunctionId.of_ctors_section
337
+ end
338
+ FUNCALL(funcall_expr.location, referrer,
339
+ FunctionId.new(fun.name, fun.signature.to_s))
331
340
  end
332
341
  end
333
342
  end
334
343
 
335
- class CrossRefExtraction < CodeExtraction
344
+ class XRefExtraction < CodeExtraction
336
345
  def_registrant_phase Cc1::Prepare2Phase
337
346
 
338
347
  def initialize(phase_ctxt)
@@ -359,36 +368,47 @@ module CBuiltin #:nodoc:
359
368
  end
360
369
 
361
370
  def extract_variable_read(expr, var)
362
- if @accessor && var.scope.global? && var.named?
371
+ if var.scope.global? && var.named?
363
372
  # NOTE: When a value of the inner-variable of array or composite object
364
373
  # is referred, dependency record of only outmost-variable access
365
374
  # should be output.
366
375
  var = var.owner while var.inner?
367
- XREF_VAR(expr.location,
368
- FunctionId.new(@accessor.name, @accessor.signature.to_s),
369
- "R", var.name)
376
+
377
+ if @accessor
378
+ referrer = FunctionId.new(@accessor.name, @accessor.signature.to_s)
379
+ else
380
+ referrer = FunctionId.of_ctors_section
381
+ end
382
+ XREF_VAR(expr.location, referrer, "R", var.name)
370
383
  end
371
384
  end
372
385
 
373
386
  def extract_variable_write(expr, var)
374
- if @accessor && var.scope.global? && var.named?
375
- unless var.inner?
376
- # NOTE: When a value of the inner-variable of array or composite
377
- # object is updated, dependency record of the inner-variable
378
- # access should not be output and the outer variable's value
379
- # will also be notified later.
380
- XREF_VAR(expr.location,
381
- FunctionId.new(@accessor.name, @accessor.signature.to_s),
382
- "W", var.name)
387
+ # NOTE: When a value of the inner-variable of array or composite
388
+ # object is updated, dependency record of the inner-variable
389
+ # access should not be output and the outer variable's value
390
+ # will also be notified later.
391
+ return if var.inner?
392
+
393
+ if var.scope.global? && var.named?
394
+ if @accessor
395
+ referrer = FunctionId.new(@accessor.name, @accessor.signature.to_s)
396
+ else
397
+ referrer = FunctionId.of_ctors_section
383
398
  end
399
+ XREF_VAR(expr.location, referrer, "W", var.name)
384
400
  end
385
401
  end
386
402
 
387
403
  def extract_function_reference(expr, fun)
388
- if @accessor && fun.named?
389
- XREF_FUNC(expr.location,
390
- FunctionId.new(@accessor.name, @accessor.signature.to_s),
391
- "R", FunctionId.new(fun.name, fun.signature.to_s))
404
+ if fun.named?
405
+ if @accessor
406
+ referrer = FunctionId.new(@accessor.name, @accessor.signature.to_s)
407
+ else
408
+ referrer = FunctionId.of_ctors_section
409
+ end
410
+ XREF_FUNC(expr.location, referrer, "R",
411
+ FunctionId.new(fun.name, fun.signature.to_s))
392
412
  end
393
413
  end
394
414
  end
@@ -398,9 +418,9 @@ module CBuiltin #:nodoc:
398
418
 
399
419
  def initialize(phase_ctxt)
400
420
  super
401
- visitor = phase_ctxt[:cc1_visitor]
402
- visitor.enter_constant_specifier += T(:extract_constant)
403
- visitor.enter_string_literal_specifier += T(:extract_string_literal)
421
+ traversal = phase_ctxt[:cc1_ast_traversal]
422
+ traversal.enter_constant_specifier += T(:extract_constant)
423
+ traversal.enter_string_literal_specifier += T(:extract_string_literal)
404
424
  end
405
425
 
406
426
  private