/* * Main @TestNeed */ int main(int argc, const char **argv){ CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); ReturnChecker rc; MatchFinder finder; finder.addMatcher(FuncStmtMatcher, &rc); Tool.run(newFrontendActionFactory(&finder)); return 0; }
int main(int argc, const char **argv) { // CommonOptionsParser constructor will parse arguments and create // a CompilationDatabase. clang::tooling::CommonOptionsParser OptionsParser(argc, argv, SampleToolCategory); // retrive CompilationDatabase and the list of input file paths, hand // to the tool constructor -> create a ClangTool and run FrontendAction // over the code clang::tooling::ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); // ClangTool needs a new FrontendAction for each translation unit int result = Tool.run(clang::tooling::newFrontendActionFactory<PGAction>().get()); }
/* * Main @TestNeed */ int main(int argc, const char **argv){ CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); //Create an ClangTool instance to run a FrontendAction over a set of files ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); //tool::MyFactory Factory; GlobalVarChecker gvc; MatchFinder finder; finder.addMatcher(VarDeclMatcher, &gvc); Tool.run(newFrontendActionFactory(&finder)); return 0; }
int main(int argc, const char **argv) { CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); //tooling::MyFactory Factory; ParmPrinter Printer; MatchFinder Finder; Finder.addMatcher(funcMatcher, &Printer); Tool.run(newFrontendActionFactory(&Finder)); return 0; }
// Main function int main(int argc, const char **argv) { clang::tooling::CommonOptionsParser OptionsParser(argc, argv, SuperastCPPCategory); clang::tooling::ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); // Run the recursive visitor int returnValue = Tool.run( clang::tooling::newFrontendActionFactory<SuperastCPPAction>().get()); // Dump the json to stdin dumpJsonDocument(std::cout, document); // Return return returnValue; }
//Main @TestNeed int main(int argc, const char **argv){ CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); CallExprChecker cec; MatchFinder finder; finder.addMatcher(mallocMatcher, &cec); finder.addMatcher(freeMatcher, &cec); finder.addMatcher(reallocMatcher, &cec); finder.addMatcher(memcpyAryMatcher, &cec); finder.addMatcher(memcpyPtrMatcher, &cec); finder.addMatcher(memcmpAryMatcher, &cec); finder.addMatcher(memcmpPtrMatcher, &cec); Tool.run(newFrontendActionFactory(&finder)); return 0; }
int main(int argc, const char **argv) { //CommonOptionsParser constructor will parse arguments and create a //CompilationDatabase. In case of error it will terminate the program. CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); //once we have a CompilationDatabase, we can create a ClangTool and run our //FrontendAction over some code. ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); //tooling::MyFactory Factory; FunctionPrinter Printer; MatchFinder Finder; Finder.addMatcher(funcMatcher, &Printer); Tool.run(newFrontendActionFactory(&Finder)); return 0; }
int main(int argc, const char **argv){ CommonOptionsParser OptionsParser(argc, argv, MyToolCategory); //Create an ClangTool instance to run a FrontendAction over a set of files ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); //tooling::MyFactory Factory; FloatChecker fc; IntChecker ic; StringChecker sc; MatchFinder finder; finder.addMatcher(FloatLiteralMatcher , &fc); finder.addMatcher(IntLiteralMatcher , &ic); finder.addMatcher(StringLiteralMatcher , &sc); Tool.run(newFrontendActionFactory(&finder)); llvm::outs() << "Avoid magic number : " << count << "\n"; return 0; }
static int clangTidyMain(int argc, const char **argv) { CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory, cl::ZeroOrMore); auto OptionsProvider = createOptionsProvider(); if (!OptionsProvider) return 1; StringRef FileName("dummy"); auto PathList = OptionsParser.getSourcePathList(); if (!PathList.empty()) { FileName = PathList.front(); } ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FileName); std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions); if (ListChecks) { llvm::outs() << "Enabled checks:"; for (auto CheckName : EnabledChecks) llvm::outs() << "\n " << CheckName; llvm::outs() << "\n\n"; return 0; } if (DumpConfig) { EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions); llvm::outs() << configurationAsText( ClangTidyOptions::getDefaults().mergeWith( EffectiveOptions)) << "\n"; return 0; } if (EnabledChecks.empty()) { llvm::errs() << "Error: no checks enabled.\n"; llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); return 1; } if (PathList.empty()) { llvm::errs() << "Error: no input files specified.\n"; llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); return 1; } ProfileData Profile; std::vector<ClangTidyError> Errors; ClangTidyStats Stats = runClangTidy(std::move(OptionsProvider), OptionsParser.getCompilations(), PathList, &Errors, EnableCheckProfile ? &Profile : nullptr); bool FoundErrors = std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) { return E.DiagLevel == ClangTidyError::Error; }) != Errors.end(); const bool DisableFixes = Fix && FoundErrors && !FixErrors; // -fix-errors implies -fix. handleErrors(Errors, (FixErrors || Fix) && !DisableFixes); if (!ExportFixes.empty() && !Errors.empty()) { std::error_code EC; llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None); if (EC) { llvm::errs() << "Error opening output file: " << EC.message() << '\n'; return 1; } exportReplacements(Errors, OS); } printStats(Stats); if (DisableFixes) llvm::errs() << "Found compiler errors, but -fix-errors was not specified.\n" "Fixes have NOT been applied.\n\n"; if (EnableCheckProfile) printProfileData(Profile, llvm::errs()); return 0; }