Nicolas Winkler 6 anos atrás
pai
commit
e5a726a99d
6 arquivos alterados com 131 adições e 17 exclusões
  1. 4 0
      src/Operation.cpp
  2. 19 0
      src/Operation.h
  3. 53 9
      src/Scope.cpp
  4. 40 3
      src/Scope.h
  5. 3 1
      src/Type.cpp
  6. 12 4
      src/Type.h

+ 4 - 0
src/Operation.cpp

@@ -0,0 +1,4 @@
+#include "Operation.h"
+
+
+

+ 19 - 0
src/Operation.h

@@ -0,0 +1,19 @@
+#ifndef QLOW_SEM_OPERATION_H
+#define QLOW_SEM_OPERATION_H
+
+
+namespace qlow
+{
+    namespace sem
+    {
+        class InlineOperation;
+    }
+}
+
+
+class qlow::sem::InlineOperation
+{
+    
+}
+
+#endif // QLOW_SEM_OPERATION_H

+ 53 - 9
src/Scope.cpp

@@ -105,22 +105,22 @@ std::string sem::NativeScope::toString(void)
 
 sem::Variable* sem::ClassScope::getVariable(const std::string& name)
 {
-    if (class_ref == nullptr)
+    if (classRef == nullptr)
         return parentScope.getVariable(name);
-    auto m = class_ref->fields.find(name);
-    if (m != class_ref->fields.end())
+    auto m = classRef->fields.find(name);
+    if (m != classRef->fields.end())
         return (*m).second.get();
     
     return parentScope.getVariable(name);
 }
 
 
