adlint 1.10.0 → 1.12.0

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.
Files changed (49) hide show
  1. data/ChangeLog +197 -4
  2. data/MANIFEST +17 -0
  3. data/NEWS +23 -4
  4. data/etc/mesg.d/en_US/messages.yml +14 -1
  5. data/etc/mesg.d/ja_JP/messages.yml +14 -1
  6. data/features/message_detection/W0093.feature +87 -0
  7. data/features/message_detection/W0687.feature +25 -0
  8. data/features/message_detection/W0688.feature +63 -0
  9. data/features/message_detection/W0689.feature +46 -0
  10. data/features/message_detection/W0690.feature +35 -0
  11. data/features/message_detection/W0698.feature +3 -2
  12. data/features/message_detection/W0703.feature +1 -0
  13. data/features/message_detection/W0723.feature +34 -0
  14. data/features/message_detection/W0732.feature +158 -0
  15. data/features/message_detection/W0733.feature +158 -0
  16. data/features/message_detection/W0734.feature +322 -0
  17. data/features/message_detection/W0735.feature +322 -0
  18. data/features/message_detection/W1052.feature +66 -0
  19. data/features/message_detection/W9001.feature +33 -0
  20. data/features/message_detection/W9003.feature +131 -0
  21. data/lib/adlint/c/ctrlexpr.rb +51 -50
  22. data/lib/adlint/c/domain.rb +237 -223
  23. data/lib/adlint/c/expr.rb +6 -8
  24. data/lib/adlint/c/interp.rb +8 -11
  25. data/lib/adlint/c/message.rb +20 -0
  26. data/lib/adlint/c/message_shima.rb +63 -0
  27. data/lib/adlint/c/object.rb +5 -4
  28. data/lib/adlint/c/operator.rb +99 -0
  29. data/lib/adlint/c/parser.rb +2 -2
  30. data/lib/adlint/c/parser.y +2 -2
  31. data/lib/adlint/c/phase.rb +6 -1
  32. data/lib/adlint/c/syntax.rb +442 -30
  33. data/lib/adlint/c/type.rb +449 -363
  34. data/lib/adlint/c/value.rb +96 -25
  35. data/lib/adlint/c.rb +1 -0
  36. data/lib/adlint/prelude.rb +16 -18
  37. data/lib/adlint/version.rb +2 -2
  38. data/share/doc/developers_guide_ja.html +11 -5
  39. data/share/doc/developers_guide_ja.texi +9 -3
  40. data/share/doc/users_guide_en.html +697 -131
  41. data/share/doc/users_guide_en.texi +491 -41
  42. data/share/doc/users_guide_ja.html +709 -139
  43. data/share/doc/users_guide_ja.texi +499 -45
  44. data/spec/adlint/c/ctrlexpr_spec.rb +168 -0
  45. data/spec/adlint/c/domain_spec.rb +835 -0
  46. data/spec/adlint/c/operator_spec.rb +406 -0
  47. data/spec/adlint/c/syntax_spec.rb +717 -0
  48. data/spec/adlint/c/type_spec.rb +55 -30
  49. metadata +19 -2
data/lib/adlint/c/type.rb CHANGED
@@ -36,6 +36,7 @@ require "adlint/c/scope"
36
36
  require "adlint/c/object"
37
37
  require "adlint/c/conv"
38
38
  require "adlint/c/option"
39
+ require "adlint/c/operator"
39
40
 
40
41
  module AdLint #:nodoc:
41
42
  module C #:nodoc:
@@ -123,9 +124,10 @@ module C #:nodoc:
123
124
  # <--- EnumType ------------------- Scopeable <<module>>
124
125
  # <--- PointerType |
125
126
  # <--- FloatingType |
126
- # <--- FloatType |
127
- # <--- DoubleType |
128
- # <--- LongDoubleType |
127
+ # <--- StandardFloatingType |
128
+ # <--- FloatType |
129
+ # <--- DoubleType |
130
+ # <--- LongDoubleType |
129
131
  # <--- ArrayType |
130
132
  # <--- CompositeDataType -----------------------------+
131
133
  # <--- StructType |
@@ -277,6 +279,10 @@ module C #:nodoc:
277
279
  subclass_responsibility
278
280
  end
279
281
 
282
+ def standard?
283
+ subclass_responsibility
284
+ end
285
+
280
286
  def undeclared?
281
287
  subclass_responsibility
282
288
  end
@@ -740,6 +746,10 @@ module C #:nodoc:
740
746
  false
741
747
  end
742
748
 
749
+ def standard?
750
+ false
751
+ end
752
+
743
753
  def undeclared?
744
754
  true
