2016-07-01 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2017-03-31 17:56:23 +00:00
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
#ifndef SKSL_STATEMENT
|
|
|
|
#define SKSL_STATEMENT
|
|
|
|
|
2021-03-09 18:10:59 +00:00
|
|
|
#include "include/private/SkSLIRNode.h"
|
|
|
|
#include "include/private/SkSLSymbol.h"
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract supertype of all statements.
|
|
|
|
*/
|
2020-10-08 09:28:32 +00:00
|
|
|
class Statement : public IRNode {
|
|
|
|
public:
|
2016-07-01 15:22:01 +00:00
|
|
|
enum Kind {
|
2020-09-08 14:22:09 +00:00
|
|
|
kBlock = (int) Symbol::Kind::kLast + 1,
|
|
|
|
kBreak,
|
|
|
|
kContinue,
|
|
|
|
kDiscard,
|
|
|
|
kDo,
|
|
|
|
kExpression,
|
|
|
|
kFor,
|
|
|
|
kIf,
|
2020-09-09 18:18:53 +00:00
|
|
|
kInlineMarker,
|
2020-09-08 14:22:09 +00:00
|
|
|
kNop,
|
|
|
|
kReturn,
|
|
|
|
kSwitch,
|
2020-09-11 19:53:40 +00:00
|
|
|
kSwitchCase,
|
2020-09-08 14:22:09 +00:00
|
|
|
kVarDeclaration,
|
|
|
|
|
|
|
|
kFirst = kBlock,
|
2020-12-15 22:08:59 +00:00
|
|
|
kLast = kVarDeclaration,
|
2016-07-01 15:22:01 +00:00
|
|
|
};
|
|
|
|
|
2021-09-27 15:20:34 +00:00
|
|
|
Statement(int line, Kind kind)
|
|
|
|
: INHERITED(line, (int) kind) {
|
2020-09-08 14:22:09 +00:00
|
|
|
SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast);
|
|
|
|
}
|
|
|
|
|
|
|
|
Kind kind() const {
|
|
|
|
return (Kind) fKind;
|
|
|
|
}
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2020-09-03 14:50:21 +00:00
|
|
|
/**
|
|
|
|
* Use is<T> to check the type of a statement.
|
2020-09-24 14:40:29 +00:00
|
|
|
* e.g. replace `s.kind() == Statement::Kind::kReturn` with `s.is<ReturnStatement>()`.
|
2020-09-03 14:50:21 +00:00
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
bool is() const {
|
|
|
|
return this->fKind == T::kStatementKind;
|
|
|
|
}
|
|
|
|
|
2020-08-18 13:30:51 +00:00
|
|
|
/**
|
|
|
|
* Use as<T> to downcast statements.
|
|
|
|
* e.g. replace `(ReturnStatement&) s` with `s.as<ReturnStatement>()`.
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
const T& as() const {
|
2020-09-03 14:50:21 +00:00
|
|
|
SkASSERT(this->is<T>());
|
2020-08-18 13:30:51 +00:00
|
|
|
return static_cast<const T&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T& as() {
|
2020-09-03 14:50:21 +00:00
|
|
|
SkASSERT(this->is<T>());
|
2020-08-18 13:30:51 +00:00
|
|
|
return static_cast<T&>(*this);
|
|
|
|
}
|
|
|
|
|
2017-04-20 23:31:52 +00:00
|
|
|
virtual bool isEmpty() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-31 13:44:36 +00:00
|
|
|
virtual std::unique_ptr<Statement> clone() const = 0;
|
|
|
|
|
2020-10-08 09:28:32 +00:00
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = IRNode;
|
2016-07-01 15:22:01 +00:00
|
|
|
};
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace SkSL
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
#endif
|