Add tests for directive collections.

This commit is contained in:
ykiko
2024-12-07 16:50:26 +08:00
parent 6af1017d24
commit 1b7e5a6737
13 changed files with 414 additions and 157 deletions

View File

@@ -80,6 +80,10 @@ public:
return llvm::StringRef(srcMgr().getCharacterData(loc), getTokenLength(loc));
}
auto getLocation(clang::SourceLocation loc) {
return srcMgr().getPresumedLoc(loc);
}
private:
std::unique_ptr<clang::ASTFrontendAction> action;
std::unique_ptr<clang::CompilerInstance> instance;
@@ -131,6 +135,8 @@ struct CompliationParams {
/// Information about reuse PCM(name, path).
llvm::SmallVector<std::pair<std::string, std::string>> pcms;
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs = llvm::vfs::getRealFileSystem();
uint32_t line = 0, column = 0;
void addPCH(const PCHInfo& info) {

View File

@@ -4,7 +4,16 @@
namespace clice {
struct Include {};
struct Include {
/// The path of the included file.
llvm::StringRef path;
/// Location of the directive identifier.
clang::SourceLocation loc;
/// Range of the filename.
clang::SourceRange range;
};
struct Condition {
enum BranchKind : uint8_t {

View File

@@ -5,16 +5,16 @@
namespace clice::support {
template <typename T>
template <typename LHS, typename RHS = LHS>
struct Equal {
static bool equal(const T& lhs, const T& rhs) {
static bool equal(const LHS& lhs, const RHS& rhs) {
return lhs == rhs;
}
};
template <typename T>
bool equal(const T& lhs, const T& rhs) {
return Equal<T>::equal(lhs, rhs);
template <typename LHS, typename RHS>
bool equal(const LHS& lhs, const RHS& rhs) {
return Equal<LHS, RHS>::equal(lhs, rhs);
}
template <typename T>

View File

@@ -173,6 +173,13 @@ struct Serde<double> {
}
};
template <std::size_t N>
struct Serde<char[N]> {
static json::Value serialize(const char (&v)[N]) {
return json::Value(llvm::StringRef(v, N));
}
};
template <>
struct Serde<llvm::StringRef> {
using V = llvm::StringRef;