// 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_CHECK_CPP_CONTEXT_H_ #define CARBON_TOOLCHAIN_CHECK_CPP_CONTEXT_H_ #include #include "clang/Basic/SourceLocation.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" #include "llvm/ADT/SmallVector.h" namespace Carbon::Check { // Context for C++ code during check. // // This stores state for a Clang AST and Sema, as well as any additional // information needed to perform mapping between Carbon and C++ types, // declarations, and similar values. class CppContext { public: explicit CppContext(std::unique_ptr action); ~CppContext(); auto action() -> clang::FrontendAction& { return *action_; } auto ast_context() -> clang::ASTContext& { return action_->getCompilerInstance().getASTContext(); } auto sema() -> clang::Sema& { return action_->getCompilerInstance().getSema(); } auto clang_mangle_context() -> clang::MangleContext&; auto carbon_file_locations() -> llvm::SmallVector& { return carbon_file_locations_; } private: // The clang action that is generating the C++ AST. std::unique_ptr action_; // Per-Carbon-file start locations for corresponding Clang source buffers. // Owned and managed by code in location.cpp. llvm::SmallVector carbon_file_locations_; // The Clang mangle context for the target in the ASTContext. std::unique_ptr clang_mangle_context_; }; } // namespace Carbon::Check #endif // CARBON_TOOLCHAIN_CHECK_CPP_CONTEXT_H_