Changeset bfd4974 for src/InitTweak
- Timestamp:
- Oct 19, 2017, 11:13:12 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
- 21ea170
- Parents:
- 189d800
- git-author:
- Rob Schluntz <rschlunt@…> (10/12/17 15:50:44)
- git-committer:
- Rob Schluntz <rschlunt@…> (10/19/17 11:13:12)
- Location:
- src/InitTweak
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
r189d800 rbfd4974 85 85 // should not have a ConstructorInit generated. 86 86 87 bool isManaged( ObjectDecl * objDecl ) const ; // determine if object is managed 88 bool isManaged( Type * type ) const; // determine if type is managed 89 void handleDWT( DeclarationWithType * dwt ); // add type to managed if ctor/dtor 90 GenPoly::ScopedSet< std::string > managedTypes; 87 ManagedTypes managedTypes; 91 88 bool inFunction = false; 92 89 }; … … 204 201 } 205 202 206 bool CtorDtor::isManaged( Type * type ) const {203 bool ManagedTypes::isManaged( Type * type ) const { 207 204 // references are never constructed 208 205 if ( dynamic_cast< ReferenceType * >( type ) ) return false; … … 220 217 } 221 218 222 bool CtorDtor::isManaged( ObjectDecl * objDecl ) const {219 bool ManagedTypes::isManaged( ObjectDecl * objDecl ) const { 223 220 Type * type = objDecl->get_type(); 224 221 while ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { … … 228 225 } 229 226 230 void CtorDtor::handleDWT( DeclarationWithType * dwt ) {227 void ManagedTypes::handleDWT( DeclarationWithType * dwt ) { 231 228 // if this function is a user-defined constructor or destructor, mark down the type as "managed" 232 229 if ( ! LinkageSpec::isOverridable( dwt->get_linkage() ) && CodeGen::isCtorDtor( dwt->get_name() ) ) { … … 238 235 } 239 236 } 237 238 void ManagedTypes::handleStruct( StructDecl * aggregateDecl ) { 239 // don't construct members, but need to take note if there is a managed member, 240 // because that means that this type is also managed 241 for ( Declaration * member : aggregateDecl->get_members() ) { 242 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { 243 if ( isManaged( field ) ) { 244 StructInstType inst( Type::Qualifiers(), aggregateDecl ); 245 managedTypes.insert( SymTab::Mangler::mangle( &inst ) ); 246 break; 247 } 248 } 249 } 250 } 251 252 void ManagedTypes::beginScope() { managedTypes.beginScope(); } 253 void ManagedTypes::endScope() { managedTypes.endScope(); } 240 254 241 255 ImplicitCtorDtorStmt * genCtorDtor( const std::string & fname, ObjectDecl * objDecl, Expression * arg ) { … … 282 296 283 297 void CtorDtor::previsit( ObjectDecl * objDecl ) { 284 handleDWT( objDecl );298 managedTypes.handleDWT( objDecl ); 285 299 // hands off if @=, extern, builtin, etc. 286 300 // even if unmanaged, try to construct global or static if initializer is not constexpr, since this is not legal C 287 if ( tryConstruct( objDecl ) && ( isManaged( objDecl ) || ((! inFunction || objDecl->get_storageClasses().is_static ) && ! isConstExpr( objDecl->get_init() ) ) ) ) {301 if ( tryConstruct( objDecl ) && ( managedTypes.isManaged( objDecl ) || ((! inFunction || objDecl->get_storageClasses().is_static ) && ! isConstExpr( objDecl->get_init() ) ) ) ) { 288 302 // constructed objects cannot be designated 289 303 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 @=.\n", objDecl ); … … 300 314 inFunction = true; 301 315 302 handleDWT( functionDecl );316 managedTypes.handleDWT( functionDecl ); 303 317 304 318 GuardScope( managedTypes ); … … 306 320 for ( auto & tyDecl : functionDecl->get_functionType()->get_forall() ) { 307 321 for ( DeclarationWithType *& assertion : tyDecl->get_assertions() ) { 308 handleDWT( assertion );322 managedTypes.handleDWT( assertion ); 309 323 } 310 324 } … … 316 330 visit_children = false; // do not try to construct and destruct aggregate members 317 331 318 // don't construct members, but need to take note if there is a managed member, 319 // because that means that this type is also managed 320 for ( Declaration * member : aggregateDecl->get_members() ) { 321 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { 322 if ( isManaged( field ) ) { 323 StructInstType inst( Type::Qualifiers(), aggregateDecl ); 324 managedTypes.insert( SymTab::Mangler::mangle( &inst ) ); 325 break; 326 } 327 } 328 } 332 managedTypes.handleStruct( aggregateDecl ); 329 333 } 330 334 -
src/InitTweak/GenInit.h
r189d800 rbfd4974 16 16 #pragma once 17 17 18 #include <list> // for list19 #include <string> // for string18 #include <list> // for list 19 #include <string> // for string 20 20 21 #include "SynTree/SynTree.h" // for Visitor Nodes 21 #include "SynTree/SynTree.h" // for Visitor Nodes 22 23 #include "GenPoly/ScopedSet.h" // for ScopedSet 22 24 23 25 namespace InitTweak { … … 33 35 /// creates an appropriate ConstructorInit node which contains a constructor, destructor, and C-initializer 34 36 ConstructorInit * genCtorInit( ObjectDecl * objDecl ); 37 38 class ManagedTypes { 39 public: 40 bool isManaged( ObjectDecl * objDecl ) const ; // determine if object is managed 41 bool isManaged( Type * type ) const; // determine if type is managed 42 43 void handleDWT( DeclarationWithType * dwt ); // add type to managed if ctor/dtor 44 void handleStruct( StructDecl * aggregateDecl ); // add type to managed if child is managed 45 46 void beginScope(); 47 void endScope(); 48 private: 49 GenPoly::ScopedSet< std::string > managedTypes; 50 }; 35 51 } // namespace 36 52
Note: See TracChangeset
for help on using the changeset viewer.