Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
SkSL::PrefixExpression Class Referencefinal

#include <SkSLPrefixExpression.h>

Inheritance diagram for SkSL::PrefixExpression:
SkSL::Expression SkSL::IRNode SkSL::Poolable

Public Member Functions

 PrefixExpression (Position pos, Operator op, std::unique_ptr< Expression > operand)
 
Operator getOperator () const
 
std::unique_ptr< Expression > & operand ()
 
const std::unique_ptr< Expression > & operand () const
 
std::unique_ptr< Expressionclone (Position pos) const override
 
std::string description (OperatorPrecedence parentPrecedence) const override
 
- Public Member Functions inherited from SkSL::Expression
 Expression (Position pos, Kind kind, const Type *type)
 
Kind kind () const
 
const Typetype () const
 
bool isAnyConstructor () const
 
bool isIntLiteral () const
 
bool isFloatLiteral () const
 
bool isBoolLiteral () const
 
AnyConstructorasAnyConstructor ()
 
const AnyConstructorasAnyConstructor () const
 
bool isIncomplete (const Context &context) const
 
virtual ComparisonResult compareConstant (const Expression &other) const
 
CoercionCost coercionCost (const Type &target) const
 
virtual bool supportsConstantValues () const
 
virtual std::optional< double > getConstantValue (int n) const
 
virtual std::unique_ptr< Expressionclone (Position pos) const =0
 
std::unique_ptr< Expressionclone () const
 
std::string description () const final
 
virtual std::string description (OperatorPrecedence parentPrecedence) const =0
 
- Public Member Functions inherited from SkSL::IRNode
virtual ~IRNode ()
 
virtual std::string description () const =0
 
 IRNode (const IRNode &)=delete
 
IRNodeoperator= (const IRNode &)=delete
 
Position position () const
 
void setPosition (Position p)
 
template<typename T >
bool is () const
 
template<typename T >
const Tas () const
 
template<typename T >
Tas ()
 

Static Public Member Functions

static std::unique_ptr< ExpressionConvert (const Context &context, Position pos, Operator op, std::unique_ptr< Expression > base)
 
static std::unique_ptr< ExpressionMake (const Context &context, Position pos, Operator op, std::unique_ptr< Expression > base)
 
- Static Public Member Functions inherited from SkSL::Poolable
static void * operator new (const size_t size)
 
static void operator delete (void *ptr)
 

Static Public Attributes

static constexpr Kind kIRNodeKind = Kind::kPrefix
 

Additional Inherited Members

- Public Types inherited from SkSL::Expression
enum class  ComparisonResult { kUnknown = -1 , kNotEqual , kEqual }
 
using Kind = ExpressionKind
 
- Public Attributes inherited from SkSL::IRNode
Position fPosition
 
- Protected Member Functions inherited from SkSL::IRNode
 IRNode (Position position, int kind)
 
- Protected Attributes inherited from SkSL::IRNode
int fKind
 

Detailed Description

An expression modified by a unary operator appearing before it, such as '!flag'.

Definition at line 27 of file SkSLPrefixExpression.h.

Constructor & Destructor Documentation

◆ PrefixExpression()

SkSL::PrefixExpression::PrefixExpression ( Position  pos,
Operator  op,
std::unique_ptr< Expression operand 
)
inline

Definition at line 32 of file SkSLPrefixExpression.h.

33 : INHERITED(pos, kIRNodeKind, &operand->type())
34 , fOperator(op)
35 , fOperand(std::move(operand)) {}
SkPoint pos
std::unique_ptr< Expression > & operand()
static constexpr Kind kIRNodeKind

Member Function Documentation

◆ clone()

std::unique_ptr< Expression > SkSL::PrefixExpression::clone ( Position  pos) const
inlineoverridevirtual

Implements SkSL::Expression.

Definition at line 57 of file SkSLPrefixExpression.h.

57 {
58 return std::make_unique<PrefixExpression>(pos, this->getOperator(),
59 this->operand()->clone());
60 }
std::unique_ptr< Expression > clone() const
Operator getOperator() const

◆ Convert()

std::unique_ptr< Expression > SkSL::PrefixExpression::Convert ( const Context context,
Position  pos,
Operator  op,
std::unique_ptr< Expression base 
)
static

