[opengtl-commits] [604] Initial work on the LightParser to extract information such as name and function type

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


Revision: 604
Author:   cyrille
Date:     2009-03-13 17:38:43 +0100 (Fri, 13 Mar 2009)

Log Message:
-----------
Initial work on the LightParser to extract information such as name and function type

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Source.h

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.h


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2009-03-12 23:00:19 UTC (rev 603)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2009-03-13 16:38:43 UTC (rev 604)
@@ -9,6 +9,7 @@
   Compiler_p.cpp
   CodeGenerator_p.cpp
   Lexer_p.cpp
+  LightParser_p.cpp
   Parser_p.cpp
   Wrapper_p.cpp
   PixelVisitor_p.cpp

Added: trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.cpp	2009-03-13 16:38:43 UTC (rev 604)
@@ -0,0 +1,72 @@
+/*
+ *  Copyright (c) 2009 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "LightParser_p.h"
+
+#include "Lexer_p.h"
+
+using namespace OpenShiva;
+
+struct LightParser::Private {
+  Lexer* lexer;
+  GTLCore::String name;
+  Source::SourceType sourceType;
+  Source::ImageType outputImageType;
+  std::vector<Source::ImageType> inputImageTypes;
+};
+
+LightParser::LightParser( Lexer* lexer ) : ParserBase(0, lexer), d(new Private)
+{
+  d->lexer = lexer;
+}
+
+LightParser::~LightParser()
+{
+  
+}
+
+GTLCore::AST::Tree* LightParser::parse()
+{
+  d->name = "";
+  d->sourceType = Source::InvalidSource;
+  d->outputImageType = Source::InvalidImage;
+  d->inputImageTypes.clear();
+  return 0;
+}
+
+const GTLCore::String& LightParser::name() const
+{
+  return d->name;
+}
+
+Source::SourceType LightParser::sourceType() const
+{
+  return d->sourceType;
+}
+
+Source::ImageType LightParser::outputImageType() const
+{
+  return d->outputImageType;
+}
+
+const std::vector<Source::ImageType>& LightParser::inputImageTypes() const
+{
+  return d->inputImageTypes;
+}
+


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.h	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.h	2009-03-13 16:38:43 UTC (rev 604)
@@ -0,0 +1,50 @@
+/*
+ *  Copyright (c) 2009 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _OPENSHIVA_LIGHT_PARSER_H_
+#define _OPENSHIVA_LIGHT_PARSER_H_
+
+#include "GTLCore/ParserBase_p.h"
+
+#include "Source.h"
+
+namespace GTLCore {
+  class String;
+};
+
+namespace OpenShiva {
+  class Lexer;
+  class LightParser : public GTLCore::ParserBase {
+    public:
+      LightParser( Lexer* );
+      ~LightParser();
+      GTLCore::AST::Tree* parse();
+      virtual GTLCore::AST::Tree* tree() { return 0; }
+      virtual GTLCore::AST::Statement* parseStatement() { return 0; }
+      Source::SourceType sourceType() const;
+      const GTLCore::String& name() const;
+      Source::ImageType outputImageType() const;
+      const std::vector<Source::ImageType>& inputImageTypes() const;
+    private:
+      struct Private;
+      Private* const d;
+  };
+}
+
+#endif


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp	2009-03-12 23:00:19 UTC (rev 603)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp	2009-03-13 16:38:43 UTC (rev 604)
@@ -24,6 +24,8 @@
 #include <GTLCore/String.h>
 
 #include "Debug.h"
+#include "Lexer_p.h"
+#include "LightParser_p.h"
 #include "MetadataLexer_p.h"
 #include "MetadataParser_p.h"
 #include "Metadata.h"
@@ -33,13 +35,18 @@
 
 struct Source::Private
 {
-  Private() : metadata(0), metadataCompilationFailed(false) {}
+  Private() : metadata(0), metadataCompilationFailed(false), uptodate(false), type( InvalidSource ) {}
   void compileMetaData();
+  void update();
   GTLCore::String name;
   GTLCore::String source;
   Metadata* metadata;
   bool metadataCompilationFailed;
   std::list<GTLCore::ErrorMessage> compilationErrors;
+  bool uptodate; ///< Hold wether name and type have been extracted from source
+  SourceType type;
+  ImageType outputImageType;
+  std::vector<ImageType> inputImageTypes;
 };
 
 
@@ -64,6 +71,18 @@
   }
 }
 
+void Source::Private::update()
+{
+  if(uptodate) return;
+  std::istringstream iss(source);
+  Lexer lexer( &iss );
+  LightParser parser(&lexer);
+  name = parser.name();
+  type = parser.sourceType();
+  outputImageType = parser.outputImageType();
+  inputImageTypes = parser.inputImageTypes();
+  uptodate = true;
+}
 
 Source::Source() : d(new Private)
 {
@@ -88,6 +107,7 @@
 
 const GTLCore::String& Source::name() const
 {
+  d->update();
   return d->name;
 }
 const GTLCore::String& Source::source() const
@@ -100,6 +120,7 @@
   GTLCore::Metadata::Factory::deleteEntry( d->metadata );
   d->metadata = 0;
   d->metadataCompilationFailed = false;
+  d->uptodate = false;
   d->source = _source;
 }
 
@@ -116,3 +137,28 @@
 {
   return d->compilationErrors;
 }
+
+Source::SourceType Source::sourceType() const
+{
+  d->update();
+  return d->type;
+}
+
+Source::ImageType Source::outputImageType() const
+{
+  return d->outputImageType;
+}
+
+Source::ImageType Source::inputImageType(int idx) const
+{
+  if( idx > 0 and (std::size_t)idx < d->inputImageTypes.size())
+  {
+    return d->inputImageTypes[idx];
+  }
+  return InvalidImage;
+}
+
+int Source::countInputImages() const
+{
+  return d->inputImageTypes.size();
+}

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Source.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Source.h	2009-03-12 23:00:19 UTC (rev 603)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Source.h	2009-03-13 16:38:43 UTC (rev 604)
@@ -49,6 +49,39 @@
        */
       const Metadata* metadata() const;
       const std::list<GTLCore::ErrorMessage>& metadataCompilationErrors() const;
+    public:
+      enum SourceType {
+        InvalidSource, ///< Not a valid Shiva source code
+        Library, ///< \ref Library
+        GeneratorKernel, ///< A \ref Kernel with only an output image
+        FilterKernel, ///< A \ref Kernel which takes one input
+        CompositionKernel ///< A \ref Kernel with multiple input
+      };
+      /**
+       * @return the type of the Kernel/Library
+       */
+      SourceType sourceType() const;
+      enum ImageType {
+        InvalidImage,
+        Image1,
+        Image2,
+        Image3,
+        Image4,
+        Image
+      };
+      /**
+       * @return the type of the output image
+       */
+      ImageType outputImageType() const;
+      /**
+       * @return the type of images at index @p idx
+       *         (if idx is out of range, return an \ref InvalidImage)
+       */
+      ImageType inputImageType(int idx) const;
+      /**
+       * @return the number of input images (-1 indicates the input functions takes an array)
+       */
+      int countInputImages() const;
     private:
       struct Private;
       Private* const d;


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