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

#include <SkSLConstructorStruct.h>

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

Public Member Functions

 ConstructorStruct (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::kConstructorStruct
 

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 struct object, such as "Color(red, green, blue, 1)".

Definition at line 28 of file SkSLConstructorStruct.h.

Constructor & Destructor Documentation

◆ ConstructorStruct()

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

Definition at line 32 of file SkSLConstructorStruct.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::ConstructorStruct::clone ( Position  pos) const
inlineoverridevirtual

Implements SkSL::Expression.

Definition at line 48 of file SkSLConstructorStruct.h.

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

◆ Convert()

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

Definition at line 23 of file SkSLConstructorStruct.cpp.

26 {
27 SkASSERTF(type.isStruct() && type.fields().size() > 0, "%s", type.description().c_str());
28
29 // Check that the number of constructor arguments matches the array size.
30 if (type.fields().size() != SkToSizeT(args.size())) {
31 context.fErrors->error(pos,
32 String::printf("invalid arguments to '%s' constructor "
33 "(expected %zu elements, but found %d)",
34 type.displayName().c_str(), type.fields().size(),
35 args.size()));
36 return nullptr;
37 }
38
39 // A struct with atomic members cannot be constructed.
41 context.fErrors->error(
42 pos,
43 String::printf("construction of struct type '%s' with atomic member is not allowed",
44 type.displayName().c_str()));
45 return nullptr;
46 }
47
48 // Convert each constructor argument to the struct's field type.
49 for (int index=0; index<args.size(); ++index) {
50 std::unique_ptr<Expression>& argument = args[index];
51 const Field& field = type.fields()[index];
52
53 argument = field.fType->coerceExpression(std::move(argument), context);
54 if (!argument) {
55 return nullptr;
56 }
57 }
58
59 return ConstructorStruct::Make(context, pos, type, std::move(args));
60}
#define SkASSERTF(cond, fmt,...)
Definition: SkAssert.h:117
constexpr size_t SkToSizeT(S x)
Definition: SkTo.h:31
static std::unique_ptr< Expression > Make(const Context &context, Position pos, const Type &type, ExpressionArray args)
virtual SkSpan< const Field > fields() const
Definition: SkSLType.h:469
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
virtual bool isStruct() const
Definition: SkSLType.h:540
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::ConstructorStruct::Make ( const Context context,
Position  pos,
const Type type,
ExpressionArray  args 
)
static

Definition at line 77 of file SkSLConstructorStruct.cpp.

80 {
84 return std::make_unique<ConstructorStruct>(pos, type, std::move(args));
85}
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool isAllowedInES2(const Context &context) const
static bool arguments_match_field_types(const ExpressionArray &args, const Type &type)

Member Data Documentation

◆ kIRNodeKind

constexpr Kind SkSL::ConstructorStruct::kIRNodeKind = Kind::kConstructorStruct
inlinestaticconstexpr

Definition at line 30 of file SkSLConstructorStruct.h.


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