[opengtl-commits] [244] * add Expression:: markAsReturnExpression to indicate that an expression will be part of a return expression and that an object might have to live longer

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


Revision: 244
Author:   cyrille
Date:     2008-06-26 22:27:40 +0200 (Thu, 26 Jun 2008)

Log Message:
-----------
* add Expression::markAsReturnExpression  to indicate that an expression will be part of a return expression and that an object might have to live longer
* add the possibility to allocate in memory (instead of on the stack) for structure :
 - add VariableNG::setAllocateInMemory and VariableNG::cleanup (to cleanup if variable is in memory)
 - Visitor receive an extra arguments to allocate in memory

All this to be able to return structures and arrays from a function

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
    trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h
    trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.h
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h
    trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.h
    trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp


Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -42,14 +42,6 @@
   return GTLCore::ExpressionResult( visitor->get( _gc, _bb, ptr_ ) );
 }
 
-llvm::BasicBlock* AccessorExpression::assignValue( GenerationContext& _gc, llvm::BasicBlock* _bb, const Expression* _rhs )
-{
-  llvm::Value* ptr_ = pointer( _gc, _bb );
-  GTL_ASSERT(ptr_);
-  const Visitor* visitor = Visitor::getVisitorFor( type() );
-  return visitor->set( _gc, _bb, ptr_, type(), _rhs->generateValue( _gc, _bb).value(), _rhs->type() );
-}
-
 //------------------- ArraySizeAccessorExpression -------------------//
 
 ArraySizeAccessorExpression::ArraySizeAccessorExpression(AccessorExpression* _parent )
@@ -77,6 +69,9 @@
                                       indexes.begin(), indexes.end(), "", _bb);
 }
 
+void ArraySizeAccessorExpression::markAsReturnExpression()
+{
+}
 
 //------------------- StructAccessorExpression -------------------//
 
@@ -103,6 +98,11 @@
   return (*m_parent->type()->structDataMembers())[ m_index].type();
 }
 
+void StructAccessorExpression::markAsReturnExpression()
+{
+  m_parent->markAsReturnExpression();
+}
+
 //------------------- ArrayAccessorExpression -------------------//
 
 ArrayAccessorExpression::ArrayAccessorExpression(AccessorExpression * _parent, Expression* _index) : m_parent(_parent), m_index(_index)
@@ -132,6 +132,11 @@
   return type;
 }
 
+void ArrayAccessorExpression::markAsReturnExpression()
+{
+  m_parent->markAsReturnExpression();
+}
+
 //------------------- VariableAccessorExpression -------------------//
 
 VariableAccessorExpression::VariableAccessorExpression( GTLCore::VariableNG* _variable ) : m_variable(_variable)
@@ -154,6 +159,17 @@
   return m_variable->type();
 }
 
