[opengtl-commits] [172] parse statements in shiva and add a test for the 'for' statement and a first simple generator test

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


Revision: 172
Author:   cyrille
Date:     2008-05-19 11:39:08 +0200 (Mon, 19 May 2008)

Log Message:
-----------
parse statements in shiva and add a test for the 'for' statement and a first simple generator test

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.h
    trunk/OpenGTL/OpenShiva/tests/parse/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/tests/parse/kernel.shiva

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/tests/imagegenerators/
    trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva
    trunk/OpenGTL/OpenShiva/tests/parse/for.shiva


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp	2008-05-19 09:09:36 UTC (rev 171)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp	2008-05-19 09:39:08 UTC (rev 172)
@@ -25,8 +25,10 @@
 #include "Lexer_p.h"
 #include "Types_p.h"
 
+#include <GTLCore/AST/Statement.h>
 #include <GTLCore/AST/Tree.h>
 
+namespace AST = GTLCore::AST;
 using namespace OpenShiva;
 
 struct Parser::Private {
@@ -117,3 +119,52 @@
       return ParserBase::parseType();
   }
 }
+
+AST::Statement* Parser::parseStatement()
+{
+  if( isType(currentToken()) )
+  {
+    return parseVariableDeclaration();
+  }
+  switch( currentToken().type )
+  {
+    case GTLCore::Token::CONST:
+      return parseVariableDeclaration();
+    case GTLCore::Token::STRUCT:
+    {
+      parseStructDefinition();
+      return new AST::DummyStatement();
+    }
+    case GTLCore::Token::STARTBRACKET:
+    case GTLCore::Token::IDENTIFIER:
+      return parseExpressionStatement();
+    case GTLCore::Token::IF:
+      return parseIfStatement();
+    case GTLCore::Token::WHILE:
+      return parseWhileStatement();
+    case GTLCore::Token::FOR:
+      return parseForStatement();
+    case GTLCore::Token::RETURN:
+      return parseReturnStatement();
+    case GTLCore::Token::STARTBRACE:
+    {
+      startContext();
+      AST::Statement* statement = parseStatementList();
+      endContext();
+      return statement;
+    }
+    case GTLCore::Token::PRINT:
+    {
+      return parsePrintStatement();
+    }
+    default:
+      if( currentToken().isUnaryOperator() or currentToken().isConstant() )
+      {
+        return parseExpressionStatement();
+      }
+      SHIVA_DEBUG("unexpected");
+      reportUnexpected( currentToken() );
+      getNextToken();
+      return 0;
+  }
+}

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.h	2008-05-19 09:09:36 UTC (rev 171)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.h	2008-05-19 09:39:08 UTC (rev 172)
@@ -38,7 +38,7 @@
       GTLCore::AST::Tree* parse();
     protected:
       virtual GTLCore::AST::Tree* tree();
-      virtual GTLCore::AST::Statement* parseStatement() { return 0; }
+      virtual GTLCore::AST::Statement* parseStatement();
       /**
        * Reimplement for support of Image, Region and Pixel types.
        */

Added: trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/imagegenerators/PlainGenerator.shiva	2008-05-19 09:39:08 UTC (rev 172)
@@ -0,0 +1,10 @@
+kernel PlainGenerator
+{
+  void evaluatePixel(out pixel result)
+  {
+    for(int i = 0; i < result.size )
+    {
+      pixel[i] = 0.5;
+    }
+  }
+}

Modified: trunk/OpenGTL/OpenShiva/tests/parse/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/parse/CMakeLists.txt	2008-05-19 09:09:36 UTC (rev 171)
+++ trunk/OpenGTL/OpenShiva/tests/parse/CMakeLists.txt	2008-05-19 09:39:08 UTC (rev 172)
@@ -1,6 +1,7 @@
 
 set( TESTS_FILES
   kernel.shiva
+  for.shiva
   )
 
 FOREACH( TEST_FILE ${TESTS_FILES} )

Added: trunk/OpenGTL/OpenShiva/tests/parse/for.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/parse/for.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/parse/for.shiva	2008-05-19 09:39:08 UTC (rev 172)
@@ -0,0 +1,9 @@
+kernel MyKernel
+{
+  void evaluatePixel(output pixel result)
+  {
+    for(int i = 0; i < 10; ++i)
+    {
+    }
+  }
+}

Modified: trunk/OpenGTL/OpenShiva/tests/parse/kernel.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/parse/kernel.shiva	2008-05-19 09:09:36 UTC (rev 171)
+++ trunk/OpenGTL/OpenShiva/tests/parse/kernel.shiva	2008-05-19 09:39:08 UTC (rev 172)
@@ -1,6 +1,6 @@
 kernel MyKernel
 {
-  void evaluatePixel(in image source1, out pixel result)
+  void evaluatePixel(input image source1, output pixel result)
   {
     
   }


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