Переглянути джерело

fixing llvm compat errors

Nicolas Winkler 4 роки тому
батько
коміт
5f3b47ca22

+ 1 - 1
src/Driver.cpp

@@ -125,7 +125,7 @@ int Driver::run(void) try
     }*/
     
     auto* mainMethod = semClasses->getMethod("main");
-    if (mainMethod == nullptr && false) {
+    if (mainMethod == nullptr) {
         // TODO handle main ckeck well
         qlow::printError(printer, "no main method found");
         return 1;

+ 1 - 0
src/ErrorReporting.cpp

@@ -219,6 +219,7 @@ std::string SemanticError::getMessage(void) const noexcept
         {OPERATOR_NOT_FOUND, ""},
         {WRONG_NUMBER_OF_ARGUMENTS, "wrong number of arguments passed"},
         {INVALID_RETURN_TYPE, "invalid return type"},
+        {NO_MAIN_METHOD, "no main method specified"},
     };
     if (errors.find(errorCode) != errors.end())
         return errors.at(errorCode);

+ 2 - 0
src/ErrorReporting.h

@@ -134,6 +134,8 @@ public:
         TYPE_MISMATCH,
         INVALID_RETURN_TYPE,
         NEW_FOR_NON_CLASS,
+
+        NO_MAIN_METHOD,
     };
     
     

+ 1 - 1
src/ast/AstVisitor.cpp

@@ -300,7 +300,7 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::AssignmentStat
         throw SemanticError(
             SemanticError::TYPE_MISMATCH,
             "Can't assign expression of type '" + as->value->type->asString() +
-            "' to value of type '" + as->target->type->asString() + "'.",
+            "' to variable of type '" + as->target->type->asString() + "'.",
             ast.pos
         );
     }

+ 4 - 1
src/sem/CodeGeneration.cpp

@@ -121,7 +121,10 @@ std::unique_ptr<llvm::Module> generateModule(sem::GlobalScope& semantic)
         printf("verified function: %s\n", method->name.c_str());
 #endif
     }
-    generateStartFunction(module.get(), semantic.getMethod("main")->llvmNode);
+    auto mainMethod = semantic.getMethod("main");
+    if (mainMethod != nullptr) {
+        generateStartFunction(module.get(), mainMethod->llvmNode);
+    }
     return module;
 }
 

+ 4 - 0
src/util/Path.cpp

@@ -31,6 +31,10 @@ Path Path::parentPath(void) const
         return parent;
     }
 
+    if (parent.path.find(defaultDirSeparator) == std::string::npos) {
+        return "";
+    }
+
     while (!parent.endsWithSeparator()) {
         parent.path.pop_back();
     }