Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.cc

    r9b4c936 rdcd73d1  
    77#include "SynTree/Attribute.h"
    88#include "GenPoly/GenPoly.h"
     9#include "ResolvExpr/typeops.h"
    910
    1011namespace InitTweak {
     
    2223                };
    2324
     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
    2446                class InitFlattener : public Visitor {
    2547                        public:
     
    5274                maybeAccept( init, finder );
    5375                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;
    5482        }
    5583
     
    231259                return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) &&
    232260                        (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() ))
    235262                        && objDecl->get_storageClass() != DeclarationNode::Extern;
    236263        }
     
    390417                virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; }
    391418                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                }
    394429                virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; }
    395430                virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; }
    396431                virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; }
    397432                virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; }
    398                 virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ }
    399433                // these might be okay?
    400434                // virtual void visit( SizeofExpr *sizeofExpr );
     
    439473        bool isDestructor( const std::string & str ) { return str == "^?{}"; }
    440474        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        }
    441494}
Note: See TracChangeset for help on using the changeset viewer.