Changeset 3f7e12cb for src/InitTweak/InitTweak.cc
- Timestamp:
- Nov 8, 2017, 5:43:33 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, with_gc
- Children:
- 954908d
- Parents:
- 78315272 (diff), e35f30a (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r78315272 r3f7e12cb 1 #include <stddef.h> // for NULL2 1 #include <algorithm> // for find, all_of 3 2 #include <cassert> // for assertf, assert, strict_dynamic_cast … … 23 22 #include "SynTree/Type.h" // for FunctionType, ArrayType, PointerType 24 23 #include "SynTree/Visitor.h" // for Visitor, maybeAccept 24 #include "Tuples/Tuples.h" // for Tuples::isTtype 25 25 26 26 class UntypedValofExpr; … … 170 170 } 171 171 172 bool InitExpander::addReference() { 173 bool added = false; 174 for ( Expression *& expr : cur ) { 175 expr = new AddressExpr( expr ); 176 added = true; 177 } 178 return added; 179 } 180 172 181 namespace { 173 182 /// given index i, dimension d, initializer init, and callExpr f, generates … … 184 193 callExpr->get_args().splice( callExpr->get_args().end(), args ); 185 194 186 *out++ = new IfStmt( noLabels, cond, new ExprStmt( noLabels, callExpr ), NULL);195 *out++ = new IfStmt( noLabels, cond, new ExprStmt( noLabels, callExpr ), nullptr ); 187 196 188 197 UntypedExpr * increment = new UntypedExpr( new NameExpr( "++?" ) ); … … 250 259 // To accomplish this, generate switch statement, consuming all of expander's elements 251 260 Statement * InitImpl::buildListInit( UntypedExpr * dst, std::list< Expression * > & indices ) { 252 if ( ! init ) return NULL;261 if ( ! init ) return nullptr; 253 262 CompoundStmt * block = new CompoundStmt( noLabels ); 254 263 build( dst, indices.begin(), indices.end(), init, back_inserter( block->get_kids() ) ); 255 264 if ( block->get_kids().empty() ) { 256 265 delete block; 257 return NULL;266 return nullptr; 258 267 } else { 259 init = NULL; // init was consumed in creating the list init268 init = nullptr; // init was consumed in creating the list init 260 269 return block; 261 270 } 262 271 } 263 272 264 Statement * ExprImpl::buildListInit( __attribute((unused)) UntypedExpr * dst, __attribute((unused)) std::list< Expression * > & indices) {265 return NULL;273 Statement * ExprImpl::buildListInit( UntypedExpr *, std::list< Expression * > & ) { 274 return nullptr; 266 275 } 267 276 … … 270 279 } 271 280 272 bool tryConstruct( ObjectDecl * objDecl ) { 281 Type * getTypeofThis( FunctionType * ftype ) { 282 assertf( ftype, "getTypeofThis: nullptr ftype" ); 283 ObjectDecl * thisParam = getParamThis( ftype ); 284 ReferenceType * refType = strict_dynamic_cast< ReferenceType * >( thisParam->type ); 285 return refType->base; 286 } 287 288 ObjectDecl * getParamThis( FunctionType * ftype ) { 289 assertf( ftype, "getParamThis: nullptr ftype" ); 290 auto & params = ftype->parameters; 291 assertf( ! params.empty(), "getParamThis: ftype with 0 parameters: %s", toString( ftype ).c_str() ); 292 return strict_dynamic_cast< ObjectDecl * >( params.front() ); 293 } 294 295 bool tryConstruct( DeclarationWithType * dwt ) { 296 ObjectDecl * objDecl = dynamic_cast< ObjectDecl * >( dwt ); 297 if ( ! objDecl ) return false; 273 298 return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) && 274 (objDecl->get_init() == NULL || 275 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) 276 && ! objDecl->get_storageClasses().is_extern; 299 (objDecl->get_init() == nullptr || 300 ( objDecl->get_init() != nullptr && objDecl->get_init()->get_maybeConstructed() )) 301 && ! objDecl->get_storageClasses().is_extern 302 && isConstructable( objDecl->type ); 303 } 304 305 bool isConstructable( Type * type ) { 306 return ! dynamic_cast< VarArgsType * >( type ) && ! dynamic_cast< ReferenceType * >( type ) && ! dynamic_cast< FunctionType * >( type ) && ! Tuples::isTtype( type ); 277 307 } 278 308 … … 314 344 collectCtorDtorCalls( stmt, matches ); 315 345 assert( matches.size() <= 1 ); 316 return matches.size() == 1 ? matches.front() : NULL;346 return matches.size() == 1 ? matches.front() : nullptr; 317 347 } 318 348 … … 332 362 assert( expr ); 333 363 if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) { 334 return varExpr-> get_var();364 return varExpr->var; 335 365 } else if ( MemberExpr * memberExpr = dynamic_cast< MemberExpr * >( expr ) ) { 336 return memberExpr-> get_member();366 return memberExpr->member; 337 367 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 338 return getCalledFunction( castExpr-> get_arg());368 return getCalledFunction( castExpr->arg ); 339 369 } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( expr ) ) { 340 370 return handleDerefCalledFunction( untypedExpr ); … … 342 372 return handleDerefCalledFunction( appExpr ); 343 373 } else if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) { 344 return getCalledFunction( addrExpr->get_arg() ); 374 return getCalledFunction( addrExpr->arg ); 375 } else if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( expr ) ) { 376 return getCalledFunction( commaExpr->arg2 ); 345 377 } 346 378 return nullptr; … … 359 391 ApplicationExpr * isIntrinsicCallExpr( Expression * expr ) { 360 392 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr ); 361 if ( ! appExpr ) return NULL;393 if ( ! appExpr ) return nullptr; 362 394 DeclarationWithType * function = getCalledFunction( appExpr->get_function() ); 363 395 assertf( function, "getCalledFunction returned nullptr: %s", toString( appExpr->get_function() ).c_str() ); 364 396 // check for Intrinsic only - don't want to remove all overridable ctor/dtors because autogenerated ctor/dtor 365 397 // will call all member dtors, and some members may have a user defined dtor. 366 return function->get_linkage() == LinkageSpec::Intrinsic ? appExpr : NULL;398 return function->get_linkage() == LinkageSpec::Intrinsic ? appExpr : nullptr; 367 399 } 368 400 … … 482 514 return refType->get_base(); 483 515 } else { 484 return NULL;516 return nullptr; 485 517 } 486 518 } … … 488 520 Type * isPointerType( Type * type ) { 489 521 if ( getPointerBase( type ) ) return type; 490 else return NULL;522 else return nullptr; 491 523 } 492 524 … … 557 589 FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname ) { 558 590 FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ); 559 if ( ! function ) return 0;560 if ( function-> get_name() != fname ) return 0;561 FunctionType * ftype = function-> get_functionType();562 if ( ftype-> get_parameters().size() != 2 ) return 0;591 if ( ! function ) return nullptr; 592 if ( function->name != fname ) return nullptr; 593 FunctionType * ftype = function->type; 594 if ( ftype->parameters.size() != 2 ) return nullptr; 563 595 564 596 Type * t1 = getPointerBase( ftype->get_parameters().front()->get_type() ); 565 Type * t2 = ftype-> get_parameters().back()->get_type();597 Type * t2 = ftype->parameters.back()->get_type(); 566 598 assert( t1 ); 567 599 … … 583 615 } 584 616 FunctionDecl * isDefaultConstructor( Declaration * decl ) { 585 if ( isConstructor( decl-> get_name()) ) {617 if ( isConstructor( decl->name ) ) { 586 618 if ( FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl ) ) { 587 if ( func-> get_functionType()->get_parameters().size() == 1 ) {619 if ( func->type->parameters.size() == 1 ) { 588 620 return func; 589 621 }
Note:
See TracChangeset
for help on using the changeset viewer.