[opengtl-commits] [187] use the AccessorExpression, only one test fails for now : " initialiserlist.ctl" , because affecting a structure or array to an other one doesn' t work anymore

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


Revision: 187
Author:   cyrille
Date:     2008-06-12 00:04:19 +0200 (Thu, 12 Jun 2008)

Log Message:
-----------
use the AccessorExpression, only one test fails for now : "initialiserlist.ctl" , because affecting a structure or array to an other one doesn't work anymore

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/Expression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h
    trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-06-11 22:04:19 UTC (rev 187)
@@ -24,18 +24,70 @@
 
 #include "../CodeGenerator_p.h"
 #include "../ExpressionResult_p.h"
+#include "../Debug.h"
 #include "../VariableNG_p.h"
 #include "../Type.h"
 
 using namespace GTLCore::AST;
 
-//------------------- StructAccessorExpression -------------------//
+//------------------- AccessorExpression -------------------//
 
 GTLCore::ExpressionResult AccessorExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
 {
-  return GTLCore::ExpressionResult( new llvm::LoadInst( pointer( _gc, _bb ), "", _bb) );
+  llvm::Value* ptr_ = pointer( _gc, _bb );
+  GTL_DEBUG( *ptr_ << " " << *ptr_->getType() );
+  return GTLCore::ExpressionResult( new llvm::LoadInst( ptr_, "", _bb) );
 }
 
+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;
+}
+
+//------------------- ArraySizeAccessorExpression -------------------//
+
+ArraySizeAccessorExpression::ArraySizeAccessorExpression(AccessorExpression* _accessorExpression )
+  : m_accessorExpression( _accessorExpression )
+{
+}
+
+bool ArraySizeAccessorExpression::isConstant() const
+{
+  return true;
+}
+const GTLCore::Type* ArraySizeAccessorExpression::type() const
+{
+  return GTLCore::Type::Integer32;
+}
+
+
+llvm::Value* ArraySizeAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const
+{
+  GTL_DEBUG("ArraySizeAccessorExpression::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
+  return new llvm::GetElementPtrInst( m_accessorExpression->pointer( _gc, _bb),
+                                      indexes.begin(), indexes.end(), "", _bb);
+}
+
+
 //------------------- StructAccessorExpression -------------------//
 
 StructAccessorExpression::StructAccessorExpression(AccessorExpression* _accessorExpression, int _index) : m_accessorExpression(_accessorExpression), m_index(_index)
@@ -44,6 +96,7 @@
 
 llvm::Value* StructAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const
 {
+  GTL_DEBUG("StructAccessorExpression::pointer");
   std::vector<llvm::Value*> indexes;
   indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
   indexes.push_back( _gc.codeGenerator()->integerToConstant(m_index));
@@ -68,6 +121,7 @@
 
 llvm::Value* ArrayAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const
 {
+  GTL_DEBUG("ArrayAccessorExpression::pointer");
   llvm::Value* index = m_index->generateValue(_gc, _bb).value();
   return _gc.codeGenerator()->accessArrayValue(_bb, m_accessorExpression->pointer( _gc, _bb) , index);
 }
@@ -90,6 +144,7 @@
 
 llvm::Value* VariableAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const
 {
+  GTL_DEBUG("VariableAccessorExpression::pointer");
   return m_variable->pointer();
 }
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h	2008-06-11 22:04:19 UTC (rev 187)
@@ -28,15 +28,25 @@
     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;
     };
+    class ArraySizeAccessorExpression : public AccessorExpression {
+      public:
+        ArraySizeAccessorExpression(AccessorExpression* _accessorExpression );
+        virtual bool isConstant() const;
+        virtual const GTLCore::Type* type() const;
+        virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
+      private:
+        AccessorExpression * m_accessorExpression;
+    };
     class StructAccessorExpression : public AccessorExpression {
       public:
         StructAccessorExpression(AccessorExpression* _accessorExpression, int _index);
         virtual bool isConstant() const;
         virtual const GTLCore::Type* type() const;
-      protected:
+      public:
         virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
       private:
         AccessorExpression * m_accessorExpression;
@@ -47,7 +57,7 @@
         ArrayAccessorExpression(AccessorExpression * _accessorExpression, Expression* _index);
         virtual bool isConstant() const;
         virtual const GTLCore::Type* type() const;
-      protected:
+      public:
         virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
       private:
         AccessorExpression * m_accessorExpression;
@@ -58,7 +68,7 @@
         VariableAccessorExpression(GTLCore::VariableNG* _variable );
         virtual bool isConstant() const;
         virtual const GTLCore::Type* type() const;
-      protected:
+      public:
         virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
       private:
         GTLCore::VariableNG* m_variable;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp	2008-06-11 22:04:19 UTC (rev 187)
@@ -19,6 +19,8 @@
 
 #include "BinaryExpression.h"
 
+#include <llvm/Instructions.h>
+
 #include <GTLCore/Debug.h>
 #include <GTLCore/CodeGenerator_p.h>
 #include <GTLCore/ExpressionResult_p.h>
@@ -181,14 +183,28 @@
 
 llvm::BasicBlock* AssignementBinaryExpression::generateStatement( GenerationContext& _gc, llvm::BasicBlock* _bb) const
 {
-  return m_lhs->variable()->set( _gc, _bb,
+  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() );
+  }
 }
 
-GTLCore::ExpressionResult AssignementBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
+GTLCore::ExpressionResult AssignementBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
 {
-  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) );
+  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) );
+  }
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.h	2008-06-11 22:04:19 UTC (rev 187)
@@ -21,11 +21,12 @@
 #define _BINARY_EXPRESSION_H_
 
 #include "GTLCore/AST/Expression.h"
