Files
clice/unittests/AST/Selection.cpp
2024-10-26 21:00:23 +08:00

40 lines
1.1 KiB
C++

#include "../Test.h"
#include <AST/Selection.h>
#include <Compiler/Compiler.h>
namespace {
std::vector<const char*> compileArgs = {
"clang++",
"-std=c++20",
"main.cpp",
"-resource-dir",
"/home/ykiko/C++/clice2/build/lib/clang/20",
};
using namespace clice;
TEST(clice, SelectionTree) {
foreachFile("SelectionTree", [](std::string file, llvm::StringRef content) {
auto compiler = Compiler("main.cpp", content, compileArgs);
compiler.buildAST();
auto& fileMgr = compiler.fileMgr();
auto entry = fileMgr.getFileRef("main.cpp");
if(!entry) {
llvm::outs() << "Failed to get file id\n";
std::terminate();
}
auto& srcMgr = compiler.srcMgr();
auto id = srcMgr.translateFile(*entry);
auto begin = srcMgr.translateLineCol(id, 7, 17);
auto end = srcMgr.translateLineCol(id, 7, 17);
SelectionTree tree(srcMgr.getFileOffset(begin),
srcMgr.getFileOffset(end),
compiler.context(),
compiler.tokBuf());
});
}
} // namespace