• 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 kStatementKind = Kind::kReturn;
22 
ReturnStatement(int line,std::unique_ptr<Expression> expression)23     ReturnStatement(int line, std::unique_ptr<Expression> expression)
24         : INHERITED(line, kStatementKind)
25         , fExpression(std::move(expression)) {}
26 
Make(int line,std::unique_ptr<Expression> expression)27     static std::unique_ptr<Statement> Make(int line, std::unique_ptr<Expression> expression) {
28         return std::make_unique<ReturnStatement>(line, std::move(expression));
29     }
30 
expression()31     std::unique_ptr<Expression>& expression() {
32         return fExpression;
33     }
34 
expression()35     const std::unique_ptr<Expression>& expression() const {
36         return fExpression;
37     }
38 
setExpression(std::unique_ptr<Expression> expr)39     void setExpression(std::unique_ptr<Expression> expr) {
40         fExpression = std::move(expr);
41     }
42 
clone()43     std::unique_ptr<Statement> clone() const override {
44         return std::make_unique<ReturnStatement>(fLine, this->expression()->clone());
45     }
46 
description()47     String description() const override {
48         if (this->expression()) {
49             return "return " + this->expression()->description() + ";";
50         } else {
51             return String("return;");
52         }
53     }
54 
55 private:
56     std::unique_ptr<Expression> fExpression;
57 
58     using INHERITED = Statement;
59 };
60 
61 }  // namespace SkSL
62 
63 #endif
64