adlint 2.6.12 → 2.6.14
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 +77 -0
- data/NEWS +17 -4
- data/bin/adlint +24 -30
- data/bin/adlint_chk +22 -28
- data/bin/adlint_cma +20 -26
- data/bin/adlint_sma +22 -28
- data/bin/adlintize +60 -58
- data/etc/mesg.d/c_builtin/en_US/messages.yml +168 -168
- data/etc/mesg.d/c_builtin/ja_JP/messages.yml +168 -168
- data/etc/mesg.d/core/en_US/messages.yml +1 -1
- data/etc/mesg.d/core/ja_JP/messages.yml +1 -1
- data/features/code_check/W0119.feature +0 -5
- data/features/code_check/W0120.feature +1 -0
- data/features/code_check/W0121.feature +0 -5
- data/features/code_check/W0123.feature +0 -5
- data/features/code_check/W0125.feature +0 -5
- data/features/code_check/W0127.feature +0 -5
- data/features/code_check/W0128.feature +0 -5
- data/features/code_check/W0129.feature +0 -5
- data/features/code_check/W0130.feature +0 -5
- data/features/code_check/W0132.feature +1 -0
- data/features/code_check/W0133.feature +0 -5
- data/features/code_check/W0134.feature +0 -5
- data/features/code_check/W0135.feature +0 -5
- data/features/code_check/W0136.feature +0 -5
- data/features/code_check/W0137.feature +0 -5
- data/features/code_check/W0138.feature +0 -5
- data/features/code_check/W0139.feature +0 -5
- data/features/code_check/W0140.feature +0 -5
- data/features/code_check/W0141.feature +0 -5
- data/features/code_check/W0142.feature +0 -5
- data/features/code_check/W0157.feature +0 -5
- data/features/code_check/W0161.feature +0 -5
- data/features/code_check/W0165.feature +0 -5
- data/features/code_check/W0169.feature +0 -5
- data/features/code_check/W0177.feature +0 -5
- data/features/code_check/W0182.feature +0 -5
- data/features/code_check/W0183.feature +0 -5
- data/features/code_check/W0184.feature +0 -5
- data/features/code_check/W0212.feature +0 -5
- data/features/code_check/W0214.feature +0 -5
- data/features/code_check/W0221.feature +0 -5
- data/features/code_check/W0223.feature +0 -5
- data/features/code_check/W0230.feature +0 -5
- data/features/code_check/W0232.feature +0 -5
- data/features/code_check/W0245.feature +0 -5
- data/features/code_check/W0246.feature +0 -5
- data/features/code_check/W0247.feature +0 -5
- data/features/code_check/W0251.feature +0 -5
- data/features/code_check/W0650.feature +0 -4
- data/features/code_check/W0703.feature +5 -1
- data/features/code_check/W0719.feature +0 -10
- data/features/code_check/W0748.feature +0 -5
- data/features/code_check/W0751.feature +0 -5
- data/features/code_check/W0756.feature +0 -5
- data/features/code_check/W0763.feature +0 -5
- data/features/code_check/W0787.feature +7 -0
- data/features/code_check/W0794.feature +0 -1
- data/features/code_check/W1052.feature +0 -2
- data/features/support/env.rb +2 -7
- data/lib/adlint/c/syntax.rb +10 -16
- data/lib/adlint/cpp/macro.rb +96 -0
- data/lib/adlint/exam/c_builtin/c_check.rb +954 -817
- data/lib/adlint/exam/c_builtin/c_check_shima.rb +17 -19
- data/lib/adlint/exam/c_builtin/ld_check.rb +86 -44
- data/lib/adlint/message.rb +1 -1
- data/lib/adlint/util.rb +8 -8
- data/lib/adlint/version.rb +2 -2
- data/lib/adlint.rb +8 -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 +5055 -5053
- data/share/doc/users_guide_en.texi +3817 -3818
- data/share/doc/users_guide_ja.html +3787 -3786
- data/share/doc/users_guide_ja.texi +3784 -3783
- data/spec/spec_helper.rb +3 -11
- metadata +2 -2
@@ -1350,33 +1350,33 @@ module CBuiltin #:nodoc:
|
|
1350
1350
|
interp.on_function_declared += method(:add_function)
|
1351
1351
|
interp.on_function_defined += method(:add_function)
|
1352
1352
|
interp.on_translation_unit_ended += method(:check)
|
1353
|
-
@
|
1353
|
+
@obj_dcls = Hash.new { |hash, key| hash[key] = [] }
|
1354
1354
|
end
|
1355
1355
|
|
1356
1356
|
private
|
1357
|
-
def add_variable(
|
1358
|
-
if
|
1359
|
-
@
|
1360
|
-
[decl_or_def.identifier, variable.declared_as_extern?])
|
1357
|
+
def add_variable(dcl_or_def, var)
|
1358
|
+
if var.named? && var.declared_as_extern?
|
1359
|
+
@obj_dcls[mangle(var.name)].push(dcl_or_def)
|
1361
1360
|
end
|
1362
1361
|
end
|
1363
1362
|
|
1364
|
-
def add_function(
|
1365
|
-
if
|
1366
|
-
@
|
1367
|
-
[decl_or_def.identifier, function.declared_as_extern?])
|
1363
|
+
def add_function(dcl_or_def, func)
|
1364
|
+
if func.named? && func.declared_as_extern?
|
1365
|
+
@obj_dcls[mangle(func.name)].push(dcl_or_def)
|
1368
1366
|
end
|
1369
1367
|
end
|
1370
1368
|
|
1371
1369
|
def check(*)
|
1372
|
-
@
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1370
|
+
@obj_dcls.each_value do |dcls|
|
1371
|
+
similar_dcls = dcls.uniq { |dcl| dcl.identifier.value }
|
1372
|
+
next unless similar_dcls.size > 1
|
1373
|
+
|
1374
|
+
similar_dcls.each do |dcl|
|
1375
|
+
W(:W0051, dcl.location, dcl.identifier.value)
|
1376
|
+
similar_dcls.each do |pair_dcl|
|
1377
|
+
if pair_dcl != dcl
|
1378
|
+
C(:C0001, pair_dcl.location, pair_dcl.identifier.value)
|
1379
|
+
end
|
1380
1380
|
end
|
1381
1381
|
end
|
1382
1382
|
end
|
@@ -1402,44 +1402,42 @@ module CBuiltin #:nodoc:
|
|
1402
1402
|
|
1403
1403
|
def initialize(context)
|
1404
1404
|
super
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
@
|
1405
|
+
interp = context[:c_interpreter]
|
1406
|
+
interp.on_variable_declared += method(:declare_object)
|
1407
|
+
interp.on_variable_defined += method(:declare_object)
|
1408
|
+
interp.on_function_declared += method(:declare_object)
|
1409
|
+
interp.on_function_defined += method(:declare_object)
|
1410
|
+
interp.on_block_started += method(:enter_scope)
|
1411
|
+
interp.on_block_ended += method(:leave_scope)
|
1412
|
+
@dcl_names = [Hash.new { |hash, key| hash[key] = [] }]
|
1413
1413
|
end
|
1414
1414
|
|
1415
1415
|
private
|
1416
|
-
def
|
1417
|
-
|
1418
|
-
end
|
1416
|
+
def declare_object(dcl_or_def, *)
|
1417
|
+
dcl_name = dcl_or_def.identifier
|
1419
1418
|
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1419
|
+
pair_names = @dcl_names.map { |name_hash|
|
1420
|
+
name_hash[mangle(dcl_name.value)]
|
1421
|
+
}.reduce([]) { |all_names, similar_names|
|
1422
|
+
all_names + similar_names
|
1423
|
+
}.uniq { |id| id.value }.reject { |id| id.value == dcl_name.value }
|
1424
|
+
|
1425
|
+
unless pair_names.empty?
|
1426
|
+
W(:W0052, dcl_or_def.location, dcl_name.value)
|
1427
|
+
pair_names.each do |pair_name|
|
1428
|
+
C(:C0001, pair_name.location, pair_name.value)
|
1429
|
+
end
|
1430
|
+
end
|
1423
1431
|
|
1424
|
-
|
1425
|
-
@identifiers[mangle(node.identifier.value)].push(node.identifier)
|
1432
|
+
@dcl_names.last[mangle(dcl_name.value)].push(dcl_name)
|
1426
1433
|
end
|
1427
1434
|
|
1428
|
-
def
|
1429
|
-
@
|
1435
|
+
def enter_scope(*)
|
1436
|
+
@dcl_names.push(Hash.new { |hash, key| hash[key] = [] })
|
1430
1437
|
end
|
1431
1438
|
|
1432
|
-
def
|
1433
|
-
@
|
1434
|
-
id_array.uniq! { |id| id.value }
|
1435
|
-
if id_array.size > 1
|
1436
|
-
id_array.each_with_index do |id, index|
|
1437
|
-
pair = index == 0 ? id_array[1] : id_array[0]
|
1438
|
-
C(:C0001, pair.location, pair.value)
|
1439
|
-
W(:W0052, id.location, pair.value)
|
1440
|
-
end
|
1441
|
-
end
|
1442
|
-
end
|
1439
|
+
def leave_scope(*)
|
1440
|
+
@dcl_names.pop
|
1443
1441
|
end
|
1444
1442
|
|
1445
1443
|
def mangle(name)
|
@@ -3061,12 +3059,9 @@ module CBuiltin #:nodoc:
|
|
3061
3059
|
end
|
3062
3060
|
|
3063
3061
|
private
|
3064
|
-
def check(
|
3065
|
-
|
3066
|
-
|
3067
|
-
if original_variable.type.same_as?(from_type) &&
|
3068
|
-
result_variable.type.same_as?(to_type)
|
3069
|
-
W(message_id, initializer_or_expression.location)
|
3062
|
+
def check(init_or_expr, from_var, to_var)
|
3063
|
+
if match?(from_var, to_var)
|
3064
|
+
W(message_id, init_or_expr.location)
|
3070
3065
|
end
|
3071
3066
|
end
|
3072
3067
|
|
@@ -3078,6 +3073,28 @@ module CBuiltin #:nodoc:
|
|
3078
3073
|
@interp.signed_char_type
|
3079
3074
|
end
|
3080
3075
|
|
3076
|
+
def match?(from_var, to_var)
|
3077
|
+
unless from_var.type.same_as?(from_type) && to_var.type.same_as?(to_type)
|
3078
|
+
return false
|
3079
|
+
end
|
3080
|
+
|
3081
|
+
if char_type_family?(from_type) &&
|
3082
|
+
from_var.type.explicitly_signed? != from_type.explicitly_signed?
|
3083
|
+
return false
|
3084
|
+
end
|
3085
|
+
if char_type_family?(to_type) &&
|
3086
|
+
to_var.type.explicitly_signed? != to_type.explicitly_signed?
|
3087
|
+
return false
|
3088
|
+
end
|
3089
|
+
|
3090
|
+
true
|
3091
|
+
end
|
3092
|
+
|
3093
|
+
def char_type_family?(type)
|
3094
|
+
type == @interp.char_type ||
|
3095
|
+
type == @interp.signed_char_type || type == @interp.unsigned_char_type
|
3096
|
+
end
|
3097
|
+
|
3081
3098
|
def message_id
|
3082
3099
|
self.class.name.sub(/\A.*::/, "").intern
|
3083
3100
|
end
|
@@ -3113,7 +3130,7 @@ module CBuiltin #:nodoc:
|
|
3113
3130
|
end
|
3114
3131
|
|
3115
3132
|
def to_type
|
3116
|
-
@interp.
|
3133
|
+
@interp.signed_short_type
|
3117
3134
|
end
|
3118
3135
|
end
|
3119
3136
|
|
@@ -3147,7 +3164,7 @@ module CBuiltin #:nodoc:
|
|
3147
3164
|
end
|
3148
3165
|
|
3149
3166
|
def to_type
|
3150
|
-
@interp.
|
3167
|
+
@interp.signed_int_type
|
3151
3168
|
end
|
3152
3169
|
end
|
3153
3170
|
|
@@ -3181,7 +3198,7 @@ module CBuiltin #:nodoc:
|
|
3181
3198
|
end
|
3182
3199
|
|
3183
3200
|
def to_type
|
3184
|
-
@interp.
|
3201
|
+
@interp.signed_long_type
|
3185
3202
|
end
|
3186
3203
|
end
|
3187
3204
|
|
@@ -3266,7 +3283,7 @@ module CBuiltin #:nodoc:
|
|
3266
3283
|
end
|
3267
3284
|
|
3268
3285
|
def to_type
|
3269
|
-
@interp.
|
3286
|
+
@interp.signed_long_long_type
|
3270
3287
|
end
|
3271
3288
|
end
|
3272
3289
|
|
@@ -3330,7 +3347,7 @@ module CBuiltin #:nodoc:
|
|
3330
3347
|
|
3331
3348
|
private
|
3332
3349
|
def from_type
|
3333
|
-
@interp.
|
3350
|
+
@interp.signed_short_type
|
3334
3351
|
end
|
3335
3352
|
|
3336
3353
|
def to_type
|
@@ -3364,7 +3381,7 @@ module CBuiltin #:nodoc:
|
|
3364
3381
|
|
3365
3382
|
private
|
3366
3383
|
def from_type
|
3367
|
-
@interp.
|
3384
|
+
@interp.signed_int_type
|
3368
3385
|
end
|
3369
3386
|
|
3370
3387
|
def to_type
|
@@ -3398,7 +3415,7 @@ module CBuiltin #:nodoc:
|
|
3398
3415
|
|
3399
3416
|
private
|
3400
3417
|
def from_type
|
3401
|
-
@interp.
|
3418
|
+
@interp.signed_long_type
|
3402
3419
|
end
|
3403
3420
|
|
3404
3421
|
def to_type
|
@@ -3432,7 +3449,7 @@ module CBuiltin #:nodoc:
|
|
3432
3449
|
|
3433
3450
|
private
|
3434
3451
|
def from_type
|
3435
|
-
@interp.
|
3452
|
+
@interp.signed_long_long_type
|
3436
3453
|
end
|
3437
3454
|
|
3438
3455
|
def to_type
|
@@ -3504,7 +3521,7 @@ module CBuiltin #:nodoc:
|
|
3504
3521
|
end
|
3505
3522
|
|
3506
3523
|
def to_type
|
3507
|
-
@interp.
|
3524
|
+
@interp.signed_short_type
|
3508
3525
|
end
|
3509
3526
|
end
|
3510
3527
|
|
@@ -3538,7 +3555,7 @@ module CBuiltin #:nodoc:
|
|
3538
3555
|
end
|
3539
3556
|
|
3540
3557
|
def to_type
|
3541
|
-
@interp.
|
3558
|
+
@interp.signed_short_type
|
3542
3559
|
end
|
3543
3560
|
end
|
3544
3561
|
|
@@ -3555,7 +3572,7 @@ module CBuiltin #:nodoc:
|
|
3555
3572
|
end
|
3556
3573
|
|
3557
3574
|
def to_type
|
3558
|
-
@interp.
|
3575
|
+
@interp.signed_int_type
|
3559
3576
|
end
|
3560
3577
|
end
|
3561
3578
|
|
@@ -3589,7 +3606,7 @@ module CBuiltin #:nodoc:
|
|
3589
3606
|
end
|
3590
3607
|
|
3591
3608
|
def to_type
|
3592
|
-
@interp.
|
3609
|
+
@interp.signed_short_type
|
3593
3610
|
end
|
3594
3611
|
end
|
3595
3612
|
|
@@ -3606,7 +3623,7 @@ module CBuiltin #:nodoc:
|
|
3606
3623
|
end
|
3607
3624
|
|
3608
3625
|
def to_type
|
3609
|
-
@interp.
|
3626
|
+
@interp.signed_int_type
|
3610
3627
|
end
|
3611
3628
|
end
|
3612
3629
|
|
@@ -3623,7 +3640,7 @@ module CBuiltin #:nodoc:
|
|
3623
3640
|
end
|
3624
3641
|
|
3625
3642
|
def to_type
|
3626
|
-
@interp.
|
3643
|
+
@interp.signed_long_type
|
3627
3644
|
end
|
3628
3645
|
end
|
3629
3646
|
|
@@ -3657,7 +3674,7 @@ module CBuiltin #:nodoc:
|
|
3657
3674
|
end
|
3658
3675
|
|
3659
3676
|
def to_type
|
3660
|
-
@interp.
|
3677
|
+
@interp.signed_short_type
|
3661
3678
|
end
|
3662
3679
|
end
|
3663
3680
|
|
@@ -3674,7 +3691,7 @@ module CBuiltin #:nodoc:
|
|
3674
3691
|
end
|
3675
3692
|
|
3676
3693
|
def to_type
|
3677
|
-
@interp.
|
3694
|
+
@interp.signed_int_type
|
3678
3695
|
end
|
3679
3696
|
end
|
3680
3697
|
|
@@ -3691,7 +3708,7 @@ module CBuiltin #:nodoc:
|
|
3691
3708
|
end
|
3692
3709
|
|
3693
3710
|
def to_type
|
3694
|
-
@interp.
|
3711
|
+
@interp.signed_long_type
|
3695
3712
|
end
|
3696
3713
|
end
|
3697
3714
|
|
@@ -3708,7 +3725,7 @@ module CBuiltin #:nodoc:
|
|
3708
3725
|
end
|
3709
3726
|
|
3710
3727
|
def to_type
|
3711
|
-
@interp.
|
3728
|
+
@interp.signed_long_long_type
|
3712
3729
|
end
|
3713
3730
|
end
|
3714
3731
|
|
@@ -3789,7 +3806,7 @@ module CBuiltin #:nodoc:
|
|
3789
3806
|
|
3790
3807
|
private
|
3791
3808
|
def from_type
|
3792
|
-
@interp.
|
3809
|
+
@interp.signed_short_type
|
3793
3810
|
end
|
3794
3811
|
|
3795
3812
|
def to_type
|
@@ -3806,7 +3823,7 @@ module CBuiltin #:nodoc:
|
|
3806
3823
|
|
3807
3824
|
private
|
3808
3825
|
def from_type
|
3809
|
-
@interp.
|
3826
|
+
@interp.signed_short_type
|
3810
3827
|
end
|
3811
3828
|
|
3812
3829
|
def to_type
|
@@ -3823,7 +3840,7 @@ module CBuiltin #:nodoc:
|
|
3823
3840
|
|
3824
3841
|
private
|
3825
3842
|
def from_type
|
3826
|
-
@interp.
|
3843
|
+
@interp.signed_short_type
|
3827
3844
|
end
|
3828
3845
|
|
3829
3846
|
def to_type
|
@@ -3840,7 +3857,7 @@ module CBuiltin #:nodoc:
|
|
3840
3857
|
|
3841
3858
|
private
|
3842
3859
|
def from_type
|
3843
|
-
@interp.
|
3860
|
+
@interp.signed_short_type
|
3844
3861
|
end
|
3845
3862
|
|
3846
3863
|
def to_type
|
@@ -3857,7 +3874,7 @@ module CBuiltin #:nodoc:
|
|
3857
3874
|
|
3858
3875
|
private
|
3859
3876
|
def from_type
|
3860
|
-
@interp.
|
3877
|
+
@interp.signed_int_type
|
3861
3878
|
end
|
3862
3879
|
|
3863
3880
|
def to_type
|
@@ -3874,7 +3891,7 @@ module CBuiltin #:nodoc:
|
|
3874
3891
|
|
3875
3892
|
private
|
3876
3893
|
def from_type
|
3877
|
-
@interp.
|
3894
|
+
@interp.signed_int_type
|
3878
3895
|
end
|
3879
3896
|
|
3880
3897
|
def to_type
|
@@ -3891,7 +3908,7 @@ module CBuiltin #:nodoc:
|
|
3891
3908
|
|
3892
3909
|
private
|
3893
3910
|
def from_type
|
3894
|
-
@interp.
|
3911
|
+
@interp.signed_int_type
|
3895
3912
|
end
|
3896
3913
|
|
3897
3914
|
def to_type
|
@@ -3908,7 +3925,7 @@ module CBuiltin #:nodoc:
|
|
3908
3925
|
|
3909
3926
|
private
|
3910
3927
|
def from_type
|
3911
|
-
@interp.
|
3928
|
+
@interp.signed_int_type
|
3912
3929
|
end
|
3913
3930
|
|
3914
3931
|
def to_type
|
@@ -3925,7 +3942,7 @@ module CBuiltin #:nodoc:
|
|
3925
3942
|
|
3926
3943
|
private
|
3927
3944
|
def from_type
|
3928
|
-
@interp.
|
3945
|
+
@interp.signed_long_type
|
3929
3946
|
end
|
3930
3947
|
|
3931
3948
|
def to_type
|
@@ -3942,7 +3959,7 @@ module CBuiltin #:nodoc:
|
|
3942
3959
|
|
3943
3960
|
private
|
3944
3961
|
def from_type
|
3945
|
-
@interp.
|
3962
|
+
@interp.signed_long_type
|
3946
3963
|
end
|
3947
3964
|
|
3948
3965
|
def to_type
|
@@ -3959,7 +3976,7 @@ module CBuiltin #:nodoc:
|
|
3959
3976
|
|
3960
3977
|
private
|
3961
3978
|
def from_type
|
3962
|
-
@interp.
|
3979
|
+
@interp.signed_long_type
|
3963
3980
|
end
|
3964
3981
|
|
3965
3982
|
def to_type
|
@@ -3976,7 +3993,7 @@ module CBuiltin #:nodoc:
|
|
3976
3993
|
|
3977
3994
|
private
|
3978
3995
|
def from_type
|
3979
|
-
@interp.
|
3996
|
+
@interp.signed_long_type
|
3980
3997
|
end
|
3981
3998
|
|
3982
3999
|
def to_type
|
@@ -4010,7 +4027,7 @@ module CBuiltin #:nodoc:
|
|
4010
4027
|
|
4011
4028
|
private
|
4012
4029
|
def from_type
|
4013
|
-
@interp.
|
4030
|
+
@interp.signed_short_type
|
4014
4031
|
end
|
4015
4032
|
|
4016
4033
|
def to_type
|
@@ -4027,7 +4044,7 @@ module CBuiltin #:nodoc:
|
|
4027
4044
|
|
4028
4045
|
private
|
4029
4046
|
def from_type
|
4030
|
-
@interp.
|
4047
|
+
@interp.signed_int_type
|
4031
4048
|
end
|
4032
4049
|
|
4033
4050
|
def to_type
|
@@ -4044,7 +4061,7 @@ module CBuiltin #:nodoc:
|
|
4044
4061
|
|
4045
4062
|
private
|
4046
4063
|
def from_type
|
4047
|
-
@interp.
|
4064
|
+
@interp.signed_long_type
|
4048
4065
|
end
|
4049
4066
|
|
4050
4067
|
def to_type
|
@@ -4061,7 +4078,7 @@ module CBuiltin #:nodoc:
|
|
4061
4078
|
|
4062
4079
|
private
|
4063
4080
|
def from_type
|
4064
|
-
@interp.
|
4081
|
+
@interp.signed_long_long_type
|
4065
4082
|
end
|
4066
4083
|
|
4067
4084
|
def to_type
|
@@ -4078,7 +4095,7 @@ module CBuiltin #:nodoc:
|
|
4078
4095
|
|
4079
4096
|
private
|
4080
4097
|
def from_type
|
4081
|
-
@interp.
|
4098
|
+
@interp.signed_long_long_type
|
4082
4099
|
end
|
4083
4100
|
|
4084
4101
|
def to_type
|
@@ -4095,7 +4112,7 @@ module CBuiltin #:nodoc:
|
|
4095
4112
|
|
4096
4113
|
private
|
4097
4114
|
def from_type
|
4098
|
-
@interp.
|
4115
|
+
@interp.signed_long_long_type
|
4099
4116
|
end
|
4100
4117
|
|
4101
4118
|
def to_type
|
@@ -4112,7 +4129,7 @@ module CBuiltin #:nodoc:
|
|
4112
4129
|
|
4113
4130
|
private
|
4114
4131
|
def from_type
|
4115
|
-
@interp.
|
4132
|
+
@interp.signed_long_long_type
|
4116
4133
|
end
|
4117
4134
|
|
4118
4135
|
def to_type
|
@@ -4129,7 +4146,7 @@ module CBuiltin #:nodoc:
|
|
4129
4146
|
|
4130
4147
|
private
|
4131
4148
|
def from_type
|
4132
|
-
@interp.
|
4149
|
+
@interp.signed_long_long_type
|
4133
4150
|
end
|
4134
4151
|
|
4135
4152
|
def to_type
|
@@ -4248,7 +4265,7 @@ module CBuiltin #:nodoc:
|
|
4248
4265
|
|
4249
4266
|
private
|
4250
4267
|
def from_type
|
4251
|
-
@interp.
|
4268
|
+
@interp.signed_short_type
|
4252
4269
|
end
|
4253
4270
|
|
4254
4271
|
def to_type
|
@@ -4265,7 +4282,7 @@ module CBuiltin #:nodoc:
|
|
4265
4282
|
|
4266
4283
|
private
|
4267
4284
|
def from_type
|
4268
|
-
@interp.
|
4285
|
+
@interp.signed_short_type
|
4269
4286
|
end
|
4270
4287
|
|
4271
4288
|
def to_type
|
@@ -4282,7 +4299,7 @@ module CBuiltin #:nodoc:
|
|
4282
4299
|
|
4283
4300
|
private
|
4284
4301
|
def from_type
|
4285
|
-
@interp.
|
4302
|
+
@interp.signed_short_type
|
4286
4303
|
end
|
4287
4304
|
|
4288
4305
|
def to_type
|
@@ -4350,7 +4367,7 @@ module CBuiltin #:nodoc:
|
|
4350
4367
|
|
4351
4368
|
private
|
4352
4369
|
def from_type
|
4353
|
-
@interp.
|
4370
|
+
@interp.signed_int_type
|
4354
4371
|
end
|
4355
4372
|
|
4356
4373
|
def to_type
|
@@ -4367,7 +4384,7 @@ module CBuiltin #:nodoc:
|
|
4367
4384
|
|
4368
4385
|
private
|
4369
4386
|
def from_type
|
4370
|
-
@interp.
|
4387
|
+
@interp.signed_int_type
|
4371
4388
|
end
|
4372
4389
|
|
4373
4390
|
def to_type
|
@@ -4384,7 +4401,7 @@ module CBuiltin #:nodoc:
|
|
4384
4401
|
|
4385
4402
|
private
|
4386
4403
|
def from_type
|
4387
|
-
@interp.
|
4404
|
+
@interp.signed_int_type
|
4388
4405
|
end
|
4389
4406
|
|
4390
4407
|
def to_type
|
@@ -4452,7 +4469,7 @@ module CBuiltin #:nodoc:
|
|
4452
4469
|
|
4453
4470
|
private
|
4454
4471
|
def from_type
|
4455
|
-
@interp.
|
4472
|
+
@interp.signed_long_type
|
4456
4473
|
end
|
4457
4474
|
|
4458
4475
|
def to_type
|
@@ -4469,7 +4486,7 @@ module CBuiltin #:nodoc:
|
|
4469
4486
|
|
4470
4487
|
private
|
4471
4488
|
def from_type
|
4472
|
-
@interp.
|
4489
|
+
@interp.signed_long_type
|
4473
4490
|
end
|
4474
4491
|
|
4475
4492
|
def to_type
|
@@ -4486,7 +4503,7 @@ module CBuiltin #:nodoc:
|
|
4486
4503
|
|
4487
4504
|
private
|
4488
4505
|
def from_type
|
4489
|
-
@interp.
|
4506
|
+
@interp.signed_long_type
|
4490
4507
|
end
|
4491
4508
|
|
4492
4509
|
def to_type
|
@@ -4554,7 +4571,7 @@ module CBuiltin #:nodoc:
|
|
4554
4571
|
|
4555
4572
|
private
|
4556
4573
|
def from_type
|
4557
|
-
@interp.
|
4574
|
+
@interp.signed_long_long_type
|
4558
4575
|
end
|
4559
4576
|
|
4560
4577
|
def to_type
|
@@ -4571,7 +4588,7 @@ module CBuiltin #:nodoc:
|
|
4571
4588
|
|
4572
4589
|
private
|
4573
4590
|
def from_type
|
4574
|
-
@interp.
|
4591
|
+
@interp.signed_long_long_type
|
4575
4592
|
end
|
4576
4593
|
|
4577
4594
|
def to_type
|
@@ -4588,7 +4605,7 @@ module CBuiltin #:nodoc:
|
|
4588
4605
|
|
4589
4606
|
private
|
4590
4607
|
def from_type
|
4591
|
-
@interp.
|
4608
|
+
@interp.signed_long_long_type
|
4592
4609
|
end
|
4593
4610
|
|
4594
4611
|
def to_type
|
@@ -4711,7 +4728,7 @@ module CBuiltin #:nodoc:
|
|
4711
4728
|
end
|
4712
4729
|
|
4713
4730
|
def to_type
|
4714
|
-
@interp.
|
4731
|
+
@interp.signed_short_type
|
4715
4732
|
end
|
4716
4733
|
end
|
4717
4734
|
|
@@ -4745,7 +4762,7 @@ module CBuiltin #:nodoc:
|
|
4745
4762
|
end
|
4746
4763
|
|
4747
4764
|
def to_type
|
4748
|
-
@interp.
|
4765
|
+
@interp.signed_int_type
|
4749
4766
|
end
|
4750
4767
|
end
|
4751
4768
|
|
@@ -4779,7 +4796,7 @@ module CBuiltin #:nodoc:
|
|
4779
4796
|
end
|
4780
4797
|
|
4781
4798
|
def to_type
|
4782
|
-
@interp.
|
4799
|
+
@interp.signed_long_type
|
4783
4800
|
end
|
4784
4801
|
end
|
4785
4802
|
|
@@ -4864,7 +4881,7 @@ module CBuiltin #:nodoc:
|
|
4864
4881
|
end
|
4865
4882
|
|
4866
4883
|
def to_type
|
4867
|
-
@interp.
|
4884
|
+
@interp.signed_short_type
|
4868
4885
|
end
|
4869
4886
|
end
|
4870
4887
|
|
@@ -4898,7 +4915,7 @@ module CBuiltin #:nodoc:
|
|
4898
4915
|
end
|
4899
4916
|
|
4900
4917
|
def to_type
|
4901
|
-
@interp.
|
4918
|
+
@interp.signed_int_type
|
4902
4919
|
end
|
4903
4920
|
end
|
4904
4921
|
|
@@ -4932,7 +4949,7 @@ module CBuiltin #:nodoc:
|
|
4932
4949
|
end
|
4933
4950
|
|
4934
4951
|
def to_type
|
4935
|
-
@interp.
|
4952
|
+
@interp.signed_long_type
|
4936
4953
|
end
|
4937
4954
|
end
|
4938
4955
|
|
@@ -5017,7 +5034,7 @@ module CBuiltin #:nodoc:
|
|
5017
5034
|
end
|
5018
5035
|
|
5019
5036
|
def to_type
|
5020
|
-
@interp.
|
5037
|
+
@interp.signed_short_type
|
5021
5038
|
end
|
5022
5039
|
end
|
5023
5040
|
|
@@ -5051,7 +5068,7 @@ module CBuiltin #:nodoc:
|
|
5051
5068
|
end
|
5052
5069
|
|
5053
5070
|
def to_type
|
5054
|
-
@interp.
|
5071
|
+
@interp.signed_int_type
|
5055
5072
|
end
|
5056
5073
|
end
|
5057
5074
|
|
@@ -5085,7 +5102,7 @@ module CBuiltin #:nodoc:
|
|
5085
5102
|
end
|
5086
5103
|
|
5087
5104
|
def to_type
|
5088
|
-
@interp.
|
5105
|
+
@interp.signed_long_type
|
5089
5106
|
end
|
5090
5107
|
end
|
5091
5108
|
|
@@ -5119,7 +5136,7 @@ module CBuiltin #:nodoc:
|
|
5119
5136
|
end
|
5120
5137
|
|
5121
5138
|
def to_type
|
5122
|
-
@interp.
|
5139
|
+
@interp.signed_long_long_type
|
5123
5140
|
end
|
5124
5141
|
end
|
5125
5142
|
|
@@ -5153,7 +5170,7 @@ module CBuiltin #:nodoc:
|
|
5153
5170
|
end
|
5154
5171
|
|
5155
5172
|
def to_type
|
5156
|
-
@interp.
|
5173
|
+
@interp.signed_long_long_type
|
5157
5174
|
end
|
5158
5175
|
end
|
5159
5176
|
|
@@ -5187,7 +5204,7 @@ module CBuiltin #:nodoc:
|
|
5187
5204
|
end
|
5188
5205
|
|
5189
5206
|
def to_type
|
5190
|
-
@interp.
|
5207
|
+
@interp.signed_long_long_type
|
5191
5208
|
end
|
5192
5209
|
end
|
5193
5210
|
|
@@ -5221,7 +5238,7 @@ module CBuiltin #:nodoc:
|
|
5221
5238
|
end
|
5222
5239
|
|
5223
5240
|
def to_type
|
5224
|
-
@interp.
|
5241
|
+
@interp.signed_short_type
|
5225
5242
|
end
|
5226
5243
|
end
|
5227
5244
|
|
@@ -5238,7 +5255,7 @@ module CBuiltin #:nodoc:
|
|
5238
5255
|
end
|
5239
5256
|
|
5240
5257
|
def to_type
|
5241
|
-
@interp.
|
5258
|
+
@interp.signed_int_type
|
5242
5259
|
end
|
5243
5260
|
end
|
5244
5261
|
|
@@ -5255,7 +5272,7 @@ module CBuiltin #:nodoc:
|
|
5255
5272
|
end
|
5256
5273
|
|
5257
5274
|
def to_type
|
5258
|
-
@interp.
|
5275
|
+
@interp.signed_long_type
|
5259
5276
|
end
|
5260
5277
|
end
|
5261
5278
|
|
@@ -5272,7 +5289,7 @@ module CBuiltin #:nodoc:
|
|
5272
5289
|
end
|
5273
5290
|
|
5274
5291
|
def to_type
|
5275
|
-
@interp.
|
5292
|
+
@interp.signed_int_type
|
5276
5293
|
end
|
5277
5294
|
end
|
5278
5295
|
|
@@ -5289,7 +5306,7 @@ module CBuiltin #:nodoc:
|
|
5289
5306
|
end
|
5290
5307
|
|
5291
5308
|
def to_type
|
5292
|
-
@interp.
|
5309
|
+
@interp.signed_long_type
|
5293
5310
|
end
|
5294
5311
|
end
|
5295
5312
|
|
@@ -5306,7 +5323,7 @@ module CBuiltin #:nodoc:
|
|
5306
5323
|
end
|
5307
5324
|
|
5308
5325
|
def to_type
|
5309
|
-
@interp.
|
5326
|
+
@interp.signed_long_type
|
5310
5327
|
end
|
5311
5328
|
end
|
5312
5329
|
|
@@ -5323,7 +5340,7 @@ module CBuiltin #:nodoc:
|
|
5323
5340
|
end
|
5324
5341
|
|
5325
5342
|
def to_type
|
5326
|
-
@interp.
|
5343
|
+
@interp.signed_long_long_type
|
5327
5344
|
end
|
5328
5345
|
end
|
5329
5346
|
|
@@ -5340,7 +5357,7 @@ module CBuiltin #:nodoc:
|
|
5340
5357
|
end
|
5341
5358
|
|
5342
5359
|
def to_type
|
5343
|
-
@interp.
|
5360
|
+
@interp.signed_long_long_type
|
5344
5361
|
end
|
5345
5362
|
end
|
5346
5363
|
|
@@ -5357,7 +5374,7 @@ module CBuiltin #:nodoc:
|
|
5357
5374
|
end
|
5358
5375
|
|
5359
5376
|
def to_type
|
5360
|
-
@interp.
|
5377
|
+
@interp.signed_long_long_type
|
5361
5378
|
end
|
5362
5379
|
end
|
5363
5380
|
|
@@ -5374,7 +5391,7 @@ module CBuiltin #:nodoc:
|
|
5374
5391
|
end
|
5375
5392
|
|
5376
5393
|
def to_type
|
5377
|
-
@interp.
|
5394
|
+
@interp.signed_long_long_type
|
5378
5395
|
end
|
5379
5396
|
end
|
5380
5397
|
|
@@ -5388,29 +5405,26 @@ module CBuiltin #:nodoc:
|
|
5388
5405
|
def initialize(context)
|
5389
5406
|
super
|
5390
5407
|
@interp = context[:c_interpreter]
|
5391
|
-
@interp.on_function_started += method(:
|
5392
|
-
@interp.on_function_ended += method(:
|
5393
|
-
@interp.on_return_stmt_evaled += method(:
|
5394
|
-
@
|
5408
|
+
@interp.on_function_started += method(:enter_function)
|
5409
|
+
@interp.on_function_ended += method(:leave_function)
|
5410
|
+
@interp.on_return_stmt_evaled += method(:check)
|
5411
|
+
@current_func = nil
|
5395
5412
|
end
|
5396
5413
|
|
5397
5414
|
private
|
5398
|
-
def
|
5399
|
-
@
|
5415
|
+
def enter_function(func_def, func)
|
5416
|
+
@current_func = func
|
5400
5417
|
end
|
5401
5418
|
|
5402
|
-
def
|
5403
|
-
@
|
5419
|
+
def leave_function(func_def, func)
|
5420
|
+
@current_func = nil
|
5404
5421
|
end
|
5405
5422
|
|
5406
|
-
def
|
5407
|
-
|
5408
|
-
|
5409
|
-
|
5410
|
-
|
5411
|
-
if result_variable.type.same_as?(from_type) &&
|
5412
|
-
@current_function.type.return_type.same_as?(to_type)
|
5413
|
-
W(message_id, return_statement.location, @current_function.name)
|
5423
|
+
def check(return_stmt, result_var)
|
5424
|
+
if @current_func && result_var
|
5425
|
+
if match?(result_var.type, @current_func.type.return_type)
|
5426
|
+
W(message_id, return_stmt.location, @current_func.name)
|
5427
|
+
end
|
5414
5428
|
end
|
5415
5429
|
end
|
5416
5430
|
|
@@ -5422,6 +5436,28 @@ module CBuiltin #:nodoc:
|
|
5422
5436
|
@interp.signed_char_type
|
5423
5437
|
end
|
5424
5438
|
|
5439
|
+
def match?(expr_type, func_type)
|
5440
|
+
unless expr_type.same_as?(from_type) && func_type.same_as?(to_type)
|
5441
|
+
return false
|
5442
|
+
end
|
5443
|
+
|
5444
|
+
if char_type_family?(expr_type) &&
|
5445
|
+
expr_type.explicitly_signed? != from_type.explicitly_signed?
|
5446
|
+
return false
|
5447
|
+
end
|
5448
|
+
if char_type_family?(func_type) &&
|
5449
|
+
func_type.explicitly_signed? != to_type.explicitly_signed?
|
5450
|
+
return false
|
5451
|
+
end
|
5452
|
+
|
5453
|
+
true
|
5454
|
+
end
|
5455
|
+
|
5456
|
+
def char_type_family?(type)
|
5457
|
+
type == @interp.char_type ||
|
5458
|
+
type == @interp.signed_char_type || type == @interp.unsigned_char_type
|
5459
|
+
end
|
5460
|
+
|
5425
5461
|
def message_id
|
5426
5462
|
self.class.name.sub(/\A.*::/, "").intern
|
5427
5463
|
end
|
@@ -5457,7 +5493,7 @@ module CBuiltin #:nodoc:
|
|
5457
5493
|
end
|
5458
5494
|
|
5459
5495
|
def to_type
|
5460
|
-
@interp.
|
5496
|
+
@interp.signed_short_type
|
5461
5497
|
end
|
5462
5498
|
end
|
5463
5499
|
|
@@ -5491,7 +5527,7 @@ module CBuiltin #:nodoc:
|
|
5491
5527
|
end
|
5492
5528
|
|
5493
5529
|
def to_type
|
5494
|
-
@interp.
|
5530
|
+
@interp.signed_int_type
|
5495
5531
|
end
|
5496
5532
|
end
|
5497
5533
|
|
@@ -5525,7 +5561,7 @@ module CBuiltin #:nodoc:
|
|
5525
5561
|
end
|
5526
5562
|
|
5527
5563
|
def to_type
|
5528
|
-
@interp.
|
5564
|
+
@interp.signed_long_type
|
5529
5565
|
end
|
5530
5566
|
end
|
5531
5567
|
|
@@ -5610,7 +5646,7 @@ module CBuiltin #:nodoc:
|
|
5610
5646
|
end
|
5611
5647
|
|
5612
5648
|
def to_type
|
5613
|
-
@interp.
|
5649
|
+
@interp.signed_long_long_type
|
5614
5650
|
end
|
5615
5651
|
end
|
5616
5652
|
|
@@ -5674,7 +5710,7 @@ module CBuiltin #:nodoc:
|
|
5674
5710
|
|
5675
5711
|
private
|
5676
5712
|
def from_type
|
5677
|
-
@interp.
|
5713
|
+
@interp.signed_short_type
|
5678
5714
|
end
|
5679
5715
|
|
5680
5716
|
def to_type
|
@@ -5708,7 +5744,7 @@ module CBuiltin #:nodoc:
|
|
5708
5744
|
|
5709
5745
|
private
|
5710
5746
|
def from_type
|
5711
|
-
@interp.
|
5747
|
+
@interp.signed_int_type
|
5712
5748
|
end
|
5713
5749
|
|
5714
5750
|
def to_type
|
@@ -5742,7 +5778,7 @@ module CBuiltin #:nodoc:
|
|
5742
5778
|
|
5743
5779
|
private
|
5744
5780
|
def from_type
|
5745
|
-
@interp.
|
5781
|
+
@interp.signed_long_type
|
5746
5782
|
end
|
5747
5783
|
|
5748
5784
|
def to_type
|
@@ -5776,7 +5812,7 @@ module CBuiltin #:nodoc:
|
|
5776
5812
|
|
5777
5813
|
private
|
5778
5814
|
def from_type
|
5779
|
-
@interp.
|
5815
|
+
@interp.signed_long_long_type
|
5780
5816
|
end
|
5781
5817
|
|
5782
5818
|
def to_type
|
@@ -5848,7 +5884,7 @@ module CBuiltin #:nodoc:
|
|
5848
5884
|
end
|
5849
5885
|
|
5850
5886
|
def to_type
|
5851
|
-
@interp.
|
5887
|
+
@interp.signed_short_type
|
5852
5888
|
end
|
5853
5889
|
end
|
5854
5890
|
|
@@ -5882,7 +5918,7 @@ module CBuiltin #:nodoc:
|
|
5882
5918
|
end
|
5883
5919
|
|
5884
5920
|
def to_type
|
5885
|
-
@interp.
|
5921
|
+
@interp.signed_short_type
|
5886
5922
|
end
|
5887
5923
|
end
|
5888
5924
|
|
@@ -5899,7 +5935,7 @@ module CBuiltin #:nodoc:
|
|
5899
5935
|
end
|
5900
5936
|
|
5901
5937
|
def to_type
|
5902
|
-
@interp.
|
5938
|
+
@interp.signed_int_type
|
5903
5939
|
end
|
5904
5940
|
end
|
5905
5941
|
|
@@ -5933,7 +5969,7 @@ module CBuiltin #:nodoc:
|
|
5933
5969
|
end
|
5934
5970
|
|
5935
5971
|
def to_type
|
5936
|
-
@interp.
|
5972
|
+
@interp.signed_short_type
|
5937
5973
|
end
|
5938
5974
|
end
|
5939
5975
|
|
@@ -5950,7 +5986,7 @@ module CBuiltin #:nodoc:
|
|
5950
5986
|
end
|
5951
5987
|
|
5952
5988
|
def to_type
|
5953
|
-
@interp.
|
5989
|
+
@interp.signed_int_type
|
5954
5990
|
end
|
5955
5991
|
end
|
5956
5992
|
|
@@ -5967,7 +6003,7 @@ module CBuiltin #:nodoc:
|
|
5967
6003
|
end
|
5968
6004
|
|
5969
6005
|
def to_type
|
5970
|
-
@interp.
|
6006
|
+
@interp.signed_long_type
|
5971
6007
|
end
|
5972
6008
|
end
|
5973
6009
|
|
@@ -6001,7 +6037,7 @@ module CBuiltin #:nodoc:
|
|
6001
6037
|
end
|
6002
6038
|
|
6003
6039
|
def to_type
|
6004
|
-
@interp.
|
6040
|
+
@interp.signed_short_type
|
6005
6041
|
end
|
6006
6042
|
end
|
6007
6043
|
|
@@ -6018,7 +6054,7 @@ module CBuiltin #:nodoc:
|
|
6018
6054
|
end
|
6019
6055
|
|
6020
6056
|
def to_type
|
6021
|
-
@interp.
|
6057
|
+
@interp.signed_int_type
|
6022
6058
|
end
|
6023
6059
|
end
|
6024
6060
|
|
@@ -6035,7 +6071,7 @@ module CBuiltin #:nodoc:
|
|
6035
6071
|
end
|
6036
6072
|
|
6037
6073
|
def to_type
|
6038
|
-
@interp.
|
6074
|
+
@interp.signed_long_type
|
6039
6075
|
end
|
6040
6076
|
end
|
6041
6077
|
|
@@ -6052,7 +6088,7 @@ module CBuiltin #:nodoc:
|
|
6052
6088
|
end
|
6053
6089
|
|
6054
6090
|
def to_type
|
6055
|
-
@interp.
|
6091
|
+
@interp.signed_long_long_type
|
6056
6092
|
end
|
6057
6093
|
end
|
6058
6094
|
|
@@ -6133,7 +6169,7 @@ module CBuiltin #:nodoc:
|
|
6133
6169
|
|
6134
6170
|
private
|
6135
6171
|
def from_type
|
6136
|
-
@interp.
|
6172
|
+
@interp.signed_short_type
|
6137
6173
|
end
|
6138
6174
|
|
6139
6175
|
def to_type
|
@@ -6150,7 +6186,7 @@ module CBuiltin #:nodoc:
|
|
6150
6186
|
|
6151
6187
|
private
|
6152
6188
|
def from_type
|
6153
|
-
@interp.
|
6189
|
+
@interp.signed_short_type
|
6154
6190
|
end
|
6155
6191
|
|
6156
6192
|
def to_type
|
@@ -6167,7 +6203,7 @@ module CBuiltin #:nodoc:
|
|
6167
6203
|
|
6168
6204
|
private
|
6169
6205
|
def from_type
|
6170
|
-
@interp.
|
6206
|
+
@interp.signed_short_type
|
6171
6207
|
end
|
6172
6208
|
|
6173
6209
|
def to_type
|
@@ -6184,7 +6220,7 @@ module CBuiltin #:nodoc:
|
|
6184
6220
|
|
6185
6221
|
private
|
6186
6222
|
def from_type
|
6187
|
-
@interp.
|
6223
|
+
@interp.signed_short_type
|
6188
6224
|
end
|
6189
6225
|
|
6190
6226
|
def to_type
|
@@ -6201,7 +6237,7 @@ module CBuiltin #:nodoc:
|
|
6201
6237
|
|
6202
6238
|
private
|
6203
6239
|
def from_type
|
6204
|
-
@interp.
|
6240
|
+
@interp.signed_int_type
|
6205
6241
|
end
|
6206
6242
|
|
6207
6243
|
def to_type
|
@@ -6218,7 +6254,7 @@ module CBuiltin #:nodoc:
|
|
6218
6254
|
|
6219
6255
|
private
|
6220
6256
|
def from_type
|
6221
|
-
@interp.
|
6257
|
+
@interp.signed_int_type
|
6222
6258
|
end
|
6223
6259
|
|
6224
6260
|
def to_type
|
@@ -6235,7 +6271,7 @@ module CBuiltin #:nodoc:
|
|
6235
6271
|
|
6236
6272
|
private
|
6237
6273
|
def from_type
|
6238
|
-
@interp.
|
6274
|
+
@interp.signed_int_type
|
6239
6275
|
end
|
6240
6276
|
|
6241
6277
|
def to_type
|
@@ -6252,7 +6288,7 @@ module CBuiltin #:nodoc:
|
|
6252
6288
|
|
6253
6289
|
private
|
6254
6290
|
def from_type
|
6255
|
-
@interp.
|
6291
|
+
@interp.signed_int_type
|
6256
6292
|
end
|
6257
6293
|
|
6258
6294
|
def to_type
|
@@ -6269,7 +6305,7 @@ module CBuiltin #:nodoc:
|
|
6269
6305
|
|
6270
6306
|
private
|
6271
6307
|
def from_type
|
6272
|
-
@interp.
|
6308
|
+
@interp.signed_long_type
|
6273
6309
|
end
|
6274
6310
|
|
6275
6311
|
def to_type
|
@@ -6286,7 +6322,7 @@ module CBuiltin #:nodoc:
|
|
6286
6322
|
|
6287
6323
|
private
|
6288
6324
|
def from_type
|
6289
|
-
@interp.
|
6325
|
+
@interp.signed_long_type
|
6290
6326
|
end
|
6291
6327
|
|
6292
6328
|
def to_type
|
@@ -6303,7 +6339,7 @@ module CBuiltin #:nodoc:
|
|
6303
6339
|
|
6304
6340
|
private
|
6305
6341
|
def from_type
|
6306
|
-
@interp.
|
6342
|
+
@interp.signed_long_type
|
6307
6343
|
end
|
6308
6344
|
|
6309
6345
|
def to_type
|
@@ -6320,7 +6356,7 @@ module CBuiltin #:nodoc:
|
|
6320
6356
|
|
6321
6357
|
private
|
6322
6358
|
def from_type
|
6323
|
-
@interp.
|
6359
|
+
@interp.signed_long_type
|
6324
6360
|
end
|
6325
6361
|
|
6326
6362
|
def to_type
|
@@ -6354,7 +6390,7 @@ module CBuiltin #:nodoc:
|
|
6354
6390
|
|
6355
6391
|
private
|
6356
6392
|
def from_type
|
6357
|
-
@interp.
|
6393
|
+
@interp.signed_short_type
|
6358
6394
|
end
|
6359
6395
|
|
6360
6396
|
def to_type
|
@@ -6371,7 +6407,7 @@ module CBuiltin #:nodoc:
|
|
6371
6407
|
|
6372
6408
|
private
|
6373
6409
|
def from_type
|
6374
|
-
@interp.
|
6410
|
+
@interp.signed_int_type
|
6375
6411
|
end
|
6376
6412
|
|
6377
6413
|
def to_type
|
@@ -6388,7 +6424,7 @@ module CBuiltin #:nodoc:
|
|
6388
6424
|
|
6389
6425
|
private
|
6390
6426
|
def from_type
|
6391
|
-
@interp.
|
6427
|
+
@interp.signed_long_type
|
6392
6428
|
end
|
6393
6429
|
|
6394
6430
|
def to_type
|
@@ -6405,7 +6441,7 @@ module CBuiltin #:nodoc:
|
|
6405
6441
|
|
6406
6442
|
private
|
6407
6443
|
def from_type
|
6408
|
-
@interp.
|
6444
|
+
@interp.signed_long_long_type
|
6409
6445
|
end
|
6410
6446
|
|
6411
6447
|
def to_type
|
@@ -6422,7 +6458,7 @@ module CBuiltin #:nodoc:
|
|
6422
6458
|
|
6423
6459
|
private
|
6424
6460
|
def from_type
|
6425
|
-
@interp.
|
6461
|
+
@interp.signed_long_long_type
|
6426
6462
|
end
|
6427
6463
|
|
6428
6464
|
def to_type
|
@@ -6439,7 +6475,7 @@ module CBuiltin #:nodoc:
|
|
6439
6475
|
|
6440
6476
|
private
|
6441
6477
|
def from_type
|
6442
|
-
@interp.
|
6478
|
+
@interp.signed_long_long_type
|
6443
6479
|
end
|
6444
6480
|
|
6445
6481
|
def to_type
|
@@ -6456,7 +6492,7 @@ module CBuiltin #:nodoc:
|
|
6456
6492
|
|
6457
6493
|
private
|
6458
6494
|
def from_type
|
6459
|
-
@interp.
|
6495
|
+
@interp.signed_long_long_type
|
6460
6496
|
end
|
6461
6497
|
|
6462
6498
|
def to_type
|
@@ -6473,7 +6509,7 @@ module CBuiltin #:nodoc:
|
|
6473
6509
|
|
6474
6510
|
private
|
6475
6511
|
def from_type
|
6476
|
-
@interp.
|
6512
|
+
@interp.signed_long_long_type
|
6477
6513
|
end
|
6478
6514
|
|
6479
6515
|
def to_type
|
@@ -6592,7 +6628,7 @@ module CBuiltin #:nodoc:
|
|
6592
6628
|
|
6593
6629
|
private
|
6594
6630
|
def from_type
|
6595
|
-
@interp.
|
6631
|
+
@interp.signed_short_type
|
6596
6632
|
end
|
6597
6633
|
|
6598
6634
|
def to_type
|
@@ -6609,7 +6645,7 @@ module CBuiltin #:nodoc:
|
|
6609
6645
|
|
6610
6646
|
private
|
6611
6647
|
def from_type
|
6612
|
-
@interp.
|
6648
|
+
@interp.signed_short_type
|
6613
6649
|
end
|
6614
6650
|
|
6615
6651
|
def to_type
|
@@ -6626,7 +6662,7 @@ module CBuiltin #:nodoc:
|
|
6626
6662
|
|
6627
6663
|
private
|
6628
6664
|
def from_type
|
6629
|
-
@interp.
|
6665
|
+
@interp.signed_short_type
|
6630
6666
|
end
|
6631
6667
|
|
6632
6668
|
def to_type
|
@@ -6694,7 +6730,7 @@ module CBuiltin #:nodoc:
|
|
6694
6730
|
|
6695
6731
|
private
|
6696
6732
|
def from_type
|
6697
|
-
@interp.
|
6733
|
+
@interp.signed_int_type
|
6698
6734
|
end
|
6699
6735
|
|
6700
6736
|
def to_type
|
@@ -6711,7 +6747,7 @@ module CBuiltin #:nodoc:
|
|
6711
6747
|
|
6712
6748
|
private
|
6713
6749
|
def from_type
|
6714
|
-
@interp.
|
6750
|
+
@interp.signed_int_type
|
6715
6751
|
end
|
6716
6752
|
|
6717
6753
|
def to_type
|
@@ -6728,7 +6764,7 @@ module CBuiltin #:nodoc:
|
|
6728
6764
|
|
6729
6765
|
private
|
6730
6766
|
def from_type
|
6731
|
-
@interp.
|
6767
|
+
@interp.signed_int_type
|
6732
6768
|
end
|
6733
6769
|
|
6734
6770
|
def to_type
|
@@ -6796,7 +6832,7 @@ module CBuiltin #:nodoc:
|
|
6796
6832
|
|
6797
6833
|
private
|
6798
6834
|
def from_type
|
6799
|
-
@interp.
|
6835
|
+
@interp.signed_long_type
|
6800
6836
|
end
|
6801
6837
|
|
6802
6838
|
def to_type
|
@@ -6813,7 +6849,7 @@ module CBuiltin #:nodoc:
|
|
6813
6849
|
|
6814
6850
|
private
|
6815
6851
|
def from_type
|
6816
|
-
@interp.
|
6852
|
+
@interp.signed_long_type
|
6817
6853
|
end
|
6818
6854
|
|
6819
6855
|
def to_type
|
@@ -6830,7 +6866,7 @@ module CBuiltin #:nodoc:
|
|
6830
6866
|
|
6831
6867
|
private
|
6832
6868
|
def from_type
|
6833
|
-
@interp.
|
6869
|
+
@interp.signed_long_type
|
6834
6870
|
end
|
6835
6871
|
|
6836
6872
|
def to_type
|
@@ -6898,7 +6934,7 @@ module CBuiltin #:nodoc:
|
|
6898
6934
|
|
6899
6935
|
private
|
6900
6936
|
def from_type
|
6901
|
-
@interp.
|
6937
|
+
@interp.signed_long_long_type
|
6902
6938
|
end
|
6903
6939
|
|
6904
6940
|
def to_type
|
@@ -6915,7 +6951,7 @@ module CBuiltin #:nodoc:
|
|
6915
6951
|
|
6916
6952
|
private
|
6917
6953
|
def from_type
|
6918
|
-
@interp.
|
6954
|
+
@interp.signed_long_long_type
|
6919
6955
|
end
|
6920
6956
|
|
6921
6957
|
def to_type
|
@@ -6932,7 +6968,7 @@ module CBuiltin #:nodoc:
|
|
6932
6968
|
|
6933
6969
|
private
|
6934
6970
|
def from_type
|
6935
|
-
@interp.
|
6971
|
+
@interp.signed_long_long_type
|
6936
6972
|
end
|
6937
6973
|
|
6938
6974
|
def to_type
|
@@ -7055,7 +7091,7 @@ module CBuiltin #:nodoc:
|
|
7055
7091
|
end
|
7056
7092
|
|
7057
7093
|
def to_type
|
7058
|
-
@interp.
|
7094
|
+
@interp.signed_short_type
|
7059
7095
|
end
|
7060
7096
|
end
|
7061
7097
|
|
@@ -7089,7 +7125,7 @@ module CBuiltin #:nodoc:
|
|
7089
7125
|
end
|
7090
7126
|
|
7091
7127
|
def to_type
|
7092
|
-
@interp.
|
7128
|
+
@interp.signed_int_type
|
7093
7129
|
end
|
7094
7130
|
end
|
7095
7131
|
|
@@ -7123,7 +7159,7 @@ module CBuiltin #:nodoc:
|
|
7123
7159
|
end
|
7124
7160
|
|
7125
7161
|
def to_type
|
7126
|
-
@interp.
|
7162
|
+
@interp.signed_long_type
|
7127
7163
|
end
|
7128
7164
|
end
|
7129
7165
|
|
@@ -7208,7 +7244,7 @@ module CBuiltin #:nodoc:
|
|
7208
7244
|
end
|
7209
7245
|
|
7210
7246
|
def to_type
|
7211
|
-
@interp.
|
7247
|
+
@interp.signed_short_type
|
7212
7248
|
end
|
7213
7249
|
end
|
7214
7250
|
|
@@ -7242,7 +7278,7 @@ module CBuiltin #:nodoc:
|
|
7242
7278
|
end
|
7243
7279
|
|
7244
7280
|
def to_type
|
7245
|
-
@interp.
|
7281
|
+
@interp.signed_int_type
|
7246
7282
|
end
|
7247
7283
|
end
|
7248
7284
|
|
@@ -7276,7 +7312,7 @@ module CBuiltin #:nodoc:
|
|
7276
7312
|
end
|
7277
7313
|
|
7278
7314
|
def to_type
|
7279
|
-
@interp.
|
7315
|
+
@interp.signed_long_type
|
7280
7316
|
end
|
7281
7317
|
end
|
7282
7318
|
|
@@ -7361,7 +7397,7 @@ module CBuiltin #:nodoc:
|
|
7361
7397
|
end
|
7362
7398
|
|
7363
7399
|
def to_type
|
7364
|
-
@interp.
|
7400
|
+
@interp.signed_short_type
|
7365
7401
|
end
|
7366
7402
|
end
|
7367
7403
|
|
@@ -7395,7 +7431,7 @@ module CBuiltin #:nodoc:
|
|
7395
7431
|
end
|
7396
7432
|
|
7397
7433
|
def to_type
|
7398
|
-
@interp.
|
7434
|
+
@interp.signed_int_type
|
7399
7435
|
end
|
7400
7436
|
end
|
7401
7437
|
|
@@ -7429,7 +7465,7 @@ module CBuiltin #:nodoc:
|
|
7429
7465
|
end
|
7430
7466
|
|
7431
7467
|
def to_type
|
7432
|
-
@interp.
|
7468
|
+
@interp.signed_long_type
|
7433
7469
|
end
|
7434
7470
|
end
|
7435
7471
|
|
@@ -7463,7 +7499,7 @@ module CBuiltin #:nodoc:
|
|
7463
7499
|
end
|
7464
7500
|
|
7465
7501
|
def to_type
|
7466
|
-
@interp.
|
7502
|
+
@interp.signed_long_long_type
|
7467
7503
|
end
|
7468
7504
|
end
|
7469
7505
|
|
@@ -7497,7 +7533,7 @@ module CBuiltin #:nodoc:
|
|
7497
7533
|
end
|
7498
7534
|
|
7499
7535
|
def to_type
|
7500
|
-
@interp.
|
7536
|
+
@interp.signed_long_long_type
|
7501
7537
|
end
|
7502
7538
|
end
|
7503
7539
|
|
@@ -7531,7 +7567,7 @@ module CBuiltin #:nodoc:
|
|
7531
7567
|
end
|
7532
7568
|
|
7533
7569
|
def to_type
|
7534
|
-
@interp.
|
7570
|
+
@interp.signed_long_long_type
|
7535
7571
|
end
|
7536
7572
|
end
|
7537
7573
|
|
@@ -7561,7 +7597,7 @@ module CBuiltin #:nodoc:
|
|
7561
7597
|
|
7562
7598
|
private
|
7563
7599
|
def from_type
|
7564
|
-
@interp.
|
7600
|
+
@interp.signed_short_type
|
7565
7601
|
end
|
7566
7602
|
|
7567
7603
|
def to_type
|
@@ -7595,7 +7631,7 @@ module CBuiltin #:nodoc:
|
|
7595
7631
|
|
7596
7632
|
private
|
7597
7633
|
def from_type
|
7598
|
-
@interp.
|
7634
|
+
@interp.signed_int_type
|
7599
7635
|
end
|
7600
7636
|
|
7601
7637
|
def to_type
|
@@ -7612,11 +7648,11 @@ module CBuiltin #:nodoc:
|
|
7612
7648
|
|
7613
7649
|
private
|
7614
7650
|
def from_type
|
7615
|
-
@interp.
|
7651
|
+
@interp.signed_int_type
|
7616
7652
|
end
|
7617
7653
|
|
7618
7654
|
def to_type
|
7619
|
-
@interp.
|
7655
|
+
@interp.signed_short_type
|
7620
7656
|
end
|
7621
7657
|
end
|
7622
7658
|
|
@@ -7663,7 +7699,7 @@ module CBuiltin #:nodoc:
|
|
7663
7699
|
|
7664
7700
|
private
|
7665
7701
|
def from_type
|
7666
|
-
@interp.
|
7702
|
+
@interp.signed_long_type
|
7667
7703
|
end
|
7668
7704
|
|
7669
7705
|
def to_type
|
@@ -7680,11 +7716,11 @@ module CBuiltin #:nodoc:
|
|
7680
7716
|
|
7681
7717
|
private
|
7682
7718
|
def from_type
|
7683
|
-
@interp.
|
7719
|
+
@interp.signed_long_type
|
7684
7720
|
end
|
7685
7721
|
|
7686
7722
|
def to_type
|
7687
|
-
@interp.
|
7723
|
+
@interp.signed_short_type
|
7688
7724
|
end
|
7689
7725
|
end
|
7690
7726
|
|
@@ -7697,11 +7733,11 @@ module CBuiltin #:nodoc:
|
|
7697
7733
|
|
7698
7734
|
private
|
7699
7735
|
def from_type
|
7700
|
-
@interp.
|
7736
|
+
@interp.signed_long_type
|
7701
7737
|
end
|
7702
7738
|
|
7703
7739
|
def to_type
|
7704
|
-
@interp.
|
7740
|
+
@interp.signed_int_type
|
7705
7741
|
end
|
7706
7742
|
end
|
7707
7743
|
|
@@ -7765,7 +7801,7 @@ module CBuiltin #:nodoc:
|
|
7765
7801
|
|
7766
7802
|
private
|
7767
7803
|
def from_type
|
7768
|
-
@interp.
|
7804
|
+
@interp.signed_long_long_type
|
7769
7805
|
end
|
7770
7806
|
|
7771
7807
|
def to_type
|
@@ -7782,11 +7818,11 @@ module CBuiltin #:nodoc:
|
|
7782
7818
|
|
7783
7819
|
private
|
7784
7820
|
def from_type
|
7785
|
-
@interp.
|
7821
|
+
@interp.signed_long_long_type
|
7786
7822
|
end
|
7787
7823
|
|
7788
7824
|
def to_type
|
7789
|
-
@interp.
|
7825
|
+
@interp.signed_short_type
|
7790
7826
|
end
|
7791
7827
|
end
|
7792
7828
|
|
@@ -7799,11 +7835,11 @@ module CBuiltin #:nodoc:
|
|
7799
7835
|
|
7800
7836
|
private
|
7801
7837
|
def from_type
|
7802
|
-
@interp.
|
7838
|
+
@interp.signed_long_long_type
|
7803
7839
|
end
|
7804
7840
|
|
7805
7841
|
def to_type
|
7806
|
-
@interp.
|
7842
|
+
@interp.signed_int_type
|
7807
7843
|
end
|
7808
7844
|
end
|
7809
7845
|
|
@@ -7816,11 +7852,11 @@ module CBuiltin #:nodoc:
|
|
7816
7852
|
|
7817
7853
|
private
|
7818
7854
|
def from_type
|
7819
|
-
@interp.
|
7855
|
+
@interp.signed_long_long_type
|
7820
7856
|
end
|
7821
7857
|
|
7822
7858
|
def to_type
|
7823
|
-
@interp.
|
7859
|
+
@interp.signed_long_type
|
7824
7860
|
end
|
7825
7861
|
end
|
7826
7862
|
|
@@ -7905,7 +7941,7 @@ module CBuiltin #:nodoc:
|
|
7905
7941
|
end
|
7906
7942
|
|
7907
7943
|
def to_type
|
7908
|
-
@interp.
|
7944
|
+
@interp.signed_short_type
|
7909
7945
|
end
|
7910
7946
|
end
|
7911
7947
|
|
@@ -7922,7 +7958,7 @@ module CBuiltin #:nodoc:
|
|
7922
7958
|
end
|
7923
7959
|
|
7924
7960
|
def to_type
|
7925
|
-
@interp.
|
7961
|
+
@interp.signed_int_type
|
7926
7962
|
end
|
7927
7963
|
end
|
7928
7964
|
|
@@ -7939,7 +7975,7 @@ module CBuiltin #:nodoc:
|
|
7939
7975
|
end
|
7940
7976
|
|
7941
7977
|
def to_type
|
7942
|
-
@interp.
|
7978
|
+
@interp.signed_long_type
|
7943
7979
|
end
|
7944
7980
|
end
|
7945
7981
|
|
@@ -7956,7 +7992,7 @@ module CBuiltin #:nodoc:
|
|
7956
7992
|
end
|
7957
7993
|
|
7958
7994
|
def to_type
|
7959
|
-
@interp.
|
7995
|
+
@interp.signed_int_type
|
7960
7996
|
end
|
7961
7997
|
end
|
7962
7998
|
|
@@ -7973,7 +8009,7 @@ module CBuiltin #:nodoc:
|
|
7973
8009
|
end
|
7974
8010
|
|
7975
8011
|
def to_type
|
7976
|
-
@interp.
|
8012
|
+
@interp.signed_long_type
|
7977
8013
|
end
|
7978
8014
|
end
|
7979
8015
|
|
@@ -7990,7 +8026,7 @@ module CBuiltin #:nodoc:
|
|
7990
8026
|
end
|
7991
8027
|
|
7992
8028
|
def to_type
|
7993
|
-
@interp.
|
8029
|
+
@interp.signed_long_type
|
7994
8030
|
end
|
7995
8031
|
end
|
7996
8032
|
|
@@ -8007,7 +8043,7 @@ module CBuiltin #:nodoc:
|
|
8007
8043
|
end
|
8008
8044
|
|
8009
8045
|
def to_type
|
8010
|
-
@interp.
|
8046
|
+
@interp.signed_long_long_type
|
8011
8047
|
end
|
8012
8048
|
end
|
8013
8049
|
|
@@ -8024,7 +8060,7 @@ module CBuiltin #:nodoc:
|
|
8024
8060
|
end
|
8025
8061
|
|
8026
8062
|
def to_type
|
8027
|
-
@interp.
|
8063
|
+
@interp.signed_long_long_type
|
8028
8064
|
end
|
8029
8065
|
end
|
8030
8066
|
|
@@ -8041,7 +8077,7 @@ module CBuiltin #:nodoc:
|
|
8041
8077
|
end
|
8042
8078
|
|
8043
8079
|
def to_type
|
8044
|
-
@interp.
|
8080
|
+
@interp.signed_long_long_type
|
8045
8081
|
end
|
8046
8082
|
end
|
8047
8083
|
|
@@ -8058,7 +8094,7 @@ module CBuiltin #:nodoc:
|
|
8058
8094
|
end
|
8059
8095
|
|
8060
8096
|
def to_type
|
8061
|
-
@interp.
|
8097
|
+
@interp.signed_long_long_type
|
8062
8098
|
end
|
8063
8099
|
end
|
8064
8100
|
|
@@ -9928,128 +9964,160 @@ module CBuiltin #:nodoc:
|
|
9928
9964
|
interp.on_label_defined += method(:define_label)
|
9929
9965
|
interp.on_block_started += method(:enter_scope)
|
9930
9966
|
interp.on_block_ended += method(:leave_scope)
|
9931
|
-
@
|
9967
|
+
@dcl_names = [[]]
|
9932
9968
|
@tag_names = [[]]
|
9933
9969
|
@label_names = [[]]
|
9934
9970
|
end
|
9935
9971
|
|
9936
9972
|
private
|
9937
|
-
def define_variable(
|
9938
|
-
|
9973
|
+
def define_variable(var_def, *)
|
9974
|
+
dcl_name = var_def.identifier
|
9939
9975
|
|
9940
|
-
(@tag_names + @label_names).
|
9941
|
-
|
9942
|
-
|
9943
|
-
|
9976
|
+
pair_names = (@tag_names + @label_names).flatten.select { |id|
|
9977
|
+
id.value == dcl_name.value
|
9978
|
+
}
|
9979
|
+
|
9980
|
+
unless pair_names.empty?
|
9981
|
+
W(:W0491, var_def.location, dcl_name.value)
|
9982
|
+
pair_names.each do |pair_name|
|
9983
|
+
C(:C0001, pair_name.location, pair_name.value)
|
9944
9984
|
end
|
9945
9985
|
end
|
9946
9986
|
|
9947
|
-
@
|
9987
|
+
@dcl_names.last.push(dcl_name)
|
9948
9988
|
end
|
9949
9989
|
|
9950
|
-
def declare_variable(
|
9951
|
-
|
9990
|
+
def declare_variable(var_dcl, *)
|
9991
|
+
dcl_name = var_dcl.identifier
|
9952
9992
|
|
9953
|
-
(@tag_names + @label_names).
|
9954
|
-
|
9955
|
-
|
9956
|
-
|
9993
|
+
pair_names = (@tag_names + @label_names).flatten.select { |id|
|
9994
|
+
id.value == dcl_name.value
|
9995
|
+
}
|
9996
|
+
|
9997
|
+
unless pair_names.empty?
|
9998
|
+
W(:W0491, var_dcl.location, dcl_name.value)
|
9999
|
+
pair_names.each do |pair_name|
|
10000
|
+
C(:C0001, pair_name.location, pair_name.value)
|
9957
10001
|
end
|
9958
10002
|
end
|
9959
10003
|
|
9960
|
-
@
|
10004
|
+
@dcl_names.last.push(dcl_name)
|
9961
10005
|
end
|
9962
10006
|
|
9963
|
-
def declare_struct(
|
9964
|
-
|
9965
|
-
return unless
|
10007
|
+
def declare_struct(struct_dcl)
|
10008
|
+
tag_name = struct_dcl.identifier
|
10009
|
+
return unless tag_name
|
9966
10010
|
|
9967
|
-
(@
|
9968
|
-
|
9969
|
-
|
9970
|
-
|
10011
|
+
pair_names = (@dcl_names + @label_names).flatten.select { |id|
|
10012
|
+
id.value == tag_name.value
|
10013
|
+
}
|
10014
|
+
|
10015
|
+
unless pair_names.empty?
|
10016
|
+
W(:W0491, struct_dcl.location, tag_name.value)
|
10017
|
+
pair_names.each do |pair_name|
|
10018
|
+
C(:C0001, pair_name.location, pair_name.value)
|
9971
10019
|
end
|
9972
10020
|
end
|
9973
10021
|
|
9974
|
-
@tag_names.last.push(
|
10022
|
+
@tag_names.last.push(tag_name)
|
9975
10023
|
end
|
9976
10024
|
|
9977
|
-
def declare_union(
|
9978
|
-
|
9979
|
-
return unless
|
10025
|
+
def declare_union(union_dcl)
|
10026
|
+
tag_name = union_dcl.identifier
|
10027
|
+
return unless tag_name
|
9980
10028
|
|
9981
|
-
(@
|
9982
|
-
|
9983
|
-
|
9984
|
-
|
10029
|
+
pair_names = (@dcl_names + @label_names).flatten.select { |id|
|
10030
|
+
id.value == tag_name.value
|
10031
|
+
}
|
10032
|
+
|
10033
|
+
unless pair_names.empty?
|
10034
|
+
W(:W0491, union_dcl.location, tag_name.value)
|
10035
|
+
pair_names.each do |pair_name|
|
10036
|
+
C(:C0001, pair_name.location, pair_name.value)
|
9985
10037
|
end
|
9986
10038
|
end
|
9987
10039
|
|
9988
|
-
@tag_names.last.push(
|
10040
|
+
@tag_names.last.push(tag_name)
|
9989
10041
|
end
|
9990
10042
|
|
9991
|
-
def declare_enum(
|
9992
|
-
|
9993
|
-
return unless
|
10043
|
+
def declare_enum(enum_dcl)
|
10044
|
+
tag_name = enum_dcl.identifier
|
10045
|
+
return unless tag_name
|
9994
10046
|
|
9995
|
-
(@
|
9996
|
-
|
9997
|
-
|
9998
|
-
|
10047
|
+
pair_names = (@dcl_names + @label_names).flatten.select { |id|
|
10048
|
+
id.value == tag_name.value
|
10049
|
+
}
|
10050
|
+
|
10051
|
+
unless pair_names.empty?
|
10052
|
+
W(:W0491, enum_dcl.location, tag_name.value)
|
10053
|
+
pair_names.each do |pair_name|
|
10054
|
+
C(:C0001, pair_name.location, pair_name.value)
|
9999
10055
|
end
|
10000
10056
|
end
|
10001
10057
|
|
10002
|
-
@tag_names.last.push(
|
10058
|
+
@tag_names.last.push(tag_name)
|
10003
10059
|
end
|
10004
10060
|
|
10005
|
-
def declare_typedef(
|
10006
|
-
|
10061
|
+
def declare_typedef(typedef_dcl)
|
10062
|
+
dcl_name = typedef_dcl.identifier
|
10007
10063
|
|
10008
|
-
(@tag_names + @label_names).
|
10009
|
-
|
10010
|
-
|
10011
|
-
|
10064
|
+
pair_names = (@tag_names + @label_names).flatten.select { |id|
|
10065
|
+
id.value == dcl_name.value
|
10066
|
+
}
|
10067
|
+
|
10068
|
+
unless pair_names.empty?
|
10069
|
+
W(:W0491, typedef_dcl.location, dcl_name.value)
|
10070
|
+
pair_names.each do |pair_name|
|
10071
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10012
10072
|
end
|
10013
10073
|
end
|
10014
10074
|
|
10015
|
-
@
|
10075
|
+
@dcl_names.last.push(dcl_name)
|
10016
10076
|
end
|
10017
10077
|
|
10018
|
-
def define_parameter(
|
10019
|
-
|
10020
|
-
return unless
|
10078
|
+
def define_parameter(param_def, *)
|
10079
|
+
dcl_name = param_def.identifier
|
10080
|
+
return unless dcl_name
|
10021
10081
|
|
10022
|
-
(@tag_names + @label_names).
|
10023
|
-
|
10024
|
-
|
10025
|
-
|
10082
|
+
pair_names = (@tag_names + @label_names).flatten.select { |id|
|
10083
|
+
id.value == dcl_name.value
|
10084
|
+
}
|
10085
|
+
|
10086
|
+
unless pair_names.empty?
|
10087
|
+
W(:W0491, param_def.location, dcl_name.value)
|
10088
|
+
pair_names.each do |pair_name|
|
10089
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10026
10090
|
end
|
10027
10091
|
end
|
10028
10092
|
|
10029
|
-
@
|
10093
|
+
@dcl_names.last.push(dcl_name)
|
10030
10094
|
end
|
10031
10095
|
|
10032
|
-
def define_label(
|
10033
|
-
|
10096
|
+
def define_label(labeled_stmt)
|
10097
|
+
label_name = labeled_stmt.label
|
10034
10098
|
|
10035
|
-
(@
|
10036
|
-
|
10037
|
-
|
10038
|
-
|
10099
|
+
pair_names = (@dcl_names + @tag_names).flatten.select { |id|
|
10100
|
+
id.value == label_name.value
|
10101
|
+
}
|
10102
|
+
|
10103
|
+
unless pair_names.empty?
|
10104
|
+
W(:W0491, labeled_stmt.location, label_name.value)
|
10105
|
+
pair_names.each do |pair_name|
|
10106
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10039
10107
|
end
|
10040
10108
|
end
|
10041
10109
|
|
10042
|
-
@label_names.last.push(
|
10110
|
+
@label_names.last.push(label_name)
|
10043
10111
|
end
|
10044
10112
|
|
10045
|
-
def enter_scope(
|
10046
|
-
@
|
10113
|
+
def enter_scope(*)
|
10114
|
+
@dcl_names.push([])
|
10047
10115
|
@tag_names.push([])
|
10048
10116
|
@label_names.push([])
|
10049
10117
|
end
|
10050
10118
|
|
10051
|
-
def leave_scope(
|
10052
|
-
@
|
10119
|
+
def leave_scope(*)
|
10120
|
+
@dcl_names.pop
|
10053
10121
|
@tag_names.pop
|
10054
10122
|
@label_names.pop
|
10055
10123
|
end
|
@@ -10067,169 +10135,178 @@ module CBuiltin #:nodoc:
|
|
10067
10135
|
interp = context[:c_interpreter]
|
10068
10136
|
interp.on_variable_defined += method(:define_variable)
|
10069
10137
|
interp.on_variable_declared += method(:declare_variable)
|
10070
|
-
interp.on_struct_declared += method(:
|
10071
|
-
interp.on_union_declared += method(:
|
10138
|
+
interp.on_struct_declared += method(:declare_struct_or_union)
|
10139
|
+
interp.on_union_declared += method(:declare_struct_or_union)
|
10072
10140
|
interp.on_enum_declared += method(:declare_enum)
|
10073
10141
|
interp.on_typedef_declared += method(:declare_typedef)
|
10074
10142
|
interp.on_parameter_defined += method(:define_parameter)
|
10075
10143
|
interp.on_label_defined += method(:define_label)
|
10076
10144
|
interp.on_block_started += method(:enter_scope)
|
10077
10145
|
interp.on_block_ended += method(:leave_scope)
|
10078
|
-
@
|
10146
|
+
@dcl_names = [[]]
|
10079
10147
|
@tag_names = [[]]
|
10080
10148
|
@label_names = [[]]
|
10081
|
-
@
|
10149
|
+
@memb_names = [[]]
|
10082
10150
|
end
|
10083
10151
|
|
10084
10152
|
private
|
10085
|
-
def define_variable(
|
10086
|
-
|
10153
|
+
def define_variable(var_def, *)
|
10154
|
+
dcl_name = var_def.identifier
|
10087
10155
|
|
10088
|
-
@
|
10089
|
-
|
10090
|
-
|
10091
|
-
|
10156
|
+
pair_names = @memb_names.flatten.select { |id|
|
10157
|
+
id.value == dcl_name.value
|
10158
|
+
}
|
10159
|
+
|
10160
|
+
unless pair_names.empty?
|
10161
|
+
W(:W0492, var_def.location, dcl_name.value)
|
10162
|
+
pair_names.each do |pair_name|
|
10163
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10092
10164
|
end
|
10093
10165
|
end
|
10094
10166
|
|
10095
|
-
@
|
10167
|
+
@dcl_names.last.push(dcl_name)
|
10096
10168
|
end
|
10097
10169
|
|
10098
|
-
def declare_variable(
|
10099
|
-
|
10170
|
+
def declare_variable(var_dcl, *)
|
10171
|
+
dcl_name = var_dcl.identifier
|
10100
10172
|
|
10101
|
-
@
|
10102
|
-
|
10103
|
-
|
10104
|
-
|
10173
|
+
pair_names = @memb_names.flatten.select { |id|
|
10174
|
+
id.value == dcl_name.value
|
10175
|
+
}
|
10176
|
+
|
10177
|
+
unless pair_names.empty?
|
10178
|
+
W(:W0492, var_dcl.location, dcl_name.value)
|
10179
|
+
pair_names.each do |pair_name|
|
10180
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10105
10181
|
end
|
10106
10182
|
end
|
10107
10183
|
|
10108
|
-
@
|
10184
|
+
@dcl_names.last.push(dcl_name)
|
10109
10185
|
end
|
10110
10186
|
|
10111
|
-
def
|
10112
|
-
|
10113
|
-
return unless
|
10187
|
+
def declare_struct_or_union(struct_or_union_dcl)
|
10188
|
+
tag_name = struct_or_union_dcl.identifier
|
10189
|
+
return unless tag_name
|
10114
10190
|
|
10115
|
-
@
|
10116
|
-
|
10117
|
-
|
10118
|
-
break
|
10119
|
-
end
|
10120
|
-
end
|
10121
|
-
|
10122
|
-
member_declarations = MemberExtractor.new.tap { |ext|
|
10123
|
-
struct_type_declaration.accept(ext)
|
10124
|
-
}.result
|
10191
|
+
pair_names = @memb_names.flatten.select { |id|
|
10192
|
+
id.value == tag_name.value
|
10193
|
+
}
|
10125
10194
|
|
10126
|
-
|
10127
|
-
|
10128
|
-
|
10129
|
-
|
10130
|
-
}
|
10131
|
-
W(:W0492, member.location, member.identifier.value) if member
|
10195
|
+
unless pair_names.empty?
|
10196
|
+
W(:W0492, struct_or_union_dcl.location, tag_name.value)
|
10197
|
+
pair_names.each do |pair_name|
|
10198
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10132
10199
|
end
|
10133
10200
|
end
|
10134
10201
|
|
10135
|
-
@
|
10136
|
-
*member_declarations.map { |memb| memb.identifier })
|
10137
|
-
end
|
10202
|
+
@tag_names.last.push(tag_name)
|
10138
10203
|
|
10139
|
-
|
10140
|
-
|
10141
|
-
return unless tag_id
|
10142
|
-
|
10143
|
-
@member_names.each do |identifier_array|
|
10144
|
-
if identifier_array.any? { |id| id.value == tag_id.value }
|
10145
|
-
W(:W0492, union_type_declaration.location, tag_id.value)
|
10146
|
-
break
|
10147
|
-
end
|
10148
|
-
end
|
10204
|
+
declare_members(struct_or_union_dcl)
|
10205
|
+
end
|
10149
10206
|
|
10150
|
-
|
10151
|
-
|
10207
|
+
def declare_members(struct_or_union_dcl)
|
10208
|
+
memb_dcls = MemberExtractor.new.tap { |ext|
|
10209
|
+
struct_or_union_dcl.accept(ext)
|
10152
10210
|
}.result
|
10153
10211
|
|
10154
|
-
|
10155
|
-
|
10156
|
-
|
10157
|
-
|
10212
|
+
memb_dcls.each do |memb_dcl|
|
10213
|
+
pair_names =
|
10214
|
+
(@dcl_names + @tag_names + @label_names).flatten.select { |id|
|
10215
|
+
id.value == memb_dcl.identifier.value
|
10158
10216
|
}
|
10159
|
-
|
10217
|
+
unless pair_names.empty?
|
10218
|
+
W(:W0492, memb_dcl.location, memb_dcl.identifier.value)
|
10219
|
+
pair_names.each do |pair_name|
|
10220
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10221
|
+
end
|
10160
10222
|
end
|
10161
|
-
end
|
10162
10223
|
|
10163
|
-
|
10164
|
-
|
10224
|
+
@memb_names.last.push(memb_dcl.identifier)
|
10225
|
+
end
|
10165
10226
|
end
|
10166
10227
|
|
10167
|
-
def declare_enum(
|
10168
|
-
|
10169
|
-
return unless
|
10228
|
+
def declare_enum(enum_dcl)
|
10229
|
+
tag_name = enum_dcl.identifier
|
10230
|
+
return unless tag_name
|
10170
10231
|
|
10171
|
-
@
|
10172
|
-
|
10173
|
-
|
10174
|
-
|
10232
|
+
pair_names = @memb_names.flatten.select { |id|
|
10233
|
+
id.value == tag_name.value
|
10234
|
+
}
|
10235
|
+
|
10236
|
+
unless pair_names.empty?
|
10237
|
+
W(:W0492, enum_dcl.location, tag_name.value)
|
10238
|
+
pair_names.each do |pair_name|
|
10239
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10175
10240
|
end
|
10176
10241
|
end
|
10177
10242
|
|
10178
|
-
@tag_names.last.push(
|
10243
|
+
@tag_names.last.push(tag_name)
|
10179
10244
|
end
|
10180
10245
|
|
10181
|
-
def declare_typedef(
|
10182
|
-
|
10246
|
+
def declare_typedef(typedef_dcl)
|
10247
|
+
dcl_name = typedef_dcl.identifier
|
10183
10248
|
|
10184
|
-
@
|
10185
|
-
|
10186
|
-
|
10187
|
-
|
10249
|
+
pair_names = @memb_names.flatten.select { |id|
|
10250
|
+
id.value == dcl_name.value
|
10251
|
+
}
|
10252
|
+
|
10253
|
+
unless pair_names.empty?
|
10254
|
+
W(:W0492, typedef_dcl.location, dcl_name.value)
|
10255
|
+
pair_names.each do |pair_name|
|
10256
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10188
10257
|
end
|
10189
10258
|
end
|
10190
10259
|
|
10191
|
-
@
|
10260
|
+
@dcl_names.last.push(dcl_name)
|
10192
10261
|
end
|
10193
10262
|
|
10194
|
-
def define_parameter(
|
10195
|
-
|
10196
|
-
return unless
|
10263
|
+
def define_parameter(param_def, *)
|
10264
|
+
dcl_name = param_def.identifier
|
10265
|
+
return unless dcl_name
|
10197
10266
|
|
10198
|
-
@
|
10199
|
-
|
10200
|
-
|
10201
|
-
|
10267
|
+
pair_names = @memb_names.flatten.select { |id|
|
10268
|
+
id.value == dcl_name.value
|
10269
|
+
}
|
10270
|
+
|
10271
|
+
unless pair_names.empty?
|
10272
|
+
W(:W0492, param_def.location, dcl_name.value)
|
10273
|
+
pair_names.each do |pair_name|
|
10274
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10202
10275
|
end
|
10203
10276
|
end
|
10204
10277
|
|
10205
|
-
@
|
10278
|
+
@dcl_names.last.push(dcl_name)
|
10206
10279
|
end
|
10207
10280
|
|
10208
|
-
def define_label(
|
10209
|
-
|
10281
|
+
def define_label(labeled_stmt)
|
10282
|
+
label_name = labeled_stmt.label
|
10210
10283
|
|
10211
|
-
@
|
10212
|
-
|
10213
|
-
|
10214
|
-
|
10284
|
+
pair_names = @memb_names.flatten.select { |id|
|
10285
|
+
id.value == label_name.value
|
10286
|
+
}
|
10287
|
+
|
10288
|
+
unless pair_names.empty?
|
10289
|
+
W(:W0492, labeled_stmt.location, label_name.value)
|
10290
|
+
pair_names.each do |pair_name|
|
10291
|
+
C(:C0001, pair_name.location, pair_name.value)
|
10215
10292
|
end
|
10216
10293
|
end
|
10217
10294
|
|
10218
|
-
@label_names.last.push(
|
10295
|
+
@label_names.last.push(label_name)
|
10219
10296
|
end
|
10220
10297
|
|
10221
|
-
def enter_scope(
|
10222
|
-
@
|
10298
|
+
def enter_scope(*)
|
10299
|
+
@dcl_names.push([])
|
10223
10300
|
@tag_names.push([])
|
10224
10301
|
@label_names.push([])
|
10225
|
-
@
|
10302
|
+
@memb_names.push([])
|
10226
10303
|
end
|
10227
10304
|
|
10228
|
-
def leave_scope(
|
10229
|
-
@
|
10305
|
+
def leave_scope(*)
|
10306
|
+
@dcl_names.pop
|
10230
10307
|
@tag_names.pop
|
10231
10308
|
@label_names.pop
|
10232
|
-
@
|
10309
|
+
@memb_names.pop
|
10233
10310
|
end
|
10234
10311
|
|
10235
10312
|
class MemberExtractor < C::SyntaxTreeVisitor
|
@@ -10241,16 +10318,16 @@ module CBuiltin #:nodoc:
|
|
10241
10318
|
|
10242
10319
|
def visit_struct_type_declaration(node)
|
10243
10320
|
if node.struct_declarations
|
10244
|
-
node.struct_declarations.each do |
|
10245
|
-
|
10321
|
+
node.struct_declarations.each do |struct_dcl|
|
10322
|
+
struct_dcl.accept(self)
|
10246
10323
|
end
|
10247
10324
|
end
|
10248
10325
|
end
|
10249
10326
|
|
10250
10327
|
def visit_union_type_declaration(node)
|
10251
10328
|
if node.struct_declarations
|
10252
|
-
node.struct_declarations.each do |
|
10253
|
-
|
10329
|
+
node.struct_declarations.each do |struct_dcl|
|
10330
|
+
struct_dcl.accept(self)
|
10254
10331
|
end
|
10255
10332
|
end
|
10256
10333
|
end
|
@@ -15507,39 +15584,66 @@ module CBuiltin #:nodoc:
|
|
15507
15584
|
interp.on_enum_declared += method(:declare_enum)
|
15508
15585
|
interp.on_block_started += method(:enter_scope)
|
15509
15586
|
interp.on_block_ended += method(:leave_scope)
|
15510
|
-
@tag_names = [
|
15587
|
+
@tag_names = [[]]
|
15511
15588
|
end
|
15512
15589
|
|
15513
15590
|
private
|
15514
|
-
def declare_struct(
|
15515
|
-
tag_name =
|
15516
|
-
|
15517
|
-
|
15591
|
+
def declare_struct(struct_dcl)
|
15592
|
+
tag_name = struct_dcl.identifier
|
15593
|
+
|
15594
|
+
pair_names = @tag_names.flatten.select { |id|
|
15595
|
+
id.value == tag_name.value
|
15596
|
+
}
|
15597
|
+
|
15598
|
+
unless pair_names.empty?
|
15599
|
+
W(:W0703, struct_dcl.location, tag_name.value)
|
15600
|
+
pair_names.each do |pair_name|
|
15601
|
+
C(:C0001, pair_name.location, pair_name.value)
|
15602
|
+
end
|
15518
15603
|
end
|
15519
|
-
|
15604
|
+
|
15605
|
+
@tag_names.last.push(tag_name)
|
15520
15606
|
end
|
15521
15607
|
|
15522
|
-
def declare_union(
|
15523
|
-
tag_name =
|
15524
|
-
|
15525
|
-
|
15608
|
+
def declare_union(union_dcl)
|
15609
|
+
tag_name = union_dcl.identifier
|
15610
|
+
|
15611
|
+
pair_names = @tag_names.flatten.select { |id|
|
15612
|
+
id.value == tag_name.value
|
15613
|
+
}
|
15614
|
+
|
15615
|
+
unless pair_names.empty?
|
15616
|
+
W(:W0703, union_dcl.location, tag_name.value)
|
15617
|
+
pair_names.each do |pair_name|
|
15618
|
+
C(:C0001, pair_name.location, pair_name.value)
|
15619
|
+
end
|
15526
15620
|
end
|
15527
|
-
|
15621
|
+
|
15622
|
+
@tag_names.last.push(tag_name)
|
15528
15623
|
end
|
15529
15624
|
|
15530
|
-
def declare_enum(
|
15531
|
-
tag_name =
|
15532
|
-
|
15533
|
-
|
15625
|
+
def declare_enum(enum_dcl)
|
15626
|
+
tag_name = enum_dcl.identifier
|
15627
|
+
|
15628
|
+
pair_names = @tag_names.flatten.select { |id|
|
15629
|
+
id.value == tag_name.value
|
15630
|
+
}
|
15631
|
+
|
15632
|
+
unless pair_names.empty?
|
15633
|
+
W(:W0703, enum_dcl.location, tag_name.value)
|
15634
|
+
pair_names.each do |pair_name|
|
15635
|
+
C(:C0001, pair_name.location, pair_name.value)
|
15636
|
+
end
|
15534
15637
|
end
|
15535
|
-
|
15638
|
+
|
15639
|
+
@tag_names.last.push(tag_name)
|
15536
15640
|
end
|
15537
15641
|
|
15538
|
-
def enter_scope(
|
15539
|
-
@tag_names.push(
|
15642
|
+
def enter_scope(*)
|
15643
|
+
@tag_names.push([])
|
15540
15644
|
end
|
15541
15645
|
|
15542
|
-
def leave_scope(
|
15646
|
+
def leave_scope(*)
|
15543
15647
|
@tag_names.pop
|
15544
15648
|
end
|
15545
15649
|
end
|
@@ -15563,115 +15667,178 @@ module CBuiltin #:nodoc:
|
|
15563
15667
|
interp.on_parameter_defined += method(:define_parameter)
|
15564
15668
|
interp.on_block_started += method(:enter_scope)
|
15565
15669
|
interp.on_block_ended += method(:leave_scope)
|
15566
|
-
@vdcls = [
|
15567
|
-
@vdefs = [
|
15568
|
-
@fdcls = [
|
15569
|
-
@fdefs = [
|
15570
|
-
@tdefs = [
|
15571
|
-
@enums = [
|
15670
|
+
@vdcls = [[]]
|
15671
|
+
@vdefs = [[]]
|
15672
|
+
@fdcls = [[]]
|
15673
|
+
@fdefs = [[]]
|
15674
|
+
@tdefs = [[]]
|
15675
|
+
@enums = [[]]
|
15572
15676
|
end
|
15573
15677
|
|
15574
15678
|
private
|
15575
|
-
def define_variable(
|
15576
|
-
|
15577
|
-
|
15578
|
-
|
15679
|
+
def define_variable(var_def, *)
|
15680
|
+
dcl_name = var_def.identifier
|
15681
|
+
|
15682
|
+
pair_names = wider_identifiers_of_variable_definition.select { |id|
|
15683
|
+
id.value == dcl_name.value
|
15684
|
+
}
|
15685
|
+
|
15686
|
+
unless pair_names.empty?
|
15687
|
+
W(:W0704, var_def.location, dcl_name.value)
|
15688
|
+
pair_names.each do |pair_name|
|
15689
|
+
C(:C0001, pair_name.location, pair_name.value)
|
15690
|
+
end
|
15579
15691
|
end
|
15580
|
-
|
15692
|
+
|
15693
|
+
@vdefs.last.push(dcl_name)
|
15581
15694
|
end
|
15582
15695
|
|
15583
15696
|
def wider_identifiers_of_variable_definition
|
15584
15697
|
(@vdcls[0..-2] + @vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] +
|
15585
|
-
@tdefs[0..-2] + @enums[0..-2]).
|
15698
|
+
@tdefs[0..-2] + @enums[0..-2]).flatten
|
15586
15699
|
end
|
15587
15700
|
|
15588
|
-
def declare_function(
|
15589
|
-
|
15590
|
-
|
15591
|
-
|
15701
|
+
def declare_function(func_dcl, *)
|
15702
|
+
dcl_name = func_dcl.identifier
|
15703
|
+
|
15704
|
+
pair_names = wider_identifiers_of_function_declaration.select { |id|
|
15705
|
+
id.value == dcl_name.value
|
15706
|
+
}
|
15707
|
+
|
15708
|
+
unless pair_names.empty?
|
15709
|
+
W(:W0704, func_dcl.location, dcl_name.value)
|
15710
|
+
pair_names.each do |pair_name|
|
15711
|
+
C(:C0001, pair_name.location, pair_name.value)
|
15712
|
+
end
|
15592
15713
|
end
|
15593
|
-
|
15714
|
+
|
15715
|
+
@fdcls.last.push(dcl_name)
|
15594
15716
|
end
|
15595
15717
|
|
15596
15718
|
def wider_identifiers_of_function_declaration
|
15597
15719
|
(@vdcls[0..-2] + @vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] +
|
15598
|
-
@tdefs[0..-2] + @enums[0..-2]).
|
15720
|
+
@tdefs[0..-2] + @enums[0..-2]).flatten
|
15599
15721
|
end
|
15600
15722
|
|
15601
|
-
def declare_variable(
|
15602
|
-
|
15603
|
-
|
15604
|
-
|
15723
|
+
def declare_variable(var_dcl, *)
|
15724
|
+
dcl_name = var_dcl.identifier
|
15725
|
+
|
15726
|
+
pair_names = wider_identifiers_of_variable_declaration.select { |id|
|
15727
|
+
id.value == dcl_name.value
|
15728
|
+
}
|
15729
|
+
|
15730
|
+
unless pair_names.empty?
|
15731
|
+
W(:W0704, var_dcl.location, dcl_name.value)
|
15732
|
+
pair_names.each do |pair_name|
|
15733
|
+
C(:C0001, pair_name.location, pair_name.value)
|
15734
|
+
end
|
15605
15735
|
end
|
15606
|
-
|
15736
|
+
|
15737
|
+
@vdcls.last.push(dcl_name)
|
15607
15738
|
end
|
15608
15739
|
|
15609
15740
|
def wider_identifiers_of_variable_declaration
|
15610
15741
|
(@vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] + @tdefs[0..-2] +
|
15611
|
-
@enums[0..-2]).
|
15742
|
+
@enums[0..-2]).flatten
|
15612
15743
|
end
|
15613
15744
|
|
15614
|
-
def declare_enum(
|
15615
|
-
|
15616
|
-
|
15617
|
-
|
15618
|
-
|
15745
|
+
def declare_enum(enum_dcl)
|
15746
|
+
enum_dcl.enumerators.each do |enum|
|
15747
|
+
enum_name = enum.identifier
|
15748
|
+
|
15749
|
+
pair_names = wider_identifiers_of_enum_declaration.select { |id|
|
15750
|
+
id.value == enum_name.value
|
15751
|
+
}
|
15752
|
+
|
15753
|
+
unless pair_names.empty?
|
15754
|
+
W(:W0704, enum.location, enum_name.value)
|
15755
|
+
pair_names.each do |pair_name|
|
15756
|
+
C(:C0001, pair_name.location, pair_name.value)
|
15757
|
+
end
|
15619
15758
|
end
|
15620
|
-
|
15759
|
+
|
15760
|
+
@enums.last.push(enum_name)
|
15621
15761
|
end
|
15622
15762
|
end
|
15623
15763
|
|
15624
15764
|
def wider_identifiers_of_enum_declaration
|
15625
15765
|
(@vdcls[0..-2] + @vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] +
|
15626
|
-
@tdefs[0..-2] + @enums[0..-2]).
|
15766
|
+
@tdefs[0..-2] + @enums[0..-2]).flatten
|
15627
15767
|
end
|
15628
15768
|
|
15629
|
-
def declare_typedef(
|
15630
|
-
|
15631
|
-
|
15632
|
-
|
15769
|
+
def declare_typedef(typedef_dcl)
|
15770
|
+
dcl_name = typedef_dcl.identifier
|
15771
|
+
|
15772
|
+
pair_names = wider_identifiers_of_typedef_declaration.select { |id|
|
15773
|
+
id.value == dcl_name.value
|
15774
|
+
}
|
15775
|
+
|
15776
|
+
unless pair_names.empty?
|
15777
|
+
W(:W0704, typedef_dcl.location, dcl_name.value)
|
15778
|
+
pair_names.each do |pair_name|
|
15779
|
+
C(:C0001, pair_name.location, pair_name.value)
|
15780
|
+
end
|
15633
15781
|
end
|
15634
|
-
|
15782
|
+
|
15783
|
+
@enums.last.push(dcl_name)
|
15635
15784
|
end
|
15636
15785
|
|
15637
15786
|
def wider_identifiers_of_typedef_declaration
|
15638
15787
|
(@vdcls[0..-2] + @vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] +
|
15639
|
-
@tdefs[0..-2] + @enums[0..-2]).
|
15788
|
+
@tdefs[0..-2] + @enums[0..-2]).flatten
|
15640
15789
|
end
|
15641
15790
|
|
15642
|
-
def define_function(
|
15643
|
-
|
15644
|
-
|
15645
|
-
|
15791
|
+
def define_function(func_def, *)
|
15792
|
+
dcl_name = func_def.identifier
|
15793
|
+
|
15794
|
+
pair_names = wider_identifiers_of_function_definition.select { |id|
|
15795
|
+
id.value == dcl_name.value
|
15796
|
+
}
|
15797
|
+
|
15798
|
+
unless pair_names.empty?
|
15799
|
+
W(:W0704, func_def.location, dcl_name.value)
|
15800
|
+
pair_names.each do |pair_name|
|
15801
|
+
C(:C0001, pair_name.location, pair_name.value)
|
15802
|
+
end
|
15646
15803
|
end
|
15647
|
-
|
15804
|
+
|
15805
|
+
@fdefs.last.push(dcl_name)
|
15648
15806
|
end
|
15649
15807
|
|
15650
15808
|
def wider_identifiers_of_function_definition
|
15651
15809
|
(@vdcls[0..-2] + @vdefs[0..-2] + @fdefs[0..-2] + @tdefs[0..-2] +
|
15652
|
-
@enums[0..-2]).
|
15810
|
+
@enums[0..-2]).flatten
|
15653
15811
|
end
|
15654
15812
|
|
15655
|
-
def define_parameter(
|
15656
|
-
|
15657
|
-
|
15658
|
-
|
15813
|
+
def define_parameter(param_def, *)
|
15814
|
+
dcl_name = param_def.identifier
|
15815
|
+
|
15816
|
+
pair_names = wider_identifiers_of_parameter_definition.select { |id|
|
15817
|
+
id.value == dcl_name.value
|
15818
|
+
}
|
15819
|
+
|
15820
|
+
unless pair_names.empty?
|
15821
|
+
W(:W0704, param_def.location, dcl_name.value)
|
15822
|
+
pair_names.each do |pair_name|
|
15823
|
+
C(:C0001, pair_name.location, pair_name.value)
|
15824
|
+
end
|
15659
15825
|
end
|
15660
|
-
|
15826
|
+
|
15827
|
+
@vdefs.last.push(dcl_name)
|
15661
15828
|
end
|
15662
15829
|
|
15663
15830
|
def wider_identifiers_of_parameter_definition
|
15664
15831
|
(@vdcls[0..-2] + @vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] +
|
15665
|
-
@tdefs[0..-2] + @enums[0..-2]).
|
15832
|
+
@tdefs[0..-2] + @enums[0..-2]).flatten
|
15666
15833
|
end
|
15667
15834
|
|
15668
15835
|
def enter_scope(compound_statement)
|
15669
|
-
@vdcls.push(
|
15670
|
-
@vdefs.push(
|
15671
|
-
@fdcls.push(
|
15672
|
-
@fdefs.push(
|
15673
|
-
@tdefs.push(
|
15674
|
-
@enums.push(
|
15836
|
+
@vdcls.push([])
|
15837
|
+
@vdefs.push([])
|
15838
|
+
@fdcls.push([])
|
15839
|
+
@fdefs.push([])
|
15840
|
+
@tdefs.push([])
|
15841
|
+
@enums.push([])
|
15675
15842
|
end
|
15676
15843
|
|
15677
15844
|
def leave_scope(compound_statement)
|
@@ -17487,7 +17654,7 @@ module CBuiltin #:nodoc:
|
|
17487
17654
|
|
17488
17655
|
private
|
17489
17656
|
def from_type
|
17490
|
-
@interp.
|
17657
|
+
@interp.signed_short_type
|
17491
17658
|
end
|
17492
17659
|
|
17493
17660
|
def to_type
|
@@ -17521,7 +17688,7 @@ module CBuiltin #:nodoc:
|
|
17521
17688
|
|
17522
17689
|
private
|
17523
17690
|
def from_type
|
17524
|
-
@interp.
|
17691
|
+
@interp.signed_int_type
|
17525
17692
|
end
|
17526
17693
|
|
17527
17694
|
def to_type
|
@@ -17538,11 +17705,11 @@ module CBuiltin #:nodoc:
|
|
17538
17705
|
|
17539
17706
|
private
|
17540
17707
|
def from_type
|
17541
|
-
@interp.
|
17708
|
+
@interp.signed_int_type
|
17542
17709
|
end
|
17543
17710
|
|
17544
17711
|
def to_type
|
17545
|
-
@interp.
|
17712
|
+
@interp.signed_short_type
|
17546
17713
|
end
|
17547
17714
|
end
|
17548
17715
|
|
@@ -17589,7 +17756,7 @@ module CBuiltin #:nodoc:
|
|
17589
17756
|
|
17590
17757
|
private
|
17591
17758
|
def from_type
|
17592
|
-
@interp.
|
17759
|
+
@interp.signed_long_type
|
17593
17760
|
end
|
17594
17761
|
|
17595
17762
|
def to_type
|
@@ -17606,11 +17773,11 @@ module CBuiltin #:nodoc:
|
|
17606
17773
|
|
17607
17774
|
private
|
17608
17775
|
def from_type
|
17609
|
-
@interp.
|
17776
|
+
@interp.signed_long_type
|
17610
17777
|
end
|
17611
17778
|
|
17612
17779
|
def to_type
|
17613
|
-
@interp.
|
17780
|
+
@interp.signed_short_type
|
17614
17781
|
end
|
17615
17782
|
end
|
17616
17783
|
|
@@ -17623,11 +17790,11 @@ module CBuiltin #:nodoc:
|
|
17623
17790
|
|
17624
17791
|
private
|
17625
17792
|
def from_type
|
17626
|
-
@interp.
|
17793
|
+
@interp.signed_long_type
|
17627
17794
|
end
|
17628
17795
|
|
17629
17796
|
def to_type
|
17630
|
-
@interp.
|
17797
|
+
@interp.signed_int_type
|
17631
17798
|
end
|
17632
17799
|
end
|
17633
17800
|
|
@@ -17691,7 +17858,7 @@ module CBuiltin #:nodoc:
|
|
17691
17858
|
|
17692
17859
|
private
|
17693
17860
|
def from_type
|
17694
|
-
@interp.
|
17861
|
+
@interp.signed_long_long_type
|
17695
17862
|
end
|
17696
17863
|
|
17697
17864
|
def to_type
|
@@ -17708,11 +17875,11 @@ module CBuiltin #:nodoc:
|
|
17708
17875
|
|
17709
17876
|
private
|
17710
17877
|
def from_type
|
17711
|
-
@interp.
|
17878
|
+
@interp.signed_long_long_type
|
17712
17879
|
end
|
17713
17880
|
|
17714
17881
|
def to_type
|
17715
|
-
@interp.
|
17882
|
+
@interp.signed_short_type
|
17716
17883
|
end
|
17717
17884
|
end
|
17718
17885
|
|
@@ -17725,11 +17892,11 @@ module CBuiltin #:nodoc:
|
|
17725
17892
|
|
17726
17893
|
private
|
17727
17894
|
def from_type
|
17728
|
-
@interp.
|
17895
|
+
@interp.signed_long_long_type
|
17729
17896
|
end
|
17730
17897
|
|
17731
17898
|
def to_type
|
17732
|
-
@interp.
|
17899
|
+
@interp.signed_int_type
|
17733
17900
|
end
|
17734
17901
|
end
|
17735
17902
|
|
@@ -17742,11 +17909,11 @@ module CBuiltin #:nodoc:
|
|
17742
17909
|
|
17743
17910
|
private
|
17744
17911
|
def from_type
|
17745
|
-
@interp.
|
17912
|
+
@interp.signed_long_long_type
|
17746
17913
|
end
|
17747
17914
|
|
17748
17915
|
def to_type
|
17749
|
-
@interp.
|
17916
|
+
@interp.signed_long_type
|
17750
17917
|
end
|
17751
17918
|
end
|
17752
17919
|
|
@@ -17882,42 +18049,33 @@ module CBuiltin #:nodoc:
|
|
17882
18049
|
interp.on_variable_declared += method(:declare_variable)
|
17883
18050
|
interp.on_function_declared += method(:declare_function)
|
17884
18051
|
interp.on_translation_unit_ended += method(:check)
|
17885
|
-
@
|
17886
|
-
@function_declarations = Hash.new { |hash, key| hash[key] = [] }
|
18052
|
+
@obj_dcls = Hash.new { |hash, key| hash[key] = [] }
|
17887
18053
|
end
|
17888
18054
|
|
17889
18055
|
private
|
17890
|
-
def declare_variable(
|
17891
|
-
if
|
17892
|
-
@
|
18056
|
+
def declare_variable(var_dcl, var)
|
18057
|
+
if var.named? && var.declared_as_extern?
|
18058
|
+
@obj_dcls[var.name].push(var_dcl)
|
17893
18059
|
end
|
17894
18060
|
end
|
17895
18061
|
|
17896
|
-
def declare_function(
|
17897
|
-
if
|
17898
|
-
@
|
18062
|
+
def declare_function(func_dcl, func)
|
18063
|
+
if func.named? && func.declared_as_extern?
|
18064
|
+
@obj_dcls[func.name].push(func_dcl)
|
17899
18065
|
end
|
17900
18066
|
end
|
17901
18067
|
|
17902
18068
|
def check(*)
|
17903
|
-
@
|
17904
|
-
|
17905
|
-
|
17906
|
-
|
17907
|
-
|
17908
|
-
|
17909
|
-
|
17910
|
-
|
17911
|
-
|
17912
|
-
|
17913
|
-
|
17914
|
-
@function_declarations.each_value do |declarations|
|
17915
|
-
decl_locations = declarations.map { |decl|
|
17916
|
-
decl.location
|
17917
|
-
}.uniq { |location| location.fpath }
|
17918
|
-
if decl_locations.size > 1
|
17919
|
-
decl_locations.each do |location|
|
17920
|
-
W(:W0771, location, declarations.first.identifier.value)
|
18069
|
+
@obj_dcls.each_value do |dcls|
|
18070
|
+
similar_dcls = dcls.uniq { |dcl| dcl.location.fpath }
|
18071
|
+
next unless similar_dcls.size > 1
|
18072
|
+
|
18073
|
+
similar_dcls.each do |dcl|
|
18074
|
+
W(:W0771, dcl.location, dcl.identifier.value)
|
18075
|
+
similar_dcls.each do |pair_dcl|
|
18076
|
+
if pair_dcl != dcl
|
18077
|
+
C(:C0001, pair_dcl.location, pair_dcl.identifier.value)
|
18078
|
+
end
|
17921
18079
|
end
|
17922
18080
|
end
|
17923
18081
|
end
|
@@ -17993,36 +18151,34 @@ module CBuiltin #:nodoc:
|
|
17993
18151
|
end
|
17994
18152
|
|
17995
18153
|
private
|
17996
|
-
def check(
|
17997
|
-
|
17998
|
-
|
17999
|
-
|
18000
|
-
|
18001
|
-
|
18002
|
-
|
18003
|
-
|
18004
|
-
W(message_id, expression.location)
|
18154
|
+
def check(*, orig_var, result_var)
|
18155
|
+
if @rvalues && orig_var.type.floating?
|
18156
|
+
case expr = @rvalues[orig_var]
|
18157
|
+
when C::AdditiveExpression, C::MultiplicativeExpression
|
18158
|
+
if orig_var.type.same_as?(from_type) &&
|
18159
|
+
result_var.type.same_as?(to_type)
|
18160
|
+
W(message_id, expr.location)
|
18161
|
+
end
|
18005
18162
|
end
|
18006
18163
|
end
|
18007
18164
|
end
|
18008
18165
|
|
18009
|
-
def clear_rvalues(
|
18166
|
+
def clear_rvalues(*)
|
18010
18167
|
@rvalues = {}
|
18011
18168
|
end
|
18012
18169
|
|
18013
|
-
def handle_additive(
|
18014
|
-
|
18015
|
-
memorize_rvalue_derivation(result_variable, additive_expression)
|
18170
|
+
def handle_additive(expr, lhs_var, rhs_var, result_var)
|
18171
|
+
memorize_rvalue_derivation(result_var, expr)
|
18016
18172
|
end
|
18017
18173
|
|
18018
|
-
def handle_multiplicative(
|
18019
|
-
|
18020
|
-
|
18021
|
-
|
18174
|
+
def handle_multiplicative(expr, lhs_var, rhs_var, result_var)
|
18175
|
+
unless expr.operator.type == "%"
|
18176
|
+
memorize_rvalue_derivation(result_var, expr)
|
18177
|
+
end
|
18022
18178
|
end
|
18023
18179
|
|
18024
|
-
def memorize_rvalue_derivation(rvalue_holder,
|
18025
|
-
@rvalues[rvalue_holder] =
|
18180
|
+
def memorize_rvalue_derivation(rvalue_holder, expr)
|
18181
|
+
@rvalues[rvalue_holder] = expr if @rvalues
|
18026
18182
|
end
|
18027
18183
|
|
18028
18184
|
def from_type
|
@@ -18238,131 +18394,140 @@ module CBuiltin #:nodoc:
|
|
18238
18394
|
interp.on_function_defined += method(:check_object_declaration)
|
18239
18395
|
interp.on_typedef_declared += method(:check_typedef_declaration)
|
18240
18396
|
interp.on_enum_declared += method(:check_enum_declaration)
|
18241
|
-
interp.on_block_started += method(:
|
18242
|
-
interp.on_block_ended += method(:
|
18397
|
+
interp.on_block_started += method(:enter_scope)
|
18398
|
+
interp.on_block_ended += method(:leave_scope)
|
18243
18399
|
|
18244
|
-
@
|
18245
|
-
@
|
18246
|
-
@
|
18400
|
+
@obj_dcls = [Hash.new { |hash, key| hash[key] = [] }]
|
18401
|
+
@typedef_dcls = [Hash.new { |hash, key| hash[key] = [] }]
|
18402
|
+
@enum_names = [Hash.new { |hash, key| hash[key] = [] }]
|
18247
18403
|
|
18248
|
-
@
|
18249
|
-
@
|
18250
|
-
@
|
18404
|
+
@obj_dcls_in_other_scope = Hash.new { |hash, key| hash[key] = [] }
|
18405
|
+
@typedef_dcls_in_other_scope = Hash.new { |hash, key| hash[key] = [] }
|
18406
|
+
@enum_names_in_other_scope = Hash.new { |hash, key| hash[key] = [] }
|
18251
18407
|
end
|
18252
18408
|
|
18253
18409
|
private
|
18254
|
-
def check_object_declaration(
|
18255
|
-
return unless
|
18410
|
+
def check_object_declaration(obj_dcl, obj)
|
18411
|
+
return unless obj.declared_as_extern?
|
18256
18412
|
|
18257
|
-
name =
|
18258
|
-
type =
|
18413
|
+
name = obj_dcl.identifier.value
|
18414
|
+
type = obj_dcl.type
|
18259
18415
|
|
18260
|
-
|
18261
|
-
|
18262
|
-
|
18263
|
-
|
18416
|
+
same_name_obj_dcls = @obj_dcls_in_other_scope[name]
|
18417
|
+
incompatibles = same_name_obj_dcls.select { |dcl| dcl.type != type }
|
18418
|
+
unless incompatibles.empty?
|
18419
|
+
W(:W0787, obj_dcl.location, name)
|
18420
|
+
incompatibles.each do |same_name_dcl|
|
18421
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18422
|
+
end
|
18264
18423
|
end
|
18265
18424
|
|
18266
|
-
|
18267
|
-
unless
|
18268
|
-
W(:W0787,
|
18269
|
-
|
18425
|
+
same_name_typedef_dcls = @typedef_dcls_in_other_scope[name]
|
18426
|
+
unless same_name_typedef_dcls.empty?
|
18427
|
+
W(:W0787, obj_dcl.location, name)
|
18428
|
+
same_name_typedef_dcls.each do |same_name_dcl|
|
18429
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18430
|
+
end
|
18270
18431
|
end
|
18271
18432
|
|
18272
|
-
|
18273
|
-
unless
|
18274
|
-
W(:W0787,
|
18275
|
-
|
18276
|
-
|
18277
|
-
|
18278
|
-
unless @object_decls_stack.empty?
|
18279
|
-
@object_decls_stack.last[name].push(declaration_or_definition)
|
18433
|
+
same_name_enums = @enum_names_in_other_scope[name]
|
18434
|
+
unless same_name_enums.empty?
|
18435
|
+
W(:W0787, obj_dcl.location, name)
|
18436
|
+
same_name_enums.each do |same_name_enum|
|
18437
|
+
C(:C0001, same_name_enum.location, same_name_enum.identifier.value)
|
18438
|
+
end
|
18280
18439
|
end
|
18440
|
+
|
18441
|
+
@obj_dcls.last[name].push(obj_dcl)
|
18281
18442
|
end
|
18282
18443
|
|
18283
|
-
def check_typedef_declaration(
|
18284
|
-
name =
|
18285
|
-
type =
|
18444
|
+
def check_typedef_declaration(typedef_dcl)
|
18445
|
+
name = typedef_dcl.identifier.value
|
18446
|
+
type = typedef_dcl.type
|
18286
18447
|
|
18287
|
-
|
18288
|
-
unless
|
18289
|
-
W(:W0787,
|
18290
|
-
|
18448
|
+
same_name_obj_dcls = @obj_dcls_in_other_scope[name]
|
18449
|
+
unless same_name_obj_dcls.empty?
|
18450
|
+
W(:W0787, typedef_dcl.location, name)
|
18451
|
+
same_name_obj_dcls.each do |same_name_dcl|
|
18452
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18453
|
+
end
|
18291
18454
|
end
|
18292
18455
|
|
18293
|
-
|
18294
|
-
|
18295
|
-
|
18296
|
-
|
18456
|
+
same_name_typedef_dcls = @typedef_dcls_in_other_scope[name]
|
18457
|
+
incompatibles = same_name_typedef_dcls.select { |dcl| dcl.type != type }
|
18458
|
+
unless incompatibles.empty?
|
18459
|
+
W(:W0787, typedef_dcl.location, name)
|
18460
|
+
incompatibles.each do |same_name_dcl|
|
18461
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18462
|
+
end
|
18297
18463
|
end
|
18298
18464
|
|
18299
|
-
|
18300
|
-
unless
|
18301
|
-
W(:W0787,
|
18302
|
-
|
18303
|
-
|
18304
|
-
|
18305
|
-
unless @typedef_decls_stack.empty?
|
18306
|
-
@typedef_decls_stack.last[name].push(typedef_declaration)
|
18465
|
+
same_name_enums = @enum_names_in_other_scope[name]
|
18466
|
+
unless same_name_enums.empty?
|
18467
|
+
W(:W0787, typedef_dcl.location, name)
|
18468
|
+
same_name_enums.each do |same_name_enum|
|
18469
|
+
C(:C0001, same_name_enum.location, same_name_enum.identifier.value)
|
18470
|
+
end
|
18307
18471
|
end
|
18472
|
+
|
18473
|
+
@typedef_dcls.last[name].push(typedef_dcl)
|
18308
18474
|
end
|
18309
18475
|
|
18310
|
-
def check_enum_declaration(
|
18311
|
-
|
18476
|
+
def check_enum_declaration(enum_dcl)
|
18477
|
+
enum_dcl.enumerators.each { |enum| check_enumerator(enum) }
|
18312
18478
|
end
|
18313
18479
|
|
18314
|
-
def check_enumerator(
|
18315
|
-
name =
|
18480
|
+
def check_enumerator(enum)
|
18481
|
+
name = enum.identifier.value
|
18316
18482
|
|
18317
|
-
|
18318
|
-
unless
|
18319
|
-
W(:W0787,
|
18320
|
-
|
18483
|
+
same_name_obj_dcls = @obj_dcls_in_other_scope[name]
|
18484
|
+
unless same_name_obj_dcls.empty?
|
18485
|
+
W(:W0787, enum.location, name)
|
18486
|
+
same_name_obj_dcls.each do |same_name_dcl|
|
18487
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18488
|
+
end
|
18321
18489
|
end
|
18322
18490
|
|
18323
|
-
|
18324
|
-
unless
|
18325
|
-
W(:W0787,
|
18326
|
-
|
18491
|
+
same_name_typedef_dcls = @typedef_dcls_in_other_scope[name]
|
18492
|
+
unless same_name_typedef_dcls.empty?
|
18493
|
+
W(:W0787, enum.location, name)
|
18494
|
+
same_name_typedef_dcls.each do |same_name_dcl|
|
18495
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18496
|
+
end
|
18327
18497
|
end
|
18328
18498
|
|
18329
|
-
|
18330
|
-
unless
|
18331
|
-
W(:W0787,
|
18332
|
-
|
18333
|
-
|
18334
|
-
|
18335
|
-
unless @enumerators_stack.empty?
|
18336
|
-
@enumerators_stack.last[name] += 1
|
18499
|
+
same_name_enums = @enum_names_in_other_scope[name]
|
18500
|
+
unless same_name_enums.empty?
|
18501
|
+
W(:W0787, enum.location, name)
|
18502
|
+
same_name_enums.each do |same_name_enum|
|
18503
|
+
C(:C0001, same_name_enum.location, same_name_enum.identifier.value)
|
18504
|
+
end
|
18337
18505
|
end
|
18506
|
+
|
18507
|
+
@enum_names.last[name].push(enum)
|
18338
18508
|
end
|
18339
18509
|
|
18340
|
-
def
|
18341
|
-
@
|
18342
|
-
@
|
18343
|
-
@
|
18510
|
+
def enter_scope(*)
|
18511
|
+
@obj_dcls.push(Hash.new { |hash, key| hash[key] = [] })
|
18512
|
+
@typedef_dcls.push(Hash.new { |hash, key| hash[key] = [] })
|
18513
|
+
@enum_names.push(Hash.new { |hash, key| hash[key] = [] })
|
18344
18514
|
end
|
18345
18515
|
|
18346
|
-
def
|
18347
|
-
|
18348
|
-
@
|
18349
|
-
@object_decls_in_other_scope[name].concat(decls)
|
18350
|
-
end
|
18351
|
-
@object_decls_stack.pop
|
18516
|
+
def leave_scope(*)
|
18517
|
+
@obj_dcls.last.each do |name, dcls|
|
18518
|
+
@obj_dcls_in_other_scope[name].concat(dcls)
|
18352
18519
|
end
|
18520
|
+
@obj_dcls.pop
|
18353
18521
|
|
18354
|
-
|
18355
|
-
@
|
18356
|
-
@typedef_decls_in_other_scope[name].concat(decls)
|
18357
|
-
end
|
18358
|
-
@typedef_decls_stack.pop
|
18522
|
+
@typedef_dcls.last.each do |name, dcls|
|
18523
|
+
@typedef_dcls_in_other_scope[name].concat(dcls)
|
18359
18524
|
end
|
18525
|
+
@typedef_dcls.pop
|
18360
18526
|
|
18361
|
-
|
18362
|
-
@
|
18363
|
-
@enumerators_in_other_scope[name] += decl_num
|
18364
|
-
end
|
18527
|
+
@enum_names.last.each do |name, enums|
|
18528
|
+
@enum_names_in_other_scope[name].concat(enums)
|
18365
18529
|
end
|
18530
|
+
@enum_names.pop
|
18366
18531
|
end
|
18367
18532
|
end
|
18368
18533
|
|
@@ -18382,127 +18547,123 @@ module CBuiltin #:nodoc:
|
|
18382
18547
|
interp.on_function_defined += method(:check_object_declaration)
|
18383
18548
|
interp.on_typedef_declared += method(:check_typedef_declaration)
|
18384
18549
|
interp.on_enum_declared += method(:check_enum_declaration)
|
18385
|
-
interp.on_block_started += method(:
|
18386
|
-
interp.on_block_ended += method(:
|
18550
|
+
interp.on_block_started += method(:enter_scope)
|
18551
|
+
interp.on_block_ended += method(:leave_scope)
|
18387
18552
|
|
18388
|
-
@
|
18389
|
-
@
|
18390
|
-
@
|
18553
|
+
@obj_dcls = [Hash.new { |hash, key| hash[key] = [] }]
|
18554
|
+
@typedef_dcls = [Hash.new { |hash, key| hash[key] = [] }]
|
18555
|
+
@enum_names = [Hash.new { |hash, key| hash[key] = [] }]
|
18391
18556
|
end
|
18392
18557
|
|
18393
18558
|
private
|
18394
|
-
def check_object_declaration(
|
18395
|
-
name =
|
18396
|
-
type =
|
18559
|
+
def check_object_declaration(obj_dcl, *)
|
18560
|
+
name = obj_dcl.identifier.value
|
18561
|
+
type = obj_dcl.type
|
18397
18562
|
|
18398
|
-
|
18399
|
-
|
18400
|
-
|
18401
|
-
|
18402
|
-
|
18563
|
+
same_name_obj_dcls = @obj_dcls.last[name]
|
18564
|
+
incompatibles = same_name_obj_dcls.select { |dcl| dcl.type != type }
|
18565
|
+
unless incompatibles.empty?
|
18566
|
+
W(:W0788, obj_dcl.location, name)
|
18567
|
+
incompatibles.each do |same_name_dcl|
|
18568
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18403
18569
|
end
|
18404
18570
|
end
|
18405
18571
|
|
18406
|
-
|
18407
|
-
|
18408
|
-
|
18409
|
-
|
18410
|
-
|
18572
|
+
same_name_typedef_dcls = @typedef_dcls.last[name]
|
18573
|
+
unless same_name_typedef_dcls.empty?
|
18574
|
+
W(:W0788, obj_dcl.location, name)
|
18575
|
+
same_name_typedef_dcls.each do |same_name_dcl|
|
18576
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18411
18577
|
end
|
18412
18578
|
end
|
18413
18579
|
|
18414
|
-
|
18415
|
-
|
18416
|
-
|
18417
|
-
|
18418
|
-
|
18580
|
+
same_name_enums = @enum_names.last[name]
|
18581
|
+
unless same_name_enums.empty?
|
18582
|
+
W(:W0788, obj_dcl.location, name)
|
18583
|
+
same_name_enums.each do |same_name_enum|
|
18584
|
+
C(:C0001, same_name_enum.location, same_name_enum.identifier.value)
|
18419
18585
|
end
|
18420
18586
|
end
|
18421
|
-
|
18422
|
-
|
18423
|
-
@object_decls_stack.last[name].push(declaration_or_definition)
|
18424
|
-
end
|
18587
|
+
|
18588
|
+
@obj_dcls.last[name].push(obj_dcl)
|
18425
18589
|
end
|
18426
18590
|
|
18427
|
-
def check_typedef_declaration(
|
18428
|
-
name =
|
18429
|
-
type =
|
18591
|
+
def check_typedef_declaration(typedef_dcl)
|
18592
|
+
name = typedef_dcl.identifier.value
|
18593
|
+
type = typedef_dcl.type
|
18430
18594
|
|
18431
|
-
|
18432
|
-
|
18433
|
-
|
18434
|
-
|
18435
|
-
|
18595
|
+
same_name_obj_dcls = @obj_dcls.last[name]
|
18596
|
+
unless same_name_obj_dcls.empty?
|
18597
|
+
W(:W0788, typedef_dcl.location, name)
|
18598
|
+
same_name_obj_dcls.each do |same_name_dcl|
|
18599
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18436
18600
|
end
|
18437
18601
|
end
|
18438
18602
|
|
18439
|
-
|
18440
|
-
|
18441
|
-
|
18442
|
-
|
18443
|
-
|
18603
|
+
same_name_typedef_dcls = @typedef_dcls.last[name]
|
18604
|
+
incompatibles = same_name_typedef_dcls.select { |dcl| dcl.type != type }
|
18605
|
+
unless incompatibles.empty?
|
18606
|
+
W(:W0788, typedef_dcl.location, name)
|
18607
|
+
incompatibles.each do |same_name_dcl|
|
18608
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18444
18609
|
end
|
18445
18610
|
end
|
18446
18611
|
|
18447
|
-
|
18448
|
-
|
18449
|
-
|
18450
|
-
|
18451
|
-
|
18612
|
+
same_name_enums = @enum_names.last[name]
|
18613
|
+
unless same_name_enums.empty?
|
18614
|
+
W(:W0788, typedef_dcl.location, name)
|
18615
|
+
same_name_enums.each do |same_name_enum|
|
18616
|
+
C(:C0001, same_name_enum.location, same_name_enum.identifier.value)
|
18452
18617
|
end
|
18453
18618
|
end
|
18454
|
-
|
18455
|
-
|
18456
|
-
@typedef_decls_stack.last[name].push(typedef_declaration)
|
18457
|
-
end
|
18619
|
+
|
18620
|
+
@typedef_dcls.last[name].push(typedef_dcl)
|
18458
18621
|
end
|
18459
18622
|
|
18460
|
-
def check_enum_declaration(
|
18461
|
-
|
18623
|
+
def check_enum_declaration(enum_dcl)
|
18624
|
+
enum_dcl.enumerators.each { |enum| check_enumerator(enum) }
|
18462
18625
|
end
|
18463
18626
|
|
18464
|
-
def check_enumerator(
|
18465
|
-
name =
|
18627
|
+
def check_enumerator(enum)
|
18628
|
+
name = enum.identifier.value
|
18466
18629
|
|
18467
|
-
|
18468
|
-
|
18469
|
-
|
18470
|
-
|
18471
|
-
|
18630
|
+
same_name_obj_dcls = @obj_dcls.last[name]
|
18631
|
+
unless same_name_obj_dcls.empty?
|
18632
|
+
W(:W0788, enum.location, name)
|
18633
|
+
same_name_obj_dcls.each do |same_name_dcl|
|
18634
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18472
18635
|
end
|
18473
18636
|
end
|
18474
18637
|
|
18475
|
-
|
18476
|
-
|
18477
|
-
|
18478
|
-
|
18479
|
-
|
18638
|
+
same_name_typedef_dcls = @typedef_dcls.last[name]
|
18639
|
+
unless same_name_typedef_dcls.empty?
|
18640
|
+
W(:W0788, enum.location, name)
|
18641
|
+
same_name_typedef_decls.each do |same_name_dcl|
|
18642
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18480
18643
|
end
|
18481
18644
|
end
|
18482
18645
|
|
18483
|
-
|
18484
|
-
|
18485
|
-
|
18486
|
-
|
18487
|
-
|
18646
|
+
same_name_enums = @enum_names.last[name]
|
18647
|
+
unless same_name_enums.empty?
|
18648
|
+
W(:W0788, enum.location, name)
|
18649
|
+
same_name_enums.each do |same_name_enum|
|
18650
|
+
C(:C0001, same_name_enum.location, same_name_enum.identifier.value)
|
18488
18651
|
end
|
18489
18652
|
end
|
18490
|
-
|
18491
|
-
|
18492
|
-
@enumerators_stack.last[name] += 1
|
18493
|
-
end
|
18653
|
+
|
18654
|
+
@enum_names.last[name].push(enum)
|
18494
18655
|
end
|
18495
18656
|
|
18496
|
-
def
|
18497
|
-
@
|
18498
|
-
@
|
18499
|
-
@
|
18657
|
+
def enter_scope(*)
|
18658
|
+
@obj_dcls.push(Hash.new { |hash, key| hash[key] = [] })
|
18659
|
+
@typedef_dcls.push(Hash.new { |hash, key| hash[key] = [] })
|
18660
|
+
@enum_names.push(Hash.new { |hash, key| hash[key] = [] })
|
18500
18661
|
end
|
18501
18662
|
|
18502
|
-
def
|
18503
|
-
@
|
18504
|
-
@
|
18505
|
-
@
|
18663
|
+
def leave_scope(*)
|
18664
|
+
@obj_dcls.pop
|
18665
|
+
@typedef_dcls.pop
|
18666
|
+
@enum_names.pop
|
18506
18667
|
end
|
18507
18668
|
end
|
18508
18669
|
|
@@ -18522,130 +18683,127 @@ module CBuiltin #:nodoc:
|
|
18522
18683
|
interp.on_function_defined += method(:check_object_declaration)
|
18523
18684
|
interp.on_typedef_declared += method(:check_typedef_declaration)
|
18524
18685
|
interp.on_enum_declared += method(:check_enum_declaration)
|
18525
|
-
interp.on_block_started += method(:
|
18526
|
-
interp.on_block_ended += method(:
|
18686
|
+
interp.on_block_started += method(:enter_scope)
|
18687
|
+
interp.on_block_ended += method(:leave_scope)
|
18527
18688
|
|
18528
|
-
@
|
18529
|
-
@
|
18530
|
-
@
|
18689
|
+
@obj_dcls = [Hash.new { |hash, key| hash[key] = [] }]
|
18690
|
+
@typedef_dcls = [Hash.new { |hash, key| hash[key] = [] }]
|
18691
|
+
@enum_names = [Hash.new { |hash, key| hash[key] = [] }]
|
18531
18692
|
end
|
18532
18693
|
|
18533
18694
|
private
|
18534
|
-
def check_object_declaration(
|
18535
|
-
name =
|
18536
|
-
type =
|
18695
|
+
def check_object_declaration(obj_dcl, *)
|
18696
|
+
name = obj_dcl.identifier.value
|
18697
|
+
type = obj_dcl.type
|
18537
18698
|
|
18538
|
-
|
18539
|
-
|
18540
|
-
unless
|
18541
|
-
W(:W0789,
|
18542
|
-
|
18699
|
+
same_name_obj_dcls = merge_upper_scopes(name, @obj_dcls)
|
18700
|
+
incompatibles = same_name_obj_dcls.select { |dcl| dcl.type != type }
|
18701
|
+
unless incompatibles.empty?
|
18702
|
+
W(:W0789, obj_dcl.location, name)
|
18703
|
+
incompatibles.each do |same_name_dcl|
|
18704
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18705
|
+
end
|
18543
18706
|
end
|
18544
18707
|
|
18545
|
-
|
18546
|
-
|
18547
|
-
|
18548
|
-
|
18549
|
-
|
18708
|
+
same_name_typedef_dcls = merge_upper_scopes(name, @typedef_dcls)
|
18709
|
+
unless same_name_typedef_dcls.empty?
|
18710
|
+
W(:W0789, obj_dcl.location, name)
|
18711
|
+
same_name_typedef_dcls.each do |same_name_dcl|
|
18712
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18713
|
+
end
|
18550
18714
|
end
|
18551
18715
|
|
18552
|
-
|
18553
|
-
|
18554
|
-
|
18555
|
-
|
18556
|
-
|
18557
|
-
|
18558
|
-
ensure
|
18559
|
-
unless @object_decls_stack.empty?
|
18560
|
-
@object_decls_stack.last[name].push(declaration_or_definition)
|
18716
|
+
same_name_enums = merge_upper_scopes(name, @enum_names)
|
18717
|
+
unless same_name_enums.empty?
|
18718
|
+
W(:W0789, obj_dcl.location, name)
|
18719
|
+
same_name_enums.each do |same_name_enum|
|
18720
|
+
C(:C0001, same_name_enum.location, same_name_enum.identifier.value)
|
18721
|
+
end
|
18561
18722
|
end
|
18723
|
+
|
18724
|
+
@obj_dcls.last[name].push(obj_dcl)
|
18562
18725
|
end
|
18563
18726
|
|
18564
|
-
def check_typedef_declaration(
|
18565
|
-
name =
|
18566
|
-
type =
|
18727
|
+
def check_typedef_declaration(typedef_dcl)
|
18728
|
+
name = typedef_dcl.identifier.value
|
18729
|
+
type = typedef_dcl.type
|
18567
18730
|
|
18568
|
-
|
18569
|
-
|
18570
|
-
|
18571
|
-
|
18572
|
-
|
18731
|
+
same_name_obj_dcls = merge_upper_scopes(name, @obj_dcls)
|
18732
|
+
unless same_name_obj_dcls.empty?
|
18733
|
+
W(:W0789, typedef_dcl.location, name)
|
18734
|
+
same_name_obj_dcls.each do |same_name_dcl|
|
18735
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18736
|
+
end
|
18573
18737
|
end
|
18574
18738
|
|
18575
|
-
|
18576
|
-
|
18577
|
-
unless
|
18578
|
-
W(:W0789,
|
18579
|
-
|
18739
|
+
same_name_typedef_dcls = merge_upper_scopes(name, @typedef_dcls)
|
18740
|
+
incompatibles = same_name_typedef_dcls.select { |dcl| dcl.type != type }
|
18741
|
+
unless incompatibles.empty?
|
18742
|
+
W(:W0789, typedef_dcl.location, name)
|
18743
|
+
incompatibles.each do |same_name_dcl|
|
18744
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18745
|
+
end
|
18580
18746
|
end
|
18581
18747
|
|
18582
|
-
|
18583
|
-
|
18584
|
-
|
18585
|
-
|
18586
|
-
|
18587
|
-
|
18588
|
-
ensure
|
18589
|
-
unless @typedef_decls_stack.empty?
|
18590
|
-
@typedef_decls_stack.last[name].push(typedef_declaration)
|
18748
|
+
same_name_enums = merge_upper_scopes(name, @enum_names)
|
18749
|
+
unless same_name_enums.empty?
|
18750
|
+
W(:W0789, typedef_dcl.location, name)
|
18751
|
+
same_name_enums.each do |same_name_enum|
|
18752
|
+
C(:C0001, same_name_enum.location, same_name_enum.identifier.value)
|
18753
|
+
end
|
18591
18754
|
end
|
18755
|
+
|
18756
|
+
@typedef_dcls.last[name].push(typedef_dcl)
|
18592
18757
|
end
|
18593
18758
|
|
18594
|
-
def check_enum_declaration(
|
18595
|
-
|
18759
|
+
def check_enum_declaration(enum_dcl)
|
18760
|
+
enum_dcl.enumerators.each { |enum| check_enumerator(enum) }
|
18596
18761
|
end
|
18597
18762
|
|
18598
|
-
def check_enumerator(
|
18599
|
-
name =
|
18763
|
+
def check_enumerator(enum)
|
18764
|
+
name = enum.identifier.value
|
18600
18765
|
|
18601
|
-
|
18602
|
-
|
18603
|
-
|
18604
|
-
|
18605
|
-
|
18766
|
+
same_name_obj_dcls = merge_upper_scopes(name, @obj_dcls)
|
18767
|
+
unless same_name_obj_dcls.empty?
|
18768
|
+
W(:W0789, enum.location, name)
|
18769
|
+
same_name_obj_dcls.each do |same_name_dcl|
|
18770
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18771
|
+
end
|
18606
18772
|
end
|
18607
18773
|
|
18608
|
-
|
18609
|
-
|
18610
|
-
|
18611
|
-
|
18612
|
-
|
18774
|
+
same_name_typedef_dcls = merge_upper_scopes(name, @typedef_dcls)
|
18775
|
+
unless same_name_typedef_dcls.empty?
|
18776
|
+
W(:W0789, enum.location, name)
|
18777
|
+
same_name_typedef_dcls.each do |same_name_dcl|
|
18778
|
+
C(:C0001, same_name_dcl.location, same_name_dcl.identifier.value)
|
18779
|
+
end
|
18613
18780
|
end
|
18614
18781
|
|
18615
|
-
|
18616
|
-
|
18617
|
-
|
18618
|
-
|
18619
|
-
|
18620
|
-
|
18621
|
-
ensure
|
18622
|
-
unless @enumerators_stack.empty?
|
18623
|
-
@enumerators_stack.last[name] += 1
|
18782
|
+
same_name_enums = merge_upper_scopes(name, @enum_names)
|
18783
|
+
unless same_name_enums.empty?
|
18784
|
+
W(:W0789, enum.location, name)
|
18785
|
+
same_name_enums.each do |same_name_enum|
|
18786
|
+
C(:C0001, same_name_enum.location, same_name_enum.identifier.value)
|
18787
|
+
end
|
18624
18788
|
end
|
18625
|
-
end
|
18626
18789
|
|
18627
|
-
|
18628
|
-
@object_decls_stack.push(Hash.new { |hash, key| hash[key] = [] })
|
18629
|
-
@typedef_decls_stack.push(Hash.new { |hash, key| hash[key] = [] })
|
18630
|
-
@enumerators_stack.push(Hash.new(0))
|
18790
|
+
@enum_names.last[name].push(enum)
|
18631
18791
|
end
|
18632
18792
|
|
18633
|
-
def
|
18634
|
-
@
|
18635
|
-
@
|
18636
|
-
@
|
18793
|
+
def enter_scope(*)
|
18794
|
+
@obj_dcls.push(Hash.new { |hash, key| hash[key] = [] })
|
18795
|
+
@typedef_dcls.push(Hash.new { |hash, key| hash[key] = [] })
|
18796
|
+
@enum_names.push(Hash.new { |hash, key| hash[key] = [] })
|
18637
18797
|
end
|
18638
18798
|
|
18639
|
-
def
|
18640
|
-
|
18799
|
+
def leave_scope(*)
|
18800
|
+
@obj_dcls.pop
|
18801
|
+
@typedef_dcls.pop
|
18802
|
+
@enum_names.pop
|
18641
18803
|
end
|
18642
18804
|
|
18643
|
-
def
|
18644
|
-
|
18645
|
-
end
|
18646
|
-
|
18647
|
-
def merge_same_name_enumerators(name, scopes)
|
18648
|
-
scopes.reduce(0) { |result, hash| result + hash[name] }
|
18805
|
+
def merge_upper_scopes(name, scoped_hash)
|
18806
|
+
scoped_hash[0..-2].reduce([]) { |result, hash| result + hash[name] }
|
18649
18807
|
end
|
18650
18808
|
end
|
18651
18809
|
|
@@ -18659,45 +18817,24 @@ module CBuiltin #:nodoc:
|
|
18659
18817
|
def initialize(context)
|
18660
18818
|
super
|
18661
18819
|
interp = context[:c_interpreter]
|
18662
|
-
interp.on_variable_defined += method(:
|
18663
|
-
interp.on_function_defined += method(:
|
18664
|
-
|
18665
|
-
interp.on_block_ended += method(:leave_block)
|
18666
|
-
@global_var_names = Set.new
|
18667
|
-
@global_fun_names = Set.new
|
18668
|
-
@block_level = 0
|
18820
|
+
interp.on_variable_defined += method(:check)
|
18821
|
+
interp.on_function_defined += method(:check)
|
18822
|
+
@global_names = Hash.new { |hash, key| hash[key] = [] }
|
18669
18823
|
end
|
18670
18824
|
|
18671
18825
|
private
|
18672
|
-
def
|
18673
|
-
|
18674
|
-
|
18675
|
-
|
18676
|
-
|
18677
|
-
|
18678
|
-
|
18679
|
-
|
18680
|
-
|
18681
|
-
|
18682
|
-
|
18683
|
-
def check_function(function_definition, function)
|
18684
|
-
return unless @block_level == 0 && function.declared_as_extern?
|
18685
|
-
|
18686
|
-
name = function_definition.identifier.value
|
18687
|
-
if @global_var_names.include?(name) || @global_fun_names.include?(name)
|
18688
|
-
W(:W0790, function_definition.location, name)
|
18689
|
-
else
|
18690
|
-
@global_fun_names.add(name)
|
18826
|
+
def check(var_or_func_def, var)
|
18827
|
+
if var.declared_as_extern?
|
18828
|
+
name = var_or_func_def.identifier
|
18829
|
+
if @global_names.include?(name.value)
|
18830
|
+
W(:W0790, var_or_func_def.location, name.value)
|
18831
|
+
@global_names[name.value].each do |pair_name|
|
18832
|
+
C(:C0001, pair_name.location, pair_name.value)
|
18833
|
+
end
|
18834
|
+
end
|
18835
|
+
@global_names[name.value].push(name)
|
18691
18836
|
end
|
18692
18837
|
end
|
18693
|
-
|
18694
|
-
def enter_block(*)
|
18695
|
-
@block_level += 1
|
18696
|
-
end
|
18697
|
-
|
18698
|
-
def leave_block(*)
|
18699
|
-
@block_level -= 1
|
18700
|
-
end
|
18701
18838
|
end
|
18702
18839
|
|
18703
18840
|
class W0792 < PassiveCodeCheck
|