Inlines any eligible functions that are found. Returns true if any changes are made.
1082 {
1083
1084 if (this->settings().fInlineThreshold <= 0) {
1085 return false;
1086 }
1087
1088
1089 if (fInlinedStatementCounter >= kInlinedStatementLimit) {
1090 return false;
1091 }
1092
1093 InlineCandidateList candidateList;
1094 this->buildCandidateList(elements,
symbols,
usage, &candidateList);
1095
1096
1098 std::unique_ptr<Statement>*>;
1099 StatementRemappingTable statementRemappingTable;
1100
1101 bool madeChanges = false;
1102 for (const InlineCandidate& candidate : candidateList.fCandidates) {
1103 const FunctionCall& funcCall = (*candidate.fCandidateExpr)->as<FunctionCall>();
1104
1105
1106 InlinedCall inlinedCall = this->inlineCall(funcCall, candidate.fSymbols, *
usage,
1107 &candidate.fEnclosingFunction->declaration());
1108
1109
1110 if (!inlinedCall.fInlinedBody && !inlinedCall.fReplacementExpr) {
1111 break;
1112 }
1113
1114
1115 this->ensureScopedBlocks(inlinedCall.fInlinedBody.get(), candidate.fParentStmt->get());
1116
1117
1118 usage->add(inlinedCall.fInlinedBody.get());
1119
1120
1121 std::unique_ptr<Statement>* enclosingStmt = candidate.fEnclosingStmt;
1122 for (;;) {
1123 std::unique_ptr<Statement>** remappedStmt = statementRemappingTable.
find(enclosingStmt);
1124 if (!remappedStmt) {
1125 break;
1126 }
1127 enclosingStmt = *remappedStmt;
1128 }
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138 inlinedCall.fInlinedBody->children().push_back(std::move(*enclosingStmt));
1139 *enclosingStmt = std::move(inlinedCall.fInlinedBody);
1140
1141
1142 usage->remove(candidate.fCandidateExpr->get());
1143 usage->add(inlinedCall.fReplacementExpr.get());
1144 *candidate.fCandidateExpr = std::move(inlinedCall.fReplacementExpr);
1145 madeChanges = true;
1146
1147
1148
1149 statementRemappingTable.set(enclosingStmt,&(*enclosingStmt)->as<
Block>().children().back());
1150
1151
1152 if (fInlinedStatementCounter >= kInlinedStatementLimit) {
1153 break;
1154 }
1155
1156
1157
1158 }
1159
1160 return madeChanges;
1161}
V * find(const K &key) const
static void usage(char *argv0)