236 {
237 const Type& baseType =
base->type();
238 switch (op.kind()) {
240 if (baseType.isArray() || !baseType.componentType().isNumber()) {
241 context.fErrors->error(
pos,
242 "'+' cannot operate on '" + baseType.displayName() + "'");
243 return nullptr;
244 }
245 break;
246
247 case Operator::Kind::MINUS:
248 if (baseType.isArray() || !baseType.componentType().isNumber()) {
249 context.fErrors->error(
pos,
250 "'-' cannot operate on '" + baseType.displayName() + "'");
251 return nullptr;
252 }
253 break;
254
255 case Operator::Kind::PLUSPLUS:
256 case Operator::Kind::MINUSMINUS:
257 if (baseType.isArray() || !baseType.componentType().isNumber()) {
258 context.fErrors->error(
pos,
259 "'" + std::string(op.tightOperatorName()) +
260 "' cannot operate on '" + baseType.displayName() + "'");
261 return nullptr;
262 }
264 context.fErrors)) {
265 return nullptr;
266 }
267 break;
268
269 case Operator::Kind::LOGICALNOT:
270 if (!baseType.isBoolean()) {
271 context.fErrors->error(
pos,
272 "'" + std::string(op.tightOperatorName()) +
273 "' cannot operate on '" + baseType.displayName() + "'");
274 return nullptr;
275 }
276 break;
277
278 case Operator::Kind::BITWISENOT:
279 if (context.fConfig->strictES2Mode()) {
280
281 context.fErrors->error(
283 "operator '" + std::string(op.tightOperatorName()) + "' is not allowed");
284 return nullptr;
285 }
286 if (baseType.isArray() || !baseType.componentType().isInteger()) {
287 context.fErrors->error(
pos,
288 "'" + std::string(op.tightOperatorName()) +
289 "' cannot operate on '" + baseType.displayName() + "'");
290 return nullptr;
291 }
292 break;
293
294 default:
295 SK_ABORT(
"unsupported prefix operator");
296 }
297
301}
#define SK_ABORT(message,...)
static std::unique_ptr< Expression > Make(const Context &context, Position pos, Operator op, std::unique_ptr< Expression > base)
bool UpdateVariableRefKind(Expression *expr, VariableRefKind kind, ErrorReporter *errors=nullptr)