MCPcopy Create free account
hub / github.com/csmith-project/csmith / build_init_recursive

Method build_init_recursive

src/ArrayVariable.cpp:458–477  ·  view source on GitHub ↗

print the initializer recursively for multi-dimension arrays this is based on John's idea

Source from the content-addressed store, hash-verified

456// print the initializer recursively for multi-dimension arrays
457// this is based on John's idea
458string
459ArrayVariable::build_init_recursive(size_t dimen, const vector<string>& init_strings) const
460{
461 assert (dimen < get_dimension());
462 static unsigned seed = 0xABCDEF;
463 string ret = "{";
464 for (size_t i=0; i<sizes[dimen]; i++) {
465 if (dimen == sizes.size() - 1) {
466 // use magic number to choose an initial value
467 size_t rnd_index = ((seed * seed + (i+7) * (i+13)) * 52369) % (init_strings.size());
468 ret += init_strings[rnd_index];
469 seed++;
470 } else {
471 ret += build_init_recursive(dimen + 1, init_strings);
472 }
473 if (i != sizes[dimen]-1) ret += ",";
474 }
475 ret += "}";
476 return ret;
477}
478
479// build the string initializer in form of "{...}"
480string

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected