LLDB  mainline
CppModuleConfiguration.h
Go to the documentation of this file.
1 //===-- CppModuleConfiguration.h --------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CPPMODULECONFIGURATION_H
10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CPPMODULECONFIGURATION_H
11 
12 #include <lldb/Core/FileSpecList.h>
13 #include <llvm/Support/Regex.h>
14 
15 namespace lldb_private {
16 
17 /// A Clang configuration when importing C++ modules.
18 ///
19 /// This class computes a list of include paths and module names that can be
20 /// imported given a list of source files. Currently only used when importing
21 /// the 'std' module and its dependencies.
23  /// Utility class for a path that can only be set once.
24  class SetOncePath {
26  bool m_valid = false;
27  /// True iff this path hasn't been set yet.
28  bool m_first = true;
29 
30  public:
31  /// Try setting the path. Returns true if the path was set and false if
32  /// the path was already set.
33  LLVM_NODISCARD bool TrySet(llvm::StringRef path);
34  /// Return the path if there is one.
35  llvm::StringRef Get() const {
36  assert(m_valid && "Called Get() on an invalid SetOncePath?");
37  return m_path;
38  }
39  /// Returns true iff this path was set exactly once so far.
40  bool Valid() const { return m_valid; }
41  };
42 
43  /// If valid, the include path used for the std module.
45  /// If valid, the per-target include path used for the std module.
46  /// This is an optional path only required on some systems.
48  /// If valid, the include path to the C library (e.g. /usr/include).
50  /// If valid, the include path to target-specific C library files
51  /// (e.g. /usr/include/x86_64-linux-gnu).
52  /// This is an optional path only required on some systems.
54  /// The Clang resource include path for this configuration.
56 
57  std::vector<std::string> m_include_dirs;
58  std::vector<std::string> m_imported_modules;
59 
60  /// Analyze a given source file to build the current configuration.
61  /// Returns false iff there was a fatal error that makes analyzing any
62  /// further files pointless as the configuration is now invalid.
63  bool analyzeFile(const FileSpec &f, const llvm::Triple &triple);
64 
65 public:
66  /// Creates a configuration by analyzing the given list of used source files.
67  /// The triple (if valid) is used to search for target-specific include paths.
68  explicit CppModuleConfiguration(const FileSpecList &support_files,
69  const llvm::Triple &triple);
70  /// Creates an empty and invalid configuration.
71  CppModuleConfiguration() = default;
72 
73  /// Returns true iff this is a valid configuration that can be used to
74  /// load and compile modules.
75  bool hasValidConfig();
76 
77  /// Returns a list of include directories that should be used when using this
78  /// configuration (e.g. {"/usr/include", "/usr/include/c++/v1"}).
79  llvm::ArrayRef<std::string> GetIncludeDirs() const { return m_include_dirs; }
80 
81  /// Returns a list of (top level) modules that should be imported when using
82  /// this configuration (e.g. {"std"}).
83  llvm::ArrayRef<std::string> GetImportedModules() const {
84  return m_imported_modules;
85  }
86 };
87 
88 } // namespace lldb_private
89 
90 #endif
lldb_private::CppModuleConfiguration::m_c_inc
SetOncePath m_c_inc
If valid, the include path to the C library (e.g. /usr/include).
Definition: CppModuleConfiguration.h:49
lldb_private::CppModuleConfiguration::SetOncePath::m_first
bool m_first
True iff this path hasn't been set yet.
Definition: CppModuleConfiguration.h:28
lldb_private::CppModuleConfiguration::m_include_dirs
std::vector< std::string > m_include_dirs
Definition: CppModuleConfiguration.h:57
lldb_private::CppModuleConfiguration::SetOncePath::m_path
std::string m_path
Definition: CppModuleConfiguration.h:25
lldb_private::CppModuleConfiguration::GetImportedModules
llvm::ArrayRef< std::string > GetImportedModules() const
Returns a list of (top level) modules that should be imported when using this configuration (e....
Definition: CppModuleConfiguration.h:83
lldb_private::CppModuleConfiguration::SetOncePath
Utility class for a path that can only be set once.
Definition: CppModuleConfiguration.h:24
lldb_private::CppModuleConfiguration::SetOncePath::Get
llvm::StringRef Get() const
Return the path if there is one.
Definition: CppModuleConfiguration.h:35
lldb_private::CppModuleConfiguration::CppModuleConfiguration
CppModuleConfiguration()=default
Creates an empty and invalid configuration.
lldb_private::CppModuleConfiguration::SetOncePath::TrySet
LLVM_NODISCARD bool TrySet(llvm::StringRef path)
Try setting the path.
Definition: CppModuleConfiguration.cpp:17
lldb_private::CppModuleConfiguration::SetOncePath::Valid
bool Valid() const
Returns true iff this path was set exactly once so far.
Definition: CppModuleConfiguration.h:40
lldb_private::CppModuleConfiguration
A Clang configuration when importing C++ modules.
Definition: CppModuleConfiguration.h:22
lldb_private::CppModuleConfiguration::SetOncePath::m_valid
bool m_valid
Definition: CppModuleConfiguration.h:26
lldb_private::CppModuleConfiguration::m_std_inc
SetOncePath m_std_inc
If valid, the include path used for the std module.
Definition: CppModuleConfiguration.h:44
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::CppModuleConfiguration::m_resource_inc
std::string m_resource_inc
The Clang resource include path for this configuration.
Definition: CppModuleConfiguration.h:55
lldb_private::CppModuleConfiguration::GetIncludeDirs
llvm::ArrayRef< std::string > GetIncludeDirs() const
Returns a list of include directories that should be used when using this configuration (e....
Definition: CppModuleConfiguration.h:79
FileSpecList.h
lldb_private::CppModuleConfiguration::m_imported_modules
std::vector< std::string > m_imported_modules
Definition: CppModuleConfiguration.h:58
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::CppModuleConfiguration::m_c_target_inc
SetOncePath m_c_target_inc
If valid, the include path to target-specific C library files (e.g.
Definition: CppModuleConfiguration.h:53
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::CppModuleConfiguration::m_std_target_inc
SetOncePath m_std_target_inc
If valid, the per-target include path used for the std module.
Definition: CppModuleConfiguration.h:47
lldb_private::CppModuleConfiguration::analyzeFile
bool analyzeFile(const FileSpec &f, const llvm::Triple &triple)
Analyze a given source file to build the current configuration.
Definition: CppModuleConfiguration.cpp:61
lldb_private::CppModuleConfiguration::hasValidConfig
bool hasValidConfig()
Returns true iff this is a valid configuration that can be used to load and compile modules.
Definition: CppModuleConfiguration.cpp:106