• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkSLIRNode.h"
12 #include "include/private/SkSLProgramElement.h"
13 
14 namespace SkSL {
15 
16 class Type;
17 
18 /**
19  * Represents a symboltable entry.
20  */
21 class Symbol : public IRNode {
22 public:
23     using Kind = SymbolKind;
24 
25     Symbol(Position pos, Kind kind, std::string_view name, const Type* type = nullptr)
26         : INHERITED(pos, (int) kind)
27         , fName(name)
28         , fType(type) {
29         SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast);
30     }
31 
~Symbol()32     ~Symbol() override {}
33 
type()34     const Type& type() const {
35         SkASSERT(fType);
36         return *fType;
37     }
38 
kind()39     Kind kind() const {
40         return (Kind) fKind;
41     }
42 
name()43     std::string_view name() const {
44         return fName;
45     }
46 
47     /**
48      *  Don't call this directly--use SymbolTable::renameSymbol instead!
49      */
setName(std::string_view newName)50     void setName(std::string_view newName) {
51         fName = newName;
52     }
53 
54 private:
55     std::string_view fName;
56     const Type* fType;
57 
58     using INHERITED = IRNode;
59 };
60 
61 }  // namespace SkSL
62 
63 #endif
64