MCPcopy Create free account
hub / github.com/bytedance/bolt / resolveType

Method resolveType

bolt/expression/SwitchExpr.cpp:235–281  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

233
234// static
235TypePtr SwitchExpr::resolveType(const std::vector<TypePtr>& argTypes) {
236 BOLT_CHECK_GT(
237 argTypes.size(),
238 1,
239 "Switch statements expect at least 2 arguments, received {}",
240 argTypes.size());
241 // Type structure is [cond1Type, then1Type, cond2Type, then2Type, ...
242 // elseType*]
243
244 // Make sure all 'condition' expressions hae type BOOLEAN and all 'then' and
245 // an optional 'else' clause have the same type.
246 int numCases = argTypes.size() / 2;
247
248 auto& expressionType = argTypes[1];
249
250 for (auto i = 0; i < numCases; i++) {
251 auto& conditionType = argTypes[i * 2];
252 auto& thenType = argTypes[i * 2 + 1];
253
254 BOLT_CHECK_EQ(
255 conditionType->kind(),
256 TypeKind::BOOLEAN,
257 "Condition of SWITCH statement is not bool");
258
259 BOLT_CHECK(
260 *thenType == *expressionType,
261 "All then clauses of a SWITCH statement must have the same type. "
262 "Expected {}, but got {}.",
263 expressionType->toString(),
264 thenType->toString());
265 }
266
267 bool hasElse = argTypes.size() % 2 == 1;
268
269 if (hasElse) {
270 auto& elseClauseType = argTypes.back();
271
272 BOLT_CHECK(
273 *elseClauseType == *expressionType,
274 "Else clause of a SWITCH statement must have the same type as 'then' clauses. "
275 "Expected {}, but got {}.",
276 expressionType->toString(),
277 elseClauseType->toString());
278 }
279
280 return expressionType;
281}
282
283TypePtr SwitchCallToSpecialForm::resolveType(
284 const std::vector<TypePtr>& argTypes) {

Callers

nothing calls this directly

Calls 5

resolveTypeFunction · 0.85
backMethod · 0.80
sizeMethod · 0.45
kindMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected