adlint 2.6.0 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -114,8 +114,7 @@ module C #:nodoc:
114
114
  }
115
115
  end
116
116
 
117
- def temporary_variable(type = undeclared_type,
118
- value = type.undefined_value)
117
+ def create_tempvar(type = undeclared_type, value = type.undefined_value)
119
118
  variable_table.define_temporary(type, value)
120
119
  end
121
120
 
@@ -687,7 +687,7 @@ module C #:nodoc:
687
687
  end
688
688
 
689
689
  def storage_duration_of(declaration_or_definition)
690
- # NOTE: The ISO C99 standard saids;
690
+ # NOTE: The ISO C99 standard says;
691
691
  #
692
692
  # 6.2.2 Linkages of identifiers
693
693
  #
@@ -835,10 +835,10 @@ module C #:nodoc:
835
835
  return_values_via_pointer_arguments(interpreter, funcall_expr, args)
836
836
 
837
837
  if type.return_type.function?
838
- interpreter.temporary_variable
838
+ interpreter.create_tempvar
839
839
  else
840
- interpreter.temporary_variable(type.return_type,
841
- type.return_type.return_value)
840
+ return_type = type.return_type
841
+ interpreter.create_tempvar(return_type, return_type.return_value)
842
842
  end
843
843
  end
844
844
 
@@ -853,16 +853,15 @@ module C #:nodoc:
853
853
  case
854
854
  when arg.type.array? && param_type.pointer?
855
855
  arg_value = interpreter.pointer_value_of(arg)
856
- converted = interpreter.temporary_variable(param_type, arg_value)
856
+ converted = interpreter.create_tempvar(param_type, arg_value)
857
857
  when arg.type.pointer? && param_type.array?
858
858
  converted = interpreter.pointee_of(arg)
859
859
  when arg.type.function? && param_type.pointer?
860
860
  arg_value = interpreter.pointer_value_of(arg)
861
- converted = interpreter.temporary_variable(param_type, arg_value)
861
+ converted = interpreter.create_tempvar(param_type, arg_value)
862
862
  when arg.variable? && !arg.type.same_as?(param_type)
863
- converted =
864
- interpreter.do_conversion(arg, param_type) ||
865
- interpreter.temporary_variable(param_type)
863
+ converted = interpreter.do_conversion(arg, param_type) ||
864
+ interpreter.create_tempvar(param_type)
866
865
  else
867
866
  converted = arg
868
867
  end
data/lib/adlint/c/seqp.rb CHANGED
@@ -32,7 +32,7 @@
32
32
  module AdLint #:nodoc:
33
33
  module C #:nodoc:
34
34
 
35
- # NOTE: The ISO C99 standard saids;
35
+ # NOTE: The ISO C99 standard says;
36
36
  #
37
37
  # Annex C (informative) Sequence points
38
38
  #
@@ -445,7 +445,7 @@ module C #:nodoc:
445
445
  def full=(full_expression)
446
446
  @full = full_expression
447
447
 
448
- # NOTE: The ISO C99 standard saids;
448
+ # NOTE: The ISO C99 standard says;
449
449
  #
450
450
  # Annex C (informative) Sequence points
451
451
  #
@@ -1944,7 +1944,7 @@ module C #:nodoc:
1944
1944
  def initialize(operator, lhs_operand, rhs_operand)
1945
1945
  super
1946
1946
 
1947
- # NOTE: The ISO C99 standard saids;
1947
+ # NOTE: The ISO C99 standard says;
1948
1948
  #
1949
1949
  # 6.5.13 Logical AND operator
1950
1950
  #
@@ -1993,7 +1993,7 @@ module C #:nodoc:
1993
1993
  def initialize(operator, lhs_operand, rhs_operand)
1994
1994
  super
1995
1995
 
1996
- # NOTE: The ISO C99 standard saids;
1996
+ # NOTE: The ISO C99 standard says;
1997
1997
  #
1998
1998
  # 6.5.14 Logical OR operator
1999
1999
  #
@@ -2046,7 +2046,7 @@ module C #:nodoc:
2046
2046
  @else_expression = else_expression
