From c8c98c76ea7cb1097d472e907622e7773b3378ab Mon Sep 17 00:00:00 2001 From: James Cherry Date: Wed, 5 Jul 2023 12:40:56 -0700 Subject: [PATCH] filter null checks Signed-off-by: James Cherry --- tcl/StaTcl.i | 86 ++++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/tcl/StaTcl.i b/tcl/StaTcl.i index d427f067..1415b96a 100644 --- a/tcl/StaTcl.i +++ b/tcl/StaTcl.i @@ -2495,21 +2495,23 @@ filter_ports(const char *property, const char *pattern, PortSeq *ports) { - Sta *sta = Sta::sta(); PortSeq filtered_ports; - bool exact_match = stringEq(op, "=="); - bool pattern_match = stringEq(op, "=~"); - bool not_match = stringEq(op, "!="); - for (const Port *port : *ports) { - PropertyValue value(getProperty(port, property, sta)); - const char *prop = value.stringValue(); - if (prop && - ((exact_match && stringEq(prop, pattern)) - || (not_match && !stringEq(prop, pattern)) - || (pattern_match && patternMatch(pattern, prop)))) - filtered_ports.push_back(port); + if (ports) { + Sta *sta = Sta::sta(); + bool exact_match = stringEq(op, "=="); + bool pattern_match = stringEq(op, "=~"); + bool not_match = stringEq(op, "!="); + for (const Port *port : *ports) { + PropertyValue value(getProperty(port, property, sta)); + const char *prop = value.stringValue(); + if (prop && + ((exact_match && stringEq(prop, pattern)) + || (not_match && !stringEq(prop, pattern)) + || (pattern_match && patternMatch(pattern, prop)))) + filtered_ports.push_back(port); + } + delete ports; } - delete ports; return filtered_ports; } @@ -2519,22 +2521,24 @@ filter_insts(const char *property, const char *pattern, InstanceSeq *insts) { - Sta *sta = Sta::sta(); - cmdLinkedNetwork(); - bool exact_match = stringEq(op, "=="); - bool pattern_match = stringEq(op, "=~"); - bool not_match = stringEq(op, "!="); InstanceSeq filtered_insts; - for (const Instance *inst : *insts) { - PropertyValue value(getProperty(inst, property, sta)); - const char *prop = value.stringValue(); - if (prop && - ((exact_match && stringEq(prop, pattern)) - || (not_match && !stringEq(prop, pattern)) - || (pattern_match && patternMatch(pattern, prop)))) - filtered_insts.push_back(inst); + if (insts) { + Sta *sta = Sta::sta(); + cmdLinkedNetwork(); + bool exact_match = stringEq(op, "=="); + bool pattern_match = stringEq(op, "=~"); + bool not_match = stringEq(op, "!="); + for (const Instance *inst : *insts) { + PropertyValue value(getProperty(inst, property, sta)); + const char *prop = value.stringValue(); + if (prop && + ((exact_match && stringEq(prop, pattern)) + || (not_match && !stringEq(prop, pattern)) + || (pattern_match && patternMatch(pattern, prop)))) + filtered_insts.push_back(inst); + } + delete insts; } - delete insts; return filtered_insts; } @@ -2544,21 +2548,23 @@ filter_pins(const char *property, const char *pattern, PinSeq *pins) { - Sta *sta = Sta::sta(); PinSeq filtered_pins; - bool exact_match = stringEq(op, "=="); - bool pattern_match = stringEq(op, "=~"); - bool not_match = stringEq(op, "!="); - for (const Pin *pin : *pins) { - PropertyValue value(getProperty(pin, property, sta)); - const char *prop = value.stringValue(); - if (prop && - ((exact_match && stringEq(prop, pattern)) - || (not_match && !stringEq(prop, pattern)) - || (pattern_match && patternMatch(pattern, prop)))) - filtered_pins.push_back(pin); + if (pins) { + Sta *sta = Sta::sta(); + bool exact_match = stringEq(op, "=="); + bool pattern_match = stringEq(op, "=~"); + bool not_match = stringEq(op, "!="); + for (const Pin *pin : *pins) { + PropertyValue value(getProperty(pin, property, sta)); + const char *prop = value.stringValue(); + if (prop && + ((exact_match && stringEq(prop, pattern)) + || (not_match && !stringEq(prop, pattern)) + || (pattern_match && patternMatch(pattern, prop)))) + filtered_pins.push_back(pin); + } + delete pins; } - delete pins; return filtered_pins; }