+void VariableAccessorExpression::markAsReturnExpression()
+{
+  m_variable->setAllocateInMemory( true );
+  GTL_DEBUG( m_variable->allocatedInMemory() );
+}
+
+bool VariableAccessorExpression::allocatedInMemory() const
+{
+  return m_variable->allocatedInMemory();
+}
+
 //------------------- FunctionMemberAccessorExpression -------------------//
 
 FunctionMemberAccessorExpression::FunctionMemberAccessorExpression( AccessorExpression * _parent, 
@@ -173,6 +189,7 @@
 {
   return m_member->returnType();
 }
+
 GTLCore::ExpressionResult FunctionMemberAccessorExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
 {
   return GTLCore::ExpressionResult( _gc.codeGenerator()->callFunction( _gc, bb, m_member->function(), m_arguments ) );
@@ -180,6 +197,24 @@
 
 llvm::Value* FunctionMemberAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const
 {
-  GTL_ABORT("no pointer for function member accessor");
+  GTL_ABORT("No pointer for function member accessor.");
   return 0;
 }
+
+bool FunctionMemberAccessorExpression::allocatedInMemory() const
+{
+  GTL_ABORT("No memory is allocated for a function member accessor.");
+  return false;
+}
+
+void FunctionMemberAccessorExpression::markAsReturnExpression()
+{
+  // There is no easy way to know if an Array/Structure given as argument of a function
+  // will or will not be returned by the function, hence the need to mark parameters
+  // as part of a return expression
+  for( std::list<Expression*>::iterator it = m_arguments.begin();
+       it != m_arguments.end(); ++it)
+  {
+    (*it)->markAsReturnExpression();
+  }
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h	2008-06-26 20:27:40 UTC (rev 244)
@@ -29,9 +29,9 @@
     class AccessorExpression : public Expression {
       public:
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
-        llvm::BasicBlock* assignValue( GenerationContext& _gc, llvm::BasicBlock* _bb, const Expression* _rhs );
       public:
         virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const = 0;
+        virtual bool allocatedInMemory() const = 0;
     };
     class ArraySizeAccessorExpression : public AccessorExpression {
       public:
@@ -39,6 +39,8 @@
         virtual bool isConstant() const;
         virtual const GTLCore::Type* type() const;
         virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+        virtual void markAsReturnExpression();
+        virtual bool allocatedInMemory() const { return m_parent->allocatedInMemory(); }
       private:
         AccessorExpression * m_parent;
     };
@@ -49,6 +51,8 @@
         virtual const GTLCore::Type* type() const;
       public:
         virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+        virtual void markAsReturnExpression();
+        virtual bool allocatedInMemory() const { return m_parent->allocatedInMemory(); }
       private:
         AccessorExpression * m_parent;
         int m_index;
@@ -60,6 +64,8 @@
         virtual const GTLCore::Type* type() const;
       public:
         virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+        virtual void markAsReturnExpression();
+        virtual bool allocatedInMemory() const { return m_parent->allocatedInMemory(); }
       private:
         AccessorExpression * m_parent;
         Expression* m_index;
@@ -71,6 +77,8 @@
         virtual const GTLCore::Type* type() const;
       public:
         virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+        virtual void markAsReturnExpression();
+        virtual bool allocatedInMemory() const;
       private:
         GTLCore::VariableNG* m_variable;
     };
@@ -84,6 +92,8 @@
       public:
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
         virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+        virtual void markAsReturnExpression();
+        virtual bool allocatedInMemory() const;
       private:
         AccessorExpression* m_parent;
         const Type::StructFunctionMember* m_member;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -52,6 +52,12 @@
   return GTLCore::Type::Boolean;
 }
 
+void BinaryExpression::markAsReturnExpression()
+{
+  m_lhs->markAsReturnExpression();
+  m_rhs->markAsReturnExpression();
+}
+
 const GTLCore::Type* OrBinaryExpression::type() const
 {
   return Type::Boolean;
@@ -190,7 +196,7 @@
   GTL_DEBUG( *m_lhs->type() );
   GTL_DEBUG( *rightHandSide()->type() );
   return visitor->set( _gc, _bb, ptr_, m_lhs->type(),
-                      rightHandSide()->generateValue( _gc, _bb).value(), rightHandSide()->type() );
+                      rightHandSide()->generateValue( _gc, _bb).value(), rightHandSide()->type(), false );
 }
 
 GTLCore::ExpressionResult AssignementBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h	2008-06-26 20:27:40 UTC (rev 244)
@@ -46,6 +46,7 @@
         {
           return m_lhs->isConstant() or m_rhs->isConstant();
         }
+        virtual void markAsReturnExpression();
       private:
         Expression* m_lhs;
         Expression* m_rhs;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -101,3 +101,8 @@
   GTL_ABORT("Can't generate coumpound value, neither array, neither expression.");
   return GTLCore::ExpressionResult();
 }
+
+void CoumpoundExpression::markAsReturnExpression()
+{
+  GTL_ABORT("CoumpoundExpression can't be in a return statement");
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.h	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.h	2008-06-26 20:27:40 UTC (rev 244)
@@ -33,6 +33,7 @@
         virtual bool isConstant() const;
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const;
         int size() { return m_expressions.size(); }
+        void markAsReturnExpression();
       private:
         std::vector<Expression*> m_expressions;
         const GTLCore::Type* m_type;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -94,6 +94,18 @@
   return _gc.codeGenerator()->callFunction( _gc, bb, m_function, m_arguments );
 }
 
