Procházet zdrojové kódy

finally with not too many bugs

Nicolas Winkler před 6 roky
rodič
revize
dc6b07be8b
13 změnil soubory, kde provedl 199 přidání a 78 odebrání
  1. 20 9
      src/AstVisitor.cpp
  2. 4 3
      src/Builtin.cpp
  3. 3 2
      src/Builtin.h
  4. 17 3
      src/CodeGeneration.cpp
  5. 14 5
      src/CodegenVisitor.cpp
  6. 2 0
      src/CodegenVisitor.h
  7. 55 3
      src/Scope.cpp
  8. 32 5
      src/Scope.h
  9. 15 9
      src/Semantic.cpp
  10. 28 28
      src/Semantic.h
  11. 3 1
      src/TypeVisitor.cpp
  12. 6 5
      src/main.cpp
  13. 0 5
      src/test.qlw

+ 20 - 9
src/AstVisitor.cpp

@@ -19,9 +19,10 @@ sem::Class* StructureVisitor::getType(const std::string& type, sem::Scope& scope
 
 std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::Class& ast, sem::Scope& scope)
 {
-    auto c = std::make_unique<sem::Class>();
-    c->name = ast.name;
-    return c;
+    //auto c = std::make_unique<sem::Class>();
+    //c->name = ast.name;
+    //return c;
+    throw "shouldn't be called";
 }
 
 
@@ -52,7 +53,7 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::FieldDeclarati
 
 std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::MethodDefinition& ast, sem::Scope& scope)
 {
-    auto m = std::make_unique<sem::Method>();
+    auto m = std::make_unique<sem::Method>(scope);
     m->name = ast.name;
     auto returnType = scope.getType(ast.type);
     if (returnType) {
@@ -66,6 +67,7 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::MethodDefiniti
     }
     m->astNode = &ast;
     return m;
+    //throw "  std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::MethodDefinition& ast, sem::Scope& scope) shouldn't be called";
 }
 
 
