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.
- data/ChangeLog +374 -13
- data/INSTALL +1 -3
- data/MANIFEST +12 -0
- data/NEWS +30 -4
- data/README +0 -4
- data/TODO +2 -1
- data/etc/mesg.d/c_builtin/en_US/messages.yml +2 -2
- data/etc/mesg.d/c_builtin/ja_JP/messages.yml +2 -2
- data/etc/mesg.d/core/en_US/messages.yml +5 -1
- data/etc/mesg.d/core/ja_JP/messages.yml +5 -1
- data/features/code_check/W0422.feature +128 -0
- data/features/code_check/W0491.feature +57 -0
- data/features/code_check/W0492.feature +80 -0
- data/features/code_check/W0542.feature +20 -0
- data/features/code_check/W0580.feature +25 -0
- data/features/code_check/W0610.feature +36 -0
- data/features/code_check/W0642.feature +67 -0
- data/features/code_check/W0786.feature +39 -0
- data/features/code_check/W0830.feature +27 -0
- data/features/code_check/W1047.feature +72 -0
- data/features/code_check/W9003.feature +22 -0
- data/features/code_extraction/TODO +1 -0
- data/features/metric_measurement/TODO +1 -0
- data/lib/adlint/analyzer.rb +2 -2
- data/lib/adlint/cc1/ctrlexpr.rb +27 -6
- data/lib/adlint/cc1/domain.rb +72 -12
- data/lib/adlint/cc1/enum.rb +4 -0
- data/lib/adlint/cc1/expr.rb +31 -29
- data/lib/adlint/cc1/interp.rb +45 -56
- data/lib/adlint/cc1/lexer.rb +26 -5
- data/lib/adlint/cc1/mediator.rb +35 -6
- data/lib/adlint/cc1/object.rb +62 -19
- data/lib/adlint/cc1/parser.rb +948 -904
- data/lib/adlint/cc1/parser.y +59 -29
- data/lib/adlint/cc1/phase.rb +6 -8
- data/lib/adlint/cc1/syntax.rb +70 -17
- data/lib/adlint/cc1/util.rb +4 -4
- data/lib/adlint/code.rb +16 -6
- data/lib/adlint/cpp/eval.rb +31 -25
- data/lib/adlint/cpp/lexer.rb +11 -5
- data/lib/adlint/cpp/macro.rb +34 -7
- data/lib/adlint/cpp/phase.rb +8 -8
- data/lib/adlint/error.rb +6 -0
- data/lib/adlint/exam/c_builtin/cc1_check.rb +557 -594
- data/lib/adlint/exam/c_builtin/cc1_check_shima.rb +72 -72
- data/lib/adlint/exam/c_builtin/cc1_code.rb +72 -52
- data/lib/adlint/exam/c_builtin/cc1_metric.rb +131 -131
- data/lib/adlint/exam/c_builtin/cpp_check.rb +48 -48
- data/lib/adlint/exam/c_builtin/cpp_check_shima.rb +2 -2
- data/lib/adlint/exam/c_builtin/cpp_code.rb +21 -21
- data/lib/adlint/exam/c_builtin/ld_check.rb +88 -87
- data/lib/adlint/exam/c_builtin/ld_metric.rb +4 -5
- data/lib/adlint/exam/c_builtin.rb +6 -6
- data/lib/adlint/ld/object.rb +269 -186
- data/lib/adlint/ld/phase.rb +19 -19
- data/lib/adlint/ld/typedef.rb +7 -7
- data/lib/adlint/ld/util.rb +25 -17
- data/lib/adlint/location.rb +6 -1
- data/lib/adlint/memo.rb +66 -13
- data/lib/adlint/prelude.rb +2 -2
- data/lib/adlint/report.rb +13 -14
- data/lib/adlint/util.rb +1 -1
- data/lib/adlint/version.rb +2 -2
- data/share/doc/Makefile +6 -2
- data/share/doc/c99gram.dot +502 -0
- data/share/doc/c99gram.pdf +0 -0
- data/share/doc/developers_guide_ja.html +4 -3
- data/share/doc/developers_guide_ja.texi +2 -1
- data/share/doc/users_guide_en.html +9 -9
- data/share/doc/users_guide_en.texi +7 -7
- data/share/doc/users_guide_ja.html +9 -9
- data/share/doc/users_guide_ja.texi +7 -7
- 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
|
-
|
50
|
-
if
|
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
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
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
|
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
|
-
|
177
|
-
var_traversal
|
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
|
-
|
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 { |
|
202
|
-
|
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
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
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
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
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
|
-
|
297
|
+
@fun_map.lookup_function_declarations(fun.name).select { |dcl|
|
296
298
|
dcl.explicit? && dcl.extern? && dcl.signature != fun.signature
|
297
|
-
} +
|
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 { |
|
304
|
-
C(:C0001,
|
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
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
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
|
-
|
46
|
-
@phase_ctxt[:
|
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
|
-
|
55
|
-
|
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
|
-
|
795
|
+
FunDclExtraction,
|
796
796
|
VarDefExtraction,
|
797
|
-
|
797
|
+
FunDefExtraction,
|
798
798
|
LabelDefExtraction,
|
799
799
|
InitializationExtraction,
|
800
800
|
AssignmentExtraction,
|
801
|
-
|
802
|
-
|
801
|
+
FuncallExtraction,
|
802
|
+
XRefExtraction,
|
803
803
|
LiteralExtraction,
|
804
|
-
|
805
|
-
|
804
|
+
ObjLikeMacroExtraction,
|
805
|
+
FunLikeMacroExtraction,
|
806
806
|
IncludeDirectiveExtraction,
|
807
807
|
DirectiveExtraction
|
808
808
|
]
|