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

#include <SkSLConstructor.h>

Inheritance diagram for SkSL::AnyConstructor:
SkSL::Expression SkSL::IRNode SkSL::Poolable SkSL::MultiArgumentConstructor SkSL::SingleArgumentConstructor SkSL::ConstructorArray SkSL::ConstructorCompound SkSL::ConstructorStruct SkSL::ConstructorArrayCast SkSL::ConstructorCompoundCast SkSL::ConstructorDiagonalMatrix SkSL::ConstructorMatrixResize SkSL::ConstructorScalarCast SkSL::ConstructorSplat

Public Member Functions

 AnyConstructor (Position pos, Kind kind, const Type *type)
 
virtual SkSpan< std::unique_ptr< Expression > > argumentSpan ()=0
 
virtual SkSpan< const std::unique_ptr< Expression > > argumentSpan () const =0
 
std::string description (OperatorPrecedence) const override
 
const TypecomponentType () const
 
bool supportsConstantValues () const override
 
std::optional< double > getConstantValue (int n) const override
 
ComparisonResult compareConstant (const Expression &other) 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 ()
 

Additional Inherited Members

- Public Types inherited from SkSL::Expression
enum class  ComparisonResult { kUnknown = -1 , kNotEqual , kEqual }
 
using Kind = ExpressionKind
 
- 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

Base class representing a constructor with unknown arguments.

Definition at line 31 of file SkSLConstructor.h.

Constructor & Destructor Documentation

◆ AnyConstructor()

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

Definition at line 33 of file SkSLConstructor.h.

34 : INHERITED(pos, kind, type) {}
SkPoint pos
Kind kind() const
const Type & type() const

Member Function Documentation

◆ argumentSpan() [1/2]

virtual SkSpan< const std::unique_ptr< Expression > > SkSL::AnyConstructor::argumentSpan ( ) const
pure virtual

◆ argumentSpan() [2/2]

virtual SkSpan< std::unique_ptr< Expression > > SkSL::AnyConstructor::argumentSpan ( )
pure virtual

◆ compareConstant()

Expression::ComparisonResult SkSL::AnyConstructor::compareConstant ( const Expression other) const
overridevirtual

Reimplemented from SkSL::Expression.

Definition at line 192 of file SkSLConstructor.cpp.

192 {
193 SkASSERT(this->type().slotCount() == other.type().slotCount());
194
195 if (!other.supportsConstantValues()) {
197 }
198
199 int exprs = this->type().slotCount();
200 for (int n = 0; n < exprs; ++n) {
201 // Get the n'th subexpression from each side. If either one is null, return "unknown."
202 std::optional<double> left = this->getConstantValue(n);
203 if (!left.has_value()) {
205 }
206 std::optional<double> right = other.getConstantValue(n);
207 if (!right.has_value()) {
209 }
210 // Both sides are known and can be compared for equality directly.
211 if (*left != *right) {
213 }
214 }
216}
#define SkASSERT(cond)
Definition: SkAssert.h:116
std::optional< double > getConstantValue(int n) const override
const Type & type() const
Definition: SkSLSymbol.h:42
virtual size_t slotCount() const
Definition: SkSLType.h:457

◆ componentType()

const Type & SkSL::AnyConstructor::componentType ( ) const
inline

Definition at line 41 of file SkSLConstructor.h.

41 {
42 return this->type().componentType();
43 }
virtual const Type & componentType() const
Definition: SkSLType.h:404

◆ description()

std::string SkSL::AnyConstructor::description ( OperatorPrecedence  ) const
overridevirtual

Implements SkSL::Expression.

Definition at line 228 of file SkSLConstructor.cpp.

228 {
229 std::string result = this->type().description() + "(";
230 auto separator = SkSL::String::Separator();
231 for (const std::unique_ptr<Expression>& arg : this->argumentSpan()) {
232 result += separator();
233 result += arg->description(OperatorPrecedence::kSequence);
234 }
235 result.push_back(')');
236 return result;
237}
virtual SkSpan< std::unique_ptr< Expression > > argumentSpan()=0
std::string description() const override
Definition: SkSLType.h:238
GAsyncResult * result
std::string void void auto Separator()
Definition: SkSLString.h:30

◆ getConstantValue()

std::optional< double > SkSL::AnyConstructor::getConstantValue ( int  n) const
overridevirtual

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 from SkSL::Expression.

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

Definition at line 178 of file SkSLConstructor.cpp.

178 {
179 SkASSERT(n >= 0 && n < (int)this->type().slotCount());
180 for (const std::unique_ptr<Expression>& arg : this->argumentSpan()) {
181 int argSlots = arg->type().slotCount();
182 if (n < argSlots) {
183 return arg->getConstantValue(n);
184 }
185 n -= argSlots;
186 }
187
188 SkDEBUGFAIL("argument-list slot count doesn't match constructor-type slot count");
189 return std::nullopt;
190}
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118

◆ supportsConstantValues()

bool SkSL::AnyConstructor::supportsConstantValues ( ) const
inlineoverridevirtual

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 from SkSL::Expression.

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

Definition at line 45 of file SkSLConstructor.h.

45{ return true; }

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