Skip to content

Commit 6c73964

Browse files
authored
Merge pull request #116 from nickrolfe/desig_init
C++: support for designated initializers
2 parents 69ca103 + 0589be1 commit 6c73964

13 files changed

+5612
-5002
lines changed

cpp/ql/src/semmle/code/cpp/exprs/Literal.qll

+4-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ class ClassAggregateLiteral extends AggregateLiteral {
173173
*/
174174
Expr getFieldExpr(Field field) {
175175
field = classType.getAField() and
176-
result = getChild(field.getInitializationOrder())
176+
aggregate_field_init(underlyingElement(this), unresolveElement(result),
177+
unresolveElement(field))
177178
}
178179

179180
/**
@@ -230,7 +231,8 @@ class ArrayAggregateLiteral extends AggregateLiteral {
230231
* element `elementIndex`, if present.
231232
*/
232233
Expr getElementExpr(int elementIndex) {
233-
result = getChild(elementIndex)
234+
aggregate_array_init(underlyingElement(this), unresolveElement(result),
235+
elementIndex)
234236
}
235237

236238
/**

cpp/ql/src/semmlecode.cpp.dbscheme

+74-13
Original file line numberDiff line numberDiff line change
@@ -543,19 +543,60 @@ enumconstants(
543543
@localscopevariable = @localvariable | @parameter;
544544

545545
/*
546-
Built-in types are the fundamental types, i.e., integral, floating, and void.
547-
kind(1) = error, kind(2) = unknown, kind(3) = void, kind(4) = boolean,
548-
kind(5) = char, kind(6) = unsigned char, kind(7) = signed char
549-
kind(8) = short, kind(9) = unsigned short, kind(10) = signed short
550-
kind(11) = int, kind(12) = unsigned int, kind(13) = signed int,
551-
kind(14) = long, kind(15) = unsigned long, kind(16) = signed long,
552-
kind(17) = long long, kind(18) = unsigned long long, kind(19) = signed long long,
553-
kind(20) = __int8, kind(21) = __int16, kind(22) = __int32, kind(23) = __int64, // Microsoft specific
554-
kind(24) = float, kind(25) = double, kind(26) = long double,
555-
kind(27) = _Complex float, kind(28) = _Complex double, kind(29) = _Complex long double, //C99 specific
556-
kind(30) = _Imaginary float, kind(31) = _Imaginary double, kind(32) = _Imaginary long double, //C99 specific
557-
kind(33) = wchar_t, // MS specific
558-
kind(34) = decltype(nullptr), // C++11
546+
Built-in types are the fundamental types, e.g., integral, floating, and void.
547+
548+
case @builtintype.kind of
549+
1 = error
550+
| 2 = unknown
551+
| 3 = void
552+
| 4 = boolean
553+
| 5 = char
554+
| 6 = unsigned_char
555+
| 7 = signed_char
556+
| 8 = short
557+
| 9 = unsigned_short
558+
| 10 = signed_short
559+
| 11 = int
560+
| 12 = unsigned_int
561+
| 13 = signed_int
562+
| 14 = long
563+
| 15 = unsigned_long
564+
| 16 = signed_long
565+
| 17 = long_long
566+
| 18 = unsigned_long_long
567+
| 19 = signed_long_long
568+
| 20 = __int8 // Microsoft-specific
569+
| 21 = __int16 // Microsoft-specific
570+
| 22 = __int32 // Microsoft-specific
571+
| 23 = __int64 // Microsoft-specific
572+
| 24 = float
573+
| 25 = double
574+
| 26 = long_double
575+
| 27 = _Complex_float // C99-specific
576+
| 28 = _Complex_double // C99-specific
577+
| 29 = _Complex_long double // C99-specific
578+
| 30 = _Imaginary_float // C99-specific
579+
| 31 = _Imaginary_double // C99-specific
580+
| 32 = _Imaginary_long_double // C99-specific
581+
| 33 = wchar_t // Microsoft-specific
582+
| 34 = decltype_nullptr // C++11
583+
| 35 = __int128
584+
| 36 = unsigned___int128
585+
| 37 = signed___int128
586+
| 38 = __float128
587+
| 39 = _Complex___float128
588+
| 40 = _Decimal32
589+
| 41 = _Decimal64
590+
| 42 = _Decimal128
591+
| 43 = char16_t
592+
| 44 = char32_t
593+
| 45 = _Float32
594+
| 46 = _Float32x
595+
| 47 = _Float64
596+
| 48 = _Float64x
597+
| 49 = _Float128
598+
| 50 = _Float128x
599+
;
559600
*/
560601
builtintypes(
561602
unique int id: @builtintype,
@@ -1400,6 +1441,26 @@ new_array_allocated_type(
14001441
int type_id: @type ref
14011442
);
14021443

1444+
/**
1445+
* The field being initialized by an initializer expression within an aggregate
1446+
* initializer for a class/struct/union.
1447+
*/
1448+
aggregate_field_init(
1449+
unique int aggregate: @aggregateliteral ref,
1450+
int initializer: @expr ref,
1451+
int field: @membervariable ref
1452+
);
1453+
1454+
/**
1455+
* The index of the element being initialized by an initializer expression
1456+
* within an aggregate initializer for an array.
1457+
*/
1458+
aggregate_array_init(
1459+
unique int aggregate: @aggregateliteral ref,
1460+
int initializer: @expr ref,
1461+
int element_index: int ref
1462+
);
1463+
14031464
@ctorinit = @ctordirectinit
14041465
| @ctorvirtualinit
14051466
| @ctorfieldinit

0 commit comments

Comments
 (0)