[opengtl-commits] [188] finish the accessor refactoring:

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


Revision: 188
Author:   cyrille
Date:     2008-06-13 21:38:35 +0200 (Fri, 13 Jun 2008)

Log Message:
-----------
finish the accessor refactoring:
 * Visitor replace accessor, are singletons, and are limited to copy of value and of initialisation, this makes the ugly MemberArray unneeded
 * structure copy works again and is now tested

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/tests/complextypes/CMakeLists.txt
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h
    trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h
    trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
    trunk/OpenGTL/OpenGTL/GTLCore/Macros.h
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/Type.h
    trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h

Added Paths:
-----------
    trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h

Removed Paths:
-------------
    trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/ArrayStructs_p.h


Modified: trunk/OpenGTL/OpenCTL/tests/complextypes/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/complextypes/CMakeLists.txt	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenCTL/tests/complextypes/CMakeLists.txt	2008-06-13 19:38:35 UTC (rev 188)
@@ -13,6 +13,7 @@
   structarraysimplecoumpoundinitialiser.ctl
   structarrayarraysimplecoumpoundinitialiser.ctl
   structfunctioncoumpoundinitialisation.ctl
+  copystruct.ctl
   )
 
 FOREACH( TEST_FILE ${TESTS_FILES} )

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-06-13 19:38:35 UTC (rev 188)
@@ -26,6 +26,7 @@
 #include "../ExpressionResult_p.h"
 #include "../Debug.h"
 #include "../VariableNG_p.h"
+#include "../Visitor_p.h"
 #include "../Type.h"
 
 using namespace GTLCore::AST;
@@ -36,28 +37,15 @@
 {
   llvm::Value* ptr_ = pointer( _gc, _bb );
   GTL_DEBUG( *ptr_ << " " << *ptr_->getType() );
-  return GTLCore::ExpressionResult( new llvm::LoadInst( ptr_, "", _bb) );
+  const Visitor* visitor = Visitor::getVisitorFor( type() );
+  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 );
-  if( type()->dataType() == Type::ARRAY )
-  {
-    GTL_ASSERT(false);
-  } else if( type()->dataType() == Type::STRUCTURE ) {
-    GTL_ASSERT(false);
-  } else {
-    GTL_DEBUG( *ptr_ << " " << *ptr_->getType());
-    new llvm::StoreInst(
-            _gc.codeGenerator()->convertValueTo(
-                      _bb,
-                      _rhs->generateValue( _gc, _bb).value(),
-                      _rhs->type(),
-                      type() ),
-            ptr_, "", _bb );
-  }
-  return _bb;
+  const Visitor* visitor = Visitor::getVisitorFor( type() );
+  return visitor->set( _gc, _bb, ptr_, type(), _rhs->generateValue( _gc, _bb).value(), _rhs->type() );
 }
 
 //------------------- ArraySizeAccessorExpression -------------------//

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp	2008-06-13 19:38:35 UTC (rev 188)
@@ -26,6 +26,7 @@
 #include <GTLCore/ExpressionResult_p.h>
 #include <GTLCore/Type.h>
 #include <GTLCore/VariableNG_p.h>
+#include <GTLCore/Visitor_p.h>
 
 using namespace GTLCore::AST;
 
@@ -181,30 +182,47 @@
   return _gc.codeGenerator()->createModuloExpression(bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
 }
 
+#if 0
+
 llvm::BasicBlock* AssignementBinaryExpression::generateStatement( GenerationContext& _gc, llvm::BasicBlock* _bb) const
 {
-  if( m_lhs )
-  {
-    return m_lhs->variable()->set( _gc, _bb,
-                  rightHandSide()->generateValue( _gc, _bb).value(), rightHandSide()->type(), m_lhs->memberArray());
-  } else {
-    GTL_ASSERT( m_lhsBis);
-    return m_lhsBis->assignValue( _gc, _bb, rightHandSide() );
-  }
+  GTL_ASSERT( m_lhs);
+  return m_lhs->assignValue( _gc, _bb, rightHandSide() );
 }
 
+#endif
+
+#if 0
 GTLCore::ExpressionResult AssignementBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
 {
-  if( m_lhs )
-  {
-    llvm::BasicBlock* bbr = m_lhs->variable()->set( _gc, _bb,
-                  rightHandSide()->generateValue( _gc, _bb).value(), rightHandSide()->type(), m_lhs->memberArray());
-    GTL_ASSERT( bbr == _bb);
-    return GTLCore::ExpressionResult( m_lhs->generateValue( _gc, _bb) );
-  } else {
-    GTL_ASSERT( m_lhsBis);
-    llvm::BasicBlock* bbr = m_lhsBis->assignValue( _gc, _bb, rightHandSide() );
-    GTL_ASSERT( bbr == _bb);
-    return GTLCore::ExpressionResult( m_lhsBis->generateValue( _gc, _bb) );
-  }
+  GTL_ASSERT( m_lhs);
+  llvm::BasicBlock* bbr = m_lhs->assignValue( _gc, _bb, rightHandSide() );
+  GTL_ASSERT( bbr == _bb);
+  return GTLCore::ExpressionResult( m_lhs->generateValue( _gc, _bb) );
 }
+#endif
+
+#if 1
+
+llvm::BasicBlock* AssignementBinaryExpression::generateStatement( GenerationContext& _gc, llvm::BasicBlock* _bb) const
+{
+  GTL_ASSERT( m_lhs);
+  llvm::Value* ptr_ = m_lhs->pointer( _gc, _bb );
+  const Visitor* visitor = Visitor::getVisitorFor( m_lhs->type() );
+  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() );
+}
+
+#endif
+
+
+GTLCore::ExpressionResult AssignementBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
+{
+  GTL_ASSERT( m_lhs);
+  llvm::BasicBlock* bbr = generateStatement( _gc, _bb );
+  GTL_ASSERT( bbr == _bb);
+  return GTLCore::ExpressionResult( m_lhs->generateValue( _gc, _bb) );
+}
+

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h	2008-06-13 19:38:35 UTC (rev 188)
@@ -264,17 +264,13 @@
      */
     class AssignementBinaryExpression : public BinaryExpression {
       public:
-        AssignementBinaryExpression( VariableExpression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs ), m_lhs(lhs), m_lhsBis(0)
+        AssignementBinaryExpression( AccessorExpression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs ), m_lhs(lhs)
         {
         }
-        AssignementBinaryExpression( AccessorExpression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs ), m_lhs(0), m_lhsBis(lhs)
-        {
-        }
         virtual llvm::BasicBlock* generateStatement( GenerationContext&, llvm::BasicBlock* ) const;
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
       private:
-        VariableExpression* m_lhs;
-        AccessorExpression* m_lhsBis;
+        AccessorExpression* m_lhs;
     };
   }
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-06-13 19:38:35 UTC (rev 188)
@@ -27,7 +27,6 @@
 
 #include "GTLCore/CodeGenerator_p.h"
 #include "GTLCore/ExpressionResult_p.h"
-#include "GTLCore/ArrayStructs_p.h"
 #include "GTLCore/VariableNG_p.h"
 #include "GTLCore/Type.h"
 #include "GTLCore/Type_p.h"
@@ -76,29 +75,6 @@
 }
 
 //------------------------------------------//
-//----------- VariableExpression -----------//
-//------------------------------------------//
-
-VariableExpression::~VariableExpression()
-{
-  delete m_memberArray;
-}
-
-const GTLCore::Type* VariableExpression::type() const
-{
-  return m_variable->type();
-}
-bool VariableExpression::isConstant() const
-{
-  return m_variable->constant();
-}
-
-GTLCore::ExpressionResult VariableExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
-{
-  return GTLCore::ExpressionResult(m_variable->get( _gc, bb, m_memberArray));
-}
-
-//------------------------------------------//
 //--------- FunctionCallExpression ---------//
 //------------------------------------------//
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.h	2008-06-13 19:38:35 UTC (rev 188)
@@ -25,7 +25,6 @@
 
 namespace GTLCore {
   class ExpressionResult;
-  class MemberArray;
   class Type;
   class Function;
 
@@ -97,28 +96,6 @@
       private:
         _T_ m_val;
     };
