Browse Source

more driver refactoring

Nicolas Winkler 6 years ago
parent
commit
0a60866194
2 changed files with 27 additions and 17 deletions
  1. 25 17
      src/Driver.cpp
  2. 2 0
      src/Driver.h

+ 25 - 17
src/Driver.cpp

@@ -81,23 +81,7 @@ int Driver::run(void)
         return 1;
     }
     
-    std::unique_ptr<qlow::sem::GlobalScope> semClasses = nullptr;
-    try {
-        semClasses =
-            qlow::sem::createFromAst(this->ast);
-    }
-    catch(SemanticError& se) {
-        se.print(logger);
-        errorOccurred = true;
-    }
-    catch(const char* err) {
-        reportError(err);
-        errorOccurred = true;
-    }
-    catch (...) {
-        reportError("an unknown error occurred.");
-        errorOccurred = true;
-    }
+    errorOccurred = semanticStage();
     
     if (errorOccurred) {
         logger << "Aborting due to semantic errors." << std::endl;
@@ -205,6 +189,30 @@ bool Driver::parseStage(void)
 }
 
 
+bool Driver::semanticStage(void)
+{
+    bool errorOccurred = false;
+
+    try {
+        this->semClasses = qlow::sem::createFromAst(this->ast);
+    }
+    catch(SemanticError& se) {
+        se.print(logger);
+        errorOccurred = true;
+    }
+    catch(const char* err) {
+        reportError(err);
+        errorOccurred = true;
+    }
+    catch (...) {
+        reportError("an unknown error occurred.");
+        errorOccurred = true;
+    }
+
+    return errorOccurred;
+}
+
+
 qlow::ast::Ast Driver::parseFile(FILE* file,
         const std::string& filename)
 {

+ 2 - 0
src/Driver.h

@@ -39,6 +39,7 @@ class qlow::Driver
 {
     Options options;
     std::unique_ptr<qlow::ast::Ast> ast = nullptr;
+    std::unique_ptr<qlow::sem::GlobalScope> semClasses = nullptr;
 public:
     Driver(void) = delete;
     Driver(int argc, char** argv);
@@ -46,6 +47,7 @@ public:
     int run(void);
 
     bool parseStage(void);
+    bool semanticStage(void);
     
     qlow::ast::Ast parseFile(FILE* file, const std::string& filename);
 };