MCPcopy Create free account
hub / github.com/bytedance/bolt / chooseRandomSignatureTemplate

Method chooseRandomSignatureTemplate

bolt/expression/fuzzer/ExpressionFuzzer.cpp:1237–1267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1235}
1236
1237const SignatureTemplate* ExpressionFuzzer::chooseRandomSignatureTemplate(
1238 const TypePtr& returnType,
1239 const std::string& typeName,
1240 const std::string& functionName) {
1241 std::vector<const SignatureTemplate*> eligible;
1242 if (expressionToTemplatedSignature_.find(functionName) ==
1243 expressionToTemplatedSignature_.end()) {
1244 return nullptr;
1245 }
1246 auto it = expressionToTemplatedSignature_[functionName].find(typeName);
1247 if (it == expressionToTemplatedSignature_[functionName].end()) {
1248 return nullptr;
1249 }
1250 // Only function signatures whose return type can match returnType are
1251 // eligible. There may be ineligible signatures in signaturesMap_ because
1252 // the map keys only differentiate the top-level type names.
1253 auto& signatureTemplates = it->second;
1254 for (auto signatureTemplate : signatureTemplates) {
1255 exec::ReverseSignatureBinder binder{
1256 *signatureTemplate->signature, returnType};
1257 if (binder.tryBind()) {
1258 eligible.push_back(signatureTemplate);
1259 }
1260 }
1261 if (eligible.empty()) {
1262 return nullptr;
1263 }
1264
1265 auto idx = rand32(0, eligible.size() - 1);
1266 return eligible[idx];
1267}
1268
1269const SignatureTemplate* ExpressionFuzzer::findSignatureTemplate(
1270 const std::vector<TypePtr>& argTypes,

Callers

nothing calls this directly

Calls 6

findMethod · 0.45
endMethod · 0.45
tryBindMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected