blob: 0a35912ddfb434e297f01a41872429c2abdd1f9d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_SYMBOLTABLE
#define SKSL_SYMBOLTABLE
#include <map>
#include <memory>
#include <vector>
#include "SkSLErrorReporter.h"
#include "SkSLSymbol.h"
namespace SkSL {
struct FunctionDeclaration;
/**
* Maps identifiers to symbols. Functions, in particular, are mapped to either FunctionDeclaration
* or UnresolvedFunction depending on whether they are overloaded or not.
*/
class SymbolTable {
public:
SymbolTable(ErrorReporter* errorReporter)
: fErrorReporter(*errorReporter) {}
SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter* errorReporter)
: fParent(parent)
, fErrorReporter(*errorReporter) {}
const Symbol* operator[](StringFragment name);
void add(StringFragment name, std::unique_ptr<Symbol> symbol);
void addWithoutOwnership(StringFragment name, const Symbol* symbol);
Symbol* takeOwnership(Symbol* s);
IRNode* takeOwnership(IRNode* n);
void markAllFunctionsBuiltin();
std::map<StringFragment, const Symbol*>::iterator begin();
std::map<StringFragment, const Symbol*>::iterator end();
const std::shared_ptr<SymbolTable> fParent;
private:
static std::vector<const FunctionDeclaration*> GetFunctions(const Symbol& s);
std::vector<std::unique_ptr<Symbol>> fOwnedSymbols;
std::vector<std::unique_ptr<IRNode>> fOwnedNodes;
std::map<StringFragment, const Symbol*> fSymbols;
ErrorReporter& fErrorReporter;
};
} // namespace
#endif
|