153 {
154 SkASSERT(caseValues.size() == caseStatements.size());
155
156 value = context.fTypes.fInt->coerceExpression(std::move(
value), context);
158 return nullptr;
159 }
160
162 for (int i = 0; i < caseValues.size(); ++i) {
163 if (caseValues[i]) {
164 Position casePos = caseValues[i]->fPosition;
165
166 std::unique_ptr<Expression> caseValue =
value->type().coerceExpression(
167 std::move(caseValues[i]), context);
168 if (!caseValue) {
169 return nullptr;
170 }
173 context.fErrors->error(casePos, "case value must be a constant integer");
174 return nullptr;
175 }
177 } else {
179 }
180 }
181
182
183
185 if (!duplicateCases.empty()) {
186 duplicateCases.reverse();
187 for (const SwitchCase* sc : duplicateCases) {
188 if (sc->isDefault()) {
189 context.fErrors->error(sc->fPosition, "duplicate default case");
190 } else {
191 context.fErrors->error(sc->fPosition, "duplicate case value '" +
192 std::to_string(sc->value()) + "'");
193 }
194 }
195 return nullptr;
196 }
197
201 Block::MakeBlock(
pos,
203 Block::Kind::kBracedScope,
204 std::move(symbolTable)));
205}
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 std::forward_list< const SwitchCase * > find_duplicate_case_values(const StatementArray &cases)