+void FunctionCallExpression::markAsReturnExpression()
+{
+  // There is no easy way to know if an Array/Structure given as argument of a function
+  // will or will not be returned by the function, hence the need to mark parameters
+  // as part of a return expression
+  for( std::list<Expression*>::iterator it = m_arguments.begin();
+       it != m_arguments.end(); ++it)
+  {
+    (*it)->markAsReturnExpression();
+  }
+}
+
 // NumberExpression
 
 namespace GTLCore { // GCC or C++ or both sucks and it is required for the template to be defined

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h	2008-06-26 20:27:40 UTC (rev 244)
@@ -42,6 +42,13 @@
         virtual bool isConstant() const = 0;
         virtual llvm::BasicBlock* generateStatement( GenerationContext&, llvm::BasicBlock* ) const;
         virtual GTLCore::ExpressionResult generateValue( GenerationContext&, llvm::BasicBlock* bb ) const = 0;
+        /**
+         * This function is called inside a \ref ReturnStatement to warn the \ref Expression
+         * that the result will be returned.
+         * This is mostly used to mark Array and Structure to be allocated in memory
+         * and not on the stack.
+         */
+        virtual void markAsReturnExpression() = 0;
     };
 
     /**
@@ -67,6 +74,7 @@
         virtual const GTLCore::Type* type() const { return m_clone->type(); }
         virtual bool isConstant() const { return m_clone->isConstant(); }
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+        virtual void markAsReturnExpression() { m_clone->markAsReturnExpression(); }
       private:
         Expression* m_clone;
     };
@@ -77,6 +85,7 @@
         virtual const GTLCore::Type* type() const { return m_expression->type(); }
         virtual bool isConstant() const { return true; }
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+        virtual void markAsReturnExpression() { m_expression->markAsReturnExpression(); }
       private:
         Expression* m_expression;
     };
@@ -93,6 +102,7 @@
         virtual bool isConstant() const { return true; }
         _T_ value() const { return m_val; }
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+        virtual void markAsReturnExpression() { }
       private:
         _T_ m_val;
     };
@@ -115,6 +125,7 @@
         virtual const GTLCore::Type* type() const;
         virtual bool isConstant() const { return false; }
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+        virtual void markAsReturnExpression();
       private:
         GTLCore::Function* m_function;
         std::list<Expression*> m_arguments;
@@ -141,6 +152,7 @@
         virtual const GTLCore::Type* type() const { return 0; }
         virtual bool isConstant() const { return true; }
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
+        virtual void markAsReturnExpression() {}
       private:
         GTLCore::String m_string;
     };

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -102,7 +102,13 @@
   // List of functions
   std::vector<llvm::Function*> functions( params.size() + 1 );
   // Generate the full function
-  llvm::FunctionType* definitionType = llvm::FunctionType::get( m_function->returnType()->d->type(), params, false );
+  const llvm::Type* returnType = m_function->returnType()->d->type();
+  if( m_function->returnType()->dataType() == Type::STRUCTURE
+      or m_function->returnType()->dataType() == Type::ARRAY )
+  {
+    returnType = llvm::PointerType::get( returnType, 0 );
+  }
+  llvm::FunctionType* definitionType = llvm::FunctionType::get( returnType, params, false );
   GTLCore::String fullFunctionName = GTLCore::Function::Data::symbolName( m_function->name(), m_function->parameters());
   llvm::Function* fullFunction = _codeGenerator->createFunction(definitionType, fullFunctionName );
   functions[ params.size() ] = fullFunction;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -202,23 +202,50 @@
   return after;
 }
 
+//------------------------- ReturnStatement -------------------------//
+
+ReturnStatement::ReturnStatement( Expression* _returnExpr, std::list<VariableNG*> _variablesToClean ) : m_returnExpr( _returnExpr ), m_variablesToClean( _variablesToClean )
+{
+  if( m_returnExpr )
+  {
+    m_returnExpr->markAsReturnExpression();
+  }
+}
+
 ReturnStatement::~ReturnStatement()
 {
   delete m_returnExpr;
 }
 
 llvm::BasicBlock* ReturnStatement::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb) const
-{ // TODO move to the code generator ?
+{
   if( m_returnExpr )
   {
     llvm::Value* result = m_returnExpr->generateValue( _context, _bb).value();
-    new llvm::ReturnInst( _context.codeGenerator()->convertValueTo(_bb, result, m_returnExpr->type(), _context.function()->returnType()  ), _bb);
+    for( std::list<VariableNG*>::const_iterator it = m_variablesToClean.begin();
+         it != m_variablesToClean.end(); ++it)
+    {
+      _bb = (*it)->cleanUp( _context, _bb, result);
+    }
+    if( m_returnExpr->type()->dataType() != Type::ARRAY
+        and m_returnExpr->type()->dataType() != Type::STRUCTURE )
+    {
+      result = _context.codeGenerator()->convertValueTo(_bb, result, m_returnExpr->type(), _context.function()->returnType() );
+    }
+    new llvm::ReturnInst( result, _bb);
   } else {
+    for( std::list<VariableNG*>::const_iterator it = m_variablesToClean.begin();
+         it != m_variablesToClean.end(); ++it)
+    {
+      _bb = (*it)->cleanUp(_context, _bb, 0);
+    }
     new llvm::ReturnInst( _bb );
   }
   return _bb;
 }
 
+//------------------------- PrintStatement --------------------------//
+
 PrintStatement::~PrintStatement()
 {
   deleteAll( m_expressions );
@@ -229,7 +256,7 @@
   std::vector<const llvm::Type*> params;
   params.push_back( llvm::Type::Int32Ty);
   llvm::FunctionType* definitionType = llvm::FunctionType::get( llvm::Type::VoidTy, params, true );
-  llvm::Function* func = dynamic_cast<llvm::Function*>( _context.llvmModule()->getOrInsertFunction("_Z5printiz", definitionType));
+  llvm::Function* func = dynamic_cast<llvm::Function*>( _context.llvmModule()->getOrInsertFunction("print", definitionType));
   
   std::vector<llvm::Value*> values;
   values.push_back( _context.codeGenerator()->integerToConstant( m_expressions.size() ));

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.h	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.h	2008-06-26 20:27:40 UTC (rev 244)
@@ -163,13 +163,17 @@
      */
     class ReturnStatement : public Statement {
       public:
-        ReturnStatement( Expression* _returnExpr ) : m_returnExpr( _returnExpr )
-        {
-        }
+        /**
+         * @param _returnExpr
+         * @param _variablesToClean list of variables used so far, that will need to be
+         *        cleaned by the return expression
+         */
+        ReturnStatement( Expression* _returnExpr, std::list<VariableNG*> _variablesToClean );
         ~ReturnStatement();
         virtual llvm::BasicBlock* generateStatement( GenerationContext&, llvm::BasicBlock* ) const;
       private:
         Expression* m_returnExpr;
+        std::list<VariableNG*> m_variablesToClean;
     };
     /**
      * @internal

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -31,6 +31,10 @@
   delete m_rhs;
 }
 
+void UnaryExpression::markAsReturnExpression()
+{
+  m_rhs->markAsReturnExpression();
+}
 
 GTLCore::ExpressionResult MinusUnaryExpression::generateValue( GenerationContext& _gc,  llvm::BasicBlock* bb ) const
 {

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h	2008-06-26 20:27:40 UTC (rev 244)
@@ -39,6 +39,7 @@
         virtual const GTLCore::Type* type() const { return m_rhs->type(); }
         virtual bool isConstant() const { return m_rhs->isConstant(); }
         const Expression* rightHandSide() const { return m_rhs; }
+        virtual void markAsReturnExpression();
       private:
         Expression* m_rhs;
     };

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -61,6 +61,7 @@
   LexerBase* lexer;
   String nameSpace;
   std::list< Context > contextes;
+  std::list<VariableNG*> functionVariables;
 };
 
 ParserBase::ParserBase(CompilerBase* _compiler, LexerBase* _lexer) : d(new Private)
@@ -254,7 +255,7 @@
   }
 }
 
-AST::Expression* ParserBase::parseExpression(bool _constantExpression)
+AST::Expression* ParserBase::parseExpression(bool _constantExpression, const GTLCore::Type* _type)
 {
   // The first token of an expression is either a primary, or an unary expression or a parenthesis
   if( d->currentToken.type == Token::STARTBRACKET )
@@ -302,6 +303,13 @@
     } else if( expr and d->currentToken.isBinaryOperator() ) {
       return parseFlatBinaryOperator( _constantExpression, expr );
     }
+  } else if( currentToken().type == Token::STARTBRACE )
+  {
+    AST::CoumpoundExpression* coumpoundExpression = parseCoumpoundExpression( _type, true );
+    if( coumpoundExpression )
+    {
+      return new AST::GlobalDataExpression( coumpoundExpression );
+    }
   } else {
     GTL_DEBUG("unexpected");
     reportUnexpected( d->currentToken );
@@ -355,6 +363,12 @@
         expr = parsePrimaryExpression(_constantExpression);
       } else if( d->currentToken.isUnaryOperator() ) {
         expr = parseUnaryOperator(_constantExpression);
+      } else if( currentToken().type == Token::STARTBRACE ) {
+        AST::CoumpoundExpression* coumpoundExpression = parseCoumpoundExpression( _lhs->type() , true );
+        if( coumpoundExpression )
+        {
+          return new AST::GlobalDataExpression( coumpoundExpression );
+        }
       } else {
         GTL_DEBUG("unexpected");
         reportUnexpected( d->currentToken );
@@ -568,8 +582,13 @@
 void ParserBase::parseFunction()
 {
   GTL_ASSERT( d->currentToken.isFunctionType() );
+  // Parse the type
   const Type* returnType = parseFunctionType();
-  GTL_ASSERT( returnType );
+  if( not returnType ) return;
+  
+  // Clear the list of variables
+  d->functionVariables.clear();
+  
   // Next is the name of the function
   if( isOfType( d->currentToken, Token::IDENTIFIER ) )
   {
@@ -614,13 +633,7 @@
               if( d->currentToken.type == Token::EQUAL )
               {
                 getNextToken();
-                if( currentToken().type == Token::STARTBRACE )
-                {
-                  AST::CoumpoundExpression* coumpoundExpression = parseCoumpoundExpression( ptype, false );
-                  initialiser = new AST::GlobalDataExpression( coumpoundExpression );
-                } else {
-                  initialiser = parseExpression( false );
-                }
+                initialiser = parseExpression( false, ptype );
                 needToHaveInitialiser = true;
               } else if( needToHaveInitialiser )
               {
@@ -863,13 +876,13 @@
   if( d->currentToken.type == Token::SEMI )
   { // TODO check type
     getNextToken(); // eat the coma
-    return new AST::ReturnStatement( 0 );
+    return new AST::ReturnStatement( 0, functionVariables() );
   } else {
     AST::Expression* expr = parseExpression(false);
     if(expr and isOfType( d->currentToken, Token::SEMI ) )
     {
       getNextToken();
-      return new AST::ReturnStatement( expr );
+      return new AST::ReturnStatement( expr, functionVariables() );
     } else {
       return 0;
     }
@@ -915,18 +928,7 @@
         {
           getNextToken(); // eat the equal
           // Check if it's a coumpound expression
-          if( currentToken().type == Token::STARTBRACE )
-          {
-            AST::CoumpoundExpression* coumpoundExpression = parseCoumpoundExpression( type, true );
-/*            if( coumpoundExpression->size() != *memberArraySize.begin()) // TODO: recurisvely check other sizes
-            {
-              GTL_DEBUG( memberArraySize.size() << " " << coumpoundExpression->size() );
-              reportError("Wrong coumpound initialiser size", currentToken() );
-            }*/
-            initialiser = new AST::GlobalDataExpression( coumpoundExpression );
-          } else {
-            initialiser = parseExpression( false );
-          }
+          initialiser = parseExpression( false, type );
           initialised = true;
         }
         // Create the variable declaration statement
