| 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 "src/sksl/ir/SkSLExpression.h" |
| 12 |
#include "src/sksl/ir/SkSLStatement.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 |
|
| 23 |
ReturnStatement(Position pos, std::unique_ptr<Expression> expression) |
| 24 |
: INHERITED(pos, kIRNodeKind) |
| 25 |
, fExpression(std::move(expression)) {} |
| 26 |
|
| 27 |
static std::unique_ptr<Statement> Make(Position pos, std::unique_ptr<Expression> expression) { |
| 28 |
return std::make_unique<ReturnStatement>(pos, std::move(expression)); |
| 29 |
} |
| 30 |
|
| 31 |
std::unique_ptr<Expression>& expression() { |
| 32 |
return fExpression; |
| 33 |
} |
| 34 |
|
| 35 |
const std::unique_ptr<Expression>& expression() const { |
| 36 |
return fExpression; |
| 37 |
} |
| 38 |
|
| 39 |
void setExpression(std::unique_ptr<Expression> expr) { |
| 40 |
fExpression = std::move(expr); |
| 41 |
} |
| 42 |
|
| 43 |
std::string description() const override { |
| 44 |
if (this->expression()) { |
| 45 |
return "return " + this->expression()->description() + ";"; |
| 46 |
} else { |
| 47 |
return "return;"; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
private: |
| 52 |
std::unique_ptr<Expression> fExpression; |
| 53 |
|
| 54 |
using INHERITED = Statement; |
| 55 |
}; |
| 56 |
|
| 57 |
} // namespace SkSL |
| 58 |
|
| 59 |
#endif |