adlint 1.4.0 → 1.6.0
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 +413 -5
- data/MANIFEST +6 -0
- data/NEWS +43 -4
- data/etc/mesg.d/en_US/messages.yml +1 -1
- data/etc/mesg.d/ja_JP/messages.yml +1 -1
- data/lib/adlint/c.rb +1 -0
- data/lib/adlint/c/enum.rb +52 -0
- data/lib/adlint/c/expr.rb +43 -102
- data/lib/adlint/c/interp.rb +1 -1
- data/lib/adlint/c/mediator.rb +1 -0
- data/lib/adlint/c/message.rb +831 -49
- data/lib/adlint/c/message_shima.rb +236 -0
- data/lib/adlint/c/metric.rb +9 -0
- data/lib/adlint/c/object.rb +37 -32
- data/lib/adlint/c/parser.rb +7 -7
- data/lib/adlint/c/parser.y +7 -7
- data/lib/adlint/c/phase.rb +21 -0
- data/lib/adlint/c/syntax.rb +11 -4
- data/lib/adlint/c/type.rb +1 -1
- data/lib/adlint/cpp.rb +1 -0
- data/lib/adlint/cpp/asm.rb +73 -0
- data/lib/adlint/cpp/message.rb +13 -0
- data/lib/adlint/cpp/message_shima.rb +36 -0
- data/lib/adlint/cpp/phase.rb +3 -0
- data/lib/adlint/cpp/source.rb +9 -0
- data/lib/adlint/version.rb +3 -3
- data/share/demo/Makefile +4 -0
- data/share/demo/bad_conv/bad_conv.c +12 -0
- data/share/demo/bad_enum/bad_enum.c +48 -2
- data/share/demo/bad_label/bad_label.c +26 -0
- data/share/demo/bad_macro/bad_macro.c +3 -0
- data/share/demo/implicit_conv/implicit_conv.c +1 -0
- data/share/demo/inline_asm/inline_asm.c +18 -0
- data/share/demo/invalid_call/invalid_call.c +5 -0
- data/share/demo/multi_decl/multi_decl_1.c +30 -0
- data/share/demo/overflow/overflow.c +3 -3
- data/share/demo/redundant_select/redundant_select.c +25 -0
- data/share/demo/reserved_ident/reserved_ident.c +98 -0
- 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 +234 -126
- data/share/doc/users_guide_en.texi +207 -98
- data/share/doc/users_guide_ja.html +247 -156
- data/share/doc/users_guide_ja.texi +221 -130
- data/share/sample/vim-7.3/adlint/xxd/adlint_traits.yml +1 -1
- metadata +8 -2
data/lib/adlint/c/phase.rb
CHANGED
@@ -551,7 +551,9 @@ module C #:nodoc:
|
|
551
551
|
W0570.new(context),
|
552
552
|
W0571.new(context),
|
553
553
|
W0572.new(context),
|
554
|
+
W0573.new(context),
|
554
555
|
W0578.new(context),
|
556
|
+
W0579.new(context),
|
555
557
|
W0580.new(context),
|
556
558
|
W0581.new(context),
|
557
559
|
W0582.new(context),
|
@@ -614,6 +616,8 @@ module C #:nodoc:
|
|
614
616
|
W0682.new(context),
|
615
617
|
W0683.new(context),
|
616
618
|
W0684.new(context),
|
619
|
+
W0685.new(context),
|
620
|
+
W0686.new(context),
|
617
621
|
W0698.new(context),
|
618
622
|
W0699.new(context),
|
619
623
|
W0703.new(context),
|
@@ -670,8 +674,12 @@ module C #:nodoc:
|
|
670
674
|
W0777.new(context),
|
671
675
|
W0778.new(context),
|
672
676
|
W0779.new(context),
|
677
|
+
W0781.new(context),
|
673
678
|
W0785.new(context),
|
674
679
|
W0786.new(context),
|
680
|
+
W0787.new(context),
|
681
|
+
W0788.new(context),
|
682
|
+
W0789.new(context),
|
675
683
|
W0790.new(context),
|
676
684
|
W0795.new(context),
|
677
685
|
W0796.new(context),
|
@@ -680,6 +688,7 @@ module C #:nodoc:
|
|
680
688
|
W0799.new(context),
|
681
689
|
W0800.new(context),
|
682
690
|
W0801.new(context),
|
691
|
+
W0809.new(context),
|
683
692
|
W0810.new(context),
|
684
693
|
W0827.new(context),
|
685
694
|
W0828.new(context),
|
@@ -690,6 +699,7 @@ module C #:nodoc:
|
|
690
699
|
W1027.new(context),
|
691
700
|
W1028.new(context),
|
692
701
|
W1029.new(context),
|
702
|
+
W1030.new(context),
|
693
703
|
W1031.new(context),
|
694
704
|
W1032.new(context),
|
695
705
|
W1033.new(context),
|
@@ -698,6 +708,17 @@ module C #:nodoc:
|
|
698
708
|
W1050.new(context),
|
699
709
|
W1051.new(context),
|
700
710
|
W1052.new(context),
|
711
|
+
W1053.new(context),
|
712
|
+
W1054.new(context),
|
713
|
+
W1055.new(context),
|
714
|
+
W1056.new(context),
|
715
|
+
W1057.new(context),
|
716
|
+
W1058.new(context),
|
717
|
+
W1059.new(context),
|
718
|
+
W1060.new(context),
|
719
|
+
W1061.new(context),
|
720
|
+
W1062.new(context),
|
721
|
+
W1063.new(context),
|
701
722
|
W1064.new(context),
|
702
723
|
W1065.new(context),
|
703
724
|
W9001.new(context)
|
data/lib/adlint/c/syntax.rb
CHANGED
@@ -31,6 +31,7 @@
|
|
31
31
|
|
32
32
|
require "adlint/symbol"
|
33
33
|
require "adlint/util"
|
34
|
+
require "adlint/c/enum"
|
34
35
|
require "adlint/c/seqp"
|
35
36
|
|
36
37
|
module AdLint #:nodoc:
|
@@ -411,10 +412,16 @@ module C #:nodoc:
|
|
411
412
|
subclass_responsibility
|
412
413
|
end
|
413
414
|
|
414
|
-
def constant?
|
415
|
-
|
416
|
-
|
417
|
-
|
415
|
+
def constant?(enumerator_table)
|
416
|
+
object_specifiers.all? { |object_specifier|
|
417
|
+
enumerator_table.lookup(object_specifier.identifier.value)
|
418
|
+
}
|
419
|
+
end
|
420
|
+
|
421
|
+
def object_specifiers
|
422
|
+
ObjectSpecifierCollector.new.tap { |collector|
|
423
|
+
self.accept(collector)
|
424
|
+
}.object_specifiers
|
418
425
|
end
|
419
426
|
|
420
427
|
def to_s
|
data/lib/adlint/c/type.rb
CHANGED
@@ -7558,7 +7558,7 @@ module C #:nodoc:
|
|
7558
7558
|
end
|
7559
7559
|
size ||= 0
|
7560
7560
|
else
|
7561
|
-
if size_expression.
|
7561
|
+
if size_expression.object_specifiers.empty?
|
7562
7562
|
object = Interpreter.new(@type_table).execute(size_expression)
|
7563
7563
|
if object.variable? && object.value.scalar?
|
7564
7564
|
size = object.value.unique_sample
|
data/lib/adlint/cpp.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Inline assembly notations.
|
2
|
+
#
|
3
|
+
# Author:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
|
4
|
+
# Copyright:: Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
|
5
|
+
# License:: GPLv3+: GNU General Public License version 3 or later
|
6
|
+
#
|
7
|
+
# Owner:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
|
8
|
+
|
9
|
+
#--
|
10
|
+
# ___ ____ __ ___ _________
|
11
|
+
# / | / _ |/ / / / | / /__ __/ Source Code Static Analyzer
|
12
|
+
# / /| | / / / / / / / |/ / / / AdLint - Advanced Lint
|
13
|
+
# / __ |/ /_/ / /___/ / /| / / /
|
14
|
+
# /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
|
15
|
+
#
|
16
|
+
# This file is part of AdLint.
|
17
|
+
#
|
18
|
+
# AdLint is free software: you can redistribute it and/or modify it under the
|
19
|
+
# terms of the GNU General Public License as published by the Free Software
|
20
|
+
# Foundation, either version 3 of the License, or (at your option) any later
|
21
|
+
# version.
|
22
|
+
#
|
23
|
+
# AdLint is distributed in the hope that it will be useful, but WITHOUT ANY
|
24
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
25
|
+
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
26
|
+
#
|
27
|
+
# You should have received a copy of the GNU General Public License along with
|
28
|
+
# AdLint. If not, see <http://www.gnu.org/licenses/>.
|
29
|
+
#
|
30
|
+
#++
|
31
|
+
|
32
|
+
require "adlint/cpp/subst"
|
33
|
+
|
34
|
+
module AdLint #:nodoc:
|
35
|
+
module Cpp #:nodoc:
|
36
|
+
|
37
|
+
module InlineAssemblyDefinition
|
38
|
+
def create_inline_assembly_substitutions(source)
|
39
|
+
[create_cxx_asm_definition(source)] +
|
40
|
+
create_extended_asm_definitions(source)
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_cxx_asm_definition(source)
|
44
|
+
CodeSubstitution.new("asm(__adlint__any);", "").tap do |subst|
|
45
|
+
subst.on_substitution += lambda { |location, matched|
|
46
|
+
source.on_inline_assembly.invoke(location, matched)
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_extended_asm_definitions(source)
|
52
|
+
[
|
53
|
+
"__asm(__adlint__any);",
|
54
|
+
"asm { __adlint__any }",
|
55
|
+
"__asm { __adlint__any }",
|
56
|
+
"__asm__(__adlint__any);",
|
57
|
+
"__asm__ volatile (__adlint__any);",
|
58
|
+
"__asm__ __volatile__ (__adlint__any);",
|
59
|
+
"asm(__adlint__any);",
|
60
|
+
"asm volatile (__adlint__any);",
|
61
|
+
"asm __volatile__ (__adlint__any);"
|
62
|
+
].map do |pattern|
|
63
|
+
CodeSubstitution.new(pattern, "").tap { |subst|
|
64
|
+
subst.on_substitution += lambda { |location, matched|
|
65
|
+
source.on_inline_assembly.invoke(location, matched)
|
66
|
+
}
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
data/lib/adlint/cpp/message.rb
CHANGED
@@ -771,6 +771,19 @@ module Cpp #:nodoc:
|
|
771
771
|
end
|
772
772
|
end
|
773
773
|
|
774
|
+
class W0541 < PassiveMessageDetection
|
775
|
+
# NOTE: W0541 may be duplicative when the same header which has the token
|
776
|
+
# sequence of the compiler specific extension is included twice or
|
777
|
+
# more.
|
778
|
+
ensure_uniqueness_of :W0541
|
779
|
+
|
780
|
+
def initialize(context)
|
781
|
+
super
|
782
|
+
context[:c_source].on_inline_assembly +=
|
783
|
+
lambda { |location, matched| W(:W0541, location) }
|
784
|
+
end
|
785
|
+
end
|
786
|
+
|
774
787
|
class W0549 < PassiveMessageDetection
|
775
788
|
# NOTE: W0549 may be duplicative when the same header which causes this
|
776
789
|
# warning is included twice or more.
|
@@ -147,5 +147,41 @@ module Cpp #:nodoc:
|
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
+
class W0807 < W0687
|
151
|
+
# NOTE: W0807 may be duplicative when the same header which causes this
|
152
|
+
# warning is included twice or more.
|
153
|
+
ensure_uniqueness_of :W0807
|
154
|
+
|
155
|
+
private
|
156
|
+
def check(undef_line, macro)
|
157
|
+
if macro.kind_of?(SpecialMacro)
|
158
|
+
identifier = undef_line.identifier
|
159
|
+
W(:W0807, identifier.location, identifier.value)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
class W0808 < PassiveMessageDetection
|
165
|
+
# NOTE: W0808 may be duplicative when the same header which causes this
|
166
|
+
# warning is included twice or more.
|
167
|
+
ensure_uniqueness_of :W0808
|
168
|
+
|
169
|
+
def initialize(context)
|
170
|
+
super
|
171
|
+
interp = context[:cpp_interpreter]
|
172
|
+
interp.on_object_like_macro_defined += method(:check)
|
173
|
+
@macro_table = context[:cpp_macro_table]
|
174
|
+
end
|
175
|
+
|
176
|
+
private
|
177
|
+
def check(define_line, macro)
|
178
|
+
identifier = define_line.identifier
|
179
|
+
|
180
|
+
if @macro_table.lookup(identifier.value)
|
181
|
+
W(:W0808, identifier.location, identifier.value)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
150
186
|
end
|
151
187
|
end
|
data/lib/adlint/cpp/phase.rb
CHANGED
@@ -94,6 +94,7 @@ module Cpp #:nodoc:
|
|
94
94
|
W0483.new(context),
|
95
95
|
W0511.new(context),
|
96
96
|
W0528.new(context),
|
97
|
+
W0541.new(context),
|
97
98
|
W0549.new(context),
|
98
99
|
W0554.new(context),
|
99
100
|
W0574.new(context),
|
@@ -108,6 +109,8 @@ module Cpp #:nodoc:
|
|
108
109
|
W0696.new(context),
|
109
110
|
W0804.new(context),
|
110
111
|
W0806.new(context),
|
112
|
+
W0807.new(context),
|
113
|
+
W0808.new(context),
|
111
114
|
W0831.new(context),
|
112
115
|
W9002.new(context)
|
113
116
|
]
|
data/lib/adlint/cpp/source.rb
CHANGED
@@ -31,12 +31,15 @@
|
|
31
31
|
|
32
32
|
require "adlint/token"
|
33
33
|
require "adlint/util"
|
34
|
+
require "adlint/cpp/asm"
|
34
35
|
require "adlint/cpp/subst"
|
35
36
|
|
36
37
|
module AdLint #:nodoc:
|
37
38
|
module Cpp #:nodoc:
|
38
39
|
|
39
40
|
class PreprocessedSource
|
41
|
+
include InlineAssemblyDefinition
|
42
|
+
|
40
43
|
def initialize(root_fpath)
|
41
44
|
@root_fpath = root_fpath
|
42
45
|
@tokens = []
|
@@ -45,6 +48,7 @@ module Cpp #:nodoc:
|
|
45
48
|
extend Pluggable
|
46
49
|
|
47
50
|
def_plugin :on_language_extension
|
51
|
+
def_plugin :on_inline_assembly
|
48
52
|
|
49
53
|
attr_reader :root_fpath
|
50
54
|
|
@@ -68,6 +72,11 @@ module Cpp #:nodoc:
|
|
68
72
|
substitution = create_arbitrary_substitution(pattern, replacement)
|
69
73
|
@tokens = substitution.execute(@tokens)
|
70
74
|
end
|
75
|
+
|
76
|
+
create_inline_assembly_substitutions(self).each do |substitution|
|
77
|
+
@tokens = substitution.execute(@tokens)
|
78
|
+
end
|
79
|
+
|
71
80
|
self
|
72
81
|
end
|
73
82
|
|
data/lib/adlint/version.rb
CHANGED
@@ -32,9 +32,9 @@
|
|
32
32
|
module AdLint #:nodoc:
|
33
33
|
|
34
34
|
MAJOR_VERSION = 1
|
35
|
-
MINOR_VERSION =
|
35
|
+
MINOR_VERSION = 6
|
36
36
|
PATCH_VERSION = 0
|
37
|
-
RELEASE_DATE = "2012-
|
37
|
+
RELEASE_DATE = "2012-04-06"
|
38
38
|
|
39
39
|
TRAITS_SCHEMA_VERSION = "1.0.0"
|
40
40
|
|
@@ -64,7 +64,7 @@ module AdLint #:nodoc:
|
|
64
64
|
EOS
|
65
65
|
|
66
66
|
AUTHOR = <<EOS
|
67
|
-
Written by Yutaka Yanoh, Rie Shima and
|
67
|
+
Written by Yutaka Yanoh, Rie Shima and OGIS-RI Co.,Ltd.
|
68
68
|
|
69
69
|
EOS
|
70
70
|
|
data/share/demo/Makefile
CHANGED
@@ -11,6 +11,7 @@ bad_conv \
|
|
11
11
|
bad_enum \
|
12
12
|
bad_indent \
|
13
13
|
bad_init \
|
14
|
+
bad_label \
|
14
15
|
bad_line \
|
15
16
|
bad_macro \
|
16
17
|
bad_return \
|
@@ -32,6 +33,7 @@ implicit_conv \
|
|
32
33
|
implicit_int \
|
33
34
|
incomplete_type \
|
34
35
|
indirect_recur \
|
36
|
+
inline_asm \
|
35
37
|
intro_demo \
|
36
38
|
invalid_call \
|
37
39
|
kandr_fundef \
|
@@ -60,6 +62,8 @@ octal_const \
|
|
60
62
|
output_by_param \
|
61
63
|
overflow \
|
62
64
|
press_release \
|
65
|
+
redundant_select \
|
66
|
+
reserved_ident \
|
63
67
|
retn_lvar_addr \
|
64
68
|
sequence_point \
|
65
69
|
shift_expr \
|
@@ -44,5 +44,17 @@ int main(void)
|
|
44
44
|
scanf("%3llc %fc\n", &i, &ii);
|
45
45
|
scanf("%3llz %c\n", &i, &ii);
|
46
46
|
|
47
|
+
scanf("%[z-a]\n", &i);
|
48
|
+
scanf("%[abcd]\n", &i);
|
49
|
+
scanf("%[abca]\n", &i);
|
50
|
+
|
47
51
|
return 0;
|
48
52
|
}
|
53
|
+
|
54
|
+
static void foo(void)
|
55
|
+
{
|
56
|
+
char buf[256];
|
57
|
+
|
58
|
+
printf("%s", buf);
|
59
|
+
scanf("%s", buf);
|
60
|
+
}
|
@@ -3,24 +3,70 @@ enum Bar { BAR_A = 1, BAR_B, BAR_C };
|
|
3
3
|
enum Baz { BAZ_A = 2, BAZ_B = 4, BAZ_C = 8 };
|
4
4
|
|
5
5
|
extern void func1(enum Foo f);
|
6
|
+
int func3(int i)
|
7
|
+
{
|
8
|
+
const enum Foo foo = FOO_A;
|
9
|
+
|
10
|
+
foo1(i);
|
11
|
+
foo = i;
|
12
|
+
foo = FOO_A + i;
|
13
|
+
|
14
|
+
switch (i) {
|
15
|
+
case FOO_A:
|
16
|
+
return foo;
|
17
|
+
case FOO_B:
|
18
|
+
return FOO_B;
|
19
|
+
case FOO_C:
|
20
|
+
return i;
|
21
|
+
default:
|
22
|
+
return (int) BAR_A;
|
23
|
+
}
|
24
|
+
}
|
6
25
|
|
7
|
-
enum Foo func2(const enum Foo param)
|
26
|
+
enum Foo func2(const enum Foo param, const int i)
|
8
27
|
{
|
9
28
|
enum Foo foo = BAR_A;
|
29
|
+
enum Bar bar = BAZ_A;
|
30
|
+
enum Baz baz = FOO_A;
|
31
|
+
|
10
32
|
foo = FOO_A;
|
33
|
+
bar = BAR_A;
|
34
|
+
baz = BAZ_A;
|
35
|
+
|
36
|
+
func3(foo);
|
37
|
+
func3(BAR_A);
|
38
|
+
func3((int) BAZ_C);
|
11
39
|
|
12
40
|
switch (param) {
|
13
41
|
case FOO_A:
|
14
42
|
foo = BAR_A;
|
15
43
|
func1(BAR_A);
|
44
|
+
func1(1);
|
45
|
+
func1(baz);
|
46
|
+
foo = 1;
|
47
|
+
foo = bar;
|
16
48
|
return BAR_B;
|
17
49
|
case BAR_B:
|
18
50
|
case 5:
|
19
51
|
foo = BAZ_C;
|
20
52
|
func1(BAZ_C);
|
53
|
+
func1(0x2);
|
54
|
+
baz = BAZ_C;
|
55
|
+
func1(baz);
|
56
|
+
foo = 0x2;
|
57
|
+
foo = baz;
|
21
58
|
return BAZ_C;
|
22
59
|
case 6:
|
23
|
-
return 10;
|
60
|
+
return FOO_A + 10;
|
61
|
+
case 7:
|
62
|
+
return FOO_A + i;
|
63
|
+
case 8:
|
64
|
+
return bar;
|
65
|
+
case 9:
|
66
|
+
baz = BAZ_C;
|
67
|
+
return baz;
|
68
|
+
case 10:
|
69
|
+
return i;
|
24
70
|
}
|
25
71
|
|
26
72
|
return FOO_C;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
int foo(const int i)
|
2
|
+
{
|
3
|
+
if (i == 0) {
|
4
|
+
label:
|
5
|
+
return 0;
|
6
|
+
}
|
7
|
+
|
8
|
+
if (i < 0) {
|
9
|
+
goto label;
|
10
|
+
}
|
11
|
+
|
12
|
+
label:
|
13
|
+
return 1;
|
14
|
+
}
|
15
|
+
|
16
|
+
int bar(const int i)
|
17
|
+
{
|
18
|
+
if (i == 0) {
|
19
|
+
goto label;
|
20
|
+
}
|
21
|
+
|
22
|
+
i = 0;
|
23
|
+
|
24
|
+
label:
|
25
|
+
return i;
|
26
|
+
}
|