@@ -95,21 +97,21 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::ArgumentDeclar
 
 std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::DoEndBlock& ast, sem::Scope& scope)
 {
-    auto body = std::make_unique<sem::DoEndBlock>();
+    auto body = std::make_unique<sem::DoEndBlock>(scope);
     for (auto& statement : ast.statements) {
         
         if (ast::NewVariableStatement* nvs = dynamic_cast<ast::NewVariableStatement*>(statement.get()); nvs) {
-            auto type = scope.getType(nvs->type);
+            auto type = body->scope.getType(nvs->type);
 
             if (!type)
                 throw sem::SemanticException(sem::SemanticException::UNKNOWN_TYPE, nvs->type, nvs->pos);
 
             auto var = std::make_unique<sem::Variable>(type.value().typeClass, nvs->name);
-            body->variables.push_back(std::move(var));
+            body->scope.putVariable(nvs->name, std::move(var));
             continue;
         }
         
-        auto v = statement->accept(*this, scope);
+        auto v = statement->accept(*this, body->scope);
         if (dynamic_cast<sem::FeatureCallExpression*>(v.get()) != nullptr) {
             body->statements.push_back(std::make_unique<sem::FeatureCallStatement>(unique_dynamic_cast<sem::FeatureCallExpression>(std::move(v))));
         }
@@ -141,11 +143,20 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::FeatureCall& a
     auto* var = scope.getVariable(ast.name);
     
     if (var) {
+        auto lve = std::make_unique<sem::LocalVariableExpression>();
+        lve->var = var;
+        return lve;
     }
     else if (method) {
-ce;
+        auto fce = std::make_unique<sem::FeatureCallExpression>();
+        fce->callee = method;
+        return fce;
     }
     else {
+#ifdef DEBUGGING
+        printf("var not found: %s\n", ast.name.c_str());
+        printf("current scope: %s\n", scope.toString().c_str());
+#endif
         throw sem::SemanticException(sem::SemanticException::FEATURE_NOT_FOUND, ast.name, ast.pos);
     }
 }

+ 4 - 3
src/Builtin.cpp

@@ -1,15 +1,16 @@
 #include "Builtin.h"
 
 using namespace qlow;
-
+/*
 sem::Class initInt32(void)
 {
-    sem::Class c;
-    c.astNode = nullptr;
+    //sem::Class c(void);
+    //c.astNode = nullptr;
 }
 
 
 sem::Class sem::Int32 = initInt32();
 
 
+*/
 

+ 3 - 2
src/Builtin.h

@@ -9,8 +9,9 @@ namespace qlow
 {
     namespace sem
     {
-        extern Class Int32;
-        extern Class String;
+
+        //extern Class Int32;
+        //extern Class String;
     }
 }
 

+ 17 - 3
src/CodeGeneration.cpp

@@ -35,7 +35,15 @@ std::unique_ptr<llvm::Module> generateModule(const sem::SymbolTable<sem::Class>&
 
     std::unique_ptr<Module> module = llvm::make_unique<Module>("qlow_module", context);
     
-    std::vector<Type*> doubles(1, Type::getDoubleTy(context));
+    for (auto& [name, cl] : classes){
+        for (auto& [name, method] : cl->methods) {
+            std::vector<Type*> doubles(1, Type::getDoubleTy(context));
+            FunctionType* funcType = FunctionType::get(Type::getDoubleTy(context), doubles, false);
+            Function* func = Function::Create(funcType, Function::ExternalLinkage, method->name, module.get());
+            method->llvmNode = func;
+        }
+    }
+
     for (auto& [name, cl] : classes){
         for (auto& [name, method] : cl->methods) {
 
@@ -174,7 +182,13 @@ llvm::Function* qlow::gen::FunctionGenerator::generate(void)
 
     std::vector<Type*> doubles(1, Type::getDoubleTy(context));
     FunctionType* funcType = FunctionType::get(Type::getDoubleTy(context), doubles, false);
-    Function* func = Function::Create(funcType, Function::ExternalLinkage, method.name, module);
+    //Function* func = Function::Create(funcType, Function::ExternalLinkage, method.name, module);
+    Function* func = module->getFunction(method.name);
+
+    if (func == nullptr) {
+        throw "internal error: function not found";
+    }
+
     BasicBlock* bb = BasicBlock::Create(context, "entry", func);
     
     /*Function::arg_iterator args = func->arg_begin();
@@ -191,7 +205,7 @@ llvm::Function* qlow::gen::FunctionGenerator::generate(void)
 
     IRBuilder<> builder(context);
     builder.SetInsertPoint(bb);
-    for (auto& var : method.body->variables) {
+    for (auto& [name, var] : method.body->scope.getLocals()) {
         llvm::AllocaInst* v = builder.CreateAlloca(Type::getDoubleTy(context));
         var->allocaInst = v;
     }

+ 14 - 5
src/CodegenVisitor.cpp

@@ -7,6 +7,14 @@
 
 using namespace qlow;
 
+llvm::Value* ExpressionVisitor::visit(sem::LocalVariableExpression& lve, llvm::IRBuilder<>& builder)
+{
+    llvm::Value* val = builder.CreateLoad(lve.var->allocaInst);
+    return val;
+}
+
+
+
 llvm::Value* ExpressionVisitor::visit(sem::BinaryOperation& binop, llvm::IRBuilder<>& builder)
 {
     using llvm::Value;
@@ -40,9 +48,9 @@ llvm::Value* ExpressionVisitor::visit(sem::UnaryOperation& unop, llvm::IRBuilder
             return builder.CreateNeg(value, "negate");
 
         case ast::Operation::Operator::PLUS:
-        [[fallthrough]]
+        [[fallthrough]];
         case ast::Operation::Operator::ASTERISK:
-        [[fallthrough]]
+        [[fallthrough]];
         case ast::Operation::Operator::SLASH:
             throw "operator not supported";
     }
@@ -71,7 +79,7 @@ llvm::Value* StatementVisitor::visit(sem::AssignmentStatement& assignment,
     llvm::IRBuilder<> builder(fg.getContext());
     builder.SetInsertPoint(fg.getCurrentBlock());
     llvm::Value* val = assignment.value->accept(fg.expressionVisitor, builder);
-    builder.CreateRet(val);
+    //builder.CreateRet(val);
     return llvm::ConstantFP::get(fg.getContext(), llvm::APFloat(5.0));
 }
 
@@ -81,8 +89,9 @@ llvm::Value* StatementVisitor::visit(sem::FeatureCallStatement& fc, gen::Functio
     llvm::Module* module = fg.getModule();
     llvm::IRBuilder<> builder(fg.getContext());
     builder.SetInsertPoint(fg.getCurrentBlock());
-    llvm::Constant* c = module->getOrInsertFunction(fc.expr->callee->name, {});
-    builder.CreateCall(c, {});
+    //llvm::Constant* c = module->getOrInsertFunction(fc.expr->callee->name, {});
+    llvm::Function* f = fc.expr->callee->llvmNode;
+    builder.CreateCall(f, {});
     return llvm::ConstantFP::get(fg.getContext(), llvm::APFloat(5.0));
 }
 

+ 2 - 0
src/CodegenVisitor.h

@@ -34,6 +34,7 @@ class qlow::ExpressionVisitor :
         llvm::Value*,
         llvm::IRBuilder<>,
 
+        sem::LocalVariableExpression,
         sem::BinaryOperation,
         sem::UnaryOperation,
         sem::FeatureCallExpression,
@@ -41,6 +42,7 @@ class qlow::ExpressionVisitor :
     >
 {
 public:
+    llvm::Value* visit(sem::LocalVariableExpression& node, llvm::IRBuilder<>&) override;
     llvm::Value* visit(sem::BinaryOperation& node, llvm::IRBuilder<>&) override;
     llvm::Value* visit(sem::UnaryOperation& node, llvm::IRBuilder<>&) override;
     llvm::Value* visit(sem::FeatureCallExpression& node, llvm::IRBuilder<>&) override;

+ 55 - 3
src/Scope.cpp

@@ -1,4 +1,5 @@
 #include "Scope.h"
+#include "Semantic.h"
 
 using namespace qlow;
 
@@ -28,6 +29,18 @@ std::optional<sem::Type> sem::GlobalScope::getType(const std::string& name)
 }
 
 
+std::string sem::GlobalScope::toString(void)
+{
+    std::string ret;
+    ret += "Classes:\n";
+    for (auto& [name, c] : classes) {
+        ret += "\t";
+        ret += c->toString() + "\n";
+    }
+    return ret;
+}
+
+
 sem::Variable* sem::ClassScope::getVariable(const std::string& name)
 {
     if (class_ref == nullptr)
@@ -52,13 +65,41 @@ 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) {
+        ret += "\t";
+        ret += m->toString() + "\n";
+    }
+    for (auto& [name, f] : class_ref->fields) {
+        ret += "\t";
+        ret += f->toString() + "\n";
+    }
+
+    return ret + "\nParent:\n" + parentScope.toString();
+}
+
+
 std::optional<sem::Type> sem::ClassScope::getType(const std::string& name)
 {
     return parentScope.getType(name);
 }
 
 
-sem::Variable* sem::MethodScope::getVariable(const std::string& name)
+void sem::LocalScope::putVariable(const std::string& name, std::unique_ptr<Variable> v)
+{
+    localVariables.insert({name, std::move(v)});
+}
+
+
+sem::SymbolTable<sem::Variable>& sem::LocalScope::getLocals(void)
+{
+    return localVariables;
+}
+
+
+sem::Variable* sem::LocalScope::getVariable(const std::string& name)
 {
     auto m = localVariables.find(name);
     if (m != localVariables.end())
@@ -68,16 +109,27 @@ sem::Variable* sem::MethodScope::getVariable(const std::string& name)
 }
 
 
-sem::Method * sem::MethodScope::getMethod(const std::string& name)
+sem::Method * sem::LocalScope::getMethod(const std::string& name)
 {
     return parentScope.getMethod(name);
 }
 
 
-std::optional<sem::Type> sem::MethodScope::getType(const std::string& name)
+std::optional<sem::Type> sem::LocalScope::getType(const std::string& name)
 {
     return parentScope.getType(name);
 }
 
 
+std::string sem::LocalScope::toString(void)
+{
+    std::string ret;
+    for (auto& [name, v] : localVariables) {
+        ret += "\t";
+        ret += v->toString() + "\n";
+    }
+
+    return ret + "\nParent:\n" + parentScope.toString();
+}
+
 

+ 32 - 5
src/Scope.h

@@ -2,21 +2,39 @@
 #define QLOW_SEM_SCOPE_H
 
 #include <optional>
-
-#include "Semantic.h"
+#include <map>
+#include <memory>
 
 namespace qlow
 {
     namespace sem
     {
+        /*!
+         * \note contains owning pointers to elements
+         */
+        template<typename T>
+        using SymbolTable = std::map<std::string, std::unique_ptr<T>>;
+
+
+        struct Class;
+        struct Method;
+        struct Variable;
+        struct Type;
+
         class Scope;
         class GlobalScope;
         class ClassScope;
-        class MethodScope;
+        class LocalScope;
     }
 }
 
 
+struct qlow::sem::Type
+{
+    Class* typeClass;
+};
+
+
 class qlow::sem::Scope
 {
 public:
@@ -24,6 +42,8 @@ public:
     virtual Variable* getVariable(const std::string& name) = 0;
     virtual Method* getMethod(const std::string& name) = 0;
     virtual std::optional<Type> getType(const std::string& name) = 0;
+
+    virtual std::string toString(void) = 0;
 };
 
 
@@ -35,6 +55,8 @@ public:
     virtual Variable* getVariable(const std::string& name);
     virtual Method* getMethod(const std::string& name);
     virtual std::optional<Type> getType(const std::string& name);
+
+    virtual std::string toString(void);
 };
 
 
@@ -50,21 +72,26 @@ public:
     virtual Variable* getVariable(const std::string& name);
     virtual Method* getMethod(const std::string& name);
     virtual std::optional<Type> getType(const std::string& name);
+    virtual std::string toString(void);
 };
 
 
