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_SYMBOL
|
|
|
|
#define SKSL_SYMBOL
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/sksl/ir/SkSLIRNode.h"
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a symboltable entry.
|
|
|
|
*/
|
|
|
|
struct Symbol : public IRNode {
|
|
|
|
enum Kind {
|
|
|
|
kFunctionDeclaration_Kind,
|
|
|
|
kUnresolvedFunction_Kind,
|
|
|
|
kType_Kind,
|
|
|
|
kVariable_Kind,
|
2019-05-15 19:29:54 +00:00
|
|
|
kField_Kind,
|
|
|
|
kExternal_Kind
|
2016-07-01 15:22:01 +00:00
|
|
|
};
|
|
|
|
|
2017-09-11 20:50:14 +00:00
|
|
|
Symbol(int offset, Kind kind, StringFragment name)
|
2020-03-31 22:31:46 +00:00
|
|
|
: INHERITED(offset)
|
|
|
|
, fKind(kind)
|
|
|
|
, fName(name) {}
|
|
|
|
|
2020-08-14 02:58:04 +00:00
|
|
|
~Symbol() override {}
|
2018-03-01 20:05:17 +00:00
|
|
|
|
2020-08-18 14:40:03 +00:00
|
|
|
/**
|
|
|
|
* Use as<T> to downcast symbols. e.g. replace `(Variable&) sym` with `sym.as<Variable>()`.
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
const T& as() const {
|
|
|
|
SkASSERT(this->fKind == T::kSymbolKind);
|
|
|
|
return static_cast<const T&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T& as() {
|
|
|
|
SkASSERT(this->fKind == T::kSymbolKind);
|
|
|
|
return static_cast<T&>(*this);
|
|
|
|
}
|
|
|
|
|
2017-09-18 18:10:39 +00:00
|
|
|
Kind fKind;
|
2017-09-11 20:50:14 +00:00
|
|
|
StringFragment fName;
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
typedef IRNode INHERITED;
|
|
|
|
};
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace SkSL
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
#endif
|