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

Method getRandomExpression

bolt/expression/fuzzer/ExpressionFuzzer.cpp:1410–1436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1408}
1409
1410core::TypedExprPtr ExpressionFuzzer::ExprBank::getRandomExpression(
1411 const bytedance::bolt::TypePtr& returnType,
1412 int uptoLevelOfNesting) {
1413 BOLT_CHECK_LE(uptoLevelOfNesting, maxLevelOfNesting_);
1414 auto typeString = returnType->toString();
1415 if (typeToExprsByLevel_.find(typeString) == typeToExprsByLevel_.end()) {
1416 return nullptr;
1417 }
1418 auto& expressionsByLevel = typeToExprsByLevel_[typeString];
1419 int totalToConsider = 0;
1420 for (int i = 0; i <= uptoLevelOfNesting; i++) {
1421 totalToConsider += expressionsByLevel[i].size();
1422 }
1423 if (totalToConsider > 0) {
1424 int choice = boost::random::uniform_int_distribution<uint32_t>(
1425 0, totalToConsider - 1)(rng_);
1426 for (int i = 0; i <= uptoLevelOfNesting; i++) {
1427 if (choice >= expressionsByLevel[i].size()) {
1428 choice -= expressionsByLevel[i].size();
1429 continue;
1430 }
1431 return expressionsByLevel[i][choice];
1432 }
1433 BOLT_CHECK(false, "Should have found an expression.");
1434 }
1435 return nullptr;
1436}
1437
1438TypePtr ExpressionFuzzer::fuzzReturnType() {
1439 auto chooseFromConcreteSignatures = rand32(0, 1);

Callers 2

generateExpressionMethod · 0.80
TEST_FFunction · 0.80

Calls 4

toStringMethod · 0.45
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by 1

TEST_FFunction · 0.64