Changeset 8a930c03 for src/ResolvExpr/CommonType.cc
- Timestamp:
- Jun 12, 2023, 12:05:58 PM (2 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CommonType.cc
r2b78949 r8a930c03 21 21 22 22 #include "AST/Decl.hpp" 23 #include "AST/Pass.hpp" 23 24 #include "AST/Type.hpp" 24 25 #include "Common/PassVisitor.h" … … 675 676 const ast::Type * type2; 676 677 WidenMode widen; 677 const ast::SymbolTable & symtab;678 678 ast::TypeEnvironment & tenv; 679 679 const ast::OpenVarSet & open; … … 685 685 686 686 CommonType_new( 687 const ast::Type * t2, WidenMode w, const ast::SymbolTable & st,687 const ast::Type * t2, WidenMode w, 688 688 ast::TypeEnvironment & env, const ast::OpenVarSet & o, 689 689 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() {} 691 691 692 692 void previsit( const ast::Node * ) { visit_children = false; } … … 748 748 ast::AssertionSet need, have; 749 749 if ( ! tenv.bindVar( 750 var, voidPtr->base, entry->second, need, have, open, widen , symtab)750 var, voidPtr->base, entry->second, need, have, open, widen ) 751 751 ) return; 752 752 } … … 761 761 ast::OpenVarSet newOpen{ open }; 762 762 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)) { 764 764 result = type1; 765 765 return true; … … 798 798 799 799 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() ) ) { 801 801 result = pointer; 802 802 if ( q1.val != q2.val ) { … … 841 841 if (unifyExact( 842 842 arg1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open, 843 noWiden() , symtab)) {843 noWiden() )) { 844 844 break; 845 845 … … 850 850 if (unifyExact( 851 851 tupleFromTypes( crnt1, end1 ), arg2, tenv, need, have, open, 852 noWiden() , symtab)) {852 noWiden() )) { 853 853 break; 854 854 … … 874 874 875 875 if ( ! unifyExact( 876 base1, base2, tenv, need, have, open, noWiden() , symtab)876 base1, base2, tenv, need, have, open, noWiden() ) 877 877 ) return; 878 878 } … … 894 894 895 895 if ( ! unifyExact( 896 base1, base2, tenv, need, have, open, noWiden() , symtab)896 base1, base2, tenv, need, have, open, noWiden() ) 897 897 ) return; 898 898 } … … 902 902 } 903 903 else if (! unifyExact( 904 arg1, arg2, tenv, need, have, open, noWiden() , symtab)) return;904 arg1, arg2, tenv, need, have, open, noWiden() )) return; 905 905 906 906 ++crnt1; ++crnt2; … … 912 912 if (! unifyExact( 913 913 t1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open, 914 noWiden() , symtab)) return;914 noWiden() )) return; 915 915 } else if ( crnt2 != end2 ) { 916 916 // try unifying empty tuple with ttype … … 919 919 if (! unifyExact( 920 920 tupleFromTypes( crnt1, end1 ), t2, tenv, need, have, open, 921 noWiden() , symtab)) return;921 noWiden() )) return; 922 922 } 923 923 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()))) { 925 925 result = pointer; 926 926 … … 979 979 980 980 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() ) ) { 982 982 result = ref; 983 983 if ( q1.val != q2.val ) { … … 994 994 } else { 995 995 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 ); 997 997 } 998 998 } … … 1012 1012 void postvisit( const ast::EnumInstType * enumInst ) { 1013 1013 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); 1015 1015 } 1016 1016 1017 1017 void postvisit( const ast::TraitInstType * ) {} 1018 1018 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 ) { 1044 1022 tryResolveWithTypedEnum( tuple ); 1045 1023 } … … 1102 1080 ast::ptr< ast::Type > handleReference( 1103 1081 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, 1105 1083 const ast::OpenVarSet & open 1106 1084 ) { … … 1110 1088 1111 1089 // 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 ) ) { 1113 1091 ast::CV::Qualifiers q1 = t1->qualifiers, q2 = t2->qualifiers; 1114 1092 PRINT( … … 1134 1112 const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, 1135 1113 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 1136 const ast::OpenVarSet & open, WidenMode widen , const ast::SymbolTable & symtab1114 const ast::OpenVarSet & open, WidenMode widen 1137 1115 ) { 1138 1116 unsigned depth1 = type1->referenceDepth(); … … 1149 1127 if ( depth1 > depth2 ) { 1150 1128 assert( ref1 ); 1151 result = handleReference( ref1->base, type2, widen, symtab,env, open );1129 result = handleReference( ref1->base, type2, widen, env, open ); 1152 1130 } else { // implies depth1 < depth2 1153 1131 assert( ref2 ); 1154 result = handleReference( type1, ref2->base, widen, symtab,env, open );1132 result = handleReference( type1, ref2->base, widen, env, open ); 1155 1133 } 1156 1134 … … 1170 1148 } 1171 1149 // 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 }; 1173 1151 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; 1202 1155 } 1203 1156
Note:
See TracChangeset
for help on using the changeset viewer.