static
| 233 | |
| 234 | // static |
| 235 | TypePtr 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 | |
| 283 | TypePtr SwitchCallToSpecialForm::resolveType( |
| 284 | const std::vector<TypePtr>& argTypes) { |
nothing calls this directly
no test coverage detected