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; }
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*/)); } }
bool VisitStmt(Stmt* stmt){ if(Context == NULL ) return true ; if( stmt == NULL ) return true ; FullSourceLoc FullLocation = Context->getFullLoc(stmt->getLocStart()) ; if ( !FullLocation.isValid() || exclude(FullLocation.getManager() , stmt) ) return true ; // If we are on a declaration statement, check that we // correctly provide a default value. if(stmt->getStmtClass() == Stmt::DeclStmtClass) { auto& smanager=Context->getSourceManager() ; DeclStmt* declstmt=dyn_cast<DeclStmt>(stmt) ; for(auto cs=declstmt->decl_begin(); cs!=declstmt->decl_end();++cs) { Decl* decl = *cs; VarDecl* vardecl = dyn_cast<VarDecl>(decl) ; if(vardecl){ auto tmp=vardecl->getMostRecentDecl() ; if(tmp) decl=tmp ; SourceRange declsr=decl->getSourceRange() ; SourceLocation sl=declsr.getBegin(); auto fileinfo=smanager.getFileEntryForID(smanager.getFileID(sl)) ; if(fileinfo==NULL || isInExcludedPath(fileinfo->getName(), excludedPathPatterns)) continue ; if( vardecl->getAnyInitializer() == NULL ){ printErrorV1(fileinfo->getName(), smanager.getPresumedLineNumber(sl), smanager.getPresumedColumnNumber(sl), vardecl->getNameAsString()) ; } } } }else if(stmt->getStmtClass() == Stmt::GotoStmtClass){ SourceRange sr=stmt->getSourceRange() ; SourceLocation sl=sr.getBegin() ; auto& smanager=Context->getSourceManager() ; auto fileinfo=smanager.getFileEntryForID(smanager.getFileID(sl)) ; if(fileinfo==NULL || isInExcludedPath(fileinfo->getName(), excludedPathPatterns)) return true ; printErrorW1(fileinfo->getName(), smanager.getPresumedLineNumber(sl), smanager.getPresumedColumnNumber(sl)); }else if(stmt->getStmtClass() == Stmt::CallExprClass){ CallExpr* callexpr=dyn_cast<CallExpr>(stmt) ; FunctionDecl* fctdecl=callexpr->getDirectCallee() ; if(fctdecl){ const string& fctname = fctdecl->getNameAsString() ; for(auto p : oldccode) { if(fctname == p.first){ SourceRange sr=stmt->getSourceRange() ; SourceLocation sl=sr.getBegin() ; auto& smanager=Context->getSourceManager() ; auto fileinfo=smanager.getFileEntryForID(smanager.getFileID(sl)) ; if(fileinfo==NULL || isInExcludedPath(fileinfo->getName(), excludedPathPatterns)) return true ; printErrorW2(fileinfo->getName(), smanager.getPresumedLineNumber(sl), smanager.getPresumedColumnNumber(sl), p.first, p.second); break ; } } } } return true ; }