@@ -975,7 +977,10 @@
     getNextToken();
     return Type::Void;
   } else {
-    return parseType();
+    const Type* type = parseType();
+    if( not type ) return 0;
+    std::list< AST::Expression* > sizes = parseArraySize(true);
+    return d->compiler->typeManager()->getArray( type, sizes.size() );
   }
 }
 
@@ -1126,9 +1131,10 @@
     {
       break;
     } else {
-      AST::Expression* expression = parseExpression( false );
+      int posArg = arguments.size();
+      AST::Expression* expression = parseExpression( false, _parameters[ posArg ].type() );
       arguments.push_back( expression);
-      if( _parameters[ arguments.size() - 1 ].output() )
+      if( _parameters[ posArg ].output() )
       {
         if( not dynamic_cast< AST::AccessorExpression* >( expression ) )
         {
@@ -1297,9 +1303,15 @@
   return 0;
 }
 
+std::list<VariableNG*> ParserBase::functionVariables() const
+{
+  return d->functionVariables;
+}
+
 void ParserBase::declareVariable( const ScopedName& _scopedName, VariableNG* _variable)
 {
   d->contextes.begin()->variables[_scopedName] = _variable;
+  d->functionVariables.push_back( _variable );
 }
 
 std::list<int> ParserBase::expressionsListToIntegersList( const std::list< AST::Expression* >& list )

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h	2008-06-26 20:27:40 UTC (rev 244)
@@ -62,7 +62,7 @@
       virtual AST::Tree* tree() = 0;
     protected:
     // Parse functions
-      AST::Expression* parseExpression( bool _constantExpression );
+      AST::Expression* parseExpression( bool _constantExpression, const GTLCore::Type* _type = 0 );
       AST::Expression* parseUnaryOperator( bool _constantExpression );
       /**
        * Will continiously call \ref parseBinaryOperator until there is no more
@@ -146,6 +146,10 @@
       // Context
       struct Context;
       VariableNG* getVariable( const ScopedName&  ) const;
+      /**
+       * @return the list of variables in the function (so far)
+       */
+      std::list<VariableNG*> functionVariables() const;
       void declareVariable( const ScopedName& , VariableNG* );
       void startContext();
       void endContext();

Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -38,6 +38,7 @@
   bool constant;
   bool isInitialised;
   llvm::Value* pointer;
+  bool allocatedInMemory;
 };
 
 VariableNG::VariableNG(const GTLCore::Type* _type, bool _constant ) : d(new Private)
@@ -47,6 +48,7 @@
   d->isInitialised = false;
   d->visitor = Visitor::getVisitorFor( _type );
   d->pointer = 0;
+  d->allocatedInMemory = false;
 }
 VariableNG::~VariableNG()
 {
@@ -64,12 +66,20 @@
 llvm::BasicBlock* VariableNG::initialise( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _bb, llvm::Value* _initialiser, const GTLCore::Type* _initialiserType, const std::list<llvm::Value*>& _initialSize )
 {
   GTL_DEBUG( _initialSize.size() );
-  initialise( _generationContext, new llvm::AllocaInst::AllocaInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb) );
-  _bb = d->visitor->initialise( _generationContext, _bb, d->pointer, d->type, _initialSize);
+  llvm::Value* pointer = 0;
+  if( d->allocatedInMemory
+      and (type()->dataType() == Type::ARRAY or type()->dataType() == Type::STRUCTURE ) )
+  {
+    pointer = new llvm::MallocInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb);
+  } else {
+    pointer = new llvm::AllocaInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb);
+  }
+  initialise( _generationContext, pointer );
+  _bb = d->visitor->initialise( _generationContext, _bb, d->pointer, d->type, _initialSize, d->allocatedInMemory);
   
   if( _initialiser )
   {
-    _bb = d->visitor->set( _generationContext, _bb, d->pointer, d->type, _initialiser, _initialiserType );
+    _bb = d->visitor->set( _generationContext, _bb, d->pointer, d->type, _initialiser, _initialiserType , d->allocatedInMemory);
   }
   return _bb;
 }
