Compare commits
No commits in common. "6f3dce5972deb5080b9d980a031a8a0faf16f919" and "e30d779c30559e7ba73074a66a02398df9cd486f" have entirely different histories.
6f3dce5972
...
e30d779c30
@ -31,8 +31,10 @@ StatementMatcher UnaryArithmeticMatcher =
|
||||
StatementMatcher CompoundMatcher =
|
||||
compoundStmt().bind("compound_stmt");
|
||||
|
||||
//StatementMatcher ForStatementMatcher =
|
||||
// forStmt(hasInitStatement(expr().bind("init"))).bind("for_stmt");
|
||||
bool isInMainFile(const MatchFinder::MatchResult &result, const SourceLocation &loc)
|
||||
{
|
||||
return result.Context->getSourceManager().isWrittenInMainFile(loc);
|
||||
}
|
||||
|
||||
template<typename TOp>
|
||||
StringRef getOpcode(const TOp *op)
|
||||
@ -40,23 +42,13 @@ StringRef getOpcode(const TOp *op)
|
||||
return op->getOpcodeStr(op->getOpcode());
|
||||
}
|
||||
|
||||
SourceLocation ResolveOperationSourceLocation(const SourceManager& source_manager, const SourceLocation& original)
|
||||
{
|
||||
if (source_manager.isMacroBodyExpansion(original))
|
||||
{
|
||||
return source_manager.getExpansionLoc(original);
|
||||
}
|
||||
|
||||
return original;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OperationFinder::addMatcher(MatchFinder &finder)
|
||||
{
|
||||
finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, ArithmeticMatcher), this);
|
||||
finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, AssignmentMatcher), this);
|
||||
//finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, CompoundMatcher), this);
|
||||
finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, CompoundMatcher), this);
|
||||
finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, UnaryArithmeticMatcher), this);
|
||||
}
|
||||
|
||||
@ -86,8 +78,12 @@ void OperationFinder::_processAssignment(const clang::ast_matchers::MatchFinder:
|
||||
|
||||
assert(op);
|
||||
|
||||
if (!isInMainFile(result, op->getBeginLoc()))
|
||||
return;
|
||||
|
||||
const auto& loc = op->getBeginLoc();
|
||||
const auto& source_manager = *result.SourceManager;
|
||||
const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc());
|
||||
|
||||
|
||||
llvm::outs() << source_manager.getFilename(loc) << ":"
|
||||
<< source_manager.getSpellingLineNumber(loc) << ":"
|
||||
@ -105,8 +101,11 @@ void OperationFinder::_processArithmetic(const MatchFinder::MatchResult& result)
|
||||
|
||||
assert(op);
|
||||
|
||||
if (!isInMainFile(result, op->getBeginLoc()))
|
||||
return;
|
||||
|
||||
const auto& loc = op->getBeginLoc();
|
||||
const auto& source_manager = *result.SourceManager;
|
||||
const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc());
|
||||
|
||||
llvm::outs() << source_manager.getFilename(loc) << ":"
|
||||
<< source_manager.getSpellingLineNumber(loc) << ":"
|
||||
@ -129,8 +128,11 @@ void OperationFinder::_processCompoundStmt(const clang::ast_matchers::MatchFinde
|
||||
if (!op || !op->isCompoundAssignmentOp())
|
||||
return;
|
||||
|
||||
if (!isInMainFile(result, op->getBeginLoc()))
|
||||
return;
|
||||
|
||||
const auto& loc = op->getBeginLoc();
|
||||
const auto& source_manager = *result.SourceManager;
|
||||
const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc());
|
||||
|
||||
llvm::outs() << source_manager.getFilename(loc) << ":"
|
||||
<< source_manager.getSpellingLineNumber(loc) << ":"
|
||||
@ -150,8 +152,11 @@ void OperationFinder::_processUnaryArithmetic(const MatchFinder::MatchResult &re
|
||||
assert(op);
|
||||
assert(lhs);
|
||||
|
||||
if (!isInMainFile(result, lhs->getBeginLoc()))
|
||||
return;
|
||||
|
||||
const auto& loc = lhs->getBeginLoc();
|
||||
const auto& source_manager = *result.SourceManager;
|
||||
const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc());
|
||||
|
||||
llvm::outs() << source_manager.getFilename(loc) << ":"
|
||||
<< source_manager.getSpellingLineNumber(loc) << ":"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user