SkSLSymbolTable.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef SKSL_SYMBOLTABLE
  8. #define SKSL_SYMBOLTABLE
  9. #include <unordered_map>
  10. #include <memory>
  11. #include <vector>
  12. #include "src/sksl/SkSLErrorReporter.h"
  13. #include "src/sksl/ir/SkSLSymbol.h"
  14. namespace SkSL {
  15. struct FunctionDeclaration;
  16. /**
  17. * Maps identifiers to symbols. Functions, in particular, are mapped to either FunctionDeclaration
  18. * or UnresolvedFunction depending on whether they are overloaded or not.
  19. */
  20. class SymbolTable {
  21. public:
  22. SymbolTable(ErrorReporter* errorReporter)
  23. : fErrorReporter(*errorReporter) {}
  24. SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter* errorReporter)
  25. : fParent(parent)
  26. , fErrorReporter(*errorReporter) {}
  27. const Symbol* operator[](StringFragment name);
  28. void add(StringFragment name, std::unique_ptr<Symbol> symbol);
  29. void addWithoutOwnership(StringFragment name, const Symbol* symbol);
  30. Symbol* takeOwnership(std::unique_ptr<Symbol> s);
  31. IRNode* takeOwnership(std::unique_ptr<IRNode> n);
  32. void markAllFunctionsBuiltin();
  33. std::unordered_map<StringFragment, const Symbol*>::iterator begin();
  34. std::unordered_map<StringFragment, const Symbol*>::iterator end();
  35. const std::shared_ptr<SymbolTable> fParent;
  36. private:
  37. static std::vector<const FunctionDeclaration*> GetFunctions(const Symbol& s);
  38. std::vector<std::unique_ptr<Symbol>> fOwnedSymbols;
  39. std::vector<std::unique_ptr<IRNode>> fOwnedNodes;
  40. std::unordered_map<StringFragment, const Symbol*> fSymbols;
  41. ErrorReporter& fErrorReporter;
  42. };
  43. } // namespace
  44. #endif