[opengtl-commits] [395] implement a VariablesGarbageCollectionStatement that takes a list of Variables and garbage collect them

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 395
Author:   cyrille
Date:     2008-09-20 00:18:35 +0200 (Sat, 20 Sep 2008)

Log Message:
-----------
implement a VariablesGarbageCollectionStatement that takes a list of Variables and garbage collect them

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.h
    trunk/OpenGTL/OpenGTL/GTLCore/VariablesManager_p.cpp


Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-09-14 07:55:54 UTC (rev 394)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-09-19 22:18:35 UTC (rev 395)
@@ -240,7 +240,7 @@
   GTL_DEBUG("Call member funcion: " << m_member->function()->name());
   GTLCore::ExpressionResult returnValue = _gc.codeGenerator()->callFunction( _gc, bb, m_member->function(), m_arguments );
   
-  _gc.appendDelayedStatement( new GarbageCollectionStatement( returnValue.value(), returnValue.type() ) );
+  _gc.appendDelayedStatement( new PointerGarbageCollectionStatement( returnValue.value(), returnValue.type() ) );
   
   return returnValue;
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-09-14 07:55:54 UTC (rev 394)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-09-19 22:18:35 UTC (rev 395)
@@ -98,7 +98,7 @@
 GTLCore::ExpressionResult FunctionCallExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
 {
   GTLCore::ExpressionResult returnValue = _gc.codeGenerator()->callFunction( _gc, bb, m_function, m_arguments );
-  _gc.appendDelayedStatement( new GarbageCollectionStatement( returnValue.value(), returnValue.type() ) );
+  _gc.appendDelayedStatement( new PointerGarbageCollectionStatement( returnValue.value(), returnValue.type() ) );
   return returnValue;
 }
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.cpp	2008-09-14 07:55:54 UTC (rev 394)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.cpp	2008-09-19 22:18:35 UTC (rev 395)
@@ -26,19 +26,20 @@
 
 #include "../Type.h"
 #include "../CodeGenerator_p.h"
+#include "../VariableNG_p.h"
 #include "../Visitor_p.h"
 
 using namespace GTLCore::AST;
 
-GarbageCollectionStatement::GarbageCollectionStatement( llvm::Value* _pointer, const GTLCore::Type* _type ) : m_pointer(_pointer), m_type(_type)
+PointerGarbageCollectionStatement::PointerGarbageCollectionStatement( llvm::Value* _pointer, const GTLCore::Type* _type ) : m_pointer(_pointer), m_type(_type)
 {
 }
 
-GarbageCollectionStatement::~GarbageCollectionStatement()
+PointerGarbageCollectionStatement::~PointerGarbageCollectionStatement()
 {
 }
 
-llvm::BasicBlock* GarbageCollectionStatement::generateStatement( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock) const
+llvm::BasicBlock* PointerGarbageCollectionStatement::generateStatement( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock) const
 {
   // FIXME: garbage collect if needed
   
@@ -56,3 +57,21 @@
     return _currentBlock;
   }
 }
+
+VariablesGarbageCollectionStatement::VariablesGarbageCollectionStatement( std::list< VariableNG* > _variablesToCollect )
+  : m_variablesToCollect(_variablesToCollect)
+{
+}
+
+VariablesGarbageCollectionStatement::~VariablesGarbageCollectionStatement()
+{
+}
+
+llvm::BasicBlock* VariablesGarbageCollectionStatement::generateStatement( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock) const
+{
+  for( std::list< VariableNG* >::const_iterator it = m_variablesToCollect.begin(); it != m_variablesToCollect.end(); ++it )
+  {
+    _currentBlock = (*it)->cleanUp( _generationContext, _currentBlock, 0 );
+  }
+  return _currentBlock;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.h	2008-09-14 07:55:54 UTC (rev 394)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/GarbageCollectionStatement.h	2008-09-19 22:18:35 UTC (rev 395)
@@ -28,15 +28,23 @@
      * @internal
      * @ingroup GTLCore_AST
      */
-    class GarbageCollectionStatement : public Statement {
+    class PointerGarbageCollectionStatement : public Statement {
       public:
-        GarbageCollectionStatement( llvm::Value* _pointer, const GTLCore::Type* _type );
-        virtual ~GarbageCollectionStatement();
+        PointerGarbageCollectionStatement( llvm::Value* _pointer, const GTLCore::Type* _type );
+        virtual ~PointerGarbageCollectionStatement();
         virtual llvm::BasicBlock* generateStatement( GenerationContext&, llvm::BasicBlock* ) const;
       private:
         llvm::Value* m_pointer;
         const GTLCore::Type* m_type;
     };
+    class VariablesGarbageCollectionStatement : public Statement {
+      public:
+        VariablesGarbageCollectionStatement( std::list< VariableNG* > _variablesToCollect );
+        virtual ~VariablesGarbageCollectionStatement();
+        virtual llvm::BasicBlock* generateStatement( GenerationContext&, llvm::BasicBlock* ) const;
+      private:
+        std::list< VariableNG* > m_variablesToCollect;
+    };
   }
 }
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariablesManager_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariablesManager_p.cpp	2008-09-14 07:55:54 UTC (rev 394)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariablesManager_p.cpp	2008-09-19 22:18:35 UTC (rev 395)
@@ -24,6 +24,7 @@
 
 #include "Debug.h"
 #include "ScopedName.h"
+#include "AST/GarbageCollectionStatement.h"
 
 using namespace GTLCore;
 
@@ -39,6 +40,7 @@
   String nameSpace;
   
   VariableNG* getVariableInMap( const std::map< ScopedName, VariableNG* >&, const ScopedName& );
+  void fillList( std::list< VariableNG* >& list, const std::map< ScopedName, VariableNG* >& map );
 };
 
 
@@ -57,6 +59,15 @@
   return 0;
 }
 
+void VariablesManager::Private::fillList( std::list< VariableNG* >& list, const std::map< ScopedName, VariableNG* >& map )
+{
+  for( std::map<ScopedName, VariableNG*>::const_iterator it = map.begin();
+        it != map.end(); ++it)
+  {
+    list.push_back( it->second );
+  }
+}
+
 VariablesManager::VariablesManager() : d(new Private)
 {
 }
@@ -124,12 +135,20 @@
 
 AST::Statement* VariablesManager::garbageCollectCurrentContext() const
 {
-  return 0;
+  std::list< VariableNG* > list;
+  d->fillList( list, d->contextes.begin()->variables );
+  return new AST::VariablesGarbageCollectionStatement( list );
 }
 
 AST::Statement* VariablesManager::garbageCollectEverything( ) const
 {
-  return 0;
+  std::list< VariableNG* > list;
+  for( std::list<Context>::const_iterator cit = d->contextes.begin();
+       cit != d->contextes.end(); cit++)
+  {
+    d->fillList( list, cit->variables );
+  }
+  return new AST::VariablesGarbageCollectionStatement( list );
 }
 
 void VariablesManager::declareConstant( const ScopedName& _scopedName, VariableNG* _variable)


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/