Class: AdLint::Cc1::IntegerType

Inherits:
ScalarDataType show all
Defined in:
lib/adlint/cc1/type.rb

Instance Attribute Summary

Attributes inherited from ScalarDataType

#bit_alignment, #bit_size

Attributes inherited from Type

#declarations, #name, #type_table

Instance Method Summary collapse

Methods inherited from ScalarDataType

#_arithmetic_type_with_array, #_arithmetic_type_with_bitfield, #_arithmetic_type_with_char, #_arithmetic_type_with_double, #_arithmetic_type_with_enum, #_arithmetic_type_with_extended_big_int, #_arithmetic_type_with_float, #_arithmetic_type_with_function, #_arithmetic_type_with_int, #_arithmetic_type_with_long, #_arithmetic_type_with_long_double, #_arithmetic_type_with_long_int, #_arithmetic_type_with_long_long, #_arithmetic_type_with_long_long_int, #_arithmetic_type_with_pointer, #_arithmetic_type_with_short, #_arithmetic_type_with_short_int, #_arithmetic_type_with_signed, #_arithmetic_type_with_signed_char, #_arithmetic_type_with_signed_int, #_arithmetic_type_with_signed_long, #_arithmetic_type_with_signed_long_int, #_arithmetic_type_with_signed_long_long, #_arithmetic_type_with_signed_long_long_int, #_arithmetic_type_with_signed_short, #_arithmetic_type_with_signed_short_int, #_arithmetic_type_with_struct, #_arithmetic_type_with_undeclared, #_arithmetic_type_with_union, #_arithmetic_type_with_unresolved, #_arithmetic_type_with_unsigned, #_arithmetic_type_with_unsigned_char, #_arithmetic_type_with_unsigned_int, #_arithmetic_type_with_unsigned_long, #_arithmetic_type_with_unsigned_long_int, #_arithmetic_type_with_unsigned_long_long, #_arithmetic_type_with_unsigned_long_long_int, #_arithmetic_type_with_unsigned_short, #_arithmetic_type_with_unsigned_short_int, #_arithmetic_type_with_void, #arbitrary_value, #array?, #base_type, #coerce_array_value, #coerce_composite_value, #coerce_scalar_value, #coercible?, #const?, #function?, #have_va_list?, #impl_length, #length, #member_named, #members, #named?, #nil_value, #parameter_types, #parameter_value, #qualified?, #real_type, #restrict?, #return_type, #return_value, #scalar?, #struct?, #undeclared?, #undefined_value, #union?, #unqualify, #unresolved?, #user?, #void?, #volatile?, #zero_value

Methods included from UsualArithmeticTypeConversion

#do_usual_arithmetic_type_conversion

Methods inherited from Type

#==, #_arithmetic_type_with_array, #_arithmetic_type_with_bitfield, #_arithmetic_type_with_char, #_arithmetic_type_with_double, #_arithmetic_type_with_enum, #_arithmetic_type_with_extended_big_int, #_arithmetic_type_with_float, #_arithmetic_type_with_function, #_arithmetic_type_with_int, #_arithmetic_type_with_long, #_arithmetic_type_with_long_double, #_arithmetic_type_with_long_int, #_arithmetic_type_with_long_long, #_arithmetic_type_with_long_long_int, #_arithmetic_type_with_pointer, #_arithmetic_type_with_short, #_arithmetic_type_with_short_int, #_arithmetic_type_with_signed, #_arithmetic_type_with_signed_char, #_arithmetic_type_with_signed_int, #_arithmetic_type_with_signed_long, #_arithmetic_type_with_signed_long_int, #_arithmetic_type_with_signed_long_long, #_arithmetic_type_with_signed_long_long_int, #_arithmetic_type_with_signed_short, #_arithmetic_type_with_signed_short_int, #_arithmetic_type_with_struct, #_arithmetic_type_with_undeclared, #_arithmetic_type_with_union, #_arithmetic_type_with_unresolved, #_arithmetic_type_with_unsigned, #_arithmetic_type_with_unsigned_char, #_arithmetic_type_with_unsigned_int, #_arithmetic_type_with_unsigned_long, #_arithmetic_type_with_unsigned_long_int, #_arithmetic_type_with_unsigned_long_long, #_arithmetic_type_with_unsigned_long_long_int, #_arithmetic_type_with_unsigned_short, #_arithmetic_type_with_unsigned_short_int, #_arithmetic_type_with_void, #aligned_bit_size, #aligned_byte_size, #arbitrary_value, #array?, #base_type, #bit_alignment, #bit_size, #byte_alignment, #byte_size, #coerce_array_value, #coerce_composite_value, #coerce_scalar_value, #coercible?, #composite?, #const?, #convertible?, #function?, #have_va_list?, #impl_length, #incomplete?, #inspect, #length, #length=, #member_named, #members, #more_cv_qualified?, #named?, #nil_value, #parameter?, #parameter_types, #parameter_value, #qualified?, #real_type, #restrict?, #return_type, #return_value, #same_as?, #scalar?, #struct?, #undeclared?, #undefined_value, #union?, #unqualify, #unresolved?, #unsigned?, #user?, #void?, #volatile?, #zero_value