-
-    /**
-     * @internal
-     * This represent access to a variable in the tree. It can either be used to affect
-     * the variable with a \ref AssignementBinaryExpression , or to return the value
-     * contains by this \ref Variable .
-     * 
-     * @ingroup GTLCore_AST
-     */
-    class VariableExpression : public Expression {
-      public:
-        explicit VariableExpression( GTLCore::VariableNG* _variable, GTLCore::MemberArray* _memberArray ) : m_variable(_variable), m_memberArray(_memberArray) {}
-        ~VariableExpression();
-        virtual const GTLCore::Type* type() const;
-        virtual bool isConstant() const;
-        GTLCore::VariableNG* variable() { return m_variable; }
-        GTLCore::MemberArray* memberArray() { return m_memberArray; }
-        virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
-      private:
-        GTLCore::VariableNG* m_variable;
-        GTLCore::MemberArray* m_memberArray;
-    };
     
     /**
      * @internal

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp	2008-06-13 19:38:35 UTC (rev 188)
@@ -39,25 +39,15 @@
 
 GTLCore::ExpressionResult MinusMinusUnaryExpression::generateValue( GenerationContext& _gc,  llvm::BasicBlock* bb ) const
 {
-  if( m_rhs )
-  {
-    _gc.codeGenerator()->createDecrementExpression( bb, m_rhs->variable() );
-  } else {
-    GTL_ASSERT( m_rhsBis );
-    _gc.codeGenerator()->createDecrementExpression( bb, m_rhsBis->pointer( _gc, bb) );
-  }
+  GTL_ASSERT( m_rhs );
+  _gc.codeGenerator()->createDecrementExpression( bb, m_rhs->pointer( _gc, bb) );
   return rightHandSide()->generateValue( _gc, bb);
 }
 
 GTLCore::ExpressionResult PlusPlusUnaryExpression::generateValue( GenerationContext& _gc,  llvm::BasicBlock* bb ) const
 {
-  if( m_rhs )
-  {
-    _gc.codeGenerator()->createIncrementExpression( bb, m_rhs->variable() );
-  } else {
-    GTL_ASSERT( m_rhsBis );
-    _gc.codeGenerator()->createIncrementExpression( bb, m_rhsBis->pointer( _gc, bb) );
-  }
+  GTL_ASSERT( m_rhs );
+  _gc.codeGenerator()->createIncrementExpression( bb, m_rhs->pointer( _gc, bb) );
   return rightHandSide()->generateValue( _gc, bb);
 }
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h	2008-06-13 19:38:35 UTC (rev 188)
@@ -57,13 +57,11 @@
      */
     class MinusMinusUnaryExpression : public UnaryExpression {
       public:
-        explicit MinusMinusUnaryExpression(VariableExpression* rhs) : UnaryExpression(rhs), m_rhs(rhs), m_rhsBis(0) {}
-        explicit MinusMinusUnaryExpression(AccessorExpression* rhs) : UnaryExpression(rhs), m_rhs(0), m_rhsBis(rhs) {}
+        explicit MinusMinusUnaryExpression(AccessorExpression* rhs) : UnaryExpression(rhs), m_rhs(rhs) {}
         virtual bool isConstant() const { return false; }
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
       private:
-        VariableExpression* m_rhs;
-        AccessorExpression* m_rhsBis;
+        AccessorExpression* m_rhs;
     };
     /**
      * @internal
@@ -71,13 +69,11 @@
      */
     class PlusPlusUnaryExpression : public UnaryExpression {
       public:
-        explicit PlusPlusUnaryExpression(VariableExpression* rhs) : UnaryExpression(rhs), m_rhs(rhs) {}
-        explicit PlusPlusUnaryExpression(AccessorExpression* rhs) : UnaryExpression(rhs), m_rhs(0), m_rhsBis(rhs) {}
+        explicit PlusPlusUnaryExpression(AccessorExpression* rhs) : UnaryExpression(rhs), m_rhs(rhs) {}
         virtual bool isConstant() const { return false; }
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
       private:
-        VariableExpression* m_rhs;
-        AccessorExpression* m_rhsBis;
+        AccessorExpression* m_rhs;
     };
     /**
      * @internal

Deleted: trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.cpp	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.cpp	2008-06-13 19:38:35 UTC (rev 188)
@@ -1,393 +0,0 @@
-/*
- *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "Accessor_p.h"
-
-// LLVM
-#include <llvm/BasicBlock.h>
-#include <llvm/Constants.h>
-#include <llvm/Function.h>
-#include <llvm/Instructions.h>
-
-// GTLCore
-#include "ArrayStructs_p.h"
-#include "CodeGenerator_p.h"
-#include "Debug.h"
-#include "Type.h"
-#include "Type_p.h"
-#include "ErrorMessage.h"
-#include "ErrorMessages_p.h"
-#include "ExpressionResult_p.h"
-#include "VariableNG_p.h"
-#include "Utils_p.h"
-
-#include "AST/Expression.h"
-
-using namespace GTLCore;
-
-//--------- Accessor ---------///
-
-Accessor::Accessor(const GTLCore::Type* _type, bool constant) :
-    m_constant(constant),
-    m_initialisedValue(false),
-    m_type(_type)
-{
-}
-
-Accessor::~Accessor()
-{
-  
-}
-
-bool Accessor::isConstant() const
-{
-  return m_constant;
-}
-
-const GTLCore::Type* Accessor::type()
-{
-  return m_type;
-}
-
-Accessor* Accessor::getAccessorFor(const GTLCore::Type* _type, bool constant)
-{
-  if( _type->dataType() == Type::ARRAY )
-  {
-    return new ArrayAccessor(_type, constant );
-  } else if( _type->dataType() == Type::STRUCTURE ) {
-    return new StructureAccessor(_type, constant );
-  } else {
-    return new PrimitiveAccessor(_type, constant );
-  }
-}
-
-llvm::BasicBlock* Accessor::initialiseValue( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType )
-{
-  GTL_ASSERT(not m_initialisedValue);
-  m_initialisedValue = true;
-  if( _value )
-  {
-    bool constant = m_constant;
-    m_constant = false;
-    _currentBlock = set( _generationContext, _currentBlock, _pointer, _value, _valueType );
-    m_constant = constant;
-  }
-  return _currentBlock;
-}
-
-//--------- PrimitiveAccessor ---------///
-
-PrimitiveAccessor::PrimitiveAccessor(const GTLCore::Type* _type, bool constant) : Accessor( _type, constant )
-{
-}
-
-PrimitiveAccessor::~PrimitiveAccessor()
-{
-}
-
-llvm::Value* PrimitiveAccessor::get( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-                                llvm::Value* _pointer, MemberArray* _ma)
-{
-  GTL_ASSERT( not _ma or _ma->empty );
-  return new llvm::LoadInst( _pointer, "", _currentBlock);
-}
-
-llvm::BasicBlock* PrimitiveAccessor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-                        llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma)
-{
-  GTL_ASSERT( not _ma or _ma->empty );
-  GTL_ASSERT( not isConstant());
-  new llvm::StoreInst(
-          _generationContext.codeGenerator()->convertValueTo( _currentBlock, _value, _valueType, type() ),
-          _pointer, "", _currentBlock);
-  return _currentBlock;
-}
-
-void PrimitiveAccessor::setSize(GenerationContext& , llvm::BasicBlock*, llvm::Value* , llvm::Value* )
-{
-  GTL_ASSERT(false);
-}
-
-llvm::Value* PrimitiveAccessor::getSize(GenerationContext& , llvm::BasicBlock*, llvm::Value* )
-{
-  GTL_ASSERT(false);
-  return 0;
-}
-
-llvm::BasicBlock* PrimitiveAccessor::initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const std::list< llvm::Value*>& _sizes)
-{
-  // Don't do nothing
-  return _currentBlock;
-}
-
-//--------- ArrayAccessor ---------///
-
-ArrayAccessor::ArrayAccessor(const GTLCore::Type* _type, bool constant) : Accessor( _type, constant ), m_accessor( Accessor::getAccessorFor( _type-> arrayType(), constant) )
-{
-}
-
-ArrayAccessor::~ArrayAccessor()
-{
-  delete m_accessor;
-}
-
-
-llvm::Value* ArrayAccessor::pointerToValue(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-                            llvm::Value* _pointer, MemberArray* _ma )
-{
-  return _generationContext.codeGenerator()->accessArrayValue( _currentBlock, _pointer, _ma->index->generateValue( _generationContext, _currentBlock).value() );
-}
-
-llvm::Value* ArrayAccessor::get( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-                                llvm::Value* _pointer, MemberArray* _ma )
-{
-  if(not _ma or _ma->empty )
-  {
-    return _pointer;
-  } else {
-    if( _ma->array)
-    {
-      llvm::Value* nptr = pointerToValue(_generationContext, _currentBlock, _pointer, _ma);
-      return m_accessor->get( _generationContext, _currentBlock, nptr, _ma->next );
-    } else if (_ma->size ) {
-      return getSize( _generationContext, _currentBlock, _pointer );
-    }
-    GTL_ABORT("Invalid member array for array");
-    return 0;
-  }
-}
-
-llvm::BasicBlock* ArrayAccessor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma )
-{
-  if( not _ma or _ma->empty )
-  {
-    // 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, getSize( _generationContext, ifContent, _value ) );
-    
-      llvm::BasicBlock* afterIf = new llvm::BasicBlock;
-      _generationContext.llvmFunction()->getBasicBlockList().push_back( afterIf);
-      _generationContext.codeGenerator()->createIfStatement( _currentBlock, test, Type::Boolean, ifContent, ifContent, afterIf );
-      _currentBlock = afterIf;
-    
-    }
-    //   int i = 0;
-    GTLCore::VariableNG* index = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
-    index->initialise( _generationContext, _currentBlock, _generationContext.codeGenerator()->integerToConstant(0), Type::Integer32, std::list<llvm::Value*>());
-    
-    // Construct the body of the for loop
-    llvm::BasicBlock* bodyBlock = new llvm::BasicBlock("bodyBlock");
-    _generationContext.llvmFunction()->getBasicBlockList().push_back( bodyBlock);
-//     GTL_DEBUG( " value = " << *_pointer << " type = " << *_pointer->getType() );
-//     GTL_DEBUG( " value = " << *_value << " type = " << *_value->getType() );
-    llvm::BasicBlock* endBodyBlock = m_accessor->set( _generationContext, bodyBlock, 
-        _generationContext.codeGenerator()->accessArrayValue( bodyBlock, _pointer, index->get( _generationContext, bodyBlock  ) ),
-        new llvm::LoadInst( _generationContext.codeGenerator()->accessArrayValue( bodyBlock, _value, index->get( _generationContext, bodyBlock  ) ), "", bodyBlock ), _valueType->arrayType() );
-    
-    // Create the for statement
-    return _generationContext.codeGenerator()->createIterationForStatement(
-                    _generationContext.llvmFunction(),
-                    _currentBlock,
-                    index,
-                    getSize( _generationContext, _currentBlock, _pointer),
-                    Type::Integer32,
-                    bodyBlock,
-                    endBodyBlock );
-    
-  } else {
-    GTL_ASSERT( _ma->array);
-    llvm::Value* nptr = pointerToValue(_generationContext, _currentBlock, _pointer, _ma);
-    m_accessor->set( _generationContext, _currentBlock, nptr, _value, _valueType, _ma->next );
-    return _currentBlock;
-  }
-}
-
-void ArrayAccessor::setSize(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _size)
-{
-  GTL_DEBUG( *_size );
-  std::vector<llvm::Value*> indexes;
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the structure of the array
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the size of the array
-  { // Init the size
-    llvm::Value* ptr = new llvm::GetElementPtrInst( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
-    new llvm::StoreInst(_generationContext.codeGenerator()->convertValueTo( _currentBlock, _size, GTLCore::Type::Integer32, GTLCore::Type::Integer32 ), ptr, "", _currentBlock);
-  }
-  // Allocate the Array
-  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(
-                    type()->arrayType()->d->type(), _size, "", _currentBlock);
-    new llvm::StoreInst( array, ptr, "", _currentBlock);
-  }
-}
-
-llvm::Value* ArrayAccessor::getSize(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer )
-{
-  std::vector<llvm::Value*> indexes;
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the structure of the array
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the size of the array
-  llvm::Value* ptr = new llvm::GetElementPtrInst( _pointer, indexes.begin(), indexes.end(), "", currentBlock);
-  return new llvm::LoadInst( ptr, "", currentBlock);
-}
-
-llvm::BasicBlock* ArrayAccessor::initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const std::list< llvm::Value*>& _sizes)
-{
-  GTL_DEBUG( _sizes.empty() );
-  if( not _sizes.empty())
-  {
-    setSize( _generationContext, _currentBlock, _pointer, _sizes.front() );
-    std::list< llvm::Value*> sizeAfter = _sizes;
-    sizeAfter.pop_front();
-    //   int i = 0;
-    GTLCore::VariableNG* index = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
-    index->initialise( _generationContext, _currentBlock, _generationContext.codeGenerator()->integerToConstant(0), Type::Integer32, std::list<llvm::Value*>());
-    
-    // Construct the body of the for loop
-    llvm::BasicBlock* bodyBlock = new llvm::BasicBlock("bodyBlock");
-    _generationContext.llvmFunction()->getBasicBlockList().push_back( bodyBlock);
-    
-    llvm::BasicBlock* endBodyBlock = m_accessor->initialise( _generationContext, bodyBlock, 
-        _generationContext.codeGenerator()->accessArrayValue( bodyBlock, _pointer, index->get( _generationContext, bodyBlock  ) ), sizeAfter );
-    
-    // Create the for statement
-    return _generationContext.codeGenerator()->createIterationForStatement(
-                    _generationContext.llvmFunction(),
-                    _currentBlock,
-                    index,
-                    _generationContext.codeGenerator()->integerToConstant(_sizes.size()),
-                    Type::Integer32,
-                    bodyBlock,
-                    endBodyBlock );
-  }
-  return _currentBlock;
-}
-
-//--------- PrimitiveAccessor ---------///
-
-StructureAccessor::StructureAccessor(const GTLCore::Type* _type, bool constant) : Accessor( _type, constant )
-{
-  const std::vector<GTLCore::Type::StructDataMember>* sm = type()->structDataMembers();
-  for( std::vector<GTLCore::Type::StructDataMember>::const_iterator it = sm->begin();
-        it != sm->end(); ++it)
-  {
-    m_accessors.push_back( Accessor::getAccessorFor( it->type() , constant));
-  }
-  GTL_ASSERT(m_accessors.size() == sm->size());
-}
-
-StructureAccessor::~StructureAccessor()
-{
-  deleteAll( m_accessors );
-}
-
-llvm::Value* StructureAccessor::pointerToValue( GenerationContext& /*_generationContext*/,
-                                                llvm::BasicBlock* _currentBlock,
-                                                llvm::Value* _pointer, int _index )
-{
-  std::vector<llvm::Value*> indexes;
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0));
-  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, _index));
-  return new llvm::GetElementPtrInst( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
-}
-
-int StructureAccessor::memberToIndex(MemberArray* _ma)
-{
-  const std::vector<GTLCore::Type::StructDataMember>* sm = type()->structDataMembers();
-  GTL_ASSERT(sm);
-  int count = 0;
-  for( std::vector<GTLCore::Type::StructDataMember>::const_iterator it = sm->begin();
-        it != sm->end(); ++it, ++count)
-  {
-    if( it->name() == _ma->identifier.name() )
-    {
-      return count;
-    }
-  }
-  return -1;
-}
-
-llvm::Value* StructureAccessor::get( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, MemberArray* _ma )
-{
-  if(not _ma or _ma->empty )
-  {
-    return _pointer;
-  } else {
-    GTL_ASSERT( _ma->member);
-    int idx = memberToIndex( _ma );
-    GTL_ASSERT( idx != -1 );
-    llvm::Value* nptr = pointerToValue( _generationContext, _currentBlock, _pointer, idx);
-    return m_accessors[idx]->get( _generationContext, _currentBlock, nptr, _ma->next );
-  }
-}
-
-llvm::BasicBlock* StructureAccessor::set( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-                        llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma )
-{
-  if( not _ma or _ma->empty )
-  {
-    for(uint i = 0; i < type()->structDataMembers()->size(); ++i)
-    {
-      llvm::Value* nptrToOwnMember = pointerToValue(_generationContext, _currentBlock, _pointer, i);
-      llvm::Value* nptrToValueMember = pointerToValue( _generationContext, _currentBlock, _value, i);
-      llvm::Value* memberValue = m_accessors[i]->get( _generationContext, _currentBlock, nptrToValueMember, 0 );
-      m_accessors[i]->set( _generationContext, _currentBlock, nptrToOwnMember, memberValue, (*_valueType->structDataMembers())[i].type() , _ma ? _ma->next : (MemberArray*)0 );
-    }
-  } else {
-    GTL_ASSERT( _ma->member );
-    int idx = memberToIndex( _ma );
-    GTL_ASSERT( idx != -1 );
-    llvm::Value* nptr = pointerToValue(_generationContext, _currentBlock, _pointer, idx);
-    m_accessors[idx]->set( _generationContext, _currentBlock, nptr, _value, _valueType, _ma->next );
-  }
-  return _currentBlock;
-}
-
-
-void StructureAccessor::setSize(GenerationContext& _generationContext, llvm::BasicBlock*, llvm::Value* _pointer , llvm::Value* )
-{
-  GTL_ABORT( "Can't assign a size to a structure" );
-}
-
-llvm::Value* StructureAccessor::getSize(GenerationContext& _generationContext, llvm::BasicBlock*, llvm::Value* _pointer )
-{
-  GTL_ABORT( "Can't get a size from a structure" );
-  return 0;
-}
-
-llvm::BasicBlock* StructureAccessor::initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const std::list< llvm::Value*>& _sizes)
-{
-  const std::vector<GTLCore::Type::StructDataMember>* sm = type()->structDataMembers();
-  
-  for( uint i = 0; i < sm->size(); ++i)
-  {
-    std::list< llvm::Value* > sizes;
-    for(std::list<int>::const_iterator it = (*sm)[i].initialSizes().begin();
-        it != (*sm)[i].initialSizes().end(); ++it)
-    {
-      sizes.push_back( _generationContext.codeGenerator()->integerToConstant( *it ) );
-    }
-    _currentBlock = m_accessors[i]->initialise( _generationContext, _currentBlock,
-                                pointerToValue( _generationContext, _currentBlock, _pointer, i ), sizes );
-  }
-  return _currentBlock;
-}