745
755
  end
@@ -1264,6 +1274,10 @@ module C #:nodoc:
1264
1274
  false
1265
1275
  end
1266
1276
 
1277
+ def standard?
1278
+ false
1279
+ end
1280
+
1267
1281
  def undeclared?
1268
1282
  false
1269
1283
  end
@@ -1804,6 +1818,10 @@ module C #:nodoc:
1804
1818
  @base_type.void?
1805
1819
  end
1806
1820
 
1821
+ def standard?
1822
+ @base_type.standard?
1823
+ end
1824
+
1807
1825
  def undeclared?
1808
1826
  @base_type.undeclared?
1809
1827
  end
@@ -2117,6 +2135,10 @@ module C #:nodoc:
2117
2135
  true
2118
2136
  end
2119
2137
 
2138
+ def standard?
2139
+ true
2140
+ end
2141
+
2120
2142
  def undeclared?
2121
2143
  false
2122
2144
  end
@@ -2645,6 +2667,10 @@ module C #:nodoc:
2645
2667
  false
2646
2668
  end
2647
2669
 
2670
+ def standard?
2671
+ false
2672
+ end
2673
+
2648
2674
  def undeclared?
2649
2675
  false
2650
2676
  end
@@ -3186,6 +3212,10 @@ module C #:nodoc:
3186
3212
  false
3187
3213
  end
3188
3214
 
3215
+ def standard?
3216
+ subclass_responsibility
3217
+ end
3218
+
3189
3219
  def undeclared?
3190
3220
  false
3191
3221
  end
@@ -3284,7 +3314,7 @@ module C #:nodoc:
3284
3314
 
3285
3315
  def coerce_scalar_value(value)
3286
3316
  value.dup.tap do |val|
3287
- val.narrow_domain!(:==, ScalarValue.of(min_value..max_value))
3317
+ val.narrow_domain!(Operator::EQ, ScalarValue.of(min_value..max_value))
3288
3318
  end
3289
3319
  end
3290
3320
 
@@ -3548,6 +3578,10 @@ module C #:nodoc:
3548
3578
  subclass_responsibility
3549
3579
  end
3550
3580
 
3581
+ def standard?
3582
+ subclass_responsibility
3583
+ end
3584
+
3551
3585
  def bitfield?
3552
3586
  subclass_responsibility
3553
3587
  end
@@ -3666,6 +3700,10 @@ module C #:nodoc:
3666
3700
  false
3667
3701
  end
3668
3702
 
3703
+ def standard?
3704
+ true
3705
+ end
3706
+
3669
3707
  def bitfield?
3670
3708
  false
3671
3709
  end
@@ -4896,43 +4934,24 @@ module C #:nodoc:
4896
4934
  end
4897
4935
  end
4898
4936
 
4899
- class FloatingType < ScalarDataType
4900
- def initialize(type_table, name, bit_size, bit_alignment)
4901
- super(type_table, name, bit_size, bit_alignment)
4902
- end
4903
-
4904
- def id
4905
- subclass_responsibility
4906
- end
4937
+ class BitfieldType < IntegerType
4938
+ def initialize(type_table, base_type, field_width)
4939
+ super(type_table,
4940
+ "#{base_type.real_type.name}:#{field_width}",
4941
+ field_width, base_type.bit_alignment,
4942
+ base_type.signed?, base_type.explicitly_signed?)
4907
4943
 
4908
- def image
4909
- name
4944
+ @base_type = base_type
4910
4945
  end
4911
4946
 
4912
- def brief_image
4913
- name
4914
- end
4947
+ attr_reader :base_type
4915
4948
 
4916
- def location
4917
- nil
4949
+ def id
4950
+ @id ||= BitfieldTypeId.new(@base_type, bit_size)
4918
4951
  end
4919
4952
 
4920
4953
  def incomplete?
4921
- false
4922
- end
4923
-
4924
- def compatible?(to_type)
4925
- type.floating? &&
4926
- to_type.min_value <= self.min_value &&
4927
- self.max_value <= to_type.max_value
4928
- end
4929
-
4930
- def integer?
4931
- false
4932
- end
4933
-
4934
- def floating?
4935
- true
4954
+ @base_type.incomplete?
4936
4955
  end
4937
4956
 
4938
4957
  def pointer?
@@ -4943,44 +4962,63 @@ module C #:nodoc:
4943
4962
  false
4944
4963
  end
4945
4964
 
4946
- def bitfield?
4965
+ def standard?
4947
4966
  false
4948
4967
  end
4949
4968
 
4950
- def signed?
4951
- true
4952
- end
4953
-
4954
- def explicitly_signed?
4969
+ def bitfield?
4955
4970
  true
