Repository navigation
Expand file tree
/
Copy pathRangeForStmtHandler.cpp
More file actions
47 lines (38 loc) · 1.69 KB
/
Copy pathRangeForStmtHandler.cpp
File metadata and controls
47 lines (38 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/******************************************************************************
*
* C++ Insights, copyright (C) by Andreas Fertig
* Distributed under an MIT license. See LICENSE for details
*
****************************************************************************/
#include "RangeForStmtHandler.h"
#include "CodeGenerator.h"
#include "InsightsHelpers.h"
#include "InsightsMatchers.h"
#include "OutputFormatHelper.h"
//-----------------------------------------------------------------------------
using namespace clang;
using namespace clang::ast_matchers;
//-----------------------------------------------------------------------------
namespace clang::insights {
RangeForStmtHandler::RangeForStmtHandler(Rewriter& rewrite, MatchFinder& matcher)
: InsightsBase(rewrite)
{
matcher.addMatcher(
cxxForRangeStmt(
unless(anyOf(isExpansionInSystemHeader(), isTemplate, isMacroOrInvalidLocation(), hasLambdaAncestor)))
.bind("forRange"),
this);
}
//-----------------------------------------------------------------------------
void RangeForStmtHandler::run(const MatchFinder::MatchResult& result)
{
const auto* rangeForStmt = result.Nodes.getNodeAs<CXXForRangeStmt>("forRange");
const auto& sm = GetSM(result);
const auto columnNr = sm.getSpellingColumnNumber(rangeForStmt->getLocStart());
OutputFormatHelper outputFormatHelper{columnNr};
CodeGenerator codeGenerator{outputFormatHelper};
codeGenerator.InsertArg(rangeForStmt);
mRewrite.ReplaceText(rangeForStmt->getSourceRange(), outputFormatHelper.GetString());
}
//-----------------------------------------------------------------------------
} // namespace clang::insights