@@ -90,10 +100,31 @@
 llvm::BasicBlock* VariableNG::set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _value, const GTLCore::Type* _valueType )
 {
   GTL_ASSERT(not constant() );
-  return d->visitor->set( _generationContext, _currentBlock, d->pointer, d->type, _value, _valueType);
+  return d->visitor->set( _generationContext, _currentBlock, d->pointer, d->type, _value, _valueType, d->allocatedInMemory);
 }
 
 llvm::Value* VariableNG::pointer()
 {
   return d->pointer;
 }
+
+void VariableNG::setAllocateInMemory( bool v )
+{
+  GTL_ASSERT( not d->isInitialised );
+  d->allocatedInMemory = v;
+}
+
+bool VariableNG::allocatedInMemory() const
+{
+  return d->allocatedInMemory;
+}
+
+llvm::BasicBlock* VariableNG::cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _donttouch )
+{
+  if( d->allocatedInMemory )
+  {
+    return d->visitor->cleanUp( _generationContext, _currentBlock, d->pointer, d->type, _donttouch, d->allocatedInMemory );
+    // TODO DESALLOCATE
+  }
+  return _currentBlock;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h	2008-06-26 20:27:40 UTC (rev 244)
@@ -77,6 +77,20 @@
        * @return the pointer for this variable
        */
       llvm::Value* pointer();
+      /**
+       * Mark the variable to be allocated in memory
+       */
+      void setAllocateInMemory( bool v );
+      /**
+       * @return true if the variable is allocated in memory, false otherwise
+       */
+      bool allocatedInMemory() const;
+      /**
+       * Cleanup the variable, free memory if needed, but don't touch the
+       * value in argument.
+       * @param _donttouch variable protected in memory
+       */
+      llvm::BasicBlock* cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _donttouch );
     private:
       struct Private;
       Private* const d;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -106,7 +106,7 @@
   return new llvm::LoadInst( _pointer, "", _currentBlock);
 }
 
