Changes in src/InitTweak/InitTweak.cc [dcd73d1:9b4c936]
- File:
-
- 1 edited
-
src/InitTweak/InitTweak.cc (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
rdcd73d1 r9b4c936 7 7 #include "SynTree/Attribute.h" 8 8 #include "GenPoly/GenPoly.h" 9 #include "ResolvExpr/typeops.h"10 9 11 10 namespace InitTweak { … … 23 22 }; 24 23 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 46 24 class InitFlattener : public Visitor { 47 25 public: … … 74 52 maybeAccept( init, finder ); 75 53 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;82 54 } 83 55 … … 259 231 return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) && 260 232 (objDecl->get_init() == NULL || 261 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) 233 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) && 234 ! isDesignated( objDecl->get_init() ) 262 235 && objDecl->get_storageClass() != DeclarationNode::Extern; 263 236 } … … 417 390 virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; } 418 391 virtual void visit( UntypedExpr *untypedExpr ) { 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 } 392 virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; } 393 virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 429 394 virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; } 430 395 virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; } 431 396 virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; } 432 397 virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; } 398 virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ } 433 399 // these might be okay? 434 400 // virtual void visit( SizeofExpr *sizeofExpr ); … … 473 439 bool isDestructor( const std::string & str ) { return str == "^?{}"; } 474 440 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 }494 441 }
Note:
See TracChangeset
for help on using the changeset viewer.