/// \brief Prints the current instantiation stack through a series of /// notes. void Sema::PrintInstantiationStack() { for (llvm::SmallVector<ActiveTemplateInstantiation, 16>::reverse_iterator Active = ActiveTemplateInstantiations.rbegin(), ActiveEnd = ActiveTemplateInstantiations.rend(); Active != ActiveEnd; ++Active) { switch (Active->Kind) { case ActiveTemplateInstantiation::TemplateInstantiation: { unsigned DiagID = diag::note_template_member_class_here; CXXRecordDecl *Record = (CXXRecordDecl *)Active->Entity; if (isa<ClassTemplateSpecializationDecl>(Record)) DiagID = diag::note_template_class_instantiation_here; Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), DiagID) << Context.getTypeDeclType(Record) << Active->InstantiationRange; break; } case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: { TemplateDecl *Template = cast<TemplateDecl>((Decl *)Active->Entity); std::string TemplateArgsStr = TemplateSpecializationType::PrintTemplateArgumentList( Active->TemplateArgs, Active->NumTemplateArgs); Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), diag::note_default_arg_instantiation_here) << (Template->getNameAsString() + TemplateArgsStr) << Active->InstantiationRange; break; } } } }
void EvaluateTSynthesizer::Transform() { if (!getTransaction()->getCompilationOpts().DynamicScoping) return; // include the DynamicLookup specific builtins if (!m_EvalDecl) { TemplateDecl* D = cast_or_null<TemplateDecl>(m_Interpreter->LookupDecl("cling"). LookupDecl("runtime"). LookupDecl("internal"). LookupDecl("EvaluateT"). getSingleDecl()); assert(D && "Cannot find EvaluateT TemplateDecl!\n"); m_EvalDecl = dyn_cast<FunctionDecl>(D->getTemplatedDecl()); assert (m_EvalDecl && "The Eval function not found!"); } if (m_NoRange.isInvalid()) { NamespaceDecl* NSD = utils::Lookup::Namespace(m_Sema, "cling"); NSD = utils::Lookup::Namespace(m_Sema, "runtime", NSD); NSD = utils::Lookup::Namespace(m_Sema, "internal", NSD); DeclarationName Name = &m_Context->Idents.get( "InterpreterGeneratedCodeDiagnosticsMaybeIncorrect"); LookupResult R(*m_Sema, Name, SourceLocation(), Sema::LookupOrdinaryName, Sema::ForRedeclaration); m_Sema->LookupQualifiedName(R, NSD); assert(!R.empty() && "Cannot find PrintValue(...)"); NamedDecl* ND = R.getFoundDecl(); m_NoRange = ND->getSourceRange(); m_NoSLoc = m_NoRange.getBegin(); m_NoELoc = m_NoRange.getEnd(); } for (Transaction::const_iterator I = getTransaction()->decls_begin(), E = getTransaction()->decls_end(); I != E; ++I) for (DeclGroupRef::const_iterator J = (*I).begin(), JE = (*I).end(); J != JE; ++J) if (ShouldVisit(*J) && (*J)->hasBody()) { if (FunctionDecl* FD = dyn_cast<FunctionDecl>(*J)) { // Set the decl context, which is needed by Evaluate. m_CurDeclContext = FD->getDeclContext(); ASTNodeInfo NewBody = Visit((*J)->getBody()); FD->setBody(NewBody.getAsSingleNode()); } assert ((!isa<BlockDecl>(*J) || !isa<ObjCMethodDecl>(*J)) && "Not implemented yet!"); } //TODO: Check for error before returning. }
static bool IsSmallVector(QualType T) { const TemplateSpecializationType *TS = T->getAs<TemplateSpecializationType>(); if (!TS) return false; TemplateName TM = TS->getTemplateName(); TemplateDecl *TD = TM.getAsTemplateDecl(); if (!TD || !InLLVMNamespace(TD)) return false; return TD->getName() == "SmallVector"; }
TemplateName TemplateName::getNameToSubstitute() const { TemplateDecl *Decl = getAsTemplateDecl(); // Substituting a dependent template name: preserve it as written. if (!Decl) return *this; // If we have a template declaration, use the most recent non-friend // declaration of that template. Decl = cast<TemplateDecl>(Decl->getMostRecentDecl()); while (Decl->getFriendObjectKind()) { Decl = cast<TemplateDecl>(Decl->getPreviousDecl()); assert(Decl && "all declarations of template are friends"); } return TemplateName(Decl); }
void EvaluateTSynthesizer::Initialize() { // Most of the declaration we are looking up are in cling::runtime::internal NamespaceDecl* NSD = utils::Lookup::Namespace(m_Sema, "cling"); NamespaceDecl* clingRuntimeNSD = utils::Lookup::Namespace(m_Sema, "runtime", NSD); NSD = utils::Lookup::Namespace(m_Sema, "internal", clingRuntimeNSD); // Find and set up EvaluateT DeclarationName Name = &m_Context->Idents.get("EvaluateT"); LookupResult R(*m_Sema, Name, SourceLocation(), Sema::LookupOrdinaryName, Sema::ForRedeclaration); assert(NSD && "There must be a valid namespace."); m_Sema->LookupQualifiedName(R, NSD); // We have specialized EvaluateT but we don't care because the templated // decl is needed. TemplateDecl* TplD = dyn_cast_or_null<TemplateDecl>(*R.begin()); m_EvalDecl = dyn_cast<FunctionDecl>(TplD->getTemplatedDecl()); assert(m_EvalDecl && "The Eval function not found!"); // Find the LifetimeHandler declaration R.clear(); Name = &m_Context->Idents.get("LifetimeHandler"); R.setLookupName(Name); m_Sema->LookupQualifiedName(R, NSD); m_LifetimeHandlerDecl = R.getAsSingle<CXXRecordDecl>(); assert(m_LifetimeHandlerDecl && "LifetimeHandler could not be found."); // Find the LifetimeHandler::getMemory declaration R.clear(); Name = &m_Context->Idents.get("getMemory"); R.setLookupName(Name); m_Sema->LookupQualifiedName(R, m_LifetimeHandlerDecl); m_LHgetMemoryDecl = R.getAsSingle<CXXMethodDecl>(); assert(m_LHgetMemoryDecl && "LifetimeHandler::getMemory couldn't be found."); // Find the DynamicExprInfo declaration R.clear(); Name = &m_Context->Idents.get("DynamicExprInfo"); R.setLookupName(Name); m_Sema->LookupQualifiedName(R, NSD); m_DynamicExprInfoDecl = R.getAsSingle<CXXRecordDecl>(); assert(m_DynamicExprInfoDecl && "DynExprInfo could not be found."); // Find the DeclContext declaration R.clear(); Name = &m_Context->Idents.get("DeclContext"); R.setLookupName(Name); NamespaceDecl* clangNSD = utils::Lookup::Namespace(m_Sema, "clang"); m_Sema->LookupQualifiedName(R, clangNSD); m_DeclContextDecl = R.getAsSingle<CXXRecordDecl>(); assert(m_DeclContextDecl && "clang::DeclContext decl could not be found."); // Find the gCling declaration R.clear(); Name = &m_Context->Idents.get("gCling"); R.setLookupName(Name); m_Sema->LookupQualifiedName(R, clingRuntimeNSD); m_gCling = R.getAsSingle<VarDecl>(); assert(m_gCling && "gCling decl could not be found."); // Find and set the source locations to valid ones. R.clear(); Name = &m_Context->Idents.get( "InterpreterGeneratedCodeDiagnosticsMaybeIncorrect"); R.setLookupName(Name); m_Sema->LookupQualifiedName(R, NSD); assert(!R.empty() && "Cannot find InterpreterGeneratedCodeDiagnosticsMaybeIncorrect"); NamedDecl* ND = R.getFoundDecl(); m_NoRange = ND->getSourceRange(); m_NoSLoc = m_NoRange.getBegin(); m_NoELoc = m_NoRange.getEnd(); }