verilated_random: drop peek in get-value parse for a single paren-depth scan
This commit is contained in:
parent
c149856155
commit
ccca5273a4
|
|
@ -1097,50 +1097,42 @@ bool VlRandomizer::nextPhased(VlRNG& rngr) {
|
||||||
};
|
};
|
||||||
|
|
||||||
auto parseGetValue = [&]() -> bool {
|
auto parseGetValue = [&]() -> bool {
|
||||||
|
// Parse ((name value) ...): one paren-depth counter drives every match.
|
||||||
char c;
|
char c;
|
||||||
// Read a balanced parenthesised group, opening '(' already read.
|
|
||||||
auto readGroup = [&](std::string& out) {
|
|
||||||
out = "(";
|
|
||||||
int depth = 1;
|
|
||||||
char gc;
|
|
||||||
while (depth > 0 && os.get(gc)) {
|
|
||||||
out += gc;
|
|
||||||
if (gc == '(') {
|
|
||||||
++depth;
|
|
||||||
} else if (gc == ')') {
|
|
||||||
--depth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
os >> c; // outer '('
|
os >> c; // outer '('
|
||||||
while (true) {
|
if (c != '(') return false;
|
||||||
os >> c;
|
int depth = 1;
|
||||||
if (c == ')') break;
|
std::string tokens[2];
|
||||||
if (c != '(') return false;
|
std::string cur;
|
||||||
|
int fields = 0;
|
||||||
// LHS: the queried term echoed back, a name or (select ...) group.
|
auto flush = [&]() {
|
||||||
os >> std::ws;
|
if (cur.empty()) return;
|
||||||
std::string name;
|
if (fields < 2) tokens[fields] = cur;
|
||||||
if (os.peek() == '(') {
|
++fields;
|
||||||
os.get(c);
|
cur.clear();
|
||||||
readGroup(name);
|
};
|
||||||
|
while (depth > 0 && os.get(c)) {
|
||||||
|
if (c == '(') {
|
||||||
|
++depth;
|
||||||
|
if (depth >= 3) cur += c;
|
||||||
|
} else if (c == ')') {
|
||||||
|
--depth;
|
||||||
|
if (depth >= 2) {
|
||||||
|
cur += c;
|
||||||
|
} else if (depth == 1) {
|
||||||
|
flush();
|
||||||
|
if (fields == 2) solvedValues[tokens[0]] = tokens[1];
|
||||||
|
fields = 0;
|
||||||
|
}
|
||||||
|
} else if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
|
||||||
|
if (depth >= 3) {
|
||||||
|
cur += c;
|
||||||
|
} else {
|
||||||
|
flush();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
os >> name;
|
cur += c;
|
||||||
}
|
}
|
||||||
|
|
||||||
os >> std::ws;
|
|
||||||
std::string value;
|
|
||||||
if (os.peek() == '(') {
|
|
||||||
os.get(c);
|
|
||||||
readGroup(value);
|
|
||||||
os >> c; // pair-closing ')'
|
|
||||||
} else {
|
|
||||||
while (os.get(c) && c != ')') { value += c; }
|
|
||||||
const size_t end = value.find_last_not_of(" \t\n\r");
|
|
||||||
if (end != std::string::npos) value = value.substr(0, end + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
solvedValues[name] = value;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue