55 std::vector<Scope *> &result) {
59 if (
auto parent = ctxt->getParent()) {
63 new Scope(result.back(), Scope::DeclScope, sema.getDiagnostics());
64 scope->setEntity(ctxt);
65 result.push_back(scope);
67 result.push_back(sema.TUScope);
73 IdentifierInfo &ident = sema.getASTContext().Idents.get(name);
75 std::unique_ptr<LookupResult> lookup_result;
76 lookup_result = std::make_unique<LookupResult>(sema, DeclarationName(&ident),
78 Sema::LookupOrdinaryName);
83 std::vector<Scope *> scopes;
87 sema.LookupName(*lookup_result, scopes.back());
91 for (Scope *s : scopes)
92 if (s->getDepth() != 0)
128 while (foreign_ctxt && foreign_ctxt->isInlineNamespace())
129 foreign_ctxt = foreign_ctxt->getParent();
132 if (foreign_ctxt->isTranslationUnit())
133 return sema.getASTContext().getTranslationUnitDecl();
136 llvm::Expected<DeclContext *> parent =
142 if (foreign_ctxt->isNamespace()) {
143 NamedDecl *ns = llvm::cast<NamedDecl>(foreign_ctxt);
144 llvm::StringRef ns_name = ns->getName();
147 for (NamedDecl *named_decl : *lookup_result) {
148 if (DeclContext *DC = llvm::dyn_cast<DeclContext>(named_decl))
149 return DC->getPrimaryContext();
151 return llvm::make_error<MissingDeclContext>(
153 "Couldn't find namespace " + ns->getQualifiedNameAsString());
156 return llvm::make_error<MissingDeclContext>(foreign_ctxt,
"Unknown context ");
188 auto td = dyn_cast<ClassTemplateSpecializationDecl>(d);
193 if (!td->getDeclContext()->isStdNamespace())
202 auto &foreign_args = td->getTemplateInstantiationArgs();
208 llvm::Expected<DeclContext *> to_context =
212 "Got error while searching equal local DeclContext for decl "
219 std::unique_ptr<LookupResult> lookup =
222 ClassTemplateDecl *new_class_template =
nullptr;
223 for (
auto LD : *lookup) {
224 if ((new_class_template = dyn_cast<ClassTemplateDecl>(LD)))
227 if (!new_class_template)
231 llvm::SmallVector<TemplateArgument, 4> imported_args;
234 for (
const TemplateArgument &arg : foreign_args.asArray()) {
235 switch (arg.getKind()) {
236 case TemplateArgument::Type: {
237 llvm::Expected<QualType> type =
m_importer->Import(arg.getAsType());
239 LLDB_LOG_ERROR(log, type.takeError(),
"Couldn't import type: {0}");
242 imported_args.push_back(
243 TemplateArgument(*type,
false, arg.getIsDefaulted()));
246 case TemplateArgument::Integral: {
247 llvm::APSInt integral = arg.getAsIntegral();
248 llvm::Expected<QualType> type =
251 LLDB_LOG_ERROR(log, type.takeError(),
"Couldn't import type: {0}");
254 imported_args.push_back(TemplateArgument(d->getASTContext(), integral,
255 *type, arg.getIsDefaulted()));
259 assert(
false &&
"templateArgsAreSupported not updated?");
265 void *InsertPos =
nullptr;
266 ClassTemplateSpecializationDecl *result =
267 new_class_template->findSpecialization(imported_args, InsertPos);
279 new_class_template->getTemplatedDecl()->getTagKind(),
280 new_class_template->getDeclContext(),
281 new_class_template->getTemplatedDecl()->getLocation(),
282 new_class_template->getLocation(), new_class_template, imported_args,
283 td->hasStrictPackMatch(),
286 new_class_template->AddSpecialization(result, InsertPos);
287 if (new_class_template->isOutOfLine())
288 result->setLexicalDeclContext(
289 new_class_template->getLexicalDeclContext());
static void makeScopes(Sema &sema, DeclContext *ctxt, std::vector< Scope * > &result)
Builds a list of scopes that point into the given context.
static llvm::Expected< DeclContext * > getEqualLocalDeclContext(Sema &sema, DeclContext *foreign_ctxt)
Given a foreign decl context, this function finds the equivalent local decl context in the ASTContext...
static std::unique_ptr< LookupResult > emulateLookupInCtxt(Sema &sema, llvm::StringRef name, DeclContext *ctxt)
Uses the Sema to look up the given name in the given DeclContext.
MissingDeclContext(DeclContext *context, std::string error)
void log(llvm::raw_ostream &OS) const override
std::error_code convertToErrorCode() const override