Improve PCH handling (#136)
This commit is contained in:
@@ -97,33 +97,16 @@ std::string scanModuleName(CompilationParams& params) {
|
||||
}
|
||||
|
||||
std::expected<ModuleInfo, std::string> scanModule(CompilationParams& params) {
|
||||
struct ModuleCollector : public clang::PPCallbacks {
|
||||
ModuleInfo& info;
|
||||
|
||||
ModuleCollector(ModuleInfo& info) : info(info) {}
|
||||
|
||||
void moduleImport(clang::SourceLocation importLoc,
|
||||
clang::ModuleIdPath path,
|
||||
const clang::Module* imported) override {
|
||||
assert(path.size() == 1);
|
||||
info.mods.emplace_back(path[0].first->getName());
|
||||
}
|
||||
};
|
||||
|
||||
ModuleInfo info;
|
||||
clang::PreprocessOnlyAction action;
|
||||
auto instance = impl::createInstance(params);
|
||||
|
||||
if(!action.BeginSourceFile(*instance, instance->getFrontendOpts().Inputs[0])) {
|
||||
return std::unexpected("Failed to begin source file");
|
||||
auto AST = preprocess(params);
|
||||
if(!AST) {
|
||||
return std::unexpected(AST.error());
|
||||
}
|
||||
|
||||
auto& pp = instance->getPreprocessor();
|
||||
auto&& pp = AST->pp();
|
||||
|
||||
pp.addPPCallbacks(std::make_unique<ModuleCollector>(info));
|
||||
|
||||
if(auto error = action.Execute()) {
|
||||
return std::unexpected(std::format("{}", error));
|
||||
for(auto& import: AST->directives()[AST->getInterestedFile()].imports) {
|
||||
info.mods.emplace_back(import.name);
|
||||
}
|
||||
|
||||
if(pp.isInNamedModule()) {
|
||||
|
||||
Reference in New Issue
Block a user