Changes in src/ResolvExpr/Unify.cc [07de76b:c7f834e]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
r07de76b rc7f834e 25 25 #include <vector> 26 26 27 #include "AST/Copy.hpp" 27 28 #include "AST/Decl.hpp" 28 29 #include "AST/Node.hpp" 29 30 #include "AST/Pass.hpp" 31 #include "AST/Print.hpp" 30 32 #include "AST/Type.hpp" 31 33 #include "AST/TypeEnvironment.hpp" … … 135 137 findOpenVars( newSecond, open, closed, need, have, FirstOpen ); 136 138 137 return unifyExact( 138 newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab ); 139 return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab ); 139 140 } 140 141 … … 148 149 newFirst->get_qualifiers() = Type::Qualifiers(); 149 150 newSecond->get_qualifiers() = Type::Qualifiers(); 150 /// std::cerr << "first is "; 151 /// first->print( std::cerr ); 152 /// std::cerr << std::endl << "second is "; 153 /// second->print( std::cerr ); 154 /// std::cerr << std::endl << "newFirst is "; 155 /// newFirst->print( std::cerr ); 156 /// std::cerr << std::endl << "newSecond is "; 157 /// newSecond->print( std::cerr ); 158 /// std::cerr << std::endl; 151 159 152 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 160 153 delete newFirst; … … 170 163 ast::AssertionSet need, have; 171 164 172 ast::ptr<ast::Type> newFirst{ first }, newSecond{ second }; 173 env.apply( newFirst ); 174 env.apply( newSecond ); 175 reset_qualifiers( newFirst ); 176 reset_qualifiers( newSecond ); 165 ast::Type * newFirst = shallowCopy( first ); 166 ast::Type * newSecond = shallowCopy( second ); 167 newFirst ->qualifiers = {}; 168 newSecond->qualifiers = {}; 169 ast::ptr< ast::Type > t1_(newFirst ); 170 ast::ptr< ast::Type > t2_(newSecond); 171 172 ast::ptr< ast::Type > subFirst = env.apply(newFirst).node; 173 ast::ptr< ast::Type > subSecond = env.apply(newSecond).node; 177 174 178 175 return unifyExact( 179 newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab ); 176 subFirst, 177 subSecond, 178 newEnv, need, have, open, noWiden(), symtab ); 180 179 } 181 180 … … 326 325 327 326 void markAssertionSet( AssertionSet &assertions, DeclarationWithType *assert ) { 328 /// std::cerr << "assertion set is" << std::endl;329 /// printAssertionSet( assertions, std::cerr, 8 );330 /// std::cerr << "looking for ";331 /// assert->print( std::cerr );332 /// std::cerr << std::endl;333 327 AssertionSet::iterator i = assertions.find( assert ); 334 328 if ( i != assertions.end() ) { 335 /// std::cerr << "found it!" << std::endl;336 329 i->second.isUsed = true; 337 330 } // if … … 943 936 944 937 private: 945 template< typename RefType > 946 const RefType * handleRefType( const RefType * inst, const ast::Type * other ) { 938 // Returns: other, cast as XInstType 939 // Assigns this->result: whether types are compatible (up to generic parameters) 940 template< typename XInstType > 941 const XInstType * handleRefType( const XInstType * inst, const ast::Type * other ) { 947 942 // check that the other type is compatible and named the same 948 auto otherInst = dynamic_cast< const RefType * >( other );949 result = otherInst && inst->name == otherInst->name;943 auto otherInst = dynamic_cast< const XInstType * >( other ); 944 this->result = otherInst && inst->name == otherInst->name; 950 945 return otherInst; 951 946 } … … 968 963 } 969 964 970 template< typename RefType >971 void handleGenericRefType( const RefType * inst, const ast::Type * other ) {965 template< typename XInstType > 966 void handleGenericRefType( const XInstType * inst, const ast::Type * other ) { 972 967 // check that other type is compatible and named the same 973 const RefType * inst2= handleRefType( inst, other );974 if ( ! inst2) return;968 const XInstType * otherInst = handleRefType( inst, other ); 969 if ( ! this->result ) return; 975 970 976 971 // check that parameters of types unify, if any 977 972 const std::vector< ast::ptr< ast::Expr > > & params = inst->params; 978 const std::vector< ast::ptr< ast::Expr > > & params2 = inst2->params;973 const std::vector< ast::ptr< ast::Expr > > & params2 = otherInst->params; 979 974 980 975 auto it = params.begin(); … … 1202 1197 // force t1 and t2 to be cloned if their qualifiers must be stripped, so that type1 and 1203 1198 // type2 are left unchanged; calling convention forces type{1,2}->strong_ref >= 1 1204 ast::ptr<ast::Type> t1{ type1 }, t2{ type2 }; 1205 reset_qualifiers( t1 ); 1206 reset_qualifiers( t2 ); 1199 ast::Type * t1 = shallowCopy(type1.get()); 1200 ast::Type * t2 = shallowCopy(type2.get()); 1201 t1->qualifiers = {}; 1202 t2->qualifiers = {}; 1203 ast::ptr< ast::Type > t1_(t1); 1204 ast::ptr< ast::Type > t2_(t2); 1207 1205 1208 1206 if ( unifyExact( t1, t2, env, need, have, open, widen, symtab ) ) { 1209 t1 = nullptr; t2 = nullptr; // release t1, t2 to avoid spurious clones1210 1211 1207 // if exact unification on unqualified types, try to merge qualifiers 1212 1208 if ( q1 == q2 || ( ( q1 > q2 || widen.first ) && ( q2 > q1 || widen.second ) ) ) { 1213 common = type1;1214 reset_qualifiers( common, q1 | q2 );1209 t1->qualifiers = q1 | q2; 1210 common = t1; 1215 1211 return true; 1216 1212 } else { … … 1219 1215 1220 1216 } else if (( common = commonType( t1, t2, widen, symtab, env, open ) )) { 1221 t1 = nullptr; t2 = nullptr; // release t1, t2 to avoid spurious clones1222 1223 1217 // no exact unification, but common type 1224 reset_qualifiers( common, q1 | q2 ); 1218 auto c = shallowCopy(common.get()); 1219 c->qualifiers = q1 | q2; 1220 common = c; 1225 1221 return true; 1226 1222 } else {
Note: See TracChangeset
for help on using the changeset viewer.