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

#include <SkSLBlock.h>

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

Public Types

enum class  Kind { kUnbracedBlock , kBracedScope , kCompoundStatement }
 
- Public Types inherited from SkSL::Statement
using Kind = StatementKind
 

Public Member Functions

 Block (Position pos, StatementArray statements, Kind kind=Kind::kBracedScope, std::unique_ptr< SymbolTable > symbols=nullptr)
 
const StatementArraychildren () const
 
StatementArraychildren ()
 
bool isScope () const
 
Kind blockKind () const
 
void setBlockKind (Kind kind)
 
SymbolTablesymbolTable () const
 
bool isEmpty () const override
 
std::string description () const override
 
- Public Member Functions inherited from SkSL::Statement
 Statement (Position pos, Kind kind)
 
Kind kind () 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< StatementMake (Position pos, StatementArray statements, Kind kind=Kind::kBracedScope, std::unique_ptr< SymbolTable > symbols=nullptr)
 
static std::unique_ptr< StatementMakeCompoundStatement (std::unique_ptr< Statement > existing, std::unique_ptr< Statement > additional)
 
static std::unique_ptr< BlockMakeBlock (Position pos, StatementArray statements, Kind kind=Kind::kBracedScope, std::unique_ptr< SymbolTable > symbols=nullptr)
 
- 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::kBlock
 

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

A block of multiple statements functioning as a single statement.

Definition at line 26 of file SkSLBlock.h.

Member Enumeration Documentation

◆ Kind

enum class SkSL::Block::Kind
strong
Enumerator
kUnbracedBlock 
kBracedScope 
kCompoundStatement 

Definition at line 32 of file SkSLBlock.h.

32 {
33 kUnbracedBlock, // Represents a group of statements without curly braces.
34 kBracedScope, // Represents a language-level Block, with curly braces.
35 kCompoundStatement, // A block which conceptually represents a single statement, such as
36 // `int a, b;`. (SkSL represents this internally as two statements:
37 // `int a; int b;`) Allowed to optimize away to its interior Statement.
38 // Treated as a single statement by the debugger.
39 };

Constructor & Destructor Documentation

◆ Block()

SkSL::Block::Block ( Position  pos,
StatementArray  statements,
Kind  kind = Kind::kBracedScope,
std::unique_ptr< SymbolTable symbols = nullptr 
)
inline

Definition at line 41 of file SkSLBlock.h.

45 : INHERITED(pos, kIRNodeKind)
46 , fSymbolTable(std::move(symbols))
47 , fChildren(std::move(statements))
48 , fBlockKind(kind) {}
SkPoint pos
static constexpr Kind kIRNodeKind
Definition SkSLBlock.h:28
Kind kind() const

Member Function Documentation

◆ blockKind()

Kind SkSL::Block::blockKind ( ) const
inline

Definition at line 83 of file SkSLBlock.h.

83 {
84 return fBlockKind;
85 }

◆ children() [1/2]

StatementArray & SkSL::Block::children ( )
inline

Definition at line 75 of file SkSLBlock.h.

75 {
76 return fChildren;
77 }

◆ children() [2/2]

const StatementArray & SkSL::Block::children ( ) const
inline

Definition at line 71 of file SkSLBlock.h.

71 {
72 return fChildren;
73 }

◆ description()

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

Implements SkSL::IRNode.

Definition at line 97 of file SkSLBlock.cpp.

97 {
98 std::string result;
99
100 // Write scope markers if this block is a scope, or if the block is empty (since we need to emit
101 // something here to make the code valid).
102 bool isScope = this->isScope() || this->isEmpty();
103 if (isScope) {
104 result += "{";
105 }
106 for (const std::unique_ptr<Statement>& stmt : this->children()) {
107 result += "\n";
108 result += stmt->description();
109 }
110 result += isScope ? "\n}\n" : "\n";
111 return result;
112}
bool isEmpty() const override
Definition SkSLBlock.h:95
const StatementArray & children() const
Definition SkSLBlock.h:71
bool isScope() const
Definition SkSLBlock.h:79
GAsyncResult * result

◆ isEmpty()

bool SkSL::Block::isEmpty ( ) const
inlineoverridevirtual

Reimplemented from SkSL::Statement.

Definition at line 95 of file SkSLBlock.h.

95 {
96 for (const std::unique_ptr<Statement>& stmt : this->children()) {
97 if (!stmt->isEmpty()) {
98 return false;
99 }
100 }
101 return true;
102 }

◆ isScope()

bool SkSL::Block::isScope ( ) const
inline

Definition at line 79 of file SkSLBlock.h.

79 {
80 return fBlockKind == Kind::kBracedScope;
81 }

