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