• 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_RETURNSTATEMENT
9 #define SKSL_RETURNSTATEMENT
10 
11 #include "include/private/SkSLStatement.h"
12 #include "src/sksl/ir/SkSLExpression.h"
13 
14 namespace SkSL {
15 
16 /**
17  * A 'return' statement.
18  */
19 class ReturnStatement final : public Statement {
20 public:
21     inline static constexpr Kind kIRNodeKind = Kind::kReturn;
22 
ReturnStatement(Position pos,std::unique_ptr<Expression> expression)23     ReturnStatement(Position pos, std::unique_ptr<Expression> expression)
24         : INHERITED(pos, kIRNodeKind)
25         , fExpression(std::move(expression)) {}
26 
Make(Position pos,std::unique_ptr<Expression> expression)27     static std::unique_ptr<Statement> Make(Position pos,
28             std::unique_ptr<Expression> expression) {
29         return std::make_unique<ReturnStatement>(pos, std::move(expression));
30     }
31 
expression()32     std::unique_ptr<Expression>& expression() {
33         return fExpression;
34     }
35 
expression()36     const std::unique_ptr<Expression>& expression() const {
37         return fExpression;
38     }
39 
setExpression(std::unique_ptr<Expression> expr)40     void setExpression(std::unique_ptr<Expression> expr) {
41         fExpression = std::move(expr);
42     }
43 
clone()44     std::unique_ptr<Statement> clone() const override {
45         return std::make_unique<ReturnStatement>(fPosition,
46                 this->expression() ? this->expression()->clone() : nullptr);
47     }
48 
description()49     std::string description() const override {
50         if (this->expression()) {
51             return "return " + this->expression()->description() + ";";
52         } else {
53             return "return;";
54         }
55     }
56 
57 private:
58     std::unique_ptr<Expression> fExpression;
59 
60     using INHERITED = Statement;
61 };
62 
63 }  // namespace SkSL
64 
65 #endif
66