◆ Make()

std::unique_ptr< Statement > SkSL::Block::Make ( Position  pos,
StatementArray  statements,
Kind  kind = Kind::kBracedScope,
std::unique_ptr< SymbolTable symbols = nullptr 
)
static

Definition at line 14 of file SkSLBlock.cpp.

17 {
18 // We can't simplify away braces or populated symbol tables.
19 if (kind == Kind::kBracedScope || (symbols && symbols->count())) {
20 return std::make_unique<Block>(pos, std::move(statements), kind, std::move(symbols));
21 }
22
23 // If the Block is completely empty, synthesize a Nop.
24 if (statements.empty()) {
25 return Nop::Make();
26 }
27
28 if (statements.size() > 1) {
29 // The statement array contains multiple statements, but some of those might be no-ops.
30 // If the statement array only contains one real statement, we can return that directly and
31 // avoid creating an additional Block node.
32 std::unique_ptr<Statement>* foundStatement = nullptr;
33 for (std::unique_ptr<Statement>& stmt : statements) {
34 if (!stmt->isEmpty()) {
35 if (!foundStatement) {
36 // We found a single non-empty statement. Remember it and keep looking.
37 foundStatement = &stmt;
38 continue;
39 }
40 // We found more than one non-empty statement. We actually do need a Block.
41 return std::make_unique<Block>(pos, std::move(statements), kind,
42 /*symbols=*/nullptr);
43 }
44 }
45
46 // The array wrapped one valid Statement. Avoid allocating a Block by returning it directly.
47 if (foundStatement) {
48 return std::move(*foundStatement);
49 }
50
51 // The statement array contained nothing but empty statements!
52 // In this case, we don't actually need to allocate a Block.
53 // We can just return one of those empty statements. Fall through to...
54 }
55
56 return std::move(statements.front());
57}
static std::unique_ptr< Statement > Make()
Definition SkSLNop.h:26

◆ MakeBlock()

std::unique_ptr< Block > SkSL::Block::MakeBlock ( Position  pos,
StatementArray  statements,
Kind  kind = Kind::kBracedScope,
std::unique_ptr< SymbolTable symbols = nullptr 
)
static

Definition at line 59 of file SkSLBlock.cpp.

62 {
63 // Nothing to optimize here--eliminating empty statements doesn't actually improve the generated
64 // code, and we promise to return a Block.
65 return std::make_unique<Block>(pos, std::move(statements), kind, std::move(symbols));
66}

◆ MakeCompoundStatement()

std::unique_ptr< Statement > SkSL::Block::MakeCompoundStatement ( std::unique_ptr< Statement existing,
std::unique_ptr< Statement additional 
)
static

Definition at line 68 of file SkSLBlock.cpp.

69 {
70 // If either of the two Statements is empty, return the other.
71 if (!existing || existing->isEmpty()) {
72 return additional;
73 }
74 if (!additional || additional->isEmpty()) {
75 return existing;
76 }
77
78 // If the existing statement is a compound-statement Block, append the additional statement.
79 if (existing->is<Block>()) {
80 SkSL::Block& block = existing->as<Block>();
81 if (block.blockKind() == Block::Kind::kCompoundStatement) {
82 block.children().push_back(std::move(additional));
83 return existing;
84 }
85 }
86
87 // The existing statement was not a compound-statement Block; create one, and put both
88 // statements inside of it.
89 Position pos = existing->fPosition.rangeThrough(additional->fPosition);
90 StatementArray stmts;
91 stmts.reserve_exact(2);
92 stmts.push_back(std::move(existing));
93 stmts.push_back(std::move(additional));
94 return Block::Make(pos, std::move(stmts), Block::Kind::kCompoundStatement);
95}
Kind blockKind() const
Definition SkSLBlock.h:83
const T & as() const
Definition SkSLIRNode.h:133
void reserve_exact(int n)
Definition SkTArray.h:176
skia_private::STArray< 2, std::unique_ptr< Statement > > StatementArray
Definition SkSLDefines.h:34

◆ setBlockKind()

void SkSL::Block::setBlockKind ( Kind  kind)
inline

Definition at line 87 of file SkSLBlock.h.

87 {
88 fBlockKind = kind;
89 }

◆ symbolTable()

SymbolTable * SkSL::Block::symbolTable ( ) const
inline

Definition at line 91 of file SkSLBlock.h.

91 {
92 return fSymbolTable.get();
93 }

Member Data Documentation

◆ kIRNodeKind

constexpr Kind SkSL::Block::kIRNodeKind = Kind::kBlock
inlinestaticconstexpr

Definition at line 28 of file SkSLBlock.h.


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