2047
2047
  @question_mark = question_mark
2048
2048
 
2049
- # NOTE: The ISO C99 standard saids;
2049
+ # NOTE: The ISO C99 standard says;
2050
2050
  #
2051
2051
  # 6.5.15 Conditional operator
2052
2052
  #
@@ -2232,7 +2232,7 @@ module C #:nodoc:
2232
2232
  def push(expression)
2233
2233
  @expressions.push(expression)
2234
2234
 
2235
- # NOTE: The ISO C99 standard saids;
2235
+ # NOTE: The ISO C99 standard says;
2236
2236
  #
2237
2237
  # 6.5.17 Comma operator
2238
2238
  #
@@ -3055,7 +3055,7 @@ module C #:nodoc:
3055
3055
  def full=(full_declarator)
3056
3056
  @full = full_declarator
3057
3057
 
3058
- # NOTE: The ISO C99 standard saids;
3058
+ # NOTE: The ISO C99 standard says;
3059
3059
  #
3060
3060
  # 6.7.5 Declarators
3061
3061
  #
data/lib/adlint/c/type.rb CHANGED
@@ -3475,7 +3475,7 @@ module C #:nodoc:
3475
3475
  end
3476
3476
 
3477
3477
  def integer_promoted_type
3478
- # NOTE: The ISO C99 standard saids;
3478
+ # NOTE: The ISO C99 standard says;
3479
3479
  #
3480
3480
  # 6.3.1 Arithmetic operands
3481
3481
  # 6.3.1.1 Boolean, characters, and integers
@@ -3500,7 +3500,7 @@ module C #:nodoc:
3500
3500
  end
3501
3501
 
3502
3502
  def argument_promoted_type
3503
- # NOTE: The ISO C99 standard saids;
3503
+ # NOTE: The ISO C99 standard says;
3504
3504
  #
3505
3505
  # 6.5.2.2 Function calls
3506
3506
  #
@@ -3609,7 +3609,7 @@ module C #:nodoc:
3609
3609
  end
3610
3610
 
3611
3611
  def integer_conversion_rank
3612
- # NOTE: The ISO C99 standard saids;
3612
+ # NOTE: The ISO C99 standard says;
3613
3613
  #
3614
3614
  # 6.3.1 Arithmetic operands
3615
3615
  # 6.3.1.1 Boolean, characters, and integers
@@ -4851,7 +4851,7 @@ module C #:nodoc:
4851
4851
 
4852
4852
  def integer_promoted_type
4853
4853
  # TODO: Should support the C99 _Bool type.
4854
- # NOTE: The ISO C99 standard saids;
4854
+ # NOTE: The ISO C99 standard says;
4855
4855
  #
4856
4856
  # 6.3.1 Arithmetic operands
4857
4857
  # 6.3.1.1 Boolean, characters, and integers
@@ -4960,7 +4960,7 @@ module C #:nodoc:
4960
4960
  end
4961
4961
 
4962
4962
  def integer_conversion_rank
4963
- # NOTE: The ISO C99 standard saids;
4963
+ # NOTE: The ISO C99 standard says;
4964
4964
  #
4965
4965
  # 6.3.1 Arithmetic operands
4966
4966
  # 6.3.1.1 Boolean, characters, and integers
@@ -5347,7 +5347,7 @@ module C #:nodoc:
5347
5347
  end
5348
5348
 
5349
5349
  def argument_promoted_type
5350
- # NOTE: The ISO C99 standard saids;
5350
+ # NOTE: The ISO C99 standard says;
5351
5351
  #
5352
5352
  # 6.5.2.2 Function calls
5353
5353
  #
@@ -5728,7 +5728,7 @@ module C #:nodoc:
5728
5728
  end
5729
5729
 
5730
5730
  def coerce_array_value(value)
5731
- # NOTE: The ISO C99 standard saids;
5731
+ # NOTE: The ISO C99 standard says;
5732
5732
  #
5733
5733
  # 6.7.8 Initialization
5734
5734
  #