Deleted: trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.h	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.h	2008-06-13 19:38:35 UTC (rev 188)
@@ -1,191 +0,0 @@
-/*
- *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef _GTLCORE_ACCESSOR_H_
-#define _GTLCORE_ACCESSOR_H_
-
-#include <list>
-#include <vector>
-#include <GTLCore/Macros.h>
-
-namespace llvm {
-  class ErrorMessage;
-  class BasicBlock;
-  class Type;
-  class Value;
-}
-
-namespace GTLCore {
-  struct MemberArray;
-  class GenerationContext;
-  class Type;
-  /**
-   * @internal
-   * @brief This is an interface that defines functions use to access the member of a variable.
-   * 
-   * This class is used internally by \ref VariableNG to access the exact value of a varible.
-   *
-   * @ingroup GTLCore
-   */
-  class Accessor {
-    public:
-      /**
-       * @param constant set it to true if the variable accessible by this Accessor is constant
-       */
-      Accessor(const GTLCore::Type* _type, bool constant);
-      virtual ~Accessor();
-      /**
-       * Allow to get the value
-       * @param _errMsg a pointer to a pointer (usually initialised to 0), the pointer will be
-       *                set if an error occurs with the content of the error
-       * @param _currentBlock the llvm block that will contains the instructions generated
-       *                      by calling this function
-       * @param _pointer a pointer toward the data
-       * @param _ma
-       * @return the value
-       */
-      virtual llvm::Value* get(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
-                       llvm::Value* pointer, MemberArray* _ma = 0) = 0;
-      /**
-       * Allow to set the value
-       * @param _errMsg a pointer to a pointer (usually initialised to 0), the pointer will be
-       *                set if an error occurs with the content of the error
-       * @param _currentBlock the llvm block that will contains the instructions generated
-       *                      by calling this function
-       * @param _pointer a pointer toward the data
-       * @param _value the new value
-       * @param _ma
-       */
-      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-               llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma = 0) = 0;
-      /**
-       * @return true if this accessor is pointer toward a constant value
-       */
-      bool isConstant() const;
-      /**
-       * Allow to set the size of an array
-       * @param _errMsg a pointer to a pointer (usually initialised to 0), the pointer will be
-       *                set if an error occurs with the content of the error
-       * @param _currentBlock the llvm block that will contains the instructions generated
-       *                      by calling this function
-       * @param _pointer a pointer toward the data
-       * @param _size the new size of the array
-       */
-      virtual void setSize(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer, llvm::Value* _size ) = 0;
-      /**
-       * Allow to access the size of an array.
-       * @param _errMsg a pointer to a pointer (usually initialised to 0), the pointer will be
-       *                set if an error occurs with the content of the error
-       * @param _currentBlock the llvm block that will contains the instructions generated
-       *                      by calling this function
-       * @param _pointer a pointer toward the data
-       * @return the size if an array, or generate an error message
-       */
-      virtual llvm::Value* getSize(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer ) = 0;
-      /**
-       * initialise a the data which is pointed by this accessor.
-       * @param _errMsg a pointer to a pointer (usually initialised to 0), the pointer will be
-       *                set if an error occurs with the content of the error
-       * @param _currentBlock the llvm block that will contains the instructions generated
-       *                      by calling this function
-       * @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 std::list< llvm::Value*>& _sizes) = 0;
-      llvm::BasicBlock* initialiseValue( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType );
-    public:
-      /**
-       * This function create the accessor for the type given in argument
-       */
-      static Accessor* getAccessorFor(const GTLCore::Type* _type, bool constant);
-    protected:
-      /**
-       * @return the type of the data behind this accessor.
-       */
-      const GTLCore::Type* type();
-    private:
-      bool m_constant;
-      bool m_initialisedValue;
-      const GTLCore::Type* m_type;
-  };
-  /**
-   * @internal
-   * @brief Give access to a primitive type (float, integer, bool).
-   */
-  class PrimitiveAccessor : public Accessor {
-    public:
-      PrimitiveAccessor(const GTLCore::Type* _type, bool constant);
-      virtual ~PrimitiveAccessor();
-      virtual llvm::Value* get( GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
-                                llvm::Value* pointer, MemberArray* _ma = 0);
-      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
-                        llvm::Value* pointer, llvm::Value*, const GTLCore::Type* _valueType, MemberArray* _ma = 0);
-      virtual void setSize(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer, llvm::Value* _size );
-      virtual llvm::Value* getSize(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer );
-      virtual llvm::BasicBlock* initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const std::list< llvm::Value*>& _sizes);
-  };
-  /**
-   * @internal
-   * @brief Give access to the elements of an array
-   */
-  class ArrayAccessor : public Accessor {
-    public:
-      ArrayAccessor(const GTLCore::Type* _type, bool constant);
-      virtual ~ArrayAccessor();
-      virtual llvm::Value* get( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-                                llvm::Value* _pointer, MemberArray* _ma = 0);
-      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-                        llvm::Value* _pointer, llvm::Value*, const GTLCore::Type* _valueType, MemberArray* _ma = 0);
-      virtual void setSize( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-                           llvm::Value* _pointer, llvm::Value* _size);
-      virtual llvm::Value* getSize( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer );
-      virtual llvm::BasicBlock* initialise( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const std::list< llvm::Value*>& _sizes);
-    private:
-      llvm::Value* pointerToValue(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-                                  llvm::Value* _pointer, MemberArray* _ma );
-      Accessor* m_accessor;
-  };
-
-  /**
-   * @internal
-   * @brief Give access to members of a structure
-   */
-  class StructureAccessor : public Accessor {
-    public:
-      StructureAccessor( const GTLCore::Type* _type, bool constant);
-      virtual ~StructureAccessor();
-      virtual llvm::Value* get( GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
-                                llvm::Value* pointer, MemberArray* _ma = 0);
-      virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock,
-                        llvm::Value* pointer, llvm::Value*, const GTLCore::Type* _valueType, MemberArray* _ma = 0);
-      virtual void setSize( GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer, llvm::Value* _size );
-      virtual llvm::Value* getSize( GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer );
-      virtual llvm::BasicBlock* initialise( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const std::list< llvm::Value*>& _sizes);
-    private:
-      llvm::Value* pointerToValue(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
-                                  llvm::Value* _pointer, int index );
-      int memberToIndex(MemberArray* _ma);
-      std::vector<Accessor*> m_accessors;
-  };
-
-
-}
-
-
-#endif

