adlint 1.10.0 → 1.12.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.
Files changed (49) hide show
  1. data/ChangeLog +197 -4
  2. data/MANIFEST +17 -0
  3. data/NEWS +23 -4
  4. data/etc/mesg.d/en_US/messages.yml +14 -1
  5. data/etc/mesg.d/ja_JP/messages.yml +14 -1
  6. data/features/message_detection/W0093.feature +87 -0
  7. data/features/message_detection/W0687.feature +25 -0
  8. data/features/message_detection/W0688.feature +63 -0
  9. data/features/message_detection/W0689.feature +46 -0
  10. data/features/message_detection/W0690.feature +35 -0
  11. data/features/message_detection/W0698.feature +3 -2
  12. data/features/message_detection/W0703.feature +1 -0
  13. data/features/message_detection/W0723.feature +34 -0
  14. data/features/message_detection/W0732.feature +158 -0
  15. data/features/message_detection/W0733.feature +158 -0
  16. data/features/message_detection/W0734.feature +322 -0
  17. data/features/message_detection/W0735.feature +322 -0
  18. data/features/message_detection/W1052.feature +66 -0
  19. data/features/message_detection/W9001.feature +33 -0
  20. data/features/message_detection/W9003.feature +131 -0
  21. data/lib/adlint/c/ctrlexpr.rb +51 -50
  22. data/lib/adlint/c/domain.rb +237 -223
  23. data/lib/adlint/c/expr.rb +6 -8
  24. data/lib/adlint/c/interp.rb +8 -11
  25. data/lib/adlint/c/message.rb +20 -0
  26. data/lib/adlint/c/message_shima.rb +63 -0
  27. data/lib/adlint/c/object.rb +5 -4
  28. data/lib/adlint/c/operator.rb +99 -0
  29. data/lib/adlint/c/parser.rb +2 -2
  30. data/lib/adlint/c/parser.y +2 -2
  31. data/lib/adlint/c/phase.rb +6 -1
  32. data/lib/adlint/c/syntax.rb +442 -30
  33. data/lib/adlint/c/type.rb +449 -363
  34. data/lib/adlint/c/value.rb +96 -25
  35. data/lib/adlint/c.rb +1 -0
  36. data/lib/adlint/prelude.rb +16 -18
  37. data/lib/adlint/version.rb +2 -2
  38. data/share/doc/developers_guide_ja.html +11 -5
  39. data/share/doc/developers_guide_ja.texi +9 -3
  40. data/share/doc/users_guide_en.html +697 -131
  41. data/share/doc/users_guide_en.texi +491 -41
  42. data/share/doc/users_guide_ja.html +709 -139
  43. data/share/doc/users_guide_ja.texi +499 -45
  44. data/spec/adlint/c/ctrlexpr_spec.rb +168 -0
  45. data/spec/adlint/c/domain_spec.rb +835 -0
  46. data/spec/adlint/c/operator_spec.rb +406 -0
  47. data/spec/adlint/c/syntax_spec.rb +717 -0
  48. data/spec/adlint/c/type_spec.rb +55 -30
  49. metadata +19 -2
