CppInterOp
C++ Language Interoperability Layer
Loading...
Searching...
No Matches
Paths.h
Go to the documentation of this file.
1//--------------------------------------------------------------------*- C++ -*-
2// CLING - the C++ LLVM-based InterpreterG :)
3// author:
4//
5// This file is dual-licensed: you can choose to license it under the University
6// of Illinois Open Source License or the GNU Lesser General Public License. See
7// LICENSE.TXT for details.
8//------------------------------------------------------------------------------
9
10#ifndef CPPINTEROP_UTILS_PATHS_H
11#define CPPINTEROP_UTILS_PATHS_H
12
13#include "llvm/ADT/SmallVector.h"
14#include "llvm/ADT/StringRef.h"
15#include <string>
16#include <vector>
17
18namespace llvm {
19class raw_ostream;
20}
21
22namespace clang {
23class HeaderSearchOptions;
24class FileManager;
25} // namespace clang
26
27namespace CppInternal {
28namespace utils {
29
30namespace platform {
31///\brief Platform specific delimiter for splitting environment variables.
32/// ':' on Unix, and ';' on Windows
33extern const char* const kEnvDelim;
34
35///
36bool GetSystemLibraryPaths(llvm::SmallVectorImpl<std::string>& Paths);
37
38///\brief Returns a normalized version of the given Path
39///
40std::string NormalizePath(const std::string& Path);
41
42///\brief Open a handle to a shared library. On Unix the lib is opened with
43/// RTLD_LAZY|RTLD_GLOBAL flags.
44///
45/// \param [in] Path - Library to open
46/// \param [out] Err - Write errors to this string when given
47///
48/// \returns the library handle
49///
50void* DLOpen(const std::string& Path, std::string* Err = nullptr);
51
52///\brief Close a handle to a shared library.
53///
54/// \param [in] Lib - Handle to library from previous call to DLOpen
55/// \param [out] Err - Write errors to this string when given
56///
57/// \returns the library handle
58///
59void DLClose(void* Lib, std::string* Err = nullptr);
60} // namespace platform
61
63 kPruneNonExistent, ///< Don't add non-existent paths into output
64 kFailNonExistent, ///< Fail on any non-existent paths
65 kAllowNonExistent ///< Add all paths whether they exist or not
66};
67
68///\brief Collect the constituent paths from a PATH string.
69/// /bin:/usr/bin:/usr/local/bin -> {/bin, /usr/bin, /usr/local/bin}
70///
71/// All paths returned existed at the time of the call
72/// \param [in] PathStr - The PATH string to be split
73/// \param [out] Paths - All the paths in the string that exist
74/// \param [in] Mode - If any path doesn't exist stop and return false
75/// \param [in] Delim - The delimiter to use
76/// \param [in] Verbose - Whether to print out details as 'clang -v' would
77///
78/// \return true if all paths existed, otherwise false
79///
80bool SplitPaths(llvm::StringRef PathStr,
81 llvm::SmallVectorImpl<llvm::StringRef>& Paths,
83 llvm::StringRef Delim = CppInternal::utils::platform::kEnvDelim,
84 bool Verbose = false);
85
86///\brief Adds multiple include paths separated by a delimiter into the
87/// given HeaderSearchOptions. This adds the paths but does no further
88/// processing. See Interpreter::AddIncludePaths or CIFactory::createCI
89/// for examples of what needs to be done once the paths have been added.
90///
91///\param[in] PathStr - Path(s)
92///\param[in] Opts - HeaderSearchOptions to add paths into
93///\param[in] Delim - Delimiter to separate paths or NULL if a single path
94///
96 llvm::StringRef PathStr, clang::HeaderSearchOptions& HOpts,
97 const char* Delim = CppInternal::utils::platform::kEnvDelim);
98
99///\brief Write to cling::errs that directory does not exist in a format
100/// matching what 'clang -v' would do
101///
102void LogNonExistentDirectory(llvm::StringRef Path);
103
104///\brief Copies the current include paths into the HeaderSearchOptions.
105///
106///\param[in] Opts - HeaderSearchOptions to read from
107///\param[out] Paths - Vector to output elements into
108///\param[in] WithSystem - if true, incpaths will also contain system
109/// include paths (framework, STL etc).
110///\param[in] WithFlags - if true, each element in incpaths will be prefixed
111/// with a "-I" or similar, and some entries of incpaths will signal
112/// a new include path region (e.g. "-cxx-isystem"). Also, flags
113/// defining header search behavior will be included in incpaths, e.g.
114/// "-nostdinc".
115///
116void CopyIncludePaths(const clang::HeaderSearchOptions& Opts,
117 llvm::SmallVectorImpl<std::string>& Paths,
118 bool WithSystem, bool WithFlags);
119
120} // namespace utils
121} // namespace CppInternal
122
123#endif // CPPINTEROP_UTILS_PATHS_H
void * DLOpen(const std::string &Path, std::string *Err=nullptr)
Open a handle to a shared library.
std::string NormalizePath(const std::string &Path)
Returns a normalized version of the given Path.
Definition Paths.cpp:100
const char *const kEnvDelim
Platform specific delimiter for splitting environment variables.
bool GetSystemLibraryPaths(llvm::SmallVectorImpl< std::string > &Paths)
Definition Paths.cpp:59
void DLClose(void *Lib, std::string *Err=nullptr)
Close a handle to a shared library.
@ kAllowNonExistent
Add all paths whether they exist or not.
Definition Paths.h:65
@ kPruneNonExistent
Don't add non-existent paths into output.
Definition Paths.h:63
@ kFailNonExistent
Fail on any non-existent paths.
Definition Paths.h:64
void CopyIncludePaths(const clang::HeaderSearchOptions &Opts, llvm::SmallVectorImpl< std::string > &incpaths, bool withSystem, bool withFlags)
Copies the current include paths into the HeaderSearchOptions.
Definition Paths.cpp:150
bool SplitPaths(llvm::StringRef PathStr, llvm::SmallVectorImpl< llvm::StringRef > &Paths, SplitMode Mode, llvm::StringRef Delim, bool Verbose)
Collect the constituent paths from a PATH string.
Definition Paths.cpp:250
void AddIncludePaths(llvm::StringRef PathStr, clang::HeaderSearchOptions &HOpts, const char *Delim)
Adds multiple include paths separated by a delimiter into the given HeaderSearchOptions.
Definition Paths.cpp:337
void LogNonExistentDirectory(llvm::StringRef Path)
Write to cling::errs that directory does not exist in a format matching what 'clang -v' would do.
Definition Paths.cpp:244
Definition Paths.h:18