Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
src
sksl
ir
SkSLExpressionStatement.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2021 Google LLC
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
src/sksl/ir/SkSLExpressionStatement.h
"
9
10
#include "
include/core/SkTypes.h
"
11
#include "
src/sksl/SkSLAnalysis.h
"
12
#include "
src/sksl/SkSLContext.h
"
13
#include "
src/sksl/SkSLOperator.h
"
14
#include "
src/sksl/SkSLProgramSettings.h
"
15
#include "
src/sksl/ir/SkSLBinaryExpression.h
"
16
#include "
src/sksl/ir/SkSLNop.h
"
17
#include "
src/sksl/ir/SkSLVariableReference.h
"
18
19
namespace
SkSL
{
20
21
std::unique_ptr<Statement>
ExpressionStatement::Convert
(
const
Context
& context,
22
std::unique_ptr<Expression> expr) {
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
}
30
31
std::unique_ptr<Statement>
ExpressionStatement::Make
(
const
Context
& context,
32
std::unique_ptr<Expression> expr) {
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
}
57
58
std::string
ExpressionStatement::description
()
const
{
59
return
this->
expression
()->description(
OperatorPrecedence::kStatement
) +
";"
;
60
}
61
62
}
// namespace SkSL
SkASSERT
#define SkASSERT(cond)
Definition
SkAssert.h:116
SkSLAnalysis.h
SkSLBinaryExpression.h
SkSLContext.h
SkSLExpressionStatement.h
SkSLNop.h
SkSLOperator.h
SkSLProgramSettings.h
SkSLVariableReference.h
SkTypes.h
SkSL::BinaryExpression
Definition
SkSLBinaryExpression.h:30
SkSL::Context
Definition
SkSLContext.h:24
SkSL::Context::fConfig
ProgramConfig * fConfig
Definition
SkSLContext.h:33
SkSL::ExpressionStatement::description
std::string description() const override
Definition
SkSLExpressionStatement.cpp:58
SkSL::ExpressionStatement::Convert
static std::unique_ptr< Statement > Convert(const Context &context, std::unique_ptr< Expression > expr)
Definition
SkSLExpressionStatement.cpp:21
SkSL::ExpressionStatement::Make
static std::unique_ptr< Statement > Make(const Context &context, std::unique_ptr< Expression > expr)
Definition
SkSLExpressionStatement.cpp:31
SkSL::ExpressionStatement::expression
const std::unique_ptr< Expression > & expression() const
Definition
SkSLExpressionStatement.h:42
SkSL::Nop::Make
static std::unique_ptr< Statement > Make()
Definition
SkSLNop.h:26
SkSL::VariableReference
Definition
SkSLVariableReference.h:41
SkSL::Analysis::HasSideEffects
bool HasSideEffects(const Expression &expr)
Definition
SkSLHasSideEffects.cpp:22
SkSL
Definition
SkCapabilities.h:15
SkSL::VariableRefKind::kWrite
@ kWrite
SkSL::VariableRefKind::kReadWrite
@ kReadWrite
SkSL::OperatorPrecedence::kStatement
@ kStatement
SkSL::ProgramConfig::fSettings
ProgramSettings fSettings
Definition
SkSLProgramSettings.h:85
SkSL::ProgramSettings::fOptimize
bool fOptimize
Definition
SkSLProgramSettings.h:46
Generated on Fri Apr 26 2024 06:17:31 for Flutter Engine by
1.9.8