Changeset 9cdfb4d0 for src/GenPoly
- Timestamp:
- Jan 22, 2018, 3:09:01 PM (8 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, stuck-waitfor-destruct, with_gc
- Children:
- e23d20b
- Parents:
- 326cd2b (diff), 4bf3b2b (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:
-
- 4 edited
-
Box.cc (modified) (4 diffs)
-
Lvalue.cc (modified) (7 diffs)
-
ScrubTyVars.cc (modified) (6 diffs)
-
ScrubTyVars.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r326cd2b r9cdfb4d0 302 302 Expression *makeOp( const std::string &name, Expression *arg ) { 303 303 UntypedExpr *expr = new UntypedExpr( new NameExpr( name ) ); 304 expr-> get_args().push_back( arg );304 expr->args.push_back( arg ); 305 305 return expr; 306 306 } … … 309 309 Expression *makeOp( const std::string &name, Expression *lhs, Expression *rhs ) { 310 310 UntypedExpr *expr = new UntypedExpr( new NameExpr( name ) ); 311 expr-> get_args().push_back( lhs );312 expr-> get_args().push_back( rhs );311 expr->args.push_back( lhs ); 312 expr->args.push_back( rhs ); 313 313 return expr; 314 314 } … … 316 316 /// Returns the dereference of a local pointer variable 317 317 Expression *derefVar( ObjectDecl *var ) { 318 return makeOp( "*?",new VariableExpr( var ) );318 return UntypedExpr::createDeref( new VariableExpr( var ) ); 319 319 } 320 320 … … 831 831 if ( ! isPolyType( arg->get_type() ) ) { 832 832 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 833 deref->get_args().push_back( new CastExpr( new VariableExpr( param ), new PointerType( Type::Qualifiers(), arg->get_type()->clone() ) ) ); 834 deref->set_result( arg->get_type()->clone() ); 833 deref->args.push_back( new CastExpr( new VariableExpr( param ), new PointerType( Type::Qualifiers(), arg->get_type()->clone() ) ) ); 834 deref->result = arg->get_type()->clone(); 835 deref->result->set_lvalue( true ); 835 836 return deref; 836 837 } // if -
src/GenPoly/Lvalue.cc
r326cd2b r9cdfb4d0 47 47 if ( SymTab::dereferenceOperator ) { 48 48 VariableExpr * deref = new VariableExpr( SymTab::dereferenceOperator ); 49 deref-> set_result( new PointerType( Type::Qualifiers(), deref->get_result() ));50 Type * base = InitTweak::getPointerBase( arg-> get_result());51 assertf( base, "expected pointer type in dereference (type was %s)", toString( arg-> get_result()).c_str() );49 deref->result = new PointerType( Type::Qualifiers(), deref->result ); 50 Type * base = InitTweak::getPointerBase( arg->result ); 51 assertf( base, "expected pointer type in dereference (type was %s)", toString( arg->result ).c_str() ); 52 52 ApplicationExpr * ret = new ApplicationExpr( deref, { arg } ); 53 delete ret-> get_result();54 ret-> set_result( base->clone());55 ret-> get_result()->set_lvalue( true );53 delete ret->result; 54 ret->result = base->clone(); 55 ret->result->set_lvalue( true ); 56 56 return ret; 57 57 } else { … … 308 308 int diff = depth1-depth2; 309 309 if ( diff == 0 ) { 310 // conversion between references of the same depth 310 311 assertf( depth1 == depth2, "non-intrinsic reference with cast of reference to reference not yet supported: %d %d %s", depth1, depth2, toString( castExpr ).c_str() ); 311 312 PRINT( std::cerr << castExpr << std::endl; ) 312 313 return castExpr; 313 314 } else if ( diff < 0 ) { 314 Expression * ret = castExpr->get_arg(); 315 // conversion from reference to reference with less depth (e.g. int && -> int &): add dereferences 316 Expression * ret = castExpr->arg; 315 317 for ( int i = 0; i < diff; ++i ) { 316 318 ret = mkDeref( ret ); 317 319 } 318 ret->set_env( castExpr->get_env() ); 319 delete ret->get_result(); 320 ret->set_result( castExpr->get_result() ); 321 castExpr->set_env( nullptr ); 322 castExpr->set_arg( nullptr ); 323 castExpr->set_result( nullptr ); 320 ret->env = castExpr->env; 321 delete ret->result; 322 ret->result = castExpr->result; 323 ret->result->set_lvalue( true ); // ensure result is lvalue 324 castExpr->env = nullptr; 325 castExpr->arg = nullptr; 326 castExpr->result = nullptr; 324 327 delete castExpr; 325 328 return ret; 326 329 } else if ( diff > 0 ) { 327 Expression * ret = castExpr->get_arg(); 330 // conversion from reference to reference with more depth (e.g. int & -> int &&): add address-of 331 Expression * ret = castExpr->arg; 328 332 for ( int i = 0; i < diff; ++i ) { 329 333 ret = new AddressExpr( ret ); 330 334 } 331 ret-> set_env( castExpr->get_env() );332 delete ret-> get_result();333 ret-> set_result( castExpr->get_result() );334 castExpr-> set_env( nullptr );335 castExpr-> set_arg( nullptr );336 castExpr-> set_result( nullptr );335 ret->env = castExpr->env; 336 delete ret->result; 337 ret->result = castExpr->result; 338 castExpr->env = nullptr; 339 castExpr->arg = nullptr; 340 castExpr->result = nullptr; 337 341 delete castExpr; 338 342 return ret; … … 342 346 PRINT( std::cerr << castExpr << std::endl; ) 343 347 return castExpr; 344 } else if ( castExpr-> get_arg()->get_result()->get_lvalue() ) {348 } else if ( castExpr->arg->result->get_lvalue() ) { 345 349 // conversion from lvalue to reference 346 350 // xxx - keep cast, but turn into pointer cast?? … … 348 352 PRINT( 349 353 std::cerr << "convert lvalue to reference -- &" << std::endl; 350 std::cerr << castExpr-> get_arg()<< std::endl;354 std::cerr << castExpr->arg << std::endl; 351 355 ) 352 AddressExpr * ret = new AddressExpr( castExpr-> get_arg());353 if ( refType-> get_base()->get_qualifiers() != castExpr->get_arg()->get_result()->get_qualifiers() ) {356 AddressExpr * ret = new AddressExpr( castExpr->arg ); 357 if ( refType->base->get_qualifiers() != castExpr->arg->result->get_qualifiers() ) { 354 358 // must keep cast if cast-to type is different from the actual type 355 castExpr-> set_arg( ret );359 castExpr->arg = ret; 356 360 return castExpr; 357 361 } 358 ret-> set_env( castExpr->get_env() );359 delete ret-> get_result();360 ret-> set_result( castExpr->get_result() );361 castExpr-> set_env( nullptr );362 castExpr-> set_arg( nullptr );363 castExpr-> set_result( nullptr );362 ret->env = castExpr->env; 363 delete ret->result; 364 ret->result = castExpr->result; 365 castExpr->env = nullptr; 366 castExpr->arg = nullptr; 367 castExpr->result = nullptr; 364 368 delete castExpr; 365 369 return ret; … … 368 372 } 369 373 assertf( false, "Only conversions to reference from lvalue are currently supported: %s", toString( castExpr ).c_str() ); 370 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( castExpr-> get_arg()->get_result()) ) {374 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( castExpr->arg->result ) ) { 371 375 (void)refType; 372 376 // conversion from reference to rvalue … … 375 379 std::cerr << "was = " << castExpr << std::endl; 376 380 ) 377 Expression * ret = castExpr-> get_arg();378 TypeSubstitution * env = castExpr-> get_env();381 Expression * ret = castExpr->arg; 382 TypeSubstitution * env = castExpr->env; 379 383 castExpr->set_env( nullptr ); 380 384 if ( ! isIntrinsicReference( ret ) ) { … … 382 386 ret = mkDeref( ret ); 383 387 } 384 if ( ResolvExpr::typesCompatibleIgnoreQualifiers( castExpr-> get_result(), castExpr->get_arg()->get_result()->stripReferences(), SymTab::Indexer() ) ) {388 if ( ResolvExpr::typesCompatibleIgnoreQualifiers( castExpr->result, castExpr->arg->result->stripReferences(), SymTab::Indexer() ) ) { 385 389 // can remove cast if types are compatible, changing expression type to value type 386 ret->set_result( castExpr->get_result()->clone() ); 387 castExpr->set_arg( nullptr ); 390 ret->result = castExpr->result->clone(); 391 ret->result->set_lvalue( true ); // ensure result is lvalue 392 castExpr->arg = nullptr; 388 393 delete castExpr; 389 394 } else { 390 395 // must keep cast if types are different 391 castExpr-> set_arg( ret );396 castExpr->arg = ret; 392 397 ret = castExpr; 393 398 } -
src/GenPoly/ScrubTyVars.cc
r326cd2b r9cdfb4d0 25 25 26 26 namespace GenPoly { 27 Type * ScrubTyVars:: mutate( TypeInstType *typeInst ) {27 Type * ScrubTyVars::postmutate( TypeInstType * typeInst ) { 28 28 if ( ! tyVars ) { 29 29 if ( typeInst->get_isFtype() ) { … … 31 31 return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); 32 32 } else { 33 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) );33 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); 34 34 delete typeInst; 35 35 return ret; … … 37 37 } 38 38 39 TyVarMap::const_iterator tyVar = tyVars->find( typeInst-> get_name());39 TyVarMap::const_iterator tyVar = tyVars->find( typeInst->name ); 40 40 if ( tyVar != tyVars->end() ) { 41 41 switch ( tyVar->second.kind ) { … … 43 43 case TypeDecl::Ttype: 44 44 { 45 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) );45 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); 46 46 delete typeInst; 47 47 return ret; … … 55 55 } 56 56 57 Type * ScrubTyVars::mutateAggregateType( Type * ty ) {57 Type * ScrubTyVars::mutateAggregateType( Type * ty ) { 58 58 if ( shouldScrub( ty ) ) { 59 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) );59 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) ); 60 60 delete ty; 61 61 return ret; … … 64 64 } 65 65 66 Type * ScrubTyVars:: mutate( StructInstType *structInst ) {66 Type * ScrubTyVars::postmutate( StructInstType * structInst ) { 67 67 return mutateAggregateType( structInst ); 68 68 } 69 69 70 Type * ScrubTyVars:: mutate( UnionInstType *unionInst ) {70 Type * ScrubTyVars::postmutate( UnionInstType * unionInst ) { 71 71 return mutateAggregateType( unionInst ); 72 72 } 73 73 74 Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) { 74 void ScrubTyVars::primeBaseScrub( Type * type ) { 75 // need to determine whether type needs to be scrubbed to determine whether 76 // automatic recursion is necessary 77 if ( Type * t = shouldScrub( type ) ) { 78 visit_children = false; 79 GuardValue( dynType ); 80 dynType = t; 81 } 82 } 83 84 Expression * ScrubTyVars::postmutate( SizeofExpr * szeof ) { 75 85 // sizeof( T ) => _sizeof_T parameter, which is the size of T 76 if ( Type *dynType = shouldScrub( szeof->get_type() )) {86 if ( dynType ) { 77 87 Expression *expr = new NameExpr( sizeofName( mangleType( dynType ) ) ); 78 88 return expr; 79 } else {80 return Mutator::mutate( szeof );81 89 } // if 90 return szeof; 82 91 } 83 92 84 Expression * ScrubTyVars:: mutate( AlignofExpr *algnof ) {93 Expression * ScrubTyVars::postmutate( AlignofExpr * algnof ) { 85 94 // alignof( T ) => _alignof_T parameter, which is the alignment of T 86 if ( Type *dynType = shouldScrub( algnof->get_type() )) {95 if ( dynType ) { 87 96 Expression *expr = new NameExpr( alignofName( mangleType( dynType ) ) ); 88 97 return expr; 89 } else {90 return Mutator::mutate( algnof );91 98 } // if 99 return algnof; 92 100 } 93 101 94 Type * ScrubTyVars::mutate( PointerType *pointer ) { 95 // // special case of shouldScrub that takes all TypeInstType pointer bases, even if they're not dynamic 96 // Type *base = pointer->get_base(); 97 // Type *dynType = 0; 98 // if ( dynamicOnly ) { 99 // if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( base ) ) { 100 // if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { dynType = typeInst; } 101 // } else { 102 // dynType = isDynType( base, tyVars ); 103 // } 104 // } else { 105 // dynType = isPolyType( base, tyVars ); 106 // } 107 // if ( dynType ) { 108 if ( Type *dynType = shouldScrub( pointer->get_base() ) ) { 109 Type *ret = dynType->acceptMutator( *this ); 102 Type * ScrubTyVars::postmutate( PointerType * pointer ) { 103 if ( dynType ) { 104 Type * ret = dynType->acceptMutator( *visitor ); 110 105 ret->get_qualifiers() |= pointer->get_qualifiers(); 111 pointer-> set_base( 0 );106 pointer->base = nullptr; 112 107 delete pointer; 113 108 return ret; 114 109 } 115 return Mutator::mutate( pointer );110 return pointer; 116 111 } 117 112 } // namespace GenPoly -
src/GenPoly/ScrubTyVars.h
r326cd2b r9cdfb4d0 18 18 #include <cassert> // for assert 19 19 20 #include "Common/PassVisitor.h" 20 21 #include "GenPoly.h" // for TyVarMap, isPolyType, isDynType 21 22 #include "SynTree/Mutator.h" // for Mutator … … 27 28 28 29 namespace GenPoly { 29 class ScrubTyVars : public Mutator{30 struct ScrubTyVars : public WithVisitorRef<ScrubTyVars>, public WithShortCircuiting, public WithGuards { 30 31 /// Whether to scrub all type variables from the provided map, dynamic type variables from the provided map, or all type variables 31 32 enum ScrubMode { FromMap, DynamicFromMap, All }; … … 51 52 static SynTreeClass *scrubAll( SynTreeClass *target ); 52 53 53 virtual Type* mutate( TypeInstType *typeInst ); 54 virtual Type* mutate( StructInstType *structInst ); 55 virtual Type* mutate( UnionInstType *unionInst ); 56 virtual Expression* mutate( SizeofExpr *szeof ); 57 virtual Expression* mutate( AlignofExpr *algnof ); 58 virtual Type* mutate( PointerType *pointer ); 54 /// determine if children should be visited based on whether base type should be scrubbed. 55 void primeBaseScrub( Type * ); 56 57 void premutate( TypeInstType * ) { visit_children = false; } 58 void premutate( StructInstType * ) { visit_children = false; } 59 void premutate( UnionInstType * ) { visit_children = false; } 60 void premutate( SizeofExpr * szeof ) { primeBaseScrub( szeof->type ); } 61 void premutate( AlignofExpr * algnof ) { primeBaseScrub( algnof->type ); } 62 void premutate( PointerType * pointer ) { primeBaseScrub( pointer->base ); } 63 64 Type * postmutate( TypeInstType * typeInst ); 65 Type * postmutate( StructInstType * structInst ); 66 Type * postmutate( UnionInstType * unionInst ); 67 Expression * postmutate( SizeofExpr * szeof ); 68 Expression * postmutate( AlignofExpr * algnof ); 69 Type * postmutate( PointerType * pointer ); 59 70 60 71 private: … … 75 86 const TyVarMap *tyVars; ///< Type variables to scrub 76 87 ScrubMode mode; ///< which type variables to scrub? [FromMap] 88 89 Type * dynType = nullptr; ///< result of shouldScrub 77 90 }; 78 91 79 92 template< typename SynTreeClass > 80 93 SynTreeClass * ScrubTyVars::scrub( SynTreeClass *target, const TyVarMap &tyVars ) { 81 ScrubTyVarsscrubber( tyVars );94 PassVisitor<ScrubTyVars> scrubber( tyVars ); 82 95 return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) ); 83 96 } … … 85 98 template< typename SynTreeClass > 86 99 SynTreeClass * ScrubTyVars::scrubDynamic( SynTreeClass *target, const TyVarMap &tyVars ) { 87 ScrubTyVarsscrubber( tyVars, ScrubTyVars::DynamicFromMap );100 PassVisitor<ScrubTyVars> scrubber( tyVars, ScrubTyVars::DynamicFromMap ); 88 101 return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) ); 89 102 } … … 91 104 template< typename SynTreeClass > 92 105 SynTreeClass * ScrubTyVars::scrubAll( SynTreeClass *target ) { 93 ScrubTyVarsscrubber;106 PassVisitor<ScrubTyVars> scrubber; 94 107 return static_cast< SynTreeClass * >( target->acceptMutator( scrubber ) ); 95 108 }
Note:
See TracChangeset
for help on using the changeset viewer.