Changeset 8cbe732 for src/GenPoly
- Timestamp:
- Oct 13, 2023, 7:13:21 PM (2 years ago)
- Branches:
- master
- Children:
- a97b9ed, bab2917
- Parents:
- 85034ed (diff), 0bf0b978 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/GenPoly
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.h
r85034ed r8cbe732 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Box.h -- 7 // Box.h -- Implement polymorphic function calls and types. 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:23:52 201713 // Update Count : 611 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Oct 6 13:37:00 2022 13 // Update Count : 7 14 14 // 15 15 … … 19 19 20 20 class Declaration; 21 namespace ast { 22 class TranslationUnit; 23 } 21 24 22 25 namespace GenPoly { 23 26 /// boxes polymorphic function calls 24 27 void box( std::list< Declaration* >& translationUnit ); 28 void box( ast::TranslationUnit & translationUnit ); 25 29 } // namespace GenPoly 26 30 -
src/GenPoly/InstantiateGeneric.h
r85034ed r8cbe732 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // InstantiateGeneric.h -- 7 // InstantiateGeneric.h -- Create concrete instances of generic types. 8 8 // 9 9 // Author : Aaron B. Moss … … 24 24 25 25 namespace GenPoly { 26 /// Replaces all generic types that have static layout with concrete 27 /// instantiations. Types with concrete values for otype parameters will be 28 /// template-expanded, while dtype and ftype parameters will be replaced by 29 /// the appropriate void type. 26 30 27 void instantiateGeneric( std::list< Declaration* > &translationUnit ); 31 28 void instantiateGeneric( ast::TranslationUnit & translationUnit ); 29 /// Replaces all generic types that have static layout with concrete 30 /// instantiations. Sized types are replaced with the concrete argument types 31 /// while unsized types are erased to a void type. 32 /// This pass can cause designators to ignore the pretty print option. 33 32 34 } // namespace GenPoly 33 35 -
src/GenPoly/InstantiateGenericNew.cpp
r85034ed r8cbe732 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // InstantiateGenericNew.cpp -- 7 // InstantiateGenericNew.cpp -- Create concrete instances of generic types. 8 8 // 9 9 // Author : Andrew Beach … … 335 335 ast::Expr const * FixDtypeStatic::postvisit( ast::MemberExpr const * expr ) { 336 336 ast::ptr<ast::Type> const & type = expr->aggregate->result; 337 if ( !isGenericType( type ) ) { 338 return expr; 339 } else if ( auto inst = type.as<ast::StructInstType>() ) { 340 return fixMemberExpr( inst, expr ); 337 if ( auto inst = type.as<ast::StructInstType>() ) { 338 if ( !inst->params.empty() ) return fixMemberExpr( inst, expr ); 341 339 } else if ( auto inst = type.as<ast::UnionInstType>() ) { 342 return fixMemberExpr( inst, expr );340 if ( !inst->params.empty() ) return fixMemberExpr( inst, expr ); 343 341 } 344 342 return expr; … … 451 449 ast::Expr const * postvisit( ast::MemberExpr const * expr ); 452 450 ast::Expr const * postvisit( ast::Expr const * expr ); 453 void previsit( ast::ParseNode const * node ); 454 451 ast::Designation const * postvisit( ast::Designation const * ); 452 453 void previsit( ast::ParseNode const * node ) { 454 GuardValue( location ) = &node->location; 455 } 455 456 void previsit( ast::FunctionType const * ) { 456 457 GuardValue( inFunctionType ) = true; … … 628 629 } 629 630 630 void GenericInstantiator::previsit( ast::ParseNode const * node ) { 631 GuardValue( location ) = &node->location; 631 // This attempts to figure out what the final name of the field will be. 632 // Pretty printing can cause this to become incorrect. 633 std::string getPrintName( ast::DeclWithType const * decl ) { 634 return ( decl->linkage.is_mangled ) 635 ? decl->scopedMangleName() : decl->name; 636 } 637 638 ast::Designation const * GenericInstantiator::postvisit( 639 ast::Designation const * designation ) { 640 // Disconnect designator names from their fields. 641 // It is now incorrect to point at the generic definition where the used 642 // type now is replaced with a concrete instance. Ideally, new variable 643 // expressions would point at fields in the concrete instances, but that 644 // is work and that information should not be needed this late in 645 // compilation. 646 647 // Modify all designations, even if not needed. 648 auto mutNode = mutate( designation ); 649 for ( ast::ptr<ast::Expr> & designator : mutNode->designators ) { 650 if ( auto var = designator.as<ast::VariableExpr>() ) { 651 designator = new ast::NameExpr( 652 var->location, getPrintName( var->var ) ); 653 } 654 } 655 return mutNode; 632 656 } 633 657 -
src/GenPoly/module.mk
r85034ed r8cbe732 22 22 23 23 SRC += $(SRC_GENPOLY) \ 24 GenPoly/BoxNew.cpp \ 24 25 GenPoly/Box.cc \ 25 26 GenPoly/Box.h \
Note:
See TracChangeset
for help on using the changeset viewer.