• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/private/SkSLStatement.h"
12 #include "src/sksl/ir/SkSLExpression.h"
13 
14 namespace SkSL {
15 
16 /**
17  * A lone expression being used as a statement.
18  */
19 class ExpressionStatement final : public Statement {
20 public:
21     inline static constexpr Kind kStatementKind = Kind::kExpression;
22 
ExpressionStatement(std::unique_ptr<Expression> expression)23     ExpressionStatement(std::unique_ptr<Expression> expression)
24         : INHERITED(expression->fLine, kStatementKind)
25         , fExpression(std::move(expression)) {}
26 
27     // Creates an SkSL expression-statement. Note that there is never any type-coercion and no error
28     // cases are reported; any Expression can be an ExpressionStatement.
29     static std::unique_ptr<Statement> Make(const Context& context,
30                                            std::unique_ptr<Expression> expr);
31 
expression()32     const std::unique_ptr<Expression>& expression() const {
33         return fExpression;
34     }
35 
expression()36     std::unique_ptr<Expression>& expression() {
37         return fExpression;
38     }
39 
clone()40     std::unique_ptr<Statement> clone() const override {
41         return std::make_unique<ExpressionStatement>(this->expression()->clone());
42     }
43 
description()44     String description() const override {
45         return this->expression()->description() + ";";
46     }
47 
48 private:
49     std::unique_ptr<Expression> fExpression;
50 
51     using INHERITED = Statement;
52 };
53 
54 }  // namespace SkSL
55 
56 #endif
57