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