Deleted: trunk/OpenGTL/OpenGTL/GTLCore/ArrayStructs_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ArrayStructs_p.h	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ArrayStructs_p.h	2008-06-13 19:38:35 UTC (rev 188)
@@ -1,81 +0,0 @@
-/*
- *  Copyright (c) 2007-2008 Cyrille Berger <cberger@xxxxxxxxxxx>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef _GTLCORE_COMPILER_ARRAY_SIZE_H_
-#define _GTLCORE_COMPILER_ARRAY_SIZE_H_
-
-#include "ScopedName.h"
-#include "String.h"
-
-#include "AST/Expression.h"
-
-// TODO move MemberArray in the AST directory
-
-namespace GTLCore {
-  namespace AST {
-    class Expression;
-  }
-  
-  /**
-  * This structure contains information on access to an array or a member of
-  * a structure.
-  * @internal
-  */
-  struct MemberArray {
-    MemberArray() : empty(true), size(false), member(false), array(false), identifier("",""), next(0), index(0)
-    {
-    }
-    MemberArray( const ScopedName& _identifier, MemberArray* _next) : empty(false), size(false), member(true), array(false), identifier(_identifier), next(_next), index(0)
-    {
-    }
-    MemberArray( AST::Expression* _index, MemberArray* _next) : empty(false), size(false), member(false), array(true), identifier("",""), next(_next), index(_index)
-    {
-    }
-    ~MemberArray() {
-      delete index;
-      delete next;
-    }
-    bool empty;
-    bool size;
-    bool member;
-    bool array;
-    GTLCore::ScopedName identifier; ///< identifier of the structure
-    
-    MemberArray* next;
-    
-    AST::Expression* index; ///< index in the array
-    
-    static MemberArray* createEmpty()
-    {
-      MemberArray* ma = new MemberArray();
-      ma->empty = true;
-      ma->size = false;
-      return ma;
-    }
-    static MemberArray* createSize()
-    {
-      MemberArray* ma = new MemberArray();
-      ma->empty = false;
-      ma->size = true;
-      return ma;
-    }
-  };
-
-}
-#endif

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt	2008-06-13 19:38:35 UTC (rev 188)
@@ -6,7 +6,6 @@
 ## GTLCore library ##
 
 set(GTLCore_SRCS
-  Accessor_p.cpp
   Array.cpp
   Buffer.cpp
   Debug.cpp
@@ -44,6 +43,7 @@
   TypeManager_p.cpp
   VariableNG_p.cpp
   VirtualMachine_p.cpp
+  Visitor_p.cpp
   ${LLVM_NATIVE_OBJECTS}
   )
 
