Skip to content

Commit 9dfb86e

Browse files
committed
Use the indent function. NFC.
1 parent 3ce31ae commit 9dfb86e

File tree

1 file changed

+31
-79
lines changed

1 file changed

+31
-79
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 31 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,6 @@ namespace Cpp {
12971297
// encompassed in an anonymous namespace as follows.
12981298
namespace {
12991299
static unsigned long long gWrapperSerial = 0LL;
1300-
static const std::string kIndentString(" ");
13011300

13021301
enum EReferenceType { kNotReference, kLValueReference, kRValueReference };
13031302

@@ -1308,6 +1307,7 @@ namespace Cpp {
13081307
// FIXME: Use that routine throughout CallFunc's port in places such as
13091308
// make_narg_call.
13101309
static inline void indent(ostringstream &buf, int indent_level) {
1310+
static const std::string kIndentString(" ");
13111311
for (int i = 0; i < indent_level; ++i)
13121312
buf << kIndentString;
13131313
}
@@ -1355,9 +1355,9 @@ namespace Cpp {
13551355
QT.print(OS, Policy, type_name);
13561356
OS.flush();
13571357
}
1358-
for (int i = 0; i < indent_level; ++i) {
1359-
typedefbuf << kIndentString;
1360-
}
1358+
1359+
indent(typedefbuf, indent_level);
1360+
13611361
typedefbuf << "typedef " << fp_typedef_name << ";\n";
13621362
return;
13631363
} else if (QT->isMemberPointerType()) {
@@ -1370,9 +1370,9 @@ namespace Cpp {
13701370
QT.print(OS, Policy, type_name);
13711371
OS.flush();
13721372
}
1373-
for (int i = 0; i < indent_level; ++i) {
1374-
typedefbuf << kIndentString;
1375-
}
1373+
1374+
indent(typedefbuf, indent_level);
1375+
13761376
typedefbuf << "typedef " << mp_typedef_name << ";\n";
13771377
return;
13781378
} else if (QT->isPointerType()) {
@@ -1397,9 +1397,7 @@ namespace Cpp {
13971397
QT.print(OS, Policy, type_name);
13981398
OS.flush();
13991399
}
1400-
for (int i = 0; i < indent_level; ++i) {
1401-
typedefbuf << kIndentString;
1402-
}
1400+
indent(typedefbuf, indent_level);
14031401
typedefbuf << "typedef " << ar_typedef_name << ";\n";
14041402
return;
14051403
}
@@ -1431,9 +1429,7 @@ namespace Cpp {
14311429
callbuf << ' ';
14321430
} else {
14331431
callbuf << "\n";
1434-
for (int j = 0; j <= indent_level; ++j) {
1435-
callbuf << kIndentString;
1436-
}
1432+
indent(callbuf, indent_level);
14371433
}
14381434
}
14391435
if (refType != kNotReference) {
@@ -1493,9 +1489,7 @@ namespace Cpp {
14931489
callbuf << ' ';
14941490
} else {
14951491
callbuf << "\n";
1496-
for (int j = 0; j <= indent_level; ++j) {
1497-
callbuf << kIndentString;
1498-
}
1492+
indent(callbuf, indent_level);
14991493
}
15001494
}
15011495
const ParmVarDecl* PVD = FD->getParamDecl(i);
@@ -1557,9 +1551,7 @@ namespace Cpp {
15571551
callbuf << ' ';
15581552
} else {
15591553
callbuf << "\n";
1560-
for (int j = 0; j <= indent_level; ++j) {
1561-
callbuf << kIndentString;
1562-
}
1554+
indent(callbuf, indent_level);
15631555
}
15641556
}
15651557

