Line data Source code
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_SYMBOLTABLE
9 : #define SKSL_SYMBOLTABLE
10 :
11 : #include <memory>
12 : #include <unordered_map>
13 : #include <vector>
14 : #include "SkSLErrorReporter.h"
15 : #include "SkSLSymbol.h"
16 :
17 : namespace SkSL {
18 :
19 : struct FunctionDeclaration;
20 :
21 : /**
22 : * Maps identifiers to symbols. Functions, in particular, are mapped to either FunctionDeclaration
23 : * or UnresolvedFunction depending on whether they are overloaded or not.
24 : */
25 0 : class SymbolTable {
26 : public:
27 0 : SymbolTable(ErrorReporter* errorReporter)
28 0 : : fErrorReporter(*errorReporter) {}
29 :
30 0 : SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter* errorReporter)
31 0 : : fParent(parent)
32 0 : , fErrorReporter(*errorReporter) {}
33 :
34 : const Symbol* operator[](const String& name);
35 :
36 : void add(const String& name, std::unique_ptr<Symbol> symbol);
37 :
38 : void addWithoutOwnership(const String& name, const Symbol* symbol);
39 :
40 : Symbol* takeOwnership(Symbol* s);
41 :
42 : void markAllFunctionsBuiltin();
43 :
44 : const std::shared_ptr<SymbolTable> fParent;
45 :
46 : private:
47 : static std::vector<const FunctionDeclaration*> GetFunctions(const Symbol& s);
48 :
49 : std::vector<std::unique_ptr<Symbol>> fOwnedPointers;
50 :
51 : std::unordered_map<String, const Symbol*> fSymbols;
52 :
53 : ErrorReporter& fErrorReporter;
54 : };
55 :
56 : } // namespace
57 :
58 : #endif
|