Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.h
39648 views
//===-- CppModuleConfiguration.h --------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CPPMODULECONFIGURATION_H9#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CPPMODULECONFIGURATION_H1011#include <lldb/Utility/FileSpecList.h>12#include <llvm/Support/Regex.h>1314namespace lldb_private {1516/// A Clang configuration when importing C++ modules.17///18/// This class computes a list of include paths and module names that can be19/// imported given a list of source files. Currently only used when importing20/// the 'std' module and its dependencies.21class CppModuleConfiguration {22/// Utility class for a path that can only be set once.23class SetOncePath {24std::string m_path;25bool m_valid = false;26/// True iff this path hasn't been set yet.27bool m_first = true;2829public:30/// Try setting the path. Returns true if the path was set and false if31/// the path was already set.32[[nodiscard]] bool TrySet(llvm::StringRef path);33/// Return the path if there is one.34llvm::StringRef Get() const {35assert(m_valid && "Called Get() on an invalid SetOncePath?");36return m_path;37}38/// Returns true iff this path was set exactly once so far.39bool Valid() const { return m_valid; }40};4142/// If valid, the include path used for the std module.43SetOncePath m_std_inc;44/// If valid, the per-target include path used for the std module.45/// This is an optional path only required on some systems.46SetOncePath m_std_target_inc;47/// If valid, the include path to the C library (e.g. /usr/include).48SetOncePath m_c_inc;49/// If valid, the include path to target-specific C library files50/// (e.g. /usr/include/x86_64-linux-gnu).51/// This is an optional path only required on some systems.52SetOncePath m_c_target_inc;53/// The Clang resource include path for this configuration.54std::string m_resource_inc;5556std::vector<std::string> m_include_dirs;57std::vector<std::string> m_imported_modules;5859/// Analyze a given source file to build the current configuration.60/// Returns false iff there was a fatal error that makes analyzing any61/// further files pointless as the configuration is now invalid.62bool analyzeFile(const FileSpec &f, const llvm::Triple &triple);6364public:65/// Creates a configuration by analyzing the given list of used source files.66/// The triple (if valid) is used to search for target-specific include paths.67explicit CppModuleConfiguration(const FileSpecList &support_files,68const llvm::Triple &triple);69/// Creates an empty and invalid configuration.70CppModuleConfiguration() = default;7172/// Returns true iff this is a valid configuration that can be used to73/// load and compile modules.74bool hasValidConfig();7576/// Returns a list of include directories that should be used when using this77/// configuration (e.g. {"/usr/include", "/usr/include/c++/v1"}).78llvm::ArrayRef<std::string> GetIncludeDirs() const { return m_include_dirs; }7980/// Returns a list of (top level) modules that should be imported when using81/// this configuration (e.g. {"std"}).82llvm::ArrayRef<std::string> GetImportedModules() const {83return m_imported_modules;84}85};8687} // namespace lldb_private8889#endif909192