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
@@ -42,12 +42,13 @@ module CBuiltin #:nodoc:
42
42
  def initialize(phase_ctxt)
43
43
  super
44
44
  phase_ctxt[:ld_function_traversal].on_definition += T(:check)
45
+ @call_graph = phase_ctxt[:ld_call_graph]
45
46
  end
46
47
 
47
48
  private
48
49
  def check(fun)
49
- call_graph = @phase_ctxt[:ld_function_call_graph]
50
- if call_graph.indirect_callers_of(fun).include?(fun)
50
+ refs = @call_graph.indirect_callers_of(fun)
51
+ if refs.any? { |ref| caller_fun = ref.function and caller_fun == fun }
51
52
  W(fun.location)
52
53
  end
53
54
  end
@@ -59,12 +60,12 @@ module CBuiltin #:nodoc:
59
60
  def initialize(phase_ctxt)
60
61
  super
61
62
  phase_ctxt[:ld_typedef_traversal].on_declaration += T(:check)
63
+ @map = phase_ctxt[:ld_typedef_map]
62
64
  end
63
65
 
64
66
  private
65
67
  def check(typedef)
66
- mapping = @phase_ctxt[:ld_typedef_mapping]
67
- if mapping.lookup(typedef.name).any? { |td| td != typedef }
68
+ if @map.lookup(typedef.name).any? { |td| td != typedef }
68
69
  W(typedef.location, typedef.name)
69
70
  end
70
71
  end
@@ -77,26 +78,31 @@ module CBuiltin #:nodoc:
77
78
  super
78
79
  phase_ctxt[:ld_function_traversal].on_definition += T(:check_function)
79
80
  phase_ctxt[:ld_variable_traversal].on_definition += T(:check_variable)
81
+ @xref_graph = phase_ctxt[:ld_xref_graph]
80
82
  end
81
83
 
82
84
  private
83
85
  def check_function(fun)
84
- return unless fun.extern?
85
- call_graph = @phase_ctxt[:ld_function_call_graph]
86
- direct_callers = call_graph.direct_callers_of(fun)
87
- if direct_callers.size == 1 &&
88
- direct_callers.first.location.fpath == fun.location.fpath
89
- W(fun.location, fun.signature, direct_callers.first.signature)
86
+ if fun.extern?
87
+ refs = @xref_graph.direct_referrers_of(fun)
88
+ ref_funs = refs.map { |ref| ref.function }.compact.uniq
89
+ if ref_funs.size == 1
90
+ if ref_funs.first.location.fpath == fun.location.fpath
91
+ W(fun.location, fun.signature, ref_funs.first.signature)
92
+ end
93
+ end
90
94
  end
91
95
  end
92
96
 
93
97
  def check_variable(var)
94
- return unless var.extern?
95
- ref_graph = @phase_ctxt[:ld_variable_reference_graph]
96
- direct_referrers = ref_graph.direct_referrers_of(var)
97
- if direct_referrers.size == 1 &&
98
- direct_referrers.first.location.fpath == var.location.fpath
99
- W(var.location, var.name, direct_referrers.first.signature)
98
+ if var.extern?
99
+ refs = @xref_graph.direct_referrers_of(var)
100
+ ref_funs = refs.map { |ref| ref.function }.compact.uniq
101
+ if ref_funs.size == 1
102
+ if ref_funs.first.location.fpath == var.location.fpath
103
+ W(var.location, var.name, ref_funs.first.signature)
104
+ end
105
+ end
100
106
  end
101
107
  end
102
108
  end
@@ -107,16 +113,17 @@ module CBuiltin #:nodoc:
107
113
  def initialize(phase_ctxt)
108
114
  super
109
115
  phase_ctxt[:ld_function_traversal].on_definition += T(:check)
116
+ @xref_graph = phase_ctxt[:ld_xref_graph]
110
117
  end
111
118
 
112
119
  private
113
120
  def check(fun)
