Nicolas Winkler 6 年 前
コミット
91181cec6c
3 ファイル変更24 行追加3 行削除
  1. 3 3
      src/CMakeLists.txt
  2. 15 0
      src/util/Path.cpp
  3. 6 0
      src/util/Path.h

+ 3 - 3
src/CMakeLists.txt

@@ -30,9 +30,9 @@ else()
     include_directories(bison/)
 endif()
 
-FILE(GLOB CppSources *.cpp ast/*.cpp sem/*.cpp)
+FILE(GLOB CppSources *.cpp ast/*.cpp sem/*.cpp util/*.cpp)
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
-include_directories(ast sem .)
+include_directories(ast sem util .)
 
 add_executable(${PROJECT_NAME} ${BISON_QlowParser_OUTPUTS} ${FLEX_QlowLexer_OUTPUTS} ${CppSources} ${AdditionalSources})
 
@@ -76,7 +76,7 @@ if (${APPLE})
 endif()
 
 if (${WIN32})
-    target_compile_definitions(${PROJECT_NAME} PRIVATE QLOW_TARGET_APPLE)
+    target_compile_definitions(${PROJECT_NAME} PRIVATE QLOW_TARGET_WINDOWS)
 endif()
 
 #explicit_llvm_config(${PROJECT_NAME} STATIC_LIBRARY)

+ 15 - 0
src/util/Path.cpp

@@ -2,9 +2,17 @@
 
 using qlow::util::Path;
 
+#ifdef QLOW_TARGET_WINDOWS
+const std::string Path::dirSeparator = "\\";
+#else
+const std::string Path::dirSeparator = "/";
+#endif
+
 
 void Path::append(const Path& other)
 {
+    if (!endsWithSeparator())
+        path += dirSeparator;
     path += other.path;
 }
 
@@ -13,3 +21,10 @@ Path::operator const std::string&(void) const
 {
     return path;
 }
+
+
+bool Path::endsWithSeparator(void) const
+{
+    return path.size() > dirSeparator.size() &&
+        std::equal(dirSeparator.rbegin(), dirSeparator.rend(), path.rbegin());
+}

+ 6 - 0
src/util/Path.h

@@ -13,6 +13,9 @@ namespace qlow::util
 class qlow::util::Path
 {
     std::string path;
+
+    static const std::string dirSeparator;
+
 public:
 
     inline Path(std::string path) :
@@ -22,6 +25,9 @@ public:
 
     void append(const Path& other);
     operator const std::string&(void) const;
+    
+private:
+    bool endsWithSeparator(void) const;
 };
 
 #endif // QLOW_UTIL_PATH_H_