本文整理汇总了C++中MatchFinder::addMatcher方法的典型用法代码示例。如果您正苦于以下问题:C++ MatchFinder::addMatcher方法的具体用法?C++ MatchFinder::addMatcher怎么用?C++ MatchFinder::addMatcher使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatchFinder
的用法示例。
在下文中一共展示了MatchFinder::addMatcher方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: apply
int UseAutoTransform::apply(const clang::tooling::CompilationDatabase &Database,
const std::vector<std::string> &SourcePaths) {
ClangTool UseAutoTool(Database, SourcePaths,
SharedModuleProvider::Create<LLVMModuleProvider>());
unsigned AcceptedChanges = 0;
MatchFinder Finder;
ReplacementsVec Replaces;
IteratorReplacer ReplaceIterators(AcceptedChanges, Options().MaxRiskLevel,
/*Owner=*/ *this);
NewReplacer ReplaceNew(AcceptedChanges, Options().MaxRiskLevel,
/*Owner=*/ *this);
Finder.addMatcher(makeIteratorDeclMatcher(), &ReplaceIterators);
Finder.addMatcher(makeDeclWithNewMatcher(), &ReplaceNew);
if (int Result = UseAutoTool.run(createActionFactory(Finder).get())) {
llvm::errs() << "Error encountered during translation.\n";
return Result;
}
setAcceptedChanges(AcceptedChanges);
return 0;
}
示例2: apply
int QueryMangledNameTransform::apply(const CompilationDatabase &Database,
const std::vector<std::string> &SourcePaths,
const llvm::cl::list<std::string>& LineRanges
) {
llvm::errs() << "QueryMangledName begin\n";
parsePositionArguments( LineRanges );
ClangTool QueryMangledNameTool(Database, SourcePaths);
unsigned AcceptedChanges = 0;
MatchFinder Finder;
QueryMangledNameFixer Fixer(AcceptedChanges, /*Owner=*/ *this);
Finder.addMatcher(makeQueryMangledNameMatcher(), &Fixer);
Finder.addMatcher(makeQueryMangledNameMatcherRef(), &Fixer);
if (int result = QueryMangledNameTool.run(createActionFactory(Finder))) {
llvm::errs() << "Error encountered during translation.\n";
return result;
}
setAcceptedChanges(AcceptedChanges);
llvm::errs() << "QueryMangledName done\n";
return 0;
}
示例3: main
int main(int argc, const char** argv)
{
// Parse the arguments and pass them to the the internal sub-tools
CommonOptionsParser optionsParser(argc, argv, annotatorCategory);
PathFilter bindingPathFilter
(optionsParser.getSourcePathList(), [](const std::string& path) { return path.find("API.cpp") != std::string::npos; });
PathFilter nonBindingPathFilter
(optionsParser.getSourcePathList(), [](const std::string& path) { return path.find("API.cpp") == std::string::npos; });
ClangTool bindingExtractor(optionsParser.getCompilations(), bindingPathFilter.GetPathList());
RefactoringTool annotator(optionsParser.getCompilations(), nonBindingPathFilter.GetPathList());
// Setup finder to match against AST nodes from existing AngelScript binding source files
ExtractCallback extractCallback;
MatchFinder bindingFinder;
// Find exposed class names (they are registered through RegisterObjectType(), RegisterRefCounted(), RegisterObject(), etc)
bindingFinder.addMatcher(
memberCallExpr(
callee(
methodDecl(hasName("RegisterObjectType"))),
hasArgument(0, stringLiteral().bind("className"))), &extractCallback);
bindingFinder.addMatcher(
callExpr(
hasDeclaration(
functionDecl(hasParameter(1, hasName("className")))),
hasArgument(1, stringLiteral().bind("className"))), &extractCallback);
// Setup finder to match against AST nodes for annotating Urho3D library source files
AnnotateCallback annotateCallback(annotator.getReplacements());
MatchFinder annotateFinder;
// Find exported class declaration with Urho3D namespace
annotateFinder.addMatcher(
recordDecl(
#ifndef _MSC_VER
hasAttr(attr::Visibility),
#else
hasAttr(attr::DLLExport),
#endif
matchesName("^::Urho3D::")).bind("className"), &annotateCallback);
// Unbuffered stdout stream to keep the Travis-CI's log flowing and thus prevent it from killing a potentially long running job
outs().SetUnbuffered();
// Success when both sub-tools are run successfully
return (outs() << "Extracting", true) &&
bindingExtractor.run(newFrontendActionFactory(&bindingFinder).get()) == EXIT_SUCCESS &&
(outs() << "\nExtracted " << classNames_.size() << " bound class names\n"
<< "Annotating", true) &&
annotator.runAndSave(newFrontendActionFactory(&annotateFinder).get()) == EXIT_SUCCESS &&
(outs() << "\nAnnotated " << annotatedClassNames_.size() << " exported class names as non-scriptable\n", true) ?
EXIT_SUCCESS : EXIT_FAILURE;
}
示例4: RegisterASTMatcherCallback
void VariableNamingRule::RegisterASTMatcherCallback(MatchFinder& finder)
{
finder.addMatcher(
varDecl(unless(anyOf(isExpansionInSystemHeader(), // ignore system headers
isImplicit(), // ignore implicit (compiler-generated) variables
hasEmptyName()))) // unnamed function parameters are fine
.bind("varDecl"),
this);
finder.addMatcher(
fieldDecl(unless(anyOf(isExpansionInSystemHeader(),
isImplicit(),
hasEmptyName())))
.bind("fieldDecl"),
this);
}
示例5: buildFuncSet
void CanRunScriptChecker::buildFuncSet(ASTContext *Context) {
// We create a match finder.
MatchFinder Finder;
// We create the callback which will be called when we find a function with
// a MOZ_CAN_RUN_SCRIPT annotation.
FuncSetCallback Callback(CanRunScriptFuncs);
// We add the matcher to the finder, linking it to our callback.
Finder.addMatcher(
functionDecl(hasCanRunScriptAnnotation()).bind("canRunScriptFunction"),
&Callback);
Finder.addMatcher(
lambdaExpr().bind("lambda"),
&Callback);
// We start the analysis, given the ASTContext our main checker is in.
Finder.matchAST(*Context);
}
示例6: main
int main(int argc, const char **argv) {
CommonOptionsParser op(argc, argv, ToolingSampleCategory);
RefactoringTool Tool(op.getCompilations(), op.getSourcePathList());
// Set up AST matcher callbacks.
IfStmtHandler HandlerForIf(&Tool.getReplacements());
MatchFinder Finder;
Finder.addMatcher(ifStmt().bind("ifStmt"), &HandlerForIf);
// Run the tool and collect a list of replacements. We could call runAndSave,
// which would destructively overwrite the files with their new contents.
// However, for demonstration purposes it's interesting to show the
// replacements.
if (int Result = Tool.run(newFrontendActionFactory(&Finder).get())) {
return Result;
}
llvm::outs() << "Replacements collected by the tool:\n";
for (auto &r : Tool.getReplacements()) {
llvm::outs() << r.toString() << "\n";
}
return 0;
}
示例7: main
//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;
}
示例8: main
/*
* 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;
SimilarNameChecker snc;
MatchFinder finder;
finder.addMatcher(VarNameMatcher, &snc);
Tool.run(newFrontendActionFactory(&finder));
for(int i = 0; i < nameVec.size(); ++i)
{
std::string oneName(nameVec[i]);
for(int j = i + 1; j < nameVec.size(); ++j)
{
std::string anotherName(nameVec[j]);
if(calculateSimilarity(oneName,anotherName) >= 0.5 && calculateSimilarity(oneName,anotherName) != 1)
{
ofstream out("Rule053", std::ostream::app);
out << oneName << " : " << anotherName << "\n";
}
}
}
return 0;
}
示例9: depthCallback
TEST(StmtDepthMetricTest, ObjCForCollectionStatement)
{
StmtDepthCallback depthCallback(2);
MatchFinder finder;
finder.addMatcher(functionDeclMatcher, &depthCallback);
testMatcherOnObjCCode(finder, "void m() { id array; for(id one in array) {} }");
}
示例10: ncssCallback
TEST(NcssMetricTest, DeclStmtWithManyVariables)
{
NCSSCallback ncssCallback(1);
MatchFinder finder;
finder.addMatcher(functionDeclMatcher, &ncssCallback);
testMatcherOnCode(finder, "void m() { int a = 1, b = 2, c = 3; }");
}