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