@@ -1023,139 +1023,112 @@ bool ByteCodeExprGen<Emitter>::VisitArraySubscriptExpr(
1023
1023
1024
1024
template <class Emitter >
1025
1025
bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
1026
+ const Expr *ArrayFiller,
1026
1027
const Expr *E) {
1027
- assert (E->getType ()->isRecordType ());
1028
- const Record *R = getRecord (E-> getType () );
1028
+ if (E->getType ()->isVoidType ())
1029
+ return this -> emitInvalid (E );
1029
1030
1030
- if (Inits.size () == 1 && E->getType () == Inits[0 ]->getType ()) {
1031
- return this ->visitInitializer (Inits[0 ]);
1031
+ // Handle discarding first.
1032
+ if (DiscardResult) {
1033
+ for (const Expr *Init : Inits) {
1034
+ if (!this ->discard (Init))
1035
+ return false ;
1036
+ }
1037
+ return true ;
1032
1038
}
1033
1039
1034
- unsigned InitIndex = 0 ;
1035
- for (const Expr *Init : Inits) {
1036
- // Skip unnamed bitfields.
1037
- while (InitIndex < R->getNumFields () &&
1038
- R->getField (InitIndex)->Decl ->isUnnamedBitField ())
1039
- ++InitIndex;
1040
+ // Primitive values.
1041
+ if (std::optional<PrimType> T = classify (E->getType ())) {
1042
+ assert (!DiscardResult);
1043
+ if (Inits.size () == 0 )
1044
+ return this ->visitZeroInitializer (*T, E->getType (), E);
1045
+ assert (Inits.size () == 1 );
1046
+ return this ->delegate (Inits[0 ]);
1047
+ }
1040
1048
1041
- if (!this ->emitDupPtr (E))
1042
- return false ;
1049
+ QualType T = E->getType ();
1050
+ if (T->isRecordType ()) {
1051
+ const Record *R = getRecord (E->getType ());
1043
1052
1044
- if (std::optional<PrimType> T = classify (Init)) {
1045
- const Record::Field *FieldToInit = R->getField (InitIndex);
1046
- if (!this ->visit (Init))
1047
- return false ;
1053
+ if (Inits.size () == 1 && E->getType () == Inits[0 ]->getType ()) {
1054
+ return this ->visitInitializer (Inits[0 ]);
1055
+ }
1048
1056
1049
- if (FieldToInit->isBitField ()) {
1050
- if (!this ->emitInitBitField (*T, FieldToInit, E))
1051
- return false ;
1052
- } else {
1053
- if (!this ->emitInitField (*T, FieldToInit->Offset , E))
1054
- return false ;
1055
- }
1057
+ unsigned InitIndex = 0 ;
1058
+ for (const Expr *Init : Inits) {
1059
+ // Skip unnamed bitfields.
1060
+ while (InitIndex < R->getNumFields () &&
1061
+ R->getField (InitIndex)->Decl ->isUnnamedBitField ())
1062
+ ++InitIndex;
1056
1063
1057
- if (!this ->emitPopPtr (E))
1064
+ if (!this ->emitDupPtr (E))
1058
1065
return false ;
1059
- ++InitIndex;
1060
- } else {
1061
- // Initializer for a direct base class.
1062
- if (const Record::Base *B = R->getBase (Init->getType ())) {
1063
- if (!this ->emitGetPtrBasePop (B->Offset , Init))
1064
- return false ;
1065
-
1066
- if (!this ->visitInitializer (Init))
1067
- return false ;
1068
1066
1069
- if (!this ->emitFinishInitPop (E))
1070
- return false ;
1071
- // Base initializers don't increase InitIndex, since they don't count
1072
- // into the Record's fields.
1073
- } else {
1067
+ if (std::optional<PrimType> T = classify (Init)) {
1074
1068
const Record::Field *FieldToInit = R->getField (InitIndex);
1075
- // Non-primitive case. Get a pointer to the field-to-initialize
1076
- // on the stack and recurse into visitInitializer().
1077
- if (!this ->emitGetPtrField (FieldToInit->Offset , Init))
1069
+ if (!this ->visit (Init))
1078
1070
return false ;
1079
1071
1080
- if (!this ->visitInitializer (Init))
1081
- return false ;
1072
+ if (FieldToInit->isBitField ()) {
1073
+ if (!this ->emitInitBitField (*T, FieldToInit, E))
1074
+ return false ;
1075
+ } else {
1076
+ if (!this ->emitInitField (*T, FieldToInit->Offset , E))
1077
+ return false ;
1078
+ }
1082
1079
1083
1080
if (!this ->emitPopPtr (E))
1084
1081
return false ;
1085
1082
++InitIndex;
1086
- }
1087
- }
1088
- }
1089
- return true ;
1090
- }
1083
+ } else {
1084
+ // Initializer for a direct base class.
1085
+ if ( const Record::Base *B = R-> getBase (Init-> getType ())) {
1086
+ if (! this -> emitGetPtrBasePop (B-> Offset , Init))
1087
+ return false ;
1091
1088
1092
- // / Pointer to the array(not the element!) must be on the stack when calling
1093
- // / this.
1094
- template <class Emitter >
1095
- bool ByteCodeExprGen<Emitter>::visitArrayElemInit(unsigned ElemIndex,
1096
- const Expr *Init) {
1097
- if (std::optional<PrimType> T = classify (Init->getType ())) {
1098
- // Visit the primitive element like normal.
1099
- if (!this ->visit (Init))
1100
- return false ;
1101
- return this ->emitInitElem (*T, ElemIndex, Init);
1102
- }
1089
+ if (!this ->visitInitializer (Init))
1090
+ return false ;
1103
1091
1104
- // Advance the pointer currently on the stack to the given
1105
- // dimension.
1106
- if (! this -> emitConstUint32 (ElemIndex, Init))
1107
- return false ;
1108
- if (! this -> emitArrayElemPtrUint32 (Init))
1109
- return false ;
1110
- if (! this -> visitInitializer (Init))
1111
- return false ;
1112
- return this ->emitFinishInitPop ( Init);
1113
- }
1092
+ if (! this -> emitFinishInitPop (E))
1093
+ return false ;
1094
+ // Base initializers don't increase InitIndex, since they don't count
1095
+ // into the Record's fields.
1096
+ } else {
1097
+ const Record::Field *FieldToInit = R-> getField (InitIndex) ;
1098
+ // Non-primitive case. Get a pointer to the field-to-initialize
1099
+ // on the stack and recurse into visitInitializer().
1100
+ if (! this ->emitGetPtrField (FieldToInit-> Offset , Init))
1101
+ return false ;
1114
1102
1115
- template <class Emitter >
1116
- bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
1117
- if (E->getType ()->isVoidType ())
1118
- return this ->emitInvalid (E);
1103
+ if (!this ->visitInitializer (Init))
1104
+ return false ;
1119
1105
1120
- // Handle discarding first.
1121
- if (DiscardResult) {
1122
- for ( const Expr *Init : E-> inits ()) {
1123
- if (! this -> discard (Init))
1124
- return false ;
1106
+ if (! this -> emitPopPtr (E))
1107
+ return false ;
1108
+ ++InitIndex;
1109
+ }
1110
+ }
1125
1111
}
1126
1112
return true ;
1127
1113
}
1128
1114
1129
- // Primitive values.
1130
- if (std::optional<PrimType> T = classify (E->getType ())) {
1131
- assert (!DiscardResult);
1132
- if (E->getNumInits () == 0 )
1133
- return this ->visitZeroInitializer (*T, E->getType (), E);
1134
- assert (E->getNumInits () == 1 );
1135
- return this ->delegate (E->inits ()[0 ]);
1136
- }
1137
-
1138
- QualType T = E->getType ();
1139
- if (T->isRecordType ())
1140
- return this ->visitInitList (E->inits (), E);
1141
-
1142
1115
if (T->isArrayType ()) {
1143
1116
unsigned ElementIndex = 0 ;
1144
- for (const Expr *Init : E-> inits () ) {
1117
+ for (const Expr *Init : Inits ) {
1145
1118
if (!this ->visitArrayElemInit (ElementIndex, Init))
1146
1119
return false ;
1147
1120
++ElementIndex;
1148
1121
}
1149
1122
1150
1123
// Expand the filler expression.
1151
1124
// FIXME: This should go away.
1152
- if (const Expr *Filler = E-> getArrayFiller () ) {
1125
+ if (ArrayFiller ) {
1153
1126
const ConstantArrayType *CAT =
1154
1127
Ctx.getASTContext ().getAsConstantArrayType (E->getType ());
1155
1128
uint64_t NumElems = CAT->getZExtSize ();
1156
1129
1157
1130
for (; ElementIndex != NumElems; ++ElementIndex) {
1158
- if (!this ->visitArrayElemInit (ElementIndex, Filler ))
1131
+ if (!this ->visitArrayElemInit (ElementIndex, ArrayFiller ))
1159
1132
return false ;
1160
1133
}
1161
1134
}
@@ -1164,10 +1137,10 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
1164
1137
}
1165
1138
1166
1139
if (const auto *ComplexTy = E->getType ()->getAs <ComplexType>()) {
1167
- unsigned NumInits = E-> getNumInits ();
1140
+ unsigned NumInits = Inits. size ();
1168
1141
1169
1142
if (NumInits == 1 )
1170
- return this ->delegate (E-> inits () [0 ]);
1143
+ return this ->delegate (Inits [0 ]);
1171
1144
1172
1145
QualType ElemQT = ComplexTy->getElementType ();
1173
1146
PrimType ElemT = classifyPrim (ElemQT);
@@ -1181,7 +1154,7 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
1181
1154
}
1182
1155
} else if (NumInits == 2 ) {
1183
1156
unsigned InitIndex = 0 ;
1184
- for (const Expr *Init : E-> inits () ) {
1157
+ for (const Expr *Init : Inits ) {
1185
1158
if (!this ->visit (Init))
1186
1159
return false ;
1187
1160
@@ -1195,14 +1168,14 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
1195
1168
1196
1169
if (const auto *VecT = E->getType ()->getAs <VectorType>()) {
1197
1170
unsigned NumVecElements = VecT->getNumElements ();
1198
- assert (NumVecElements >= E-> getNumInits ());
1171
+ assert (NumVecElements >= Inits. size ());
1199
1172
1200
1173
QualType ElemQT = VecT->getElementType ();
1201
1174
PrimType ElemT = classifyPrim (ElemQT);
1202
1175
1203
1176
// All initializer elements.
1204
1177
unsigned InitIndex = 0 ;
1205
- for (const Expr *Init : E-> inits () ) {
1178
+ for (const Expr *Init : Inits ) {
1206
1179
if (!this ->visit (Init))
1207
1180
return false ;
1208
1181
@@ -1224,19 +1197,38 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
1224
1197
return false ;
1225
1198
}
1226
1199
1200
+ // / Pointer to the array(not the element!) must be on the stack when calling
1201
+ // / this.
1202
+ template <class Emitter >
1203
+ bool ByteCodeExprGen<Emitter>::visitArrayElemInit(unsigned ElemIndex,
1204
+ const Expr *Init) {
1205
+ if (std::optional<PrimType> T = classify (Init->getType ())) {
1206
+ // Visit the primitive element like normal.
1207
+ if (!this ->visit (Init))
1208
+ return false ;
1209
+ return this ->emitInitElem (*T, ElemIndex, Init);
1210
+ }
1211
+
1212
+ // Advance the pointer currently on the stack to the given
1213
+ // dimension.
1214
+ if (!this ->emitConstUint32 (ElemIndex, Init))
1215
+ return false ;
1216
+ if (!this ->emitArrayElemPtrUint32 (Init))
1217
+ return false ;
1218
+ if (!this ->visitInitializer (Init))
1219
+ return false ;
1220
+ return this ->emitFinishInitPop (Init);
1221
+ }
1222
+
1223
+ template <class Emitter >
1224
+ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
1225
+ return this ->visitInitList (E->inits (), E->getArrayFiller (), E);
1226
+ }
1227
+
1227
1228
template <class Emitter >
1228
1229
bool ByteCodeExprGen<Emitter>::VisitCXXParenListInitExpr(
1229
1230
const CXXParenListInitExpr *E) {
1230
- if (DiscardResult) {
1231
- for (const Expr *Init : E->getInitExprs ()) {
1232
- if (!this ->discard (Init))
1233
- return false ;
1234
- }
1235
- return true ;
1236
- }
1237
-
1238
- assert (E->getType ()->isRecordType ());
1239
- return this ->visitInitList (E->getInitExprs (), E);
1231
+ return this ->visitInitList (E->getInitExprs (), E->getArrayFiller (), E);
1240
1232
}
1241
1233
1242
1234
template <class Emitter >
0 commit comments