114
- return unless fun.extern?
115
- call_graph = @phase_ctxt[:ld_function_call_graph]
116
- direct_callers = call_graph.direct_callers_of(fun)
117
- if !direct_callers.empty? &&
118
- direct_callers.all? { |f| f.location.fpath == fun.location.fpath }
119
- W(fun.location, fun.signature)
121
+ if fun.extern?
122
+ direct_refs = @xref_graph.direct_referrers_of(fun)
123
+ if !direct_refs.empty? &&
124
+ direct_refs.all? { |ref| ref.location.fpath == fun.location.fpath }
125
+ W(fun.location, fun.signature)
126
+ end
120
127
  end
121
128
  end
122
129
  end
@@ -127,16 +134,17 @@ module CBuiltin #:nodoc:
127
134
  def initialize(phase_ctxt)
128
135
  super
129
136
  phase_ctxt[:ld_variable_traversal].on_definition += T(:check)
137
+ @xref_graph = phase_ctxt[:ld_xref_graph]
130
138
  end
131
139
 
132
140
  private
133
141
  def check(var)
134
- return unless var.extern?
135
- ref_graph = @phase_ctxt[:ld_variable_reference_graph]
136
- direct_referrers = ref_graph.direct_referrers_of(var)
137
- if !direct_referrers.empty? &&
138
- direct_referrers.all? { |f| f.location.fpath == var.location.fpath }
139
- W(var.location, var.name)
142
+ if var.extern?
143
+ direct_refs = @xref_graph.direct_referrers_of(var)
144
+ if !direct_refs.empty? &&
145
+ direct_refs.all? { |ref| ref.location.fpath == var.location.fpath }
146
+ W(var.location, var.name)
147
+ end
140
148
  end
141
149
  end
142
150
  end
@@ -147,13 +155,13 @@ module CBuiltin #:nodoc:
147
155
  def initialize(phase_ctxt)
148
156
  super
149
157
  phase_ctxt[:ld_function_traversal].on_definition += T(:check)
158
+ @xref_graph = phase_ctxt[:ld_xref_graph]
150
159
  end
151
160
 
152
161
  private
153
162
  def check(fun)
154
- call_graph = @phase_ctxt[:ld_function_call_graph]
155
163
  unless fun.name == "main"
156
- if call_graph.direct_callers_of(fun).empty?
164
+ if @xref_graph.direct_referrers_of(fun).empty?
157
165
  W(fun.location, fun.signature)
158
166
  end
159
167
  end
@@ -170,11 +178,13 @@ module CBuiltin #:nodoc:
170
178
  def initialize(phase_ctxt)
171
179
  super
172
180
  fun_traversal = phase_ctxt[:ld_function_traversal]
173
- var_traversal = phase_ctxt[:ld_variable_traversal]
174
181
  fun_traversal.on_declaration += T(:check_function_declaration)
175
182
  fun_traversal.on_definition += T(:check_function_definition)
176
- var_traversal.on_declaration += T(:check_variable)
177
- var_traversal.on_definition += T(:check_variable)
183
+ @fun_map = phase_ctxt[:ld_function_map]
184
+ var_traversal = phase_ctxt[:ld_variable_traversal]
185
+ var_traversal.on_declaration += T(:check_variable)
186
+ var_traversal.on_definition += T(:check_variable)
187
+ @var_map = phase_ctxt[:ld_variable_map]
178
188
  end
179
189
 
180
190
  private
@@ -191,31 +201,26 @@ module CBuiltin #:nodoc:
191
201
  end
192
202
 
193
203
  def check_function(fun)
194
- mapping = @phase_ctxt[:ld_function_mapping]
195
204
  similar_dcls =
