Repository navigation
Expand file tree
/
Copy pathOutputFormatHelper.cpp
More file actions
71 lines (56 loc) · 1.98 KB
/
Copy pathOutputFormatHelper.cpp
File metadata and controls
71 lines (56 loc) · 1.98 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/******************************************************************************
*
* C++ Insights, copyright (C) by Andreas Fertig
* Distributed under an MIT license. See LICENSE for details
*
****************************************************************************/
#include "OutputFormatHelper.h"
//-----------------------------------------------------------------------------
namespace clang::insights {
static const std::string MakeIndent(const int indent)
{
std::string str{};
for(int i = 1; i < indent; i++) {
str += ' ';
}
return str;
}
//-----------------------------------------------------------------------------
void OutputFormatHelper::Indent(unsigned count)
{
mOutput.append(MakeIndent(count + 1));
}
//-----------------------------------------------------------------------------
void OutputFormatHelper::AppendParameterList(const ArrayRef<ParmVarDecl*> parameters,
const WithParameterName withParameterName)
{
ForEachArg(parameters, [&](const auto& p) {
const auto& type = p->getType();
if(WithParameterName::Yes == withParameterName) {
const auto& name{GetName(*p)};
Append(GetTypeNameAsParameter(type, name));
} else {
Append(GetName(type));
}
});
}
//-----------------------------------------------------------------------------
void OutputFormatHelper::CloseScope(const NoNewLineBefore newLineBefore)
{
if(NoNewLineBefore::No == newLineBefore) {
NewLine();
}
/* After a newline we are already indented by one level to much. Try to decrease it. */
if(0 != mDefaultIndent) {
for(unsigned i = 0; i < SCOPE_INDENT; ++i) {
if(' ' != mOutput.back()) {
break;
}
mOutput.pop_back();
}
}
Append('}');
DecreaseIndent();
}
//-----------------------------------------------------------------------------
} // namespace clang::insights