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

#include <SkSLConstructorArray.h>

Inheritance diagram for SkSL::ConstructorArray:
SkSL::MultiArgumentConstructor SkSL::AnyConstructor SkSL::Expression SkSL::IRNode SkSL::Poolable

Public Member Functions

 ConstructorArray (Position pos, const Type &type, ExpressionArray arguments)
 
std::unique_ptr< Expressionclone (Position pos) const override
 
- Public Member Functions inherited from SkSL::MultiArgumentConstructor
 MultiArgumentConstructor (Position pos, Kind kind, const Type *type, ExpressionArray arguments)
 
ExpressionArrayarguments ()
 
const ExpressionArrayarguments () const
 
SkSpan< std::unique_ptr< Expression > > argumentSpan () final
 
SkSpan< const std::unique_ptr< Expression > > argumentSpan () const final
 
- Public Member Functions inherited from SkSL::AnyConstructor
 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 ()
 

Static Public Member Functions

static std::unique_ptr< ExpressionConvert (const Context &context, Position pos, const Type &type, ExpressionArray args)
 
static std::unique_ptr< ExpressionMake (const Context &context, Position pos, const Type &type, ExpressionArray args)
 
- 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::kConstructorArray
 

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

Represents the construction of an array type, such as "float[5](x, y, z, w, 1)".

Definition at line 28 of file SkSLConstructorArray.h.

Constructor & Destructor Documentation

◆ ConstructorArray()

SkSL::ConstructorArray::ConstructorArray ( Position  pos,
const Type type,
ExpressionArray  arguments 
)
inline

Definition at line 32 of file SkSLConstructorArray.h.

33 : INHERITED(pos, kIRNodeKind, &type, std::move(arguments)) {}
SkPoint pos
static constexpr Kind kIRNodeKind
const Type & type() const
ExpressionArray & arguments()

Member Function Documentation

◆ clone()

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

Implements SkSL::Expression.

Definition at line 48 of file SkSLConstructorArray.h.

48 {
49 return std::make_unique<ConstructorArray>(pos, this->type(), this->arguments().clone());
50 }
std::unique_ptr< Expression > clone() const

◆ Convert()

std::unique_ptr< Expression > SkSL::ConstructorArray::Convert ( const Context context,
Position  pos,
const Type type,
ExpressionArray  args 
)
static

Definition at line 23 of file SkSLConstructorArray.cpp.

26 {
27 SkASSERTF(type.isArray() && type.columns() > 0, "%s", type.description().c_str());
28
29 // ES2 doesn't support first-class array types.
30 if (context.fConfig->strictES2Mode()) {
31 context.fErrors->error(pos, "construction of array type '" + type.displayName() +
32 "' is not supported");
33 return nullptr;
34 }
35
36 // An array of atomics cannot be constructed.
38 context.fErrors->error(
39 pos,
40 String::printf("construction of array type '%s' with atomic member is not allowed",
41 type.displayName().c_str()));
42 return nullptr;
43 }
44
45 // If there is a single argument containing an array of matching size and the types are
46 // coercible, this is actually a cast. i.e., `half[10](myFloat10Array)`. This isn't a GLSL
47 // feature, but the Pipeline stage code generator needs this functionality so that code which
48 // was originally compiled with "allow narrowing conversions" enabled can be later recompiled
49 // without narrowing conversions (we patch over these conversions with an explicit cast).
50 if (args.size() == 1) {
51 const Expression& expr = *args.front();
52 const Type& exprType = expr.type();
53
54 if (exprType.isArray() && exprType.canCoerceTo(type, /*allowNarrowing=*/true)) {
55 return ConstructorArrayCast::Make(context, pos, type, std::move(args.front()));
56 }
57 }
58
59 // Check that the number of constructor arguments matches the array size.
60 if (type.columns() != args.size()) {
61 context.fErrors->error(pos, String::printf("invalid arguments to '%s' constructor "
62 "(expected %d elements, but found %d)", type.displayName().c_str(), type.columns(),
63 args.size()));
64 return nullptr;
65 }
66
67 // Convert each constructor argument to the array's component type.
68 const Type& baseType = type.componentType();
69 for (std::unique_ptr<Expression>& argument : args) {
70 argument = baseType.coerceExpression(std::move(argument), context);
71 if (!argument) {
72 return nullptr;
73 }
74 }
75
76 return ConstructorArray::Make(context, pos, type, std::move(args));
77}
#define SkASSERTF(cond, fmt,...)
Definition: SkAssert.h:117
static std::unique_ptr< Expression > Make(const Context &context, Position pos, const Type &type, std::unique_ptr< Expression > arg)
static std::unique_ptr< Expression > Make(const Context &context, Position pos, const Type &type, ExpressionArray args)
Expression(Position pos, Kind kind, const Type *type)
virtual bool isArray() const
Definition: SkSLType.h:532
std::unique_ptr< Expression > coerceExpression(std::unique_ptr< Expression > expr, const Context &context) const
virtual const Type & componentType() const
Definition: SkSLType.h:404
virtual int columns() const
Definition: SkSLType.h:429
std::string description() const override
Definition: SkSLType.h:238
virtual bool isOrContainsAtomic() const
Definition: SkSLType.h:586
std::string displayName() const
Definition: SkSLType.h:234
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83

◆ Make()

std::unique_ptr< Expression > SkSL::ConstructorArray::Make ( const Context context,
Position  pos,
const Type type,
ExpressionArray  args 
)
static

Definition at line 79 of file SkSLConstructorArray.cpp.

82 {
83 SkASSERT(!context.fConfig->strictES2Mode());
85 SkASSERT(type.columns() == args.size());
87 SkASSERT(std::all_of(args.begin(), args.end(), [&](const std::unique_ptr<Expression>& arg) {
88 return type.componentType().matches(arg->type());
89 }));
90
91 return std::make_unique<ConstructorArray>(pos, type, std::move(args));
92}
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool isAllowedInES2(const Context &context) const

Member Data Documentation

◆ kIRNodeKind

constexpr Kind SkSL::ConstructorArray::kIRNodeKind = Kind::kConstructorArray
inlinestaticconstexpr

Definition at line 30 of file SkSLConstructorArray.h.


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