4956
4971
  end
4957
4972
 
4958
- def enumerators
4959
- []
4973
+ def undeclared?
4974
+ @base_type.undeclared?
4960
4975
  end
4961
4976
 
4962
- def min_value
4963
- (-2**fraction_bit_size * 10**(exponent_bit_size - 1)).to_f
4977
+ def unresolved?
4978
+ @base_type.unresolved?
4964
4979
  end
4965
4980
 
4966
- def max_value
4967
- (2**fraction_bit_size * 10**(exponent_bit_size - 1)).to_f
4981
+ def enumerators
4982
+ []
4968
4983
  end
4969
4984
 
4970
4985
  def integer_conversion_rank
4971
- 0 # NOTREACHED
4986
+ -1
4972
4987
  end
4973
4988
 
4974
4989
  def integer_promoted_type
4975
- self # NOTREACHED
4976
- end
4977
-
4978
- def argument_promoted_type
4979
- subclass_responsibility
4990
+ # TODO: Should support the C99 _Bool type.
4991
+ # NOTE: The ISO C99 standard saids;
4992
+ #
4993
+ # 6.3.1 Arithmetic operands
4994
+ # 6.3.1.1 Boolean, characters, and integers
4995
+ #
4996
+ # 2 The following may be used in an expression wherever an int or
4997
+ # unsigned int may be used:
4998
+ #
4999
+ # -- An object or expression with an integer type whose integer
5000
+ # conversion rank is less than or equal to the rank of int and
5001
+ # unsigned int.
5002
+ # -- A bit-field of type _Bool, int, signed int, or unsigned int.
5003
+ #
5004
+ # If an int can represent all values of the original type, the value is
5005
+ # converted to an int; otherwise, it is converted to an unsigned int.
5006
+ # These are called the integer promotions. All other types are
5007
+ # unchanged by the integer promotions.
5008
+ if self.undeclared? || self.unresolved?
5009
+ self
5010
+ else
5011
+ if @base_type.same_as?(int_type) ||
5012
+ @base_type.same_as?(unsigned_int_type)
5013
+ self.compatible?(int_type) ? int_type : unsigned_int_type
5014
+ else
5015
+ self
5016
+ end
5017
+ end
4980
5018
  end
4981
5019
 
4982
5020
  def arithmetic_type_with(type)
4983
- subclass_responsibility
5021
+ type._arithmetic_type_with_bitfield(self)
4984
5022
  end
4985
5023
 
4986
5024
  def corresponding_signed_type
@@ -4990,348 +5028,127 @@ module C #:nodoc:
4990
5028
  def corresponding_unsigned_type
4991
5029
  self # NOTREACHED
4992
5030
  end
5031
+ end
4993
5032
 
4994
- private
4995
- def fraction_bit_size
4996
- subclass_responsibility
5033
+ class BitfieldTypeId < TypeId
5034
+ def initialize(base_type, field_width)
5035
+ super(create_value(base_type, field_width))
4997
5036
  end
4998
5037
 
4999
- def exponent_bit_size
5000
- subclass_responsibility
5038
+ private
5039
+ def create_value(base_type, field_width)
5040
+ "#{base_type.real_type.name.split(" ").sort.join(" ")}:#{field_width}"
5001
5041
  end
5002
5042
  end
5003
5043
 
5004
- class FloatType < FloatingType
5044
+ module Scopeable
5045
+ attr_accessor :scope
5046
+ end
5047
+
5048
+ class EnumType < IntegerType
5049
+ include Scopeable
5005
5050
  include StandardTypeAccessor
5006
5051
 
5007
- def initialize(type_table)
5008
- super(type_table, "float", float_size, float_alignment)
5052
+ def initialize(type_table, enum_type_declaration)
5053
+ super(type_table, enum_type_declaration.identifier.value,
5054
+ int_size, int_alignment, true, true, [enum_type_declaration])
5055
+
5056
+ @image = enum_type_declaration.enum_specifier.to_s
5057
+ @location = enum_type_declaration.location
5009
5058
  end
5010
5059
 
5060
+ attr_accessor :image
5061
+ attr_accessor :location
5062
+
5011
5063
  def id
5012
- @id ||= FloatTypeId.new
5064
+ @id ||= EnumTypeId.new(name)
5013
5065
  end
5014
5066
 
