void IncrementalParser::markWholeTransactionAsUsed(Transaction* T) const { for (size_t Idx = 0; Idx < T->size() /*can change in the loop!*/; ++Idx) { Transaction::DelayCallInfo I = (*T)[Idx]; // FIXME: implement for multiple decls in a DGR. assert(I.m_DGR.isSingleDecl()); Decl* D = I.m_DGR.getSingleDecl(); if (!D->hasAttr<clang::UsedAttr>()) D->addAttr(::new (D->getASTContext()) clang::UsedAttr(D->getSourceRange(), D->getASTContext(), 0/*AttributeSpellingListIndex*/)); } }
///\brief This is the most important function of the class ASTImportSource /// since from here initiates the lookup and import part of the missing /// Decl(s) (Contexts). /// bool ASTImportSource::FindExternalVisibleDeclsByName( const DeclContext *childCurrentDeclContext, DeclarationName childDeclName) { assert(childCurrentDeclContext->hasExternalVisibleStorage() && "DeclContext has no visible decls in storage"); //Check if we have already found this declaration Name before DeclarationName parentDeclName; std::map<clang::DeclarationName, clang::DeclarationName>::iterator II = m_DeclName_map.find(childDeclName); if (II != m_DeclName_map.end()) { parentDeclName = II->second; } else { // Get the identifier info from the parent interpreter // for this Name. llvm::StringRef name(childDeclName.getAsString()); IdentifierTable &parentIdentifierTable = m_parent_Interp->getCI()->getASTContext().Idents; IdentifierInfo &parentIdentifierInfo = parentIdentifierTable.get(name); DeclarationName parentDeclNameTemp(&parentIdentifierInfo); parentDeclName = parentDeclNameTemp; } // Search in the map of the stored Decl Contexts for this // Decl Context. std::map<const clang::DeclContext *, clang::DeclContext *>::iterator I; if ((I = m_DeclContexts_map.find(childCurrentDeclContext)) != m_DeclContexts_map.end()) { // If childCurrentDeclContext was found before and is already in the map, // then do the lookup using the stored pointer. DeclContext *parentDeclContext = I->second; Decl *fromDeclContext = Decl::castFromDeclContext(parentDeclContext); ASTContext &from_ASTContext = fromDeclContext->getASTContext(); Decl *toDeclContext = Decl::castFromDeclContext(childCurrentDeclContext); ASTContext &to_ASTContext = toDeclContext->getASTContext(); DeclContext::lookup_result lookup_result = parentDeclContext->lookup(parentDeclName); // Check if we found this Name in the parent interpreter if (!lookup_result.empty()) { // Do the import if (Import(lookup_result, from_ASTContext, to_ASTContext, childCurrentDeclContext, childDeclName, parentDeclName)) return true; } } return false; }
void DeclCollector::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { assert(D->isImplicit()); // We need to mark the decls coming from the modules if (comesFromASTReader(RD) || comesFromASTReader(D)) { Decl* implicitD = const_cast<Decl*>(D); implicitD->addAttr(UsedAttr::CreateImplicit(implicitD->getASTContext())); } }
void Indexer::GetTranslationUnitsFor(Entity Ent, TranslationUnitHandler &Handler) { assert(Ent.isValid() && "Expected valid Entity"); if (Ent.isInternalToTU()) { Decl *D = Ent.getInternalDecl(); CtxTUMapTy::iterator I = CtxTUMap.find(&D->getASTContext()); if (I != CtxTUMap.end()) Handler.Handle(I->second); return; } MapTy::iterator I = Map.find(Ent); if (I == Map.end()) return; TUSetTy &Set = I->second; for (TUSetTy::iterator I = Set.begin(), E = Set.end(); I != E; ++I) Handler.Handle(*I); }
void ClangDocHTML::HandleTranslationUnit(TranslationUnitDecl *D) { for(CommentsList::iterator c=commentsList.begin(); c!=commentsList.end(); ++c) { bool bInvalid = false; const char *cbegin = astConsumer->sourceManager->getCharacterData((*c).getBegin(), &bInvalid); const char *cend = astConsumer->sourceManager->getCharacterData((*c).getEnd(), &bInvalid); llvm::StringRef string = llvm::StringRef(cbegin, cend-cbegin); if(string.startswith("///< ")) { for(DeclList::reverse_iterator d=declList.rbegin(); d!=declList.rend(); ++d) { SourceLocation dl = (*d)->getLocation(); SourceLocation cl = (*c).getEnd(); if(cl < dl) { continue; } else { commentsByDecl.insert(CommentsByDeclPair((*d), string.substr(5)) ); break; } } } else if(string.startswith("/// ")) { for(DeclList::iterator d=declList.begin(); d!=declList.end(); ++d) { SourceLocation dl = (*d)->getLocation(); SourceLocation cl = (*c).getEnd(); if(dl < cl) { continue; } else { commentsByDecl.insert(CommentsByDeclPair((*d), string.substr(4)) ); break; } } } } for (DeclByType::iterator it=declByType.begin(); it!=declByType.end(); ++it) { *Out << (it->second)->getKind() << " " << (it->second)->getDeclKindName() << "\n"; } *Out << "<table border = \"1\">\n"; if(!inclusionDirectives.empty()) { *Out << "<th align=\"left\">" << "Include Directives" << "</th>\n"; *Out << "<tbody>"; for(InclusionDirectivesIt it = inclusionDirectives.begin(); it != inclusionDirectives.end(); ++it) { *Out << "<tr><td align=\"left\">\n"; *Out << *it; *Out << "</td></tr>\n"; } *Out << "</tbody>"; } /*PreprocessingRecord *PPRec = astConsumer->preprocessor->getPreprocessingRecord(); if (PPRec && PPRec->begin() != PPRec->end()) { for (PreprocessingRecord::iterator E = PPRec->begin(), EEnd = PPRec->end(); E != EEnd; ++E) { if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { *Out << "<tr><td align=\"left\">\n"; *Out << ID->getFileName(); *Out << "</td></tr>\n"; } } } }*/ for (DeclByTypeIt it=declByType.begin(); it!=declByType.end();) { DeclByTypeItPair result = declByType.equal_range(it->first); *Out << "<th align=\"left\">" << (it->second)->getDeclKindName() << "</th>\n"; *Out << "<tbody>"; for (it=result.first; it!=result.second; ++it) { int Indentation = 0; *Out << "<tr>"; Decl *decl = it->second; { *Out << "<td align=\"right\">\n"; *Out << "<pre>\t"; PrintingPolicyHTML printingPolicy = PrintingPolicyHTML(decl->getASTContext().PrintingPolicy); printingPolicy.htmlSuppressIdentifier = 1; printingPolicy.SuppressInitializers = 1; DeclPrinterHTML Printer(*Out, decl->getASTContext(), printingPolicy, Indentation); Printer.Visit(decl); *Out << "</pre>\n"; *Out << "</td>\n"; } { *Out << "<td>\n"; *Out << "<pre>"; PrintingPolicyHTML printingPolicy = PrintingPolicyHTML(decl->getASTContext().PrintingPolicy); printingPolicy.SuppressSpecifiers = 1; DeclPrinterHTML Printer(*Out, decl->getASTContext(), printingPolicy, Indentation); Printer.Visit(decl); *Out << "</pre>\n"; *Out << "</td>\n"; } { *Out << "<td>\n"; *Out << "<pre>"; CommentsByDeclItPair comments = commentsByDecl.equal_range(decl); for (CommentsByDeclIt cit=comments.first; cit!=comments.second; ++cit) { *Out << cit->second << " "; } //SourceLocation sl = decl->getLocation(); //SourceLocation slend = astConsumer->preprocessor->getCurrentLexer() //astConsumer->sourceManager->get //const char *cbegin = astConsumer->sourceManager->getCharacterData(Comment.getBegin(), &bInvalid); *Out << "</pre>\n"; *Out << "</td>\n"; } *Out << "</tr>"; } *Out << "</tbody>"; } *Out << "</table>\n"; }