MCPcopy Create free account
hub / github.com/CMU-SAFARI/ramulator2 / _parse_default

Function _parse_default

python/ramulator/cpp_parser.py:277–304  ·  view source on GitHub ↗

Parse a C++ default value literal to a Python value.

(val_str, cpp_type)

Source from the content-addressed store, hash-verified

275
276
277def _parse_default(val_str, cpp_type):
278 """Parse a C++ default value literal to a Python value."""
279 val_str = val_str.strip()
280 # Remove suffixes
281 if val_str.endswith("ULL") or val_str.endswith("ull"):
282 val_str = val_str[:-3]
283 elif val_str.endswith("f") and cpp_type == "float":
284 val_str = val_str[:-1]
285 # Bool literal
286 if val_str in ("true", "false"):
287 return val_str == "true"
288 # String literal
289 if val_str.startswith('"') and val_str.endswith('"'):
290 return val_str[1:-1]
291 # std::vector<...>{...} brace-init literal — recognise the empty form
292 # and any comma-separated literal list of scalars.
293 if cpp_type.startswith("std::vector<") and "{" in val_str and val_str.endswith("}"):
294 inside = val_str[val_str.index("{") + 1:-1].strip()
295 if not inside:
296 return []
297 return [_parse_default(item, "") for item in inside.split(",")]
298 # Numeric
299 try:
300 if "." in val_str:
301 return float(val_str)
302 return int(val_str)
303 except ValueError:
304 return val_str

Callers 1

parse_paramsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected