Debian Codegraph @

src/sksl/ir/SkSLSymbol.h

raw
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
11 #include "include/private/base/SkAssert.h"
12 #include "src/sksl/SkSLPosition.h"
13 #include "src/sksl/ir/SkSLIRNode.h"
14
15 #include <memory>
16 #include <string_view>
17
18 namespace SkSL {
19
20 class Context;
21 class Expression;
22 class Type;
23
24 /**
25 * Represents a symbol table entry.
26 */
27 class Symbol : public IRNode {
28 public:
29 using Kind = SymbolKind;
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
62 private:
63 std::string_view fName;
64 const Type* fType;
65
66 using INHERITED = IRNode;
67 };
68
69 } // namespace SkSL
70
71 #endif