Changes in src/ResolvExpr/Unify.cc [90ce35aa:07de76b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
r90ce35aa r07de76b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:27:10 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Sep 4 10:00:00201913 // Update Count : 4 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:43:05 2019 13 // Update Count : 46 14 14 // 15 15 … … 25 25 #include <vector> 26 26 27 #include "AST/Copy.hpp"28 27 #include "AST/Decl.hpp" 29 28 #include "AST/Node.hpp" 30 29 #include "AST/Pass.hpp" 31 #include "AST/Print.hpp"32 30 #include "AST/Type.hpp" 33 31 #include "AST/TypeEnvironment.hpp" 34 32 #include "Common/PassVisitor.h" // for PassVisitor 35 33 #include "FindOpenVars.h" // for findOpenVars 36 #include " Parser/LinkageSpec.h"// for C34 #include "SynTree/LinkageSpec.h" // for C 37 35 #include "SynTree/Constant.h" // for Constant 38 36 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Data, Declarati... … … 137 135 findOpenVars( newSecond, open, closed, need, have, FirstOpen ); 138 136 139 return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab ); 137 return unifyExact( 138 newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab ); 140 139 } 141 140 … … 149 148 newFirst->get_qualifiers() = Type::Qualifiers(); 150 149 newSecond->get_qualifiers() = Type::Qualifiers(); 151 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; 152 159 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 153 160 delete newFirst; … … 163 170 ast::AssertionSet need, have; 164 171 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); 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 ); 171 177 172 178 return unifyExact( 173 env.apply( newFirst ).node, 174 env.apply( newSecond ).node, 175 newEnv, need, have, open, noWiden(), symtab ); 179 newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab ); 176 180 } 177 181 … … 322 326 323 327 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; 324 333 AssertionSet::iterator i = assertions.find( assert ); 325 334 if ( i != assertions.end() ) { 335 /// std::cerr << "found it!" << std::endl; 326 336 i->second.isUsed = true; 327 337 } // if … … 771 781 if ( const ast::EqvClass * clz = tenv.lookup( typeInst->name ) ) { 772 782 // expand ttype parameter into its actual type 773 if ( clz->data.kind == ast::Type Var::Ttype && clz->bound ) {783 if ( clz->data.kind == ast::TypeDecl::Ttype && clz->bound ) { 774 784 return clz->bound; 775 785 } … … 933 943 934 944 private: 935 // Returns: other, cast as XInstType 936 // Assigns this->result: whether types are compatible (up to generic parameters) 937 template< typename XInstType > 938 const XInstType * handleRefType( const XInstType * inst, const ast::Type * other ) { 945 template< typename RefType > 946 const RefType * handleRefType( const RefType * inst, const ast::Type * other ) { 939 947 // check that the other type is compatible and named the same 940 auto otherInst = dynamic_cast< const XInstType * >( other );941 this->result = otherInst && inst->name == otherInst->name;948 auto otherInst = dynamic_cast< const RefType * >( other ); 949 result = otherInst && inst->name == otherInst->name; 942 950 return otherInst; 943 951 } … … 960 968 } 961 969 962 template< typename XInstType >963 void handleGenericRefType( const XInstType * inst, const ast::Type * other ) {970 template< typename RefType > 971 void handleGenericRefType( const RefType * inst, const ast::Type * other ) { 964 972 // check that other type is compatible and named the same 965 const XInstType * otherInst= handleRefType( inst, other );966 if ( ! this->result) return;973 const RefType * inst2 = handleRefType( inst, other ); 974 if ( ! inst2 ) return; 967 975 968 976 // check that parameters of types unify, if any 969 977 const std::vector< ast::ptr< ast::Expr > > & params = inst->params; 970 const std::vector< ast::ptr< ast::Expr > > & params2 = otherInst->params;978 const std::vector< ast::ptr< ast::Expr > > & params2 = inst2->params; 971 979 972 980 auto it = params.begin(); … … 1194 1202 // force t1 and t2 to be cloned if their qualifiers must be stripped, so that type1 and 1195 1203 // type2 are left unchanged; calling convention forces type{1,2}->strong_ref >= 1 1196 ast::Type * t1 = shallowCopy(type1.get()); 1197 ast::Type * t2 = shallowCopy(type2.get()); 1198 t1->qualifiers = {}; 1199 t2->qualifiers = {}; 1200 ast::ptr< ast::Type > t1_(t1); 1201 ast::ptr< ast::Type > t2_(t2); 1204 ast::ptr<ast::Type> t1{ type1 }, t2{ type2 }; 1205 reset_qualifiers( t1 ); 1206 reset_qualifiers( t2 ); 1202 1207 1203 1208 if ( unifyExact( t1, t2, env, need, have, open, widen, symtab ) ) { 1209 t1 = nullptr; t2 = nullptr; // release t1, t2 to avoid spurious clones 1210 1204 1211 // if exact unification on unqualified types, try to merge qualifiers 1205 1212 if ( q1 == q2 || ( ( q1 > q2 || widen.first ) && ( q2 > q1 || widen.second ) ) ) { 1206 t1->qualifiers = q1 | q2;1207 common = t1;1213 common = type1; 1214 reset_qualifiers( common, q1 | q2 ); 1208 1215 return true; 1209 1216 } else { … … 1212 1219 1213 1220 } else if (( common = commonType( t1, t2, widen, symtab, env, open ) )) { 1221 t1 = nullptr; t2 = nullptr; // release t1, t2 to avoid spurious clones 1222 1214 1223 // no exact unification, but common type 1215 auto c = shallowCopy(common.get()); 1216 c->qualifiers = q1 | q2; 1217 common = c; 1224 reset_qualifiers( common, q1 | q2 ); 1218 1225 return true; 1219 1226 } else {
Note:
See TracChangeset
for help on using the changeset viewer.