Changes in src/ResolvExpr/Unify.cc [ee574a2:f474e91]
- File:
-
- 1 edited
-
src/ResolvExpr/Unify.cc (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
ree574a2 rf474e91 136 136 137 137 return unifyExact( 138 newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab );138 newFirst, newSecond, newEnv, need, have, open, WidenMode{ false, false }, symtab ); 139 139 } 140 140 … … 173 173 env.apply( newFirst ); 174 174 env.apply( newSecond ); 175 reset_qualifiers( newFirst );176 reset_qualifiers( newSecond );175 clear_qualifiers( newFirst ); 176 clear_qualifiers( newSecond ); 177 177 178 178 return unifyExact( 179 newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab );179 newFirst, newSecond, newEnv, need, have, open, WidenMode{ false, false }, symtab ); 180 180 } 181 181 … … 700 700 } 701 701 702 class Unify_new final: public ast::WithShortCircuiting {702 class Unify_new : public ast::WithShortCircuiting { 703 703 const ast::Type * type2; 704 704 ast::TypeEnvironment & tenv; … … 720 720 void previsit( const ast::Node * ) { visit_children = false; } 721 721 722 void postvisit( const ast::VoidType * ) { 722 void previsit( const ast::VoidType * ) { 723 visit_children = false; 723 724 result = dynamic_cast< const ast::VoidType * >( type2 ); 724 725 } 725 726 726 void postvisit( const ast::BasicType * basic ) { 727 void previsit( const ast::BasicType * basic ) { 728 visit_children = false; 727 729 if ( auto basic2 = dynamic_cast< const ast::BasicType * >( type2 ) ) { 728 730 result = basic->kind == basic2->kind; … … 730 732 } 731 733 732 void postvisit( const ast::PointerType * pointer ) { 734 void previsit( const ast::PointerType * pointer ) { 735 visit_children = false; 733 736 if ( auto pointer2 = dynamic_cast< const ast::PointerType * >( type2 ) ) { 734 737 result = unifyExact( 735 738 pointer->base, pointer2->base, tenv, need, have, open, 736 noWiden(), symtab ); 737 } 738 } 739 740 void postvisit( const ast::ArrayType * array ) { 739 WidenMode{ false, false }, symtab ); 740 } 741 } 742 743 void previsit( const ast::ArrayType * array ) { 744 visit_children = false; 741 745 auto array2 = dynamic_cast< const ast::ArrayType * >( type2 ); 742 746 if ( ! array2 ) return; … … 757 761 758 762 result = unifyExact( 759 array->base, array2->base, tenv, need, have, open, noWiden(),763 array->base, array2->base, tenv, need, have, open, WidenMode{ false, false }, 760 764 symtab ); 761 765 } 762 766 763 void postvisit( const ast::ReferenceType * ref ) { 767 void previsit( const ast::ReferenceType * ref ) { 768 visit_children = false; 764 769 if ( auto ref2 = dynamic_cast< const ast::ReferenceType * >( type2 ) ) { 765 770 result = unifyExact( 766 ref->base, ref2->base, tenv, need, have, open, noWiden(),771 ref->base, ref2->base, tenv, need, have, open, WidenMode{ false, false }, 767 772 symtab ); 768 773 } … … 778 783 TtypeExpander_new( ast::TypeEnvironment & env ) : tenv( env ) {} 779 784 780 const ast::Type * post visit( const ast::TypeInstType * typeInst ) {785 const ast::Type * postmutate( const ast::TypeInstType * typeInst ) { 781 786 if ( const ast::EqvClass * clz = tenv.lookup( typeInst->name ) ) { 782 787 // expand ttype parameter into its actual type … … 806 811 // overloaded on outermost mutex and a mutex function has different 807 812 // requirements than a non-mutex function 808 remove_qualifiers( t, ast::CV::Const | ast::CV::Volatile | ast::CV::Atomic ); 813 t.get_and_mutate()->qualifiers 814 -= ast::CV::Const | ast::CV::Volatile | ast::CV::Atomic; 809 815 dst.emplace_back( new ast::ObjectDecl{ d->location, "", t } ); 810 816 } … … 845 851 return unifyExact( 846 852 t1, tupleFromDecls( crnt2, end2 ), env, need, have, open, 847 noWiden(), symtab );853 WidenMode{ false, false }, symtab ); 848 854 } else if ( ! isTuple1 && isTuple2 ) { 849 855 // combine remainder of list1, then unify 850 856 return unifyExact( 851 857 tupleFromDecls( crnt1, end1 ), t2, env, need, have, open, 852 noWiden(), symtab );858 WidenMode{ false, false }, symtab ); 853 859 } 854 860 855 861 if ( ! unifyExact( 856 t1, t2, env, need, have, open, noWiden(), symtab )862 t1, t2, env, need, have, open, WidenMode{ false, false }, symtab ) 857 863 ) return false; 858 864 … … 868 874 return unifyExact( 869 875 t1, tupleFromDecls( crnt2, end2 ), env, need, have, open, 870 noWiden(), symtab );876 WidenMode{ false, false }, symtab ); 871 877 } else if ( crnt2 != end2 ) { 872 878 // try unifying empty tuple with ttype … … 875 881 return unifyExact( 876 882 tupleFromDecls( crnt1, end1 ), t2, env, need, have, open, 877 noWiden(), symtab );883 WidenMode{ false, false }, symtab ); 878 884 } 879 885 … … 913 919 914 920 public: 915 void postvisit( const ast::FunctionType * func ) { 921 void previsit( const ast::FunctionType * func ) { 922 visit_children = false; 916 923 auto func2 = dynamic_cast< const ast::FunctionType * >( type2 ); 917 924 if ( ! func2 ) return; … … 945 952 template< typename RefType > 946 953 const RefType * handleRefType( const RefType * inst, const ast::Type * other ) { 954 visit_children = false; 947 955 // check that the other type is compatible and named the same 948 956 auto otherInst = dynamic_cast< const RefType * >( other ); … … 1003 1011 1004 1012 if ( ! unifyExact( 1005 pty, pty2, tenv, need, have, open, noWiden(), symtab ) ) {1013 pty, pty2, tenv, need, have, open, WidenMode{ false, false }, symtab ) ) { 1006 1014 result = false; 1007 1015 return; … … 1015 1023 1016 1024 public: 1017 void p ostvisit( const ast::StructInstType * aggrType ) {1025 void previsit( const ast::StructInstType * aggrType ) { 1018 1026 handleGenericRefType( aggrType, type2 ); 1019 1027 } 1020 1028 1021 void p ostvisit( const ast::UnionInstType * aggrType ) {1029 void previsit( const ast::UnionInstType * aggrType ) { 1022 1030 handleGenericRefType( aggrType, type2 ); 1023 1031 } 1024 1032 1025 void p ostvisit( const ast::EnumInstType * aggrType ) {1033 void previsit( const ast::EnumInstType * aggrType ) { 1026 1034 handleRefType( aggrType, type2 ); 1027 1035 } 1028 1036 1029 void p ostvisit( const ast::TraitInstType * aggrType ) {1037 void previsit( const ast::TraitInstType * aggrType ) { 1030 1038 handleRefType( aggrType, type2 ); 1031 1039 } 1032 1040 1033 void p ostvisit( const ast::TypeInstType * typeInst ) {1041 void previsit( const ast::TypeInstType * typeInst ) { 1034 1042 assert( open.find( typeInst->name ) == open.end() ); 1035 1043 handleRefType( typeInst, type2 ); … … 1070 1078 return unifyExact( 1071 1079 t1, tupleFromTypes( list2 ), env, need, have, open, 1072 noWiden(), symtab );1080 WidenMode{ false, false }, symtab ); 1073 1081 } else if ( ! isTuple1 && isTuple2 ) { 1074 1082 // combine entirety of list1, then unify 1075 1083 return unifyExact( 1076 1084 tupleFromTypes( list1 ), t2, env, need, have, open, 1077 noWiden(), symtab );1085 WidenMode{ false, false }, symtab ); 1078 1086 } 1079 1087 1080 1088 if ( ! unifyExact( 1081 t1, t2, env, need, have, open, noWiden(), symtab )1089 t1, t2, env, need, have, open, WidenMode{ false, false }, symtab ) 1082 1090 ) return false; 1083 1091 … … 1093 1101 return unifyExact( 1094 1102 t1, tupleFromTypes( list2 ), env, need, have, open, 1095 noWiden(), symtab );1103 WidenMode{ false, false }, symtab ); 1096 1104 } else if ( crnt2 != list2.end() ) { 1097 1105 // try unifying empty tuple with ttype … … 1102 1110 return unifyExact( 1103 1111 tupleFromTypes( list1 ), t2, env, need, have, open, 1104 noWiden(), symtab );1112 WidenMode{ false, false }, symtab ); 1105 1113 } 1106 1114 … … 1109 1117 1110 1118 public: 1111 void postvisit( const ast::TupleType * tuple ) { 1119 void previsit( const ast::TupleType * tuple ) { 1120 visit_children = false; 1112 1121 auto tuple2 = dynamic_cast< const ast::TupleType * >( type2 ); 1113 1122 if ( ! tuple2 ) return; … … 1123 1132 } 1124 1133 1125 void postvisit( const ast::VarArgsType * ) { 1134 void previsit( const ast::VarArgsType * ) { 1135 visit_children = false; 1126 1136 result = dynamic_cast< const ast::VarArgsType * >( type2 ); 1127 1137 } 1128 1138 1129 void postvisit( const ast::ZeroType * ) { 1139 void previsit( const ast::ZeroType * ) { 1140 visit_children = false; 1130 1141 result = dynamic_cast< const ast::ZeroType * >( type2 ); 1131 1142 } 1132 1143 1133 void postvisit( const ast::OneType * ) { 1144 void previsit( const ast::OneType * ) { 1145 visit_children = false; 1134 1146 result = dynamic_cast< const ast::OneType * >( type2 ); 1135 1147 } … … 1139 1151 template< typename RefType > void handleGenericRefType( RefType *inst, Type *other ); 1140 1152 }; 1141 1142 bool unify(1143 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,1144 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,1145 ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common1146 ) {1147 ast::OpenVarSet closed;1148 findOpenVars( type1, open, closed, need, have, FirstClosed );1149 findOpenVars( type2, open, closed, need, have, FirstOpen );1150 return unifyInexact(1151 type1, type2, env, need, have, open, WidenMode{ true, true }, symtab, common );1152 }1153 1153 1154 1154 bool unifyExact( … … 1184 1184 1185 1185 bool unifyInexact( 1186 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 1187 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 1188 const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab, 1189 ast::ptr<ast::Type> & common 1186 ast::ptr<ast::Type> & type1, ast::ptr<ast::Type> & type2, ast::TypeEnvironment & env, 1187 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 1188 WidenMode widen, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common 1190 1189 ) { 1191 1190 ast::CV::Qualifiers q1 = type1->qualifiers, q2 = type2->qualifiers; … … 1194 1193 // type2 are left unchanged; calling convention forces type{1,2}->strong_ref >= 1 1195 1194 ast::ptr<ast::Type> t1{ type1 }, t2{ type2 }; 1196 reset_qualifiers( t1 );1197 reset_qualifiers( t2 );1195 clear_qualifiers( t1 ); 1196 clear_qualifiers( t2 ); 1198 1197 1199 1198 if ( unifyExact( t1, t2, env, need, have, open, widen, symtab ) ) { … … 1202 1201 // if exact unification on unqualified types, try to merge qualifiers 1203 1202 if ( q1 == q2 || ( ( q1 > q2 || widen.first ) && ( q2 > q1 || widen.second ) ) ) { 1204 common = type1; 1205 reset_qualifiers( common, q1 | q2 ); 1203 common.set_and_mutate( type1 )->qualifiers = q1 | q2; 1206 1204 return true; 1207 1205 } else { … … 1213 1211 1214 1212 // no exact unification, but common type 1215 reset_qualifiers( common, q1 | q2 );1213 common.get_and_mutate()->qualifiers = q1 | q2; 1216 1214 return true; 1217 1215 } else {
Note:
See TracChangeset
for help on using the changeset viewer.