Changes in src/GenPoly/Box.cc [2ae171d8:08fc48f]
- File:
-
- 1 edited
-
src/GenPoly/Box.cc (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r2ae171d8 r08fc48f 25 25 26 26 #include "Box.h" 27 28 #include "CodeGen/OperatorTable.h"29 27 #include "Common/ScopedMap.h" // for ScopedMap, ScopedMap<>::iter... 30 28 #include "Common/SemanticError.h" // for SemanticError … … 566 564 // To compound the issue, the right side can be *x, etc. because of lvalue-returning functions 567 565 if ( UntypedExpr * assign = dynamic_cast< UntypedExpr * >( commaExpr->get_arg1() ) ) { 568 if ( CodeGen::isAssignment( InitTweak::getFunctionName( assign ) ) ) {566 if ( InitTweak::isAssignment( InitTweak::getFunctionName( assign ) ) ) { 569 567 assert( assign->get_args().size() == 2 ); 570 568 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( assign->get_args().back() ) ) { … … 606 604 } 607 605 } else { 608 throw SemanticError( "Cannot pass non-struct type for generic struct : ", argBaseType);606 throw SemanticError( "Cannot pass non-struct type for generic struct" ); 609 607 } 610 608 } … … 756 754 Type * newType = arg->get_result()->clone(); 757 755 if ( env ) env->apply( newType ); 758 std:: unique_ptr<Type> manager( newType );756 std::auto_ptr<Type> manager( newType ); 759 757 if ( isPolyType( newType ) ) { 760 758 // if the argument's type is polymorphic, we don't need to box again! … … 774 772 newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right??? 775 773 stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) ); 776 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); // TODO: why doesn't this just use initialization syntax?774 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 777 775 assign->get_args().push_back( new VariableExpr( newObj ) ); 778 776 assign->get_args().push_back( arg ); … … 1021 1019 } // if 1022 1020 if ( baseType1 || baseType2 ) { 1023 delete ret->get_result();1024 1021 ret->set_result( appExpr->get_result()->clone() ); 1025 1022 if ( appExpr->get_env() ) { … … 1035 1032 assert( ! appExpr->get_args().empty() ); 1036 1033 if ( isPolyType( appExpr->get_result(), scopeTyVars, env ) ) { 1037 // remove dereference from polymorphic types since they are boxed.1038 1034 Expression *ret = appExpr->get_args().front(); 1039 // fix expr type to remove pointer1040 1035 delete ret->get_result(); 1041 1036 ret->set_result( appExpr->get_result()->clone() ); … … 1127 1122 1128 1123 assert( appExpr->get_function()->has_result() ); 1129 FunctionType * function = getFunctionType( appExpr->get_function()->get_result() );1130 assertf( function, "ApplicationExpr has non-function type: %s", toString( appExpr->get_function()->get_result() ).c_str() );1124 PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() ); 1125 FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() ); 1131 1126 1132 1127 if ( Expression *newExpr = handleIntrinsics( appExpr ) ) { … … 1205 1200 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) { 1206 1201 assert( appExpr->get_function()->has_result() ); 1207 FunctionType *function = getFunctionType( appExpr->get_function()->get_result() );1208 assert( function);1202 PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() ); 1203 FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() ); 1209 1204 needs = needsAdapter( function, scopeTyVars ); 1210 1205 } // if … … 1215 1210 // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward 1216 1211 // out of the if condition. 1212 bool polytype = isPolyType( addrExpr->get_arg()->get_result(), scopeTyVars, env ); 1217 1213 addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) ); 1218 // ... but must happen after mutate, since argument might change (e.g. intrinsic *?, ?[?]) - re-evaluate above comment1219 bool polytype = isPolyType( addrExpr->get_arg()->get_result(), scopeTyVars, env );1220 1214 if ( polytype || needs ) { 1221 1215 Expression *ret = addrExpr->get_arg(); … … 1284 1278 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 1285 1279 std::string adapterName = makeAdapterName( mangleName ); 1286 // adapter may not be used in body, pass along with unused attribute. 1287 paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) ); 1280 paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0 ) ); 1288 1281 adaptersDone.insert( adaptersDone.begin(), mangleName ); 1289 1282 } … … 1391 1384 std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin(); 1392 1385 std::list< DeclarationWithType *> inferredParams; 1393 // size/align/offset parameters may not be used in body, pass along with unused attribute. 1394 ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, 1395 { new Attribute( "unused" ) } ); 1386 ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 ); 1396 1387 ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0, 1397 1388 new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 ); … … 1416 1407 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) { 1417 1408 // *assert = (*assert)->acceptMutator( *this ); 1418 // assertion parameters may not be used in body, pass along with unused attribute.1419 (*assert)->get_attributes().push_back( new Attribute( "unused" ) );1420 1409 inferredParams.push_back( *assert ); 1421 1410 }
Note:
See TracChangeset
for help on using the changeset viewer.