Context.h 603 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef QLOW_SEM_CONTEXT_H
  2. #define QLOW_SEM_CONTEXT_H
  3. #include "Type.h"
  4. #include "unordered_map"
  5. namespace qlow::sem
  6. {
  7. class Context;
  8. using TypeId = size_t;
  9. }
  10. class qlow::sem::Context
  11. {
  12. private:
  13. std::vector<std::unique_ptr<Type>> types;
  14. std::unordered_map<Type&, TypeId> typesMap;
  15. public:
  16. TypeId addType(Type&& type) {
  17. if (typesMap.contains(type)) {
  18. return typesMap[type];
  19. }
  20. else {
  21. types.push_back(std::unique_ptr<Type>(type));
  22. return types.size() - 1;
  23. }
  24. }
  25. };
  26. #endif // QLOW_SEM_CONTEXT_H