Changes in src/GenPoly/Box.cc [acd7c5dd:83794e1]
- File:
-
- 1 edited
-
src/GenPoly/Box.cc (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
racd7c5dd r83794e1 27 27 #include "Box.h" 28 28 #include "DeclMutator.h" 29 #include " Lvalue.h"29 #include "PolyMutator.h" 30 30 #include "FindFunction.h" 31 #include "PolyMutator.h"32 31 #include "ScopedSet.h" 33 32 #include "ScrubTyVars.h" … … 56 55 #include "Common/UniqueName.h" 57 56 #include "Common/utility.h" 57 58 #include "CodeGen/OperatorTable.h" 58 59 59 60 #include "InitTweak/InitTweak.h" … … 203 204 }; 204 205 205 /// Replaces initialization of polymorphic values with alloca, declaration of dtype/ftype with appropriate void expression, sizeof expressions of polymorphic types with the proper variable, and strips fields from generic struct declarations.206 /// Replaces initialization of polymorphic values with alloca, declaration of dtype/ftype with appropriate void expression, and sizeof expressions of polymorphic types with the proper variable 206 207 class Pass3 final : public PolyMutator { 207 208 public: … … 211 212 using PolyMutator::mutate; 212 213 virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override; 213 virtual Declaration *mutate( StructDecl *structDecl ) override;214 virtual Declaration *mutate( UnionDecl *unionDecl ) override;215 214 virtual ObjectDecl *mutate( ObjectDecl *objectDecl ) override; 216 215 virtual TypedefDecl *mutate( TypedefDecl *objectDecl ) override; … … 570 569 // To compound the issue, the right side can be *x, etc. because of lvalue-returning functions 571 570 if ( UntypedExpr * assign = dynamic_cast< UntypedExpr * >( commaExpr->get_arg1() ) ) { 572 if ( InitTweak::isAssignment( InitTweak::getFunctionName( assign ) ) ) {571 if ( CodeGen::isAssignment( InitTweak::getFunctionName( assign ) ) ) { 573 572 assert( assign->get_args().size() == 2 ); 574 573 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( assign->get_args().back() ) ) { … … 610 609 } 611 610 } else { 612 throw SemanticError( "Cannot pass non-struct type for generic struct ");611 throw SemanticError( "Cannot pass non-struct type for generic struct: ", argBaseType ); 613 612 } 614 613 } … … 758 757 assertf( arg->has_result(), "arg does not have result: %s", toString( arg ).c_str() ); 759 758 if ( isPolyType( param, exprTyVars ) ) { 760 Type * newType = arg->get_result()->clone(); 761 if ( env ) env->apply( newType ); 762 std::auto_ptr<Type> manager( newType ); 763 if ( isPolyType( newType ) ) { 759 if ( isPolyType( arg->get_result() ) ) { 764 760 // if the argument's type is polymorphic, we don't need to box again! 765 761 return; 766 } else if ( arg->get_result()->get_lvalue() ) { 767 // argument expression may be CFA lvalue, but not C lvalue -- apply generalizedLvalue transformations. 768 arg = generalizedLvalue( new AddressExpr( arg ) ); 762 } else if ( arg->get_result()->get_lvalue() ) { // xxx - is this still right?? 763 // xxx - dynamic_cast<ReferenceType *>( arg->get_result() )?? 764 // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue) 765 // xxx - need to test that this code is still reachable 766 if ( CommaExpr *commaArg = dynamic_cast< CommaExpr* >( arg ) ) { 767 commaArg->set_arg2( new AddressExpr( commaArg->get_arg2() ) ); 768 } else { 769 arg = new AddressExpr( arg ); 770 } 769 771 if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) { 770 772 // silence warnings by casting boxed parameters when the actual type does not match up with the formal type. … … 1025 1027 } // if 1026 1028 if ( baseType1 || baseType2 ) { 1029 delete ret->get_result(); 1027 1030 ret->set_result( appExpr->get_result()->clone() ); 1028 1031 if ( appExpr->get_env() ) { … … 1038 1041 assert( ! appExpr->get_args().empty() ); 1039 1042 if ( isPolyType( appExpr->get_result(), scopeTyVars, env ) ) { 1043 // remove dereference from polymorphic types since they are boxed. 1040 1044 Expression *ret = appExpr->get_args().front(); 1045 // fix expr type to remove pointer 1041 1046 delete ret->get_result(); 1042 1047 ret->set_result( appExpr->get_result()->clone() ); … … 1128 1133 1129 1134 assert( appExpr->get_function()->has_result() ); 1130 PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() );1131 FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() );1135 FunctionType * function = getFunctionType( appExpr->get_function()->get_result() ); 1136 assertf( function, "ApplicationExpr has non-function type: %s", toString( appExpr->get_function()->get_result() ).c_str() ); 1132 1137 1133 1138 if ( Expression *newExpr = handleIntrinsics( appExpr ) ) { … … 1206 1211 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) { 1207 1212 assert( appExpr->get_function()->has_result() ); 1208 PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() );1209 FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base());1213 FunctionType *function = getFunctionType( appExpr->get_function()->get_result() ); 1214 assert( function ); 1210 1215 needs = needsAdapter( function, scopeTyVars ); 1211 1216 } // if … … 1216 1221 // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward 1217 1222 // out of the if condition. 1223 addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) ); 1224 // ... but must happen after mutate, since argument might change (e.g. intrinsic *?, ?[?]) - re-evaluate above comment 1218 1225 bool polytype = isPolyType( addrExpr->get_arg()->get_result(), scopeTyVars, env ); 1219 addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );1220 1226 if ( polytype || needs ) { 1221 1227 Expression *ret = addrExpr->get_arg(); … … 1284 1290 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 1285 1291 std::string adapterName = makeAdapterName( mangleName ); 1286 paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0 ) ); 1292 // adapter may not be used in body, pass along with unused attribute. 1293 paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) ); 1287 1294 adaptersDone.insert( adaptersDone.begin(), mangleName ); 1288 1295 } … … 1390 1397 std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin(); 1391 1398 std::list< DeclarationWithType *> inferredParams; 1392 ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 ); 1399 // size/align/offset parameters may not be used in body, pass along with unused attribute. 1400 ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, 1401 { new Attribute( "unused" ) } ); 1393 1402 ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0, 1394 1403 new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 ); … … 1413 1422 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) { 1414 1423 // *assert = (*assert)->acceptMutator( *this ); 1424 // assertion parameters may not be used in body, pass along with unused attribute. 1425 (*assert)->get_attributes().push_back( new Attribute( "unused" ) ); 1415 1426 inferredParams.push_back( *assert ); 1416 1427 } … … 1749 1760 1750 1761 Expression *PolyGenericCalculator::mutate( SizeofExpr *sizeofExpr ) { 1751 Type *ty = sizeofExpr->get_ isType() ? sizeofExpr->get_type() : sizeofExpr->get_expr()->get_result();1762 Type *ty = sizeofExpr->get_type(); 1752 1763 if ( findGeneric( ty ) ) { 1753 1764 Expression *ret = new NameExpr( sizeofName( mangleType( ty ) ) ); … … 1759 1770 1760 1771 Expression *PolyGenericCalculator::mutate( AlignofExpr *alignofExpr ) { 1761 Type *ty = alignofExpr->get_ isType() ? alignofExpr->get_type() : alignofExpr->get_expr()->get_result();1772 Type *ty = alignofExpr->get_type(); 1762 1773 if ( findGeneric( ty ) ) { 1763 1774 Expression *ret = new NameExpr( alignofName( mangleType( ty ) ) ); … … 1869 1880 } 1870 1881 1871 /// Strips the members from a generic aggregate1872 void stripGenericMembers(AggregateDecl* decl) {1873 if ( ! decl->get_parameters().empty() ) decl->get_members().clear();1874 }1875 1876 Declaration *Pass3::mutate( StructDecl *structDecl ) {1877 stripGenericMembers( structDecl );1878 return structDecl;1879 }1880 1881 Declaration *Pass3::mutate( UnionDecl *unionDecl ) {1882 stripGenericMembers( unionDecl );1883 return unionDecl;1884 }1885 1886 1882 TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) { 1887 1883 // Initializer *init = 0;
Note:
See TracChangeset
for help on using the changeset viewer.