@@ -7051,7 +7051,7 @@ module C #:nodoc:
7051
7051
  end
7052
7052
 
7053
7053
  def integer_conversion_rank
7054
- # NOTE: The ISO C99 standard saids;
7054
+ # NOTE: The ISO C99 standard says;
7055
7055
  #
7056
7056
  # 6.3.1 Arithmetic operands
7057
7057
  # 6.3.1.1 Boolean, characters, and integers
@@ -482,7 +482,7 @@ module Cpp #:nodoc:
482
482
  pp_tokens = pp_tokens(context)
483
483
  discard_extra_tokens_until_newline(context)
484
484
 
485
- # NOTE: The ISO C99 standard saids;
485
+ # NOTE: The ISO C99 standard says;
486
486
  #
487
487
  # 6.10.4 Line control
488
488
  #
@@ -237,7 +237,7 @@ module Cpp #:nodoc:
237
237
 
238
238
  def substitute_argument(param_token, next_token, arg, location, result,
239
239
  macro_table, context)
240
- # NOTE: The ISO C99 standard saids;
240
+ # NOTE: The ISO C99 standard says;
241
241
  #
242
242
  # 6.10.3.1 Argument substitution
243
243
  #
@@ -263,7 +263,7 @@ module Cpp #:nodoc:
263
263
  end
264
264
 
265
265
  def stringize_argument(arg, expansion_location, macro_table)
266
- # NOTE: The ISO C99 standard saids;
266
+ # NOTE: The ISO C99 standard says;
267
267
  #
268
268
  # 6.10.3.2 The # operator
269
269
  #
@@ -310,7 +310,7 @@ module Cpp #:nodoc:
310
310
 
311
311
  def concat_with_last_token(arg_tokens, expansion_location, result_tokens,
312
312
  macro_table)
313
- # NOTE: The ISO C99 standard saids;
313
+ # NOTE: The ISO C99 standard says;
314
314
  #
315
315
  # 6.10.3.3 The ## operator
316
316
  #
@@ -634,7 +634,7 @@ module Cpp #:nodoc:
634
634
  expanded = macro.expand(tokens[index, size], self, context)
635
635
  context.add_to_hide_set(tokens[index], expanded, macro.name.value)
636
636
 
637
- # NOTE: The ISO C99 standard saids;
637
+ # NOTE: The ISO C99 standard says;
638
638
  #
639
639
  # 6.10.3.4 Rescanning and further replacement
640
640
  #
@@ -79,7 +79,7 @@ module Cpp #:nodoc:
79
79
  string.chars.to_a - select_adapted(string)
80
80
  end
81
81
 
82
- # NOTE: The ISO C99 standard saids;
82
+ # NOTE: The ISO C99 standard says;
83
83
  #
84
84
  # 5.2 Environmental considerations
85
85
  # 5.2.1 Character sets
@@ -1695,15 +1695,19 @@ module CBuiltin #:nodoc:
1695
1695
  end
1696
1696
 
1697
1697
  private
1698
- def check(unary_arithmetic_expression, operand_variable, result_variable)
1699
- if unary_arithmetic_expression.operator.type == "-"
1700
- if operand_variable.type.same_as?(@interp.unsigned_char_type) ||
1701
- operand_variable.type.same_as?(@interp.unsigned_short_type) ||
1702
- operand_variable.type.bitfield?
1703
- W(:W0082, unary_arithmetic_expression.location)
1698
+ def check(unary_arith_expr, operand_var, *)
1699
+ if unary_arith_expr.operator.type == "-"
1700
+ if unsigned_underlying_type?(operand_var.type)
1701
+ W(:W0082, unary_arith_expr.location, operand_var.type.brief_image)
1704
1702
  end
1705
1703
  end
1706
1704
  end
1705
+
1706
+ def unsigned_underlying_type?(type)
1707
+ type.same_as?(@interp.unsigned_char_type) ||
1708
+ type.same_as?(@interp.unsigned_short_type) ||
1709
+ type.bitfield?
1710
+ end
1707
1711
  end
1708
1712
 
1709
1713
  class W0084 < PassiveCodeCheck
