Improve PCH handling (#136)

This commit is contained in:
ykiko
2025-06-10 22:33:17 +08:00
committed by GitHub
parent 0c67c14eef
commit bbece60524
7 changed files with 347 additions and 269 deletions

View File

@@ -45,15 +45,8 @@ struct CompilationParams {
}
};
namespace impl {
/// Create a compiler invocation from the given compilation parameters.
std::unique_ptr<clang::CompilerInvocation> createInvocation(CompilationParams& params);
/// Create a compiler instance from the given compilation parameters.
std::unique_ptr<clang::CompilerInstance> createInstance(CompilationParams& params);
} // namespace impl
/// Only preprocess ths source flie.
std::expected<ASTInfo, std::string> preprocess(CompilationParams& params);
/// Build AST from given file path and content. If pch or pcm provided, apply them to the compiler.
/// Note this function will not check whether we need to update the PCH or PCM, caller should check

View File

@@ -115,12 +115,25 @@ struct Pragma {
clang::SourceLocation loc;
};
struct Import {
/// The name of imported module.
std::string name;
/// The location of import keyword, may comes from macro expansion.
clang::SourceLocation location;
/// The locations of tokens that make up the token name, may comes
/// from macro expansion.
std::vector<clang::SourceLocation> name_locations;
};
struct Directive {
std::vector<Include> includes;
std::vector<HasInclude> hasIncludes;
std::vector<Condition> conditions;
std::vector<MacroRef> macros;
std::vector<Pragma> pragmas;
std::vector<Import> imports;
/// Tell preprocessor to collect directives information and store them in `directives`.
static void attach(clang::Preprocessor& pp,