Nicolas Winkler 7 years ago
parent
commit
1806b74b99
4 changed files with 93 additions and 6 deletions
  1. 29 5
      src/Logging.cpp
  2. 22 0
      src/Logging.h
  3. 34 0
      src/Semantic.h
  4. 8 1
      src/makefile

+ 29 - 5
src/Logging.cpp

@@ -22,29 +22,53 @@ int Out::overflow(int c)
         for (int i = 0; i < indentVal; i++)
             target.put(' ');
 
-    target.put(char(c));
-
-    firstChar = c == '\n';
+    if (logType <= logLevel)
+        target.put(char(c));
+
+    if (c == '\n') {
+        // remove formatting
+        target << "\033[0m";
+        logType = LogLevel::NONE;
+        firstChar = true;
+    }
+    else
+        firstChar = false;
 
     return 0;
 }
 
 
+std::ostream& operator << (std::ostream& o, qlow::LogLevel l)
+{
+    switch(l)
+    {
+        case qlow::LogLevel::WARNING:
+            try {
+                dynamic_cast<qlow::Out&>(o).setLogType(l);
+            }
+            catch(...) {}
+            return o << "\033[33m";
+    }
+    return o;
+}
+
+
 /*std::streamsize Out::xsputn(const char* s, std::streamsize n)
 {
     target.write(s, n);
 }*/
 
 
-int main()
+/*int main()
 {
     qlow::Out& l = Out::stdout;
     l << "aha" << std::endl;
     l.indent(10);
     l << "aha" << std::endl;
+    l << qlow::LogLevel::WARNING << "ee";
     l.unindent(10);
     l << "aha" << std::endl;
-}
+}*/
 
 
 

+ 22 - 0
src/Logging.h

@@ -6,7 +6,20 @@
 
 namespace qlow
 {
+    // indenting ostream
     class Out;
+
+
+    enum class LogLevel
+    {
+        NONE,
+        ERROR,
+        WARNING,
+        INFO,
+        DEBUG,
+        TRACE,
+        OFF,
+    };
 }
 
 
@@ -19,6 +32,10 @@ protected:
     bool firstChar;
     int indentVal;
 
+    // type of current logging
+    LogLevel logType = LogLevel::OFF;
+    LogLevel logLevel = LogLevel::INFO;
+
 public:
     Out(std::ostream& target);
     ~Out(void) = default;
@@ -26,6 +43,8 @@ public:
     inline void indent(int width = 4) { indentVal += width; }
     inline void unindent(int width = 4) { indentVal -= width; }
 
+    inline void setLogType(LogLevel l) { logType = l; }
+
     static Out stdout;
 
 protected:
@@ -34,5 +53,8 @@ protected:
 };
 
 
+std::ostream& operator << (std::ostream& o, qlow::LogLevel l);
+
+
 #endif // QLOW_LOGGING_H
 

+ 34 - 0
src/Semantic.h

@@ -0,0 +1,34 @@
+#ifndef QLOW_SEMANTIC_H
+#define QLOW_SEMANTIC_H
+
+
+namespace qlow
+{
+    namespace sem
+    {
+
+        class Class;
+
+        class Field;
+        class Method;
+    }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#endif // QLOW_SEMANTIC_H
+
+

+ 8 - 1
src/makefile

@@ -1,5 +1,5 @@
 CXX := g++
-CXXFLAGS := -g -Wall -std=c++17
+CXXFLAGS := -Wall -std=c++17
 LINKFLAGS :=
 
 YACC := bison
@@ -16,6 +16,13 @@ EXECUTABLE := qlow
 all: $(EXECUTABLE)
 
 
+
+release: CXXFLAGS += -O3
+release: all
+
+debug: CXXFLAGS += -DDEBUGGING -g
+debug: all
+
 $(EXECUTABLE): $(OBJECTS)
 	$(CXX) $^ $(LINKFLAGS) -o $@