IL5XPFSWQX3OWZHEUSDP3R2IKVWHHOI6MNNBKU3P6MNBT6MVYJ2QC
const vector<clause_t> &decode_clauses(const cFunctionData *restrict attribute,
int n_clauses, const char **clauses) {
// We assume that each `clauses` pointer is unique
static unordered_map<const char **, vector<clause_t> > memoized_results;
auto result_it = memoized_results.find(clauses);
if (result_it != memoized_results.end())
return result_it->second;
vector<clause_t> decode_clauses(const cFunctionData *restrict attribute,
const rdwr_t rdwr) {
for (int n = 0; n < n_clauses; ++n) {
for (const char *restrict p = clauses[n]; *p;) {
// Find beginning of word
while (isspace(*p))
++p;
if (!*p)
break;
// Read grid function / group name
assert(isalnum(*p) || *p == '_' || *p == ':');
const char *const name0 = p;
while (isalnum(*p) || *p == '_' || *p == ':')
++p;
string name(name0, p);
for (int n = 0; n < attribute->n_RDWR; ++n) {
const RDWR_entry &restrict RDWR = attribute->RDWR[n];
int gi = CCTK_GroupIndexFromVarI(RDWR.var_id);
assert(gi >= 0);
int vi = RDWR.var_id - CCTK_FirstVarIndexI(gi);
assert(vi >= 0 && vi < CCTK_NumVarsInGroupI(gi));
int tl = RDWR.time_level;
int where = rdwr == rdwr_t::read ? RDWR.where_rd : RDWR.where_wr;
assert(*p == ')');
++p;
} else {
assert(0); // missing region
valid.valid_int = valid.valid_bnd = true;
}
assert(!*p || isspace(*p));
int tl = 0;
while (name.size() >= 2 && name.substr(name.size() - 2) == "_p") {
name = name.substr(0, name.size() - 2);
++tl;
} else {
const int var = CCTK_VarIndex(name.c_str());
if (var >= 0) {
const int gi = CCTK_GroupIndexFromVarI(var);
const int v0 = CCTK_FirstVarIndexI(gi);
const int vi = var - v0;
result.push_back({gi, vi, tl, valid});
} else {
CCTK_VERROR("Cannot decode group/variable name \"%s\" in %s: %s::%s",
name.c_str(), attribute->where, attribute->thorn,
attribute->routine);
}
}