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