Chromium Code Reviews| Index: src/sksl/ir/SkSLSymbolTable.h |
| diff --git a/src/sksl/ir/SkSLSymbolTable.h b/src/sksl/ir/SkSLSymbolTable.h |
| index 151475d6423690d3024d322c2c3968f0a21a9066..2c9598253fc181bc0820d97150b45d2b4faf5dd2 100644 |
| --- a/src/sksl/ir/SkSLSymbolTable.h |
| +++ b/src/sksl/ir/SkSLSymbolTable.h |
| @@ -23,23 +23,38 @@ namespace SkSL { |
| class SymbolTable { |
| public: |
| SymbolTable(ErrorReporter& errorReporter) |
| - : fErrorReporter(errorReporter) {} |
| + : fOwner(true) |
|
dogben
2016/07/08 19:56:40
Would it be simpler for Block and FunctionDeclarat
|
| + , fErrorReporter(errorReporter) {} |
| - SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter& errorReporter) |
| + SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter& errorReporter, |
| + bool owner = false) |
| : fParent(parent) |
| + , fOwner(owner) |
| , fErrorReporter(errorReporter) {} |
| - std::shared_ptr<Symbol> operator[](const std::string& name); |
| + ~SymbolTable(); |
| + |
| + const Symbol* operator[](const std::string& name); |
| + |
| + // SymbolTable will take ownership of the pointer, deleting it when it is destroyed |
| + void add(const std::string& name, Symbol* symbol); |
|
dogben
2016/07/08 19:56:40
nit: use std::unique_ptr to transfer ownership
|
| - void add(const std::string& name, std::shared_ptr<Symbol> symbol); |
| + void addWithoutOwnership(const std::string& name, const Symbol* symbol); |
| + |
| + void takeOwnership(Symbol* s); |
| const std::shared_ptr<SymbolTable> fParent; |
| private: |
| - static std::vector<std::shared_ptr<FunctionDeclaration>> GetFunctions( |
| - const std::shared_ptr<Symbol>& s); |
| + static std::vector<const FunctionDeclaration*> GetFunctions(const Symbol& s); |
| + |
| + // true if this symbol should directly own the pointers it contains, false to delegate ownership |
| + // to its parent |
| + const bool fOwner; |
| + |
| + std::vector<Symbol*> fOwnedPointers; |
|
dogben
2016/07/08 19:56:40
nit: std::vector<std::unique_ptr<Symbol>> eliminat
|
| - std::unordered_map<std::string, std::shared_ptr<Symbol>> fSymbols; |
| + std::unordered_map<std::string, const Symbol*> fSymbols; |
| ErrorReporter& fErrorReporter; |
| }; |