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_PROGRAMELEMENT
|
|
|
|
#define SKSL_PROGRAMELEMENT
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/sksl/ir/SkSLIRNode.h"
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2019-06-26 17:54:14 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a top-level element (e.g. function or global variable) in a program.
|
|
|
|
*/
|
|
|
|
struct ProgramElement : public IRNode {
|
|
|
|
enum Kind {
|
2017-11-10 20:34:03 +00:00
|
|
|
kEnum_Kind,
|
|
|
|
kExtension_Kind,
|
2016-07-01 15:22:01 +00:00
|
|
|
kFunction_Kind,
|
|
|
|
kInterfaceBlock_Kind,
|
2017-06-29 14:03:38 +00:00
|
|
|
kModifiers_Kind,
|
2017-11-10 20:34:03 +00:00
|
|
|
kSection_Kind,
|
|
|
|
kVar_Kind
|
2016-07-01 15:22:01 +00:00
|
|
|
};
|
|
|
|
|
2017-09-11 20:50:14 +00:00
|
|
|
ProgramElement(int offset, Kind kind)
|
|
|
|
: INHERITED(offset)
|
2016-07-01 15:22:01 +00:00
|
|
|
, fKind(kind) {}
|
|
|
|
|
2020-08-19 21:48:31 +00:00
|
|
|
/**
|
|
|
|
* Use as<T> to downcast program elements. e.g. replace `(Enum&) el` with `el.as<Enum>()`.
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
const T& as() const {
|
|
|
|
SkASSERT(this->fKind == T::kProgramElementKind);
|
|
|
|
return static_cast<const T&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T& as() {
|
|
|
|
SkASSERT(this->fKind == T::kProgramElementKind);
|
|
|
|
return static_cast<T&>(*this);
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
Kind fKind;
|
|
|
|
|
2018-07-31 13:44:36 +00:00
|
|
|
virtual std::unique_ptr<ProgramElement> 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
|