adlint 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -1
- data/ChangeLog +272 -0
- data/MANIFEST +4 -0
- data/NEWS +39 -4
- data/etc/mesg.d/en_US/messages.yml +2 -2
- data/etc/mesg.d/ja_JP/messages.yml +2 -2
- data/lib/adlint/c.rb +1 -0
- data/lib/adlint/c/expr.rb +20 -26
- data/lib/adlint/c/interp.rb +137 -45
- data/lib/adlint/c/mediator.rb +4 -0
- data/lib/adlint/c/message.rb +479 -16
- data/lib/adlint/c/message_shima.rb +151 -0
- data/lib/adlint/c/phase.rb +23 -0
- data/lib/adlint/c/resolver.rb +1 -0
- data/lib/adlint/c/syntax.rb +93 -89
- data/lib/adlint/c/type.rb +70 -0
- data/lib/adlint/cpp/eval.rb +12 -1
- data/lib/adlint/cpp/message_shima.rb +51 -0
- data/lib/adlint/cpp/phase.rb +3 -0
- data/lib/adlint/version.rb +2 -2
- data/share/demo/Makefile +3 -0
- data/share/demo/bad_enum/bad_enum.c +27 -0
- data/share/demo/bad_macro/bad_macro.c +4 -0
- data/share/demo/bad_return/bad_return.c +83 -0
- data/share/demo/incomplete_type/incomplete_type.c +3 -0
- data/share/demo/overflow/overflow.c +59 -5
- data/share/demo/union_type/union_type.c +13 -0
- data/share/demo/unnamed_member/unnamed_member.c +13 -0
- data/share/demo/various_fundef/various_fundef.c +43 -0
- data/share/demo/wrap_around/wrap_around.c +95 -21
- data/share/doc/developers_guide_ja.html +3 -3
- data/share/doc/developers_guide_ja.texi +1 -1
- data/share/doc/users_guide_en.html +222 -149
- data/share/doc/users_guide_en.texi +194 -120
- data/share/doc/users_guide_ja.html +224 -167
- data/share/doc/users_guide_ja.texi +194 -137
- metadata +6 -2
data/lib/adlint/c/type.rb
CHANGED
@@ -312,6 +312,10 @@ module C #:nodoc:
|
|
312
312
|
subclass_responsibility
|
313
313
|
end
|
314
314
|
|
315
|
+
def enumerators
|
316
|
+
subclass_responsibility
|
317
|
+
end
|
318
|
+
|
315
319
|
def length
|
316
320
|
subclass_responsibility
|
317
321
|
end
|
@@ -763,6 +767,10 @@ module C #:nodoc:
|
|
763
767
|
[]
|
764
768
|
end
|
765
769
|
|
770
|
+
def enumerators
|
771
|
+
[]
|
772
|
+
end
|
773
|
+
|
766
774
|
def length
|
767
775
|
0
|
768
776
|
end
|
@@ -1279,6 +1287,10 @@ module C #:nodoc:
|
|
1279
1287
|
[]
|
1280
1288
|
end
|
1281
1289
|
|
1290
|
+
def enumerators
|
1291
|
+
[]
|
1292
|
+
end
|
1293
|
+
|
1282
1294
|
def length
|
1283
1295
|
0
|
1284
1296
|
end
|
@@ -1793,6 +1805,10 @@ module C #:nodoc:
|
|
1793
1805
|
@base_type.parameter_types
|
1794
1806
|
end
|
1795
1807
|
|
1808
|
+
def enumerators
|
1809
|
+
@base_type.enumerators
|
1810
|
+
end
|
1811
|
+
|
1796
1812
|
def length
|
1797
1813
|
@base_type.length
|
1798
1814
|
end
|
@@ -2098,6 +2114,10 @@ module C #:nodoc:
|
|
2098
2114
|
[]
|
2099
2115
|
end
|
2100
2116
|
|
2117
|
+
def enumerators
|
2118
|
+
[]
|
2119
|
+
end
|
2120
|
+
|
2101
2121
|
def length
|
2102
2122
|
0
|
2103
2123
|
end
|
@@ -2615,6 +2635,10 @@ module C #:nodoc:
|
|
2615
2635
|
@have_va_list
|
2616
2636
|
end
|
2617
2637
|
|
2638
|
+
def enumerators
|
2639
|
+
[]
|
2640
|
+
end
|
2641
|
+
|
2618
2642
|
def length
|
2619
2643
|
0
|
2620
2644
|
end
|
@@ -3159,6 +3183,10 @@ module C #:nodoc:
|
|
3159
3183
|
[]
|
3160
3184
|
end
|
3161
3185
|
|
3186
|
+
def enumerators
|
3187
|
+
subclass_responsibility
|
3188
|
+
end
|
3189
|
+
|
3162
3190
|
def length
|
3163
3191
|
0
|
3164
3192
|
end
|
@@ -3484,6 +3512,10 @@ module C #:nodoc:
|
|
3484
3512
|
@explicitly_signed
|
3485
3513
|
end
|
3486
3514
|
|
3515
|
+
def enumerators
|
3516
|
+
subclass_responsibility
|
3517
|
+
end
|
3518
|
+
|
3487
3519
|
def min_value
|
3488
3520
|
if @signed
|
3489
3521
|
-2**(@bit_size - 1)
|
@@ -3590,6 +3622,10 @@ module C #:nodoc:
|
|
3590
3622
|
false
|
3591
3623
|
end
|
3592
3624
|
|
3625
|
+
def enumerators
|
3626
|
+
[]
|
3627
|
+
end
|
3628
|
+
|
3593
3629
|
def integer_conversion_rank
|
3594
3630
|
subclass_responsibility
|
3595
3631
|
end
|
@@ -4854,6 +4890,10 @@ module C #:nodoc:
|
|
4854
4890
|
false
|
4855
4891
|
end
|
4856
4892
|
|
4893
|
+
def enum?
|
4894
|
+
false
|
4895
|
+
end
|
4896
|
+
|
4857
4897
|
def bitfield?
|
4858
4898
|
false
|
4859
4899
|
end
|
@@ -4866,6 +4906,10 @@ module C #:nodoc:
|
|
4866
4906
|
true
|
4867
4907
|
end
|
4868
4908
|
|
4909
|
+
def enumerators
|
4910
|
+
[]
|
4911
|
+
end
|
4912
|
+
|
4869
4913
|
def min_value
|
4870
4914
|
(-2**fraction_bit_size * 10**(exponent_bit_size - 1)).to_f
|
4871
4915
|
end
|
@@ -5084,6 +5128,10 @@ module C #:nodoc:
|
|
5084
5128
|
@base_type.unresolved?
|
5085
5129
|
end
|
5086
5130
|
|
5131
|
+
def enumerators
|
5132
|
+
[]
|
5133
|
+
end
|
5134
|
+
|
5087
5135
|
def integer_conversion_rank
|
5088
5136
|
-1
|
5089
5137
|
end
|
@@ -5186,6 +5234,10 @@ module C #:nodoc:
|
|
5186
5234
|
"enum #{name}"
|
5187
5235
|
end
|
5188
5236
|
|
5237
|
+
def enumerators
|
5238
|
+
declarations.map { |decl| decl.enumerators }.compact.flatten.uniq
|
5239
|
+
end
|
5240
|
+
|
5189
5241
|
def integer_conversion_rank
|
5190
5242
|
# NOTE: The ISO C99 standard saids;
|
5191
5243
|
#
|
@@ -5304,6 +5356,10 @@ module C #:nodoc:
|
|
5304
5356
|
false
|
5305
5357
|
end
|
5306
5358
|
|
5359
|
+
def enumerators
|
5360
|
+
[]
|
5361
|
+
end
|
5362
|
+
|
5307
5363
|
def integer_conversion_rank
|
5308
5364
|
# NOTE: Pointer variables must not be converted implicitly.
|
5309
5365
|
100
|
@@ -5562,6 +5618,10 @@ module C #:nodoc:
|
|
5562
5618
|
[]
|
5563
5619
|
end
|
5564
5620
|
|
5621
|
+
def enumerators
|
5622
|
+
[]
|
5623
|
+
end
|
5624
|
+
|
5565
5625
|
def members
|
5566
5626
|
[]
|
5567
5627
|
end
|
@@ -6118,6 +6178,10 @@ module C #:nodoc:
|
|
6118
6178
|
[]
|
6119
6179
|
end
|
6120
6180
|
|
6181
|
+
def enumerators
|
6182
|
+
[]
|
6183
|
+
end
|
6184
|
+
|
6121
6185
|
def length
|
6122
6186
|
0
|
6123
6187
|
end
|
@@ -6651,6 +6715,7 @@ module C #:nodoc:
|
|
6651
6715
|
def_delegator :@base_type, :have_va_list?
|
6652
6716
|
def_delegator :@base_type, :return_type
|
6653
6717
|
def_delegator :@base_type, :parameter_types
|
6718
|
+
def_delegator :@base_type, :enumerators
|
6654
6719
|
def_delegator :@base_type, :length
|
6655
6720
|
def_delegator :@base_type, :impl_length
|
6656
6721
|
def_delegator :@base_type, :members
|
@@ -6792,6 +6857,7 @@ module C #:nodoc:
|
|
6792
6857
|
def_delegator :@type, :have_va_list?
|
6793
6858
|
def_delegator :@type, :return_type
|
6794
6859
|
def_delegator :@type, :parameter_types
|
6860
|
+
def_delegator :@type, :enumerators
|
6795
6861
|
def_delegator :@type, :length
|
6796
6862
|
def_delegator :@type, :impl_length
|
6797
6863
|
def_delegator :@type, :members
|
@@ -6882,6 +6948,10 @@ module C #:nodoc:
|
|
6882
6948
|
false
|
6883
6949
|
end
|
6884
6950
|
|
6951
|
+
def enumerators
|
6952
|
+
[]
|
6953
|
+
end
|
6954
|
+
|
6885
6955
|
def integer_conversion_rank
|
6886
6956
|
# NOTE: The ISO C99 standard saids;
|
6887
6957
|
#
|
data/lib/adlint/cpp/eval.rb
CHANGED
@@ -61,6 +61,7 @@ module Cpp #:nodoc:
|
|
61
61
|
def_plugin :on_object_like_macro_defined
|
62
62
|
def_plugin :on_function_like_macro_defined
|
63
63
|
def_plugin :on_va_function_like_macro_defined
|
64
|
+
def_plugin :on_macro_undefined
|
64
65
|
def_plugin :on_asm_section_evaled
|
65
66
|
def_plugin :on_unknown_pragma_evaled
|
66
67
|
def_plugin :on_pp_token_extracted
|
@@ -492,8 +493,14 @@ module Cpp #:nodoc:
|
|
492
493
|
unless new_line = context.next_token and new_line.type == :NEW_LINE
|
493
494
|
return nil
|
494
495
|
end
|
496
|
+
|
497
|
+
undef_line = UndefLine.new(keyword, identifier)
|
498
|
+
macro = context.macro_table.lookup(identifier.value)
|
499
|
+
# NOTE: Undefining macro may be nil if not defined.
|
500
|
+
notify_macro_undefined(undef_line, macro)
|
501
|
+
|
495
502
|
context.macro_table.undef(identifier.value)
|
496
|
-
|
503
|
+
undef_line
|
497
504
|
end
|
498
505
|
|
499
506
|
def line_line(context)
|
@@ -803,6 +810,10 @@ module Cpp #:nodoc:
|
|
803
810
|
on_va_function_like_macro_defined.invoke(define_line, macro)
|
804
811
|
end
|
805
812
|
|
813
|
+
def notify_macro_undefined(undef_line, macro)
|
814
|
+
on_macro_undefined.invoke(undef_line, macro)
|
815
|
+
end
|
816
|
+
|
806
817
|
def notify_asm_section_evaled(asm_section)
|
807
818
|
on_asm_section_evaled.invoke(asm_section)
|
808
819
|
end
|
@@ -35,6 +35,25 @@ require "adlint/message"
|
|
35
35
|
module AdLint #:nodoc:
|
36
36
|
module Cpp #:nodoc:
|
37
37
|
|
38
|
+
class W0687 < PassiveMessageDetection
|
39
|
+
# NOTE: W0687 may be duplicative when the same header which causes this
|
40
|
+
# warning is included twice or more.
|
41
|
+
ensure_uniqueness_of :W0687
|
42
|
+
|
43
|
+
def initialize(context)
|
44
|
+
super
|
45
|
+
interp = context[:cpp_interpreter]
|
46
|
+
interp.on_macro_undefined += method(:check)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def check(undef_line, macro)
|
51
|
+
if undef_line.identifier.value == "defined"
|
52
|
+
W(:W0687, undef_line.identifier.location)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
38
57
|
class W0688 < PassiveMessageDetection
|
39
58
|
# NOTE: W0688 may be duplicative when the same header which causes this
|
40
59
|
# warning is included twice or more.
|
@@ -96,5 +115,37 @@ module Cpp #:nodoc:
|
|
96
115
|
end
|
97
116
|
end
|
98
117
|
|
118
|
+
class W0695 < W0687
|
119
|
+
# NOTE: W0695 may be duplicative when the same header which causes this
|
120
|
+
# warning is included twice or more.
|
121
|
+
ensure_uniqueness_of :W0695
|
122
|
+
|
123
|
+
private
|
124
|
+
def check(undef_line, macro)
|
125
|
+
if undef_line.identifier.value == "assert"
|
126
|
+
W(:W0695, undef_line.identifier.location)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
class W0806 < PassiveMessageDetection
|
132
|
+
# NOTE: W0806 may be duplicative when the same header which causes this
|
133
|
+
# warning is included twice or more.
|
134
|
+
ensure_uniqueness_of :W0806
|
135
|
+
|
136
|
+
def initialize(context)
|
137
|
+
super
|
138
|
+
interp = context[:cpp_interpreter]
|
139
|
+
interp.on_object_like_macro_defined += method(:check)
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
def check(define_line, macro)
|
144
|
+
if define_line.identifier.value == "defined"
|
145
|
+
W(:W0806, define_line.identifier.location)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
99
150
|
end
|
100
151
|
end
|
data/lib/adlint/cpp/phase.rb
CHANGED
@@ -100,11 +100,14 @@ module Cpp #:nodoc:
|
|
100
100
|
W0575.new(context),
|
101
101
|
W0576.new(context),
|
102
102
|
W0577.new(context),
|
103
|
+
W0687.new(context),
|
103
104
|
W0688.new(context),
|
104
105
|
W0689.new(context),
|
105
106
|
W0690.new(context),
|
107
|
+
W0695.new(context),
|
106
108
|
W0696.new(context),
|
107
109
|
W0804.new(context),
|
110
|
+
W0806.new(context),
|
108
111
|
W0831.new(context),
|
109
112
|
W9002.new(context)
|
110
113
|
]
|
data/lib/adlint/version.rb
CHANGED
data/share/demo/Makefile
CHANGED
@@ -8,10 +8,12 @@ bad_charset \
|
|
8
8
|
bad_comment \
|
9
9
|
bad_const \
|
10
10
|
bad_conv \
|
11
|
+
bad_enum \
|
11
12
|
bad_indent \
|
12
13
|
bad_init \
|
13
14
|
bad_line \
|
14
15
|
bad_macro \
|
16
|
+
bad_return \
|
15
17
|
bitwise_expr \
|
16
18
|
call_by_value \
|
17
19
|
cross_ref \
|
@@ -71,6 +73,7 @@ uninit_vars \
|
|
71
73
|
union_type \
|
72
74
|
unmatch_decl \
|
73
75
|
unmatch_paren_macro \
|
76
|
+
unnamed_member \
|
74
77
|
unreachable \
|
75
78
|
useless_exp_funs \
|
76
79
|
useless_exp_vars \
|
@@ -0,0 +1,27 @@
|
|
1
|
+
enum Foo { FOO_A, FOO_B, FOO_C };
|
2
|
+
enum Bar { BAR_A = 1, BAR_B, BAR_C };
|
3
|
+
enum Baz { BAZ_A = 2, BAZ_B = 4, BAZ_C = 8 };
|
4
|
+
|
5
|
+
extern void func1(enum Foo f);
|
6
|
+
|
7
|
+
enum Foo func2(const enum Foo param)
|
8
|
+
{
|
9
|
+
enum Foo foo = BAR_A;
|
10
|
+
foo = FOO_A;
|
11
|
+
|
12
|
+
switch (param) {
|
13
|
+
case FOO_A:
|
14
|
+
foo = BAR_A;
|
15
|
+
func1(BAR_A);
|
16
|
+
return BAR_B;
|
17
|
+
case BAR_B:
|
18
|
+
case 5:
|
19
|
+
foo = BAZ_C;
|
20
|
+
func1(BAZ_C);
|
21
|
+
return BAZ_C;
|
22
|
+
case 6:
|
23
|
+
return 10;
|
24
|
+
}
|
25
|
+
|
26
|
+
return FOO_C;
|
27
|
+
}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
int ansi_int_func_1(const int i)
|
2
|
+
{
|
3
|
+
if (i == 0) {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
else {
|
7
|
+
return i * 2;
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
int kandr_int_func_1(i)
|
12
|
+
const int i;
|
13
|
+
{
|
14
|
+
if (i == 0) {
|
15
|
+
return;
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
return i * 2;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
static void ansi_void_func(const int i)
|
23
|
+
{
|
24
|
+
if (i == 0) {
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
return i * 2;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
static void kandr_void_func(i)
|
33
|
+
const int i;
|
34
|
+
{
|
35
|
+
if (i == 0) {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
else {
|
39
|
+
return i * 2;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
ansi_int_func_2(const i)
|
44
|
+
{
|
45
|
+
if (i == 0) {
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
else {
|
49
|
+
return i * 2;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
kandr_int_func2(i)
|
54
|
+
const i;
|
55
|
+
{
|
56
|
+
if (i == 0) {
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
else {
|
60
|
+
return i * 2;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
const void ansi_qualified_void_func_1(const int i)
|
65
|
+
{
|
66
|
+
if (i == 0) {
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
return i * 2;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
volatile void kandr_qualified_void_func_1(i)
|
75
|
+
const int i;
|
76
|
+
{
|
77
|
+
if (i == 0) {
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
return i * 2;
|
82
|
+
}
|
83
|
+
}
|