From 8ba75fdb9c093ae2d4b9efc6a44ccbe231bdf963 Mon Sep 17 00:00:00 2001 From: James Cherry Date: Thu, 24 Apr 2025 11:09:30 -0700 Subject: [PATCH] Property::to_string Signed-off-by: James Cherry --- include/sta/Property.hh | 2 +- sdc/Sdc.i | 13 +++++++------ search/Property.cc | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/sta/Property.hh b/include/sta/Property.hh index cd8eb1e5..047e3d1f 100644 --- a/include/sta/Property.hh +++ b/include/sta/Property.hh @@ -85,7 +85,7 @@ public: Type type() const { return type_; } const Unit *unit() const { return unit_; } - const char *asString(const Network *network) const; + std::string to_string(const Network *network) const; const char *stringValue() const; // valid for type string float floatValue() const; // valid for type float bool boolValue() const; // valid for type bool diff --git a/sdc/Sdc.i b/sdc/Sdc.i index 81d94240..8eabec89 100644 --- a/sdc/Sdc.i +++ b/sdc/Sdc.i @@ -1227,12 +1227,13 @@ filter_objects(const char *property, bool not_pattern_match = stringEq(op, "!~"); for (T *object : *objects) { PropertyValue value(getProperty(object, property, sta)); - const char *prop = value.asString(sta->network()); - if (prop && - ((exact_match && stringEq(prop, pattern)) - || (not_match && !stringEq(prop, pattern)) - || (pattern_match && patternMatch(pattern, prop)) - || (not_pattern_match && !patternMatch(pattern, prop)))) + string prop_str = value.to_string(sta->network()); + const char *prop = prop_str.c_str(); + if (!prop_str.empty() + && ((exact_match && stringEq(prop, pattern)) + || (not_match && !stringEq(prop, pattern)) + || (pattern_match && patternMatch(pattern, prop)) + || (not_pattern_match && !patternMatch(pattern, prop)))) filtered_objects.push_back(object); } delete objects; diff --git a/search/Property.cc b/search/Property.cc index 9c3f598a..85c3978f 100644 --- a/search/Property.cc +++ b/search/Property.cc @@ -613,8 +613,8 @@ PropertyValue::operator=(PropertyValue &&value) return *this; } -const char * -PropertyValue::asString(const Network *network) const +string +PropertyValue::to_string(const Network *network) const { switch (type_) { case Type::type_string: @@ -652,9 +652,9 @@ PropertyValue::asString(const Network *network) const case Type::type_clks: case Type::type_paths: case Type::type_pwr_activity: - return nullptr; + return ""; } - return nullptr; + return ""; } const char *