Flutter Engine
The Flutter Engine
SkSLSymbol.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SKSL_SYMBOL
9#define SKSL_SYMBOL
10
14
15#include <memory>
16#include <string_view>
17
18namespace SkSL {
19
20class Context;
21class Expression;
22class Type;
23
24/**
25 * Represents a symbol table entry.
26 */
27class Symbol : public IRNode {
28public:
30
31 Symbol(Position pos, Kind kind, std::string_view name, const Type* type = nullptr)
32 : INHERITED(pos, (int) kind)
33 , fName(name)
34 , fType(type) {
35 SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast);
36 }
37
38 ~Symbol() override {}
39
40 std::unique_ptr<Expression> instantiate(const Context& context, Position pos) const;
41
42 const Type& type() const {
43 SkASSERT(fType);
44 return *fType;
45 }
46
47 Kind kind() const {
48 return (Kind) fKind;
49 }
50
51 std::string_view name() const {
52 return fName;
53 }
54
55 /**
56 * Don't call this directly--use SymbolTable::renameSymbol instead!
57 */
58 void setName(std::string_view newName) {
59 fName = newName;
60 }
61
62private:
63 std::string_view fName;
64 const Type* fType;
65
66 using INHERITED = IRNode;
67};
68
69} // namespace SkSL
70
71#endif
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
IRNode(const IRNode &)=delete
std::string_view name() const
Definition: SkSLSymbol.h:51
Kind kind() const
Definition: SkSLSymbol.h:47
Symbol(Position pos, Kind kind, std::string_view name, const Type *type=nullptr)
Definition: SkSLSymbol.h:31
~Symbol() override
Definition: SkSLSymbol.h:38
void setName(std::string_view newName)
Definition: SkSLSymbol.h:58
std::unique_ptr< Expression > instantiate(const Context &context, Position pos) const
Definition: SkSLSymbol.cpp:24
const Type & type() const
Definition: SkSLSymbol.h:42
SymbolKind
Definition: SkSLIRNode.h:32