Changeset 5fda714 for src/InitTweak/InitTweak.cc
- Timestamp:
- Sep 7, 2016, 9:30:25 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, 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:
- 9f70ab57
- Parents:
- 1f75e2d (diff), f04a8b81 (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
r1f75e2d r5fda714 7 7 #include "SynTree/Attribute.h" 8 8 #include "GenPoly/GenPoly.h" 9 #include "ResolvExpr/typeops.h" 9 10 10 11 namespace InitTweak { … … 22 23 }; 23 24 25 class InitDepthChecker : public Visitor { 26 public: 27 bool depthOkay = true; 28 Type * type; 29 int curDepth = 0, maxDepth = 0; 30 InitDepthChecker( Type * type ) : type( type ) { 31 Type * t = type; 32 while ( ArrayType * at = dynamic_cast< ArrayType * >( t ) ) { 33 maxDepth++; 34 t = at->get_base(); 35 } 36 maxDepth++; 37 } 38 virtual void visit( ListInit * listInit ) { 39 curDepth++; 40 if ( curDepth > maxDepth ) depthOkay = false; 41 Visitor::visit( listInit ); 42 curDepth--; 43 } 44 }; 45 24 46 class InitFlattener : public Visitor { 25 47 public: … … 52 74 maybeAccept( init, finder ); 53 75 return finder.hasDesignations; 76 } 77 78 bool checkInitDepth( ObjectDecl * objDecl ) { 79 InitDepthChecker checker( objDecl->get_type() ); 80 maybeAccept( objDecl->get_init(), checker ); 81 return checker.depthOkay; 54 82 } 55 83 … … 231 259 return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) && 232 260 (objDecl->get_init() == NULL || 233 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) && 234 ! isDesignated( objDecl->get_init() ) 261 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) 235 262 && objDecl->get_storageClass() != DeclarationNode::Extern; 236 263 } … … 390 417 virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; } 391 418 virtual void visit( UntypedExpr *untypedExpr ) { isConstExpr = false; } 392 virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; } 393 virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 419 virtual void visit( NameExpr *nameExpr ) { 420 // xxx - temporary hack, because 0 and 1 really should be constexprs, even though they technically aren't in Cforall today 421 if ( nameExpr->get_name() != "0" && nameExpr->get_name() != "1" ) isConstExpr = false; 422 } 423 // virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 424 virtual void visit( AddressExpr *addressExpr ) { 425 // address of a variable or member expression is constexpr 426 Expression * arg = addressExpr->get_arg(); 427 if ( ! dynamic_cast< NameExpr * >( arg) && ! dynamic_cast< VariableExpr * >( arg ) && ! dynamic_cast< MemberExpr * >( arg ) && ! dynamic_cast< UntypedMemberExpr * >( arg ) ) isConstExpr = false; 428 } 394 429 virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; } 395 430 virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; } 396 431 virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; } 397 432 virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; } 398 virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ }399 433 // these might be okay? 400 434 // virtual void visit( SizeofExpr *sizeofExpr ); … … 439 473 bool isDestructor( const std::string & str ) { return str == "^?{}"; } 440 474 bool isCtorDtor( const std::string & str ) { return isConstructor( str ) || isDestructor( str ); } 475 476 FunctionDecl * isCopyConstructor( Declaration * decl ) { 477 FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ); 478 if ( ! function ) return 0; 479 if ( ! isConstructor( function->get_name() ) ) return 0; 480 FunctionType * ftype = function->get_functionType(); 481 if ( ftype->get_parameters().size() != 2 ) return 0; 482 483 Type * t1 = ftype->get_parameters().front()->get_type(); 484 Type * t2 = ftype->get_parameters().back()->get_type(); 485 PointerType * ptrType = dynamic_cast< PointerType * > ( t1 ); 486 assert( ptrType ); 487 488 if ( ResolvExpr::typesCompatible( ptrType->get_base(), t2, SymTab::Indexer() ) ) { 489 return function; 490 } else { 491 return 0; 492 } 493 } 441 494 }
Note: See TracChangeset
for help on using the changeset viewer.