Ignore:
Timestamp:
Apr 15, 2024, 12:03:53 PM (4 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
dc58e5d
Parents:
d9bad51
Message:

Reimplement the resolution of Enum instance type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    rd9bad51 raf746cc  
    274274                void previsit( const ast::Node * ) { visit_children = false; }
    275275
    276                 void postvisit( const ast::VoidType * ) {
    277                         result = dynamic_cast< const ast::VoidType * >( type2 );
     276                void postvisit( const ast::VoidType * vt) {
     277                        result = dynamic_cast< const ast::VoidType * >( type2 )
     278                                || tryToUnifyWithEnumValue(vt, type2, tenv, need, have, open, noWiden());
     279                        ;
    278280                }
    279281
     
    282284                                result = basic->kind == basic2->kind;
    283285                        }
     286                        result = result || tryToUnifyWithEnumValue(basic, type2, tenv, need, have, open, noWiden());
    284287                }
    285288
     
    290293                                        noWiden());
    291294                        }
     295                        result = result || tryToUnifyWithEnumValue(pointer, type2, tenv, need, have, open, noWiden());
    292296                }
    293297
     
    307311
    308312                        result = unifyExact(
    309                                 array->base, array2->base, tenv, need, have, open, noWiden());
     313                                array->base, array2->base, tenv, need, have, open, noWiden())
     314                                || tryToUnifyWithEnumValue(array, type2, tenv, need, have, open, noWiden());
    310315                }
    311316
     
    399404                }
    400405
     406                bool tryToUnifyWithEnumValue( const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
     407                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
     408                        WidenMode widen) {
     409                        if ( auto attrType2 = dynamic_cast<const ast::EnumAttrType *>(type2)) {
     410                                if (attrType2->attr == ast::EnumAttribute::Value) {
     411                                        return unifyExact( type1, attrType2->instance->base->base, env, need, have, open,
     412                                                widen);
     413                                } else if (attrType2->attr == ast::EnumAttribute::Posn) {
     414                                        return unifyExact( type1, attrType2->instance, env, need, have, open, widen );
     415                                }
     416                        }
     417                        return false;
     418                }
     419
    401420        public:
    402421                void postvisit( const ast::FunctionType * func ) {
     
    507526                void postvisit( const ast::StructInstType * aggrType ) {
    508527                        handleGenericRefType( aggrType, type2 );
     528                        result = result || tryToUnifyWithEnumValue(aggrType, type2, tenv, need, have, open, noWiden());
    509529                }
    510530
    511531                void postvisit( const ast::UnionInstType * aggrType ) {
    512532                        handleGenericRefType( aggrType, type2 );
     533                        result = result || tryToUnifyWithEnumValue(aggrType, type2, tenv, need, have, open, noWiden());
    513534                }
    514535
    515536                void postvisit( const ast::EnumInstType * aggrType ) {
    516537                        handleRefType( aggrType, type2 );
    517                 }
    518 
    519                 void postvisit( const ast::EnumPosType * posType ) {
     538                        result = result || tryToUnifyWithEnumValue(aggrType, type2, tenv, need, have, open, noWiden());
     539                }
     540
     541                void postvisit( const ast::EnumAttrType * enumAttr ) {
    520542                        // Lazy approach for now
    521                         auto otherPos = dynamic_cast< const ast::EnumPosType *>(type2);
    522                         if ( otherPos ) {
    523                                 if ( otherPos->instance->base->name == posType->instance->base->name )
    524                                         result = otherPos;
    525                         }
     543                        if ( auto otherPos = dynamic_cast< const ast::EnumAttrType *>(type2) ) {
     544                            if ( enumAttr->match(otherPos) ) {
     545                                    result = otherPos;
     546                            }
     547            } 
    526548                }
    527549
    528550                void postvisit( const ast::TraitInstType * aggrType ) {
    529551                        handleRefType( aggrType, type2 );
     552                        result = result || tryToUnifyWithEnumValue(aggrType, type2, tenv, need, have, open, noWiden());
    530553                }
    531554
     
    536559                                this->result = otherInst;
    537560                        }
     561                        result = result || tryToUnifyWithEnumValue(typeInst, type2, tenv, need, have, open, noWiden());
    538562                }
    539563
     
    610634                        auto types2 = flatten( flat2 );
    611635
    612                         result = unifyList( types, types2, tenv, need, have, open );
    613                 }
    614 
    615                 void postvisit( const ast::VarArgsType * ) {
    616                         result = dynamic_cast< const ast::VarArgsType * >( type2 );
    617                 }
    618 
    619                 void postvisit( const ast::ZeroType * ) {
    620                         result = dynamic_cast< const ast::ZeroType * >( type2 );
    621                 }
    622 
    623                 void postvisit( const ast::OneType * ) {
    624                         result = dynamic_cast< const ast::OneType * >( type2 );
     636                        result = unifyList( types, types2, tenv, need, have, open )
     637                                || tryToUnifyWithEnumValue(tuple, type2, tenv, need, have, open, noWiden());
     638                }
     639
     640                void postvisit( const ast::VarArgsType * vat) {
     641                        result = dynamic_cast< const ast::VarArgsType * >( type2 )
     642                                || tryToUnifyWithEnumValue(vat, type2, tenv, need, have, open, noWiden());
     643                }
     644
     645                void postvisit( const ast::ZeroType * zt) {
     646                        result = dynamic_cast< const ast::ZeroType * >( type2 )
     647                                || tryToUnifyWithEnumValue(zt, type2, tenv, need, have, open, noWiden());
     648                }
     649
     650                void postvisit( const ast::OneType * ot) {
     651                        result = dynamic_cast< const ast::OneType * >( type2 )
     652                                || tryToUnifyWithEnumValue(ot, type2, tenv, need, have, open, noWiden());
    625653                }
    626654        };
Note: See TracChangeset for help on using the changeset viewer.