@@ -11243,51 +11247,48 @@ module CBuiltin #:nodoc:
11243
11247
  end
11244
11248
 
11245
11249
  private
11246
- def check(initializer_or_expression, original_variable, result_variable)
11250
+ def check(init_or_expr, src_var, dst_var)
11247
11251
  return unless @rvalues
11248
- return unless original_variable.type.integer?
11249
11252
 
11250
- src_type = original_variable.type
11251
- dst_type = result_variable.type
11253
+ src_type = src_var.type
11254
+ dst_type = dst_var.type
11255
+ return unless src_type.integer?
11252
11256
 
11253
11257
  if src_type.integer_conversion_rank < dst_type.integer_conversion_rank
11254
- case @rvalues[original_variable]
11258
+ case @rvalues[src_var]
11255
11259
  when C::UnaryArithmeticExpression, C::ShiftExpression,
11256
11260
  C::AdditiveExpression, C::MultiplicativeExpression
11257
- W(:W0578, initializer_or_expression.location)
11261
+ W(:W0578, init_or_expr.location,
11262
+ src_type.brief_image, dst_type.brief_image)
11258
11263
  end
11259
11264
  end
11260
11265
  end
11261
11266
 
11262
- def clear_rvalues(function_definition, function)
11267
+ def clear_rvalues(*)
11263
11268
  @rvalues = {}
11264
11269
  end
11265
11270
 
11266
- def handle_unary(unary_arithmetic_expression,
11267
- operand_variable, result_variable)
11268
- return unless unary_arithmetic_expression.operator == "~"
11269
- memorize_rvalue_derivation(result_variable, unary_arithmetic_expression)
11271
+ def handle_unary(unary_arith_expr, *, result_var)
11272
+ return unless unary_arith_expr.operator == "~"
11273
+ memorize_rvalue_derivation(result_var, unary_arith_expr)
11270
11274
  end
11271
11275
 
11272
- def handle_shift(shift_expression,
11273
- lhs_variable, rhs_variable, result_variable)
11274
- return unless shift_expression.operator.type == "<<"
11275
- memorize_rvalue_derivation(result_variable, shift_expression)
11276
+ def handle_shift(shift_expr, *, result_var)
11277
+ return unless shift_expr.operator.type == "<<"
11278
+ memorize_rvalue_derivation(result_var, shift_expr)
11276
11279
  end
11277
11280
 
11278
- def handle_additive(additive_expression,
11279
- lhs_variable, rhs_variable, result_variable)
11280
- memorize_rvalue_derivation(result_variable, additive_expression)
11281
+ def handle_additive(additive_expr, *, result_var)
11282
+ memorize_rvalue_derivation(result_var, additive_expr)
11281
11283
  end
11282
11284
 
11283
- def handle_multiplicative(multiplicative_expression,
11284
- lhs_variable, rhs_variable, result_variable)
11285
- return if multiplicative_expression.operator.type == "%"
11286
- memorize_rvalue_derivation(result_variable, multiplicative_expression)
11285
+ def handle_multiplicative(multiplicative_expr, *, result_var)
11286
+ return if multiplicative_expr.operator.type == "%"
11287
+ memorize_rvalue_derivation(result_var, multiplicative_expr)
11287
11288
  end
11288
11289
 
11289
- def memorize_rvalue_derivation(rvalue_holder, expression)
11290
- @rvalues[rvalue_holder] = expression if @rvalues
11290
+ def memorize_rvalue_derivation(rvalue_holder, expr)
11291
+ @rvalues[rvalue_holder] = expr if @rvalues
11291
11292
  end
11292
11293
  end
11293
11294
 
@@ -11307,51 +11308,48 @@ module CBuiltin #:nodoc:
11307
11308
  end
11308
11309
 
11309
11310
  private
11310
- def check(cast_expression, original_variable, result_variable)
11311
+ def check(cast_expr, src_var, dst_var)
11311
11312
  return unless @rvalues
11312
- return unless original_variable.type.integer?
11313
11313
 
