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)15std::unique_ptr<Statement> ExpressionStatement::Make(const Context& context, 16 std::unique_ptr<Expression> expr) { 17 if (expr->isIncomplete(context)) { 18 return nullptr; 19 } 20 21 if (context.fConfig->fSettings.fOptimize) { 22 // Expression-statements without any side effect can be replaced with a Nop. 23 if (!expr->hasSideEffects()) { 24 return Nop::Make(); 25 } 26 } 27 28 return std::make_unique<ExpressionStatement>(std::move(expr)); 29 } 30 31 } // namespace SkSL 32