• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkSLContext.h"
9 #include "src/sksl/SkSLProgramSettings.h"
10 #include "src/sksl/ir/SkSLExpressionStatement.h"
11 #include "src/sksl/ir/SkSLNop.h"
12 
13 namespace SkSL {
14 
Make(const Context & context,std::unique_ptr<Expression> expr)15 std::unique_ptr<Statement> ExpressionStatement::Make(const Context& context,
16                                                      std::unique_ptr<Expression> expr) {
17     if (context.fConfig->fSettings.fOptimize) {
18         // Expression-statements without any side effect can be replaced with a Nop.
19         if (!expr->hasSideEffects()) {
20             return Nop::Make();
21         }
22     }
23 
24     return std::make_unique<ExpressionStatement>(std::move(expr));
25 }
26 
27 }  // namespace SkSL
28