adlint 1.4.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/MANIFEST
CHANGED
@@ -38,6 +38,7 @@ lib/adlint/c/const.rb
|
|
38
38
|
lib/adlint/c/conv.rb
|
39
39
|
lib/adlint/c/ctrlexpr.rb
|
40
40
|
lib/adlint/c/domain.rb
|
41
|
+
lib/adlint/c/enum.rb
|
41
42
|
lib/adlint/c/environ.rb
|
42
43
|
lib/adlint/c/expr.rb
|
43
44
|
lib/adlint/c/format.rb
|
@@ -61,6 +62,7 @@ lib/adlint/c/util.rb
|
|
61
62
|
lib/adlint/c/value.rb
|
62
63
|
lib/adlint/code.rb
|
63
64
|
lib/adlint/cpp.rb
|
65
|
+
lib/adlint/cpp/asm.rb
|
64
66
|
lib/adlint/cpp/code.rb
|
65
67
|
lib/adlint/cpp/constexpr.y
|
66
68
|
lib/adlint/cpp/constexpr.rb
|
@@ -113,6 +115,7 @@ share/demo/bad_conv/bad_conv.c
|
|
113
115
|
share/demo/bad_enum/bad_enum.c
|
114
116
|
share/demo/bad_indent/bad_indent.c
|
115
117
|
share/demo/bad_init/bad_init.c
|
118
|
+
share/demo/bad_label/bad_label.c
|
116
119
|
share/demo/bad_line/bad_line.c
|
117
120
|
share/demo/bad_macro/bad_macro.c
|
118
121
|
share/demo/bad_return/bad_return.c
|
@@ -140,6 +143,7 @@ share/demo/indirect_recur/indirect_recur_2.h
|
|
140
143
|
share/demo/indirect_recur/indirect_recur_3.c
|
141
144
|
share/demo/indirect_recur/indirect_recur_3.h
|
142
145
|
share/demo/indirect_recur/indirect_recur_4.c
|
146
|
+
share/demo/inline_asm/inline_asm.c
|
143
147
|
share/demo/intro_demo/intro_demo.c
|
144
148
|
share/demo/intro_demo/intro_demo.h
|
145
149
|
share/demo/intro_demo/useless_header.h
|
@@ -180,6 +184,8 @@ share/demo/octal_const/octal_const.c
|
|
180
184
|
share/demo/output_by_param/output_by_param.c
|
181
185
|
share/demo/overflow/overflow.c
|
182
186
|
share/demo/press_release/press_release.c
|
187
|
+
share/demo/redundant_select/redundant_select.c
|
188
|
+
share/demo/reserved_ident/reserved_ident.c
|
183
189
|
share/demo/retn_lvar_addr/retn_lvar_addr.c
|
184
190
|
share/demo/sequence_point/sequence_point.c
|
185
191
|
share/demo/shift_expr/shift_expr.c
|
data/NEWS
CHANGED
@@ -21,6 +21,49 @@
|
|
21
21
|
|
22
22
|
++
|
23
23
|
|
24
|
+
=== \AdLint 1.6.0 is released (2012-04-06)
|
25
|
+
|
26
|
+
==== Changes since the 1.4.0 release
|
27
|
+
|
28
|
+
* Add W0541 detection
|
29
|
+
* Add W0573 detection
|
30
|
+
* Add W0579 detection
|
31
|
+
* Add W0685 detection
|
32
|
+
* Add W0686 detection
|
33
|
+
* Add W0781 detection
|
34
|
+
* Add W0787 detection
|
35
|
+
* Add W0788 detection
|
36
|
+
* Add W0789 detection
|
37
|
+
* Add W0807 detection
|
38
|
+
* Add W0808 detection
|
39
|
+
* Add W0809 detection
|
40
|
+
* Add W1030 detection
|
41
|
+
* Add W1053 detection
|
42
|
+
* Add W1054 detection
|
43
|
+
* Add W1055 detection
|
44
|
+
* Add W1056 detection
|
45
|
+
* Add W1057 detection
|
46
|
+
* Add W1058 detection
|
47
|
+
* Add W1059 detection
|
48
|
+
* Add W1060 detection
|
49
|
+
* Add W1061 detection
|
50
|
+
* Add W1062 detection
|
51
|
+
* Add W1063 detection
|
52
|
+
* Fix W0027 detection not to warn when a pointer variable is compared
|
53
|
+
with NULL constant
|
54
|
+
* Fix W0728, W0729 and W0730 detections not to warn when the target
|
55
|
+
is a variable of the other enum type
|
56
|
+
* Fix W0104 detection not to warn about invariant parameter of array
|
57
|
+
type whose base type is qualified as const
|
58
|
+
* Fix bad W0031, W0100, W0104, W0459 and W0460 detections
|
59
|
+
* Fix bad FN_UNUV measurement
|
60
|
+
* Update the user's guide in Japanese
|
61
|
+
* Update the user's guide in English
|
62
|
+
|
63
|
+
See the file
|
64
|
+
{ChangeLog}[http://adlint.sourceforge.net/pmwiki/upload.d/Main/ChangeLog]
|
65
|
+
for more details.
|
66
|
+
|
24
67
|
=== \AdLint 1.4.0 is released (2012-03-29)
|
25
68
|
|
26
69
|
==== Changes since the 1.2.0 release
|
@@ -56,10 +99,6 @@
|
|
56
99
|
* Update the user's guide in Japanese
|
57
100
|
* Update the user's guide in English
|
58
101
|
|
59
|
-
See the file
|
60
|
-
{ChangeLog}[http://adlint.sourceforge.net/pmwiki/upload.d/Main/ChangeLog]
|
61
|
-
for more details.
|
62
|
-
|
63
102
|
=== \AdLint 1.2.0 is released (2012-03-21)
|
64
103
|
|
65
104
|
==== Changes since the 1.0.0 release
|
data/lib/adlint/c.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
# C Enumerators.
|
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/c/syntax"
|
33
|
+
|
34
|
+
module AdLint #:nodoc:
|
35
|
+
module C #:nodoc:
|
36
|
+
|
37
|
+
class EnumeratorTable
|
38
|
+
def initialize
|
39
|
+
@enumerators = {}
|
40
|
+
end
|
41
|
+
|
42
|
+
def define(enumerator)
|
43
|
+
@enumerators[enumerator.identifier.value] = enumerator
|
44
|
+
end
|
45
|
+
|
46
|
+
def lookup(name_str)
|
47
|
+
@enumerators[name_str]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/lib/adlint/c/expr.rb
CHANGED
@@ -45,16 +45,10 @@ module C #:nodoc:
|
|
45
45
|
variable.declarations_and_definitions.each do |decl_or_def|
|
46
46
|
decl_or_def.mark_as_referred_by(node.identifier)
|
47
47
|
end
|
48
|
-
if variable.type.array?
|
49
|
-
# NOTE: Array object is referred to derive the start address.
|
50
|
-
# NOTE: Kill this notification not to confuse the W0459 and W0460
|
51
|
-
# detections of the expression-statement `a[i] = 0;' when
|
52
|
-
# contents of `a' is not initialized.
|
53
|
-
# _notify_variable_value_referred(node, variable)
|
54
|
-
variable = temporary_variable(pointer_type(variable.type.base_type),
|
55
|
-
pointer_value_of(variable))
|
56
|
-
end
|
57
48
|
_notify_object_referred(node, variable)
|
49
|
+
# NOTE: Array object will be converted into its start address by the
|
50
|
+
# outer expression. So, it is correct to return an array object
|
51
|
+
# itself.
|
58
52
|
return variable
|
59
53
|
end
|
60
54
|
|
@@ -68,40 +62,43 @@ module C #:nodoc:
|
|
68
62
|
|
69
63
|
if enumerator = enumerator_named(node.identifier.value)
|
70
64
|
enumerator.mark_as_referred_by(node.identifier)
|
71
|
-
return temporary_variable(enumerator.type,
|
65
|
+
return temporary_variable(enumerator.type,
|
66
|
+
ScalarValue.of(enumerator.value))
|
72
67
|
end
|
73
68
|
|
74
69
|
define_implicit_function(node.identifier.value)
|
75
70
|
end
|
76
|
-
module_function :execute_object_specifier
|
77
71
|
|
78
72
|
def execute_array_subscript_expression(node, object, subscript)
|
79
73
|
unless object.variable? && (object.type.array? || object.type.pointer?)
|
80
74
|
return temporary_variable
|
81
75
|
end
|
82
|
-
_notify_variable_value_referred(node, object)
|
83
76
|
|
84
77
|
array_or_pointer = object
|
85
78
|
|
86
79
|
result_type = array_or_pointer.type.unqualify.base_type
|
87
80
|
result_type = pointer_type(result_type) if result_type.array?
|
88
81
|
|
89
|
-
unless subscript.variable? && subscript.value.scalar? &&
|
90
|
-
subscript.value.exist?
|
91
|
-
return temporary_variable(result_type)
|
92
|
-
end
|
93
|
-
_notify_variable_value_referred(node, subscript)
|
94
|
-
|
95
82
|
case
|
96
83
|
when array_or_pointer.type.array?
|
97
84
|
array = array_or_pointer
|
85
|
+
# NOTE: An array-subscript-expression with an array object only refers
|
86
|
+
# the array object, never refer the value of the array object.
|
98
87
|
when array_or_pointer.type.pointer?
|
99
88
|
if pointee = pointee_of(array_or_pointer) and pointee.type.array?
|
100
89
|
array = pointee
|
101
|
-
_notify_variable_value_referred(node, array)
|
102
90
|
end
|
91
|
+
# NOTE: An array-subscript-expression with a pointer object do refers
|
92
|
+
# the value of the pointer object.
|
93
|
+
_notify_variable_value_referred(node, array_or_pointer)
|
103
94
|
end
|
104
95
|
|
96
|
+
unless subscript.variable? && subscript.value.scalar? &&
|
97
|
+
subscript.value.exist?
|
98
|
+
return temporary_variable(result_type)
|
99
|
+
end
|
100
|
+
_notify_variable_value_referred(node, subscript)
|
101
|
+
|
105
102
|
# NOTE: An array subscript converted to `int' implicitly.
|
106
103
|
if subscript.type.same_as?(int_type)
|
107
104
|
int_subscript = subscript
|
@@ -118,21 +115,16 @@ module C #:nodoc:
|
|
118
115
|
subscript_value = int_subscript.value.unique_sample
|
119
116
|
if array and inner_variable = array.inner_variable_at(subscript_value)
|
120
117
|
_notify_object_referred(node, inner_variable)
|
121
|
-
if inner_variable.type.
|
122
|
-
result = temporary_variable(result_type,
|
123
|
-
pointer_value_of(inner_variable))
|
124
|
-
else
|
118
|
+
if inner_variable.type.same_as?(result_type)
|
125
119
|
result = inner_variable
|
126
120
|
end
|
127
|
-
else
|
128
|
-
result = temporary_variable(result_type)
|
129
121
|
end
|
122
|
+
result ||= temporary_variable(result_type)
|
130
123
|
|
131
124
|
notify_array_subscript_expr_evaled(node, array_or_pointer,
|
132
125
|
int_subscript, array, result)
|
133
126
|
result
|
134
127
|
end
|
135
|
-
module_function :execute_array_subscript_expression
|
136
128
|
|
137
129
|
def execute_function_call_expression(node, object, args)
|
138
130
|
if object.function?
|
@@ -151,8 +143,6 @@ module C #:nodoc:
|
|
151
143
|
end
|
152
144
|
_notify_variable_value_referred(node, object)
|
153
145
|
|
154
|
-
args.each { |arg, expr| _notify_variable_value_referred(expr, arg) }
|
155
|
-
|
156
146
|
# NOTE: The ISO C99 standard saids;
|
157
147
|
#
|
158
148
|
# 6.5.2.2 Function calls
|
@@ -166,13 +156,12 @@ module C #:nodoc:
|
|
166
156
|
|
167
157
|
result = function.call(interpreter, node, args)
|
168
158
|
unless function.builtin?
|
169
|
-
|
170
|
-
|
159
|
+
arg_variables = args.map { |arg, expr| object_to_variable(arg) }
|
160
|
+
notify_function_call_expr_evaled(node, function, arg_variables, result)
|
171
161
|
end
|
172
162
|
|
173
163
|
result
|
174
164
|
end
|
175
|
-
module_function :execute_function_call_expression
|
176
165
|
|
177
166
|
def execute_member_access_by_value_expression(node, object)
|
178
167
|
unless object.variable? && object.type.composite?
|
@@ -181,7 +170,8 @@ module C #:nodoc:
|
|
181
170
|
variable = object
|
182
171
|
|
183
172
|
member_variable = variable.inner_variable_named(node.identifier.value)
|
184
|
-
|
173
|
+
# NOTE: A member-access-by-value-expression only refers the composite
|
174
|
+
# object, never refer the value of the composite object.
|
185
175
|
|
186
176
|
# NOTE: `member_variable' is nil when this expression represents the
|
187
177
|
# direct member access extension.
|
@@ -189,16 +179,11 @@ module C #:nodoc:
|
|
189
179
|
|
190
180
|
if member_variable
|
191
181
|
_notify_object_referred(node, member_variable)
|
192
|
-
if member_variable.type.array?
|
193
|
-
type = pointer_type(member_variable.type.base_type)
|
194
|
-
return temporary_variable(type, pointer_value_of(member_variable))
|
195
|
-
end
|
196
182
|
member_variable
|
197
183
|
else
|
198
184
|
temporary_variable
|
199
185
|
end
|
200
186
|
end
|
201
|
-
module_function :execute_member_access_by_value_expression
|
202
187
|
|
203
188
|
def execute_member_access_by_pointer_expression(node, object)
|
204
189
|
unqualified_type = object.type.unqualify
|
@@ -218,6 +203,8 @@ module C #:nodoc:
|
|
218
203
|
end
|
219
204
|
end
|
220
205
|
end
|
206
|
+
# NOTE: A member-access-by-pointer-expression do refers the value of the
|
207
|
+
# pointer object.
|
221
208
|
_notify_variable_value_referred(node, pointer)
|
222
209
|
|
223
210
|
if pointee && pointee.type.composite?
|
@@ -233,16 +220,11 @@ module C #:nodoc:
|
|
233
220
|
|
234
221
|
if member_variable
|
235
222
|
_notify_object_referred(node, member_variable)
|
236
|
-
if member_variable.type.array?
|
237
|
-
type = pointer_type(member_variable.type.base_type)
|
238
|
-
return temporary_variable(type, pointer_value_of(member_variable))
|
239
|
-
end
|
240
223
|
member_variable
|
241
224
|
else
|
242
225
|
temporary_variable
|
243
226
|
end
|
244
227
|
end
|
245
|
-
module_function :execute_member_access_by_pointer_expression
|
246
228
|
|
247
229
|
def execute_postfix_increment_expression(node, object)
|
248
230
|
return temporary_variable unless object.variable? && object.type.scalar?
|
@@ -264,7 +246,6 @@ module C #:nodoc:
|
|
264
246
|
|
265
247
|
result
|
266
248
|
end
|
267
|
-
module_function :execute_postfix_increment_expression
|
268
249
|
|
269
250
|
def execute_postfix_decrement_expression(node, object)
|
270
251
|
return temporary_variable unless object.variable? && object.type.scalar?
|
@@ -286,7 +267,6 @@ module C #:nodoc:
|
|
286
267
|
|
287
268
|
result
|
288
269
|
end
|
289
|
-
module_function :execute_postfix_decrement_expression
|
290
270
|
|
291
271
|
def execute_prefix_increment_expression(node, object)
|
292
272
|
return temporary_variable unless object.variable? && object.type.scalar?
|
@@ -308,7 +288,6 @@ module C #:nodoc:
|
|
308
288
|
|
309
289
|
variable
|
310
290
|
end
|
311
|
-
module_function :execute_prefix_increment_expression
|
312
291
|
|
313
292
|
def execute_prefix_decrement_expression(node, object)
|
314
293
|
return temporary_variable unless object.variable? && object.type.scalar?
|
@@ -330,7 +309,6 @@ module C #:nodoc:
|
|
330
309
|
|
331
310
|
variable
|
332
311
|
end
|
333
|
-
module_function :execute_prefix_decrement_expression
|
334
312
|
|
335
313
|
def execute_address_expression(node, object)
|
336
314
|
# NOTE: An address-expression does not read the value of the object. But
|
@@ -340,7 +318,6 @@ module C #:nodoc:
|
|
340
318
|
|
341
319
|
temporary_variable(pointer_type(object.type), pointer_value_of(object))
|
342
320
|
end
|
343
|
-
module_function :execute_address_expression
|
344
321
|
|
345
322
|
def execute_indirection_expression(node, object)
|
346
323
|
return temporary_variable unless object.variable? && object.type.pointer?
|
@@ -376,7 +353,6 @@ module C #:nodoc:
|
|
376
353
|
|
377
354
|
pointee
|
378
355
|
end
|
379
|
-
module_function :execute_indirection_expression
|
380
356
|
|
381
357
|
def execute_unary_arithmetic_expression(node, object)
|
382
358
|
variable = object_to_variable(object)
|
@@ -404,7 +380,6 @@ module C #:nodoc:
|
|
404
380
|
|
405
381
|
result
|
406
382
|
end
|
407
|
-
module_function :execute_unary_arithmetic_expression
|
408
383
|
|
409
384
|
def execute_cast_expression(node, object)
|
410
385
|
resolve_unresolved_type(node.type_name)
|
@@ -418,7 +393,6 @@ module C #:nodoc:
|
|
418
393
|
|
419
394
|
converted
|
420
395
|
end
|
421
|
-
module_function :execute_cast_expression
|
422
396
|
|
423
397
|
def execute_multiplicative_expression(node, lhs_object, rhs_object)
|
424
398
|
lhs_variable = object_to_variable(lhs_object)
|
@@ -478,7 +452,6 @@ module C #:nodoc:
|
|
478
452
|
result)
|
479
453
|
result
|
480
454
|
end
|
481
|
-
module_function :execute_multiplicative_expression
|
482
455
|
|
483
456
|
def execute_additive_expression(node, lhs_object, rhs_object)
|
484
457
|
lhs_variable = object_to_variable(lhs_object)
|
@@ -531,7 +504,6 @@ module C #:nodoc:
|
|
531
504
|
|
532
505
|
result
|
533
506
|
end
|
534
|
-
module_function :execute_additive_expression
|
535
507
|
|
536
508
|
def execute_shift_expression(node, lhs_object, rhs_object)
|
537
509
|
lhs_variable = object_to_variable(lhs_object)
|
@@ -592,7 +564,6 @@ module C #:nodoc:
|
|
592
564
|
|
593
565
|
result
|
594
566
|
end
|
595
|
-
module_function :execute_shift_expression
|
596
567
|
|
597
568
|
def execute_relational_expression(node, lhs_object, rhs_object)
|
598
569
|
lhs_variable = object_to_variable(lhs_object)
|
@@ -652,7 +623,6 @@ module C #:nodoc:
|
|
652
623
|
|
653
624
|
result
|
654
625
|
end
|
655
|
-
module_function :execute_relational_expression
|
656
626
|
|
657
627
|
def execute_equality_expression(node, lhs_object, rhs_object)
|
658
628
|
lhs_variable = object_to_variable(lhs_object)
|
@@ -706,7 +676,6 @@ module C #:nodoc:
|
|
706
676
|
|
707
677
|
result
|
708
678
|
end
|
709
|
-
module_function :execute_equality_expression
|
710
679
|
|
711
680
|
def execute_and_expression(node, lhs_object, rhs_object)
|
712
681
|
lhs_variable = object_to_variable(lhs_object)
|
@@ -749,7 +718,6 @@ module C #:nodoc:
|
|
749
718
|
|
750
719
|
result
|
751
720
|
end
|
752
|
-
module_function :execute_and_expression
|
753
721
|
|
754
722
|
def execute_exclusive_or_expression(node, lhs_object, rhs_object)
|
755
723
|
lhs_variable = object_to_variable(lhs_object)
|
@@ -792,7 +760,6 @@ module C #:nodoc:
|
|
792
760
|
|
793
761
|
result
|
794
762
|
end
|
795
|
-
module_function :execute_exclusive_or_expression
|
796
763
|
|
797
764
|
def execute_inclusive_or_expression(node, lhs_object, rhs_object)
|
798
765
|
lhs_variable = object_to_variable(lhs_object)
|
@@ -835,7 +802,6 @@ module C #:nodoc:
|
|
835
802
|
|
836
803
|
result
|
837
804
|
end
|
838
|
-
module_function :execute_inclusive_or_expression
|
839
805
|
|
840
806
|
def execute_simple_assignment_expression(node, lhs_object, rhs_object)
|
841
807
|
return lhs_object unless lhs_object.variable?
|
@@ -870,7 +836,6 @@ module C #:nodoc:
|
|
870
836
|
|
871
837
|
lhs_variable
|
872
838
|
end
|
873
|
-
module_function :execute_simple_assignment_expression
|
874
839
|
|
875
840
|
def execute_compound_assignment_expression(node, lhs_object, rhs_object)
|
876
841
|
unless lhs_object.variable? && lhs_object.type.scalar?
|
@@ -911,7 +876,6 @@ module C #:nodoc:
|
|
911
876
|
|
912
877
|
lhs_variable
|
913
878
|
end
|
914
|
-
module_function :execute_compound_assignment_expression
|
915
879
|
|
916
880
|
def execute_mul_then_assign_expression(node, lhs_variable, rhs_variable)
|
917
881
|
lhs_converted, rhs_converted =
|
@@ -962,7 +926,6 @@ module C #:nodoc:
|
|
962
926
|
|
963
927
|
notify_assignment_expr_evaled(node, lhs_variable, result_converted)
|
964
928
|
end
|
965
|
-
module_function :execute_mul_then_assign_expression
|
966
929
|
|
967
930
|
def execute_div_then_assign_expression(node, lhs_variable, rhs_variable)
|
968
931
|
lhs_converted, rhs_converted =
|
@@ -1014,7 +977,6 @@ module C #:nodoc:
|
|
1014
977
|
|
1015
978
|
notify_assignment_expr_evaled(node, lhs_variable, result_converted)
|
1016
979
|
end
|
1017
|
-
module_function :execute_div_then_assign_expression
|
1018
980
|
|
1019
981
|
def execute_mod_then_assign_expression(node, lhs_variable, rhs_variable)
|
1020
982
|
lhs_converted, rhs_converted =
|
@@ -1066,7 +1028,6 @@ module C #:nodoc:
|
|
1066
1028
|
|
1067
1029
|
notify_assignment_expr_evaled(node, lhs_variable, result_converted)
|
1068
1030
|
end
|
1069
|
-
module_function :execute_mod_then_assign_expression
|
1070
1031
|
|
1071
1032
|
def execute_add_then_assign_expression(node, lhs_variable, rhs_variable)
|
1072
1033
|
lhs_converted, rhs_converted =
|
@@ -1117,7 +1078,6 @@ module C #:nodoc:
|
|
1117
1078
|
|
1118
1079
|
notify_assignment_expr_evaled(node, lhs_variable, result_converted)
|
1119
1080
|
end
|
1120
|
-
module_function :execute_add_then_assign_expression
|
1121
1081
|
|
1122
1082
|
def execute_sub_then_assign_expression(node, lhs_variable, rhs_variable)
|
1123
1083
|
lhs_converted, rhs_converted =
|
@@ -1168,7 +1128,6 @@ module C #:nodoc:
|
|
1168
1128
|
|
1169
1129
|
notify_assignment_expr_evaled(node, lhs_variable, result_converted)
|
1170
1130
|
end
|
1171
|
-
module_function :execute_sub_then_assign_expression
|
1172
1131
|
|
1173
1132
|
def execute_shl_then_assign_expression(node, lhs_variable, rhs_variable)
|
1174
1133
|
# NOTE: The ISO C99 standard saids;
|
@@ -1227,7 +1186,6 @@ module C #:nodoc:
|
|
1227
1186
|
|
1228
1187
|
notify_assignment_expr_evaled(node, lhs_variable, result_converted)
|
1229
1188
|
end
|
1230
|
-
module_function :execute_shl_then_assign_expression
|
1231
1189
|
|
1232
1190
|
def execute_shr_then_assign_expression(node, lhs_variable, rhs_variable)
|
1233
1191
|
# NOTE: The ISO C99 standard saids;
|
@@ -1286,7 +1244,6 @@ module C #:nodoc:
|
|
1286
1244
|
|
1287
1245
|
notify_assignment_expr_evaled(node, lhs_variable, result_converted)
|
1288
1246
|
end
|
1289
|
-
module_function :execute_shr_then_assign_expression
|
1290
1247
|
|
1291
1248
|
def execute_and_then_assign_expression(node, lhs_variable, rhs_variable)
|
1292
1249
|
lhs_converted, rhs_converted =
|
@@ -1336,7 +1293,6 @@ module C #:nodoc:
|
|
1336
1293
|
|
1337
1294
|
notify_assignment_expr_evaled(node, lhs_variable, result_converted)
|
1338
1295
|
end
|
1339
|
-
module_function :execute_and_then_assign_expression
|
1340
1296
|
|
1341
1297
|
def execute_xor_then_assign_expression(node, lhs_variable, rhs_variable)
|
1342
1298
|
lhs_converted, rhs_converted =
|
@@ -1387,7 +1343,6 @@ module C #:nodoc:
|
|
1387
1343
|
|
1388
1344
|
notify_assignment_expr_evaled(node, lhs_variable, result_converted)
|
1389
1345
|
end
|
1390
|
-
module_function :execute_xor_then_assign_expression
|
1391
1346
|
|
1392
1347
|
def execute_ior_then_assign_expression(node, lhs_variable, rhs_variable)
|
1393
1348
|
lhs_converted, rhs_converted =
|
@@ -1438,7 +1393,6 @@ module C #:nodoc:
|
|
1438
1393
|
|
1439
1394
|
notify_assignment_expr_evaled(node, lhs_variable, result_converted)
|
1440
1395
|
end
|
1441
|
-
module_function :execute_ior_then_assign_expression
|
1442
1396
|
|
1443
1397
|
def _notify_object_referred(node, object)
|
1444
1398
|
case object
|
@@ -1448,7 +1402,6 @@ module C #:nodoc:
|
|
1448
1402
|
interpreter.notify_function_referred(node, object)
|
1449
1403
|
end
|
1450
1404
|
end
|
1451
|
-
module_function :_notify_object_referred
|
1452
1405
|
|
1453
1406
|
def _notify_variable_value_referred(node, object)
|
1454
1407
|
if object.variable?
|
@@ -1459,7 +1412,6 @@ module C #:nodoc:
|
|
1459
1412
|
# is referred, notification of the outer variable's value has
|
1460
1413
|
# already been done in sub expressions.
|
1461
1414
|
end
|
1462
|
-
module_function :_notify_variable_value_referred
|
1463
1415
|
|
1464
1416
|
def _notify_variable_value_updated(node, object)
|
1465
1417
|
if object.variable?
|
@@ -1473,19 +1425,16 @@ module C #:nodoc:
|
|
1473
1425
|
_notify_variable_value_updated(node, object.owner)
|
1474
1426
|
end
|
1475
1427
|
end
|
1476
|
-
module_function :_notify_variable_value_updated
|
1477
1428
|
|
1478
1429
|
def _char_array_value(string_literal)
|
1479
1430
|
chars = string_literal.chars.map { |ch| ScalarValue.of(ch.ord) }
|
1480
1431
|
ArrayValue.new(chars + [ScalarValue.of("\0".ord)])
|
1481
1432
|
end
|
1482
|
-
module_function :_char_array_value
|
1483
1433
|
|
1484
1434
|
def _wchar_array_value(string_literal)
|
1485
1435
|
chars = string_literal.chars.map { |ch| ScalarValue.of(ch.ord) }
|
1486
1436
|
ArrayValue.new(chars + [ScalarValue.of("\0".ord)])
|
1487
1437
|
end
|
1488
|
-
module_function :_wchar_array_value
|
1489
1438
|
end
|
1490
1439
|
|
1491
1440
|
module ExpressionEvaluator
|
@@ -1525,17 +1474,14 @@ module C #:nodoc:
|
|
1525
1474
|
|
1526
1475
|
case node.literal.value
|
1527
1476
|
when /\A"(.*)"\z/
|
1528
|
-
|
1529
|
-
|
1477
|
+
temporary_variable(array_type(char_type, $1.length + 1),
|
1478
|
+
_char_array_value($1))
|
1530
1479
|
when /\AL"(.*)"\z/i
|
1531
|
-
|
1532
|
-
|
1480
|
+
temporary_variable(array_type(wchar_type, $1.length + 1),
|
1481
|
+
_wchar_array_value($1))
|
1533
1482
|
else
|
1534
|
-
|
1483
|
+
temporary_variable(array_type(char_type))
|
1535
1484
|
end
|
1536
|
-
|
1537
|
-
temporary_variable(pointer_type(array.type.base_type),
|
1538
|
-
pointer_value_of(array))
|
1539
1485
|
end
|
1540
1486
|
|
1541
1487
|
def visit_null_constant_specifier(node)
|
@@ -1851,28 +1797,23 @@ module C #:nodoc:
|
|
1851
1797
|
def visit_conditional_expression(node)
|
1852
1798
|
checkpoint(node.location)
|
1853
1799
|
|
1854
|
-
|
1800
|
+
condition_variable = object_to_variable(node.condition.accept(self))
|
1855
1801
|
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
result_value =
|
1867
|
-
then_object.value.single_value_unified_with(else_object.value)
|
1868
|
-
result_object = temporary_variable(then_object.type, result_value)
|
1869
|
-
end
|
1870
|
-
end
|
1802
|
+
case
|
1803
|
+
when condition_variable.value.must_be_true?
|
1804
|
+
result_variable = object_to_variable(node.then_expression.accept(self))
|
1805
|
+
when condition_variable.value.must_be_false?
|
1806
|
+
result_variable = object_to_variable(node.else_expression.accept(self))
|
1807
|
+
else
|
1808
|
+
then_var = object_to_variable(node.then_expression.accept(self))
|
1809
|
+
else_var = object_to_variable(node.else_expression.accept(self))
|
1810
|
+
result_value = then_var.value.single_value_unified_with(else_var.value)
|
1811
|
+
result_variable = temporary_variable(then_var.type, result_value)
|
1871
1812
|
end
|
1872
1813
|
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1814
|
+
notify_conditional_expr_evaled(node, condition_variable, result_variable)
|
1815
|
+
|
1816
|
+
result_variable
|
1876
1817
|
end
|
1877
1818
|
|
1878
1819
|
def visit_simple_assignment_expression(node)
|