bool SimplifyStructUnionDecl::HandleTopLevelDecl(DeclGroupRef DGR) { DeclGroupRef::iterator DI = DGR.begin(); if (isInIncludedFile(*DI)) return true; const RecordDecl *RD = dyn_cast<RecordDecl>(*DI); if (RD) { addOneRecordDecl(RD, DGR); return true; } VarDecl *VD = dyn_cast<VarDecl>(*DI); if (!VD) return true; const Type *T = VD->getType().getTypePtr(); RD = getBaseRecordDecl(T); if (!RD) return true; const Decl *CanonicalD = RD->getCanonicalDecl(); void *DGRPointer = RecordDeclToDeclGroup[CanonicalD]; if (!DGRPointer) return true; ValidInstanceNum++; if (ValidInstanceNum != TransformationCounter) return true; TheRecordDecl = dyn_cast<RecordDecl>(CanonicalD); TheDeclGroupRefs.push_back(DGRPointer); TheDeclGroupRefs.push_back(DGR.getAsOpaquePtr()); for (DeclGroupRef::iterator I = DGR.begin(), E = DGR.end(); I != E; ++I) { VarDecl *VD = dyn_cast<VarDecl>(*I); TransAssert(VD && "Bad VarDecl!"); CombinedVars.insert(VD); } DeclGroupRef DefDGR = DeclGroupRef::getFromOpaquePtr(DGRPointer); for (DeclGroupRef::iterator I = DefDGR.begin(), E = DefDGR.end(); I != E; ++I) { VarDecl *VD = dyn_cast<VarDecl>(*I); if (VD) CombinedVars.insert(VD); } return true; }
virtual bool HandleTopLevelDecl(DeclGroupRef DR) { for (auto DB = DR.begin(), DE = DR.end(); DB != DE; ++DB) { // Traverse the declaration using our AST visitor. Visitor.TraverseDecl(*DB); } return true; }
bool ASTVistor::HandleTopLevelDecl(DeclGroupRef DG) { for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) { const Decl *D = *i; if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { if (!FD->hasBody()) continue; if (CI_.getSourceManager().isInSystemHeader(FD->getLocation())) { //loc.print(llvm::errs(), CI_.getSourceManager()); continue; } std::vector<std::string> params; for (FunctionDecl::param_const_iterator it = FD->param_begin(); it != FD->param_end(); ++it) { params.push_back((*it)->getOriginalType().getAsString()); } fmt_.AddDefinition(FD->getQualifiedNameAsString(), FD->getResultType().getAsString(), params); this->TraverseStmt(FD->getBody()); fmt_.EndDefinition(); } } ost_.flush(); return true; }
// Override the method that gets called for each parsed top-level // declaration. bool HandleTopLevelDecl(DeclGroupRef DR) override { for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) { // Traverse the declaration using our AST visitor. visitor.TraverseDecl(*b); } return true; }
// This gets called *while the source is being parsed* - the full AST does not // exist yet. bool HandleTopLevelDecl(DeclGroupRef DR) override { for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) { // llvm::errs() << "This is a toplevel decl!\n"; //(*b)->dump(); } return true; }
bool LiftAssignmentExpr::HandleTopLevelDecl(DeclGroupRef D) { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { CollectionVisitor->TraverseDecl(*I); } return true; }
bool RewriteUtils::getEntireDeclGroupStrAndRemove(DeclGroupRef DGR, std::string &Str) { Decl *FirstD, *LastD; if (DGR.isSingleDecl()) { FirstD = DGR.getSingleDecl(); LastD = FirstD; } else { DeclGroupRef::iterator I = DGR.begin(); FirstD = (*I); DeclGroupRef::iterator E = DGR.end(); --E; LastD = (*E); } SourceRange FirstRange = FirstD->getSourceRange(); SourceLocation StartLoc = FirstRange.getBegin(); SourceRange LastRange = LastD->getSourceRange(); SourceLocation EndLoc = getEndLocationUntil(LastRange, ';'); getStringBetweenLocs(Str, StartLoc, EndLoc); return !TheRewriter->RemoveText(SourceRange(StartLoc, EndLoc)); }
SourceLocation RewriteUtils::getDeclGroupRefEndLoc(DeclGroupRef DGR) { Decl *LastD; if (DGR.isSingleDecl()) { LastD = DGR.getSingleDecl(); } else { DeclGroupRef::iterator E = DGR.end(); --E; LastD = (*E); } #if 0 VarDecl *VD = dyn_cast<VarDecl>(LastD); TransAssert(VD && "Bad VD!"); SourceRange VarRange = VD->getSourceRange(); return getEndLocationFromBegin(VarRange); #endif // The LastD could be a RecordDecl SourceRange Range = LastD->getSourceRange(); SourceLocation EndLoc = getEndLocationFromBegin(Range); TransAssert(EndLoc.isValid() && "Invalid EndLoc!"); return EndLoc; }
bool RemoveNestedFunction::HandleTopLevelDecl(DeclGroupRef D) { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { NestedInvocationVisitor->TraverseDecl(*I); } return true; }
bool DeclCollector::HandleTopLevelDecl(DeclGroupRef DGR) { // if that decl comes from an AST File, i.e. PCH/PCM, no transaction needed // pipe it directly to codegen. if (comesFromASTReader(DGR)) { if (m_CodeGen) { for (DeclGroupRef::iterator I = DGR.begin(), E = DGR.end(); I != E; ++I) { if (NamespaceDecl* ND = dyn_cast<NamespaceDecl>(*I)) { for (NamespaceDecl::decl_iterator IN = ND->decls_begin(), EN = ND->decls_end(); IN != EN; ++IN) // Recurse over decls inside the namespace, like // CodeGenModule::EmitNamespace() does. HandleTopLevelDecl(DeclGroupRef(*IN)); } else { if (!shouldIgnoreDeclFromASTReader(*I)) { m_CodeGen->HandleTopLevelDecl(DeclGroupRef(*I)); } // FIXME: once modules are there this is not needed anymore. // it is used to simulate modules and the ASTDeserializationListener // for sources that are included to describe the library that was // built from the sources (ACLiC). if (!(*I)->isFromASTFile() && m_Interp->getASTDeserializationListener()) m_Interp->getASTDeserializationListener()->DeclRead(0, *I); } } } return true; } Transaction::DelayCallInfo DCI(DGR, Transaction::kCCIHandleTopLevelDecl); m_CurTransaction->append(DCI); return true; }
bool CombineLocalVarDecl::HandleTopLevelDecl(DeclGroupRef D) { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { CollectionVisitor->TraverseDecl(*I); } return true; }
bool SimpleInliner::HandleTopLevelDecl(DeclGroupRef D) { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { FunctionStmtVisitor->TraverseDecl(*I); } return true; }
virtual bool HandleTopLevelDecl(DeclGroupRef DR) { for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) { // Travel each function declaration using MyASTVisitor Visitor.TraverseDecl(*b); } return true; }
bool ReduceArraySize::HandleTopLevelDecl(DeclGroupRef D) { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { CollectionVisitor->TraverseDecl(*I); } return true; }
bool BinOpSimplification::HandleTopLevelDecl(DeclGroupRef D) { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { BinOpCollectionVisitor->TraverseDecl(*I); } return true; }
bool CDaoASTConsumer::HandleTopLevelDecl(DeclGroupRef group) { for (DeclGroupRef::iterator it = group.begin(); it != group.end(); ++it) { HandleDeclaration( *it ); } return true; }
virtual bool HandleTopLevelDecl( DeclGroupRef group ) override { for( auto itr = group.begin(); itr != group.end(); ++itr ) { // if this decl is a reflectable type ... auto tagDecl = dyn_cast<TagDecl>( *itr ); if( tagDecl== nullptr ) { continue; } // should we reflect it? mReflect.SetDefault( false ); if( mReflect.ParseComment( mContext->getCommentForDecl( tagDecl, nullptr ) ) == false ) { continue; } // recursively write it out decl and all contained types mReflect.SetDefault( true ); mVisitor.TraverseDecl( tagDecl ); } return true; }
// Override the method that gets called for each parsed top-level // declaration. virtual bool HandleTopLevelDecl(DeclGroupRef DR) { for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) // Traverse the declaration using our AST visitor. mpVisitor->TraverseDecl(*b); return true; }
bool RemoveUnusedVar::HandleTopLevelDecl(DeclGroupRef D) { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { VarDecl *VD = dyn_cast<VarDecl>(*I); if (VD) VarToDeclGroup[VD] = D; } return true; }
bool MyASTConsumer::HandleTopLevelDecl(DeclGroupRef d) { typedef DeclGroupRef::iterator iter; for (iter b = d.begin(), e = d.end(); b != e; ++b){ rv.TraverseDecl(*b); } return true; // keep going }
bool AnalysisConsumer::HandleTopLevelDecl(DeclGroupRef DG) { storeTopLevelDecls(DG); for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; i++) { Decl *D = *i; string ssStart = D->getLocStart().printToString(Mgr->getASTContext().getSourceManager()); //std::cout<<"HandleTopLevelDecl: "<<ssStart<<std::endl; } return true; }
bool UnionToStruct::HandleTopLevelDecl(DeclGroupRef D) { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { if (VarDecl *VD = dyn_cast<VarDecl>(*I)) VarToDeclGroup[VD] = D; CollectionVisitor->TraverseDecl(*I); } return true; }
void ASTConsumerHTML::HandleInterestingDecl(DeclGroupRef D) { for (DeclGroupRef::iterator it = D.begin(); it != D.end(); ++it) { Decl *decl = *it; if (decl) { log << "\n" << decl << " HandleInterestingDecl" << "\n"; decl->print(log); log << "\n"; } } }
void AnalysisConsumer::storeTopLevelDecls(DeclGroupRef DG) { for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) { // Skip ObjCMethodDecl, wait for the objc container to avoid // analyzing twice. if (isa<ObjCMethodDecl>(*I)) continue; LocalTUDecls.push_back(*I); } }
bool AggregateToScalar::HandleTopLevelDecl(DeclGroupRef D) { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { VarDecl *VD = dyn_cast<VarDecl>(*I); if (VD) VarDeclToDeclGroupMap[VD] = D; AggregateAccessVisitor->TraverseDecl(*I); } return true; }
bool VisitDeclStmt(DeclStmt* DS) { DeclGroupRef DGR = DS->getDeclGroup(); for (DeclGroupRef::const_iterator I = DGR.begin(), E = DGR.end(); I != E; ++I) { if (isCandidate(*I)) { m_ShouldVisitSubTree = true; return false; // returning false will abort the in-depth traversal. } } return true; }
bool HandleTopLevelDecl(DeclGroupRef DG) override { if (Diags.hasErrorOccurred()) return true; HandlingTopLevelDeclRAII HandlingDecl(*this); // Make sure to emit all elements of a Decl. for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) Builder->EmitTopLevelDecl(*I); return true; }
bool ASTStructExtractor::HandleTopLevelDecl(DeclGroupRef D) { DeclGroupRef::iterator decl_iterator; for (decl_iterator = D.begin(); decl_iterator != D.end(); ++decl_iterator) { Decl *decl = *decl_iterator; ExtractFromTopLevelDecl(decl); } if (m_passthrough) return m_passthrough->HandleTopLevelDecl(D); return true; }
bool SimplePrinterConsumer::HandleTopLevelDecl(DeclGroupRef D) { if(D.begin() == D.end()) { return true; } Decl *firstD = *(D.begin()); if(compInst->getSourceManager().isInSystemHeader(firstD->getLocation())) { return true; } PrintingPolicy policy = compInst->getASTContext().getPrintingPolicy(); NullStmt *nullSt = new (compInst->getASTContext()) NullStmt(SourceLocation()); for(DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { Decl *dd = *I; DPRINT("PrintingPolicy: %d %d %d %d %d", policy.SuppressSpecifiers, policy.SuppressScope, policy.SuppressTag, policy.SuppressUnwrittenScope, policy.SuppressSpecifiers); dd->print(out, policy); nullSt->printPretty(out, NULL, policy); if(dd->hasBody()) { Stmt *ss = dd->getBody(); // Print Stmts //dd->dump(); //StmtPrinter(compInst, dd->getBody()).TraverseDecl(dd); // CFG OwningPtr<CFG> cfg; cfg.reset(CFG::buildCFG((const Decl*)dd, (Stmt*)(dd->getBody()), &compInst->getASTContext(), CFG::BuildOptions())); assert(cfg.get() != NULL && "build CFG failed."); cfg->dump(compInst->getLangOpts(), true); cfg->viewCFG(compInst->getLangOpts()); } } return true; };
// This function skips type specifiers bool RewriteUtils::getDeclGroupStrAndRemove(DeclGroupRef DGR, std::string &Str) { if (DGR.isSingleDecl()) { Decl *D = DGR.getSingleDecl(); VarDecl *VD = dyn_cast<VarDecl>(D); TransAssert(VD && "Bad VarDecl!"); // We need to get the outermost TypeLocEnd instead of the StartLoc of // a var name, because we need to handle the case below: // int *x; // int *y; // If we rely on the StartLoc of a var name, then we will make bad // transformation like: // int *x, y; SourceLocation TypeLocEnd = getVarDeclTypeLocEnd(VD); SourceRange VarRange = VD->getSourceRange(); SourceLocation LocEnd = getEndLocationUntil(VarRange, ';'); getStringBetweenLocs(Str, TypeLocEnd, LocEnd); SourceLocation StartLoc = VarRange.getBegin(); SourceLocation NewEndLoc = getLocationAfterSkiping(LocEnd, ';'); return !(TheRewriter->RemoveText(SourceRange(StartLoc, NewEndLoc))); } TransAssert(DGR.getDeclGroup().size() > 1); DeclGroupRef::iterator I = DGR.begin(); DeclGroupRef::iterator E = DGR.end(); --E; Decl *FirstD = (*I); VarDecl *FirstVD = dyn_cast<VarDecl>(FirstD); Decl *LastD = (*E); VarDecl *LastVD = dyn_cast<VarDecl>(LastD); TransAssert(FirstVD && "Bad First VarDecl!"); TransAssert(LastVD && "Bad First VarDecl!"); SourceLocation TypeLocEnd = getVarDeclTypeLocEnd(FirstVD); SourceRange LastVarRange = LastVD->getSourceRange(); SourceLocation LastEndLoc = getEndLocationUntil(LastVarRange, ';'); getStringBetweenLocs(Str, TypeLocEnd, LastEndLoc); SourceLocation StartLoc = FirstVD->getLocStart(); SourceLocation NewLastEndLoc = getLocationAfterSkiping(LastEndLoc, ';'); return !(TheRewriter->RemoveText(SourceRange(StartLoc, NewLastEndLoc))); }