Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLHasSideEffects.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 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
19
20namespace SkSL {
21
23 class HasSideEffectsVisitor : public ProgramVisitor {
24 public:
25 bool visitExpression(const Expression& expr) override {
26 switch (expr.kind()) {
27 case Expression::Kind::kFunctionCall: {
28 const FunctionCall& call = expr.as<FunctionCall>();
29 if (!call.function().modifierFlags().isPure()) {
30 return true;
31 }
32 break;
33 }
34 case Expression::Kind::kPrefix: {
35 const PrefixExpression& prefix = expr.as<PrefixExpression>();
36 if (prefix.getOperator().kind() == Operator::Kind::PLUSPLUS ||
37 prefix.getOperator().kind() == Operator::Kind::MINUSMINUS) {
38 return true;
39 }
40 break;
41 }
42 case Expression::Kind::kBinary: {
43 const BinaryExpression& binary = expr.as<BinaryExpression>();
44 if (binary.getOperator().isAssignment()) {
45 return true;
46 }
47 break;
48 }
49 case Expression::Kind::kPostfix:
50 return true;
51
52 default:
53 break;
54 }
55 return INHERITED::visitExpression(expr);
56 }
57
59 };
60
61 HasSideEffectsVisitor visitor;
62 return visitor.visitExpression(expr);
63}
64
65} // namespace SkSL
#define INHERITED(method,...)
Kind kind() const
const T & as() const
Definition SkSLIRNode.h:133
bool HasSideEffects(const Expression &expr)