Add module aliasing option to swift-ide-test

Add module aliasing handling in code complete
Resolves rdar://86294338
This commit is contained in:
Ellie Shin
2021-12-08 18:07:01 -08:00
parent e358302f54
commit 93132b8ce3
6 changed files with 181 additions and 1 deletions

View File

@@ -262,6 +262,33 @@ void CompilerInvocation::setSDKPath(const std::string &Path) {
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
}
// This assumes the param args contains valid strings for module
// aliasing. The full validation of input for aliasing is done at
// ArgsToFrontendOptionsConverter::computeModulealiases.
void CompilerInvocation::setModuleAliasMap(std::vector<std::string> args) {
// ModuleAliasMap should initially be empty as setting
// it should be called only once
FrontendOpts.ModuleAliasMap.clear();
for (auto item: args) {
auto str = StringRef(item);
// splits to an alias and the underlying name
auto pair = str.split('=');
auto lhs = pair.first;
auto rhs = pair.second;
if (rhs.empty()) // bad format, so skip to the next
continue;
if (!FrontendOpts.ModuleAliasMap.insert({rhs, StringRef()}).second) {
// the underlying name was already added, so skip
continue;
}
auto underlyingName = FrontendOpts.ModuleAliasMap.find(rhs)->first();
if (!FrontendOpts.ModuleAliasMap.insert({lhs, underlyingName}).second) {
// the alias was already added, so skip
continue;
}
}
}
static bool ParseFrontendArgs(
FrontendOptions &opts, ArgList &args, DiagnosticEngine &diags,
SmallVectorImpl<std::unique_ptr<llvm::MemoryBuffer>> *buffers) {