Skip to content

Commit

Permalink
Added support of system includes via clang invoke.
Browse files Browse the repository at this point in the history
  • Loading branch information
DronCode committed Jan 20, 2024
1 parent 861f7fb commit 3263b06
Show file tree
Hide file tree
Showing 20 changed files with 1,126 additions and 65 deletions.
22 changes: 22 additions & 0 deletions Cpp/include/RG3/Cpp/AbstractMutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <type_traits>


namespace rg3::cpp
{
struct NullMutex
{
void lock() {}
void unlock() {}
bool try_lock() { return true; } // NOLINT(*-convert-member-functions-to-static)
};

template <typename T>
concept IsMutex = requires(T t)
{
t.lock();
t.unlock();
{ t.try_lock() } -> std::same_as<bool>;
};
}
24 changes: 24 additions & 0 deletions Cpp/include/RG3/Cpp/TransactionGuard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <RG3/Cpp/AbstractMutex.h>
#include <boost/noncopyable.hpp>


namespace rg3::cpp
{
template <typename TMutex> requires (IsMutex<TMutex>)
struct TransactionGuard : boost::noncopyable
{
TMutex& owned;

explicit TransactionGuard(TMutex& toBeLocked) : owned(toBeLocked)
{
owned.lock();
}

~TransactionGuard()
{
owned.unlock();
}
};
}
10 changes: 9 additions & 1 deletion LLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
project(RG3_LLVM)

# ------- Boost
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS system filesystem REQUIRED)
message(STATUS "Found boost ${BOOST_VERSION}")

# ------- LLVM BACKEND
find_package(LLVM REQUIRED CONFIG)
find_package(CLANG REQUIRED CONFIG)
Expand All @@ -14,6 +19,7 @@ target_include_directories(RG3_LLVM PUBLIC ${CLANG_INCLUDE_DIRS})
target_include_directories(RG3_LLVM PUBLIC ${LLVM_INCLUDE_DIRS})

target_link_libraries(RG3_LLVM PUBLIC
# LLVM
LLVMCore
LLVMSupport
clangAST
Expand All @@ -24,6 +30,8 @@ target_link_libraries(RG3_LLVM PUBLIC
clangToolingCore
clangSerialization
clangASTMatchers

# Boost
${Boost_LIBRARIES}
# RG3
RG3::Cpp
)
2 changes: 1 addition & 1 deletion LLVM/include/RG3/LLVM/CodeAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace rg3::llvm
enum class IssueKind { IK_NONE, IK_WARNING, IK_INFO, IK_ERROR };

IssueKind kind { IssueKind::IK_NONE };
std::filesystem::path sSourceFile;
std::string sSourceFile;
std::string sMessage;
};

Expand Down
2 changes: 2 additions & 0 deletions LLVM/include/RG3/LLVM/CompilerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace rg3::llvm
{
CxxStandard cppStandard { CxxStandard::CC_DEFAULT };
IncludeVector vIncludes {};
IncludeVector vSystemIncludes {};
std::vector<std::string> vCompilerArgs;
std::vector<std::string> vCompilerDefs;
bool bAllowCollectNonRuntimeTypes { false };
};
}
42 changes: 42 additions & 0 deletions LLVM/include/RG3/LLVM/CompilerConfigDetector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <string>
#include <variant>

#include <RG3/LLVM/CompilerConfig.h>


namespace rg3::llvm
{
struct CompilerEnvironment
{
CompilerConfig config {};
std::string triple {};
std::string options {};
std::string versionString {};
};

struct CompilerEnvError
{
std::string message {}; // Error message
enum class ErrorKind {
EK_UNKNOWN, ///< Really unknown error
EK_NO_PATHS, ///< Failed to get PATH
EK_NO_CLANG_INSTANCE, ///< Failed to invoke clang (Clang instance not found or running with errors)
EK_BAD_CLANG_OUTPUT, ///< Malformed output of clang instance
EK_NO_SYSTEM_INCLUDE_DIRS_FOUND, ///< Not found any system include dirs. Platform specific failure!
EK_UNSUPPORTED_OS ///< Requested feature or whole env recognition not supported yet
} kind { ErrorKind::EK_UNKNOWN };
};

using CompilerEnvResult = std::variant<CompilerEnvError, CompilerEnvironment>;

struct CompilerConfigDetector
{
/**
* @brief Trying to recognize where located system compiler and trying to get all information about it's environment
* @return CompilerEnvError on error, CompilerEnvironment when everything is ok
*/
static CompilerEnvResult detectSystemCompilerEnvironment();
};
}
Loading

0 comments on commit 3263b06

Please sign in to comment.