Methods included from StandardTypesAccessor

#char_alignment, #char_as_unsigned_char?, #char_size, #code_ptr_alignment, #code_ptr_size, #data_ptr_alignment, #data_ptr_size, #double_alignment, #double_size, #float_alignment, #float_size, #int_alignment, #int_size, #long_alignment, #long_double_alignment, #long_double_size, #long_long_alignment, #long_long_size, #long_size, #short_alignment, #short_size, #standard_types

Methods included from ArithmeticAccessor

#arithmetic, #logical_right_shift?

Methods included from Visitable

#accept

Constructor Details

#initialize(type_tbl, name, bit_size, bit_align, signed, explicitly_signed, type_dcls = []) ⇒ IntegerType

Returns a new instance of IntegerType.



3410
3411
3412
3413
3414
3415
# File 'lib/adlint/cc1/type.rb', line 3410

def initialize(type_tbl, name, bit_size, bit_align, signed,
               explicitly_signed, type_dcls = [])
  super(type_tbl, name, bit_size, bit_align, type_dcls)
  @signed = signed
  @explicitly_signed = explicitly_signed
end

Instance Method Details

#argument_promoted_typeObject



3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
# File 'lib/adlint/cc1/type.rb', line 3518

def argument_promoted_type
  # NOTE: The ISO C99 standard says;
  #
  # 6.5.2.2 Function calls
  #
  # 6 If the expression that denotes the called function has a type that
  #   does not include a prototype, the integer promotions are performed on
  #   each argument, and arguments that have type float are promoted to
  #   double.  These are called the default argument promotions.  If the
  #   number of arguments does not equal the number of parameters, the
  #   behavior is undefined.  If the function is defined with a type that
  #   includes a prototype, and either the prototype ends with an ellipsis
  #   (, ...) or the types of the arguments after promotion are not
  #   compatible with the types of the parameters, the behavior is
  #   undefined.  If the function is defined with a type that does not
  #   include a prototype, and the types of the arguments after promotion
  #   are not compatible with those of the parameters after promotion, the
  #   behavior is undefined, except for the following cases:
  #
  #     -- one promoted type is a signed integer type, the other promoted
  #        type is the corresponding unsigned integer type, and the value
  #        is representable in both types;
  #     -- both types are pointers to qualified or unqualified versions of
  #        a character type or void.
  self.integer_promoted_type
end

#arithmetic_type_with(type) ⇒ Object



3545
3546
3547
# File 'lib/adlint/cc1/type.rb', line 3545

def arithmetic_type_with(type)
  subclass_responsibility
end

#bitfield?Boolean

Returns:

  • (Boolean)


3457
3458
3459
# File 'lib/adlint/cc1/type.rb', line 3457

def bitfield?
  subclass_responsibility
end

#brief_imageObject



3425
3426
3427
# File 'lib/adlint/cc1/type.rb', line 3425

def brief_image
  name
end

#compatible?(to_type) ⇒ Boolean

Returns:

  • (Boolean)