5015
- def argument_promoted_type
5016
- # NOTE: The ISO C99 standard saids;
5017
- #
5018
- # 6.5.2.2 Function calls
5019
- #
5020
- # 6 If the expression that denotes the called function has a type that
5021
- # does not include a prototype, the integer promotions are performed on
5022
- # each argument, and arguments that have type float are promoted to
5023
- # double. These are called the default argument promotions. If the
5024
- # number of arguments does not equal the number of parameters, the
5025
- # behavior is undefined. If the function is defined with a type that
5026
- # includes a prototype, and either the prototype ends with an ellipsis
5027
- # (, ...) or the types of the arguments after promotion are not
5028
- # compatible with the types of the parameters, the behavior is
5029
- # undefined. If the function is defined with a type that does not
5030
- # include a prototype, and the types of the arguments after promotion
5031
- # are not compatible with those of the parameters after promotion, the
5032
- # behavior is undefined, except for the following cases:
5033
- #
5034
- # -- one promoted type is a signed integer type, the other promoted
5035
- # type is the corresponding unsigned integer type, and the value
5036
- # is representable in both types;
5037
- # -- both types are pointers to qualified or unqualified versions of
5038
- # a character type or void.
5039
- double_type
5067
+ def incomplete?
5068
+ declarations.all? { |decl| decl.enumerators.nil? }
5040
5069
  end
5041
5070
 
5042
- def arithmetic_type_with(type)
5043
- type._arithmetic_type_with_float(self)
5071
+ def pointer?
5072
+ false
5044
5073
  end
5045
5074
 
5046
- private
5047
- def fraction_bit_size
5048
- # TODO: Bit size of the fraction part of `float' should be configurable.
5049
- 23
5075
+ def enum?
5076
+ true
5050
5077
  end
5051
5078
 
5052
- def exponent_bit_size
5053
- # TODO: Bit size of the exponent part of `float' should be configurable.
5054
- 8
5079
+ def standard?
5080
+ false
5055
5081
  end
5056
- end
5057
5082
 
5058
- class FloatTypeId < StandardTypeId
5059
- def initialize
5060
- super("float")
5083
+ def bitfield?
5084
+ false
5061
5085
  end
5062
- end
5063
5086
 
5064
- class DoubleType < FloatingType
5065
- include StandardTypeAccessor
5087
+ def brief_image
5088
+ "enum #{name}"
5089
+ end
5066
5090
 
5067
- def initialize(type_table)
5068
- super(type_table, "double", double_size, double_alignment)
5091
+ def enumerators
5092
+ declarations.map { |decl| decl.enumerators }.compact.flatten.uniq
5069
5093
  end
5070
5094
 
5071
- def id
5072
- @id ||= DoubleTypeId.new
5095
+ def integer_conversion_rank
5096
+ # NOTE: The ISO C99 standard saids;
5097
+ #
5098
+ # 6.3.1 Arithmetic operands
5099
+ # 6.3.1.1 Boolean, characters, and integers
5100
+ #
5101
+ # 1 Every integer type has an integer conversion rank defined as follows:
5102
+ #
5103
+ # -- No two signed integer types shall have the same rank, even if
5104
+ # they have the same representation.
5105
+ # -- The rank of a signed integer type shall be greater than the rank
5106
+ # of any signed integer type with less precision.
5107
+ # -- The rank of long long int shall be greater than the rank of long
5108
+ # int, which shall be greater than the rank of int, which shall be
5109
+ # greater than the rank of short int, which shall be greater than
5110
+ # the rank of signed char.
5111
+ # -- The rank of any unsigned integer type shall equal the rank of
5112
+ # the corresponding signed integer type, if any.
5113
+ # -- The rank of any standard integer type shall be greater than the
5114
+ # rank of any extended integer type with the same width.
5115
+ # -- The rank of char shall equal the rank of signed char and
5116
+ # unsigned char.
5117
+ # -- The rank of _Bool shall be less than the rank of all other
5118
+ # standard integer types.
5119
+ # -- The rank of any enumerated type shall equal the rank of the
5120
+ # compatible integer type.
5121
+ # -- The rank of any extended signed integer type relative to another
5122
+ # extended signed integer type with the same precision is
5123
+ # implementation-defined, but still subject to the other rules for
5124
+ # determining the integer conversion rank.
5125
+ # -- For all integer types T1, T2, and T3, if T1 has greater rank
5126
+ # than T2 and T2 has greater rank than T3, then T1 has greater
5127
+ # rank than T3.
5128
+ #
5129
+ # NOTE: The integer conversion rank of any enumerated type is equal to
5130
+ # the rank of int.
5131
+ int_type.integer_conversion_rank
5073
5132
  end
5074
5133
 
