Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
SkSL::ExpressionStatement Class Referencefinal

#include <SkSLExpressionStatement.h>

Inheritance diagram for SkSL::ExpressionStatement:
SkSL::Statement SkSL::IRNode SkSL::Poolable

Public Member Functions

 ExpressionStatement (std::unique_ptr< Expression > expression)
 
const std::unique_ptr< Expression > & expression () const
 
std::unique_ptr< Expression > & expression ()
 
std::string description () const override
 
- Public Member Functions inherited from SkSL::Statement
 Statement (Position pos, Kind kind)
 
Kind kind () const
 
virtual bool isEmpty () const
 
- Public Member Functions inherited from SkSL::IRNode
virtual ~IRNode ()
 
 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< StatementConvert (const Context &context, std::unique_ptr< Expression > expr)
 
static std::unique_ptr< StatementMake (const Context &context, std::unique_ptr< Expression > expr)
 
- 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::kExpression
 

Additional Inherited Members

- Public Types inherited from SkSL::Statement
using Kind = StatementKind
 
- 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

A lone expression being used as a statement.

Definition at line 26 of file SkSLExpressionStatement.h.

Constructor & Destructor Documentation

◆ ExpressionStatement()

SkSL::ExpressionStatement::ExpressionStatement ( std::unique_ptr< Expression expression)
inline

Definition at line 30 of file SkSLExpressionStatement.h.

31 : INHERITED(expression->fPosition, kIRNodeKind)
32 , fExpression(std::move(expression)) {}
static constexpr Kind kIRNodeKind
const std::unique_ptr< Expression > & expression() const

Member Function Documentation

◆ Convert()

std::unique_ptr< Statement > SkSL::ExpressionStatement::Convert ( const Context context,
std::unique_ptr< Expression expr 
)
static

Definition at line 21 of file SkSLExpressionStatement.cpp.

22 {
23 // Expression-statements need to represent a complete expression.
24 // Report an error on intermediate expressions, like FunctionReference or TypeReference.
25 if (expr->isIncomplete(context)) {
26 return nullptr;
27 }
28 return ExpressionStatement::Make(context, std::move(expr));
29}
static std::unique_ptr< Statement > Make(const Context &context, std::unique_ptr< Expression > expr)

◆ description()

std::string SkSL::ExpressionStatement::description ( ) const
overridevirtual

Implements SkSL::IRNode.

Definition at line 58 of file SkSLExpressionStatement.cpp.

58 {
59 return this->expression()->description(OperatorPrecedence::kStatement) + ";";
60}

◆ expression() [1/2]

std::unique_ptr< Expression > & SkSL::ExpressionStatement::expression ( )
inline

Definition at line 46 of file SkSLExpressionStatement.h.

46 {
47 return fExpression;
48 }

◆ expression() [2/2]

const std::unique_ptr< Expression > & SkSL::ExpressionStatement::expression ( ) const
inline

Definition at line 42 of file SkSLExpressionStatement.h.

42 {
43 return fExpression;
44 }

◆ Make()

std::unique_ptr< Statement > SkSL::ExpressionStatement::Make ( const Context context,
std::unique_ptr< Expression expr 
)
static

Definition at line 31 of file SkSLExpressionStatement.cpp.

32 {
33 SkASSERT(!expr->isIncomplete(context));
34
35 if (context.fConfig->fSettings.fOptimize) {
36 // Expression-statements without any side effect can be replaced with a Nop.
37 if (!Analysis::HasSideEffects(*expr)) {
38 return Nop::Make();
39 }
40
41 // If this is an assignment statement like `a += b;`, the ref-kind of `a` will be set as
42 // read-write; `a` is written-to by the +=, and read-from by the consumer of the expression.
43 // We can demote the ref-kind to "write" safely, because the result of the expression is
44 // discarded; that is, `a` is never actually read-from.
45 if (expr->is<BinaryExpression>()) {
46 BinaryExpression& binary = expr->as<BinaryExpression>();
47 if (VariableReference* assignedVar = binary.isAssignmentIntoVariable()) {
48 if (assignedVar->refKind() == VariableRefKind::kReadWrite) {
49 assignedVar->setRefKind(VariableRefKind::kWrite);
50 }
51 }
52 }
53 }
54
55 return std::make_unique<ExpressionStatement>(std::move(expr));
56}
#define SkASSERT(cond)
Definition SkAssert.h:116
static std::unique_ptr< Statement > Make()
Definition SkSLNop.h:26
bool HasSideEffects(const Expression &expr)

Member Data Documentation

◆ kIRNodeKind

constexpr Kind SkSL::ExpressionStatement::kIRNodeKind = Kind::kExpression
inlinestaticconstexpr

Definition at line 28 of file SkSLExpressionStatement.h.


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