1 /* 2 * Copyright 2016 Google Inc. 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 #ifndef SKSL_EXPRESSIONSTATEMENT 9 #define SKSL_EXPRESSIONSTATEMENT 10 11 #include "src/sksl/ir/SkSLExpression.h" 12 #include "src/sksl/ir/SkSLIRNode.h" 13 #include "src/sksl/ir/SkSLStatement.h" 14 15 #include <memory> 16 #include <string> 17 #include <utility> 18 19 namespace SkSL { 20 21 class Context; 22 23 /** 24 * A lone expression being used as a statement. 25 */ 26 class ExpressionStatement final : public Statement { 27 public: 28 inline static constexpr Kind kIRNodeKind = Kind::kExpression; 29 ExpressionStatement(std::unique_ptr<Expression> expression)30 ExpressionStatement(std::unique_ptr<Expression> expression) 31 : INHERITED(expression->fPosition, kIRNodeKind) 32 , fExpression(std::move(expression)) {} 33 34 // Creates an SkSL expression-statement; reports errors via ErrorReporter. 35 static std::unique_ptr<Statement> Convert(const Context& context, 36 std::unique_ptr<Expression> expr); 37 38 // Creates an SkSL expression-statement; reports errors via assertion. 39 static std::unique_ptr<Statement> Make(const Context& context, 40 std::unique_ptr<Expression> expr); 41 expression()42 const std::unique_ptr<Expression>& expression() const { 43 return fExpression; 44 } 45 expression()46 std::unique_ptr<Expression>& expression() { 47 return fExpression; 48 } 49 50 std::string description() const override; 51 52 private: 53 std::unique_ptr<Expression> fExpression; 54 55 using INHERITED = Statement; 56 }; 57 58 } // namespace SkSL 59 60 #endif 61