[opengtl-commits] [431] convert to the correct type when creating a coumpound expression

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


Revision: 431
Author:   cyrille
Date:     2008-10-07 00:45:56 +0200 (Tue, 07 Oct 2008)

Log Message:
-----------
convert to the correct type when creating a coumpound expression

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-10-06 22:17:23 UTC (rev 430)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-10-06 22:45:56 UTC (rev 431)
@@ -328,28 +328,27 @@
   while(true)
   {
     AST::Expression* expression = 0;
+    const Type* subtype = _type->d->subtypeAt( index );
     if( d->currentToken.type == Token::STARTBRACE )
     {
-      const Type* type = 0;
-      if ( _type->dataType() == Type::ARRAY )
+      GTL_ASSERT( subtype );
+      GTL_DEBUG( index << " " <<  *subtype );
+      if( subtype->dataType() != Type::STRUCTURE and subtype->dataType() != Type::ARRAY )
       {
-        type = _type->embeddedType();
-      } else if( _type->dataType() == Type::STRUCTURE )
-      {
-        type = _type->structDataMember(index).type();
-      }
-      GTL_ASSERT( type );
-      GTL_DEBUG( index << " " <<  *type );
-      if( type->dataType() != Type::STRUCTURE and type->dataType() != Type::ARRAY )
-      {
         GTL_DEBUG("unexpected");
         reportUnexpected( d->currentToken );
         return 0;
       }
-      expression = parseCoumpoundExpression( type, _constantExpression );
+      expression = parseCoumpoundExpression( subtype, _constantExpression );
     } else {
       expression = parseExpression( _constantExpression );
     }
+    expression = d->compiler->convertCenter()->createConvertExpression( expression, subtype );
+    if( not expression )
+    {
+      reportError( "can't convert coumpound expression at " + String::number( index ) + ".", d->currentToken);
+      return 0;
+    }
     expressions_.push_back( expression );
     if( d->currentToken.type == Token::COMA )
     {
@@ -1431,6 +1430,7 @@
       return 0;
     }
     AST::AccessorExpression* ve = dynamic_cast<AST::AccessorExpression*>( lhs );
+    GTL_ASSERT( rhs->type() == ve->type() );
     if( ve )
     {
       if( token.type == Token::PLUSEQUAL )
@@ -1472,6 +1472,7 @@
     }
     lhs = ce.first;
     rhs = ce.second;
+    GTL_ASSERT( lhs->type() == rhs->type() );
     switch( token.type )
     {
       case Token::OR:

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp	2008-10-06 22:17:23 UTC (rev 430)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp	2008-10-06 22:45:56 UTC (rev 431)
@@ -26,6 +26,8 @@
 
 #include <llvm/DerivedTypes.h>
 
+#include "wrappers/StructWrap.h"
+
 using namespace GTLCore;
 
 //-------- Type::StructDataMember -------//
@@ -197,14 +199,14 @@
 {
   GTL_ASSERT(d->structDataMembers);
   GTL_ASSERT( index < countStructDataMembers( ) );
-  return (*d->structDataMembers)[index + 1];
+  return (*d->structDataMembers)[index + STRUCT_FIRST_ELEMENT];
 }
 
 std::size_t Type::countStructDataMembers( ) const
 {
   if( d->structDataMembers )
   {
-    return d->structDataMembers->size() - 1;
+    return d->structDataMembers->size() - STRUCT_FIRST_ELEMENT;
   } else {
     return 0;
   }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp	2008-10-06 22:17:23 UTC (rev 430)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp	2008-10-06 22:45:56 UTC (rev 431)
@@ -283,3 +283,17 @@
   return 0;
 }
 
+const GTLCore::Type* Type::Private::subtypeAt( unsigned int _index )
+{
+  switch( dataType )
+  {
+    case Type::VECTOR:
+    case Type::ARRAY:
+      return arrayType;
+    case Type::STRUCTURE:
+      return (*structDataMembers)[_index + STRUCT_FIRST_ELEMENT].type();
+    default:
+      GTL_ABORT("No subtype");
+      return 0;
+  }
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h	2008-10-06 22:17:23 UTC (rev 430)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h	2008-10-06 22:45:56 UTC (rev 431)
@@ -138,7 +138,10 @@
        * @return true if this a "nested" array (ie int a[2][3]; is nested, while int a[2]; isn't)
        */
       bool isNestedArray();
-      
+      /**
+       * @return the subtype at a given index
+       */
+      const GTLCore::Type* subtypeAt( unsigned int _index );
     private:
       void setType( const llvm::Type* _type);
       const llvm::Type* m_type;


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