-class qlow::sem::MethodScope : public Scope
+class qlow::sem::LocalScope : public Scope
 {
     Scope& parentScope;
     SymbolTable<Variable> localVariables;
 public:
-    inline MethodScope(Scope& parentScope) :
+    inline LocalScope(Scope& parentScope) :
         parentScope{ parentScope }
     {
     }
+    void putVariable(const std::string& name, std::unique_ptr<Variable> v);
+    SymbolTable<Variable>& getLocals(void);
+
     virtual Variable* getVariable(const std::string& name);
     virtual Method* getMethod(const std::string& name);
     virtual std::optional<Type> getType(const std::string& name);
+    virtual std::string toString(void);
 };
 
 

+ 15 - 9
src/Semantic.cpp

@@ -12,7 +12,7 @@ namespace qlow
 namespace sem
 {
 
-SymbolTable<qlow::sem::Class>
+std::unique_ptr<GlobalScope>
     createFromAst(const std::vector<std::unique_ptr<qlow::ast::Class>>& classes)
 {
 
@@ -21,9 +21,9 @@ SymbolTable<qlow::sem::Class>
 #endif
 
     // create classes
-    sem::GlobalScope globalScope;
+    std::unique_ptr<sem::GlobalScope> globalScope = std::make_unique<sem::GlobalScope>();
     for (auto& astClass : classes) {
-        globalScope.classes[astClass->name] = std::make_unique<sem::Class>(astClass.get());
+        globalScope->classes[astClass->name] = std::make_unique<sem::Class>(astClass.get(), *globalScope);
     }
 
 #ifdef DEBUGGING
@@ -33,7 +33,7 @@ SymbolTable<qlow::sem::Class>
     StructureVisitor av;
     
     // create all methods and fields
-    for (auto& [name, semClass] : globalScope.classes) {
+    for (auto& [name, semClass] : globalScope->classes) {
         for (auto& feature : semClass->astNode->features) {
             
             if (auto* field = dynamic_cast<qlow::ast::FieldDeclaration*> (feature.get()); field) {
@@ -41,14 +41,14 @@ SymbolTable<qlow::sem::Class>
                     throw SemanticException(SemanticException::DUPLICATE_FIELD_DECLARATION, field->name, field->pos);
                 
                 // otherwise add to the fields list
-                semClass->fields[field->name] = unique_dynamic_cast<Field>(field->accept(av, globalScope));
+                semClass->fields[field->name] = unique_dynamic_cast<Field>(field->accept(av, semClass->scope));
             }
             else if (auto* method = dynamic_cast<qlow::ast::MethodDefinition*> (feature.get()); method) {
                 if (semClass->methods.find(method->name) != semClass->methods.end()) // throw, if method already exists
                     throw SemanticException(SemanticException::DUPLICATE_METHOD_DEFINITION, method->name, method->pos);
                 
                 // otherwise add to the methods list
-                semClass->methods[method->name] = unique_dynamic_cast<Method>(method->accept(av, globalScope));
+                semClass->methods[method->name] = unique_dynamic_cast<Method>(method->accept(av, semClass->scope));
             }
             else {
                 // if a feature is neither a method nor a field, something went horribly wrong
@@ -61,16 +61,16 @@ SymbolTable<qlow::sem::Class>
     printf("created all methods and fields\n");
 #endif
     
-    for (auto& [name, semClass] : globalScope.classes) {
+    for (auto& [name, semClass] : globalScope->classes) {
         for (auto& [name, method] : semClass->methods) {
-            method->body = unique_dynamic_cast<sem::DoEndBlock>(av.visit(*method->astNode->body, globalScope));
+            method->body = unique_dynamic_cast<sem::DoEndBlock>(av.visit(*method->astNode->body, method->scope));
         }
     }
 #ifdef DEBUGGING
     printf("created all method bodies\n");
 #endif
     
-    return std::move(globalScope.classes);
+    return globalScope;
 }
 
 }
@@ -138,6 +138,7 @@ llvm::Value* ClassName::accept(Visitor& v, Arg arg) \
     return v.visit(*this, arg); \
 }
 
+ACCEPT_DEFINITION(LocalVariableExpression, ExpressionVisitor, llvm::IRBuilder<>&)
 ACCEPT_DEFINITION(BinaryOperation, ExpressionVisitor, llvm::IRBuilder<>&)
 ACCEPT_DEFINITION(UnaryOperation, ExpressionVisitor, llvm::IRBuilder<>&)
 ACCEPT_DEFINITION(FeatureCallExpression, ExpressionVisitor, llvm::IRBuilder<>&)
@@ -153,6 +154,11 @@ std::string AssignmentStatement::toString(void) const
 }
 
 
+std::string LocalVariableExpression::toString(void) const
+{
+    return "LocalVariableExpression[" + var->name + "]";
+}
+
 std::string BinaryOperation::toString(void) const
 {
     return "BinaryOperation[" + left->toString() + ", " +

+ 28 - 28
src/Semantic.h

@@ -6,6 +6,7 @@
 #include "Util.h"
 #include "Ast.h"
 #include "Visitor.h"
+#include "Scope.h"
 
 #include <llvm/IR/Value.h>
 #include <llvm/IR/IRBuilder.h>
@@ -15,14 +16,8 @@ namespace qlow
 {
     namespace sem
     {
-        /*!
-         * \note contains owning pointers to elements
-         */
-        template<typename T>
-        using SymbolTable = std::map<std::string, std::unique_ptr<T>>;
-
-        
-        SymbolTable<qlow::sem::Class> createFromAst(const std::vector<std::unique_ptr<qlow::ast::Class>>& classes);
+        std::unique_ptr<GlobalScope>
+            createFromAst(const std::vector<std::unique_ptr<qlow::ast::Class>>& classes);
 
         struct SemanticObject;
         struct Class;
@@ -48,8 +43,6 @@ namespace qlow
         struct FeatureCallExpression;
         
         struct IntConst;
-        
-        struct Type;
 
         class SemanticException;
     }
@@ -63,12 +56,6 @@ namespace qlow
 }
 
 
-struct qlow::sem::Type
-{
-    Class* typeClass;
-};
-
-
 struct qlow::sem::SemanticObject
 {
     virtual ~SemanticObject(void);
@@ -86,10 +73,10 @@ struct qlow::sem::Class : public SemanticObject
     std::string name;
     SymbolTable<Field> fields;
     SymbolTable<Method> methods;
-    
-    Class(void) = default;
-    inline Class(qlow::ast::Class* astNode) :
-        astNode{ astNode }, name{ astNode->name }
+    ClassScope scope;
+
+    inline Class(qlow::ast::Class* astNode, GlobalScope& globalScope) :
+        astNode{ astNode }, name{ astNode->name }, scope{ globalScope, this }
     {
     }
     
@@ -130,6 +117,13 @@ struct qlow::sem::Method : public SemanticObject
     std::string name;
     ast::MethodDefinition* astNode;
     std::unique_ptr<DoEndBlock> body;
+
+    LocalScope scope;
+
+    llvm::Function* llvmNode;
+
+    inline Method(Scope& parentScope) :
+        scope{ parentScope } {}
     
     virtual std::string toString(void) const override;
 };
@@ -137,8 +131,11 @@ struct qlow::sem::Method : public SemanticObject
 
 struct qlow::sem::DoEndBlock : public SemanticObject
 {
-    OwningList<Variable> variables;
+    LocalScope scope;
     OwningList<Statement> statements;
+
+    inline DoEndBlock(Scope& parentScope) :
+        scope{ parentScope } {}
 };
 
 
@@ -154,7 +151,7 @@ struct qlow::sem::AssignmentStatement : public Statement
     std::unique_ptr<Expression> value;
 
     virtual std::string toString(void) const override;
-    virtual llvm::Value* accept(qlow::StatementVisitor&, gen::FunctionGenerator&);
+    virtual llvm::Value* accept(qlow::StatementVisitor&, gen::FunctionGenerator&) override;
 };
 
 
@@ -171,7 +168,10 @@ struct qlow::sem::Operation : public Expression
 
 struct qlow::sem::LocalVariableExpression : public Expression
 {
-    
+    Variable* var;
+
+    virtual llvm::Value* accept(ExpressionVisitor& visitor, llvm::IRBuilder<>& arg2) override;
+    virtual std::string toString(void) const override;
 };
 
 
@@ -180,7 +180,7 @@ struct qlow::sem::BinaryOperation : public Operation
     std::unique_ptr<Expression> left;
     std::unique_ptr<Expression> right;
     
-    virtual llvm::Value* accept(ExpressionVisitor& visitor, llvm::IRBuilder<>& arg2);
+    virtual llvm::Value* accept(ExpressionVisitor& visitor, llvm::IRBuilder<>& arg2) override;
     
     virtual std::string toString(void) const override;
 };
@@ -190,7 +190,7 @@ struct qlow::sem::UnaryOperation : public Operation
 {
     qlow::ast::UnaryOperation::Side side;
     std::unique_ptr<Expression> arg;
-    virtual llvm::Value* accept(ExpressionVisitor& visitor, llvm::IRBuilder<>& arg2);
+    virtual llvm::Value* accept(ExpressionVisitor& visitor, llvm::IRBuilder<>& arg2) override;
     virtual std::string toString(void) const override;
 };
 
@@ -199,7 +199,7 @@ struct qlow::sem::FeatureCallExpression : public Expression
 {
     Method* callee;
     OwningList<Expression> arguments;
-    virtual llvm::Value* accept(ExpressionVisitor& visitor, llvm::IRBuilder<>& arg2);
+    virtual llvm::Value* accept(ExpressionVisitor& visitor, llvm::IRBuilder<>& arg2) override;
     
     virtual std::string toString(void) const override;
 };
@@ -214,7 +214,7 @@ struct qlow::sem::IntConst : public Expression
     {
     }
     
-    virtual llvm::Value* accept(ExpressionVisitor& visitor, llvm::IRBuilder<>& arg2);
+    virtual llvm::Value* accept(ExpressionVisitor& visitor, llvm::IRBuilder<>& arg2) override;
 };
 
 
@@ -225,7 +225,7 @@ struct qlow::sem::FeatureCallStatement : public Statement
         expr{ std::move(expr) } {}
 
     virtual std::string toString(void) const override;
-    virtual llvm::Value* accept(qlow::StatementVisitor&, gen::FunctionGenerator&);
+    virtual llvm::Value* accept(qlow::StatementVisitor&, gen::FunctionGenerator&) override;
 };
 
 