5075
- def argument_promoted_type
5134
+ def integer_promoted_type
5135
+ # NOTE: Any enumerated type should be treated as `int'.
5136
+ # But AdLint internally treats enumerated type as itself, and omits
5137
+ # integer-promotion of any enumerated type in order not to
5138
+ # over-warn about enum-enum expressions like below;
5139
+ #
5140
+ # static void foo(enum Color c)
5141
+ # {
5142
+ # if (c == RED) { /* No usual-arithmetic-conversion of
5143
+ # enumerated types and no W9003 warning */
5144
+ # ...
5145
+ # }
5146
+ # }
5076
5147
  self
5077
5148
  end
5078
5149
 
5079
5150
  def arithmetic_type_with(type)
5080
- type._arithmetic_type_with_double(self)
5081
- end
5082
-
5083
- private
5084
- def fraction_bit_size
5085
- # TODO: Bit size of the fraction part of `double' should be configurable.
5086
- 52
5087
- end
5088
-
5089
- def exponent_bit_size
5090
- # TODO: Bit size of the exponent part of `double' should be configurable.
5091
- 11
5092
- end
5093
- end
5094
-
5095
- class DoubleTypeId < StandardTypeId
5096
- def initialize
5097
- super("double")
5098
- end
5099
- end
5100
-
5101
- class LongDoubleType < FloatingType
5102
- include StandardTypeAccessor
5103
-
5104
- def initialize(type_table)
5105
- super(type_table, "long double", long_double_size, long_double_alignment)
5106
- end
5107
-
5108
- def id
5109
- @id ||= LongDoubleTypeId.new
5110
- end
5111
-
5112
- def argument_promoted_type
5113
- self
5114
- end
5115
-
5116
- def arithmetic_type_with(type)
5117
- type._arithmetic_type_with_long_double(self)
5118
- end
5119
-
5120
- private
5121
- def fraction_bit_size
5122
- # TODO: Bit size of the fraction part of `long double' should be
5123
- # configurable.
5124
- 52
5125
- end
5126
-
5127
- def exponent_bit_size
5128
- # TODO: Bit size of the exponent part of `long double' should be
5129
- # configurable.
5130
- 11
5131
- end
5132
- end
5133
-
5134
- class LongDoubleTypeId < StandardTypeId
5135
- def initialize
5136
- super("long double")
5137
- end
5138
- end
5139
-
5140
- class BitfieldType < IntegerType
5141
- def initialize(type_table, base_type, field_width)
5142
- super(type_table,
5143
- "#{base_type.real_type.name}:#{field_width}",
5144
- field_width, base_type.bit_alignment,
5145
- base_type.signed?, base_type.explicitly_signed?)
5146
-
5147
- @base_type = base_type
5148
- end
5149
-
5150
- attr_reader :base_type
5151
-
5152
- def id
5153
- @id ||= BitfieldTypeId.new(@base_type, bit_size)
5154
- end
5155
-
5156
- def incomplete?
5157
- @base_type.incomplete?
5158
- end
5159
-
5160
- def pointer?
5161
- false
5162
- end
5163
-
5164
- def enum?
5165
- false
5166
- end
5167
-
5168
- def bitfield?
5169
- true
5170
- end
5171
-
5172
- def undeclared?
5173
- @base_type.undeclared?
5174
- end
5175
-
5176
- def unresolved?
5177
- @base_type.unresolved?
5178
- end
5179
-
5180
- def enumerators
5181
- []
5182
- end
5183
-
5184
- def integer_conversion_rank
5185
- -1
5186
- end
5187
-
5188
- def integer_promoted_type
5189
- # TODO: Should support the C99 _Bool type.
5190
- # NOTE: The ISO C99 standard saids;
5191
- #
5192
- # 6.3.1 Arithmetic operands
5193
- # 6.3.1.1 Boolean, characters, and integers
5194
- #
5195
- # 2 The following may be used in an expression wherever an int or
5196
- # unsigned int may be used:
5197
- #
5198
- # -- An object or expression with an integer type whose integer
5199
- # conversion rank is less than or equal to the rank of int and
5200
- # unsigned int.
5201
- # -- A bit-field of type _Bool, int, signed int, or unsigned int.
5202
- #
5203
- # If an int can represent all values of the original type, the value is
5204
- # converted to an int; otherwise, it is converted to an unsigned int.
5205
- # These are called the integer promotions. All other types are
5206
- # unchanged by the integer promotions.
5207
- if self.undeclared? || self.unresolved?
5208
- self
5209
- else
5210
- if @base_type.same_as?(int_type) ||
5211
- @base_type.same_as?(unsigned_int_type)
5212
- self.compatible?(int_type) ? int_type : unsigned_int_type
5213
- else
5214
- self
5215
- end
5216
- end
5217
- end
5218
-
5219
- def arithmetic_type_with(type)
5220
- type._arithmetic_type_with_bitfield(self)
5221
- end
5222
-
5223
- def corresponding_signed_type
5224
- self # NOTREACHED
5225
- end
5226
-
5227
- def corresponding_unsigned_type
5228
- self # NOTREACHED
5229
- end
5230
- end
5231
-
5232
- class BitfieldTypeId < TypeId
5233
- def initialize(base_type, field_width)
5234
- super(create_value(base_type, field_width))
5235
- end
5236
-
5237
- private
5238
- def create_value(base_type, field_width)
5239
- "#{base_type.real_type.name.split(" ").sort.join(" ")}:#{field_width}"
5240
- end
5241
- end
5242
-
5243
- module Scopeable
5244
- attr_accessor :scope
5245
- end
5246
-
5247
- class EnumType < IntegerType
5248
- include Scopeable
5249
- include StandardTypeAccessor
5250
-
5251
- def initialize(type_table, enum_type_declaration)
5252
- super(type_table, enum_type_declaration.identifier.value,
5253
- int_size, int_alignment, true, true, [enum_type_declaration])
5254
-
5255
- @image = enum_type_declaration.enum_specifier.to_s
5256
- @location = enum_type_declaration.location
5257
- end
5258
-
5259
- attr_accessor :image
5260
- attr_accessor :location
5261
-
5262
- def id
5263
- @id ||= EnumTypeId.new(name)
5264
- end
5265
-
5266
- def incomplete?
5267
- declarations.all? { |decl| decl.enumerators.nil? }
5268
- end
5269
-
5270
- def pointer?
5271
- false
5272
- end
5273
-
5274
- def enum?
5275
- true
5276
- end
5277
-
5278
- def bitfield?
5279
- false
5280
- end
5281
-
5282
- def brief_image
5283
- "enum #{name}"
5284
- end
5285
-
5286
- def enumerators
5287
- declarations.map { |decl| decl.enumerators }.compact.flatten.uniq
5288
- end
5289
-
5290
- def integer_conversion_rank
5291
- # NOTE: The ISO C99 standard saids;
5292
- #
5293
- # 6.3.1 Arithmetic operands
5294
- # 6.3.1.1 Boolean, characters, and integers
5295
- #
5296
- # 1 Every integer type has an integer conversion rank defined as follows:
5297
- #
5298
- # -- No two signed integer types shall have the same rank, even if
5299
- # they have the same representation.
5300
- # -- The rank of a signed integer type shall be greater than the rank
5301
- # of any signed integer type with less precision.
5302
- # -- The rank of long long int shall be greater than the rank of long
5303
- # int, which shall be greater than the rank of int, which shall be
5304
- # greater than the rank of short int, which shall be greater than
5305
- # the rank of signed char.
5306
- # -- The rank of any unsigned integer type shall equal the rank of
5307
- # the corresponding signed integer type, if any.
5308
- # -- The rank of any standard integer type shall be greater than the
5309
- # rank of any extended integer type with the same width.
5310
- # -- The rank of char shall equal the rank of signed char and
5311
- # unsigned char.
5312
- # -- The rank of _Bool shall be less than the rank of all other
5313
- # standard integer types.
5314
- # -- The rank of any enumerated type shall equal the rank of the
5315
- # compatible integer type.
5316
- # -- The rank of any extended signed integer type relative to another
5317
- # extended signed integer type with the same precision is
5318
- # implementation-defined, but still subject to the other rules for
5319
- # determining the integer conversion rank.
5320
- # -- For all integer types T1, T2, and T3, if T1 has greater rank
5321
- # than T2 and T2 has greater rank than T3, then T1 has greater
5322
- # rank than T3.
5323
- #
5324
- # NOTE: The integer conversion rank of any enumerated type is equal to
5325
- # the rank of int.
5326
- int_type.integer_conversion_rank
5327
- end
5328
-
5329
- def integer_promoted_type
5330
- int_type
5331
- end
5332
-
5333
- def arithmetic_type_with(type)
5334
- type._arithmetic_type_with_enum(self)
5151
+ type._arithmetic_type_with_enum(self)
5335
5152
  end
