Changeset 24de7b1
- Timestamp:
- Apr 16, 2018, 3:21:17 PM (7 years ago)
- Branches:
- new-env, with_gc
- Children:
- fb97252f
- Parents:
- 6f81db3
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/GC.cc
r6f81db3 r24de7b1 40 40 } 41 41 42 const GC& GC::operator<< (const GC_ Traceable* obj) const {42 const GC& GC::operator<< (const GC_Object* obj) const { 43 43 if( obj ) 44 44 { … … 119 119 } 120 120 121 GC_Object::GC_Object( const GC_Object& ) { 122 GC::get().register_object( this ); 123 } 124 125 GC_Object::GC_Object( GC_Object&& ) { 126 GC::get().register_object( this ); 127 } 128 121 129 // Local Variables: // 122 130 // tab-width: 4 // -
src/Common/GC.h
r6f81db3 r24de7b1 18 18 #include <vector> 19 19 20 class GC_Traceable;21 20 class GC_Object; 22 21 class BaseSyntaxNode; … … 30 29 31 30 /// Traces a traceable object 32 const GC& operator<< (const GC_ Traceable*) const;31 const GC& operator<< (const GC_Object*) const; 33 32 34 33 /// Adds a new object to garbage collection … … 111 110 } 112 111 113 /// Class that is traced by the GC, but not managed by it114 class GC_ Traceable{112 /// Class that is managed by the GC 113 class GC_Object { 115 114 friend class GC; 116 115 protected: 117 116 mutable bool mark; 118 117 118 // Override default constructors to ensure clones are registered and properly marked 119 GC_Object(); 120 121 GC_Object(const GC_Object&); 122 123 GC_Object(GC_Object&&); 124 125 GC_Object& operator= (const GC_Object&) { /* do not assign mark */ return *this; } 126 127 GC_Object& operator= (GC_Object&&) { /* do not assign mark */ return *this; } 128 129 // Ensure subclasses can be deleted by garbage collector 130 virtual ~GC_Object() {} 131 119 132 /// override to trace any child objects 120 133 virtual void trace(const GC&) const {} 121 };122 123 /// Class that is managed by the GC124 class GC_Object : public GC_Traceable {125 friend class GC;126 protected:127 virtual ~GC_Object() {}128 public:129 GC_Object();130 134 }; 131 135 -
src/SynTree/GcTracer.h
r6f81db3 r24de7b1 38 38 void previsit( BaseSyntaxNode * node ) { 39 39 // skip tree if already seen 40 // xxx - this should be uncommented (it breaks object cycles), but at the moment it seems 41 // like the object cycles don't happen and other bugs do 42 // if ( node->mark == gc.mark ) { 43 // visit_children = false; 44 // return; 45 // } 40 if ( node->mark == gc.mark ) { 41 visit_children = false; 42 return; 43 } 46 44 47 45 // mark node … … 50 48 51 49 // add visits left out by PassVisitor 50 51 void postvisit( Constant* con ) { 52 maybeAccept( con->get_type(), *visitor ); 53 } 52 54 53 55 void postvisit( Expression* expr ) { … … 58 60 postvisit( static_cast<Expression*>(expr) ); 59 61 maybeAccept( expr->function, *visitor ); 62 } 63 64 void postvisit( VariableExpr* expr ) { 65 postvisit( static_cast<Expression*>(expr) ); 66 maybeAccept( expr->var, *visitor ); // not in PassVisitor because it causes cycle 60 67 } 61 68
Note: See TracChangeset
for help on using the changeset viewer.