3433
3434
3435
# File 'lib/adlint/cc1/type.rb', line 3433

def compatible?(to_type)
  to_type.integer? && to_type.min <= min && max <= to_type.max
end

#corresponding_signed_typeObject



3549
3550
3551
# File 'lib/adlint/cc1/type.rb', line 3549

def corresponding_signed_type
  subclass_responsibility
end

#corresponding_unsigned_typeObject



3553
3554
3555
# File 'lib/adlint/cc1/type.rb', line 3553

def corresponding_unsigned_type
  subclass_responsibility
end

#dupObject



3557
3558
3559
# File 'lib/adlint/cc1/type.rb', line 3557

def dup
  subclass_responsibility
end

#enum?Boolean

Returns:

  • (Boolean)


3449
3450
3451
# File 'lib/adlint/cc1/type.rb', line 3449

def enum?
  subclass_responsibility
end

#enumeratorsObject



3469
3470
3471
# File 'lib/adlint/cc1/type.rb', line 3469

def enumerators
  subclass_responsibility
end

#explicitly_signed?Boolean

Returns:

  • (Boolean)


3465
3466
3467
# File 'lib/adlint/cc1/type.rb', line 3465

def explicitly_signed?
  @explicitly_signed
end

#floating?Boolean

Returns:

  • (Boolean)


3441
3442
3443
# File 'lib/adlint/cc1/type.rb', line 3441

def floating?
  false
end

#idObject



3417
3418
3419
# File 'lib/adlint/cc1/type.rb', line 3417

def id
  subclass_responsibility
end

#imageObject



3421
3422
3423
# File 'lib/adlint/cc1/type.rb', line 3421

def image
  name
end

#integer?Boolean

Returns:

  • (Boolean)


3437
3438
3439
# File 'lib/adlint/cc1/type.rb', line 3437

def integer?
  true
end

#integer_conversion_rankObject



3489
3490
3491
# File 'lib/adlint/cc1/type.rb', line 3489

def integer_conversion_rank
  subclass_responsibility
end

#integer_promoted_typeObject



3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
# File 'lib/adlint/cc1/type.rb', line 3493

def integer_promoted_type
  # NOTE: The ISO C99 standard says;
  #
  # 6.3.1 Arithmetic operands
  # 6.3.1.1 Boolean, characters, and integers
  #
  # 2 The following may be used in an expression wherever an int or
  #   unsigned int may be used:
  #
  #     -- An object or expression with an integer type whose integer
  #        conversion rank is less than or equal to the rank of int and
  #        unsigned int.
  #     -- A bit-field of type _Bool, int, signed int, or unsigned int.
  #
  #   If an int can represent all values of the original type, the value is
  #   converted to an int; otherwise, it is converted to an unsigned int.
  #   These are called the integer promotions.  All other types are
  #   unchanged by the integer promotions.
  if self.integer_conversion_rank <= int_t.integer_conversion_rank
    self.compatible?(int_t) ? int_t : unsigned_int_t
  else
    self
  end
end

#locationObject



3429
3430
3431
# File 'lib/adlint/cc1/type.rb', line 3429

def location
  nil
end

#maxObject



3481
3482
3483
3484
3485
3486
3487
# File 'lib/adlint/cc1/type.rb', line 3481

def max
  if @signed
    2**(@bit_size - 1) - 1
  else
    2**@bit_size - 1
  end
end

#minObject



3473
3474
3475
3476
3477
3478
3479
# File 'lib/adlint/cc1/type.rb', line 3473

def min
  if @signed
    -2**(@bit_size - 1)
  else
    0
  end
end

#pointer?Boolean

Returns:

  • (Boolean)


3445
3446
3447
# File 'lib/adlint/cc1/type.rb', line 3445

def pointer?
  subclass_responsibility
end

#signed?Boolean

Returns:

  • (Boolean)


3461
3462
3463
# File 'lib/adlint/cc1/type.rb', line 3461

def signed?
  @signed
end

#standard?Boolean

Returns:

  • (Boolean)


3453
3454
3455
# File 'lib/adlint/cc1/type.rb', line 3453

def standard?
  subclass_responsibility
end