Add templated As() method to Val, use in various places we were using dynamic_cast

This commit is contained in:
Tim Wojtulewicz 2020-12-03 14:25:18 -07:00
parent a7b5915b1a
commit a94fcad957
7 changed files with 28 additions and 14 deletions

View file

@ -1853,7 +1853,7 @@ ValPtr EqExpr::Fold(Val* v1, Val* v2) const
{
if ( op1->GetType()->Tag() == TYPE_PATTERN )
{
auto re = dynamic_cast<PatternVal*>(v1);
auto re = v1->As<PatternVal*>();
const String* s = v2->AsString();
if ( tag == EXPR_EQ )
return val_mgr->Bool(re->MatchExactly(s));
@ -4151,7 +4151,7 @@ ValPtr InExpr::Fold(Val* v1, Val* v2) const
{
if ( v1->GetType()->Tag() == TYPE_PATTERN )
{
auto re = dynamic_cast<PatternVal*>(v1);
auto re = v1->As<PatternVal*>();
const String* s = v2->AsString();
return val_mgr->Bool(re->MatchAnywhere(s) != 0);
}