+#include "GTLCore/AST/AccessorExpression.h"
 
 namespace GTLCore {
 
   namespace AST {
-    
+    class AccessorExpression;
     /**
      * @internal
      * This is the base class of binary expression ( '<', '==', '+', '%'...).
@@ -263,13 +264,17 @@
      */
     class AssignementBinaryExpression : public BinaryExpression {
       public:
-        AssignementBinaryExpression( VariableExpression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs ), m_lhs(lhs)
+        AssignementBinaryExpression( VariableExpression* lhs, Expression* rhs ) : BinaryExpression( lhs, rhs ), m_lhs(lhs), m_lhsBis(0)
         {
         }
+        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;
     };
   }
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-06-11 22:04:19 UTC (rev 187)
@@ -38,6 +38,8 @@
 #include "GTLCore/Function.h"
 #include "GTLCore/Function_p.h"
 
+#include "AccessorExpression.h"
+
 using namespace GTLCore::AST;
 
 //------------------------------------------//
@@ -126,13 +128,30 @@
   {
     if(oparam_it->output())
     {
+#if USE_MEMBER_ARRAY
       VariableExpression* varex = dynamic_cast<VariableExpression*>( *it);
       GTL_ASSERT( varex );
       GTL_ASSERT( varex->variable()->pointer()->getType() == llvm::PointerType::get( oparam_it->type()->d->type(), 0) );
       convertedParams.push_back( varex->variable()->pointer() );
       GTL_DEBUG(*varex->variable()->pointer()->getType() << " " << *oparam_it->type()->d->type() );
+#else
+      AccessorExpression* aexp = dynamic_cast<AccessorExpression*>( *it );
+      GTL_ASSERT( aexp );
+      llvm::Value* pointer = aexp->pointer( _gc, bb );
+      GTL_ASSERT( pointer->getType() == llvm::PointerType::get( oparam_it->type()->d->type(), 0) );
+      convertedParams.push_back( pointer );
+      GTL_DEBUG(*pointer->getType() << " " << *oparam_it->type()->d->type() );
+#endif
     } else {
-      llvm::Value* value = (*it)->generateValue(_gc, bb).value();
+      llvm::Value* value = 0;
+      if( (*it)->type()->dataType() == GTLCore::Type::ARRAY or (*it)->type()->dataType() == GTLCore::Type::STRUCTURE )
+      {
+        AccessorExpression* aexp = dynamic_cast<AccessorExpression*>( *it );
+        GTL_ASSERT( aexp );
+        value = aexp->pointer( _gc, bb );
+      } else {
+        value = (*it)->generateValue(_gc, bb).value();
+      }
       GTL_ASSERT( value );
       if( oparam_it->type()->d->type()->isFirstClassType() )
       {

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.cpp	2008-06-11 22:04:19 UTC (rev 187)
@@ -22,6 +22,7 @@
 #include <GTLCore/CodeGenerator_p.h>
 #include <GTLCore/Type.h>
 #include <GTLCore/ExpressionResult_p.h>
+#include <GTLCore/Debug.h>
 
 using namespace GTLCore::AST;
 
@@ -38,14 +39,26 @@
 
 GTLCore::ExpressionResult MinusMinusUnaryExpression::generateValue( GenerationContext& _gc,  llvm::BasicBlock* bb ) const
 {
-  _gc.codeGenerator()->createDecrementExpression( bb, m_rhs->variable() );
-  return m_rhs->generateValue( _gc, bb);
+  if( m_rhs )
+  {
+    _gc.codeGenerator()->createDecrementExpression( bb, m_rhs->variable() );
+  } else {
+    GTL_ASSERT( m_rhsBis );
+    _gc.codeGenerator()->createDecrementExpression( bb, m_rhsBis->pointer( _gc, bb) );
+  }
+  return rightHandSide()->generateValue( _gc, bb);
 }
 
 GTLCore::ExpressionResult PlusPlusUnaryExpression::generateValue( GenerationContext& _gc,  llvm::BasicBlock* bb ) const
 {
-  _gc.codeGenerator()->createIncrementExpression( bb, m_rhs->variable() );
-  return m_rhs->generateValue( _gc, bb);
+  if( m_rhs )
+  {
+    _gc.codeGenerator()->createIncrementExpression( bb, m_rhs->variable() );
+  } else {
+    GTL_ASSERT( m_rhsBis );
+    _gc.codeGenerator()->createIncrementExpression( bb, m_rhsBis->pointer( _gc, bb) );
+  }
+  return rightHandSide()->generateValue( _gc, bb);
 }
 
 const GTLCore::Type* NotUnaryExpression::type() const

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/UnaryExpression.h	2008-06-11 22:04:19 UTC (rev 187)
@@ -21,6 +21,7 @@
 #define _UNARY_EXPRESSION_H_
 
 #include "GTLCore/AST/Expression.h"
+#include "GTLCore/AST/AccessorExpression.h"
 
 namespace GTLCore {
 
@@ -56,11 +57,13 @@
      */
     class MinusMinusUnaryExpression : public UnaryExpression {
       public:
-        explicit MinusMinusUnaryExpression(VariableExpression* rhs) : UnaryExpression(rhs), m_rhs(rhs) {}
+        explicit MinusMinusUnaryExpression(VariableExpression* rhs) : UnaryExpression(rhs), m_rhs(rhs), m_rhsBis(0) {}
+        explicit MinusMinusUnaryExpression(AccessorExpression* rhs) : UnaryExpression(rhs), m_rhs(0), m_rhsBis(rhs) {}
         virtual bool isConstant() const { return false; }
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
       private:
         VariableExpression* m_rhs;
+        AccessorExpression* m_rhsBis;
     };
     /**
      * @internal
@@ -69,10 +72,12 @@
     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) {}
         virtual bool isConstant() const { return false; }
         virtual GTLCore::ExpressionResult generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const;
       private:
         VariableExpression* m_rhs;
+        AccessorExpression* m_rhsBis;
     };
     /**
      * @internal

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt	2008-06-11 22:04:19 UTC (rev 187)
@@ -53,6 +53,8 @@
 
 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/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-06-11 22:04:19 UTC (rev 187)
@@ -325,12 +325,30 @@
   var->set( gc, currentBlock, createAdditionExpression( currentBlock, var->get(gc, currentBlock), var->type(), integerToConstant(1), Type::Integer32), var->type());
 }
 
+void CodeGenerator::createIncrementExpression( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer)
+{
+  new llvm::StoreInst(
+      createAdditionExpression( _currentBlock,
+                                new llvm::LoadInst( _pointer, "", _currentBlock ),
+                                Type::Integer32, integerToConstant(1), Type::Integer32 ),
+                      _pointer, "", _currentBlock );
+}
+
 void CodeGenerator::createDecrementExpression( llvm::BasicBlock* currentBlock, VariableNG* var)
 {
   GenerationContext gc(this, 0, 0, 0);
   var->set(gc, currentBlock, createSubstractionExpression( currentBlock, var->get(gc, currentBlock), var->type(), integerToConstant(1), Type::Integer32), var->type());
 }
 
+void CodeGenerator::createDecrementExpression( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer)
+{
+  new llvm::StoreInst(
+      createSubstractionExpression( _currentBlock,
+                                new llvm::LoadInst( _pointer, "", _currentBlock ),
+                                Type::Integer32, integerToConstant(1), Type::Integer32 ),
+                                _pointer, "", _currentBlock );
+}
+
 #define CREATE_BINARY_OPERATOR( _creator_, _v1_, _v2_) \
   if( _v1_.isConstant() and _v2_.isConstant() ) \
   { \

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2008-06-11 22:04:19 UTC (rev 187)
@@ -171,7 +171,9 @@
       llvm::Constant* createTildeExpression( llvm::Constant* rhs, const Type* rhsType);
       // Increment
       void createIncrementExpression( llvm::BasicBlock* currentBlock, VariableNG* var);
+      void createIncrementExpression( llvm::BasicBlock* currentBlock, llvm::Value* pointer);
       void createDecrementExpression( llvm::BasicBlock* currentBlock, VariableNG* var);
+      void createDecrementExpression( llvm::BasicBlock* currentBlock, llvm::Value* pointer);
       
     public: // Statements
       /**

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-06-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-06-11 22:04:19 UTC (rev 187)
@@ -154,13 +154,16 @@
     if( d->currentToken.type == GTLCore::Token::SIZE )
     {
       getNextToken(); // eat size
+      result.expression = new AST::ArraySizeAccessorExpression( _expression );
       result.memberArray = GTLCore::MemberArray::createSize();
     } 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),
-                                     parseMemberArrayExpression( result.expression , _constantExpression).memberArray );
+                                     result2.memberArray );
     }
   } else if( d->currentToken.type == GTLCore::Token::STARTBOXBRACKET )
   {
@@ -170,13 +173,16 @@
     {
       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,
-                                     parseMemberArrayExpression( result.expression, _constantExpression).memberArray );
+                                     result2.memberArray );
     }
   } else if( d->currentToken.type == GTLCore::Token::STARTBRACKET )
   {
     GTL_ASSERT(false);
   } else {
+    result.expression = _expression;
     result.memberArray = GTLCore::MemberArray::createEmpty();
   }
   return result;
@@ -386,7 +392,11 @@
       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 )
@@ -401,7 +411,11 @@
     }
     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 )
@@ -926,7 +940,6 @@
       } else {
         // It can be either a call to a function or a variable access
         GTLCore::ScopedName name("", d->currentToken.string );
-        GTLCore::MemberArray* memberArray = 0;
         getNextToken(); // eat the identifier
         if( d->currentToken.type == GTLCore::Token::COLONCOLON )
         {
@@ -955,7 +968,11 @@
               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 );
                 }
@@ -982,20 +999,23 @@
           }
         } else {
           GTLCore::VariableNG* var = getVariable( name );
-          memberArray = parseMemberArrayExpression(new AST::VariableAccessorExpression( var ) , _constantExpression).memberArray;
-          if( var )
+          if(not var)
           {
-            return new AST::VariableExpression( var, memberArray );
-          } else {
-            delete memberArray;
             AST::Expression* stdconst = d->compiler->standardConstant( name.name() );
             if( stdconst )
             {
               return stdconst;
             } else {
               reportError( "Unknown variable: " + name.toString(), d->currentToken );
+              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
         }
       }
       break;
@@ -1060,7 +1080,11 @@
   {
     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-10 18:35:42 UTC (rev 186)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h	2008-06-11 22:04:19 UTC (rev 187)
@@ -46,6 +46,7 @@
    * and array access
    */
   struct parseMemberArrayExpressionResult {
+    parseMemberArrayExpressionResult() : memberArray(0), expression(0) {}
     GTLCore::MemberArray* memberArray;
     AST::AccessorExpression* expression;
   };


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