11314
- src_type = original_variable.type
11315
- dst_type = result_variable.type
11314
+ src_type = src_var.type
11315
+ dst_type = dst_var.type
11316
+ return unless src_type.integer?
11316
11317
 
11317
11318
  if src_type.integer_conversion_rank < dst_type.integer_conversion_rank
11318
- case @rvalues[original_variable]
11319
+ case @rvalues[src_var]
11319
11320
  when C::UnaryArithmeticExpression, C::ShiftExpression,
11320
11321
  C::AdditiveExpression, C::MultiplicativeExpression
11321
- W(:W0579, cast_expression.location)
11322
+ W(:W0579, cast_expr.location,
11323
+ src_type.brief_image, dst_type.brief_image)
11322
11324
  end
11323
11325
  end
11324
11326
  end
11325
11327
 
11326
- def clear_rvalues(function_definition, function)
11328
+ def clear_rvalues(*)
11327
11329
  @rvalues = {}
11328
11330
  end
11329
11331
 
11330
- def handle_unary(unary_arithmetic_expression,
11331
- operand_variable, result_variable)
11332
- return unless unary_arithmetic_expression.operator == "~"
11333
- memorize_rvalue_derivation(result_variable, unary_arithmetic_expression)
11332
+ def handle_unary(unary_arith_expr, *, result_var)
11333
+ return unless unary_arith_expr.operator == "~"
11334
+ memorize_rvalue_derivation(result_var, unary_arith_expr)
11334
11335
  end
11335
11336
 
11336
- def handle_shift(shift_expression,
11337
- lhs_variable, rhs_variable, result_variable)
11338
- return unless shift_expression.operator.type == "<<"
11339
- memorize_rvalue_derivation(result_variable, shift_expression)
11337
+ def handle_shift(shift_expr, *, result_var)
11338
+ return unless shift_expr.operator.type == "<<"
11339
+ memorize_rvalue_derivation(result_var, shift_expr)
11340
11340
  end
11341
11341
 
11342
- def handle_additive(additive_expression,
11343
- lhs_variable, rhs_variable, result_variable)
11344
- memorize_rvalue_derivation(result_variable, additive_expression)
11342
+ def handle_additive(additive_expr, *, result_var)
11343
+ memorize_rvalue_derivation(result_var, additive_expr)
11345
11344
  end
11346
11345
 
11347
- def handle_multiplicative(multiplicative_expression,
11348
- lhs_variable, rhs_variable, result_variable)
11349
- return if multiplicative_expression.operator.type == "%"
11350
- memorize_rvalue_derivation(result_variable, multiplicative_expression)
11346
+ def handle_multiplicative(multiplicative_expr, *, result_var)
11347
+ return if multiplicative_expr.operator.type == "%"
11348
+ memorize_rvalue_derivation(result_var, multiplicative_expr)
11351
11349
  end
11352
11350
 
11353
- def memorize_rvalue_derivation(rvalue_holder, expression)
11354
- @rvalues[rvalue_holder] = expression if @rvalues
11351
+ def memorize_rvalue_derivation(rvalue_holder, expr)
11352
+ @rvalues[rvalue_holder] = expr if @rvalues
11355
11353
  end
11356
11354
  end
11357
11355
 
@@ -11781,7 +11779,9 @@ module CBuiltin #:nodoc:
11781
11779
  end
11782
11780
 
11783
11781
  def refer_variable(expression, variable)
11784
- @refer_count[variable] += 1 if variable.named?
11782
+ if variable.named?
11783
+ @refer_count[variable] += 1
11784
+ end
11785
11785
  end
11786
11786
 
11787
11787
  def update_variable(expression, variable)
@@ -12899,13 +12899,13 @@ module CBuiltin #:nodoc:
12899
12899
  end
12900
12900
 
12901
12901
  private
12902
- def check(expr, lhs_variable, rhs_variable, result_variable)
12902
+ def check(expr, lhs_var, rhs_var, *)
12903
12903
  if expr.rhs_operand.constant?(@enum_tbl)
