|
| 1 | +import cpp as default |
| 2 | + |
| 3 | +/* |
| 4 | + * Implementations of the C/C++ Fixed Width Types from cstdint. |
| 5 | + * |
| 6 | + * TODO: Deprecate once this is available in the CodeQL standard library. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * A parent class representing C/C++ a typedef'd `UserType` such as `int8_t`. |
| 11 | + */ |
| 12 | +abstract private class IntegralUnderlyingUserType extends default::UserType { |
| 13 | + IntegralUnderlyingUserType() { this.getUnderlyingType() instanceof default::IntegralType } |
| 14 | +} |
| 15 | + |
| 16 | +abstract private class TFixedWidthIntegralType extends IntegralUnderlyingUserType { } |
| 17 | + |
| 18 | +/** |
| 19 | + * A C/C++ fixed-width numeric type, such as `int8_t`. |
| 20 | + */ |
| 21 | +class FixedWidthIntegralType extends TFixedWidthIntegralType { |
| 22 | + FixedWidthIntegralType() { this instanceof TFixedWidthIntegralType } |
| 23 | +} |
| 24 | + |
| 25 | +abstract private class TMinimumWidthIntegralType extends IntegralUnderlyingUserType { } |
| 26 | + |
| 27 | +/** |
| 28 | + * A C/C++ minimum-width numeric type, such as `int_least8_t`. |
| 29 | + */ |
| 30 | +class MinimumWidthIntegralType extends TMinimumWidthIntegralType { |
| 31 | + MinimumWidthIntegralType() { this instanceof TMinimumWidthIntegralType } |
| 32 | +} |
| 33 | + |
| 34 | +abstract private class TFastestMinimumWidthIntegralType extends IntegralUnderlyingUserType { } |
| 35 | + |
| 36 | +/** |
| 37 | + * A C/C++ minimum-width numeric type, representing the fastest integer type with a |
| 38 | + * width of at least `N` such as `int_fast8_t`. |
| 39 | + */ |
| 40 | +class FastestMinimumWidthIntegralType extends TFastestMinimumWidthIntegralType { |
| 41 | + FastestMinimumWidthIntegralType() { this instanceof TFastestMinimumWidthIntegralType } |
| 42 | +} |
| 43 | + |
| 44 | +/** |
| 45 | + * An enum type based on a fixed-width integer type. For instance, `enum e: uint8_t = { a, b };` |
| 46 | + */ |
| 47 | +class FixedWidthEnumType extends default::UserType { |
| 48 | + FixedWidthEnumType() { |
| 49 | + this.(default::Enum).getExplicitUnderlyingType() instanceof FixedWidthIntegralType |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +/** |
| 54 | + * The C/C++ `int8_t` type. |
| 55 | + */ |
| 56 | +class Int8_t extends TFixedWidthIntegralType { |
| 57 | + Int8_t() { this.hasGlobalOrStdName("int8_t") } |
| 58 | + |
| 59 | + override string getAPrimaryQlClass() { result = "Int8_t" } |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * The C/C++ `int16_t` type. |
| 64 | + */ |
| 65 | +class Int16_t extends TFixedWidthIntegralType { |
| 66 | + Int16_t() { this.hasGlobalOrStdName("int16_t") } |
| 67 | + |
| 68 | + override string getAPrimaryQlClass() { result = "Int16_t" } |
| 69 | +} |
| 70 | + |
| 71 | +/** |
| 72 | + * The C/C++ `int32_t` type. |
| 73 | + */ |
| 74 | +class Int32_t extends TFixedWidthIntegralType { |
| 75 | + Int32_t() { this.hasGlobalOrStdName("int32_t") } |
| 76 | + |
| 77 | + override string getAPrimaryQlClass() { result = "Int32_t" } |
| 78 | +} |
| 79 | + |
| 80 | +/** |
| 81 | + * The C/C++ `int64_t` type. |
| 82 | + */ |
| 83 | +class Int64_t extends TFixedWidthIntegralType { |
| 84 | + Int64_t() { this.hasGlobalOrStdName("int64_t") } |
| 85 | + |
| 86 | + override string getAPrimaryQlClass() { result = "Int64_t" } |
| 87 | +} |
| 88 | + |
| 89 | +/** |
| 90 | + * The C/C++ `uint8_t` type. |
| 91 | + */ |
| 92 | +class UInt8_t extends TFixedWidthIntegralType { |
| 93 | + UInt8_t() { this.hasGlobalOrStdName("uint8_t") } |
| 94 | + |
| 95 | + override string getAPrimaryQlClass() { result = "UInt8_t" } |
| 96 | +} |
| 97 | + |
| 98 | +/** |
| 99 | + * The C/C++ `uint16_t` type. |
| 100 | + */ |
| 101 | +class UInt16_t extends TFixedWidthIntegralType { |
| 102 | + UInt16_t() { this.hasGlobalOrStdName("uint16_t") } |
| 103 | + |
| 104 | + override string getAPrimaryQlClass() { result = "UInt16_t" } |
| 105 | +} |
| 106 | + |
| 107 | +/** |
| 108 | + * The C/C++ `uint32_t` type. |
| 109 | + */ |
| 110 | +class UInt32_t extends TFixedWidthIntegralType { |
| 111 | + UInt32_t() { this.hasGlobalOrStdName("uint32_t") } |
| 112 | + |
| 113 | + override string getAPrimaryQlClass() { result = "UInt32_t" } |
| 114 | +} |
| 115 | + |
| 116 | +/** |
| 117 | + * The C/C++ `uint64_t` type. |
| 118 | + */ |
| 119 | +class UInt64_t extends TFixedWidthIntegralType { |
| 120 | + UInt64_t() { this.hasGlobalOrStdName("uint64_t") } |
| 121 | + |
| 122 | + override string getAPrimaryQlClass() { result = "UInt64_t" } |
| 123 | +} |
| 124 | + |
| 125 | +/** |
| 126 | + * The C/C++ `int_least8_t` type. |
| 127 | + */ |
| 128 | +class Int_least8_t extends TMinimumWidthIntegralType { |
| 129 | + Int_least8_t() { this.hasGlobalOrStdName("int_least8_t") } |
| 130 | + |
| 131 | + override string getAPrimaryQlClass() { result = "Int_least8_t" } |
| 132 | +} |
| 133 | + |
| 134 | +/** |
| 135 | + * The C/C++ `int_least16_t` type. |
| 136 | + */ |
| 137 | +class Int_least16_t extends TMinimumWidthIntegralType { |
| 138 | + Int_least16_t() { this.hasGlobalOrStdName("int_least16_t") } |
| 139 | + |
| 140 | + override string getAPrimaryQlClass() { result = "Int_least16_t" } |
| 141 | +} |
| 142 | + |
| 143 | +/** |
| 144 | + * The C/C++ `int_least32_t` type. |
| 145 | + */ |
| 146 | +class Int_least32_t extends TMinimumWidthIntegralType { |
| 147 | + Int_least32_t() { this.hasGlobalOrStdName("int_least32_t") } |
| 148 | + |
| 149 | + override string getAPrimaryQlClass() { result = "Int_least32_t" } |
| 150 | +} |
| 151 | + |
| 152 | +/** |
| 153 | + * The C/C++ `int_least64_t` type. |
| 154 | + */ |
| 155 | +class Int_least64_t extends TMinimumWidthIntegralType { |
| 156 | + Int_least64_t() { this.hasGlobalOrStdName("int_least64_t") } |
| 157 | + |
| 158 | + override string getAPrimaryQlClass() { result = "Int_least64_t" } |
| 159 | +} |
| 160 | + |
| 161 | +/** |
| 162 | + * The C/C++ `uint_least8_t` type. |
| 163 | + */ |
| 164 | +class UInt_least8_t extends TMinimumWidthIntegralType { |
| 165 | + UInt_least8_t() { this.hasGlobalOrStdName("uint_least8_t") } |
| 166 | + |
| 167 | + override string getAPrimaryQlClass() { result = "UInt_least8_t" } |
| 168 | +} |
| 169 | + |
| 170 | +/** |
| 171 | + * The C/C++ `uint_least16_t` type. |
| 172 | + */ |
| 173 | +class UInt_least16_t extends TMinimumWidthIntegralType { |
| 174 | + UInt_least16_t() { this.hasGlobalOrStdName("uint_least16_t") } |
| 175 | + |
| 176 | + override string getAPrimaryQlClass() { result = "UInt_least16_t" } |
| 177 | +} |
| 178 | + |
| 179 | +/** |
| 180 | + * The C/C++ `uint_least32_t` type. |
| 181 | + */ |
| 182 | +class UInt_least32_t extends TMinimumWidthIntegralType { |
| 183 | + UInt_least32_t() { this.hasGlobalOrStdName("uint_least32_t") } |
| 184 | + |
| 185 | + override string getAPrimaryQlClass() { result = "UInt_least32_t" } |
| 186 | +} |
| 187 | + |
| 188 | +/** |
| 189 | + * The C/C++ `uint_least64_t` type. |
| 190 | + */ |
| 191 | +class UInt_least64_t extends TMinimumWidthIntegralType { |
| 192 | + UInt_least64_t() { this.hasGlobalOrStdName("uint_least64_t") } |
| 193 | + |
| 194 | + override string getAPrimaryQlClass() { result = "UInt_least64_t" } |
| 195 | +} |
| 196 | + |
| 197 | +/** |
| 198 | + * The C/C++ `int_fast8_t` type. |
| 199 | + */ |
| 200 | +class Int_fast8_t extends TFastestMinimumWidthIntegralType { |
| 201 | + Int_fast8_t() { this.hasGlobalOrStdName("int_fast8_t") } |
| 202 | + |
| 203 | + override string getAPrimaryQlClass() { result = "Int_fast8_t" } |
| 204 | +} |
| 205 | + |
| 206 | +/** |
| 207 | + * The C/C++ `int_fast16_t` type. |
| 208 | + */ |
| 209 | +class Int_fast16_t extends TFastestMinimumWidthIntegralType { |
| 210 | + Int_fast16_t() { this.hasGlobalOrStdName("int_fast16_t") } |
| 211 | + |
| 212 | + override string getAPrimaryQlClass() { result = "Int_fast16_t" } |
| 213 | +} |
| 214 | + |
| 215 | +/** |
| 216 | + * The C/C++ `int_fast32_t` type. |
| 217 | + */ |
| 218 | +class Int_fast32_t extends TFastestMinimumWidthIntegralType { |
| 219 | + Int_fast32_t() { this.hasGlobalOrStdName("int_fast32_t") } |
| 220 | + |
| 221 | + override string getAPrimaryQlClass() { result = "Int_fast32_t" } |
| 222 | +} |
| 223 | + |
| 224 | +/** |
| 225 | + * The C/C++ `int_fast64_t` type. |
| 226 | + */ |
| 227 | +class Int_fast64_t extends TFastestMinimumWidthIntegralType { |
| 228 | + Int_fast64_t() { this.hasGlobalOrStdName("int_fast64_t") } |
| 229 | + |
| 230 | + override string getAPrimaryQlClass() { result = "Int_fast64_t" } |
| 231 | +} |
| 232 | + |
| 233 | +/** |
| 234 | + * The C/C++ `uint_fast8_t` type. |
| 235 | + */ |
| 236 | +class UInt_fast8_t extends TFastestMinimumWidthIntegralType { |
| 237 | + UInt_fast8_t() { this.hasGlobalOrStdName("uint_fast8_t") } |
| 238 | + |
| 239 | + override string getAPrimaryQlClass() { result = "UInt_fast8_t" } |
| 240 | +} |
| 241 | + |
| 242 | +/** |
| 243 | + * The C/C++ `uint_fast16_t` type. |
| 244 | + */ |
| 245 | +class UInt_fast16_t extends TFastestMinimumWidthIntegralType { |
| 246 | + UInt_fast16_t() { this.hasGlobalOrStdName("uint_fast16_t") } |
| 247 | + |
| 248 | + override string getAPrimaryQlClass() { result = "UInt_fast16_t" } |
| 249 | +} |
| 250 | + |
| 251 | +/** |
| 252 | + * The C/C++ `uint_fast32_t` type. |
| 253 | + */ |
| 254 | +class UInt_fast32_t extends TFastestMinimumWidthIntegralType { |
| 255 | + UInt_fast32_t() { this.hasGlobalOrStdName("uint_fast32_t") } |
| 256 | + |
| 257 | + override string getAPrimaryQlClass() { result = "UInt_fast32_t" } |
| 258 | +} |
| 259 | + |
| 260 | +/** |
| 261 | + * The C/C++ `uint_fast64_t` type. |
| 262 | + */ |
| 263 | +class UInt_fast64_t extends TFastestMinimumWidthIntegralType { |
| 264 | + UInt_fast64_t() { this.hasGlobalOrStdName("uint_fast64_t") } |
| 265 | + |
| 266 | + override string getAPrimaryQlClass() { result = "UInt_fast64_t" } |
| 267 | +} |
| 268 | + |
| 269 | +/** |
| 270 | + * Type that models a type that is either a pointer or a reference type. |
| 271 | + */ |
| 272 | +class PointerOrReferenceType extends default::DerivedType { |
| 273 | + PointerOrReferenceType() { |
| 274 | + this instanceof default::PointerType or |
| 275 | + this instanceof default::ReferenceType |
| 276 | + } |
| 277 | +} |
| 278 | + |
| 279 | +/** |
| 280 | + * Type that models a char type that is explicitly signed or unsigned. |
| 281 | + */ |
| 282 | +class ExplictlySignedOrUnsignedCharType extends default::CharType { |
| 283 | + ExplictlySignedOrUnsignedCharType() { |
| 284 | + isExplicitlySigned() or |
| 285 | + isExplicitlyUnsigned() |
| 286 | + } |
| 287 | +} |
0 commit comments