-llvm::BasicBlock* PrimitiveVisitor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType ) const
+llvm::BasicBlock* PrimitiveVisitor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType, bool _allocatedInMemory ) const
 {
   GTL_ASSERT( _pointerType->dataType() != Type::STRUCTURE and _pointerType->dataType() != Type::ARRAY );
   new llvm::StoreInst(
@@ -115,12 +115,17 @@
   return _currentBlock;
 }
 
-llvm::BasicBlock* PrimitiveVisitor::initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes) const
+llvm::BasicBlock* PrimitiveVisitor::initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const
 {
   // Don't do nothing
   return _currentBlock;
 }
 
+llvm::BasicBlock* PrimitiveVisitor::cleanUp( GenerationContext& , llvm::BasicBlock* _currentBlock, llvm::Value* , const GTLCore::Type* , llvm::Value* , bool ) const
+{
+  return _currentBlock;
+}
+
 //--------- ArrayVisitor ---------///
 
 ArrayVisitor::ArrayVisitor() : Visitor(  )
@@ -147,14 +152,14 @@
   return _pointer;
 }
 
-llvm::BasicBlock* ArrayVisitor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType) const
+llvm::BasicBlock* ArrayVisitor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType, bool _allocatedInMemory) const
 {
     // Check if size are identical or update the size of this array
     {
       llvm::Value* test= _generationContext.codeGenerator()->createDifferentExpression( _currentBlock, getSize( _generationContext, _currentBlock, _pointer ), Type::Integer32, getSize( _generationContext, _currentBlock, _value ), Type::Integer32);
       llvm::BasicBlock* ifContent = new llvm::BasicBlock;
       _generationContext.llvmFunction()->getBasicBlockList().push_back( ifContent );
-      setSize( _generationContext, ifContent, _pointer, _pointerType, getSize( _generationContext, ifContent, _value ) );
+      setSize( _generationContext, ifContent, _pointer, _pointerType, getSize( _generationContext, ifContent, _value ), _allocatedInMemory, true );
     
       llvm::BasicBlock* afterIf = new llvm::BasicBlock;
       _generationContext.llvmFunction()->getBasicBlockList().push_back( afterIf);
@@ -180,7 +185,7 @@
           visitor->get( _generationContext, bodyBlock, 
                   _generationContext.codeGenerator()->accessArrayValue(
                                     bodyBlock, _value, index->get( _generationContext, bodyBlock  ) ) ),
-          _valueType->embeddedType() );
+          _valueType->embeddedType(), _allocatedInMemory );
     
     // Create the for statement
     return CodeGenerator::createIterationForStatement(
@@ -193,7 +198,7 @@
                     endBodyBlock );
 }
 
