Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | List of all members
SkSL::Expression Class Referenceabstract

#include <SkSLExpression.h>

Inheritance diagram for SkSL::Expression:
SkSL::IRNode SkSL::Poolable SkSL::AnyConstructor SkSL::BinaryExpression SkSL::ChildCall SkSL::EmptyExpression SkSL::FieldAccess SkSL::FunctionCall SkSL::FunctionReference SkSL::IndexExpression SkSL::Literal SkSL::MethodReference SkSL::Poison SkSL::PostfixExpression SkSL::PrefixExpression SkSL::Setting SkSL::Swizzle SkSL::TernaryExpression SkSL::TypeReference SkSL::VariableReference

Public Types

enum class  ComparisonResult { kUnknown = -1 , kNotEqual , kEqual }
 
using Kind = ExpressionKind
 

Public Member Functions

 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 ()
 

Additional Inherited Members

- Static Public Member Functions inherited from SkSL::Poolable
static void * operator new (const size_t size)
 
static void operator delete (void *ptr)
 
- 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

Abstract supertype of all expressions.

Definition at line 30 of file SkSLExpression.h.

Member Typedef Documentation

◆ Kind

Definition at line 32 of file SkSLExpression.h.

Member Enumeration Documentation

◆ ComparisonResult

Compares this constant expression against another constant expression. Returns kUnknown if we aren't able to deduce a result (an expression isn't actually constant, the types are mismatched, etc).

Enumerator
kUnknown 
kNotEqual 
kEqual 

Definition at line 81 of file SkSLExpression.h.

Constructor & Destructor Documentation

◆ Expression()

SkSL::Expression::Expression ( Position  pos,
Kind  kind,
const Type type 
)
inline

Definition at line 34 of file SkSLExpression.h.

35 : INHERITED(pos, (int) kind)
36 , fType(type) {
37 SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast);
38 }
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
Kind kind() const
const Type & type() const

Member Function Documentation

◆ asAnyConstructor() [1/2]

AnyConstructor & SkSL::Expression::asAnyConstructor ( )

Definition at line 218 of file SkSLConstructor.cpp.

218 {
219 SkASSERT(this->isAnyConstructor());
220 return static_cast<AnyConstructor&>(*this);
221}
bool isAnyConstructor() const

◆ asAnyConstructor() [2/2]

const AnyConstructor & SkSL::Expression::asAnyConstructor ( ) const

Definition at line 223 of file SkSLConstructor.cpp.

223 {
224 SkASSERT(this->isAnyConstructor());
225 return static_cast<const AnyConstructor&>(*this);
226}

◆ clone() [1/2]

std::unique_ptr< Expression > SkSL::Expression::clone ( ) const
inline

Returns a clone at the same position.

Definition at line 126 of file SkSLExpression.h.

126{ return this->clone(fPosition); }
std::unique_ptr< Expression > clone() const
Position fPosition
Definition: SkSLIRNode.h:109

◆ clone() [2/2]

virtual std::unique_ptr< Expression > SkSL::Expression::clone ( Position  pos) const
pure virtual

◆ coercionCost()

CoercionCost SkSL::Expression::coercionCost ( const Type target) const
inline

Definition at line 90 of file SkSLExpression.h.

90 {
91 return this->type().coercionCost(target);
92 }
CoercionCost coercionCost(const Type &other) const
uint32_t * target

◆ compareConstant()

virtual ComparisonResult SkSL::Expression::compareConstant ( const Expression other) const
inlinevirtual

Reimplemented in SkSL::AnyConstructor, and SkSL::Literal.

Definition at line 86 of file SkSLExpression.h.

◆ description() [1/2]

std::string SkSL::Expression::description ( ) const
finalvirtual

Returns a description of the expression.

Implements SkSL::IRNode.

Definition at line 18 of file SkSLExpression.cpp.

18 {
20}
std::string description() const final

◆ description() [2/2]

virtual std::string SkSL::Expression::description ( OperatorPrecedence  parentPrecedence) const
pure virtual

◆ getConstantValue()

virtual std::optional< double > SkSL::Expression::getConstantValue ( int  n) const
inlinevirtual

