Changes in src/GenPoly/Box.cc [906e24d:1ba88a0]
- File:
-
- 1 edited
-
src/GenPoly/Box.cc (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r906e24d r1ba88a0 29 29 #include "PolyMutator.h" 30 30 #include "FindFunction.h" 31 #include "ScopedMap.h" 31 32 #include "ScopedSet.h" 32 33 #include "ScrubTyVars.h" … … 50 51 #include "SymTab/Mangler.h" 51 52 52 #include "Common/ScopedMap.h"53 53 #include "Common/SemanticError.h" 54 54 #include "Common/UniqueName.h" … … 782 782 783 783 // add size/align for generic types to parameter list 784 if ( ! appExpr->get_function()->has_result() ) return;785 FunctionType *funcType = getFunctionType( appExpr->get_function()->get_result () );784 if ( appExpr->get_function()->get_results().empty() ) return; 785 FunctionType *funcType = getFunctionType( appExpr->get_function()->get_results().front() ); 786 786 assert( funcType ); 787 787 … … 799 799 for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) { 800 800 VariableExpr *fnArgBase = getBaseVar( *fnArg ); 801 if ( ! fnArgBase ) continue; // xxx - previously had check for non-empty fnArgBase results802 passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_result (), arg, exprTyVars, seenTypes );801 if ( ! fnArgBase || fnArgBase->get_results().empty() ) continue; 802 passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_results().front(), arg, exprTyVars, seenTypes ); 803 803 } 804 804 } … … 890 890 Type * adapteeType = new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); 891 891 appExpr->get_args().push_front( new CastExpr( appExpr->get_function(), adapteeType ) ); 892 appExpr->set_function( new NameExpr( adapterName ) ); // xxx - result is never set on NameExpr892 appExpr->set_function( new NameExpr( adapterName ) ); 893 893 894 894 return ret; … … 896 896 897 897 void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) { 898 assert( arg->has_result() );898 assert( ! arg->get_results().empty() ); 899 899 if ( isPolyType( param, exprTyVars ) ) { 900 if ( isPolyType( arg->get_result () ) ) {900 if ( isPolyType( arg->get_results().front() ) ) { 901 901 // if the argument's type is polymorphic, we don't need to box again! 902 902 return; 903 } else if ( arg->get_result ()->get_isLvalue() ) {903 } else if ( arg->get_results().front()->get_isLvalue() ) { 904 904 // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue) 905 905 // xxx - need to test that this code is still reachable … … 987 987 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 988 988 deref->get_args().push_back( new CastExpr( new VariableExpr( param ), new PointerType( Type::Qualifiers(), arg->get_type()->clone() ) ) ); 989 deref-> set_result( arg->get_type()->clone() );989 deref->get_results().push_back( arg->get_type()->clone() ); 990 990 return deref; 991 991 } // if … … 1124 1124 } // if 1125 1125 addAssign->get_args().push_back( new NameExpr( sizeofName( mangleType( polyType ) ) ) ); 1126 addAssign-> set_result( appExpr->get_result()->clone());1126 addAssign->get_results().front() = appExpr->get_results().front()->clone(); 1127 1127 if ( appExpr->get_env() ) { 1128 1128 addAssign->set_env( appExpr->get_env() ); … … 1138 1138 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic ) { 1139 1139 if ( varExpr->get_var()->get_name() == "?[?]" ) { 1140 assert( appExpr->has_result() );1140 assert( ! appExpr->get_results().empty() ); 1141 1141 assert( appExpr->get_args().size() == 2 ); 1142 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result (), scopeTyVars, env );1143 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result (), scopeTyVars, env );1142 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env ); 1143 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env ); 1144 1144 assert( ! baseType1 || ! baseType2 ); // the arguments cannot both be polymorphic pointers 1145 1145 UntypedExpr *ret = 0; … … 1161 1161 } // if 1162 1162 if ( baseType1 || baseType2 ) { 1163 ret-> set_result( appExpr->get_result()->clone() );1163 ret->get_results().push_front( appExpr->get_results().front()->clone() ); 1164 1164 if ( appExpr->get_env() ) { 1165 1165 ret->set_env( appExpr->get_env() ); … … 1171 1171 } // if 1172 1172 } else if ( varExpr->get_var()->get_name() == "*?" ) { 1173 assert( appExpr->has_result() );1173 assert( ! appExpr->get_results().empty() ); 1174 1174 assert( ! appExpr->get_args().empty() ); 1175 if ( isPolyType( appExpr->get_result (), scopeTyVars, env ) ) {1175 if ( isPolyType( appExpr->get_results().front(), scopeTyVars, env ) ) { 1176 1176 Expression *ret = appExpr->get_args().front(); 1177 delete ret->get_result ();1178 ret-> set_result( appExpr->get_result()->clone());1177 delete ret->get_results().front(); 1178 ret->get_results().front() = appExpr->get_results().front()->clone(); 1179 1179 if ( appExpr->get_env() ) { 1180 1180 ret->set_env( appExpr->get_env() ); … … 1186 1186 } // if 1187 1187 } else if ( varExpr->get_var()->get_name() == "?++" || varExpr->get_var()->get_name() == "?--" ) { 1188 assert( appExpr->has_result() );1188 assert( ! appExpr->get_results().empty() ); 1189 1189 assert( appExpr->get_args().size() == 1 ); 1190 if ( Type *baseType = isPolyPtr( appExpr->get_result (), scopeTyVars, env ) ) {1191 Type *tempType = appExpr->get_result ()->clone();1190 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) { 1191 Type *tempType = appExpr->get_results().front()->clone(); 1192 1192 if ( env ) { 1193 1193 env->apply( tempType ); … … 1206 1206 } // if 1207 1207 } else if ( varExpr->get_var()->get_name() == "++?" || varExpr->get_var()->get_name() == "--?" ) { 1208 assert( appExpr->has_result() );1208 assert( ! appExpr->get_results().empty() ); 1209 1209 assert( appExpr->get_args().size() == 1 ); 1210 if ( Type *baseType = isPolyPtr( appExpr->get_result (), scopeTyVars, env ) ) {1210 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) { 1211 1211 return makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "++?" ); 1212 1212 } // if 1213 1213 } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) { 1214 assert( appExpr->has_result() );1214 assert( ! appExpr->get_results().empty() ); 1215 1215 assert( appExpr->get_args().size() == 2 ); 1216 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result (), scopeTyVars, env );1217 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result (), scopeTyVars, env );1216 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env ); 1217 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env ); 1218 1218 if ( baseType1 && baseType2 ) { 1219 1219 UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) ); 1220 1220 divide->get_args().push_back( appExpr ); 1221 1221 divide->get_args().push_back( new SizeofExpr( baseType1->clone() ) ); 1222 divide-> set_result( appExpr->get_result()->clone() );1222 divide->get_results().push_front( appExpr->get_results().front()->clone() ); 1223 1223 if ( appExpr->get_env() ) { 1224 1224 divide->set_env( appExpr->get_env() ); … … 1238 1238 } // if 1239 1239 } else if ( varExpr->get_var()->get_name() == "?+=?" || varExpr->get_var()->get_name() == "?-=?" ) { 1240 assert( appExpr->has_result() );1240 assert( ! appExpr->get_results().empty() ); 1241 1241 assert( appExpr->get_args().size() == 2 ); 1242 Type *baseType = isPolyPtr( appExpr->get_result (), scopeTyVars, env );1242 Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ); 1243 1243 if ( baseType ) { 1244 1244 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); … … 1266 1266 useRetval = oldUseRetval; 1267 1267 1268 assert( appExpr->get_function()->has_result() ); 1269 PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() ); 1270 FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() ); 1268 assert( ! appExpr->get_function()->get_results().empty() ); 1269 PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() ); 1270 assert( pointer ); 1271 FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() ); 1272 assert( function ); 1271 1273 1272 1274 if ( Expression *newExpr = handleIntrinsics( appExpr ) ) { … … 1306 1308 1307 1309 Expression *Pass1::mutate( UntypedExpr *expr ) { 1308 if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) {1310 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) { 1309 1311 if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) { 1310 1312 if ( name->get_name() == "*?" ) { … … 1320 1322 1321 1323 Expression *Pass1::mutate( AddressExpr *addrExpr ) { 1322 assert( addrExpr->get_arg()->has_result() && ! addrExpr->get_arg()->get_result()->isVoid() );1324 assert( ! addrExpr->get_arg()->get_results().empty() ); 1323 1325 1324 1326 bool needs = false; 1325 1327 if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) { 1326 if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) {1328 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) { 1327 1329 if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) { 1328 1330 if ( name->get_name() == "*?" ) { 1329 1331 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) { 1330 assert( appExpr->get_function()->has_result() ); 1331 PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() ); 1332 FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() ); 1332 assert( ! appExpr->get_function()->get_results().empty() ); 1333 PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() ); 1334 assert( pointer ); 1335 FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() ); 1336 assert( function ); 1333 1337 needs = needsAdapter( function, scopeTyVars ); 1334 1338 } // if … … 1339 1343 // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward 1340 1344 // out of the if condition. 1341 bool polytype = isPolyType( addrExpr->get_arg()->get_result (), scopeTyVars, env );1345 bool polytype = isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env ); 1342 1346 addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) ); 1343 1347 if ( polytype || needs ) { 1344 1348 Expression *ret = addrExpr->get_arg(); 1345 delete ret->get_result ();1346 ret-> set_result( addrExpr->get_result()->clone());1349 delete ret->get_results().front(); 1350 ret->get_results().front() = addrExpr->get_results().front()->clone(); 1347 1351 addrExpr->set_arg( 0 ); 1348 1352 delete addrExpr; … … 1382 1386 Statement * Pass1::mutate( ReturnStmt *returnStmt ) { 1383 1387 if ( retval && returnStmt->get_expr() ) { 1384 assert( returnStmt->get_expr()->has_result() && ! returnStmt->get_expr()->get_result()->isVoid() );1388 assert( ! returnStmt->get_expr()->get_results().empty() ); 1385 1389 // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous. 1386 1390 // if ( returnStmt->get_expr()->get_results().front()->get_isLvalue() ) { … … 1462 1466 // replace return statement with appropriate assignment to out parameter 1463 1467 Expression *retParm = new NameExpr( retval->get_name() ); 1464 retParm-> set_result( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );1468 retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) ); 1465 1469 assignExpr->get_args().push_back( retParm ); 1466 1470 assignExpr->get_args().push_back( returnStmt->get_expr() );
Note:
See TracChangeset
for help on using the changeset viewer.