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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/sksl/ir/SkSLIRNode.h"
|
|
|
|
#include "src/sksl/ir/SkSLType.h"
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract supertype of all statements.
|
|
|
|
*/
|
|
|
|
struct Statement : public IRNode {
|
|
|
|
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,
|
|
|
|
kVarDeclarations,
|
|
|
|
kWhile,
|
|
|
|
|
|
|
|
kFirst = kBlock,
|
|
|
|
kLast = kWhile
|
2016-07-01 15:22:01 +00:00
|
|
|
};
|
|
|
|
|
2017-09-11 20:50:14 +00:00
|
|
|
Statement(int offset, Kind kind)
|
2020-09-08 14:22:09 +00:00
|
|
|
: INHERITED(offset, (int) kind) {
|
|
|
|
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.
|
|
|
|
* e.g. replace `s.fKind == Statement::kReturn_Kind` with `s.is<ReturnStatement>()`.
|
|
|
|
*/
|
|
|
|
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-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
|