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 {
|
|
|
|
kBlock_Kind,
|
|
|
|
kBreak_Kind,
|
|
|
|
kContinue_Kind,
|
|
|
|
kDiscard_Kind,
|
|
|
|
kDo_Kind,
|
|
|
|
kExpression_Kind,
|
|
|
|
kFor_Kind,
|
|
|
|
kIf_Kind,
|
2017-04-20 23:31:52 +00:00
|
|
|
kNop_Kind,
|
2016-07-01 15:22:01 +00:00
|
|
|
kReturn_Kind,
|
2017-02-27 18:26:45 +00:00
|
|
|
kSwitch_Kind,
|
2017-11-07 14:42:10 +00:00
|
|
|
kVarDeclaration_Kind,
|
2016-09-07 20:37:16 +00:00
|
|
|
kVarDeclarations_Kind,
|
2016-07-01 15:22:01 +00:00
|
|
|
kWhile_Kind
|
|
|
|
};
|
|
|
|
|
2017-09-11 20:50:14 +00:00
|
|
|
Statement(int offset, Kind kind)
|
|
|
|
: INHERITED(offset)
|
2016-07-01 15:22:01 +00:00
|
|
|
, fKind(kind) {}
|
|
|
|
|
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;
|
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
const Kind fKind;
|
|
|
|
|
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
|