12904
- promoted_type = lhs_variable.type.integer_promoted_type
12904
+ promoted_type = lhs_var.type.integer_promoted_type
12905
12905
  promoted_bit_size = C::ScalarValue.of(promoted_type.bit_size)
12906
- if rhs_variable.value.must_be_equal_to?(promoted_bit_size) ||
12907
- rhs_variable.value.must_be_greater_than?(promoted_bit_size)
12908
- W(:W0650, expr.location)
12906
+ if rhs_var.value.must_be_equal_to?(promoted_bit_size) ||
12907
+ rhs_var.value.must_be_greater_than?(promoted_bit_size)
12908
+ W(:W0650, expr.location, promoted_type.brief_image)
12909
12909
  end
12910
12910
  end
12911
12911
  end
@@ -14486,17 +14486,17 @@ module CBuiltin #:nodoc:
14486
14486
  end
14487
14487
 
14488
14488
  private
14489
- def check(expr, lhs_variable, rhs_variable, result_variable)
14489
+ def check(expr, lhs_var, rhs_var, *)
14490
14490
  if expr.rhs_operand.constant?(@enum_tbl)
14491
- underlying_type = lhs_variable.type
14491
+ underlying_type = lhs_var.type
14492
14492
  underlying_bit_size = C::ScalarValue.of(underlying_type.bit_size)
14493
- promoted_type = lhs_variable.type.integer_promoted_type
14493
+ promoted_type = lhs_var.type.integer_promoted_type
14494
14494
  promoted_bit_size = C::ScalarValue.of(promoted_type.bit_size)
14495
14495
 
14496
- if rhs_variable.value.must_be_equal_to?(underlying_bit_size) ||
14497
- rhs_variable.value.must_be_greater_than?(underlying_bit_size) and
14498
- rhs_variable.value.must_be_less_than?(promoted_bit_size)
14499
- W(:W0719, expr.location)
14496
+ if rhs_var.value.must_be_equal_to?(underlying_bit_size) ||
14497
+ rhs_var.value.must_be_greater_than?(underlying_bit_size) and
14498
+ rhs_var.value.must_be_less_than?(promoted_bit_size)
14499
+ W(:W0719, expr.location, underlying_type.brief_image)
14500
14500
  end
14501
14501
  end
14502
14502
  end
@@ -17509,29 +17509,28 @@ module CBuiltin #:nodoc:
17509
17509
  end
17510
17510
 
17511
17511
  private
17512
- def check(binary_expression, lhs_variable, rhs_variable, result_variable)
17513
- return unless lhs_variable.type.scalar? && lhs_variable.type.unsigned?
17514
- return unless rhs_variable.type.scalar? && rhs_variable.type.unsigned?
17515
-
17516
- return unless lhs_variable.value.scalar? && rhs_variable.value.scalar?
17512
+ def check(binary_expr, lhs_var, rhs_var, result_var)
17513
+ return unless lhs_var.type.scalar? && lhs_var.type.unsigned?
17514
+ return unless rhs_var.type.scalar? && rhs_var.type.unsigned?
17515
+ return unless lhs_var.value.scalar? && rhs_var.value.scalar?
17517
17516
 
17518
- case binary_expression.operator.type
17517
+ case binary_expr.operator.type
17519
17518
  when "+"
17520
- unbound_value = lhs_variable.value + rhs_variable.value
17519
+ unbound_val = lhs_var.value + rhs_var.value
17521
17520
  when "-"
17522
- unbound_value = lhs_variable.value - rhs_variable.value
17521
+ unbound_val = lhs_var.value - rhs_var.value
17523
17522
  when "*"
17524
- unbound_value = lhs_variable.value * rhs_variable.value
17523
+ unbound_val = lhs_var.value * rhs_var.value
17525
17524
  else
17526
17525
  return
17527
17526
  end
17528
17527
 
17529
- result_type = result_variable.type
17530
- lower_test = unbound_value < C::ScalarValue.of(result_type.min_value)
17531
- upper_test = unbound_value > C::ScalarValue.of(result_type.max_value)
17528
+ result_type = result_var.type
17529
+ lower_test = unbound_val < C::ScalarValue.of(result_type.min_value)
17530
+ upper_test = unbound_val > C::ScalarValue.of(result_type.max_value)
17532
17531
 
