Changeset dcd73d1 for src/InitTweak
- Timestamp:
- Sep 5, 2016, 9:49:53 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:
- 621701d
- Parents:
- b16898e
- Location:
- src/InitTweak
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
rb16898e rdcd73d1 245 245 // constructed objects cannot be designated 246 246 if ( isDesignated( objDecl->get_init() ) ) throw SemanticError( "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.", objDecl ); 247 // xxx - constructed objects should not have initializers nested too deeply 247 // constructed objects should not have initializers nested too deeply 248 if ( ! checkInitDepth( objDecl ) ) throw SemanticError( "Managed object's initializer is too deep ", objDecl ); 248 249 249 250 // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor -
src/InitTweak/InitTweak.cc
rb16898e rdcd73d1 23 23 }; 24 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 25 46 class InitFlattener : public Visitor { 26 47 public: … … 53 74 maybeAccept( init, finder ); 54 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; 55 82 } 56 83 -
src/InitTweak/InitTweak.h
rb16898e rdcd73d1 40 40 /// True if the Initializer contains designations 41 41 bool isDesignated( Initializer * init ); 42 43 /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its 44 /// type, where the depth of its type is the number of nested ArrayTypes + 1 45 bool checkInitDepth( ObjectDecl * objDecl ); 42 46 43 47 /// Non-Null if expr is a call expression whose target function is intrinsic
Note: See TracChangeset
for help on using the changeset viewer.