Class: AdLint::Cc1::EnumType

Inherits:
IntegerType show all
Includes:
Scopeable
Defined in:
lib/adlint/cc1/type.rb

Instance Attribute Summary collapse

Attributes included from Scopeable

#scope

Attributes inherited from ScalarDataType

#bit_alignment, #bit_size

Attributes inherited from Type

#declarations, #name, #type_table

Instance Method Summary collapse

Methods inherited from IntegerType

#argument_promoted_type, #compatible?, #explicitly_signed?, #floating?, #integer?, #max, #min, #signed?

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, #argument_promoted_type, #array?, #base_type, #coerce_array_value, #coerce_composite_value, #coerce_scalar_value, #coercible?, #compatible?, #const?, #explicitly_signed?, #floating?, #function?, #have_va_list?, #impl_length, #integer?, #length, #max, #member_named, #members, #min, #nil_value, #parameter_types, #parameter_value, #qualified?, #real_type, #restrict?, #return_type, #return_value, #scalar?, #signed?, #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, #argument_promoted_type, #array?, #base_type, #bit_alignment, #bit_size, #byte_alignment, #byte_size, #coerce_array_value, #coerce_composite_value, #coerce_scalar_value, #coercible?, #compatible?, #composite?, #const?, #convertible?, #explicitly_signed?, #floating?, #function?, #have_va_list?, #impl_length, #inspect, #integer?, #length, #length=, #max, #member_named, #members, #min, #more_cv_qualified?, #nil_value, #parameter?, #parameter_types, #parameter_value, #qualified?, #real_type, #restrict?, #return_type, #return_value, #same_as?, #scalar?, #signed?, #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, type_dcl) ⇒ EnumType

Returns a new instance of EnumType.



4958
4959
4960
4961
4962
4963
4964
4965
4966
# File 'lib/adlint/cc1/type.rb', line 4958

def initialize(type_tbl, type_dcl)
  # FIXME: StandardTypeCatalogAccessor is not ready until @type_table is
  #        initialized.
  @type_table = type_tbl
  super(type_tbl, type_dcl.identifier.value,
        int_size, int_alignment, true, true, [type_dcl])
  @image = type_dcl.enum_specifier.to_s
  @location = type_dcl.location
end

Instance Attribute Details

#imageObject

Returns the value of attribute image.



4968
4969
4970
# File 'lib/adlint/cc1/type.rb', line 4968

def image
  @image
end

#locationObject

Returns the value of attribute location.



4969
4970
4971
# File 'lib/adlint/cc1/type.rb', line 4969

def location
  @location
end

Instance Method Details

#arithmetic_type_with(type) ⇒ Object



5062
5063
5064
# File 'lib/adlint/cc1/type.rb', line 5062

def arithmetic_type_with(type)
  type._arithmetic_type_with_enum(self)
end

#bitfield?Boolean

Returns:

  • (Boolean)


4995
4996
4997
# File 'lib/adlint/cc1/type.rb', line 4995

def bitfield?
  false
end

#brief_imageObject



4999
5000
5001
# File 'lib/adlint/cc1/type.rb', line 4999

def brief_image
  "enum #{name}"
end

#corresponding_signed_typeObject



5066
5067
5068
# File 'lib/adlint/cc1/type.rb', line 5066

def corresponding_signed_type
  signed_int_t
end

#corresponding_unsigned_typeObject



5070
5071
5072
# File 'lib/adlint/cc1/type.rb', line 5070

def corresponding_unsigned_type
  unsigned_int_t
end

#dupObject



5074
5075
5076
# File 'lib/adlint/cc1/type.rb', line 5074

def dup
  EnumType.new(type_table, declarations.first)
end

#enum?Boolean

Returns:

  • (Boolean)


4987
4988
4989
# File 'lib/adlint/cc1/type.rb', line 4987

def enum?
  true
end

#enumeratorsObject



5003
5004
5005
# File 'lib/adlint/cc1/type.rb', line 5003

def enumerators
  declarations.map { |dcl| dcl.enumerators }.compact.flatten.uniq
end

#idObject



4971
4972
4973
# File 'lib/adlint/cc1/type.rb', line 4971

def id
  @id ||= EnumTypeId.new(name)
end

#incomplete?Boolean

Returns:

  • (Boolean)


4979
4980
4981
# File 'lib/adlint/cc1/type.rb', line 4979

def incomplete?
  declarations.all? { |dcl| dcl.enumerators.nil? }
end

#integer_conversion_rankObject



5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
# File 'lib/adlint/cc1/type.rb', line 5007

def integer_conversion_rank
  # NOTE: The ISO C99 standard says;
  #
  # 6.3.1 Arithmetic operands
  # 6.3.1.1 Boolean, characters, and integers
  #
  # 1 Every integer type has an integer conversion rank defined as follows:
  #
  #     -- No two signed integer types shall have the same rank, even if
  #        they have the same representation.
  #     -- The rank of a signed integer type shall be greater than the rank
  #        of any signed integer type with less precision.
  #     -- The rank of long long int shall be greater than the rank of long
  #        int, which shall be greater than the rank of int, which shall be
  #        greater than the rank of short int, which shall be greater than
  #        the rank of signed char.
  #     -- The rank of any unsigned integer type shall equal the rank of
  #        the corresponding signed integer type, if any.
  #     -- The rank of any standard integer type shall be greater than the
  #        rank of any extended integer type with the same width.
  #     -- The rank of char shall equal the rank of signed char and
  #        unsigned char.
  #     -- The rank of _Bool shall be less than the rank of all other
  #        standard integer types.
  #     -- The rank of any enumerated type shall equal the rank of the
  #        compatible integer type.
  #     -- The rank of any extended signed integer type relative to another
  #        extended signed integer type with the same precision is
  #        implementation-defined, but still subject to the other rules for
  #        determining the integer conversion rank.
  #     -- For all integer types T1, T2, and T3, if T1 has greater rank
  #        than T2 and T2 has greater rank than T3, then T1 has greater
  #        rank than T3.
  #
  # NOTE: The integer conversion rank of any enumerated type is equal to
  #       the rank of int.
  int_t.integer_conversion_rank
end

#integer_promoted_typeObject



5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
# File 'lib/adlint/cc1/type.rb', line 5046

def integer_promoted_type
  # NOTE: Any enumerated type should be treated as `int'.
  #       But AdLint internally treats enumerated type as itself, and omits
  #       integer-promotion of any enumerated type in order not to
  #       over-warn about enum-enum expressions like below;
  #
  #         static void foo(enum Color c)
  #         {
  #             if (c == RED) { /* No usual-arithmetic-conversion of
  #                                enumerated types and no W9003 warning */
  #                 ...
  #             }
  #         }
  self
end

#named?Boolean

Returns:

  • (Boolean)


4975
4976
4977
# File 'lib/adlint/cc1/type.rb', line 4975

def named?
  declarations.all? { |dcl| !dcl.enum_specifier.anonymous? }
end

#pointer?Boolean

Returns:

  • (Boolean)


4983
4984
4985
# File 'lib/adlint/cc1/type.rb', line 4983

def pointer?
  false
end

#standard?Boolean

Returns:

  • (Boolean)


4991
4992
4993
# File 'lib/adlint/cc1/type.rb', line 4991

def standard?
  false
end