196
- mapping.lookup_function_declarations(fun.name).select { |fun_dcl|
205
+ @fun_map.lookup_function_declarations(fun.name).select { |fun_dcl|
197
206
  fun_dcl.explicit?
198
207
  }
199
208
 
200
209
  if similar_dcls.size > 1
201
- W(fun.location, fun.signature, *similar_dcls.map { |pair_dcl|
202
- next if pair_dcl == fun
203
- C(:C0001, pair_dcl.location, pair_dcl.signature)
210
+ W(fun.location, fun.signature, *similar_dcls.map { |pair|
211
+ C(:C0001, pair.location, pair.signature) unless pair == fun
204
212
  }.compact)
205
213
  end
206
214
  end
207
215
 
208
216
  def check_variable(var)
209
- return unless var.extern?
210
-
211
- mapping = @phase_ctxt[:ld_variable_mapping]
212
- similar_dcls = mapping.lookup_variable_declarations(var.name)
213
-
214
- if similar_dcls.size > 1
215
- W(var.location, var.name, *similar_dcls.map { |pair_dcl|
216
- next if pair_dcl == var
217
- C(:C0001, pair_dcl.location, pair_dcl.name)
218
- }.compact)
217
+ if var.extern?
218
+ similar_dcls = @var_map.lookup_variable_declarations(var.name)
219
+ if similar_dcls.size > 1
220
+ W(var.location, var.name, *similar_dcls.map { |pair|
221
+ C(:C0001, pair.location, pair.name) unless pair == var
222
+ }.compact)
223
+ end
219
224
  end
220
225
  end
221
226
  end
@@ -231,34 +236,30 @@ module CBuiltin #:nodoc:
231
236
  super
232
237
  phase_ctxt[:ld_function_traversal].on_definition += T(:check_function)
233
238
  phase_ctxt[:ld_variable_traversal].on_definition += T(:check_variable)
239
+ @fun_map = phase_ctxt[:ld_function_map]
240
+ @var_map = phase_ctxt[:ld_variable_map]
234
241
  end
235
242
 
236
243
  private
237
244
  def check_function(fun)
238
- return unless fun.extern?
239
-
240
- mapping = @phase_ctxt[:ld_function_mapping]
241
- similar_funs = mapping.lookup_functions(fun.name)
242
-
243
- if similar_funs.size > 1
244
- W(fun.location, fun.signature, *similar_funs.map { |pair_fun|
245
- next if pair_fun == fun
246
- C(:C0001, pair_fun.location, pair_fun.signature)
247
- }.compact)
245
+ if fun.extern?
246
+ similar_funs = @fun_map.lookup_functions(fun.name)
247
+ if similar_funs.size > 1
248
+ W(fun.location, fun.signature, *similar_funs.map { |pair|
249
+ C(:C0001, pair.location, pair.signature) unless pair == fun
250
+ }.compact)
251
+ end
248
252
  end
249
253
  end
250
254
 
251
255
  def check_variable(var)
252
- return unless var.extern?
253
-
254
- mapping = @phase_ctxt[:ld_variable_mapping]
255
- similar_vars = mapping.lookup_variables(var.name)
256
-
257
- if similar_vars.size > 1
258
- W(var.location, var.name, *similar_vars.map { |pair_var|
259
- next if pair_var == var
260
- C(:C0001, pair_var.location, pair_var.name)
261
- }.compact)
256
+ if var.extern?
257
+ similar_vars = @var_map.lookup_variables(var.name)
258
+ if similar_vars.size > 1
259
+ W(var.location, var.name, *similar_vars.map { |pair|
260
+ C(:C0001, pair.location, pair.name) unless pair == var
261
+ }.compact)
262
+ end
262
263
  end
263
264
  end
264
265
  end
@@ -273,11 +274,13 @@ module CBuiltin #:nodoc:
273
274
  def initialize(phase_ctxt)
274
275
  super
275
276
  fun_traversal = phase_ctxt[:ld_function_traversal]
276
- var_traversal = phase_ctxt[:ld_variable_traversal]
277
277
  fun_traversal.on_declaration += T(:check_function_declaration)
278
278
  fun_traversal.on_definition += T(:check_function_definition)
279
+ @fun_map = phase_ctxt[:ld_function_map]
280
+ var_traversal = phase_ctxt[:ld_variable_traversal]
279
281
  var_traversal.on_declaration += T(:check_variable)
280
282
  var_traversal.on_definition += T(:check_variable)
283
+ @var_map = phase_ctxt[:ld_variable_map]
281
284
  end
282
285
 
283
286
  private
@@ -290,36 +293,34 @@ module CBuiltin #:nodoc:
290
293
  end
291
294
 
292
295
  def check_function(fun)
293
- mapping = @phase_ctxt[:ld_function_mapping]
294
296
  similar_dcls_or_funs =
295
- mapping.lookup_function_declarations(fun.name).select { |dcl|
297
+ @fun_map.lookup_function_declarations(fun.name).select { |dcl|
296
298
  dcl.explicit? && dcl.extern? && dcl.signature != fun.signature
297
- } + mapping.lookup_functions(fun.name).select { |mapped_fun|
299
+ } + @fun_map.lookup_functions(fun.name).select { |mapped_fun|
298
300
  mapped_fun.extern? && mapped_fun.signature != fun.signature
299
301
  }
300
302
 
301
303
  unless similar_dcls_or_funs.empty?
302
304
  W(fun.location, fun.signature,
303
- *similar_dcls_or_funs.map { |pair_dcl_or_fun|
304
- C(:C0001, pair_dcl_or_fun.location, pair_dcl_or_fun.signature)
305
+ *similar_dcls_or_funs.map { |pair|
306
+ C(:C0001, pair.location, pair.signature)
305
307
  })
306
308
  end
307
309
  end
308
310
 
309
311
  def check_variable(var)
310
- return unless var.extern?
311
-
312
- mapping = @phase_ctxt[:ld_variable_mapping]
313
- similar_dcls_or_vars =
314
- (mapping.lookup_variable_declarations(var.name) +
315
- mapping.lookup_variables(var.name)).select { |dcl_or_var|
316
- dcl_or_var.extern? && dcl_or_var.type != var.type
317
- }
318
-
319
- unless similar_dcls_or_vars.empty?
320
- W(var.location, var.name, *similar_dcls_or_vars.map { |pair_dcl_or_var|
321
- C(:C0001, pair_dcl_or_var.location, pair_dcl_or_var.name)
322
- })
312
+ if var.extern?
313
+ dcls_or_vars = @var_map.lookup_variable_declarations(var.name) +
314
+ @var_map.lookup_variables(var.name)
315
+ similar_dcls_or_vars = dcls_or_vars.select { |dcl_or_var|
316
+ dcl_or_var.extern? && dcl_or_var.type != var.type
317
+ }
318
+
319
+ unless similar_dcls_or_vars.empty?
320
+ W(var.location, var.name, *similar_dcls_or_vars.map { |pair|
321
+ C(:C0001, pair.location, pair.name)
322
+ })
323
+ end
323
324
  end
324
325
  end
325
326
  end
@@ -42,8 +42,8 @@ module CBuiltin #:nodoc:
42
42
 
43
43
  def initialize(phase_ctxt)
44
44
  super
45
- @phase_ctxt = phase_ctxt
46
- @phase_ctxt[:ld_function_traversal].on_definition += T(:measure)
45
+ phase_ctxt[:ld_function_traversal].on_definition += T(:measure)
46
+ @call_graph = phase_ctxt[:ld_call_graph]
47
47
  end
48
48
 
49
49
  private
@@ -51,9 +51,8 @@ module CBuiltin #:nodoc:
51
51
  def do_execute(*) end
52
52
 
53
53
  def measure(fun)
54
- call_graph = @phase_ctxt[:ld_function_call_graph]
55
- FN_CALL(FunctionId.new(fun.name, fun.signature),
56
- fun.location, call_graph.all_callers_of(fun).size)
54
+ FN_CALL(FunctionId.new(fun.name, fun.signature), fun.location,
55
+ @call_graph.all_callers_of(fun).count { |ref| ref.function })
57
56
  end
58
57
  end
59
58
 
@@ -792,17 +792,17 @@ module CBuiltin #:nodoc:
792
792
 
793
793
  TypeDeclExtraction,
794
794
  GVarDeclExtraction,
795
- FuncDeclExtraction,
795
+ FunDclExtraction,
796
796
  VarDefExtraction,
797
- FuncDefExtraction,
797
+ FunDefExtraction,
798
798
  LabelDefExtraction,
799
799
  InitializationExtraction,
800
800
  AssignmentExtraction,
801
- FuncCallExtraction,
802
- CrossRefExtraction,
801
+ FuncallExtraction,
802
+ XRefExtraction,
803
803
  LiteralExtraction,
804
- ObjectLikeMacroExtraction,
805
- FuncLikeMacroExtraction,
804
+ ObjLikeMacroExtraction,
805
+ FunLikeMacroExtraction,
806
806
  IncludeDirectiveExtraction,
807
807
  DirectiveExtraction
808
808
  ]