Bladeren bron

fixed shared_ptr misuse

Nicolas Winkler 6 jaren geleden
bovenliggende
commit
619ead01a7
5 gewijzigde bestanden met toevoegingen van 36 en 14 verwijderingen
  1. 14 0
      src/Builtin.h
  2. 8 2
      src/Scope.cpp
  3. 9 6
      src/Scope.h
  4. 1 1
      src/Semantic.cpp
  5. 4 5
      src/Type.h

+ 14 - 0
src/Builtin.h

@@ -11,10 +11,24 @@ namespace qlow
     namespace sem
     {
         NativeScope generateNativeScope(void);
+        
+        struct NativeMethod;
+        class IntegerNativeScope;
     }
 }
 
 
+struct qlow::sem::NativeMethod : public sem::Method
+{
+    llvm::Value* generateCode(std::vector<llvm::Value*> arguments);
+}
+
+
+class qlow::sem::IntegerNativeScope : public NativeScope
+{
+public:
+    void generateAdd();
+};
 
 
 

+ 8 - 2
src/Scope.cpp

@@ -209,7 +209,7 @@ std::string sem::LocalScope::toString(void)
 
 sem::Variable* sem::TypeScope::getVariable(const std::string& name)
 {
-    if (ClassType* ct = dynamic_cast<ClassType*>(type.get()); ct) {
+    if (ClassType* ct = dynamic_cast<ClassType*>(&type); ct) {
         auto& fields = ct->getClassType()->fields;
         if (fields.find(name) != fields.end())
             return fields[name].get();
@@ -221,7 +221,7 @@ sem::Variable* sem::TypeScope::getVariable(const std::string& name)
 
 sem::Method* sem::TypeScope::getMethod(const std::string& name)
 {
-    if (ClassType* ct = dynamic_cast<ClassType*>(type.get()); ct) {
+    if (ClassType* ct = dynamic_cast<ClassType*>(&type); ct) {
         auto& methods = ct->getClassType()->methods;
         if (methods.find(name) != methods.end())
             return methods[name].get();
@@ -249,5 +249,11 @@ std::string sem::TypeScope::toString(void)
 }
 
 
+sem::Method* sem::NativeTypeScope::getMethod(const std::string& name)
+{
+    
+}
+
+
 
 

+ 9 - 6
src/Scope.h

@@ -140,10 +140,10 @@ public:
 class qlow::sem::TypeScope : public Scope
 {
 protected:
-    std::shared_ptr<Type> type;
+    Type& type;
 public:
-    inline TypeScope(std::shared_ptr<Type> type) :
-        type{ std::move(type) }
+    inline TypeScope(Type& type) :
+        type{ type }
     {
     }
     
@@ -158,14 +158,17 @@ public:
 
 class qlow::sem::NativeTypeScope : public TypeScope
 {
+    NativeType& nativeType;
 public:
-    inline NativeTypeScope(std::shared_ptr<Type> type) :
-        TypeScope{ std::move(type) }
+    inline NativeTypeScope(NativeType& type) :
+        TypeScope{ (Type&) type },
+        nativeType{ type }
     {
     }
     
     
-    std::shared_ptr<Type> implementInlineOperation(const std::string&, llvm::Value* a); 
+    virtual Method* getMethod(const std::string& name);
+    std::shared_ptr<Type> implementInlineOperation(const std::string&, llvm::Value* a);
 };
 
 

+ 1 - 1
src/Semantic.cpp

@@ -21,7 +21,7 @@ std::unique_ptr<GlobalScope>
     Logger& logger = Logger::getInstance();
 
 #ifdef DEBUGGING
-    printf("starting building semantic representation (%d objects)\n", objects.size());
+    printf("starting building semantic representation (%d objects)\n", (int) objects.size());
 #endif
 
     // create classes

+ 4 - 5
src/Type.h

@@ -46,8 +46,7 @@ struct qlow::sem::SemanticObject
 
 
 
-class qlow::sem::Type : public SemanticObject,
-                        protected std::enable_shared_from_this<Type>
+class qlow::sem::Type : public SemanticObject
 {
 public:
     virtual ~Type(void);
@@ -75,7 +74,7 @@ class qlow::sem::ClassType : public Type
 public:
     inline ClassType(sem::Class* classType) :
         classType{ classType },
-        scope{ shared_from_this() }
+        scope{ *this }
     {
     }
     
@@ -99,7 +98,7 @@ public:
     
     inline ArrayType(std::shared_ptr<sem::Type> arrayType) :
         arrayType{ std::move(arrayType) },
-        scope{ shared_from_this() }
+        scope{ *this }
     {
     }
     
@@ -134,7 +133,7 @@ public:
     
     inline NativeType(Type type) :
         type{ type },
-        scope{ shared_from_this() }
+        scope{ *this }
     {
     }