5336
5153
 
5337
5154
  def corresponding_signed_type
@@ -5409,6 +5226,10 @@ module C #:nodoc:
5409
5226
  false
5410
5227
  end
5411
5228
 
5229
+ def standard?
5230
+ false
5231
+ end
5232
+
5412
5233
  def undeclared?
5413
5234
  @base_type.undeclared?
5414
5235
  end
@@ -5518,6 +5339,253 @@ module C #:nodoc:
5518
5339
  end
5519
5340
  end
5520
5341
 
5342
+ class FloatingType < ScalarDataType
5343
+ def initialize(type_table, name, bit_size, bit_alignment)
5344
+ super(type_table, name, bit_size, bit_alignment)
5345
+ end
5346
+
5347
+ def id
5348
+ subclass_responsibility
5349
+ end
5350
+
5351
+ def image
5352
+ name
5353
+ end
5354
+
5355
+ def brief_image
5356
+ name
5357
+ end
5358
+
5359
+ def location
5360
+ nil
5361
+ end
5362
+
5363
+ def incomplete?
5364
+ false
5365
+ end
5366
+
5367
+ def compatible?(to_type)
5368
+ type.floating? &&
5369
+ to_type.min_value <= self.min_value &&
5370
+ self.max_value <= to_type.max_value
5371
+ end
5372
+
5373
+ def integer?
5374
+ false
5375
+ end
5376
+
5377
+ def floating?
5378
+ true
5379
+ end
5380
+
5381
+ def pointer?
5382
+ false
5383
+ end
5384
+
5385
+ def enum?
5386
+ false
5387
+ end
5388
+
5389
+ def bitfield?
5390
+ false
5391
+ end
5392
+
5393
+ def signed?
5394
+ true
5395
+ end
5396
+
5397
+ def explicitly_signed?
5398
+ true
5399
+ end
5400
+
5401
+ def enumerators
5402
+ []
5403
+ end
5404
+
5405
+ def min_value
5406
+ (-2**fraction_bit_size * 10**(exponent_bit_size - 1)).to_f
5407
+ end
5408
+
5409
+ def max_value
5410
+ (2**fraction_bit_size * 10**(exponent_bit_size - 1)).to_f
5411
+ end
5412
+
5413
+ def integer_conversion_rank
5414
+ 0 # NOTREACHED
5415
+ end
5416
+
5417
+ def integer_promoted_type
5418
+ self # NOTREACHED
5419
+ end
5420
+
5421
+ def argument_promoted_type
5422
+ subclass_responsibility
5423
+ end
5424
+
5425
+ def arithmetic_type_with(type)
5426
+ subclass_responsibility
5427
+ end
5428
+
5429
+ def corresponding_signed_type
5430
+ self # NOTREACHED
5431
+ end
5432
+
5433
+ def corresponding_unsigned_type
5434
+ self # NOTREACHED
5435
+ end
5436
+
5437
+ private
5438
+ def fraction_bit_size
5439
+ subclass_responsibility
5440
+ end
5441
+
5442
+ def exponent_bit_size
5443
+ subclass_responsibility
5444
+ end
5445
+ end
5446
+
5447
+ class StandardFloatingType < FloatingType
5448
+ def standard?
5449
+ true
5450
+ end
5451
+ end
5452
+
5453
+ class FloatType < StandardFloatingType
5454
+ include StandardTypeAccessor
5455
+
5456
+ def initialize(type_table)
5457
+ super(type_table, "float", float_size, float_alignment)
5458
+ end
5459
+
5460
+ def id
5461
+ @id ||= FloatTypeId.new
5462
+ end
5463
+
5464
+ def argument_promoted_type
5465
+ # NOTE: The ISO C99 standard saids;
5466
+ #
5467
+ # 6.5.2.2 Function calls
5468
+ #
5469
+ # 6 If the expression that denotes the called function has a type that
5470
+ # does not include a prototype, the integer promotions are performed on
5471
+ # each argument, and arguments that have type float are promoted to
5472
+ # double. These are called the default argument promotions. If the
5473
+ # number of arguments does not equal the number of parameters, the
5474
+ # behavior is undefined. If the function is defined with a type that
5475
+ # includes a prototype, and either the prototype ends with an ellipsis
5476
+ # (, ...) or the types of the arguments after promotion are not
5477
+ # compatible with the types of the parameters, the behavior is
5478
+ # undefined. If the function is defined with a type that does not
5479
+ # include a prototype, and the types of the arguments after promotion
5480
+ # are not compatible with those of the parameters after promotion, the
5481
+ # behavior is undefined, except for the following cases:
5482
+ #
5483
+ # -- one promoted type is a signed integer type, the other promoted
5484
+ # type is the corresponding unsigned integer type, and the value
5485
+ # is representable in both types;
5486
+ # -- both types are pointers to qualified or unqualified versions of
5487
+ # a character type or void.
5488
+ double_type
5489
+ end
5490
+
5491
+ def arithmetic_type_with(type)
5492
+ type._arithmetic_type_with_float(self)
5493
+ end
5494
+
5495
+ private
5496
+ def fraction_bit_size
5497
+ # TODO: Bit size of the fraction part of `float' should be configurable.
5498
+ 23
5499
+ end
5500
+
5501
+ def exponent_bit_size
5502
+ # TODO: Bit size of the exponent part of `float' should be configurable.
5503
+ 8
5504
+ end
5505
+ end
5506
+
5507
+ class FloatTypeId < StandardTypeId
5508
+ def initialize
5509
+ super("float")
5510
+ end
5511
+ end
5512
+
5513
+ class DoubleType < StandardFloatingType
5514
+ include StandardTypeAccessor
5515
+
5516
+ def initialize(type_table)
5517
+ super(type_table, "double", double_size, double_alignment)
5518
+ end
5519
+
5520
+ def id
5521
+ @id ||= DoubleTypeId.new
5522
+ end
5523
+
5524
+ def argument_promoted_type
5525
+ self
5526
+ end
5527
+
5528
+ def arithmetic_type_with(type)
5529
+ type._arithmetic_type_with_double(self)
5530
+ end
5531
+
5532
+ private
5533
+ def fraction_bit_size
5534
+ # TODO: Bit size of the fraction part of `double' should be configurable.
5535
+ 52
5536
+ end
5537
+
5538
+ def exponent_bit_size
5539
+ # TODO: Bit size of the exponent part of `double' should be configurable.
5540
+ 11
5541
+ end
5542
+ end
5543
+
5544
+ class DoubleTypeId < StandardTypeId
5545
+ def initialize
5546
+ super("double")
5547
+ end
5548
+ end
5549
+
5550
+ class LongDoubleType < StandardFloatingType
5551
+ include StandardTypeAccessor
5552
+
5553
+ def initialize(type_table)
5554
+ super(type_table, "long double", long_double_size, long_double_alignment)
5555
+ end
5556
+
5557
+ def id
5558
+ @id ||= LongDoubleTypeId.new
5559
+ end
5560
+
5561
+ def argument_promoted_type
5562
+ self
5563
+ end
5564
+
5565
+ def arithmetic_type_with(type)
5566
+ type._arithmetic_type_with_long_double(self)
5567
+ end
5568
+
5569
+ private
5570
+ def fraction_bit_size
5571
+ # TODO: Bit size of the fraction part of `long double' should be
5572
+ # configurable.
5573
+ 52
5574
+ end
5575
+
5576
+ def exponent_bit_size
5577
+ # TODO: Bit size of the exponent part of `long double' should be
5578
+ # configurable.
5579
+ 11
5580
+ end
5581
+ end
5582
+
5583
+ class LongDoubleTypeId < StandardTypeId
5584
+ def initialize
5585
+ super("long double")
5586
+ end
5587
+ end
5588
+
5521
5589
  class ArrayType < Type