-sem::Method * sem::ClassScope::getMethod(const std::string& name)
+sem::Method* sem::ClassScope::getMethod(const std::string& name)
 {
-    if (class_ref == nullptr)
+    if (classRef == nullptr)
         return parentScope.getMethod(name);
-    auto m = class_ref->methods.find(name);
-    if (m != class_ref->methods.end())
+    auto m = classRef->methods.find(name);
+    if (m != classRef->methods.end())
         return (*m).second.get();
     
     return parentScope.getMethod(name);
@@ -130,11 +130,11 @@ sem::Method * sem::ClassScope::getMethod(const std::string& name)
 std::string sem::ClassScope::toString(void)
 {
     std::string ret;
-    for (auto& [name, m] : class_ref->methods) {
+    for (auto& [name, m] : classRef->methods) {
         ret += "\t";
         ret += m->toString() + "\n";
     }
-    for (auto& [name, f] : class_ref->fields) {
+    for (auto& [name, f] : classRef->fields) {
         ret += "\t";
         ret += f->toString() + "\n";
     }
@@ -207,3 +207,47 @@ std::string sem::LocalScope::toString(void)
 }
 
 
+sem::Variable* sem::TypeScope::getVariable(const std::string& name)
+{
+    if (ClassType* ct = dynamic_cast<ClassType*>(type.get()); ct) {
+        auto& fields = ct->getClassType()->fields;
+        if (fields.find(name) != fields.end())
+            return fields[name].get();
+    }
+    return nullptr;
+    return nullptr;
+}
+
+
+sem::Method* sem::TypeScope::getMethod(const std::string& name)
+{
+    if (ClassType* ct = dynamic_cast<ClassType*>(type.get()); ct) {
+        auto& methods = ct->getClassType()->methods;
+        if (methods.find(name) != methods.end())
+            return methods[name].get();
+    }
+    return nullptr;
+}
+
+
+std::shared_ptr<sem::Type> sem::TypeScope::getType(const ast::Type& name)
+{
+    return nullptr;
+}
+
+
+std::shared_ptr<sem::Type> sem::TypeScope::getReturnableType(void)
+{
+    return nullptr;
+}
+
+
+std::string sem::TypeScope::toString(void)
+{
+    std::string ret;
+    return ret;
+}
+
+
+
+

+ 40 - 3
src/Scope.h

@@ -5,6 +5,9 @@
 #include <map>
 #include <memory>
 
+#include <llvm/IR/Type.h>
+#include <llvm/IR/Value.h>
+
 namespace qlow
 {
     namespace ast
@@ -30,6 +33,8 @@ namespace qlow
         class NativeScope;
         class ClassScope;
         class LocalScope;
+        class TypeScope;
+        class NativeTypeScope;
         
         class Type;
         class NativeType;
@@ -83,10 +88,10 @@ public:
 class qlow::sem::ClassScope : public Scope
 {
     Scope& parentScope;
-    Class* class_ref;
+    Class* classRef;
 public:
-    inline ClassScope(Scope& parentScope, Class* class_ref) :
-        parentScope{ parentScope }, class_ref{ class_ref }
+    inline ClassScope(Scope& parentScope, Class* classRef) :
+        parentScope{ parentScope }, classRef{ classRef }
     {
     }
     virtual Variable* getVariable(const std::string& name);
@@ -132,4 +137,36 @@ public:
 };
 
 
+class qlow::sem::TypeScope : public Scope
+{
+protected:
+    std::shared_ptr<Type> type;
+public:
+    inline TypeScope(std::shared_ptr<Type> type) :
+        type{ std::move(type) }
+    {
+    }
+    
+    
+    virtual Variable* getVariable(const std::string& name);
+    virtual Method* getMethod(const std::string& name);
+    virtual std::shared_ptr<Type> getType(const ast::Type& name);
+    virtual std::shared_ptr<Type> getReturnableType(void);
+    virtual std::string toString(void);
+};
+
+
+class qlow::sem::NativeTypeScope : public TypeScope
+{
+public:
+    inline NativeTypeScope(std::shared_ptr<Type> type) :
+        TypeScope{ std::move(type) }
+    {
+    }
+    
+    
+    std::shared_ptr<Type> implementInlineOperation(const std::string&, llvm::Value* a); 
+};
+
+
 #endif // QLOW_SEM_SCOPE_H

+ 3 - 1
src/Type.cpp

@@ -28,7 +28,7 @@ sem::Type* sem::Type::BOOLEAN = new sem::NativeType(sem::NativeType::Type::BOOLE
 
 sem::Scope& sem::ClassType::getScope(void)
 {
-    return classType->scope;
+    return scope;
 }
 
 
@@ -51,6 +51,7 @@ bool sem::ClassType::equals(const Type& other) const
 
 sem::Scope& sem::ArrayType::getScope(void)
 {
+    return scope;
 }
 
 
@@ -74,6 +75,7 @@ bool sem::ArrayType::equals(const Type& other) const
 
 sem::Scope& sem::NativeType::getScope(void)
 {
+    return scope;
 }
 
 

+ 12 - 4
src/Type.h

@@ -2,6 +2,7 @@
 #define QLOW_SEM_TYPE_H
 
 #include <memory>
+#include "Scope.h"
 
 namespace llvm {
     class Value;
@@ -45,7 +46,8 @@ struct qlow::sem::SemanticObject
 
 
 
-class qlow::sem::Type : public SemanticObject
+class qlow::sem::Type : public SemanticObject,
+                        protected std::enable_shared_from_this<Type>
 {
 public:
     virtual ~Type(void);
@@ -69,9 +71,11 @@ public:
 class qlow::sem::ClassType : public Type
 {
     sem::Class* classType;
+    sem::TypeScope scope;
 public:
     inline ClassType(sem::Class* classType) :
-        classType{ classType }
+        classType{ classType },
+        scope{ shared_from_this() }
     {
     }
     
@@ -90,10 +94,12 @@ public:
 class qlow::sem::ArrayType : public Type
 {
     std::shared_ptr<sem::Type> arrayType;
+    TypeScope scope;
 public:
     
     inline ArrayType(std::shared_ptr<sem::Type> arrayType) :
-        arrayType{ std::move(arrayType) }
+        arrayType{ std::move(arrayType) },
+        scope{ shared_from_this() }
     {
     }
     
@@ -111,6 +117,7 @@ public:
 
 class qlow::sem::NativeType : public Type
 {
+    NativeTypeScope scope;
 public:
     enum Type {
         VOID,
@@ -126,7 +133,8 @@ public:
     Type type;
     
     inline NativeType(Type type) :
-        type{ type }
+        type{ type },
+        scope{ shared_from_this() }
     {
     }