Changeset 251ce80 for src/ResolvExpr/CommonType.cc
- Timestamp:
- Jun 1, 2023, 6:29:47 PM (13 months ago)
- Branches:
- ast-experimental, master
- Children:
- 24d6572, ded6c2a6
- Parents:
- 1803d4d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CommonType.cc
r1803d4d r251ce80 676 676 const ast::Type * type2; 677 677 WidenMode widen; 678 const ast::SymbolTable & symtab;679 678 ast::TypeEnvironment & tenv; 680 679 const ast::OpenVarSet & open; … … 686 685 687 686 CommonType_new( 688 const ast::Type * t2, WidenMode w, const ast::SymbolTable & st,687 const ast::Type * t2, WidenMode w, 689 688 ast::TypeEnvironment & env, const ast::OpenVarSet & o, 690 689 ast::AssertionSet & need, ast::AssertionSet & have ) 691 : 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() {} 692 691 693 692 void previsit( const ast::Node * ) { visit_children = false; } … … 749 748 ast::AssertionSet need, have; 750 749 if ( ! tenv.bindVar( 751 var, voidPtr->base, entry->second, need, have, open, widen , symtab)750 var, voidPtr->base, entry->second, need, have, open, widen ) 752 751 ) return; 753 752 } … … 762 761 ast::OpenVarSet newOpen{ open }; 763 762 if (enumInst->base->base 764 && unifyExact(type1, enumInst->base->base, tenv, need, have, newOpen, widen , symtab)) {763 && unifyExact(type1, enumInst->base->base, tenv, need, have, newOpen, widen)) { 765 764 result = type1; 766 765 return true; … … 799 798 800 799 ast::OpenVarSet newOpen{ open }; 801 if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() , symtab) ) {800 if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() ) ) { 802 801 result = pointer; 803 802 if ( q1.val != q2.val ) { … … 842 841 if (unifyExact( 843 842 arg1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open, 844 noWiden() , symtab)) {843 noWiden() )) { 845 844 break; 846 845 … … 851 850 if (unifyExact( 852 851 tupleFromTypes( crnt1, end1 ), arg2, tenv, need, have, open, 853 noWiden() , symtab)) {852 noWiden() )) { 854 853 break; 855 854 … … 875 874 876 875 if ( ! unifyExact( 877 base1, base2, tenv, need, have, open, noWiden() , symtab)876 base1, base2, tenv, need, have, open, noWiden() ) 878 877 ) return; 879 878 } … … 895 894 896 895 if ( ! unifyExact( 897 base1, base2, tenv, need, have, open, noWiden() , symtab)896 base1, base2, tenv, need, have, open, noWiden() ) 898 897 ) return; 899 898 } … … 903 902 } 904 903 else if (! unifyExact( 905 arg1, arg2, tenv, need, have, open, noWiden() , symtab)) return;904 arg1, arg2, tenv, need, have, open, noWiden() )) return; 906 905 907 906 ++crnt1; ++crnt2; … … 913 912 if (! unifyExact( 914 913 t1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open, 915 noWiden() , symtab)) return;914 noWiden() )) return; 916 915 } else if ( crnt2 != end2 ) { 917 916 // try unifying empty tuple with ttype … … 920 919 if (! unifyExact( 921 920 tupleFromTypes( crnt1, end1 ), t2, tenv, need, have, open, 922 noWiden() , symtab)) return;921 noWiden() )) return; 923 922 } 924 923 if ((f1->returns.size() == 0 && f2->returns.size() == 0) 925 || (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()))) { 926 925 result = pointer; 927 926 … … 980 979 981 980 ast::OpenVarSet newOpen{ open }; 982 if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() , symtab) ) {981 if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() ) ) { 983 982 result = ref; 984 983 if ( q1.val != q2.val ) { … … 995 994 } else { 996 995 if (!dynamic_cast<const ast::EnumInstType *>(type2)) 997 result = commonType( type2, ref, tenv, need, have, open, widen , symtab);996 result = commonType( type2, ref, tenv, need, have, open, widen ); 998 997 } 999 998 } … … 1013 1012 void postvisit( const ast::EnumInstType * enumInst ) { 1014 1013 if (!dynamic_cast<const ast::EnumInstType *>(type2)) 1015 result = commonType( type2, enumInst, tenv, need, have, open, widen , symtab);1014 result = commonType( type2, enumInst, tenv, need, have, open, widen); 1016 1015 } 1017 1016 1018 1017 void postvisit( const ast::TraitInstType * ) {} 1019 1018 1020 void postvisit( const ast::TypeInstType * inst ) { 1021 if ( ! widen.first ) return; 1022 if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) { 1023 if ( const ast::Type * base = 1024 strict_dynamic_cast< const ast::TypeDecl * >( nt )->base 1025 ) { 1026 ast::CV::Qualifiers q1 = inst->qualifiers, q2 = type2->qualifiers; 1027 1028 // force t{1,2} to be cloned if their qualifiers must be mutated 1029 ast::ptr< ast::Type > t1{ base }, t2{ type2 }; 1030 reset_qualifiers( t1, q1 ); 1031 reset_qualifiers( t2 ); 1032 1033 ast::OpenVarSet newOpen{ open }; 1034 if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) { 1035 result = type2; 1036 reset_qualifiers( result, q1 | q2 ); 1037 } else { 1038 tryResolveWithTypedEnum( t1 ); 1039 } 1040 } 1041 } 1042 } 1019 void postvisit( const ast::TypeInstType * inst ) {} 1043 1020 1044 1021 void postvisit( const ast::TupleType * tuple) { … … 1103 1080 ast::ptr< ast::Type > handleReference( 1104 1081 const ast::ptr< ast::Type > & t1, const ast::ptr< ast::Type > & t2, WidenMode widen, 1105 const ast::SymbolTable & symtab,ast::TypeEnvironment & env,1082 ast::TypeEnvironment & env, 1106 1083 const ast::OpenVarSet & open 1107 1084 ) { … … 1111 1088 1112 1089 // need unify to bind type variables 1113 if ( unify( t1, t2, env, have, need, newOpen, symtab,common ) ) {1090 if ( unify( t1, t2, env, have, need, newOpen, common ) ) { 1114 1091 ast::CV::Qualifiers q1 = t1->qualifiers, q2 = t2->qualifiers; 1115 1092 PRINT( … … 1135 1112 const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, 1136 1113 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 1137 const ast::OpenVarSet & open, WidenMode widen , const ast::SymbolTable & symtab1114 const ast::OpenVarSet & open, WidenMode widen 1138 1115 ) { 1139 1116 unsigned depth1 = type1->referenceDepth(); … … 1150 1127 if ( depth1 > depth2 ) { 1151 1128 assert( ref1 ); 1152 result = handleReference( ref1->base, type2, widen, symtab,env, open );1129 result = handleReference( ref1->base, type2, widen, env, open ); 1153 1130 } else { // implies depth1 < depth2 1154 1131 assert( ref2 ); 1155 result = handleReference( type1, ref2->base, widen, symtab,env, open );1132 result = handleReference( type1, ref2->base, widen, env, open ); 1156 1133 } 1157 1134 … … 1171 1148 } 1172 1149 // otherwise both are reference types of the same depth and this is handled by the visitor 1173 ast::Pass<CommonType_new> visitor{ type2, widen, symtab,env, open, need, have };1150 ast::Pass<CommonType_new> visitor{ type2, widen, env, open, need, have }; 1174 1151 type1->accept( visitor ); 1175 ast::ptr< ast::Type > result = visitor.core.result; 1176 1177 // handling for opaque type declarations (?) 1178 if ( ! result && widen.second ) { 1179 if ( const ast::TypeInstType * inst = type2.as< ast::TypeInstType >() ) { 1180 if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) { 1181 auto type = strict_dynamic_cast< const ast::TypeDecl * >( nt ); 1182 if ( type->base ) { 1183 ast::CV::Qualifiers q1 = type1->qualifiers, q2 = type2->qualifiers; 1184 ast::OpenVarSet newOpen{ open }; 1185 1186 // force t{1,2} to be cloned if its qualifiers must be stripped, so that 1187 // type1 and type->base are left unchanged; calling convention forces 1188 // {type1,type->base}->strong_ref >= 1 1189 ast::ptr<ast::Type> t1{ type1 }, t2{ type->base }; 1190 reset_qualifiers( t1 ); 1191 reset_qualifiers( t2, q1 ); 1192 1193 if ( unifyExact( t1, t2, env, have, need, newOpen, noWiden(), symtab ) ) { 1194 result = t1; 1195 reset_qualifiers( result, q1 | q2 ); 1196 } 1197 } 1198 } 1199 } 1200 } 1201 1202 return result; 1152 // ast::ptr< ast::Type > result = visitor.core.result; 1153 1154 return visitor.core.result; 1203 1155 } 1204 1156
Note: See TracChangeset
for help on using the changeset viewer.