Ignore:
Timestamp:
Jun 12, 2023, 12:05:58 PM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
fec8bd1
Parents:
2b78949 (diff), 38e266ca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CommonType.cc

    r2b78949 r8a930c03  
    2121
    2222#include "AST/Decl.hpp"
     23#include "AST/Pass.hpp"
    2324#include "AST/Type.hpp"
    2425#include "Common/PassVisitor.h"
     
    675676                const ast::Type * type2;
    676677                WidenMode widen;
    677                 const ast::SymbolTable & symtab;
    678678                ast::TypeEnvironment & tenv;
    679679                const ast::OpenVarSet & open;
     
    685685
    686686                CommonType_new(
    687                         const ast::Type * t2, WidenMode w, const ast::SymbolTable & st,
     687                        const ast::Type * t2, WidenMode w,
    688688                        ast::TypeEnvironment & env, const ast::OpenVarSet & o,
    689689                        ast::AssertionSet & need, ast::AssertionSet & have )
    690                 : type2( t2 ), widen( w ), symtab( st ), tenv( env ), open( o ), need (need), have (have) ,result() {}
     690                : type2( t2 ), widen( w ), tenv( env ), open( o ), need (need), have (have) ,result() {}
    691691
    692692                void previsit( const ast::Node * ) { visit_children = false; }
     
    748748                                        ast::AssertionSet need, have;
    749749                                        if ( ! tenv.bindVar(
    750                                                 var, voidPtr->base, entry->second, need, have, open, widen, symtab )
     750                                                var, voidPtr->base, entry->second, need, have, open, widen )
    751751                                        ) return;
    752752                                }
     
    761761                                ast::OpenVarSet newOpen{ open };
    762762                                if (enumInst->base->base
    763                                 && unifyExact(type1, enumInst->base->base, tenv, need, have, newOpen, widen, symtab)) {
     763                                && unifyExact(type1, enumInst->base->base, tenv, need, have, newOpen, widen)) {
    764764                                        result = type1;
    765765                                        return true;
     
    798798
    799799                                        ast::OpenVarSet newOpen{ open };
    800                                         if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) {
     800                                        if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() ) ) {
    801801                                                result = pointer;
    802802                                                if ( q1.val != q2.val ) {
     
    841841                                                                if (unifyExact(
    842842                                                                        arg1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open,
    843                                                                         noWiden(), symtab )) {
     843                                                                        noWiden() )) {
    844844                                                                                break;
    845845
     
    850850                                                                if (unifyExact(
    851851                                                                        tupleFromTypes( crnt1, end1 ), arg2, tenv, need, have, open,
    852                                                                         noWiden(), symtab )) {
     852                                                                        noWiden() )) {
    853853                                                                                break;
    854854
     
    874874
    875875                                                                                if ( ! unifyExact(
    876                                                                                         base1, base2, tenv, need, have, open, noWiden(), symtab )
     876                                                                                        base1, base2, tenv, need, have, open, noWiden() )
    877877                                                                                ) return;
    878878                                                                        }       
     
    894894
    895895                                                                                if ( ! unifyExact(
    896                                                                                         base1, base2, tenv, need, have, open, noWiden(), symtab )
     896                                                                                        base1, base2, tenv, need, have, open, noWiden() )
    897897                                                                                ) return;
    898898                                                                        }       
     
    902902                                                        }
    903903                                                        else if (! unifyExact(
    904                                                                 arg1, arg2, tenv, need, have, open, noWiden(), symtab )) return;
     904                                                                arg1, arg2, tenv, need, have, open, noWiden() )) return;
    905905
    906906                                                        ++crnt1; ++crnt2;
     
    912912                                                        if (! unifyExact(
    913913                                                                t1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open,
    914                                                                 noWiden(), symtab )) return;
     914                                                                noWiden() )) return;
    915915                                                } else if ( crnt2 != end2 ) {
    916916                                                        // try unifying empty tuple with ttype
     
    919919                                                        if (! unifyExact(
    920920                                                                tupleFromTypes( crnt1, end1 ), t2, tenv, need, have, open,
    921                                                                 noWiden(), symtab )) return;
     921                                                                noWiden() )) return;
    922922                                                }
    923923                                                if ((f1->returns.size() == 0 && f2->returns.size() == 0)
    924                                                   || (f1->returns.size() == 1 && f2->returns.size() == 1 && unifyExact(f1->returns[0], f2->returns[0], tenv, need, have, open, noWiden(), symtab))) {
     924                                                  || (f1->returns.size() == 1 && f2->returns.size() == 1 && unifyExact(f1->returns[0], f2->returns[0], tenv, need, have, open, noWiden()))) {
    925925                                                        result = pointer;
    926926
     
    979979
    980980                                        ast::OpenVarSet newOpen{ open };
    981                                         if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) {
     981                                        if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() ) ) {
    982982                                                result = ref;
    983983                                                if ( q1.val != q2.val ) {
     
    994994                        } else {
    995995                                if (!dynamic_cast<const ast::EnumInstType *>(type2))
    996                                         result = commonType( type2, ref, tenv, need, have, open, widen, symtab );
     996                                        result = commonType( type2, ref, tenv, need, have, open, widen );
    997997                        }
    998998                }
     
    10121012                void postvisit( const ast::EnumInstType * enumInst ) {
    10131013                        if (!dynamic_cast<const ast::EnumInstType *>(type2))
    1014                                 result = commonType( type2, enumInst, tenv, need, have, open, widen, symtab);
     1014                                result = commonType( type2, enumInst, tenv, need, have, open, widen);
    10151015                }
    10161016
    10171017                void postvisit( const ast::TraitInstType * ) {}
    10181018
    1019                 void postvisit( const ast::TypeInstType * inst ) {
    1020                         if ( ! widen.first ) return;
    1021                         if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) {
    1022                                 if ( const ast::Type * base =
    1023                                                 strict_dynamic_cast< const ast::TypeDecl * >( nt )->base
    1024                                 ) {
    1025                                         ast::CV::Qualifiers q1 = inst->qualifiers, q2 = type2->qualifiers;
    1026 
    1027                                         // force t{1,2} to be cloned if their qualifiers must be mutated
    1028                                         ast::ptr< ast::Type > t1{ base }, t2{ type2 };
    1029                                         reset_qualifiers( t1, q1 );
    1030                                         reset_qualifiers( t2 );
    1031 
    1032                                         ast::OpenVarSet newOpen{ open };
    1033                                         if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) {
    1034                                                 result = type2;
    1035                                                 reset_qualifiers( result, q1 | q2 );
    1036                                         } else {
    1037                                                 tryResolveWithTypedEnum( t1 );
    1038                                         }
    1039                                 }
    1040                         }
    1041                 }
    1042 
    1043                 void postvisit( const ast::TupleType * tuple) {
     1019                void postvisit( const ast::TypeInstType * ) {}
     1020
     1021                void postvisit( const ast::TupleType * tuple ) {
    10441022                        tryResolveWithTypedEnum( tuple );
    10451023                }
     
    11021080                ast::ptr< ast::Type > handleReference(
    11031081                        const ast::ptr< ast::Type > & t1, const ast::ptr< ast::Type > & t2, WidenMode widen,
    1104                         const ast::SymbolTable & symtab, ast::TypeEnvironment & env,
     1082                        ast::TypeEnvironment & env,
    11051083                        const ast::OpenVarSet & open
    11061084                ) {
     
    11101088
    11111089                        // need unify to bind type variables
    1112                         if ( unify( t1, t2, env, have, need, newOpen, symtab, common ) ) {
     1090                        if ( unify( t1, t2, env, have, need, newOpen, common ) ) {
    11131091                                ast::CV::Qualifiers q1 = t1->qualifiers, q2 = t2->qualifiers;
    11141092                                PRINT(
     
    11341112                        const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2,
    11351113                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1136                         const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab
     1114                        const ast::OpenVarSet & open, WidenMode widen
    11371115        ) {
    11381116                unsigned depth1 = type1->referenceDepth();
     
    11491127                        if ( depth1 > depth2 ) {
    11501128                                assert( ref1 );
    1151                                 result = handleReference( ref1->base, type2, widen, symtab, env, open );
     1129                                result = handleReference( ref1->base, type2, widen, env, open );
    11521130                        } else {  // implies depth1 < depth2
    11531131                                assert( ref2 );
    1154                                 result = handleReference( type1, ref2->base, widen, symtab, env, open );
     1132                                result = handleReference( type1, ref2->base, widen, env, open );
    11551133                        }
    11561134
     
    11701148                }
    11711149                // otherwise both are reference types of the same depth and this is handled by the visitor
    1172                 ast::Pass<CommonType_new> visitor{ type2, widen, symtab, env, open, need, have };
     1150                ast::Pass<CommonType_new> visitor{ type2, widen, env, open, need, have };
    11731151                type1->accept( visitor );
    1174                 ast::ptr< ast::Type > result = visitor.core.result;
    1175 
    1176                 // handling for opaque type declarations (?)
    1177                 if ( ! result && widen.second ) {
    1178                         if ( const ast::TypeInstType * inst = type2.as< ast::TypeInstType >() ) {
    1179                                 if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) {
    1180                                         auto type = strict_dynamic_cast< const ast::TypeDecl * >( nt );
    1181                                         if ( type->base ) {
    1182                                                 ast::CV::Qualifiers q1 = type1->qualifiers, q2 = type2->qualifiers;
    1183                                                 ast::OpenVarSet newOpen{ open };
    1184 
    1185                                                 // force t{1,2} to be cloned if its qualifiers must be stripped, so that
    1186                                                 // type1 and type->base are left unchanged; calling convention forces
    1187                                                 // {type1,type->base}->strong_ref >= 1
    1188                                                 ast::ptr<ast::Type> t1{ type1 }, t2{ type->base };
    1189                                                 reset_qualifiers( t1 );
    1190                                                 reset_qualifiers( t2, q1 );
    1191 
    1192                                                 if ( unifyExact( t1, t2, env, have, need, newOpen, noWiden(), symtab ) ) {
    1193                                                         result = t1;
    1194                                                         reset_qualifiers( result, q1 | q2 );
    1195                                                 }
    1196                                         }
    1197                                 }
    1198                         }
    1199                 }
    1200 
    1201                 return result;
     1152                // ast::ptr< ast::Type > result = visitor.core.result;
     1153
     1154                return visitor.core.result;
    12021155        }
    12031156
Note: See TracChangeset for help on using the changeset viewer.