Merge pull request #64376 from rintaro/macros-plugin-server

This commit is contained in:
Rintaro Ishizaki
2023-03-20 07:52:08 -07:00
committed by GitHub
27 changed files with 857 additions and 109 deletions

View File

@@ -67,6 +67,7 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Config/config.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
@@ -6348,15 +6349,30 @@ Type ASTContext::getNamedSwiftType(ModuleDecl *module, StringRef name) {
return decl->getDeclaredInterfaceType();
}
LoadedExecutablePlugin *
Optional<StringRef>
ASTContext::lookupExecutablePluginByModuleName(Identifier moduleName) {
auto &execPluginPaths = getImpl().ExecutablePluginPaths;
auto found = execPluginPaths.find(moduleName);
if (found == execPluginPaths.end())
return nullptr;
return None;
return found->second;
}
// Let the VFS to map the path.
auto &path = found->second;
Optional<std::pair<std::string, std::string>>
ASTContext::lookupExternalLibraryPluginByModuleName(Identifier moduleName) {
auto fs = this->SourceMgr.getFileSystem();
for (auto &pair : SearchPathOpts.ExternalPluginSearchPaths) {
SmallString<128> fullPath(pair.SearchPath);
llvm::sys::path::append(fullPath, "lib" + moduleName.str() + LTDL_SHLIB_EXT);
if (fs->exists(fullPath)) {
return {{std::string(fullPath), pair.ServerPath}};
}
}
return None;
}
LoadedExecutablePlugin *ASTContext::loadExecutablePlugin(StringRef path) {
SmallString<128> resolvedPath;
auto fs = this->SourceMgr.getFileSystem();
if (auto err = fs->getRealPath(path, resolvedPath)) {