- Timestamp:
- Aug 22, 2017, 6:41:28 PM (7 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, with_gc
- Children:
- 0b5d871
- Parents:
- d104b02
- Location:
- src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
rd104b02 r5ccb10d 591 591 592 592 Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) ); 593 if ( callExpr->get_result()->get_lvalue() ) {594 // lvalue returning functions are funny. Lvalue.cc inserts a *? in front of any lvalue returning595 // non-intrinsic function. Add an AddressExpr to the call to negate the derefence and change the596 // type of the return temporary from T to T* to properly capture the return value. Then dereference597 // the result of the comma expression, since the lvalue returning call was originally wrapped with598 // an AddressExpr. Effectively, this turns599 // lvalue T f();600 // &*f();601 // into602 // T * f();603 // T * tmp_cp_retN;604 // &*(tmp_cp_retN = &*f(), tmp_cp_retN); // the first * and second & are generated here605 // which work out in terms of types, but is pretty messy. It would be nice to find a better way.606 assign->get_args().back() = new AddressExpr( assign->get_args().back() );607 608 returnDecl->set_type( new PointerType( Type::Qualifiers(), returnDecl->get_type() ) );609 retExpr->set_result( new PointerType( Type::Qualifiers(), retExpr->get_result() ) );610 retExpr = UntypedExpr::createDeref( retExpr );611 } // if612 593 // move env from callExpr to retExpr 613 594 retExpr->set_env( callExpr->get_env() ); -
src/ResolvExpr/AlternativeFinder.cc
rd104b02 r5ccb10d 845 845 // then excess components do not come out in the result expression (but UniqueExprs ensure that 846 846 // side effects will still be done). 847 if ( Tuples::maybeImpure ( argExpr ) && ! dynamic_cast< UniqueExpr * >( argExpr ) ) {847 if ( Tuples::maybeImpureIgnoreUnique( argExpr ) ) { 848 848 // expressions which may contain side effects require a single unique instance of the expression. 849 849 argExpr = new UniqueExpr( argExpr ); -
src/ResolvExpr/CommonType.cc
rd104b02 r5ccb10d 18 18 #include "Unify.h" 19 19 20 // /#define DEBUG20 // #define DEBUG 21 21 22 22 namespace ResolvExpr { -
src/ResolvExpr/ConversionCost.cc
rd104b02 r5ccb10d 28 28 const Cost Cost::reference = Cost( 0, 0, 0, 1 ); 29 29 30 #if 0 31 #define PRINT(x) x 32 #else 33 #define PRINT(x) 34 #endif 30 35 31 36 Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { … … 33 38 EqvClass eqvClass; 34 39 NamedTypeDecl *namedType; 35 /// std::cout << "type inst " << destAsTypeInst->get_name(); 40 PRINT( std::cerr << "type inst " << destAsTypeInst->get_name(); ) 36 41 if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) { 37 42 if ( eqvClass.type ) { … … 41 46 } 42 47 } else if ( ( namedType = indexer.lookupType( destAsTypeInst->get_name() ) ) ) { 43 /// std::cout << " found" << std::endl; 48 PRINT( std::cerr << " found" << std::endl; ) 44 49 TypeDecl *type = dynamic_cast< TypeDecl* >( namedType ); 45 50 // all typedefs should be gone by this point … … 49 54 } // if 50 55 } // if 51 /// std::cout << " not found" << std::endl; 52 } // if 53 /// std::cout << "src is "; 54 /// src->print( std::cout ); 55 /// std::cout << std::endl << "dest is "; 56 /// dest->print( std::cout ); 57 /// std::cout << std::endl << "env is" << std::endl; 58 /// env.print( std::cout, 8 ); 56 PRINT( std::cerr << " not found" << std::endl; ) 57 } // if 58 PRINT( 59 std::cerr << "src is "; 60 src->print( std::cerr ); 61 std::cerr << std::endl << "dest is "; 62 dest->print( std::cerr ); 63 std::cerr << std::endl << "env is" << std::endl; 64 env.print( std::cerr, 8 ); 65 ) 59 66 if ( typesCompatibleIgnoreQualifiers( src, dest, indexer, env ) ) { 60 /// std::cout << "compatible!" << std::endl; 67 PRINT( std::cerr << "compatible!" << std::endl; ) 61 68 return Cost::zero; 62 69 } else if ( dynamic_cast< VoidType* >( dest ) ) { 63 70 return Cost::safe; 64 71 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) { 65 // std::cerr << "conversionCost: dest is reference" << std::endl;72 PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; ) 66 73 return convertToReferenceCost( src, refType, indexer, env ); 67 74 } else { … … 77 84 78 85 Cost convertToReferenceCost( Type * src, Type * dest, int diff, const SymTab::Indexer & indexer, const TypeEnvironment & env ) { 79 // std::cerr << "convert to reference cost..." << std::endl;86 PRINT( std::cerr << "convert to reference cost..." << std::endl; ) 80 87 if ( diff > 0 ) { 81 88 // TODO: document this … … 92 99 ReferenceType * destAsRef = dynamic_cast< ReferenceType * >( dest ); 93 100 if ( srcAsRef && destAsRef ) { // pointer-like conversions between references 94 // std::cerr << "converting between references" << std::endl;101 PRINT( std::cerr << "converting between references" << std::endl; ) 95 102 if ( srcAsRef->get_base()->get_qualifiers() <= destAsRef->get_base()->get_qualifiers() && typesCompatibleIgnoreQualifiers( srcAsRef->get_base(), destAsRef->get_base(), indexer, env ) ) { 96 103 return Cost::safe; 97 104 } else { // xxx - this discards reference qualifiers from consideration -- reducing qualifiers is a safe conversion; is this right? 98 105 int assignResult = ptrsAssignable( srcAsRef->get_base(), destAsRef->get_base(), env ); 106 PRINT( std::cerr << "comparing references: " << assignResult << " " << srcAsRef << " " << destAsRef << std::endl; ) 99 107 if ( assignResult < 0 ) { 100 108 return Cost::safe; … … 104 112 } // if 105 113 } else { 106 // std::cerr << "reference to rvalue conversion" << std::endl;114 PRINT( std::cerr << "reference to rvalue conversion" << std::endl; ) 107 115 ConversionCost converter( dest, indexer, env ); 108 116 src->accept( converter ); … … 113 121 assert( diff == -1 && destAsRef ); 114 122 if ( typesCompatibleIgnoreQualifiers( src, destAsRef->get_base(), indexer, env ) ) { 115 // std::cerr << "converting compatible base type" << std::endl;123 PRINT( std::cerr << "converting compatible base type" << std::endl; ) 116 124 if ( src->get_lvalue() ) { 117 // std::cerr << "lvalue to reference conversion" << std::endl; 125 PRINT( 126 std::cerr << "lvalue to reference conversion" << std::endl; 127 std::cerr << src << " => " << destAsRef << std::endl; 128 ) 118 129 // lvalue-to-reference conversion: cv lvalue T => cv T & 119 130 if ( src->get_qualifiers() == destAsRef->get_base()->get_qualifiers() ) { … … 125 136 } // if 126 137 } else if ( destAsRef->get_base()->get_const() ) { 127 // std::cerr << "rvalue to const ref conversion" << std::endl;138 PRINT( std::cerr << "rvalue to const ref conversion" << std::endl; ) 128 139 // rvalue-to-const-reference conversion: T => const T & 129 140 return Cost::safe; 130 141 } else { 131 // std::cerr << "rvalue to non-const reference conversion" << std::endl;142 PRINT( std::cerr << "rvalue to non-const reference conversion" << std::endl; ) 132 143 // rvalue-to-reference conversion: T => T & 133 144 return Cost::unsafe; 134 145 } // if 135 146 } // if 136 // std::cerr << "attempting to convert from incompatible base type -- fail" << std::endl;147 PRINT( std::cerr << "attempting to convert from incompatible base type -- fail" << std::endl; ) 137 148 } 138 149 return Cost::infinity; … … 248 259 void ConversionCost::visit(PointerType *pointerType) { 249 260 if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) { 250 // std::cerr << pointerType << " ===> " << destAsPtr;261 PRINT( std::cerr << pointerType << " ===> " << destAsPtr; ) 251 262 Type::Qualifiers tq1 = pointerType->get_base()->get_qualifiers(); 252 263 Type::Qualifiers tq2 = destAsPtr->get_base()->get_qualifiers(); … … 257 268 } else { 258 269 // types are the same, except otherPointer has more qualifiers 259 // std::cerr << " :: compatible and good qualifiers" << std::endl;270 PRINT( std::cerr << " :: compatible and good qualifiers" << std::endl; ) 260 271 cost = Cost::safe; 261 272 } 262 273 } else { // xxx - this discards qualifiers from consideration -- reducing qualifiers is a safe conversion; is this right? 263 274 int assignResult = ptrsAssignable( pointerType->get_base(), destAsPtr->get_base(), env ); 264 // std::cerr << " :: " << assignResult << std::endl;275 PRINT( std::cerr << " :: " << assignResult << std::endl; ) 265 276 if ( assignResult < 0 && pointerType->get_base()->get_qualifiers() <= destAsPtr->get_qualifiers() ) { 266 277 cost = Cost::safe; … … 291 302 cost.incUnsafe(); // lose qualifiers as last resort 292 303 } 293 // std::cerr << refType << " ==> " << dest << " " << cost << std::endl;304 PRINT( std::cerr << refType << " ==> " << dest << " " << cost << std::endl; ) 294 305 } 295 306 -
src/ResolvExpr/PtrsAssignable.cc
rd104b02 r5ccb10d 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // PtrsAssignable.cc -- 7 // PtrsAssignable.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 83 83 void PtrsAssignable::visit( __attribute__((unused)) UnionInstType *inst ) {} 84 84 85 void PtrsAssignable::visit( EnumInstType * inst) {86 if ( dynamic_cast< EnumInstType* >( inst ) ) {85 void PtrsAssignable::visit( EnumInstType * ) { 86 if ( dynamic_cast< EnumInstType* >( dest ) ) { 87 87 result = 1; 88 } else if ( BasicType *bt = dynamic_cast< BasicType* >( inst ) ) {88 } else if ( BasicType *bt = dynamic_cast< BasicType* >( dest ) ) { 89 89 result = bt->get_kind() == BasicType::SignedInt; 90 90 } … … 105 105 void PtrsAssignable::visit( __attribute__((unused)) ZeroType *zeroType ) {} 106 106 void PtrsAssignable::visit( __attribute__((unused)) OneType *oneType ) {} 107 107 108 108 } // namespace ResolvExpr 109 109 -
src/SynTree/Expression.cc
rd104b02 r5ccb10d 611 611 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) { 612 612 assert( type && initializer ); 613 type->set_lvalue( true ); 613 614 set_result( type ); 614 615 } -
src/SynTree/TupleExpr.cc
rd104b02 r5ccb10d 60 60 assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested index %d in expr %s", type->size(), index, toString( tuple ).c_str() ); 61 61 set_result( (*std::next( type->get_types().begin(), index ))->clone() ); 62 get_result()->set_lvalue( type->get_lvalue() ); 62 // like MemberExpr, TupleIndexExpr is always an lvalue 63 get_result()->set_lvalue( true ); 63 64 } 64 65 -
src/SynTree/Type.h
rd104b02 r5ccb10d 311 311 virtual int referenceDepth() const; 312 312 313 // Since reference types act like value types, their size is the size of the base. 314 // This makes it simple to cast the empty tuple to a reference type, since casts that increase 315 // the number of values are disallowed. 316 virtual unsigned size() const { return base->size(); } 317 313 318 virtual ReferenceType *clone() const { return new ReferenceType( *this ); } 314 319 virtual void accept( Visitor & v ) { v.visit( this ); } -
src/prelude/prelude.cf
rd104b02 r5ccb10d 456 456 forall( dtype DT ) const volatile DT * ?=?( const volatile DT * volatile &, zero_t ); 457 457 458 forall( ftype FT ) FT * ?=?( FT * &, forall( ftype FT2 ) FT2 *);459 forall( ftype FT ) FT * ?=?( FT * volatile &, forall( ftype FT2 ) FT2 *);458 forall( ftype FT ) FT * ?=?( FT * &, zero_t ); 459 forall( ftype FT ) FT * ?=?( FT * volatile &, zero_t ); 460 460 461 461 forall( dtype T | sized(T) ) T * ?+=?( T * &, ptrdiff_t ); … … 806 806 forall( dtype DT ) void ?{}( const volatile DT * &, zero_t ); 807 807 808 forall( ftype FT ) void ?{}( FT * &, forall( ftype FT2 ) FT2 *);808 forall( ftype FT ) void ?{}( FT * &, zero_t ); 809 809 810 810 // default ctors
Note: See TracChangeset
for help on using the changeset viewer.