-void ArrayVisitor::setSize(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _size) const
+void ArrayVisitor::setSize(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _size, bool _allocatedInMemory, bool _allreadyInitialised) const
 {
   GTL_ASSERT( _pointerType->dataType() == Type::ARRAY );
   GTL_DEBUG( *_size );
@@ -208,8 +213,19 @@
   indexes[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
   {
     llvm::Value* ptr = new llvm::GetElementPtrInst( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
-    llvm::Value* array = new llvm::AllocaInst::AllocaInst(
+    llvm::Value* array = 0;
+    if( _allocatedInMemory )
+    {
+      array = new llvm::MallocInst(
                     _pointerType->embeddedType()->d->type(), _size, "", _currentBlock);
+      if( _allreadyInitialised )
+      {
+        new llvm::FreeInst( ptr, _currentBlock );
+      }
+    } else {
+      array = new llvm::AllocaInst(
+                    _pointerType->embeddedType()->d->type(), _size, "", _currentBlock);
+    }
     new llvm::StoreInst( array, ptr, "", _currentBlock);
   }
 }
@@ -223,13 +239,14 @@
   return new llvm::LoadInst( ptr, "", currentBlock);
 }
 
-llvm::BasicBlock* ArrayVisitor::initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes) const
+llvm::BasicBlock* ArrayVisitor::initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const
 {
   GTL_ASSERT( _pointerType->dataType() == Type::ARRAY );
   GTL_DEBUG( _sizes.empty() );
   if( not _sizes.empty())
   {
-    setSize( _generationContext, _currentBlock, _pointer, _pointerType, _sizes.front() );
+    llvm::Value* currentSize = _sizes.front();
+    setSize( _generationContext, _currentBlock, _pointer, _pointerType, currentSize, _allocatedInMemory, false );
     std::list< llvm::Value*> sizeAfter = _sizes;
     sizeAfter.pop_front();
     //   int i = 0;
@@ -247,14 +264,14 @@
             _generationContext.codeGenerator()->accessArrayValue(
                       bodyBlock, _pointer, index->get( _generationContext, bodyBlock ) ),
             _pointerType->embeddedType(),
-            sizeAfter );
+            sizeAfter, _allocatedInMemory );
     
     // Create the for statement
     return CodeGenerator::createIterationForStatement(
                     _generationContext,
                     _currentBlock,
                     index,
-                    CodeGenerator::integerToConstant(_sizes.size()),
+                    currentSize,
                     Type::Integer32,
                     bodyBlock,
                     endBodyBlock );
@@ -262,6 +279,12 @@
   return _currentBlock;
 }
 
+llvm::BasicBlock* ArrayVisitor::cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const
+{
+  
+  return _currentBlock;
+}
+
 //--------- PrimitiveVisitor ---------///
 
 StructureVisitor::StructureVisitor() : Visitor( )
@@ -297,7 +320,7 @@
   return _pointer;
 }
 
-llvm::BasicBlock* StructureVisitor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType ) const
+llvm::BasicBlock* StructureVisitor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType, bool _allocatedInMemory ) const
 {
   GTL_ASSERT( _pointerType->dataType() == Type::STRUCTURE );
   for(uint i = 0; i < _pointerType->structDataMembers()->size(); ++i)
@@ -307,12 +330,12 @@
     llvm::Value* nptrToValueMember = pointerToValue( _generationContext, _currentBlock, _value, i);
     const Visitor* visitor = Visitor::getVisitorFor( type );
     llvm::Value* memberValue = visitor->get( _generationContext, _currentBlock, nptrToValueMember );
-    visitor->set( _generationContext, _currentBlock, nptrToOwnMember, type, memberValue, type );
+    visitor->set( _generationContext, _currentBlock, nptrToOwnMember, type, memberValue, type, _allocatedInMemory );
   }
   return _currentBlock;
 }
 
-llvm::BasicBlock* StructureVisitor::initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes) const
+llvm::BasicBlock* StructureVisitor::initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const
 {
   GTL_ASSERT( _pointerType->dataType() == Type::STRUCTURE );
   const std::vector<GTLCore::Type::StructDataMember>* sm = _pointerType->structDataMembers();
@@ -329,7 +352,22 @@
     const Visitor* visitor = Visitor::getVisitorFor( type );
     _currentBlock = visitor->initialise( _generationContext, _currentBlock,
                             pointerToValue( _generationContext, _currentBlock, _pointer, i ),
-                            type, sizes );
+                            type, sizes, _allocatedInMemory );
   }
   return _currentBlock;
 }
+
+llvm::BasicBlock* StructureVisitor::cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const
+{
+  if( _pointer == _donttouch ) return _currentBlock;
+  GTL_ASSERT( _pointerType->dataType() == Type::STRUCTURE );
+  const std::vector<GTLCore::Type::StructDataMember>* sm = _pointerType->structDataMembers();
+  
+  for( uint i = 0; i < sm->size(); ++i)
+  {
+    const GTLCore::Type* type = (*sm)[i].type();
+    const Visitor* visitor = Visitor::getVisitorFor( type );
+    _currentBlock = visitor->cleanUp( _generationContext, _currentBlock, pointerToValue( _generationContext, _currentBlock, _pointer, i ), type, _donttouch, _allocatedInMemory );
+  }
+  return _currentBlock;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h	2008-06-26 20:27:40 UTC (rev 244)
@@ -70,8 +70,7 @@
        * @param _ma
        * @return the value
        */
-      virtual llvm::Value* get(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
-                       llvm::Value* pointer) const = 0;
+      virtual llvm::Value* get(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* pointer) const = 0;
       /**
        * Allow to set the value
        * @param _errMsg a pointer to a pointer (usually initialised to 0), the pointer will be
@@ -82,7 +81,7 @@
        * @param _value the new value
        * @param _ma
        */
-      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType) const = 0;
+      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType, bool _allocatedInMemory) const = 0;
       /**
        * initialise a the data which is pointed by this Visitor.
        * @param _errMsg a pointer to a pointer (usually initialised to 0), the pointer will be
@@ -92,7 +91,8 @@
        * @param _pointer a pointer toward the data
        * @param _size the size of the array, if applicable
        */
