Skip to content

Commit 2a01324

Browse files
committed
more maintainable pattern for class abstractions
1 parent bd7c416 commit 2a01324

File tree

1 file changed

+42
-64
lines changed

1 file changed

+42
-64
lines changed

cpp/ql/src/semmle/code/cpp/commons/CommonType.qll

Lines changed: 42 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -73,60 +73,38 @@ private class IntegralUnderlyingUserType extends UserType {
7373
/**
7474
* A C/C++ fixed-width numeric type, such as `int8_t`.
7575
*/
76-
class FixedWidthIntegralType extends UserType {
77-
FixedWidthIntegralType() {
78-
this instanceof Int8_t or
79-
this instanceof Int16_t or
80-
this instanceof Int32_t or
81-
this instanceof Int64_t or
82-
this instanceof UInt8_t or
83-
this instanceof UInt16_t or
84-
this instanceof UInt32_t or
85-
this instanceof UInt64_t
86-
}
76+
abstract private class TFixedWidthIntegralType extends IntegralUnderlyingUserType { }
77+
78+
class FixedWidthIntegralType extends TFixedWidthIntegralType {
79+
FixedWidthIntegralType() { this instanceof TFixedWidthIntegralType }
8780
}
8881

8982
/**
9083
* A C/C++ minimum-width numeric type, such as `int_least8_t`.
9184
*/
92-
class MinimumWidthIntegralType extends UserType {
93-
MinimumWidthIntegralType() {
94-
this instanceof Int_least8_t or
95-
this instanceof Int_least16_t or
96-
this instanceof Int_least32_t or
97-
this instanceof Int_least64_t or
98-
this instanceof UInt_least8_t or
99-
this instanceof UInt_least16_t or
100-
this instanceof UInt_least32_t or
101-
this instanceof UInt_least64_t
102-
}
85+
abstract private class TMinimumWidthIntegralType extends IntegralUnderlyingUserType { }
86+
87+
class MinimumWidthIntegralType extends TMinimumWidthIntegralType {
88+
MinimumWidthIntegralType() { this instanceof TMinimumWidthIntegralType }
10389
}
10490

10591
/**
10692
* A C/C++ minimum-width numeric type, representing the fastest integer type with a
10793
* width of at least `N` such as `int_fast8_t`.
10894
*/
109-
class FastestMinimumWidthIntegralType extends UserType {
110-
FastestMinimumWidthIntegralType() {
111-
this instanceof Int_fast8_t or
112-
this instanceof Int_fast16_t or
113-
this instanceof Int_fast32_t or
114-
this instanceof Int_fast64_t or
115-
this instanceof UInt_fast8_t or
116-
this instanceof UInt_fast16_t or
117-
this instanceof UInt_fast32_t or
118-
this instanceof UInt_fast64_t
119-
}
95+
abstract private class TFastestMinimumWidthIntegralType extends IntegralUnderlyingUserType { }
96+
97+
class FastestMinimumWidthIntegralType extends TFastestMinimumWidthIntegralType {
98+
FastestMinimumWidthIntegralType() { this instanceof TFastestMinimumWidthIntegralType }
12099
}
121100

122101
/**
123102
* A C/C++ maximum-width numeric type, either `intmax_t` or `uintmax_t`.
124103
*/
125-
class MaximumWidthIntegralType extends UserType {
126-
MaximumWidthIntegralType() {
127-
this instanceof Intmax_t or
128-
this instanceof Uintmax_t
129-
}
104+
abstract private class TMaximumWidthIntegralType extends IntegralUnderlyingUserType { }
105+
106+
class MaximumWidthIntegralType extends TMaximumWidthIntegralType {
107+
MaximumWidthIntegralType() { this instanceof TMaximumWidthIntegralType }
130108
}
131109

132110
/**
@@ -139,7 +117,7 @@ class FixedWidthEnumType extends UserType {
139117
/**
140118
* The C/C++ `int8_t` type.
141119
*/
142-
class Int8_t extends IntegralUnderlyingUserType {
120+
class Int8_t extends TFixedWidthIntegralType {
143121
Int8_t() { this.hasGlobalOrStdName("int8_t") }
144122

145123
override string getAPrimaryQlClass() { result = "Int8_t" }
@@ -148,7 +126,7 @@ class Int8_t extends IntegralUnderlyingUserType {
148126
/**
149127
* The C/C++ `int16_t` type.
150128
*/
151-
class Int16_t extends IntegralUnderlyingUserType {
129+
class Int16_t extends TFixedWidthIntegralType {
152130
Int16_t() { this.hasGlobalOrStdName("int16_t") }
153131

154132
override string getAPrimaryQlClass() { result = "Int16_t" }
@@ -157,7 +135,7 @@ class Int16_t extends IntegralUnderlyingUserType {
157135
/**
158136
* The C/C++ `int32_t` type.
159137
*/
160-
class Int32_t extends IntegralUnderlyingUserType {
138+
class Int32_t extends TFixedWidthIntegralType {
161139
Int32_t() { this.hasGlobalOrStdName("int32_t") }
162140

163141
override string getAPrimaryQlClass() { result = "Int32_t" }
@@ -166,7 +144,7 @@ class Int32_t extends IntegralUnderlyingUserType {
166144
/**
167145
* The C/C++ `int64_t` type.
168146
*/
169-
class Int64_t extends IntegralUnderlyingUserType {
147+
class Int64_t extends TFixedWidthIntegralType {
170148
Int64_t() { this.hasGlobalOrStdName("int64_t") }
171149

172150
override string getAPrimaryQlClass() { result = "Int64_t" }
@@ -175,7 +153,7 @@ class Int64_t extends IntegralUnderlyingUserType {
175153
/**
176154
* The C/C++ `uint8_t` type.
177155
*/
178-
class UInt8_t extends IntegralUnderlyingUserType {
156+
class UInt8_t extends TFixedWidthIntegralType {
179157
UInt8_t() { this.hasGlobalOrStdName("uint8_t") }
180158

181159
override string getAPrimaryQlClass() { result = "UInt8_t" }
@@ -184,7 +162,7 @@ class UInt8_t extends IntegralUnderlyingUserType {
184162
/**
185163
* The C/C++ `uint16_t` type.
186164
*/
187-
class UInt16_t extends IntegralUnderlyingUserType {
165+
class UInt16_t extends TFixedWidthIntegralType {
188166
UInt16_t() { this.hasGlobalOrStdName("uint16_t") }
189167

190168
override string getAPrimaryQlClass() { result = "UInt16_t" }
@@ -193,7 +171,7 @@ class UInt16_t extends IntegralUnderlyingUserType {
193171
/**
194172
* The C/C++ `uint32_t` type.
195173
*/
196-
class UInt32_t extends IntegralUnderlyingUserType {
174+
class UInt32_t extends TFixedWidthIntegralType {
197175
UInt32_t() { this.hasGlobalOrStdName("uint32_t") }
198176

199177
override string getAPrimaryQlClass() { result = "UInt32_t" }
@@ -202,7 +180,7 @@ class UInt32_t extends IntegralUnderlyingUserType {
202180
/**
203181
* The C/C++ `uint64_t` type.
204182
*/
205-
class UInt64_t extends IntegralUnderlyingUserType {
183+
class UInt64_t extends TFixedWidthIntegralType {
206184
UInt64_t() { this.hasGlobalOrStdName("uint64_t") }
207185

208186
override string getAPrimaryQlClass() { result = "UInt64_t" }
@@ -211,7 +189,7 @@ class UInt64_t extends IntegralUnderlyingUserType {
211189
/**
212190
* The C/C++ `int_least8_t` type.
213191
*/
214-
class Int_least8_t extends IntegralUnderlyingUserType {
192+
class Int_least8_t extends TMinimumWidthIntegralType {
215193
Int_least8_t() { this.hasGlobalOrStdName("int_least8_t") }
216194

217195
override string getAPrimaryQlClass() { result = "Int_least8_t" }
@@ -220,7 +198,7 @@ class Int_least8_t extends IntegralUnderlyingUserType {
220198
/**
221199
* The C/C++ `int_least16_t` type.
222200
*/
223-
class Int_least16_t extends IntegralUnderlyingUserType {
201+
class Int_least16_t extends TMinimumWidthIntegralType {
224202
Int_least16_t() { this.hasGlobalOrStdName("int_least16_t") }
225203

226204
override string getAPrimaryQlClass() { result = "Int_least16_t" }
@@ -229,7 +207,7 @@ class Int_least16_t extends IntegralUnderlyingUserType {
229207
/**
230208
* The C/C++ `int_least32_t` type.
231209
*/
232-
class Int_least32_t extends IntegralUnderlyingUserType {
210+
class Int_least32_t extends TMinimumWidthIntegralType {
233211
Int_least32_t() { this.hasGlobalOrStdName("int_least32_t") }
234212

235213
override string getAPrimaryQlClass() { result = "Int_least32_t" }
@@ -238,7 +216,7 @@ class Int_least32_t extends IntegralUnderlyingUserType {
238216
/**
239217
* The C/C++ `int_least64_t` type.
240218
*/
241-
class Int_least64_t extends IntegralUnderlyingUserType {
219+
class Int_least64_t extends TMinimumWidthIntegralType {
242220
Int_least64_t() { this.hasGlobalOrStdName("int_least64_t") }
243221

244222
override string getAPrimaryQlClass() { result = "Int_least64_t" }
@@ -247,7 +225,7 @@ class Int_least64_t extends IntegralUnderlyingUserType {
247225
/**
248226
* The C/C++ `uint_least8_t` type.
249227
*/
250-
class UInt_least8_t extends IntegralUnderlyingUserType {
228+
class UInt_least8_t extends TMinimumWidthIntegralType {
251229
UInt_least8_t() { this.hasGlobalOrStdName("uint_least8_t") }
252230

253231
override string getAPrimaryQlClass() { result = "UInt_least8_t" }
@@ -256,7 +234,7 @@ class UInt_least8_t extends IntegralUnderlyingUserType {
256234
/**
257235
* The C/C++ `uint_least16_t` type.
258236
*/
259-
class UInt_least16_t extends IntegralUnderlyingUserType {
237+
class UInt_least16_t extends TMinimumWidthIntegralType {
260238
UInt_least16_t() { this.hasGlobalOrStdName("uint_least16_t") }
261239

262240
override string getAPrimaryQlClass() { result = "UInt_least16_t" }
@@ -265,7 +243,7 @@ class UInt_least16_t extends IntegralUnderlyingUserType {
265243
/**
266244
* The C/C++ `uint_least32_t` type.
267245
*/
268-
class UInt_least32_t extends IntegralUnderlyingUserType {
246+
class UInt_least32_t extends TMinimumWidthIntegralType {
269247
UInt_least32_t() { this.hasGlobalOrStdName("uint_least32_t") }
270248

271249
override string getAPrimaryQlClass() { result = "UInt_least32_t" }
@@ -274,7 +252,7 @@ class UInt_least32_t extends IntegralUnderlyingUserType {
274252
/**
275253
* The C/C++ `uint_least64_t` type.
276254
*/
277-
class UInt_least64_t extends IntegralUnderlyingUserType {
255+
class UInt_least64_t extends TMinimumWidthIntegralType {
278256
UInt_least64_t() { this.hasGlobalOrStdName("uint_least64_t") }
279257

280258
override string getAPrimaryQlClass() { result = "UInt_least64_t" }
@@ -283,7 +261,7 @@ class UInt_least64_t extends IntegralUnderlyingUserType {
283261
/**
284262
* The C/C++ `int_fast8_t` type.
285263
*/
286-
class Int_fast8_t extends IntegralUnderlyingUserType {
264+
class Int_fast8_t extends TFastestMinimumWidthIntegralType {
287265
Int_fast8_t() { this.hasGlobalOrStdName("int_fast8_t") }
288266

289267
override string getAPrimaryQlClass() { result = "Int_fast8_t" }
@@ -292,7 +270,7 @@ class Int_fast8_t extends IntegralUnderlyingUserType {
292270
/**
293271
* The C/C++ `int_fast16_t` type.
294272
*/
295-
class Int_fast16_t extends IntegralUnderlyingUserType {
273+
class Int_fast16_t extends TFastestMinimumWidthIntegralType {
296274
Int_fast16_t() { this.hasGlobalOrStdName("int_fast16_t") }
297275

298276
override string getAPrimaryQlClass() { result = "Int_fast16_t" }
@@ -301,7 +279,7 @@ class Int_fast16_t extends IntegralUnderlyingUserType {
301279
/**
302280
* The C/C++ `int_fast32_t` type.
303281
*/
304-
class Int_fast32_t extends IntegralUnderlyingUserType {
282+
class Int_fast32_t extends TFastestMinimumWidthIntegralType {
305283
Int_fast32_t() { this.hasGlobalOrStdName("int_fast32_t") }
306284

307285
override string getAPrimaryQlClass() { result = "Int_fast32_t" }
@@ -310,7 +288,7 @@ class Int_fast32_t extends IntegralUnderlyingUserType {
310288
/**
311289
* The C/C++ `int_fast64_t` type.
312290
*/
313-
class Int_fast64_t extends IntegralUnderlyingUserType {
291+
class Int_fast64_t extends TFastestMinimumWidthIntegralType {
314292
Int_fast64_t() { this.hasGlobalOrStdName("int_fast64_t") }
315293

316294
override string getAPrimaryQlClass() { result = "Int_fast64_t" }
@@ -319,7 +297,7 @@ class Int_fast64_t extends IntegralUnderlyingUserType {
319297
/**
320298
* The C/C++ `uint_fast8_t` type.
321299
*/
322-
class UInt_fast8_t extends IntegralUnderlyingUserType {
300+
class UInt_fast8_t extends TFastestMinimumWidthIntegralType {
323301
UInt_fast8_t() { this.hasGlobalOrStdName("uint_fast8_t") }
324302

325303
override string getAPrimaryQlClass() { result = "UInt_fast8_t" }
@@ -328,7 +306,7 @@ class UInt_fast8_t extends IntegralUnderlyingUserType {
328306
/**
329307
* The C/C++ `uint_fast16_t` type.
330308
*/
331-
class UInt_fast16_t extends IntegralUnderlyingUserType {
309+
class UInt_fast16_t extends TFastestMinimumWidthIntegralType {
332310
UInt_fast16_t() { this.hasGlobalOrStdName("uint_fast16_t") }
333311

334312
override string getAPrimaryQlClass() { result = "UInt_fast16_t" }
@@ -337,7 +315,7 @@ class UInt_fast16_t extends IntegralUnderlyingUserType {
337315
/**
338316
* The C/C++ `uint_fast32_t` type.
339317
*/
340-
class UInt_fast32_t extends IntegralUnderlyingUserType {
318+
class UInt_fast32_t extends TFastestMinimumWidthIntegralType {
341319
UInt_fast32_t() { this.hasGlobalOrStdName("uint_fast32_t") }
342320

343321
override string getAPrimaryQlClass() { result = "UInt_fast32_t" }
@@ -346,7 +324,7 @@ class UInt_fast32_t extends IntegralUnderlyingUserType {
346324
/**
347325
* The C/C++ `uint_fast64_t` type.
348326
*/
349-
class UInt_fast64_t extends IntegralUnderlyingUserType {
327+
class UInt_fast64_t extends TFastestMinimumWidthIntegralType {
350328
UInt_fast64_t() { this.hasGlobalOrStdName("uint_fast64_t") }
351329

352330
override string getAPrimaryQlClass() { result = "UInt_fast64_t" }
@@ -355,7 +333,7 @@ class UInt_fast64_t extends IntegralUnderlyingUserType {
355333
/**
356334
* The C/C++ `intmax_t` type.
357335
*/
358-
class Intmax_t extends IntegralUnderlyingUserType {
336+
class Intmax_t extends TMaximumWidthIntegralType {
359337
Intmax_t() { this.hasGlobalOrStdName("intmax_t") }
360338

361339
override string getAPrimaryQlClass() { result = "Intmax_t" }
@@ -364,7 +342,7 @@ class Intmax_t extends IntegralUnderlyingUserType {
364342
/**
365343
* The C/C++ `uintmax_t` type.
366344
*/
367-
class Uintmax_t extends IntegralUnderlyingUserType {
345+
class Uintmax_t extends TMaximumWidthIntegralType {
368346
Uintmax_t() { this.hasGlobalOrStdName("uintmax_t") }
369347

370348
override string getAPrimaryQlClass() { result = "Uintmax_t" }

0 commit comments

Comments
 (0)