mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 07:51:05 +01:00
Make multiple imports of the same header only parse it once per C++ domain. Reuse of the same header in `--share-cpp-ast` mode now reuses the representation. Importing a Carbon file with C++ dependencies now makes those transitive C++ dependencies in the same C++ domain visible too. Assisted-by: Gemini via Antigravity
73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_TOOLCHAIN_SEM_IR_CPP_FILE_H_
|
|
#define CARBON_TOOLCHAIN_SEM_IR_CPP_FILE_H_
|
|
|
|
#include <memory>
|
|
|
|
namespace clang {
|
|
class ASTContext;
|
|
class CodeGenerator;
|
|
class CompilerInstance;
|
|
class DiagnosticOptions;
|
|
class DiagnosticsEngine;
|
|
class LangOptions;
|
|
class MangleContext;
|
|
class SourceManager;
|
|
} // namespace clang
|
|
|
|
namespace llvm {
|
|
class LLVMContext;
|
|
} // namespace llvm
|
|
|
|
namespace Carbon::SemIR {
|
|
|
|
class CppDomain;
|
|
|
|
// The result of compiling the C++ portion of a `File`, including both any
|
|
// imported C++ headers and any inline C++ fragments.
|
|
class CppFile {
|
|
public:
|
|
explicit CppFile(std::shared_ptr<clang::CompilerInstance> clang,
|
|
std::unique_ptr<clang::MangleContext> mangle_context,
|
|
llvm::LLVMContext* llvm_context,
|
|
clang::CodeGenerator* code_generator, CppDomain* cpp_domain);
|
|
~CppFile();
|
|
|
|
// Access to compilation options.
|
|
auto diagnostic_options() const -> const clang::DiagnosticOptions&;
|
|
auto lang_options() const -> const clang::LangOptions&;
|
|
|
|
// Access to Clang's compilation environment.
|
|
auto source_manager() -> clang::SourceManager&;
|
|
auto source_manager() const -> const clang::SourceManager&;
|
|
// TODO: This doesn't really belong here, but is currently used by lowering
|
|
// because Clang's code generation may produce diagnostics.
|
|
auto diagnostics() const -> clang::DiagnosticsEngine&;
|
|
|
|
// Access to layers of Clang's C++ representation.
|
|
auto ast_context() -> clang::ASTContext&;
|
|
auto ast_context() const -> const clang::ASTContext&;
|
|
|
|
auto mangle_context() const -> clang::MangleContext&;
|
|
|
|
auto llvm_context() const -> llvm::LLVMContext* { return llvm_context_; }
|
|
auto code_generator() const -> clang::CodeGenerator* {
|
|
return code_generator_;
|
|
}
|
|
auto cpp_domain() const -> CppDomain* { return cpp_domain_; }
|
|
|
|
private:
|
|
std::shared_ptr<clang::CompilerInstance> clang_;
|
|
std::unique_ptr<clang::MangleContext> mangle_context_;
|
|
llvm::LLVMContext* llvm_context_;
|
|
clang::CodeGenerator* code_generator_;
|
|
CppDomain* cpp_domain_;
|
|
};
|
|
|
|
} // namespace Carbon::SemIR
|
|
|
|
#endif // CARBON_TOOLCHAIN_SEM_IR_CPP_FILE_H_
|