[opengtl-commits] [421] * support for +=

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


Revision: 421
Author:   cyrille
Date:     2008-10-01 20:36:59 +0200 (Wed, 01 Oct 2008)

Log Message:
-----------
* support for +=
* support for C-style conversion

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Token_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Token_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Lexer_p.cpp
    trunk/OpenGTL/OpenShiva/tests/CMakeLists.txt

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/tests/arithmetic/
    trunk/OpenGTL/OpenShiva/tests/arithmetic/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/tests/arithmetic/plus_minus_equal.shiva


Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-10-01 06:38:54 UTC (rev 420)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-10-01 18:36:59 UTC (rev 421)
@@ -403,6 +403,18 @@
     {
       return new AST::GlobalDataExpression( coumpoundExpression );
     }
+  } else if( isType(currentToken()) ) {
+    const Type* type = parseType();
+    if( isOfType( d->currentToken, Token::STARTBRACKET ) )
+    {
+      getNextToken();
+      AST::Expression* expression = parseExpression(_constantExpression, _type);
+      if( expression and isOfType( currentToken(), Token::ENDBRACKET ) )
+      {
+        getNextToken();
+        return d->compiler->convertCenter()->createConvertExpression( expression, type );
+      }
+    }
   } else {
     GTL_DEBUG("unexpected");
     reportUnexpected( d->currentToken );
@@ -1369,7 +1381,7 @@
     delete rhs;
     return 0;
   }
-  if( token.type == Token::EQUAL )
+  if( token.type == Token::EQUAL or token.type == Token::PLUSEQUAL or token.type == Token::MINUSEQUAL)
   {
     rhs = d->compiler->convertCenter()->createConvertExpression( rhs, lhs->type() );
     if( not rhs )
@@ -1382,6 +1394,12 @@
     AST::AccessorExpression* ve = dynamic_cast<AST::AccessorExpression*>( lhs );
     if( ve )
     {
+      if( token.type == Token::PLUSEQUAL )
+      {
+        rhs = new AST::AdditionBinaryExpression( new AST::ProxyExpression(ve), rhs );
+      } else if(token.type == Token::MINUSEQUAL) {
+        rhs = new AST::SubstractionBinaryExpression( new AST::ProxyExpression(ve), rhs );
+      }
       return new AST::AssignementBinaryExpression( ve, rhs );
     }
     delete lhs;
@@ -1457,6 +1475,7 @@
         return new AST::ModuloBinaryExpression( lhs, rhs );
       }
       default:
+        GTL_ABORT("Unknown operator: " << Token::typeToString( token.type ) );
         return 0;
     }
   }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Token_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Token_p.cpp	2008-10-01 06:38:54 UTC (rev 420)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Token_p.cpp	2008-10-01 18:36:59 UTC (rev 421)
@@ -58,6 +58,10 @@
       return "=";
     case Token::EQUALEQUAL:
       return "==";
+    case Token::PLUSEQUAL:
+      return "+=";
+    case Token::MINUSEQUAL:
+      return "-=";
     case Token::DIFFERENT:
       return "!=";
     case Token::AND:
@@ -255,6 +259,8 @@
   switch( type )
   {
     case Token::EQUAL:
+    case Token::PLUSEQUAL:
+    case Token::MINUSEQUAL:
       return ASSIGNEMENT_PRIORITY;
     case Token::OR:
       return OR_PRIORITY;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Token_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Token_p.h	2008-10-01 06:38:54 UTC (rev 420)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Token_p.h	2008-10-01 18:36:59 UTC (rev 421)
@@ -52,6 +52,8 @@
       ENDBOXBRACKET, ///< ]
       EQUAL, ///< =
       EQUALEQUAL, ///< ==
+      PLUSEQUAL, ///< +=
+      MINUSEQUAL, ///< -=
       DIFFERENT, ///< !=
       AND, ///< and &&
       OR, ///< or ||

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Lexer_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Lexer_p.cpp	2008-10-01 06:38:54 UTC (rev 420)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Lexer_p.cpp	2008-10-01 18:36:59 UTC (rev 421)
@@ -113,8 +113,8 @@
     CHAR_IS_TOKEN( '^', BITXOR );
     CHAR_IS_TOKEN_OR_TOKEN_OR_TOKEN( '<', '=', '<', INFERIOR, INFERIOREQUAL, LEFTSHIFT );
     CHAR_IS_TOKEN_OR_TOKEN_OR_TOKEN( '>', '=', '>', SUPPERIOR, SUPPERIOREQUAL, RIGHTSHIFT );
-    CHAR_IS_TOKEN_OR_TOKEN( '+', '+', PLUS, PLUSPLUS );
-    CHAR_IS_TOKEN_OR_TOKEN( '-', '-', MINUS, MINUSMINUS );
+    CHAR_IS_TOKEN_OR_TOKEN_OR_TOKEN( '+', '+', '=', PLUS, PLUSPLUS, PLUSEQUAL );
+    CHAR_IS_TOKEN_OR_TOKEN_OR_TOKEN( '-', '-', '=', MINUS, MINUSMINUS, MINUSEQUAL );
     CHAR_IS_TOKEN( '*', MULTIPLY );
     CHAR_IS_TOKEN( '/', DIVIDE );
     CHAR_IS_TOKEN( '%', MODULO );

Modified: trunk/OpenGTL/OpenShiva/tests/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/CMakeLists.txt	2008-10-01 06:38:54 UTC (rev 420)
+++ trunk/OpenGTL/OpenShiva/tests/CMakeLists.txt	2008-10-01 18:36:59 UTC (rev 421)
@@ -1,4 +1,5 @@
 add_subdirectory( parse )
+add_subdirectory( arithmetic )
 add_subdirectory( library )
 add_subdirectory( structures )
 add_subdirectory( vectors )

Added: trunk/OpenGTL/OpenShiva/tests/arithmetic/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/arithmetic/CMakeLists.txt	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/arithmetic/CMakeLists.txt	2008-10-01 18:36:59 UTC (rev 421)
@@ -0,0 +1,8 @@
+
+set( TESTS_FILES
+  plus_minus_equal.shiva
+  )
+
+FOREACH( TEST_FILE ${TESTS_FILES} )
+  ADD_TEST(${TEST_FILE} ${SHIVATESTER} ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE})
+ENDFOREACH( TEST_FILE )

Added: trunk/OpenGTL/OpenShiva/tests/arithmetic/plus_minus_equal.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/arithmetic/plus_minus_equal.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/arithmetic/plus_minus_equal.shiva	2008-10-01 18:36:59 UTC (rev 421)
@@ -0,0 +1,16 @@
+kernel MyKernel
+{
+  void evaluatePixel(output pixel result)
+  {
+  }
+  int runTest()
+  {
+    int count = 0;
+    float v = 1.0;
+    v += 1.0;
+    if( v != 2.0 ) ++count;
+    v -= 2.0;
+    if( v != 0.0 ) ++count;
+    return count;
+  }
+}


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