From eb32d6eae40bb52cafb7e8eb7da0cef9b2999bbe Mon Sep 17 00:00:00 2001 From: Frederich Munch Date: Thu, 9 Jun 2016 16:05:29 -0400 Subject: [PATCH] Add Interpreter::loadLibrary and Interpreter::loadHeader. Refactor Interpreter::loadFile to call into these methods. --- include/cling/Interpreter/Interpreter.h | 22 +++++++++++++++++- lib/Interpreter/Interpreter.cpp | 31 ++++++++++++++++++++----- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/include/cling/Interpreter/Interpreter.h b/include/cling/Interpreter/Interpreter.h index 07fe3172..4da1b39c 100644 --- a/include/cling/Interpreter/Interpreter.h +++ b/include/cling/Interpreter/Interpreter.h @@ -569,9 +569,29 @@ namespace cling { /// std::string lookupFileOrLibrary(llvm::StringRef file); - ///\brief Loads header file or shared library. + ///\brief Loads a shared library. /// ///\param [in] filename - The file to loaded. + ///\param [in] lookup - Whether to try to resolve the filepath + /// + ///\returns kMoreInputExpected is returned when file could not be found + /// otherwise kSuccess or kFailure + /// + CompilationResult loadLibrary(const std::string& filename, + bool lookup = true); + + ///\brief Loads header file + /// + ///\param [in] filename - The file to loaded. + ///\param [out] T - Transaction containing the loaded file. + ///\returns result of the compilation. + /// + CompilationResult loadHeader(const std::string& filename, + Transaction** T = 0); + + ///\brief Loads header file or shared library. + /// + ///\param [in] filename - The file to be loaded. ///\param [in] allowSharedLib - Whether to try to load the file as shared /// library. ///\param [out] T - Transaction containing the loaded file. diff --git a/lib/Interpreter/Interpreter.cpp b/lib/Interpreter/Interpreter.cpp index 43846e2d..fbdb3b5d 100644 --- a/lib/Interpreter/Interpreter.cpp +++ b/lib/Interpreter/Interpreter.cpp @@ -1159,13 +1159,15 @@ namespace cling { } Interpreter::CompilationResult - Interpreter::loadFile(const std::string& filename, - bool allowSharedLib /*=true*/, - Transaction** T /*= 0*/) { + Interpreter::loadLibrary(const std::string& filename, bool lookup) { DynamicLibraryManager* DLM = getDynamicLibraryManager(); - std::string canonicalLib = DLM->lookupLibrary(filename); - if (allowSharedLib && !canonicalLib.empty()) { - switch (DLM->loadLibrary(canonicalLib, /*permanent*/false, /*resolved*/true)) { + std::string canonicalLib; + if (lookup) + canonicalLib = DLM->lookupLibrary(filename); + + const std::string &library = lookup ? canonicalLib : filename; + if (!library.empty()) { + switch (DLM->loadLibrary(library, /*permanent*/false, /*resolved*/true)) { case DynamicLibraryManager::kLoadLibSuccess: // Intentional fall through case DynamicLibraryManager::kLoadLibAlreadyLoaded: return kSuccess; @@ -1177,7 +1179,12 @@ namespace cling { return kFailure; } } + return kMoreInputExpected; + } + Interpreter::CompilationResult + Interpreter::loadHeader(const std::string& filename, + Transaction** T /*= 0*/) { std::string code; code += "#include \"" + filename + "\""; @@ -1267,6 +1274,18 @@ namespace cling { } } + Interpreter::CompilationResult + Interpreter::loadFile(const std::string& filename, + bool allowSharedLib /*=true*/, + Transaction** T /*= 0*/) { + if (allowSharedLib) { + CompilationResult result = loadLibrary(filename, true); + if (result!=kMoreInputExpected) + return result; + } + return loadHeader(filename, T); + } + static void runAndRemoveStaticDestructorsImpl(IncrementalExecutor &executor, std::vector &transactions, unsigned int begin, unsigned int end) {