Changeset 906e24d for src/GenPoly
- Timestamp:
- Sep 15, 2016, 10:17:16 AM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- aa8f9df
- Parents:
- 96a10cdd
- git-author:
- Rob Schluntz <rschlunt@…> (09/14/16 22:32:34)
- git-committer:
- Rob Schluntz <rschlunt@…> (09/15/16 10:17:16)
- Location:
- src/GenPoly
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r96a10cdd r906e24d 782 782 783 783 // add size/align for generic types to parameter list 784 if ( appExpr->get_function()->get_results().empty() ) return;785 FunctionType *funcType = getFunctionType( appExpr->get_function()->get_result s().front() );784 if ( ! appExpr->get_function()->has_result() ) return; 785 FunctionType *funcType = getFunctionType( appExpr->get_function()->get_result() ); 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 || fnArgBase->get_results().empty() ) continue;802 passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_result s().front(), arg, exprTyVars, seenTypes );801 if ( ! fnArgBase ) continue; // xxx - previously had check for non-empty fnArgBase results 802 passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_result(), 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 ) ); 892 appExpr->set_function( new NameExpr( adapterName ) ); // xxx - result is never set on NameExpr 893 893 894 894 return ret; … … 896 896 897 897 void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) { 898 assert( ! arg->get_results().empty() );898 assert( arg->has_result() ); 899 899 if ( isPolyType( param, exprTyVars ) ) { 900 if ( isPolyType( arg->get_result s().front() ) ) {900 if ( isPolyType( arg->get_result() ) ) { 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 s().front()->get_isLvalue() ) {903 } else if ( arg->get_result()->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-> get_results().push_back( arg->get_type()->clone() );989 deref->set_result( 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-> get_results().front() = appExpr->get_results().front()->clone();1126 addAssign->set_result( appExpr->get_result()->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->get_results().empty() );1140 assert( appExpr->has_result() ); 1141 1141 assert( appExpr->get_args().size() == 2 ); 1142 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result s().front(), scopeTyVars, env );1143 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result s().front(), scopeTyVars, env );1142 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env ); 1143 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result(), 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-> get_results().push_front( appExpr->get_results().front()->clone() );1163 ret->set_result( appExpr->get_result()->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->get_results().empty() );1173 assert( appExpr->has_result() ); 1174 1174 assert( ! appExpr->get_args().empty() ); 1175 if ( isPolyType( appExpr->get_result s().front(), scopeTyVars, env ) ) {1175 if ( isPolyType( appExpr->get_result(), scopeTyVars, env ) ) { 1176 1176 Expression *ret = appExpr->get_args().front(); 1177 delete ret->get_result s().front();1178 ret-> get_results().front() = appExpr->get_results().front()->clone();1177 delete ret->get_result(); 1178 ret->set_result( appExpr->get_result()->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->get_results().empty() );1188 assert( appExpr->has_result() ); 1189 1189 assert( appExpr->get_args().size() == 1 ); 1190 if ( Type *baseType = isPolyPtr( appExpr->get_result s().front(), scopeTyVars, env ) ) {1191 Type *tempType = appExpr->get_result s().front()->clone();1190 if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) { 1191 Type *tempType = appExpr->get_result()->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->get_results().empty() );1208 assert( appExpr->has_result() ); 1209 1209 assert( appExpr->get_args().size() == 1 ); 1210 if ( Type *baseType = isPolyPtr( appExpr->get_result s().front(), scopeTyVars, env ) ) {1210 if ( Type *baseType = isPolyPtr( appExpr->get_result(), 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->get_results().empty() );1214 assert( appExpr->has_result() ); 1215 1215 assert( appExpr->get_args().size() == 2 ); 1216 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result s().front(), scopeTyVars, env );1217 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result s().front(), scopeTyVars, env );1216 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env ); 1217 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result(), 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-> get_results().push_front( appExpr->get_results().front()->clone() );1222 divide->set_result( appExpr->get_result()->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->get_results().empty() );1240 assert( appExpr->has_result() ); 1241 1241 assert( appExpr->get_args().size() == 2 ); 1242 Type *baseType = isPolyPtr( appExpr->get_result s().front(), scopeTyVars, env );1242 Type *baseType = isPolyPtr( appExpr->get_result(), 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()->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 ); 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() ); 1273 1271 1274 1272 if ( Expression *newExpr = handleIntrinsics( appExpr ) ) { … … 1308 1306 1309 1307 Expression *Pass1::mutate( UntypedExpr *expr ) { 1310 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {1308 if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) { 1311 1309 if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) { 1312 1310 if ( name->get_name() == "*?" ) { … … 1322 1320 1323 1321 Expression *Pass1::mutate( AddressExpr *addrExpr ) { 1324 assert( ! addrExpr->get_arg()->get_results().empty() );1322 assert( addrExpr->get_arg()->has_result() && ! addrExpr->get_arg()->get_result()->isVoid() ); 1325 1323 1326 1324 bool needs = false; 1327 1325 if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) { 1328 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {1326 if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) { 1329 1327 if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) { 1330 1328 if ( name->get_name() == "*?" ) { 1331 1329 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) { 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 ); 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() ); 1337 1333 needs = needsAdapter( function, scopeTyVars ); 1338 1334 } // if … … 1343 1339 // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward 1344 1340 // out of the if condition. 1345 bool polytype = isPolyType( addrExpr->get_arg()->get_result s().front(), scopeTyVars, env );1341 bool polytype = isPolyType( addrExpr->get_arg()->get_result(), scopeTyVars, env ); 1346 1342 addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) ); 1347 1343 if ( polytype || needs ) { 1348 1344 Expression *ret = addrExpr->get_arg(); 1349 delete ret->get_result s().front();1350 ret-> get_results().front() = addrExpr->get_results().front()->clone();1345 delete ret->get_result(); 1346 ret->set_result( addrExpr->get_result()->clone() ); 1351 1347 addrExpr->set_arg( 0 ); 1352 1348 delete addrExpr; … … 1386 1382 Statement * Pass1::mutate( ReturnStmt *returnStmt ) { 1387 1383 if ( retval && returnStmt->get_expr() ) { 1388 assert( ! returnStmt->get_expr()->get_results().empty() );1384 assert( returnStmt->get_expr()->has_result() && ! returnStmt->get_expr()->get_result()->isVoid() ); 1389 1385 // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous. 1390 1386 // if ( returnStmt->get_expr()->get_results().front()->get_isLvalue() ) { … … 1466 1462 // replace return statement with appropriate assignment to out parameter 1467 1463 Expression *retParm = new NameExpr( retval->get_name() ); 1468 retParm-> get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );1464 retParm->set_result( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) ); 1469 1465 assignExpr->get_args().push_back( retParm ); 1470 1466 assignExpr->get_args().push_back( returnStmt->get_expr() ); -
src/GenPoly/Lvalue.cc
r96a10cdd r906e24d 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Lvalue.cc -- 7 // Lvalue.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 41 41 public: 42 42 Pass1(); 43 43 44 44 virtual Expression *mutate( ApplicationExpr *appExpr ); 45 45 virtual Statement *mutate( ReturnStmt *appExpr ); … … 99 99 appExpr->get_function()->acceptMutator( *this ); 100 100 mutateAll( appExpr->get_args(), *this ); 101 102 assert( ! appExpr->get_function()->get_results().empty() );103 101 104 PointerType *pointer = dynamic_cast< PointerType* >( appExpr->get_function()->get_results().front() ); 105 assert( pointer ); 106 FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ); 107 assert( function ); 102 PointerType *pointer = safe_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() ); 103 FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() ); 108 104 109 105 Type *funType = isLvalueRet( function ); 110 106 if ( funType && ! isIntrinsicApp( appExpr ) ) { 111 107 Expression *expr = appExpr; 112 Type *appType = appExpr->get_result s().front();108 Type *appType = appExpr->get_result(); 113 109 if ( isPolyType( funType ) && ! isPolyType( appType ) ) { 114 110 // make sure cast for polymorphic type is inside dereference … … 116 112 } 117 113 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 118 deref-> get_results().push_back( appType->clone() );119 appExpr-> get_results().front() = new PointerType( Type::Qualifiers(), appType);114 deref->set_result( appType->clone() ); 115 appExpr->set_result( new PointerType( Type::Qualifiers(), appType ) ); 120 116 deref->get_args().push_back( expr ); 121 117 return deref; … … 127 123 Statement * Pass1::mutate(ReturnStmt *retStmt) { 128 124 if ( retval && retStmt->get_expr() ) { 129 assert( ! retStmt->get_expr()->get_results().empty() ); 130 if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) { 125 if ( retStmt->get_expr()->get_result()->get_isLvalue() ) { 131 126 // ***** Code Removal ***** because casts may be stripped already 132 127 … … 155 150 retParm->set_type( new PointerType( Type::Qualifiers(), retParm->get_type() ) ); 156 151 } // if 157 152 158 153 Visitor::visit( funType ); 159 154 } -
src/GenPoly/Specialize.cc
r96a10cdd r906e24d 147 147 148 148 Expression * Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) { 149 assert( ! actual->get_results().empty() ); // using front, should have this assert150 if ( needsSpecialization( formalType, actual->get_result s().front(), env ) ) {149 assert( actual->has_result() ); 150 if ( needsSpecialization( formalType, actual->get_result(), env ) ) { 151 151 FunctionType *funType; 152 152 if ( ( funType = getFunctionType( formalType ) ) ) { … … 171 171 void Specialize::handleExplicitParams( ApplicationExpr *appExpr ) { 172 172 // create thunks for the explicit parameters 173 assert( ! appExpr->get_function()->get_results().empty() );174 FunctionType *function = getFunctionType( appExpr->get_function()->get_result s().front() );173 assert( appExpr->get_function()->has_result() ); 174 FunctionType *function = getFunctionType( appExpr->get_function()->get_result() ); 175 175 assert( function ); 176 176 std::list< DeclarationWithType* >::iterator formal; … … 200 200 Expression * Specialize::mutate( AddressExpr *addrExpr ) { 201 201 addrExpr->get_arg()->acceptMutator( *this ); 202 assert( ! addrExpr->get_results().empty() );203 addrExpr->set_arg( doSpecialization( addrExpr->get_result s().front(), addrExpr->get_arg() ) );202 assert( addrExpr->has_result() ); 203 addrExpr->set_arg( doSpecialization( addrExpr->get_result(), addrExpr->get_arg() ) ); 204 204 return addrExpr; 205 205 } … … 207 207 Expression * Specialize::mutate( CastExpr *castExpr ) { 208 208 castExpr->get_arg()->acceptMutator( *this ); 209 if ( castExpr->get_result s().empty() ) {209 if ( castExpr->get_result()->isVoid() ) { 210 210 // can't specialize if we don't have a return value 211 211 return castExpr; 212 212 } 213 Expression *specialized = doSpecialization( castExpr->get_result s().front(), castExpr->get_arg() );213 Expression *specialized = doSpecialization( castExpr->get_result(), castExpr->get_arg() ); 214 214 if ( specialized != castExpr->get_arg() ) { 215 215 // assume here that the specialization incorporates the cast
Note:
See TracChangeset
for help on using the changeset viewer.