@@ -0,0 +1,168 @@
1
+ # Unit specification of controlling expression of selection-statements and
2
+ # iteration-statements.
3
+ #
4
+ # Author:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
5
+ # Copyright:: Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
6
+ # License:: GPLv3+: GNU General Public License version 3 or later
7
+ #
8
+ # Owner:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
9
+
10
+ #--
11
+ # ___ ____ __ ___ _________
12
+ # / | / _ |/ / / / | / /__ __/ Source Code Static Analyzer
13
+ # / /| | / / / / / / / |/ / / / AdLint - Advanced Lint
14
+ # / __ |/ /_/ / /___/ / /| / / /
15
+ # /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
16
+ #
17
+ # This file is part of AdLint.
18
+ #
19
+ # AdLint is free software: you can redistribute it and/or modify it under the
20
+ # terms of the GNU General Public License as published by the Free Software
21
+ # Foundation, either version 3 of the License, or (at your option) any later
22
+ # version.
23
+ #
24
+ # AdLint is distributed in the hope that it will be useful, but WITHOUT ANY
25
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
26
+ # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
27
+ #
28
+ # You should have received a copy of the GNU General Public License along with
29
+ # AdLint. If not, see <http://www.gnu.org/licenses/>.
30
+ #
31
+ #++
32
+
33
+ require "spec_helper"
34
+
35
+ module AdLint
36
+ module C
37
+
38
+ describe ControllingExpression do
39
+ before(:all) { Traits.instance.read_from($default_traits) }
40
+
41
+ before(:each) do
42
+ @symbol_table = SymbolTable.new
43
+ @type_table = TypeTable.new
44
+ @interpreter = Interpreter.new(@type_table)
45
+ @int_i = @interpreter.define_variable(int_i_definition)
46
+ @int_j = @interpreter.define_variable(int_j_definition)
47
+ end
48
+
49
+ context "`int i = ((> 0) && (< 10)) || (== 0)' and " +
50
+ "`int j = ((> 0) && (< 10)) || (== 0)'" do
51
+ before do
52
+ @int_i.narrow_value_domain!(Operator::GE, ScalarValue.of(0))
53
+ @int_i.narrow_value_domain!(Operator::LT, ScalarValue.of(10))
54
+ @int_j.narrow_value_domain!(Operator::GE, ScalarValue.of(0))
55
+ @int_j.narrow_value_domain!(Operator::LT, ScalarValue.of(10))
56
+ end
57
+
58
+ it "(i == j) makes that `i' should contain 0 and 9, " +
59
+ "and should not contain 10" do
60
+ expr = EqualityExpression.new(eq_operator, i_specifier, j_specifier)
61
+ branched_eval(expr, NARROWING, FINAL) do
62
+ @int_i.value.may_be_equal_to?(ScalarValue.of(0)).should be_true
63
+ @int_i.value.may_be_equal_to?(ScalarValue.of(9)).should be_true
64
+ @int_i.value.may_be_equal_to?(ScalarValue.of(10)).should_not be_true
65
+ end
66
+ end
67
+
68
+ it "(i != j) makes that `i' should contain 0 and 9, " +
69
+ "and should not contain 10" do
70
+ expr = EqualityExpression.new(ne_operator, i_specifier, j_specifier)
71
+ branched_eval(expr, NARROWING, FINAL) do
72
+ @int_i.value.may_be_equal_to?(ScalarValue.of(0)).should be_true
73
+ @int_i.value.may_be_equal_to?(ScalarValue.of(9)).should be_true
74
+ @int_i.value.may_be_equal_to?(ScalarValue.of(10)).should_not be_true
75
+ end
76
+ end
77
+ end
78
+
79
+ context "`int i = ((> 0) && (< 10)) || (== 0)' and " +
80
+ "`int j = ((> 3) && (< 5)) || (== 3)'" do
81
+ before do
82
+ @int_i.narrow_value_domain!(Operator::GE, ScalarValue.of(0))
83
+ @int_i.narrow_value_domain!(Operator::LT, ScalarValue.of(10))
84
+ @int_j.narrow_value_domain!(Operator::GE, ScalarValue.of(3))
85
+ @int_j.narrow_value_domain!(Operator::LT, ScalarValue.of(5))
86
+ end
87
+
88
+ it "(i == j) makes that `i' should contain 3 and 4, " +
89
+ "and should not contain 0" do
90
+ expr = EqualityExpression.new(eq_operator, i_specifier, j_specifier)
91
+ branched_eval(expr, NARROWING, FINAL) do
92
+ @int_i.value.may_be_equal_to?(ScalarValue.of(3)).should be_true
93
+ @int_i.value.may_be_equal_to?(ScalarValue.of(4)).should be_true
94
+ @int_i.value.may_be_equal_to?(ScalarValue.of(0)).should_not be_true
95
+ end
96
+ end
97
+ end
98
+
99
+ include InterpreterMediator
100
+
101
+ private
102
+ def eq_operator
103
+ Token.new("==", "==", nil_loc)
104
+ end
105
+
106
+ def ne_operator
107
+ Token.new("!=", "!=", nil_loc)
108
+ end
109
+
110
+ def i_specifier
111
+ object_specifier_of("i")
112
+ end
113
+
114
+ def j_specifier
115
+ object_specifier_of("j")
116
+ end
117
+
118
+ def object_specifier_of(name)
119
+ ObjectSpecifier.new(identifier_of(name))
120
+ end
121
+
122
+ def int_i_definition
123
+ uninitialized_int_vardef("i", @type_table.int_type)
124
+ end
125
+
126
+ def int_j_definition
127
+ uninitialized_int_vardef("j", @type_table.int_type)
128
+ end
129
+
130
+ def uninitialized_int_vardef(name, type)
131
+ decl_specs = DeclarationSpecifiers.new.tap { |ds|
132
+ ds.type_specifiers.push(int_type_specifier)
133
+ }
134
+ decl = Declaration.new(decl_specs, [uninitialized_int_decl(name)],
135
+ @symbol_table)
136
+ decl.items.each { |item| item.type = type }
137
+ decl.items.find { |item| item.kind_of?(VariableDefinition) }
138
+ end
139
+
140
+ def uninitialized_int_decl(name)
141
+ InitDeclarator.new(IdentifierDeclarator.new(identifier_of(name)), nil)
142
+ end
143
+
144
+ def int_type_specifier
145
+ StandardTypeSpecifier.new(Token.new(:INT, "int", Location.new))
146
+ end
147
+
148
+ def identifier_of(name)
149
+ Token.new(:IDENTIFIER, name, nil_loc)
150
+ end
151
+
152
+ def nil_loc
153
+ Location.new
154
+ end
155
+
156
+ def resolve_type(node)
157
+ StaticTypeResolver.new.resolve(node)
158
+ end
159
+
160
+ def interpreter
161
+ @interpreter
162
+ end
163
+ end
164
+
165
+ include BranchOptions
166
+
167
+ end
168
+ end