================
@@ -304,47 +297,100 @@ class HeaderVisitor : public 
RecursiveASTVisitor<HeaderVisitor> {
   unsigned Pending = 0;
 };
 
-std::unique_ptr<ASTUnit> buildHeaderAST(const HeaderASTConfig &Cfg) {
-  if (!Cfg.isConfigured())
-    return nullptr;
-
-  std::string Code = Cfg.Header.front() == '<'
-                         ? "#include " + Cfg.Header + "\n"
-                         : "#include \"" + Cfg.Header + "\"\n";
-  std::vector<std::string> Args = {
-      "-std=" + Cfg.Std, "-fsyntax-only", "-x", "c++", "-isysroot", 
Cfg.Sysroot,
+/// The standard library header that declares each supported target class.
+/// Sema only accepts `std::optional` for now.
+std::optional<llvm::StringRef> headerForTarget(llvm::StringRef Target) {
+  static const llvm::StringMap<llvm::StringRef> Headers = {
+      {"std::optional", "<optional>"},
   };
+  auto It = Headers.find(Target);
+  if (It == Headers.end())
+    return std::nullopt;
+  return It->second;
+}
+
+/// Derives the invocation for the header AST from the analysed TU's one:
+/// same header search, target and macros; the main file replaced by `Path`;
+/// anything that would write files or pull in project code dropped.
+std::shared_ptr<CompilerInvocation>
+makeHeaderInvocation(const CompilerInvocation &TU, llvm::StringRef Path) {
+  auto CI = std::make_shared<CompilerInvocation>(TU);
+
+  FrontendOptions &FE = CI->getFrontendOpts();
+  FE.Inputs = {FrontendInputFile(Path, Language::CXX)};
+  FE.ProgramAction = frontend::ParseSyntaxOnly;
+  FE.OutputFile.clear();
+  CI->getDependencyOutputOpts() = DependencyOutputOptions();
+  CI->getCodeGenOpts().MainFileName.clear();
----------------
steakhal wrote:

I agree with both:
- Using the same flags by default makes sense, including the std version.
- I also don't think it's a big issue now.

https://github.com/llvm/llvm-project/pull/243889
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to