5522
5590
  # NOTE: To avoid huge array allocation in interpreting phase.
5523
5591
  MAX_LENGTH = 256
@@ -5677,6 +5745,10 @@ module C #:nodoc:
5677
5745
  false
5678
5746
  end
5679
5747
 
5748
+ def standard?
5749
+ false
5750
+ end
5751
+
5680
5752
  def undeclared?
5681
5753
  @base_type.undeclared?
5682
5754
  end
@@ -6237,6 +6309,10 @@ module C #:nodoc:
6237
6309
  false
6238
6310
  end
6239
6311
 
6312
+ def standard?
6313
+ false
6314
+ end
6315
+
6240
6316
  def undeclared?
6241
6317
  @members.any? { |member| member.type.undeclared? }
6242
6318
  end
@@ -6807,6 +6883,11 @@ module C #:nodoc:
6807
6883
  end
6808
6884
 
6809
6885
  def_delegator :@base_type, :void?
6886
+
6887
+ def standard?
6888
+ false
6889
+ end
6890
+
6810
6891
  def_delegator :@base_type, :undeclared?
6811
6892
  def_delegator :@base_type, :unresolved?
6812
6893
  def_delegator :@base_type, :const?
@@ -6954,6 +7035,7 @@ module C #:nodoc:
6954
7035
  def_delegator :@type, :enum?
6955
7036
  def_delegator :@type, :user?
6956
7037
  def_delegator :@type, :void?
7038
+ def_delegator :@type, :standard?
6957
7039
  def_delegator :@type, :undeclared?
6958
7040
  def_delegator :@type, :unresolved?
6959
7041
  def_delegator :@type, :const?
@@ -7052,6 +7134,10 @@ module C #:nodoc:
7052
7134
  false
7053
7135
  end
7054
7136
 
7137
+ def standard?
7138
+ false
7139
+ end
7140
+
7055
7141
  def bitfield?
7056
7142
  false
7057
7143
  end