Returns the n'th compile-time constant value within a literal or constructor. Use Type::slotCount to determine the number of slots within an expression. Slots which do not contain compile-time constant values will return nullopt. vec4(1, vec2(2), 3) contains four compile-time constants: (1, 2, 2, 3) mat2(f) contains four slots, and two are constant: (nullopt, 0, 0, nullopt) All classes which override this function must also implement supportsConstantValues.

Reimplemented in SkSL::AnyConstructor, SkSL::ConstructorDiagonalMatrix, SkSL::ConstructorMatrixResize, SkSL::ConstructorSplat, and SkSL::Literal.

Definition at line 116 of file SkSLExpression.h.

116 {
118 return std::nullopt;
119 }
virtual bool supportsConstantValues() const

◆ isAnyConstructor()

bool SkSL::Expression::isAnyConstructor ( ) const
inline

Definition at line 48 of file SkSLExpression.h.

48 {
49 static_assert((int)Kind::kConstructorArray - 1 == (int)Kind::kChildCall);
50 static_assert((int)Kind::kConstructorStruct + 1 == (int)Kind::kEmpty);
51 return this->kind() >= Kind::kConstructorArray && this->kind() <= Kind::kConstructorStruct;
52 }

◆ isBoolLiteral()

bool SkSL::Expression::isBoolLiteral ( ) const
inline

Definition at line 62 of file SkSLExpression.h.

62 {
63 return this->kind() == Kind::kLiteral && this->type().isBoolean();
64 }
bool isBoolean() const
Definition: SkSLType.h:297

◆ isFloatLiteral()

bool SkSL::Expression::isFloatLiteral ( ) const
inline

Definition at line 58 of file SkSLExpression.h.

58 {
59 return this->kind() == Kind::kLiteral && this->type().isFloat();
60 }
bool isFloat() const
Definition: SkSLType.h:318

◆ isIncomplete()

bool SkSL::Expression::isIncomplete ( const Context context) const

Returns true if this expression is incomplete. Specifically, dangling function/method-call references that were never invoked, or type references that were never constructed, are considered incomplete expressions and should result in an error.

Definition at line 22 of file SkSLExpression.cpp.

22 {
23 switch (this->kind()) {
24 case Kind::kFunctionReference:
25 context.fErrors->error(fPosition.after(), "expected '(' to begin function call");
26 return true;
27
28 case Kind::kMethodReference:
29 context.fErrors->error(fPosition.after(), "expected '(' to begin method call");
30 return true;
31
32 case Kind::kTypeReference:
33 context.fErrors->error(fPosition.after(),
34 "expected '(' to begin constructor invocation");
35 return true;
36
37 case Kind::kVariableReference:
38 if (this->type().matches(*context.fTypes.fSkCaps)) {
39 context.fErrors->error(fPosition, "invalid expression");
40 return true;
41 }
42 return false;
43
44 default:
45 return false;
46 }
47}
Position after() const
Definition: SkSLPosition.h:62
def matches(file)
Definition: gen_manifest.py:38

◆ isIntLiteral()

bool SkSL::Expression::isIntLiteral ( ) const
inline

Definition at line 54 of file SkSLExpression.h.

54 {
55 return this->kind() == Kind::kLiteral && this->type().isInteger();
56 }
bool isInteger() const
Definition: SkSLType.h:339

◆ kind()

Kind SkSL::Expression::kind ( ) const
inline

Definition at line 40 of file SkSLExpression.h.

40 {
41 return (Kind)fKind;
42 }

◆ supportsConstantValues()

virtual bool SkSL::Expression::supportsConstantValues ( ) const
inlinevirtual

Returns true if this expression type supports getConstantValue. (This particular expression may or may not actually contain a constant value.) It's harmless to call getConstantValue on expressions which don't support constant values or don't contain any constant values, but if supportsConstantValues returns false, you can assume that getConstantValue will return nullopt for every slot of this expression. This allows for early-out opportunities in some cases. (Some expressions have tons of slots but never hold a constant value; e.g. a variable holding a very large array.)

Reimplemented in SkSL::AnyConstructor, SkSL::ConstructorDiagonalMatrix, SkSL::ConstructorMatrixResize, SkSL::ConstructorSplat, and SkSL::Literal.

Definition at line 103 of file SkSLExpression.h.

103 {
104 return false;
105 }

◆ type()

const Type & SkSL::Expression::type ( ) const
inline

Definition at line 44 of file SkSLExpression.h.

44 {
45 return *fType;
46 }

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