xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.h (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
19dba64beSDimitry Andric //===-- CppModuleConfiguration.h --------------------------------*- C++ -*-===//
29dba64beSDimitry Andric //
39dba64beSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
49dba64beSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
59dba64beSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
69dba64beSDimitry Andric //
79dba64beSDimitry Andric //===----------------------------------------------------------------------===//
89dba64beSDimitry Andric 
9*5ffd83dbSDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CPPMODULECONFIGURATION_H
10*5ffd83dbSDimitry Andric #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CPPMODULECONFIGURATION_H
119dba64beSDimitry Andric 
129dba64beSDimitry Andric #include <lldb/Core/FileSpecList.h>
139dba64beSDimitry Andric #include <llvm/Support/Regex.h>
149dba64beSDimitry Andric 
159dba64beSDimitry Andric namespace lldb_private {
169dba64beSDimitry Andric 
179dba64beSDimitry Andric /// A Clang configuration when importing C++ modules.
189dba64beSDimitry Andric ///
199dba64beSDimitry Andric /// Includes a list of include paths that should be used when importing
209dba64beSDimitry Andric /// and a list of modules that can be imported. Currently only used when
219dba64beSDimitry Andric /// importing the 'std' module and its dependencies.
229dba64beSDimitry Andric class CppModuleConfiguration {
239dba64beSDimitry Andric   /// Utility class for a path that can only be set once.
249dba64beSDimitry Andric   class SetOncePath {
259dba64beSDimitry Andric     std::string m_path;
269dba64beSDimitry Andric     bool m_valid = false;
279dba64beSDimitry Andric     /// True iff this path hasn't been set yet.
289dba64beSDimitry Andric     bool m_first = true;
299dba64beSDimitry Andric 
309dba64beSDimitry Andric   public:
319dba64beSDimitry Andric     /// Try setting the path. Returns true if the path was set and false if
329dba64beSDimitry Andric     /// the path was already set.
339dba64beSDimitry Andric     LLVM_NODISCARD bool TrySet(llvm::StringRef path);
349dba64beSDimitry Andric     /// Return the path if there is one.
359dba64beSDimitry Andric     std::string Get() const {
369dba64beSDimitry Andric       assert(m_valid && "Called Get() on an invalid SetOncePath?");
379dba64beSDimitry Andric       return m_path;
389dba64beSDimitry Andric     }
399dba64beSDimitry Andric     /// Returns true iff this path was set exactly once so far.
409dba64beSDimitry Andric     bool Valid() const { return m_valid; }
419dba64beSDimitry Andric   };
429dba64beSDimitry Andric 
439dba64beSDimitry Andric   /// If valid, the include path used for the std module.
449dba64beSDimitry Andric   SetOncePath m_std_inc;
459dba64beSDimitry Andric   /// If valid, the include path to the C library (e.g. /usr/include).
469dba64beSDimitry Andric   SetOncePath m_c_inc;
479dba64beSDimitry Andric   /// The Clang resource include path for this configuration.
489dba64beSDimitry Andric   std::string m_resource_inc;
499dba64beSDimitry Andric 
509dba64beSDimitry Andric   std::vector<std::string> m_include_dirs;
519dba64beSDimitry Andric   std::vector<std::string> m_imported_modules;
529dba64beSDimitry Andric 
539dba64beSDimitry Andric   /// Analyze a given source file to build the current configuration.
549dba64beSDimitry Andric   /// Returns false iff there was a fatal error that makes analyzing any
559dba64beSDimitry Andric   /// further files pointless as the configuration is now invalid.
569dba64beSDimitry Andric   bool analyzeFile(const FileSpec &f);
579dba64beSDimitry Andric 
589dba64beSDimitry Andric public:
59*5ffd83dbSDimitry Andric   /// Creates a configuration by analyzing the given list of used source files.
609dba64beSDimitry Andric   ///
619dba64beSDimitry Andric   /// Currently only looks at the used paths and doesn't actually access the
629dba64beSDimitry Andric   /// files on the disk.
639dba64beSDimitry Andric   explicit CppModuleConfiguration(const FileSpecList &support_files);
649dba64beSDimitry Andric   /// Creates an empty and invalid configuration.
659dba64beSDimitry Andric   CppModuleConfiguration() {}
669dba64beSDimitry Andric 
679dba64beSDimitry Andric   /// Returns true iff this is a valid configuration that can be used to
689dba64beSDimitry Andric   /// load and compile modules.
699dba64beSDimitry Andric   bool hasValidConfig();
709dba64beSDimitry Andric 
719dba64beSDimitry Andric   /// Returns a list of include directories that should be used when using this
729dba64beSDimitry Andric   /// configuration (e.g. {"/usr/include", "/usr/include/c++/v1"}).
739dba64beSDimitry Andric   llvm::ArrayRef<std::string> GetIncludeDirs() const { return m_include_dirs; }
749dba64beSDimitry Andric 
759dba64beSDimitry Andric   /// Returns a list of (top level) modules that should be imported when using
769dba64beSDimitry Andric   /// this configuration (e.g. {"std"}).
779dba64beSDimitry Andric   llvm::ArrayRef<std::string> GetImportedModules() const {
789dba64beSDimitry Andric     return m_imported_modules;
799dba64beSDimitry Andric   }
809dba64beSDimitry Andric };
819dba64beSDimitry Andric 
829dba64beSDimitry Andric } // namespace lldb_private
839dba64beSDimitry Andric 
849dba64beSDimitry Andric #endif
85