17533
17532
  if lower_test.must_be_true? || upper_test.must_be_true?
17534
- W(:W1051, binary_expression.location)
17533
+ W(:W1051, binary_expr.location, result_type.brief_image)
17535
17534
  end
17536
17535
  end
17537
17536
  end
@@ -17547,30 +17546,29 @@ module CBuiltin #:nodoc:
17547
17546
  end
17548
17547
 
17549
17548
  private
17550
- def check(binary_expression, lhs_variable, rhs_variable, result_variable)
17551
- return unless lhs_variable.type.scalar? && lhs_variable.type.unsigned?
17552
- return unless rhs_variable.type.scalar? && rhs_variable.type.unsigned?
17549
+ def check(binary_expr, lhs_var, rhs_var, result_var)
17550
+ return unless lhs_var.type.scalar? && lhs_var.type.unsigned?
17551
+ return unless rhs_var.type.scalar? && rhs_var.type.unsigned?
17552
+ return unless lhs_var.value.scalar? && rhs_var.value.scalar?
17553
17553
 
17554
- return unless lhs_variable.value.scalar? && rhs_variable.value.scalar?
17555
-
17556
- case binary_expression.operator.type
17554
+ case binary_expr.operator.type
17557
17555
  when "+"
17558
- unbound_value = lhs_variable.value + rhs_variable.value
17556
+ unbound_val = lhs_var.value + rhs_var.value
17559
17557
  when "-"
17560
- unbound_value = lhs_variable.value - rhs_variable.value
17558
+ unbound_val = lhs_var.value - rhs_var.value
17561
17559
  when "*"
17562
- unbound_value = lhs_variable.value * rhs_variable.value
17560
+ unbound_val = lhs_var.value * rhs_var.value
17563
17561
  else
17564
17562
  return
17565
17563
  end
17566
17564
 
17567
- result_type = result_variable.type
17568
- lower_test = unbound_value < C::ScalarValue.of(result_type.min_value)
17569
- upper_test = unbound_value > C::ScalarValue.of(result_type.max_value)
17565
+ result_type = result_var.type
17566
+ lower_test = unbound_val < C::ScalarValue.of(result_type.min_value)
17567
+ upper_test = unbound_val > C::ScalarValue.of(result_type.max_value)
17570
17568
 
17571
17569
  if !lower_test.must_be_true? && lower_test.may_be_true? or
17572
17570
  !upper_test.must_be_true? && upper_test.may_be_true?
17573
- W(:W1052, binary_expression.location)
17571
+ W(:W1052, binary_expr.location, result_type.brief_image)
17574
17572
  end
17575
17573
  end
17576
17574
  end
@@ -17965,8 +17963,8 @@ module CBuiltin #:nodoc:
17965
17963
  if @current_function
17966
17964
  @return_values.each_value do |retval|
17967
17965
  unless retval[0]
17968
- fun_name = retval[2].named? ? retval[2].name : "(anonymous)"
17969
- W(:W1073, retval[1].location, fun_name)
17966
+ func_name = retval[2].named? ? retval[2].name : "(anonymous)"
17967
+ W(:W1073, retval[1].location, func_name)
17970
17968
  end
17971
17969
  end
17972
17970
  end
@@ -220,7 +220,7 @@ module CBuiltin #:nodoc:
220
220
  mapping = @context[:ld_function_mapping]
221
221
  functions = mapping.lookup_functions(function.name)
222
222
  if functions.size > 1
223
- functions.each { |fun| W(:W0791, fun.location, fun.signature) }
223
+ functions.each { |func| W(:W0791, func.location, func.signature) }
224
224
  end
225
225
  end
226
226
 
@@ -257,9 +257,9 @@ module CBuiltin #:nodoc:
257
257
  mapping = @context[:ld_function_mapping]
258
258
  defs_and_decls =