+ 3 - 1
src/TypeVisitor.cpp

@@ -29,7 +29,9 @@ sem::Type sem::TypeVisitor::visit(sem::FeatureCallExpression& expr, const sem::S
 
 sem::Type sem::TypeVisitor::visit(sem::IntConst& expr, const sem::SymbolTable<sem::Class>& classes)
 {
-    return Type{ new sem::Class() };
+    //return Type{ new sem::Class() };
+    //TODO implement
+    return Type { nullptr };
 }
 
 

+ 6 - 5
src/main.cpp

@@ -39,15 +39,16 @@ int main(int argc, char** argv)
 
         std::cout << "parsing completed!" << std::endl;
 
-        qlow::sem::SymbolTable<qlow::sem::Class> semClasses = qlow::sem::createFromAst(*parsedClasses.get());
+        std::unique_ptr<qlow::sem::GlobalScope> semClasses =
+            qlow::sem::createFromAst(*parsedClasses.get());
 
-        for (auto& [a, b] : semClasses) {
+        for (auto& [a, b] : semClasses->classes) {
             std::cout << a << ": " << b->toString() << std::endl;
         }
 
-        auto main = semClasses.find("Main");
+        auto main = semClasses->classes.find("Main");
         qlow::sem::Class* mainClass = nullptr;
-        if (main == semClasses.end()) {
+        if (main == semClasses->classes.end()) {
             throw "No Main class found!";
         }
         else {
@@ -62,7 +63,7 @@ int main(int argc, char** argv)
             mainMethod = mainmain->second.get();
         }
 
-        auto mod = qlow::gen::generateModule(semClasses);
+        auto mod = qlow::gen::generateModule(semClasses->classes);
         qlow::gen::generateObjectFile("obj.o", std::move(mod));
     }
     catch (qlow::sem::SemanticException& se)

+ 0 - 5
src/test.qlw

@@ -3,11 +3,6 @@
 class Main
     foo: Main
 
-    wow: Integer do
-        var: Integer;
-        var := 5;
-    end
-
     fop: FF do
         var: Integer;
         var := 5;