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

#include <SkSLFieldAccess.h>

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

Public Types

using OwnerKind = FieldAccessOwnerKind
 
- Public Types inherited from SkSL::Expression
enum class  ComparisonResult { kUnknown = -1 , kNotEqual , kEqual }
 
using Kind = ExpressionKind
 

Public Member Functions

 FieldAccess (Position pos, std::unique_ptr< Expression > base, int fieldIndex, OwnerKind ownerKind=OwnerKind::kDefault)
 
std::unique_ptr< Expression > & base ()
 
const std::unique_ptr< Expression > & base () const
 
int fieldIndex () const
 
OwnerKind ownerKind () const
 
std::unique_ptr< Expressionclone (Position pos) const override
 
size_t initialSlot () const
 
std::string description (OperatorPrecedence) 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, std::unique_ptr< Expression > base, std::string_view field)
 
static std::unique_ptr< ExpressionMake (const Context &context, Position pos, std::unique_ptr< Expression > base, int fieldIndex, OwnerKind ownerKind=OwnerKind::kDefault)
 
- 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::kFieldAccess
 

Additional Inherited Members

- 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 which extracts a field from a struct, as in 'foo.bar'.

Definition at line 39 of file SkSLFieldAccess.h.

Member Typedef Documentation

◆ OwnerKind

Definition at line 41 of file SkSLFieldAccess.h.

Constructor & Destructor Documentation

◆ FieldAccess()

SkSL::FieldAccess::FieldAccess ( Position  pos,
std::unique_ptr< Expression base,
int  fieldIndex,
OwnerKind  ownerKind = OwnerKind::kDefault 
)
inline

Definition at line 45 of file SkSLFieldAccess.h.

47 : INHERITED(pos, kIRNodeKind, base->type().fields()[fieldIndex].fType)
48 , fFieldIndex(fieldIndex)
49 , fOwnerKind(ownerKind)
50 , fBase(std::move(base)) {}
SkPoint pos
int fieldIndex() const
static constexpr Kind kIRNodeKind
OwnerKind ownerKind() const

Member Function Documentation

◆ base() [1/2]

std::unique_ptr< Expression > & SkSL::FieldAccess::base ( )
inline

Definition at line 65 of file SkSLFieldAccess.h.

65 {
66 return fBase;
67 }

◆ base() [2/2]

const std::unique_ptr< Expression > & SkSL::FieldAccess::base ( ) const
inline

Definition at line 69 of file SkSLFieldAccess.h.

69 {
70 return fBase;
71 }

◆ clone()

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

Implements SkSL::Expression.

Definition at line 81 of file SkSLFieldAccess.h.

81 {
82 return std::make_unique<FieldAccess>(pos,
83 this->base()->clone(),
84 this->fieldIndex(),
85 this->ownerKind());
86 }
std::unique_ptr< Expression > clone() const
std::unique_ptr< Expression > & base()

◆ Convert()

std::unique_ptr< Expression > SkSL::FieldAccess::Convert ( const Context context,
Position  pos,
std::unique_ptr< Expression base,
std::string_view  field 
)
static

Definition at line 31 of file SkSLFieldAccess.cpp.

34 {
35 const Type& baseType = base->type();
36 if (baseType.isEffectChild()) {
37 // Turn the field name into a free function name, prefixed with '$':
38 std::string methodName = "$" + std::string(field);
39 const Symbol* result = context.fSymbolTable->find(methodName);
40 if (result && result->is<FunctionDeclaration>()) {
41 return std::make_unique<MethodReference>(context, pos, std::move(base),
42 &result->as<FunctionDeclaration>());
43 }
44 context.fErrors->error(pos, "type '" + baseType.displayName() + "' has no method named '" +
45 std::string(field) + "'");
46 return nullptr;
47 }
48 if (baseType.isStruct()) {
49 SkSpan<const Field> fields = baseType.fields();
50 for (size_t i = 0; i < fields.size(); i++) {
51 if (fields[i].fName == field) {
52 return FieldAccess::Make(context, pos, std::move(base), (int)i);
53 }
54 }
55 }
56 if (baseType.matches(*context.fTypes.fSkCaps)) {
57 return Setting::Convert(context, pos, field);
58 }
59
60 context.fErrors->error(pos, "type '" + baseType.displayName() +
61 "' does not have a field named '" + std::string(field) + "'");
62 return nullptr;
63}
const char * fName
static std::unique_ptr< Expression > Make(const Context &context, Position pos, std::unique_ptr< Expression > base, int fieldIndex, OwnerKind ownerKind=OwnerKind::kDefault)
static std::unique_ptr< Expression > Convert(const Context &context, Position pos, const std::string_view &name)
Definition: SkSLSetting.cpp:63
constexpr size_t size() const
Definition: SkSpan_impl.h:95
GAsyncResult * result

◆ description()

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

Implements SkSL::Expression.

Definition at line 116 of file SkSLFieldAccess.cpp.

116 {
117 std::string f = this->base()->description(OperatorPrecedence::kPostfix);
118 if (!f.empty()) {
119 f.push_back('.');
120 }
121 return f + std::string(this->base()->type().fields()[this->fieldIndex()].fName);
122}
const Type & type() const

◆ fieldIndex()

int SkSL::FieldAccess::fieldIndex ( ) const
inline

Definition at line 73 of file SkSLFieldAccess.h.

73 {
74 return fFieldIndex;
75 }

◆ initialSlot()

size_t SkSL::FieldAccess::initialSlot ( ) const

Definition at line 105 of file SkSLFieldAccess.cpp.

105 {
106 SkSpan<const Field> fields = this->base()->type().fields();
107 const int fieldIndex = this->fieldIndex();
108
109 size_t slot = 0;
110 for (int index = 0; index < fieldIndex; ++index) {
111 slot += fields[index].fType->slotCount();
112 }
113 return slot;
114}

◆ Make()

std::unique_ptr< Expression > SkSL::FieldAccess::Make ( const Context context,
Position  pos,
std::unique_ptr< Expression base,
int  fieldIndex,
OwnerKind  ownerKind = OwnerKind::kDefault 
)
static

Definition at line 84 of file SkSLFieldAccess.cpp.

88 {
89 SkASSERT(base->type().isStruct());
90 SkASSERT(fieldIndex >= 0);
91 SkASSERT(fieldIndex < (int)base->type().fields().size());
92
93 // Replace `knownStruct.field` with the field's value if there are no side-effects involved.
95 if (expr->is<ConstructorStruct>()) {
96 if (std::unique_ptr<Expression> field = extract_field(pos, expr->as<ConstructorStruct>(),
97 fieldIndex)) {
98 return field;
99 }
100 }
101
102 return std::make_unique<FieldAccess>(pos, std::move(base), fieldIndex, ownerKind);
103}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static const Expression * GetConstantValueForVariable(const Expression &value)
Expression(Position pos, Kind kind, const Type *type)
static std::unique_ptr< Expression > extract_field(Position pos, const ConstructorStruct &ctor, int fieldIndex)

◆ ownerKind()

OwnerKind SkSL::FieldAccess::ownerKind ( ) const
inline

Definition at line 77 of file SkSLFieldAccess.h.

77 {
78 return fOwnerKind;
79 }

Member Data Documentation

◆ kIRNodeKind

constexpr Kind SkSL::FieldAccess::kIRNodeKind = Kind::kFieldAccess
inlinestaticconstexpr

Definition at line 43 of file SkSLFieldAccess.h.


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