Repository navigation
Expand file tree
/
Copy pathCompilerGeneratedHandler.cpp
More file actions
55 lines (44 loc) · 2.2 KB
/
Copy pathCompilerGeneratedHandler.cpp
File metadata and controls
55 lines (44 loc) · 2.2 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
48
49
50
51
52
53
54
55
/******************************************************************************
*
* C++ Insights, copyright (C) by Andreas Fertig
* Distributed under an MIT license. See LICENSE for details
*
****************************************************************************/
#include "CompilerGeneratedHandler.h"
#include "DPrint.h"
#include "InsightsHelpers.h"
#include "InsightsMatchers.h"
#include "InsightsStaticStrings.h"
#include "OutputFormatHelper.h"
//-----------------------------------------------------------------------------
using namespace clang;
using namespace clang::ast_matchers;
//-----------------------------------------------------------------------------
namespace clang::insights {
CompilerGeneratedHandler::CompilerGeneratedHandler(Rewriter& rewrite, MatchFinder& matcher)
: InsightsBase(rewrite)
{
static const auto compilerProvided = allOf(unless(isUserProvided()),
unless(isDeleted()),
unless(isExpansionInSystemHeader()),
unless(isTemplate),
unless(isMacroOrInvalidLocation()),
hasParent(cxxRecordDecl().bind("record")));
matcher.addMatcher(cxxMethodDecl(compilerProvided).bind("method"), this);
}
//-----------------------------------------------------------------------------
void CompilerGeneratedHandler::run(const MatchFinder::MatchResult& result)
{
if(const auto* methodDecl = result.Nodes.getNodeAs<CXXMethodDecl>("method")) {
OutputFormatHelper outputFormatHelper{};
outputFormatHelper.Append("/* ");
InsertAccessModifierAndNameWithReturnType(outputFormatHelper, *methodDecl);
outputFormatHelper.AppendNewLine("; */");
// add all compiler generated methods at the end of the class
const auto* recrodDecl = result.Nodes.getNodeAs<CXXRecordDecl>("record");
const auto loc = recrodDecl->getLocEnd();
mRewrite.InsertText(loc, outputFormatHelper.GetString(), true, true);
}
}
//-----------------------------------------------------------------------------
} // namespace clang::insights