Changeset 10a7775
- Timestamp:
- Jun 3, 2016, 2:02:29 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- e365cb5
- Parents:
- e01bfbc
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
re01bfbc r10a7775 33 33 #include "OperatorTable.h" 34 34 #include "GenType.h" 35 36 #include "InitTweak/InitTweak.h" 35 37 36 38 using namespace std; … … 255 257 std::list< Expression* >::iterator arg = applicationExpr->get_args().begin(); 256 258 switch ( opInfo.type ) { 259 case OT_CTOR: 260 case OT_DTOR: 261 { 262 // if the first argument's type is const then GCC complains. In this 263 // case, output an explicit ctor/dtor call and exit, rather than following 264 // the normal path 265 assert( arg != applicationExpr->get_args().end() ); 266 assert( (*arg)->get_results().size() >= 1 ); 267 Type * baseType = InitTweak::getPointerBase( (*arg)->get_results().front() ); 268 if ( baseType->get_isConst() ) { 269 // cast away the qualifiers, to eliminate warnings 270 Type * newType = baseType->clone(); 271 newType->get_qualifiers() = Type::Qualifiers(); 272 *arg = new CastExpr( *arg, new PointerType( Type::Qualifiers(), newType ) ); 273 varExpr->accept( *this ); 274 output << "("; 275 genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() ); 276 output << ")"; 277 return; 278 } 279 } 280 // intentional fallthrough - instrinsic ctor/dtor for non-const objects should 281 // be handled the same way as assignment 257 282 case OT_PREFIXASSIGN: 258 283 case OT_POSTFIXASSIGN: 259 284 case OT_INFIXASSIGN: 260 case OT_CTOR:261 case OT_DTOR:262 285 { 263 286 assert( arg != applicationExpr->get_args().end() ); … … 269 292 UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) ); 270 293 newExpr->get_args().push_back( *arg ); 294 assert( (*arg)->get_results().size() == 1 ); 295 Type * type = InitTweak::getPointerBase( (*arg)->get_results().front() ); 296 assert( type ); 297 newExpr->get_results().push_back( type ); 271 298 *arg = newExpr; 272 299 } // if -
src/GenPoly/Box.cc
re01bfbc r10a7775 1947 1947 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) ); 1948 1948 derefExpr->get_args().push_back( derefdVar ); 1949 // xxx - should set results on derefExpr 1949 1950 derefdVar = derefExpr; 1950 1951 } -
src/InitTweak/InitTweak.cc
re01bfbc r10a7775 137 137 } 138 138 } 139 140 Type * getPointerBase( Type * type ) { 141 if ( PointerType * ptrType = dynamic_cast< PointerType * >( type ) ) { 142 return ptrType->get_base(); 143 } else if ( ArrayType * arrayType = dynamic_cast< ArrayType * >( type ) ) { 144 return arrayType->get_base(); 145 } else { 146 return NULL; 147 } 148 } 149 139 150 } -
src/InitTweak/InitTweak.h
re01bfbc r10a7775 48 48 /// returns the argument to a call expression in position N indexed from 0 49 49 Expression * getCallArg( Expression * callExpr, unsigned int pos ); 50 51 /// returns the base type of a PointerType or ArrayType 52 Type * getPointerBase( Type * ); 50 53 } // namespace 51 54 -
src/ResolvExpr/Resolver.cc
re01bfbc r10a7775 531 531 assert( dynamic_cast< VariableExpr * >( arr ) ); 532 532 assert( arr && arr->get_results().size() == 1 ); 533 ArrayType * arrType = dynamic_cast< ArrayType * >( arr->get_results().front() ); 534 assert( arrType ); 535 type = arrType->get_base(); 533 type = InitTweak::getPointerBase( arr->get_results().front() ); 534 assert( type ); 536 535 } else { 537 536 // otherwise, constructing a plain object, which means the object's address is being taken. … … 557 556 impCtorDtorStmt->get_callStmt()->accept( *this ); 558 557 559 // and reset type qualifiers after resolving 560 type->get_qualifiers() = qualifiers; 558 // reset type qualifiers, but first need to figure out where everything is again 559 // because the expressions are often changed by the resolver. 560 callExpr = InitTweak::getCtorDtorCall( impCtorDtorStmt ); 561 assert( callExpr ); 562 constructee = InitTweak::getCallArg( callExpr, 0 ); 563 if ( ApplicationExpr * plusExpr = dynamic_cast< ApplicationExpr * >( constructee ) ) { 564 // constructee is <array>+<index> 565 // get Variable <array>, then get the base type of the VariableExpr - this is the type that needs to be fixed 566 Expression * arr = InitTweak::getCallArg( plusExpr, 0 ); 567 assert( dynamic_cast< VariableExpr * >( arr ) ); 568 assert( arr && arr->get_results().size() == 1 ); 569 type = InitTweak::getPointerBase( arr->get_results().front() ); 570 assert( type ); 571 type->get_qualifiers() = qualifiers; 572 } else { 573 // otherwise constructing a plain object 574 // replace qualifiers on AddressExpr and on inner VariableExpr 575 assert( constructee->get_results().size() == 1 ); 576 AddressExpr * addrExpr = dynamic_cast< AddressExpr * > ( constructee ); 577 assert( addrExpr ); 578 type = InitTweak::getPointerBase( addrExpr->get_results().front() ); 579 assert( type ); 580 type->get_qualifiers() = qualifiers; 581 582 VariableExpr * varExpr = dynamic_cast< VariableExpr * >( addrExpr->get_arg() ); 583 assert( varExpr && varExpr->get_results().size() == 1 ); 584 type = varExpr->get_results().front(); 585 type->get_qualifiers() = qualifiers; 586 } 561 587 } 562 588 } // namespace ResolvExpr
Note: See TracChangeset
for help on using the changeset viewer.