151 {
152 SkASSERT(caseValues.size() == caseStatements.size());
153
154 value = context.fTypes.fInt->coerceExpression(std::move(
value), context);
156 return nullptr;
157 }
158
160 for (
int i = 0;
i < caseValues.size(); ++
i) {
162 Position casePos = caseValues[
i]->fPosition;
163
164 std::unique_ptr<Expression> caseValue =
value->type().coerceExpression(
165 std::move(caseValues[
i]), context);
166 if (!caseValue) {
167 return nullptr;
168 }
171 context.fErrors->error(casePos, "case value must be a constant integer");
172 return nullptr;
173 }
175 } else {
177 }
178 }
179
180
182 if (!duplicateCases.
empty()) {
183 for (const SwitchCase* sc : duplicateCases) {
184 if (sc->isDefault()) {
185 context.fErrors->error(sc->fPosition, "duplicate default case");
186 } else {
187 context.fErrors->error(sc->fPosition, "duplicate case value '" +
189 }
190 }
191 return nullptr;
192 }
193
199 Block::Kind::kBracedScope,
200 std::move(symbolTable)));
201}
static std::unique_ptr< Block > MakeBlock(Position pos, StatementArray statements, Kind kind=Kind::kBracedScope, std::unique_ptr< SymbolTable > symbols=nullptr)
static bool GetConstantInt(const Expression &value, SKSL_INT *out)
static std::unique_ptr< SwitchCase > MakeDefault(Position pos, std::unique_ptr< Statement > statement)
static std::unique_ptr< SwitchCase > Make(Position pos, SKSL_INT value, std::unique_ptr< Statement > statement)
static std::unique_ptr< Statement > Make(const Context &context, Position pos, std::unique_ptr< Expression > value, std::unique_ptr< Statement > caseBlock)
skia_private::STArray< 2, std::unique_ptr< Statement > > StatementArray
static TArray< const SwitchCase * > find_duplicate_case_values(const StatementArray &cases)
static SkString to_string(int n)