Definition at line 233 of file SkSLPrefixExpression.cpp.

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 // GLSL ES 1.00, Section 5.1
281 context.fErrors->error(
282 pos,
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
298 std::unique_ptr<Expression> result = PrefixExpression::Make(context, pos, op, std::move(base));
299 SkASSERT(result->fPosition == pos);
300 return result;
301}
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
#define SkASSERT(cond)
Definition: SkAssert.h:116
static std::unique_ptr< Expression > Make(const Context &context, Position pos, Operator op, std::unique_ptr< Expression > base)
GAsyncResult * result
bool UpdateVariableRefKind(Expression *expr, VariableRefKind kind, ErrorReporter *errors=nullptr)

◆ description()

std::string SkSL::PrefixExpression::description ( OperatorPrecedence  parentPrecedence) const
overridevirtual

Implements SkSL::Expression.

Definition at line 349 of file SkSLPrefixExpression.cpp.

349 {
350 bool needsParens = (OperatorPrecedence::kPrefix >= parentPrecedence);
351 return std::string(needsParens ? "(" : "") +
352 std::string(this->getOperator().tightOperatorName()) +
353 this->operand()->description(OperatorPrecedence::kPrefix) +
354 std::string(needsParens ? ")" : "");
355}

◆ getOperator()

Operator SkSL::PrefixExpression::getOperator ( ) const
inline

Definition at line 45 of file SkSLPrefixExpression.h.

45 {
46 return fOperator;
47 }

◆ Make()

std::unique_ptr< Expression > SkSL::PrefixExpression::Make ( const Context context,
Position  pos,
Operator  op,
std::unique_ptr< Expression base 
)
static

Definition at line 303 of file SkSLPrefixExpression.cpp.

306 {
307 const Type& baseType = base->type();
308 switch (op.kind()) {
310 SkASSERT(!baseType.isArray());
311 SkASSERT(baseType.componentType().isNumber());
312 base->fPosition = pos;
313 return base;
314
315 case Operator::Kind::MINUS:
316 SkASSERT(!baseType.isArray());
317 SkASSERT(baseType.componentType().isNumber());
318 return negate_operand(context, pos, std::move(base));
319
320 case Operator::Kind::LOGICALNOT:
321 SkASSERT(baseType.isBoolean());
322 return logical_not_operand(context, pos, std::move(base));
323
324 case Operator::Kind::PLUSPLUS:
325 case Operator::Kind::MINUSMINUS:
326 SkASSERT(!baseType.isArray());
327 SkASSERT(baseType.componentType().isNumber());
329 break;
330
331 case Operator::Kind::BITWISENOT:
332 SkASSERT(!context.fConfig->strictES2Mode());
333 SkASSERT(!baseType.isArray());
334 SkASSERT(baseType.componentType().isInteger());
335 if (baseType.isLiteral()) {
336 // The expression `~123` is no longer a literal; coerce to the actual type.
337 base = baseType.scalarTypeForLiteral().coerceExpression(std::move(base), context);
338 SkASSERT(base);
339 }
340 return bitwise_not_operand(context, pos, std::move(base));
341
342 default:
343 SkDEBUGFAILF("unsupported prefix operator: %s", op.operatorName());
344 }
345
346 return std::make_unique<PrefixExpression>(pos, op, std::move(base));
347}
#define SkDEBUGFAILF(fmt,...)
Definition: SkAssert.h:119
bool IsAssignable(Expression &expr, AssignmentInfo *info=nullptr, ErrorReporter *errors=nullptr)
static std::unique_ptr< Expression > negate_operand(const Context &context, Position pos, std::unique_ptr< Expression > value)
static std::unique_ptr< Expression > bitwise_not_operand(const Context &context, Position pos, std::unique_ptr< Expression > operand)
static std::unique_ptr< Expression > logical_not_operand(const Context &context, Position pos, std::unique_ptr< Expression > operand)

◆ operand() [1/2]

std::unique_ptr< Expression > & SkSL::PrefixExpression::operand ( )
inline

Definition at line 49 of file SkSLPrefixExpression.h.

49 {
50 return fOperand;
51 }

◆ operand() [2/2]

const std::unique_ptr< Expression > & SkSL::PrefixExpression::operand ( ) const
inline

Definition at line 53 of file SkSLPrefixExpression.h.

53 {
54 return fOperand;
55 }

Member Data Documentation

◆ kIRNodeKind

constexpr Kind SkSL::PrefixExpression::kIRNodeKind = Kind::kPrefix
inlinestaticconstexpr

Definition at line 29 of file SkSLPrefixExpression.h.


The documentation for this class was generated from the following files: