Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.cc

    rdcd73d1 r9b4c936  
    77#include "SynTree/Attribute.h"
    88#include "GenPoly/GenPoly.h"
    9 #include "ResolvExpr/typeops.h"
    109
    1110namespace InitTweak {
     
    2322                };
    2423
    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 
    4624                class InitFlattener : public Visitor {
    4725                        public:
     
    7452                maybeAccept( init, finder );
    7553                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;
    8254        }
    8355
     
    259231                return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) &&
    260232                        (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() )
    262235                        && objDecl->get_storageClass() != DeclarationNode::Extern;
    263236        }
     
    417390                virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; }
    418391                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; }
    429394                virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; }
    430395                virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; }
    431396                virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; }
    432397                virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; }
     398                virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ }
    433399                // these might be okay?
    434400                // virtual void visit( SizeofExpr *sizeofExpr );
     
    473439        bool isDestructor( const std::string & str ) { return str == "^?{}"; }
    474440        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         }
    494441}
Note: See TracChangeset for help on using the changeset viewer.