virtual void HandleTranslationUnit(TranslationUnit& tu) { // called when everything is done UsageMap uses; for (int i = 0; i < globals.size(); ++i) { uses[globals[i]] = vector<DeclRefExpr*>(); } FindUsages fu(uses); for (int i = 0; i < functions.size(); ++i) { fu.process(functions[i]); } for (int i = 0; i < globals.size(); ++i) { VarDecl* VD = globals[i]; FullSourceLoc loc(VD->getLocation(), *sm); bool isStatic = VD->getStorageClass() == VarDecl::Static; cout << "<span class=\"global\">" << loc.getSourceName() << ": " << (isStatic?"static ":"") << VD->getName() << " (" << uses[VD].size() << " local uses)" << "\n</span>"; cout << "<span class=\"uses\">"; for (int j = 0; j < uses[VD].size(); ++j) { DeclRefExpr* dre = uses[VD][j]; FunctionDecl* fd = enclosing[dre]; FullSourceLoc loc(dre->getLocStart(), *sm); cout << " " << fd->getName() << ":" << loc.getLogicalLineNumber() << "\n"; } cout << "</span>"; } }
bool TeslaVisitor::VisitCallExpr(CallExpr *E) { FunctionDecl *F = E->getDirectCallee(); if (!F) return true; StringRef FnName = F->getName(); if (!FnName.startswith(TESLA_BASE)) return true; // TESLA function calls might be inline assertions. if (FnName == INLINE_ASSERTION) { OwningPtr<Parser> P(Parser::AssertionParser(E, *Context)); if (!P) return false; OwningPtr<AutomatonDescription> Description; OwningPtr<Usage> Use; if (!P->Parse(Description, Use)) return false; Automata.push_back(Description.take()); Roots.push_back(Use.take()); return true; } return true; }
C2::FunctionDecl* C2Sema::ActOnFuncDecl(const char* name, SourceLocation loc, bool is_public, Expr* rtype) { #ifdef SEMA_DEBUG std::cerr << COL_SEMA"SEMA: func decl " << name << " at "; loc.dump(SourceMgr); std::cerr << ANSI_NORMAL"\n"; #endif FunctionDecl* D = createFuncDecl(name, loc, is_public, rtype); if (D->getName() == "main") D->setExported(); ast.addFunction(D); addSymbol(D); return D; }
void VarCheckVisitor::checkFunction(clang::Decl* d) { auto loc = getDeclLocation(d); FunctionDecl* v = (FunctionDecl*)d; string name = v->getName(); boost::regex r{LOCAL_VAR}; if (!boost::regex_match(name, r)){ lineIssues_.push_back(Issue(loc.first, loc.second, "Incorrect Function/Method name", "Functions and Methods should be in lower camel case.", WARNING)); } }
void SimpleInliner::getValidFunctionDecls(void) { #ifdef DEBUGCL std::cerr << "SimpleInliner::getValidFunctionDecls" << std::endl; std::cerr << "FunctionDeclNumStmts.size = " << FunctionDeclNumStmts.size() << std::endl; #endif for (FunctionDeclToNumStmtsMap::iterator I = FunctionDeclNumStmts.begin(), E = FunctionDeclNumStmts.end(); I != E; ++I) { FunctionDecl *FD = (*I).first; #ifdef DEBUGCL std::cerr << FD->getName().str() << std::endl; #endif //unsigned int NumStmts = (*I).second; //unsigned int NumCalls = FunctionDeclNumCalls[FD]; //if (((NumCalls == 1) && (NumStmts <= SingleMaxNumStmts)) || // ((NumCalls > 1) && (NumStmts <= MaxNumStmts))) { ValidFunctionDecls.insert(FD); //} } }
void SimpleInliner::doAnalysis(void) { #ifdef DEBUGCL std::cerr << "SimpleInliner::doAnalysis" << std::endl; std::cerr << "Size of AllCallExprs = " << AllCallExprs.size() << std::endl; #endif getValidFunctionDecls(); for (SmallVector<CallExpr *, 10>::iterator CI = AllCallExprs.begin(), CE = AllCallExprs.end(); CI != CE; ++CI) { FunctionDecl *CalleeDecl = (*CI)->getDirectCallee(); TransAssert(CalleeDecl && "Bad CalleeDecl!"); FunctionDecl *CanonicalDecl = CalleeDecl->getCanonicalDecl(); #ifdef DEBUGCL std::cerr << "CanonicalDecl = " << CanonicalDecl->getName().str() << std::endl; #endif if (!ValidFunctionDecls.count(CanonicalDecl)) { #ifdef DEBUGCL std::cerr << "!ValidFunctionDecls.count" << std::endl; #endif continue; } if (!hasValidArgExprs(*CI)) { #ifdef DEBUGCL std::cerr << "!hasValidArgExprs" << std::endl; #endif continue; } ValidInstanceNum++; #ifdef DEBUGCL std::cerr << "TransformationCounter = " << TransformationCounter << " and ValidInstanceNum = " << ValidInstanceNum << std::endl; #endif if (TransformationCounter == ValidInstanceNum) { #ifdef DEBUGCL std::cerr << "TransformationCounter == ValidInstanceNum" << std::endl; #endif // It's possible the direct callee is not a definition if (!CalleeDecl->isThisDeclarationADefinition()) { CalleeDecl = CalleeDecl->getFirstDeclaration(); for(FunctionDecl::redecl_iterator RI = CalleeDecl->redecls_begin(), RE = CalleeDecl->redecls_end(); RI != RE; ++RI) { if ((*RI)->isThisDeclarationADefinition()) { CalleeDecl = (*RI); break; } } } TransAssert(CalleeDecl->isThisDeclarationADefinition() && "Bad CalleeDecl!"); CurrentFD = CalleeDecl; TheCaller = CalleeToCallerMap[(*CI)]; TransAssert(TheCaller && "NULL TheCaller!"); #ifdef DEBUGCL std::cerr << "Assigning TheCallExpr" << std::endl; #endif TheCallExpr = (*CI); } } }