@@ -1590,9 +1582,7 @@ namespace Cpp {
15901582
// new ClassName(args...);
15911583
// }
15921584
//
1593-
for (int i = 0; i < indent_level; ++i) {
1594-
buf << kIndentString;
1595-
}
1585+
indent(buf, indent_level);
15961586
buf << "if (ret) {\n";
15971587
++indent_level;
15981588
{
@@ -1601,9 +1591,7 @@ namespace Cpp {
16011591
//
16021592
// Write the return value assignment part.
16031593
//
1604-
for (int i = 0; i < indent_level; ++i) {
1605-
callbuf << kIndentString;
1606-
}
1594+
indent(callbuf, indent_level);
16071595
callbuf << "(*(" << class_name << "**)ret) = ";
16081596
//
16091597
// Write the actual new expression.
@@ -1613,43 +1601,31 @@ namespace Cpp {
16131601
// End the new expression statement.
16141602
//
16151603
callbuf << ";\n";
1616-
for (int i = 0; i < indent_level; ++i) {
1617-
callbuf << kIndentString;
1618-
}
1604+
indent(callbuf, indent_level);
16191605
callbuf << "return;\n";
16201606
//
16211607
// Output the whole new expression and return statement.
16221608
//
16231609
buf << typedefbuf.str() << callbuf.str();
16241610
}
16251611
--indent_level;
1626-
for (int i = 0; i < indent_level; ++i) {
1627-
buf << kIndentString;
1628-
}
1612+
indent(buf, indent_level);
16291613
buf << "}\n";
1630-
for (int i = 0; i < indent_level; ++i) {
1631-
buf << kIndentString;
1632-
}
1614+
indent(buf, indent_level);
16331615
buf << "else {\n";
16341616
++indent_level;
16351617
{
16361618
std::ostringstream typedefbuf;
16371619
std::ostringstream callbuf;
1638-
for (int i = 0; i < indent_level; ++i) {
1639-
callbuf << kIndentString;
1640-
}
1620+
indent(callbuf, indent_level);
16411621
make_narg_ctor(FD, N, typedefbuf, callbuf, class_name, indent_level);
16421622
callbuf << ";\n";
1643-
for (int i = 0; i < indent_level; ++i) {
1644-
callbuf << kIndentString;
1645-
}
1623+
indent(callbuf, indent_level);
16461624
callbuf << "return;\n";
16471625
buf << typedefbuf.str() << callbuf.str();
16481626
}
16491627
--indent_level;
1650-
for (int i = 0; i < indent_level; ++i) {
1651-
buf << kIndentString;
1652-
}
1628+
indent(buf, indent_level);
16531629
buf << "}\n";
16541630
}
16551631

@@ -1686,21 +1662,15 @@ namespace Cpp {
16861662
if (QT->isVoidType()) {
16871663
std::ostringstream typedefbuf;
16881664
std::ostringstream callbuf;
1689-
for (int i = 0; i < indent_level; ++i) {
1690-
callbuf << kIndentString;
1691-
}
1665+
indent(callbuf, indent_level);
16921666
make_narg_call(FD, "void", N, typedefbuf, callbuf, class_name,
16931667
indent_level);
16941668
callbuf << ";\n";
1695-
for (int i = 0; i < indent_level; ++i) {
1696-
callbuf << kIndentString;
1697-
}
1669+
indent(callbuf, indent_level);
16981670
callbuf << "return;\n";
16991671
buf << typedefbuf.str() << callbuf.str();
17001672
} else {
1701-
for (int i = 0; i < indent_level; ++i) {
1702-
buf << kIndentString;
1703-
}
1673+
indent(buf, indent_level);
17041674

17051675
std::string type_name;
17061676
EReferenceType refType = kNotReference;
@@ -1714,9 +1684,7 @@ namespace Cpp {
17141684
//
17151685
// Write the placement part of the placement new.
17161686
//
1717-
for (int i = 0; i < indent_level; ++i) {
1718-
callbuf << kIndentString;
1719-
}
1687+
indent(callbuf, indent_level);
17201688
callbuf << "new (ret) ";
17211689
collect_type_info(FD, QT, typedefbuf, callbuf, type_name, refType,
17221690
isPointer, indent_level, false);
@@ -1742,45 +1710,33 @@ namespace Cpp {
17421710
// End the placement new.
17431711
//
17441712
callbuf << ");\n";
1745-
for (int i = 0; i < indent_level; ++i) {
1746-
callbuf << kIndentString;
1747-
}
1713+
indent(callbuf, indent_level);
17481714
callbuf << "return;\n";
17491715
//
17501716
// Output the whole placement new expression and return statement.
17511717
//
17521718
buf << typedefbuf.str() << callbuf.str();
17531719
}
17541720
--indent_level;
1755-
for (int i = 0; i < indent_level; ++i) {
1756-
buf << kIndentString;
1757-
}
1721+
indent(buf, indent_level);
17581722
buf << "}\n";
1759-
for (int i = 0; i < indent_level; ++i) {
1760-
buf << kIndentString;
1761-
}
1723+
indent(buf, indent_level);
17621724
buf << "else {\n";
17631725
++indent_level;
17641726
{
17651727
std::ostringstream typedefbuf;
17661728
std::ostringstream callbuf;
1767-
for (int i = 0; i < indent_level; ++i) {
1768-
callbuf << kIndentString;
1769-
}
1729+
indent(callbuf, indent_level);
17701730
callbuf << "(void)(";
17711731
make_narg_call(FD, type_name, N, typedefbuf, callbuf, class_name,
17721732
indent_level);
17731733
callbuf << ");\n";
1774-
for (int i = 0; i < indent_level; ++i) {
1775-
callbuf << kIndentString;
1776-
}
1734+
indent(callbuf, indent_level);
17771735
callbuf << "return;\n";
17781736
buf << typedefbuf.str() << callbuf.str();
17791737
}
17801738
--indent_level;
1781-
for (int i = 0; i < indent_level; ++i) {
1782-
buf << kIndentString;
1783-
}
1739+
indent(buf, indent_level);
17841740
buf << "}\n";
17851741
}
17861742
}
@@ -2199,16 +2155,12 @@ namespace Cpp {
21992155
// We need one function call clause compiled for every
22002156
// possible number of arguments per call.
22012157
for (unsigned N = min_args; N <= num_params; ++N) {
2202-
for (int i = 0; i < indent_level; ++i) {
2203-
buf << kIndentString;
2204-
}
2158+
indent(buf, indent_level);
22052159
buf << "if (nargs == " << N << ") {\n";
22062160
++indent_level;
22072161
make_narg_call_with_return(I, FD, N, class_name, buf, indent_level);
22082162
--indent_level;
2209-
for (int i = 0; i < indent_level; ++i) {
2210-
buf << kIndentString;
2211-
}
2163+
indent(buf, indent_level);
22122164
buf << "}\n";
22132165
}
22142166
}

0 commit comments

Comments
 (0)