-      virtual llvm::BasicBlock* initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes) const = 0;
+      virtual llvm::BasicBlock* initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const = 0;
+      virtual llvm::BasicBlock* cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const = 0;
     public:
       /**
        * This function create the Visitor for the type given in argument
@@ -113,8 +113,9 @@
       virtual llvm::Value* pointerToIndex(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _type, llvm::Value* _index) const;
       virtual llvm::Value* get( GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
                                 llvm::Value* pointer) const;
-      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* pointer, const GTLCore::Type* _pointerType, llvm::Value*, const GTLCore::Type* _valueType) const;
-      virtual llvm::BasicBlock* initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes) const;
+      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* pointer, const GTLCore::Type* _pointerType, llvm::Value*, const GTLCore::Type* _valueType, bool _allocatedInMemory) const;
+      virtual llvm::BasicBlock* initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const;
+      virtual llvm::BasicBlock* cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const;
   };
   /**
    * @internal
@@ -129,8 +130,9 @@
       virtual const GTLCore::Type* pointerToIndexType( const GTLCore::Type* _type ) const;
       virtual llvm::Value* pointerToIndex(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _type, llvm::Value* _index) const;
       virtual llvm::Value* get( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer) const;
-      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value*, const GTLCore::Type* _valueType) const;
-      virtual llvm::BasicBlock* initialise( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes) const;
+      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value*, const GTLCore::Type* _valueType, bool _allocatedInMemory) const;
+      virtual llvm::BasicBlock* initialise( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const;
+      virtual llvm::BasicBlock* cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const;
     private:
       /**
        * Allow to access the size of an array.
@@ -151,7 +153,7 @@
        * @param _pointer a pointer toward the data
        * @param _size the new size of the array
        */
-      void setSize(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _size ) const;
+      void setSize(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _size, bool _allocatedInMemory, bool _allreadyInitialised ) const;
   };
 
   /**
@@ -166,8 +168,9 @@
       virtual const GTLCore::Type* pointerToIndexType( const GTLCore::Type* _type ) const;
       virtual llvm::Value* pointerToIndex(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _type, llvm::Value* _index) const;
       virtual llvm::Value* get( GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* pointer) const;
-      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* pointer, const GTLCore::Type* _pointerType, llvm::Value*, const GTLCore::Type* _valueType) const;
-      virtual llvm::BasicBlock* initialise( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes) const;
+      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* pointer, const GTLCore::Type* _pointerType, llvm::Value*, const GTLCore::Type* _valueType, bool _allocatedInMemory) const;
+      virtual llvm::BasicBlock* initialise( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const;
+      virtual llvm::BasicBlock* cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const;
     private:
       llvm::Value* pointerToValue(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, int index ) const;
   };

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -73,7 +73,7 @@
   return result;
 }
 
-llvm::BasicBlock* PixelVisitor::set( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType) const
+llvm::BasicBlock* PixelVisitor::set( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType, bool _allocatedInMemory) const
 {
   new llvm::StoreInst( _value,
                        CodeGenerator::accessPixelDataPtr( _generationContext, _currentBlock, _pointer ),
@@ -82,8 +82,13 @@
   return _currentBlock;
 }
 
-llvm::BasicBlock* PixelVisitor::initialise( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes) const
+llvm::BasicBlock* PixelVisitor::initialise( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemorys) const
 {
   // Don't do nothing
   return _currentBlock;
 }
+
+llvm::BasicBlock* PixelVisitor::cleanUp( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const
+{
+  return _currentBlock;
+}

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.h	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.h	2008-06-26 20:27:40 UTC (rev 244)
@@ -40,10 +40,10 @@
       virtual ~PixelVisitor();
       virtual const GTLCore::Type* pointerToIndexType( const GTLCore::Type* _type ) const;
       virtual llvm::Value* pointerToIndex( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _type, llvm::Value* _index) const;
-      virtual llvm::Value* get(GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
-                       llvm::Value* pointer) const;
-      virtual llvm::BasicBlock* set(GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType) const;
-      virtual llvm::BasicBlock* initialise(GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes) const;
+      virtual llvm::Value* get(GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* pointer) const;
+      virtual llvm::BasicBlock* set(GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType, bool _allocatedInMemory) const;
+      virtual llvm::BasicBlock* initialise(GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const;
+      virtual llvm::BasicBlock* cleanUp( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const;
   };
   
 }

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-06-26 20:23:07 UTC (rev 243)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-06-26 20:27:40 UTC (rev 244)
@@ -166,7 +166,6 @@
 
 STATIC_INITIALISATION(OpenShivaTypes)
 {
-
   { // Image
     Wrapper::Private::s_imageDataMembers.push_back( GTLCore::Type::StructDataMember( "image", GTLCore::Type::Pointer) );
   }


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