Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.cc

    r1ba88a0 rdcd73d1  
    2323                };
    2424
     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
    2546                class InitFlattener : public Visitor {
    2647                        public:
     
    5374                maybeAccept( init, finder );
    5475                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;
    5582        }
    5683
Note: See TracChangeset for help on using the changeset viewer.