-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for GetIncludePaths #178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,6 +347,10 @@ class Interpreter { | |
const_cast<const Interpreter*>(this)->getDynamicLibraryManager()); | ||
} | ||
|
||
/// @brief As a interface to store paths added in AddIncludePaths | ||
std::vector<std::string> include; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this. The include paths are stored in the HeaderSearch already. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we know that AddincludePaths() is fetching the paths and giving it to HeaderSearch, now GetIncludePaths() had the aim of exposing all the paths which were added(not present in HeaderSearch) to the user, for this we had to get/store all those paths which were being added to HeaderSearch with a vector ( as an interface) as AddIncludePaths() does'nt store any paths (makes it available for HeaderSearch). Initially, I tried other methods to store all the paths from AddIncludePaths() itself but for that we require a change in function definition and would not require another function GetIncludePaths(). I also tried creating wrappers around AddIncludePaths() but to maintain the function signature I could'nt find a way to store the paths. |
||
/// | ||
|
||
///\brief Adds multiple include paths separated by a delimter. | ||
/// | ||
///\param[in] PathsStr - Path(s) | ||
|
@@ -359,7 +363,7 @@ class Interpreter { | |
|
||
// Save the current number of entries | ||
size_t Idx = HOpts.UserEntries.size(); | ||
Cpp::utils::AddIncludePaths(PathsStr, HOpts, Delim); | ||
Cpp::utils::GetIncludePaths(include, PathsStr, HOpts, Delim); | ||
|
||
clang::Preprocessor& PP = CI->getPreprocessor(); | ||
clang::SourceManager& SM = PP.getSourceManager(); | ||
|
@@ -383,6 +387,17 @@ class Interpreter { | |
return AddIncludePaths(PathsStr, nullptr); | ||
} | ||
|
||
///\brief Stores include paths. | ||
///\param[in] includePaths - Store Path(s) | ||
/// | ||
void GetIncludePaths(std::vector<std::string>& includePaths) { | ||
includePaths = std::move(include); | ||
} | ||
|
||
void GetIncludePath(std::vector<std::string>& includePaths) { | ||
return GetIncludePaths(includePaths); | ||
} | ||
|
||
CompilationResult loadLibrary(const std::string& filename, bool lookup) { | ||
DynamicLibraryManager* DLM = getDynamicLibraryManager(); | ||
std::string canonicalLib; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,7 +434,6 @@ | |
if (!Exists) | ||
PathsChecked.push_back(Path); | ||
} | ||
|
||
const bool IsFramework = false; | ||
const bool IsSysRootRelative = true; | ||
for (llvm::StringRef Path : PathsChecked) | ||
|
@@ -449,5 +448,32 @@ | |
#undef DEBUG_TYPE | ||
} | ||
|
||
void GetIncludePaths( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition] if ((Exists = E.Path == Path))
^ Additional contextlib/Interpreter/Paths.cpp:450: if it should be an assignment, move it out of the 'if' condition if ((Exists = E.Path == Path))
^ lib/Interpreter/Paths.cpp:450: if it is meant to be an equality check, change '=' to '==' if ((Exists = E.Path == Path))
^ |
||
std::vector<std::string>& includePaths, llvm::StringRef PathStr, | ||
clang::HeaderSearchOptions& HOpts, | ||
const char* Delim /* = Cpp::utils::platform::kEnvDelim */) { | ||
#define DEBUG_TYPE "GetIncludePaths" | ||
|
||
const int val = 10; | ||
llvm::SmallVector<llvm::StringRef, val> Paths; | ||
if ((Delim != nullptr) && (*Delim != 0)) | ||
SplitPaths(PathStr, Paths, kAllowNonExistant, Delim, HOpts.Verbose); | ||
else | ||
Paths.push_back(PathStr); | ||
|
||
// Avoid duplicates | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unused variable 'Path' [clang-diagnostic-unused-variable] for (llvm::StringRef Path : PathsChecked)
^ |
||
for (llvm::StringRef Path : Paths) { | ||
Krishna-13-cyber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bool Exists = false; | ||
for (const clang::HeaderSearchOptions::Entry& E : HOpts.UserEntries) { | ||
if ((E.Path == Path)) | ||
Exists = true; | ||
break; | ||
} | ||
if (!Exists) | ||
includePaths.push_back((std::string)Path); | ||
Krishna-13-cyber marked this conversation as resolved.
Show resolved
Hide resolved
Krishna-13-cyber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
#undef DEBUG_TYPE | ||
} | ||
|
||
} // namespace utils | ||
} // namespace Cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: member variable 'include' has public visibility [cppcoreguidelines-non-private-member-variables-in-classes]