@@ -73,9 +73,9 @@ class FilterExpr
7373 FilterExpr (std::string_view expression,
7474 Report *report);
7575
76- std::vector<std::unique_ptr<Token>> postfix (bool bool_props_as_int );
76+ std::vector<std::unique_ptr<Token>> postfix ();
7777private:
78- std::vector<std::unique_ptr<Token>> lex (bool bool_props_as_int );
78+ std::vector<std::unique_ptr<Token>> lex ();
7979 std::vector<std::unique_ptr<Token>> shuntingYard (std::vector<std::unique_ptr<Token>> &infix);
8080
8181 std::string raw_;
@@ -106,20 +106,21 @@ FilterExpr::FilterExpr(std::string_view expression,
106106}
107107
108108std::vector<std::unique_ptr<FilterExpr::Token>>
109- FilterExpr::postfix (bool bool_props_as_int )
109+ FilterExpr::postfix ()
110110{
111- auto infix = lex (bool_props_as_int );
111+ auto infix = lex ();
112112 return shuntingYard (infix);
113113}
114114
115115std::vector<std::unique_ptr<FilterExpr::Token>>
116- FilterExpr::lex (bool bool_props_as_int )
116+ FilterExpr::lex ()
117117{
118118 std::vector<std::pair<std::regex, Token::Kind>> token_regexes = {
119119 {std::regex (" ^\\ s+" ), Token::Kind::skip},
120120 {std::regex (" ^defined\\ (([a-zA-Z_]+)\\ )" ), Token::Kind::defined },
121121 {std::regex (" ^undefined\\ (([a-zA-Z_]+)\\ )" ), Token::Kind::undefined},
122- {std::regex (" ^@?([a-zA-Z_]+) *((==|!=|=~|!~) *([0-9a-zA-Z_\\ /$\\ [\\ ]*?]+))?" ), Token::Kind::predicate},
122+ {std::regex (" ^@?([a-zA-Z_]+) *((==|!=|=~|!~) *([0-9a-zA-Z_\\ /$\\ [\\ ]*?.]+))?" ),
123+ Token::Kind::predicate},
123124 {std::regex (" ^(&&)" ), Token::Kind::op_and},
124125 {std::regex (" ^(\\ |\\ |)" ), Token::Kind::op_or},
125126 {std::regex (" ^(!)" ), Token::Kind::op_inv},
@@ -139,9 +140,9 @@ FilterExpr::lex(bool bool_props_as_int)
139140 std::string property = token_match[1 ].str ();
140141
141142 // The default operation on a predicate if an op and arg are
142- // omitted is 'arg == 1' / 'arg == true'.
143+ // omitted is 'prop == 1 || true'.
143144 std::string op = " ==" ;
144- std::string arg = (bool_props_as_int ? " 1" : " true " ) ;
145+ std::string arg = " 1" ;
145146
146147 if (token_match[2 ].length () != 0 ) {
147148 op = token_match[3 ].str ();
@@ -250,13 +251,18 @@ filterObjects(const char *property,
250251 bool not_pattern_match = stringEq (op, " !~" );
251252 for (T *object : all) {
252253 PropertyValue value = properties.getProperty (object, property);
253- std::string prop_str = value.to_string (network);
254- const char *prop = prop_str.c_str ();
255- if (prop &&
256- ((exact_match && stringEq (prop, pattern))
257- || (not_match && !stringEq (prop, pattern))
258- || (pattern_match && patternMatch (pattern, prop))
259- || (not_pattern_match && !patternMatch (pattern, prop))))
254+ std::string prop = value.to_string (network);
255+ if (value.type () == PropertyValue::Type::bool_) {
256+ // Canonicalize bool true/false to 1/0.
257+ if (stringEqual (pattern, " true" ))
258+ pattern = " 1" ;
259+ else if (stringEqual (pattern, " false" ))
260+ pattern = " 0" ;
261+ }
262+ if ((exact_match && stringEq (prop.c_str (), pattern))
263+ || (not_match && !stringEq (prop.c_str (), pattern))
264+ || (pattern_match && patternMatch (pattern, prop))
265+ || (not_pattern_match && !patternMatch (pattern, prop)))
260266 filtered_objects.insert (object);
261267 }
262268 return filtered_objects;
@@ -265,7 +271,6 @@ filterObjects(const char *property,
265271template <typename T> std::vector<T*>
266272filterObjects (std::string_view filter_expression,
267273 std::vector<T*> *objects,
268- bool bool_props_as_int,
269274 Sta *sta)
270275{
271276 Report *report = sta->report ();
@@ -278,7 +283,7 @@ filterObjects(std::string_view filter_expression,
278283 all.insert (object);
279284
280285 FilterExpr filter (filter_expression, report);
281- auto postfix = filter.postfix (bool_props_as_int );
286+ auto postfix = filter.postfix ();
282287 std::stack<std::set<T*>> eval_stack;
283288 for (auto &token : postfix) {
284289 if (token->kind == FilterExpr::Token::Kind::op_or) {
@@ -405,100 +410,89 @@ filterObjects(std::string_view filter_expression,
405410PortSeq
406411filterPorts (std::string_view filter_expression,
407412 PortSeq *objects,
408- bool bool_props_as_int,
409413 Sta *sta)
410414{
411- return filterObjects<const Port>(filter_expression, objects, bool_props_as_int, sta);
415+ return filterObjects<const Port>(filter_expression, objects, sta);
412416}
413417
414418InstanceSeq
415419filterInstances (std::string_view filter_expression,
416420 InstanceSeq *objects,
417- bool bool_props_as_int,
418421 Sta *sta)
419422{
420- return filterObjects<const Instance>(filter_expression, objects, bool_props_as_int, sta);
423+ return filterObjects<const Instance>(filter_expression, objects, sta);
421424}
422425
423426PinSeq
424427filterPins (std::string_view filter_expression,
425428 PinSeq *objects,
426- bool bool_props_as_int,
427429 Sta *sta)
428430{
429- return filterObjects<const Pin>(filter_expression, objects, bool_props_as_int, sta);
431+ return filterObjects<const Pin>(filter_expression, objects, sta);
430432}
431433
432434NetSeq
433435filterNets (std::string_view filter_expression,
434436 NetSeq *objects,
435- bool bool_props_as_int,
436437 Sta *sta)
437438{
438- return filterObjects<const Net>(filter_expression, objects, bool_props_as_int, sta);
439+ return filterObjects<const Net>(filter_expression, objects, sta);
439440}
440441
441442ClockSeq
442443filterClocks (std::string_view filter_expression,
443444 ClockSeq *objects,
444- bool bool_props_as_int,
445445 Sta *sta)
446446{
447- return filterObjects<Clock>(filter_expression, objects, bool_props_as_int, sta);
447+ return filterObjects<Clock>(filter_expression, objects, sta);
448448}
449449
450450LibertyCellSeq
451451filterLibCells (std::string_view filter_expression,
452452 LibertyCellSeq *objects,
453- bool bool_props_as_int,
454453 Sta *sta)
455454{
456- return filterObjects<LibertyCell>(filter_expression, objects, bool_props_as_int, sta);
455+ return filterObjects<LibertyCell>(filter_expression, objects, sta);
457456}
458457
459458LibertyPortSeq
460459filterLibPins (std::string_view filter_expression,
461460 LibertyPortSeq *objects,
462- bool bool_props_as_int,
463461 Sta *sta)
464462{
465- return filterObjects<LibertyPort>(filter_expression, objects, bool_props_as_int, sta);
463+ return filterObjects<LibertyPort>(filter_expression, objects, sta);
466464}
467465
468466LibertyLibrarySeq
469467filterLibertyLibraries (std::string_view filter_expression,
470468 LibertyLibrarySeq *objects,
471- bool bool_props_as_int,
472469 Sta *sta)
473470{
474- return filterObjects<LibertyLibrary>(filter_expression, objects, bool_props_as_int, sta);
471+ return filterObjects<LibertyLibrary>(filter_expression, objects, sta);
475472}
476473
477474EdgeSeq
478475filterTimingArcs (std::string_view filter_expression,
479476 EdgeSeq *objects,
480- bool bool_props_as_int,
481477 Sta *sta)
482478{
483- return filterObjects<Edge>(filter_expression, objects, bool_props_as_int, sta);
479+ return filterObjects<Edge>(filter_expression, objects, sta);
484480}
485481
486482PathEndSeq
487483filterPathEnds (std::string_view filter_expression,
488484 PathEndSeq *objects,
489- bool bool_props_as_int,
490485 Sta *sta)
491486{
492- return filterObjects<PathEnd>(filter_expression, objects, bool_props_as_int, sta);
487+ return filterObjects<PathEnd>(filter_expression, objects, sta);
493488}
494489
495490StringSeq
496491filterExprToPostfix (std::string_view expr,
497- bool bool_props_as_int,
498492 Report *report)
499493{
500494 FilterExpr filter (expr, report);
501- auto postfix = filter.postfix (bool_props_as_int );
495+ auto postfix = filter.postfix ();
502496 StringSeq result;
503497 for (auto &token : postfix)
504498 result.push_back (token->text );
0 commit comments