[opengtl-commits] [642] fix use of c-style conversion inside expressions

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


Revision: 642
Author:   cyrille
Date:     2009-03-16 18:28:33 +0100 (Mon, 16 Mar 2009)

Log Message:
-----------
fix use of c-style conversion inside expressions

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
    trunk/OpenGTL/OpenShiva/tests/parse/CMakeLists.txt

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/tests/parse/cstyleconvertinexpressions.shiva
    trunk/OpenGTL/OpenShiva/tests/parse/cstyleconvertinvector.shiva


Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2009-03-16 17:02:29 UTC (rev 641)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2009-03-16 17:28:33 UTC (rev 642)
@@ -455,29 +455,6 @@
       }
     }
     return expr;
-  } else if( d->currentToken.isPrimary() )
-  {
-    GTL_DEBUG( d->currentToken.isPrimary() << " " << d->currentToken);
-    AST::Expression* exprConst = parsePrimaryExpression(_constantExpression);
-    if( exprConst )
-    { // What's next ? A binary operator or a ;
-      if( d->currentToken.isExpressionTerminal() )
-      {
-        return exprConst;
-      } else if( d->currentToken.isBinaryOperator() ) {
-        return parseFlatBinaryOperator( _constantExpression, exprConst );
-      } else {
-        GTL_DEBUG("unexpected");
-        reportUnexpected( d->currentToken );
-        getNextToken();
-        delete exprConst;
-        return 0;
-      }
-    } else {
-      // An error has occured
-      reportError("Parse error while parsing constant", d->currentToken );
-      return 0;
-    }
   } else if( d->currentToken.isUnaryOperator() )
   {
     AST::Expression* expr = parseUnaryOperator(_constantExpression);
@@ -495,11 +472,38 @@
     {
       return new AST::GlobalDataExpression( coumpoundExpression );
     }
-  } else if( isType(currentToken()) ) {
-    return parseTypeCoumpoundExpression( _constantExpression );
   } else {
+    AST::Expression* expression;
+    if( d->currentToken.isPrimary() )
+    {
+      GTL_DEBUG( d->currentToken.isPrimary() << " " << d->currentToken);
+      expression = parsePrimaryExpression(_constantExpression);
+      if(not expression)
+      {
+        // An error has occured
+        reportError("Parse error while parsing constant", d->currentToken );
+        return 0;
+      }
+    } else if( isType(currentToken()) ) {
+      expression = parseTypeCoumpoundExpression( _constantExpression );
+    } else {
+      GTL_DEBUG("unexpected");
+      reportUnexpected( d->currentToken );
+      return 0;
+    }
+    if( expression )
+    { // What's next ? A binary operator or a ;
+      if( d->currentToken.isExpressionTerminal() )
+      {
+        return expression;
+      } else if( d->currentToken.isBinaryOperator() ) {
+        return parseFlatBinaryOperator( _constantExpression, expression );
+      }
+    }
     GTL_DEBUG("unexpected");
     reportUnexpected( d->currentToken );
+    getNextToken();
+    delete expression;
     return 0;
   }
   return 0;

Modified: trunk/OpenGTL/OpenShiva/tests/parse/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/parse/CMakeLists.txt	2009-03-16 17:02:29 UTC (rev 641)
+++ trunk/OpenGTL/OpenShiva/tests/parse/CMakeLists.txt	2009-03-16 17:28:33 UTC (rev 642)
@@ -7,6 +7,7 @@
   import.shiva
   multipledependent.shiva
   dependentarray.shiva
+  cstyleconvertinexpressions.shiva
   )
 
 FOREACH( TEST_FILE ${TESTS_FILES} )

Added: trunk/OpenGTL/OpenShiva/tests/parse/cstyleconvertinexpressions.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/parse/cstyleconvertinexpressions.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/parse/cstyleconvertinexpressions.shiva	2009-03-16 17:28:33 UTC (rev 642)
@@ -0,0 +1,9 @@
+kernel MyKernel
+{
+  void evaluatePixel(output pixel result)
+  {
+    float v;
+    int i = int(v) % 2;
+    v = float(i) + 0.9;
+  }
+}

Added: trunk/OpenGTL/OpenShiva/tests/parse/cstyleconvertinvector.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/parse/cstyleconvertinvector.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/parse/cstyleconvertinvector.shiva	2009-03-16 17:28:33 UTC (rev 642)
@@ -0,0 +1,12 @@
+kernel MyKernel
+{
+  float2 funct()
+  {
+    int a;
+    return float2( 4, a/4);
+  }
+  void evaluatePixel(output pixel result)
+  {
+    float2 v = float2( 2, 3);
+  }
+}


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