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

#include <SkSLIfStatement.h>

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

Public Member Functions

 IfStatement (Position pos, std::unique_ptr< Expression > test, std::unique_ptr< Statement > ifTrue, std::unique_ptr< Statement > ifFalse)
 
std::unique_ptr< Expression > & test ()
 
const std::unique_ptr< Expression > & test () const
 
std::unique_ptr< Statement > & ifTrue ()
 
const std::unique_ptr< Statement > & ifTrue () const
 
std::unique_ptr< Statement > & ifFalse ()
 
const std::unique_ptr< Statement > & ifFalse () const
 
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, Position pos, std::unique_ptr< Expression > test, std::unique_ptr< Statement > ifTrue, std::unique_ptr< Statement > ifFalse)
 
static std::unique_ptr< StatementMake (const Context &context, Position pos, std::unique_ptr< Expression > test, std::unique_ptr< Statement > ifTrue, std::unique_ptr< Statement > ifFalse)
 
- 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::kIf
 

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

An 'if' statement.

Definition at line 27 of file SkSLIfStatement.h.

Constructor & Destructor Documentation

◆ IfStatement()

SkSL::IfStatement::IfStatement ( Position  pos,
std::unique_ptr< Expression test,
std::unique_ptr< Statement ifTrue,
std::unique_ptr< Statement ifFalse 
)
inline

Definition at line 31 of file SkSLIfStatement.h.

33 : INHERITED(pos, kIRNodeKind)
34 , fTest(std::move(test))
35 , fIfTrue(std::move(ifTrue))
36 , fIfFalse(std::move(ifFalse)) {}
SkPoint pos
static constexpr Kind kIRNodeKind
std::unique_ptr< Statement > & ifTrue()
std::unique_ptr< Statement > & ifFalse()

Member Function Documentation

◆ Convert()

std::unique_ptr< Statement > SkSL::IfStatement::Convert ( const Context context,
Position  pos,
std::unique_ptr< Expression test,
std::unique_ptr< Statement ifTrue,
std::unique_ptr< Statement ifFalse 
)
static

Definition at line 32 of file SkSLIfStatement.cpp.

36 {
37 test = context.fTypes.fBool->coerceExpression(std::move(test), context);
38 if (!test) {
39 return nullptr;
40 }
43 return nullptr;
44 }
46 return nullptr;
47 }
48 return IfStatement::Make(context, pos, std::move(test), std::move(ifTrue), std::move(ifFalse));
49}
#define SkASSERT(cond)
Definition SkAssert.h:116
static std::unique_ptr< Statement > Make(const Context &context, Position pos, std::unique_ptr< Expression > test, std::unique_ptr< Statement > ifTrue, std::unique_ptr< Statement > ifFalse)
bool DetectVarDeclarationWithoutScope(const Statement &stmt, ErrorReporter *errors=nullptr)

◆ description()

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

Implements SkSL::IRNode.

Definition at line 23 of file SkSLIfStatement.cpp.

23 {
24 std::string result;
25 result += "if (" + this->test()->description() + ") " + this->ifTrue()->description();
26 if (this->ifFalse()) {
27 result += " else " + this->ifFalse()->description();
28 }
29 return result;
30}
std::unique_ptr< Expression > & test()
GAsyncResult * result

◆ ifFalse() [1/2]

std::unique_ptr< Statement > & SkSL::IfStatement::ifFalse ( )
inline

Definition at line 69 of file SkSLIfStatement.h.

69 {
70 return fIfFalse;
71 }

◆ ifFalse() [2/2]

const std::unique_ptr< Statement > & SkSL::IfStatement::ifFalse ( ) const
inline

Definition at line 73 of file SkSLIfStatement.h.

73 {
74 return fIfFalse;
75 }

◆ ifTrue() [1/2]

std::unique_ptr< Statement > & SkSL::IfStatement::ifTrue ( )
inline

Definition at line 61 of file SkSLIfStatement.h.

61 {
62 return fIfTrue;
63 }

◆ ifTrue() [2/2]

const std::unique_ptr< Statement > & SkSL::IfStatement::ifTrue ( ) const
inline

Definition at line 65 of file SkSLIfStatement.h.

65 {
66 return fIfTrue;
67 }

◆ Make()

std::unique_ptr< Statement > SkSL::IfStatement::Make ( const Context context,
Position  pos,
std::unique_ptr< Expression test,
std::unique_ptr< Statement ifTrue,
std::unique_ptr< Statement ifFalse 
)
static

Definition at line 57 of file SkSLIfStatement.cpp.

61 {
62 SkASSERT(test->type().matches(*context.fTypes.fBool));
65
66 const bool optimize = context.fConfig->fSettings.fOptimize;
67 bool trueIsEmpty = false;
68 bool falseIsEmpty = false;
69
70 if (optimize) {
71 // If both sides are empty, the if statement can be reduced to its test expression.
72 trueIsEmpty = ifTrue->isEmpty();
73 falseIsEmpty = !ifFalse || ifFalse->isEmpty();
74 if (trueIsEmpty && falseIsEmpty) {
75 return ExpressionStatement::Make(context, std::move(test));
76 }
77 }
78
79 if (optimize) {
80 // Static Boolean values can fold down to a single branch.
81 const Expression* testValue = ConstantFolder::GetConstantValueForVariable(*test);
82 if (testValue->isBoolLiteral()) {
83 if (testValue->as<Literal>().boolValue()) {
84 return replace_empty_with_nop(std::move(ifTrue), trueIsEmpty);
85 } else {
86 return replace_empty_with_nop(std::move(ifFalse), falseIsEmpty);
87 }
88 }
89 }
90
91 if (optimize) {
92 // Replace an empty if-true branches with Nop; eliminate empty if-false branches entirely.
93 ifTrue = replace_empty_with_nop(std::move(ifTrue), trueIsEmpty);
94 if (falseIsEmpty) {
95 ifFalse = nullptr;
96 }
97 }
98
99 return std::make_unique<IfStatement>(
100 pos, std::move(test), std::move(ifTrue), std::move(ifFalse));
101}
static SkTileMode optimize(SkTileMode tm, int dimension)
static const Expression * GetConstantValueForVariable(const Expression &value)
static std::unique_ptr< Statement > Make(const Context &context, std::unique_ptr< Expression > expr)
static std::unique_ptr< Statement > replace_empty_with_nop(std::unique_ptr< Statement > stmt, bool isEmpty)

◆ test() [1/2]

std::unique_ptr< Expression > & SkSL::IfStatement::test ( )
inline

Definition at line 53 of file SkSLIfStatement.h.

53 {
54 return fTest;
55 }

◆ test() [2/2]

const std::unique_ptr< Expression > & SkSL::IfStatement::test ( ) const
inline

Definition at line 57 of file SkSLIfStatement.h.

57 {
58 return fTest;
59 }

Member Data Documentation

◆ kIRNodeKind

constexpr Kind SkSL::IfStatement::kIRNodeKind = Kind::kIf
inlinestaticconstexpr

Definition at line 29 of file SkSLIfStatement.h.


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