@@ -53,8 +53,6 @@
 
 target_link_libraries(GTLCore ${LLVM_LIBS_JIT} ${LLVM_LDFLAGS} ${LLVM_LIBS} )
 
-add_definitions(-DUSE_MEMBER_ARRAY=0 )
-
 # Set the ABI version of the library
 set_target_properties(GTLCore PROPERTIES VERSION ${OPENGTL_LIB_VERSION} SOVERSION ${OPENGTL_LIB_SOVERSION} )
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Macros.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Macros.h	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Macros.h	2008-06-13 19:38:35 UTC (rev 188)
@@ -40,6 +40,9 @@
  *    staticCoolInstances.push_back( new CoolObject() );
  * }
  * @endcode
+ * 
+ * This will create a CoolObjectsFactory that you can use
+ * to declare a friend class.
  */
 #define STATIC_INITIALISATION(_name_) \
   class _name_##Factory { \

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-06-13 19:38:35 UTC (rev 188)
@@ -25,7 +25,6 @@
 #include <llvm/DerivedTypes.h>
 #include <llvm/Type.h>
 
-#include "ArrayStructs_p.h"
 #include "CodeGenerator_p.h"
 #include "ErrorMessage.h"
 #include "ExpressionResult_p.h"
@@ -145,25 +144,19 @@
   }
 }
 
-parseMemberArrayExpressionResult ParserBase::parseMemberArrayExpression(AST::AccessorExpression* _expression, bool _constantExpression)
+AST::AccessorExpression* ParserBase::parseMemberArrayExpression(AST::AccessorExpression* _expression, bool _constantExpression)
 {
-  parseMemberArrayExpressionResult result;
   if( d->currentToken.type == GTLCore::Token::DOT )
   {
     getNextToken();
     if( d->currentToken.type == GTLCore::Token::SIZE )
     {
       getNextToken(); // eat size
-      result.expression = new AST::ArraySizeAccessorExpression( _expression );
-      result.memberArray = GTLCore::MemberArray::createSize();
+      return new AST::ArraySizeAccessorExpression( _expression );
     } else if( isOfType( d->currentToken, GTLCore::Token::IDENTIFIER ) ) {
       GTLCore::String name = d->currentToken.string;
       getNextToken();
-      result.expression = new AST::StructAccessorExpression( _expression , _expression->type()->d->memberToIndex( name )  );
-      parseMemberArrayExpressionResult result2 = parseMemberArrayExpression( result.expression , _constantExpression);
-      if( result2.expression != 0 ) result.expression = result2.expression;
-      result.memberArray = new GTLCore::MemberArray( GTLCore::ScopedName("", name),
-                                     result2.memberArray );
+      return parseMemberArrayExpression( new AST::StructAccessorExpression( _expression , _expression->type()->d->memberToIndex( name )  ), _constantExpression);
     }
   } else if( d->currentToken.type == GTLCore::Token::STARTBOXBRACKET )
   {
@@ -172,20 +165,15 @@
     if( isOfType( d->currentToken, GTLCore::Token::ENDBOXBRACKET ) )
     {
       getNextToken();
-      result.expression = new AST::ArrayAccessorExpression( _expression , expr  );
-      parseMemberArrayExpressionResult result2 = parseMemberArrayExpression( result.expression , _constantExpression);
-      if( result2.expression != 0 ) result.expression = result2.expression;
-      result.memberArray = new GTLCore::MemberArray( expr,
-                                     result2.memberArray );
+      return parseMemberArrayExpression( new AST::ArrayAccessorExpression( _expression , expr  ), _constantExpression);
     }
   } else if( d->currentToken.type == GTLCore::Token::STARTBRACKET )
   {
     GTL_ASSERT(false);
   } else {
-    result.expression = _expression;
-    result.memberArray = GTLCore::MemberArray::createEmpty();
+    return _expression;
   }
-  return result;
+  return 0;
 }
 
 std::list< AST::Expression* > ParserBase::parseArraySize(bool _constantExpression)
@@ -392,11 +380,7 @@
       return new AST::MinusUnaryExpression( expr );
     case GTLCore::Token::MINUSMINUS:
     {
-#if USE_MEMBER_ARRAY
-      AST::VariableExpression* varexpr = dynamic_cast<AST::VariableExpression*>( expr );
-#else
       AST::AccessorExpression* varexpr = dynamic_cast<AST::AccessorExpression*>( expr );
-#endif
       if( varexpr  )
       {
         if( expr->type() == GTLCore::Type::Integer32 )
@@ -411,11 +395,7 @@
     }
     case GTLCore::Token::PLUSPLUS:
     {
-#if USE_MEMBER_ARRAY
-      AST::VariableExpression* varexpr = dynamic_cast<AST::VariableExpression*>( expr );
-#else
       AST::AccessorExpression* varexpr = dynamic_cast<AST::AccessorExpression*>( expr );
-#endif
       if( varexpr  )
       {
         if( expr->type() == GTLCore::Type::Integer32 )
@@ -957,39 +937,8 @@
             return 0;
           }
           getNextToken();
-          std::list<AST::Expression*> arguments;
-          while(true)
-          {
-            if( d->currentToken.type == GTLCore::Token::ENDBRACKET )
-            {
-              break;
-            } else {
-              AST::Expression* expression = parseExpression( false );
-              arguments.push_back( expression);
-              if( function->parameters()[ arguments.size() - 1 ].output() )
-              {
-#if USE_MEMBER_ARRAY
-                if( not dynamic_cast< AST::VariableExpression* >( expression ) )
-#else
-                if( not dynamic_cast< AST::AccessorExpression* >( expression ) )
-#endif
-                {
-                  reportError( "Parameter of function '" + function->name().toString() + "' is an output parameter and requires a variable as argument", d->currentToken );
-                }
-              }
-              if( d->currentToken.type == GTLCore::Token::COMA )
-              {
-                getNextToken();
-              } else if( d->currentToken.type != GTLCore::Token::ENDBRACKET )
-              {
-                GTL_DEBUG("Unexpected");
-                reportUnexpected( d->currentToken );
-                return 0;
-              }
-            }
-          }
-          GTL_ASSERT( d->currentToken.type == GTLCore::Token::ENDBRACKET );
-          getNextToken(); // eat the end bracket
+          // Parse arguments
+          std::list<AST::Expression*> arguments = parseArguments( function->name().toString(), function->parameters() );
           if( arguments.size() >= function->d->data->minimumParameters() and arguments.size() <= function->d->data->maximumParameters() )
           {
             return new AST::FunctionCallExpression( function, arguments ) ;
@@ -1010,12 +959,7 @@
               return 0;
             }
           }
-#if USE_MEMBER_ARRAY
-          GTLCore::MemberArray* memberArray = parseMemberArrayExpression(new AST::VariableAccessorExpression( var ) , _constantExpression).memberArray;
-          return new AST::VariableExpression( var, memberArray );
-#else
-          return parseMemberArrayExpression(new AST::VariableAccessorExpression( var ) , _constantExpression).expression;
-#endif
+          return parseMemberArrayExpression(new AST::VariableAccessorExpression( var ) , _constantExpression);
         }
       }
       break;