259
259
  (mapping.lookup_function_declarations(function.name) +
260
- mapping.lookup_functions(function.name)).select { |fun| fun.extern? }
261
- if defs_and_decls.any? { |fun| fun.signature != function.signature }
262
- defs_and_decls.each { |fun| W(:W1037, fun.location, fun.name) }
260
+ mapping.lookup_functions(function.name)).select { |f| f.extern? }
261
+ if defs_and_decls.any? { |f| f.signature != function.signature }
262
+ defs_and_decls.each { |f| W(:W1037, f.location, f.name) }
263
263
  end
264
264
  end
265
265
 
data/lib/adlint/traits.rb CHANGED
@@ -111,14 +111,12 @@ module AdLint #:nodoc:
111
111
 
112
112
  class ProjectTraits
113
113
  include Validation
114
+ include CompoundPathParser
114
115
 
115
116
  def initialize(doc)
116
117
  @project_name = doc["project_name"]
117
118
  @project_root = Pathname.new(doc["project_root"])
118
- @include_path =
119
- (doc["include_path"] || []).compact.map { |compound_path_str|
120
- compound_path_str.split(":").map { |str| Pathname.new(str) }
121
- }.flatten
119
+ @include_path = parse_compound_path_list(doc["include_path"])
122
120
  @initial_header = doc["initial_header"]
123
121
  @coding_style = CodingStyle.new(doc["coding_style"])
124
122
  @file_encoding = doc["file_encoding"]
@@ -195,13 +193,11 @@ module AdLint #:nodoc:
195
193
  # Traits information of the compiler used in the project.
196
194
  class CompilerTraits
197
195
  include Validation
196
+ include CompoundPathParser
198
197
 
199
198
  def initialize(doc)
200
199
  @standard_type = StandardType.new(doc["standard_type"])
201
- @include_path =
202
- (doc["include_path"] || []).compact.map { |compound_path_str|
203
- compound_path_str.split(":").map { |str| Pathname.new(str) }
204
- }.flatten
200
+ @include_path = parse_compound_path_list(doc["include_path"])
205
201
  @initial_header = doc["initial_header"]
206
202
  @arithmetic = Arithmetic.new(doc["arithmetic"])
207
203
  @extension_substitution = doc["extension_substitution"] || {}
@@ -485,18 +481,13 @@ module AdLint #:nodoc:
485
481
 
486
482
  class MessageTraits
487
483
  include Validation
484
+ include CompoundPathParser
488
485
 
489
486
  def initialize(doc)
490
487
  @language = doc["language"]
491
488
  @message_with_class = doc["message_with_class"]
492
- @warn_files_in =
493
- (doc["warn_files_in"] || []).compact.map { |compound_path_str|
494
- compound_path_str.split(":").map { |str| Pathname.new(str) }
495
- }.flatten
496
- @warn_files_not_in =
497
- (doc["warn_files_not_in"] || []).compact.map { |compound_path_str|
498
- compound_path_str.split(":").map { |str| Pathname.new(str) }
499
- }.flatten
489
+ @warn_files_in = parse_compound_path_list(doc["warn_files_in"])
490
+ @warn_files_not_in = parse_compound_path_list(doc["warn_files_not_in"])
500
491
  @individual_selection = doc["individual_selection"]
501
492
  @exclusion = Exclusion.new(doc["exclusion"])
502
493
  @inclusion = Inclusion.new(doc["inclusion"])
data/lib/adlint/util.rb CHANGED
@@ -582,6 +582,18 @@ module AdLint #:nodoc:
582
582
  module_function :package_name_of
583
583
  end
584
584
 
585
+ module CompoundPathParser
586
+ def parse_compound_path_list(ary)
587
+ (ary || []).compact.map { |str| parse_compound_path_str(str) }.flatten
588
+ end
589
+ module_function :parse_compound_path_list
590
+
591
+ def parse_compound_path_str(str)
592
+ str.split(File::PATH_SEPARATOR).map { |s| Pathname.new(s) }
593
+ end
594
+ module_function :parse_compound_path_str
595
+ end
596
+
585
597
  end
586
598
 
587
599
  if $0 == __FILE__