Bläddra i källkod

added stuff to context

QlowB 6 år sedan
förälder
incheckning
22bc412da3
2 ändrade filer med 17 tillägg och 1 borttagningar
  1. 1 1
      src/makefile
  2. 16 0
      src/sem/Context.h

+ 1 - 1
src/makefile

@@ -5,7 +5,7 @@ CXX := clang++
 
 LLVMCONFIG := llvm-config-5.0
 
-INCLUDEDIRS := -I $(shell $(LLVMCONFIG) --includedir) -I . -I sem/
+INCLUDEDIRS := -I$(shell $(LLVMCONFIG) --includedir):. -I.. -Isem/
 CXXFLAGS := -std=c++17 $(INCLUDEDIRS) -w # -Wall -Wextra
 
 ifdef STATIC

+ 16 - 0
src/sem/Context.h

@@ -2,17 +2,33 @@
 #define QLOW_SEM_CONTEXT_H
 
 #include "Type.h"
+#include "unordered_map"
 
 namespace qlow::sem
 {
     class Context;
+    
+    using TypeId = size_t;
 }
 
 
 class qlow::sem::Context
 {
 private:
+    std::vector<std::unique_ptr<Type>> types;
+    std::unordered_map<Type&, TypeId> typesMap;
+    
+public:
     
+    TypeId addType(Type&& type) {
+        if (typesMap.contains(type)) {
+            return typesMap[type];
+        }
+        else {
+            types.push_back(std::unique_ptr<Type>(type));
+            return types.size() - 1;
+        }
+    }
 };
 
 #endif // QLOW_SEM_CONTEXT_H