@@ -1027,6 +971,40 @@
   return 0;
 }
 
+std::list<AST::Expression*> ParserBase::parseArguments( const String& _name, const std::vector< Parameter >& _parameters )
+{
+  std::list<AST::Expression*> arguments;
+  while(true)
+  {
+    if( d->currentToken.type == GTLCore::Token::ENDBRACKET )
+    {
+      break;
+    } else {
+      AST::Expression* expression = parseExpression( false );
+      arguments.push_back( expression);
+      if( _parameters[ arguments.size() - 1 ].output() )
+      {
+        if( not dynamic_cast< AST::AccessorExpression* >( expression ) )
+        {
+          reportError( "Parameter of function '" + _name + "' is an output parameter and requires a variable as argument", d->currentToken );
+        }
+      }
+      if( d->currentToken.type == GTLCore::Token::COMA )
+      {
+        getNextToken();
+      } else if( d->currentToken.type != GTLCore::Token::ENDBRACKET )
+      {
+        GTL_DEBUG("Unexpected");
+        reportUnexpected( d->currentToken );
+        return std::list<AST::Expression*>();
+      }
+    }
+  }
+  GTL_ASSERT( d->currentToken.type == GTLCore::Token::ENDBRACKET );
+  getNextToken(); // eat the end bracket
+  return arguments;
+}
+
 void ParserBase::reachNextSemi()
 {
   while( d->currentToken.type != GTLCore::Token::SEMI and d->currentToken.type != GTLCore::Token::END_OF_FILE )
@@ -1080,11 +1058,7 @@
   {
     case GTLCore::Token::EQUAL:
     {
-#if USE_MEMBER_ARRAY
-      AST::VariableExpression* ve = dynamic_cast<AST::VariableExpression*>( lhs );
-#else
       AST::AccessorExpression* ve = dynamic_cast<AST::AccessorExpression*>( lhs );
-#endif
       if( ve )
       {
         return new AST::AssignementBinaryExpression( ve, rhs );

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h	2008-06-13 19:38:35 UTC (rev 188)
@@ -21,6 +21,7 @@
 #define _GTLCORE_PARSERNG_H_
 
 #include <list>
+#include <vector>
 
 #include <GTLCore/String.h>
 
@@ -34,6 +35,7 @@
   class ScopedName;
   class CompilerBase;
   class LexerBase;
+  class Parameter;
   namespace AST {
     class Tree;
     class Expression;
@@ -42,15 +44,6 @@
     class AccessorExpression;
   };
   /**
-   * Temporary structure to hold the AST path and the MemberArray path for structure
-   * and array access
-   */
-  struct parseMemberArrayExpressionResult {
-    parseMemberArrayExpressionResult() : memberArray(0), expression(0) {}
-    GTLCore::MemberArray* memberArray;
-    AST::AccessorExpression* expression;
-  };
-  /**
    * @internal
    * This is the base class for OpenGTL's Parser.
    */
@@ -98,13 +91,17 @@
       const GTLCore::Type* parseFunctionType();
       void parseStructDefinition();
       /**
+       * Parse the arguments of a function.
+       */
+      std::list<AST::Expression*> parseArguments( const String& _name, const std::vector< Parameter >& _parameters );
+      /**
        * Parse statement of the style "[ 10 ]" or "[ 2 + 3 ]", it's use for variables
        * or constants definition.
        * @param _constantExpression states wether the size of the array must be a constant
        *                            or not
        */
       std::list< AST::Expression* > parseArraySize(bool _constantExpression);
-      parseMemberArrayExpressionResult parseMemberArrayExpression(AST::AccessorExpression* _expression, bool _constantExpression);
+      AST::AccessorExpression* parseMemberArrayExpression(AST::AccessorExpression* _expression, bool _constantExpression);
       /**
        * Parse coumpound expression ( { 1, 2, { 4, 5, 6 } } )
        */

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2008-06-13 19:38:35 UTC (rev 188)
@@ -46,6 +46,7 @@
    */
   class Type {
     friend class ArrayAccessor;
+    friend class ArrayVisitor;
     friend class AST::CoumpoundExpression;
     friend class AST::FunctionCallExpression;
     friend class AST::FunctionDeclaration;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp	2008-06-13 19:38:35 UTC (rev 188)
@@ -22,21 +22,21 @@
 #include <llvm/Constants.h>
 #include <llvm/Instructions.h>
 
-#include "Accessor_p.h"
 #include "Debug.h"
 #include "GenerationContext_p.h"
 #include "Type.h"
 #include "Type_p.h"
+#include "Visitor_p.h"
 
 using namespace GTLCore;
 
 
 struct VariableNG::Private
 {
+  const Visitor* visitor;
   const GTLCore::Type* type;
   bool constant;
   bool isInitialised;
-  Accessor* accessor;
   llvm::Value* pointer;
 };
 
@@ -45,12 +45,11 @@
   d->type = _type;
   d->constant = _constant;
   d->isInitialised = false;
-  d->accessor = 0;
+  d->visitor = Visitor::getVisitorFor( _type );
   d->pointer = 0;
 }
 VariableNG::~VariableNG()
 {
-  delete d->accessor;
   delete d;
 }
 bool VariableNG::constant() const
@@ -66,8 +65,12 @@
 {
   GTL_DEBUG( _initialSize.size() );
   initialise( _generationContext, new llvm::AllocaInst::AllocaInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb) );
-  _bb = d->accessor->initialise( _generationContext, _bb, d->pointer, _initialSize);
-  _bb = d->accessor->initialiseValue( _generationContext, _bb,  d->pointer, _initialiser, _initialiserType);
+  _bb = d->visitor->initialise( _generationContext, _bb, d->pointer, d->type, _initialSize);
+  
+  if( _initialiser )
+  {
+    _bb = d->visitor->set( _generationContext, _bb, d->pointer, d->type, _initialiser, _initialiserType );
+  }
   return _bb;
 }
 
@@ -75,33 +78,21 @@
 {
   GTL_ASSERT(not d->isInitialised);
   d->isInitialised = true;
-  d->accessor = Accessor::getAccessorFor( d->type, d->constant );
   d->pointer = _pointer;
 }
 
-llvm::Value* VariableNG::get(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, MemberArray* _ma )
+llvm::Value* VariableNG::get(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock)
 {
-  llvm::Value* v = d->accessor->get( _generationContext, _currentBlock, d->pointer, _ma );
+  llvm::Value* v = d->visitor->get( _generationContext, _currentBlock, d->pointer );
   return v;
 }
 
-llvm::BasicBlock* VariableNG::set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma )
+llvm::BasicBlock* VariableNG::set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _value, const GTLCore::Type* _valueType )
 {
   GTL_ASSERT(not constant() );
-  return d->accessor->set( _generationContext, _currentBlock, d->pointer, _value, _valueType, _ma );
+  return d->visitor->set( _generationContext, _currentBlock, d->pointer, d->type, _value, _valueType);
 }
 
-void VariableNG::setSize(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _size)
-{
-  GTL_ASSERT(not constant() );
-  d->accessor->setSize( _generationContext, _currentBlock, d->pointer, _size);
-}
-
-llvm::Value* VariableNG::getSize(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock)
-{
-  return d->accessor->getSize( _generationContext, _currentBlock, d->pointer);
-}
-
 llvm::Value* VariableNG::pointer()
 {
   return d->pointer;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h	2008-06-11 22:04:19 UTC (rev 187)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h	2008-06-13 19:38:35 UTC (rev 188)
@@ -29,7 +29,6 @@
 
 namespace GTLCore {
   class GenerationContext;
-  class MemberArray;
   class Type;
   /**
    * VariableNG is the class for manipulating variables, getting and settng the values.
@@ -67,22 +66,14 @@
        * @param _ma a pointer to a structure describing the member or index accessed
        * @return the value
        */
-      llvm::Value* get(GenerationContext&, llvm::BasicBlock* _currentBlock, MemberArray* _ma = 0);
+      llvm::Value* get(GenerationContext&, llvm::BasicBlock* _currentBlock);
       /**
        * Allow to set a value. Raise an assert if called on a constant.
        * @param _ma a pointer to a structure describing the member or index accessed
        * @return the new basic block
        */
-      llvm::BasicBlock* set(GenerationContext&, llvm::BasicBlock* _currentBlock, llvm::Value* _value, const GTLCore::Type* _valueType, MemberArray* _ma = 0);
+      llvm::BasicBlock* set(GenerationContext&, llvm::BasicBlock* _currentBlock, llvm::Value* _value, const GTLCore::Type* _valueType);
       /**
-       * Set the size of an array, raise an assert otherwise.
-       */
-      void setSize(GenerationContext&, llvm::BasicBlock* _currentBlock, llvm::Value* _size);
-      /**
-       * @return the size of an array
-       */
-      llvm::Value* getSize(GenerationContext&, llvm::BasicBlock* _currentBlock);
-      /**
        * @return the pointer for this variable
        */
       llvm::Value* pointer();

Copied: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp (from rev 183, trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.cpp)
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-06-13 19:38:35 UTC (rev 188)
@@ -0,0 +1,345 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "Visitor_p.h"
+
+// LLVM
+#include <llvm/BasicBlock.h>
+#include <llvm/Constants.h>
+#include <llvm/Function.h>
+#include <llvm/Instructions.h>
+
+// GTLCore
+#include "CodeGenerator_p.h"
+#include "Debug.h"
+#include "Macros.h"
+#include "Type.h"
+#include "Type_p.h"
+#include "ErrorMessage.h"
+#include "ErrorMessages_p.h"
+#include "ExpressionResult_p.h"
+#include "VariableNG_p.h"
+#include "Utils_p.h"
+
+#include "AST/Expression.h"
+
+using namespace GTLCore;
+
+PrimitiveVisitor* primitiveVisitor = 0;
+ArrayVisitor* arrayVisitor = 0;
+StructureVisitor* structureVisitor = 0;
+
+STATIC_INITIALISATION( Visitors )
+{
+  primitiveVisitor = new PrimitiveVisitor;
+  arrayVisitor = new ArrayVisitor;
+  structureVisitor = new StructureVisitor;
+}
+
+//--------- Visitor ---------///
+
+Visitor::Visitor()
+{
+}
+
+Visitor::~Visitor()
+{
+  
+}
+
+const Visitor* Visitor::getVisitorFor(const GTLCore::Type* _type)
+{
+  if( _type->dataType() == Type::ARRAY )
+  {
+    return arrayVisitor;
+  } else if( _type->dataType() == Type::STRUCTURE ) {
+    return structureVisitor;
+  } else {
+    return primitiveVisitor;
+  }
+  return 0;
+}
+
+// llvm::BasicBlock* Visitor::initialiseValue( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _value, const GTLCore::Type* _valueType )
+// {
+//   GTL_ASSERT(not m_initialisedValue);
+//   m_initialisedValue = true;
+//   if( _value )
+//   {
+//     bool constant = m_constant;
+//     m_constant = false;
+//     _currentBlock = set( _generationContext, _currentBlock, _pointer, _value, _valueType );
+//     m_constant = constant;
+//   }
+//   return _currentBlock;
+// }
+
+//--------- PrimitiveVisitor ---------///
+
+PrimitiveVisitor::PrimitiveVisitor() : Visitor( )
+{
+}
+
+PrimitiveVisitor::~PrimitiveVisitor()
+{
+}
+
+llvm::Value* PrimitiveVisitor::get( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer) const
+{
+  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
+{
+  GTL_ASSERT( _pointerType->dataType() != Type::STRUCTURE and _pointerType->dataType() != Type::ARRAY );
+  new llvm::StoreInst(
+          _generationContext.codeGenerator()->convertValueTo( _currentBlock, _value, _valueType, _pointerType ),
+          _pointer, "", _currentBlock);
+  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
+{
+  // Don't do nothing
+  return _currentBlock;
+}
+
+//--------- ArrayVisitor ---------///
+
+ArrayVisitor::ArrayVisitor() : Visitor(  )
+{
+}
+
+ArrayVisitor::~ArrayVisitor()
+{
+}
+
+#if 0
+llvm::Value* ArrayVisitor::pointerToValue(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
+                            llvm::Value* _pointer, MemberArray* _ma )
+{
+  return _generationContext.codeGenerator()->accessArrayValue( _currentBlock, _pointer, _ma->index->generateValue( _generationContext, _currentBlock).value() );
+}
+
+#endif
+
+
+llvm::Value* ArrayVisitor::get( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock,
+                                llvm::Value* _pointer ) const
+{
+  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
+{
+    // 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 ) );
+    
+      llvm::BasicBlock* afterIf = new llvm::BasicBlock;
+      _generationContext.llvmFunction()->getBasicBlockList().push_back( afterIf);
+      _generationContext.codeGenerator()->createIfStatement( _currentBlock, test, Type::Boolean, ifContent, ifContent, afterIf );
+      _currentBlock = afterIf;
+    
+    }
+    //   int i = 0;
+    GTLCore::VariableNG* index = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
+    index->initialise( _generationContext, _currentBlock, _generationContext.codeGenerator()->integerToConstant(0), Type::Integer32, std::list<llvm::Value*>());
+    
+    // Construct the body of the for loop
+    llvm::BasicBlock* bodyBlock = new llvm::BasicBlock("bodyBlock");
+    _generationContext.llvmFunction()->getBasicBlockList().push_back( bodyBlock);
+//     GTL_DEBUG( " value = " << *_pointer << " type = " << *_pointer->getType() );
+//     GTL_DEBUG( " value = " << *_value << " type = " << *_value->getType() );
+    const Visitor* visitor = Visitor::getVisitorFor( _pointerType->arrayType() );
+    llvm::BasicBlock* endBodyBlock = visitor->set( 
+          _generationContext,
+          bodyBlock, 
+          _generationContext.codeGenerator()->accessArrayValue( bodyBlock, _pointer, index->get( _generationContext, bodyBlock  ) ),
+          _pointerType->arrayType(),
+          new llvm::LoadInst(
+                  _generationContext.codeGenerator()->accessArrayValue(
+                                    bodyBlock, _value, index->get( _generationContext, bodyBlock  ) ),
+                  "", bodyBlock ),
+          _valueType->arrayType() );
+    
+    // Create the for statement
+    return _generationContext.codeGenerator()->createIterationForStatement(
+                    _generationContext.llvmFunction(),
+                    _currentBlock,
+                    index,
+                    getSize( _generationContext, _currentBlock, _pointer),
+                    Type::Integer32,
+                    bodyBlock,
+                    endBodyBlock );
+}
+
+void ArrayVisitor::setSize(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _size) const
+{
+  GTL_ASSERT( _pointerType->dataType() == Type::ARRAY );
+  GTL_DEBUG( *_size );
+  std::vector<llvm::Value*> indexes;
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the structure of the array
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the size of the array
+  { // Init the size
+    llvm::Value* ptr = new llvm::GetElementPtrInst( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
+    new llvm::StoreInst(_generationContext.codeGenerator()->convertValueTo( _currentBlock, _size, GTLCore::Type::Integer32, GTLCore::Type::Integer32 ), ptr, "", _currentBlock);
+  }
+  // Allocate the Array
+  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(
+                    _pointerType->arrayType()->d->type(), _size, "", _currentBlock);
+    new llvm::StoreInst( array, ptr, "", _currentBlock);
+  }
+}
+
+llvm::Value* ArrayVisitor::getSize(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* _pointer ) const
+{
+  std::vector<llvm::Value*> indexes;
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the structure of the array
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); // Access the size of the array
+  llvm::Value* ptr = new llvm::GetElementPtrInst( _pointer, indexes.begin(), indexes.end(), "", currentBlock);
+  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
+{
+  GTL_ASSERT( _pointerType->dataType() == Type::ARRAY );
+  GTL_DEBUG( _sizes.empty() );
+  if( not _sizes.empty())
+  {
+    setSize( _generationContext, _currentBlock, _pointer, _pointerType, _sizes.front() );
+    std::list< llvm::Value*> sizeAfter = _sizes;
+    sizeAfter.pop_front();
+    //   int i = 0;
+    GTLCore::VariableNG* index = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
+    index->initialise( _generationContext, _currentBlock, _generationContext.codeGenerator()->integerToConstant(0), Type::Integer32, std::list<llvm::Value*>());
+    
+    // Construct the body of the for loop
+    llvm::BasicBlock* bodyBlock = new llvm::BasicBlock("bodyBlock");
+    _generationContext.llvmFunction()->getBasicBlockList().push_back( bodyBlock);
+    
+    const Visitor* visitor = Visitor::getVisitorFor( _pointerType->arrayType() );
+    llvm::BasicBlock* endBodyBlock = visitor->initialise(
+            _generationContext,
+            bodyBlock,
+            _generationContext.codeGenerator()->accessArrayValue(
+                      bodyBlock, _pointer, index->get( _generationContext, bodyBlock ) ),
+            _pointerType->arrayType(),
+            sizeAfter );
+    
+    // Create the for statement
+    return _generationContext.codeGenerator()->createIterationForStatement(
+                    _generationContext.llvmFunction(),
+                    _currentBlock,
+                    index,
+                    _generationContext.codeGenerator()->integerToConstant(_sizes.size()),
+                    Type::Integer32,
+                    bodyBlock,
+                    endBodyBlock );
+  }
+  return _currentBlock;
+}
+
+//--------- PrimitiveVisitor ---------///
+
+StructureVisitor::StructureVisitor() : Visitor( )
+{
+}
+
+StructureVisitor::~StructureVisitor()
+{
+}
+
+llvm::Value* StructureVisitor::pointerToValue( GenerationContext& /*_generationContext*/,
+                                                llvm::BasicBlock* _currentBlock,
+                                                llvm::Value* _pointer, int _index ) const
+{
+  std::vector<llvm::Value*> indexes;
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, 0));
+  indexes.push_back( llvm::ConstantInt::get(llvm::Type::Int32Ty, _index));
+  return new llvm::GetElementPtrInst( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
+}
+
+#if 0
+
+int StructureVisitor::memberToIndex(MemberArray* _ma)
+{
+  const std::vector<GTLCore::Type::StructDataMember>* sm = type()->structDataMembers();
+  GTL_ASSERT(sm);
+  int count = 0;
+  for( std::vector<GTLCore::Type::StructDataMember>::const_iterator it = sm->begin();
+        it != sm->end(); ++it, ++count)
+  {
+    if( it->name() == _ma->identifier.name() )
+    {
+      return count;
+    }
+  }
+  return -1;
+}
+
+#endif
+
+llvm::Value* StructureVisitor::get( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer ) const
+{
+  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
+{
+  GTL_ASSERT( _pointerType->dataType() == Type::STRUCTURE );
+  for(uint i = 0; i < _pointerType->structDataMembers()->size(); ++i)
+  {
+    const GTLCore::Type* type = (*_pointerType->structDataMembers())[i].type();
+    llvm::Value* nptrToOwnMember = pointerToValue(_generationContext, _currentBlock, _pointer, i);
+    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 );
+  }
+  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
+{
+  GTL_ASSERT( _pointerType->dataType() == Type::STRUCTURE );
+  const std::vector<GTLCore::Type::StructDataMember>* sm = _pointerType->structDataMembers();
+  
+  for( uint i = 0; i < sm->size(); ++i)
+  {
+    std::list< llvm::Value* > sizes;
+    for(std::list<int>::const_iterator it = (*sm)[i].initialSizes().begin();
+        it != (*sm)[i].initialSizes().end(); ++it)
+    {
+      sizes.push_back( _generationContext.codeGenerator()->integerToConstant( *it ) );
+    }
+    const GTLCore::Type* type = (*sm)[i].type();
+    const Visitor* visitor = Visitor::getVisitorFor( type );
+    _currentBlock = visitor->initialise( _generationContext, _currentBlock,
+                            pointerToValue( _generationContext, _currentBlock, _pointer, i ),
+                            type, sizes );
+  }
+  return _currentBlock;
+}

Copied: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h (from rev 183, trunk/OpenGTL/OpenGTL/GTLCore/Accessor_p.h)
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h	2008-06-13 19:38:35 UTC (rev 188)
@@ -0,0 +1,164 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _GTLCORE_Visitor_H_
+#define _GTLCORE_Visitor_H_
+
+#include <list>
+#include <vector>
+#include <GTLCore/Macros.h>
+
+class VisitorsFactory;
+
+namespace llvm {
+  class ErrorMessage;
+  class BasicBlock;
+  class Type;
+  class Value;
+}
+
+namespace GTLCore {
+  class GenerationContext;
+  class Type;
+  /**
+   * @internal
+   * @brief This is an interface that defines functions use to access the member of a variable.
+   * 
+   * This class is used internally by \ref VariableNG to access the exact value of a varible.
+   *
+   * @ingroup GTLCore
+   */
+  class Visitor {
+    public:
+      /**
+       * @param constant set it to true if the variable accessible by this Visitor is constant
+       */
+      Visitor();
+      virtual ~Visitor();
+      /**
+       * Allow to get the value
+       * @param _errMsg a pointer to a pointer (usually initialised to 0), the pointer will be
+       *                set if an error occurs with the content of the error
+       * @param _currentBlock the llvm block that will contains the instructions generated
+       *                      by calling this function
+       * @param _pointer a pointer toward the data
+       * @param _ma
+       * @return the value
+       */
+      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
+       *                set if an error occurs with the content of the error
+       * @param _currentBlock the llvm block that will contains the instructions generated
+       *                      by calling this function
+       * @param _pointer a pointer toward the data
+       * @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;
+      /**
+       * 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
+       *                set if an error occurs with the content of the error
+       * @param _currentBlock the llvm block that will contains the instructions generated
+       *                      by calling this function
+       * @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;
+    public:
+      /**
+       * This function create the Visitor for the type given in argument
+       */
+      static const Visitor* getVisitorFor(const GTLCore::Type* _type);
+  };
+  /**
+   * @internal
+   * @brief Give access to a primitive type (float, integer, bool).
+   */
+  class PrimitiveVisitor : public Visitor {
+      friend class ::VisitorsFactory;
+    private:
+      PrimitiveVisitor();
+      virtual ~PrimitiveVisitor();
+    public:
+      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;
+  };
+  /**
+   * @internal
+   * @brief Give access to the elements of an array
+   */
+  class ArrayVisitor : public Visitor {
+      friend class ::VisitorsFactory;
+    private:
+      ArrayVisitor();
+      virtual ~ArrayVisitor();
+    public:
+      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;
+    private:
+      /**
+       * Allow to access the size of an array.
+       * @param _errMsg a pointer to a pointer (usually initialised to 0), the pointer will be
+       *                set if an error occurs with the content of the error
+       * @param _currentBlock the llvm block that will contains the instructions generated
+       *                      by calling this function
+       * @param _pointer a pointer toward the data
+       * @return the size if an array, or generate an error message
+       */
+      llvm::Value* getSize(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer ) const;
+      /**
+       * Allow to set the size of an array
+       * @param _errMsg a pointer to a pointer (usually initialised to 0), the pointer will be
+       *                set if an error occurs with the content of the error
+       * @param _currentBlock the llvm block that will contains the instructions generated
+       *                      by calling this function
+       * @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;
+  };
+
+  /**
+   * @internal
+   * @brief Give access to members of a structure
+   */
+  class StructureVisitor : public Visitor {
+      friend class ::VisitorsFactory;
+      StructureVisitor( );
+      virtual ~StructureVisitor();
+    public:
+      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;
+    private:
+      llvm::Value* pointerToValue(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, int index ) const;
+  };
+
+
+}
+
+
+#endif


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