================
@@ -235,6 +236,54 @@ std::optional<Location> makeLocation(const ASTContext 
&AST, SourceLocation Loc,
   return L;
 }
 
+std::optional<LocatedSymbol>
+locateModuleReferent(const syntax::Token &TouchedIdentifier, ParsedAST &AST,
+                     llvm::StringRef MainFilePath) {
+  const SourceManager &SM = AST.getSourceManager();
+  const ASTContext &Context = AST.getASTContext();
+
+  const Module *ResultModule = nullptr;
+
+  for (const ImportDecl *Import : Context.local_imports()) {
+    const Module *Imported = Import->getImportedModule();
+    ArrayRef<SourceLocation> IdentifierLocs = Import->getIdentifierLocs();
+    if (!Imported || !Imported->isNamedModule() || IdentifierLocs.empty())
+      continue;
+
+    std::string Name = Imported->getFullModuleName();
+    if (auto Colon = Name.find(':'); Colon != std::string::npos)
+      Name.erase(0, Colon + 1);
+    if (Name.empty())
+      continue;
+
+    const size_t NameSize = static_cast<int>(Name.size() - 1);
----------------
ArcsinX wrote:

It seems this part of code can be optimized. We only need to find position of 
`:` and use it to get `NameEnd`, so we don't really need to call `Name.erase()`.

Also, some nits:
- `NameSize` name is misleading, this is not really a size of name, but an 
offset
- It seems we don't need this static_cast.


https://github.com/llvm/llvm-project/pull/219839
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to