[opengtl-commits] [603] move metadata to the source |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 603
Author: cyrille
Date: 2009-03-13 00:00:19 +0100 (Fri, 13 Mar 2009)
Log Message:
-----------
move metadata to the source
Modified Paths:
--------------
trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/Library_p.h
trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/Source.h
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp 2009-03-12 22:31:38 UTC (rev 602)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Library.cpp 2009-03-12 23:00:19 UTC (rev 603)
@@ -37,9 +37,10 @@
#include "GTLCore/Value.h"
#include "GTLCore/VirtualMachine_p.h"
#include "GTLCore/wrappers/Allocate.h"
-#include "GTLCore/Metadata/Factory_p.h"
#include "GTLCore/Metadata/Group.h"
#include "GTLCore/Metadata/ParameterEntry.h"
+#include "Metadata.h"
+#include "GTLCore/Metadata/Factory_p.h"
#include "Debug.h"
#include "CodeGenerator_p.h"
@@ -47,42 +48,12 @@
#include "Wrapper_p.h"
#include "wrappers/ImageWrap_p.h"
#include "wrappers/RegionWrap_p.h"
-#include "MetadataLexer_p.h"
-#include "MetadataParser_p.h"
-#include "Metadata.h"
+
#include "Kernel_p.h"
using namespace OpenShiva;
-// ---- Library::Private ---- //
-
-void Library::Private::compileMetaData()
-{
- GTLCore::Metadata::Factory::deleteEntry( metadata );
- metadata = 0;
- compilationErrors.clear();
- std::istringstream iss(source.source());
- MetadataLexer* lexer = new MetadataLexer(&iss);
- MetadataParser parser( lexer, "" );
- metadata = parser.parse();
- compilationErrors = parser.errorMessages();
- metadataCompilationFailed = not compilationErrors.empty();
- GTL_DEBUG( compilationErrors.size() );
- GTL_DEBUG( parser.errorMessages().size() );
- parameters.clear();
- if( compilationErrors.size() == 0 )
- {
- if( metadata and metadata->parameters() )
- {
- metadataToParameters( metadata->parameters() );
- }
- } else {
- GTLCore::Metadata::Factory::deleteEntry( metadata );
- metadata = 0;
- }
-}
-
void Library::Private::metadataToParameters( const GTLCore::Metadata::Group* group)
{
SHIVA_ASSERT( group );
@@ -98,6 +69,16 @@
}
}
+void Library::Private::initparameters()
+{
+ const Metadata* metadata = source.metadata();
+ parameters.clear();
+ if( metadata and metadata->parameters() )
+ {
+ metadataToParameters( metadata->parameters() );
+ }
+}
+
// -------- Library -------- //
Library::Library( bool _isKernel , int _channelsNb) : d(new Private)
@@ -115,7 +96,6 @@
Library::~Library()
{
cleanup();
- GTLCore::Metadata::Factory::deleteEntry( d->metadata );
delete d;
}
@@ -140,7 +120,7 @@
void Library::setSource(const GTLCore::String& _source )
{
d->source.setSource(_source);
- d->compileMetaData();
+ d->initparameters();
}
void Library::setSource(const Source& source)
@@ -172,7 +152,7 @@
std::getline(in,str);
}
d->source.setSource(source);
- d->compileMetaData();
+ d->initparameters();
}
void Library::postCompilation()
@@ -181,7 +161,11 @@
void Library::compile()
{
- if(d->metadataCompilationFailed ) return;
+ if(not d->source.metadata() )
+ {
+ d->compilationErrors = d->source.metadataCompilationErrors();
+ return;
+ }
if(d->source.source().empty()) return;
cleanup();
d->m_moduleData = new GTLCore::ModuleData(new llvm::Module(d->name));
@@ -249,7 +233,7 @@
const Metadata* Library::metadata() const
{
- return d->metadata;
+ return d->source.metadata();
}
void Library::setParameter( const GTLCore::String& _name, GTLCore::Value _value )
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Library_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Library_p.h 2009-03-12 22:31:38 UTC (rev 602)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Library_p.h 2009-03-12 23:00:19 UTC (rev 603)
@@ -43,24 +43,22 @@
namespace OpenShiva {
struct Library::Private {
- Private() : m_moduleData(0), metadata(0), metadataCompilationFailed(true)
+ Private() : m_moduleData(0)
{
}
- void compileMetaData();
void metadataToParameters( const GTLCore::Metadata::Group* );
+ void initparameters();
GTLCore::String name;
Source source;
bool compiled;
- std::list<GTLCore::ErrorMessage> compilationErrors;
llvm::ModuleProvider* moduleProvider;
GTLCore::ModuleData* m_moduleData;
int count_channels_generic;
bool isKernel;
bool isStandardLibrary;
- Metadata* metadata;
- bool metadataCompilationFailed;
std::map< GTLCore::String, GTLCore::Value > parameters;
+ std::list<GTLCore::ErrorMessage> compilationErrors;
};
}
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.cpp 2009-03-12 22:31:38 UTC (rev 602)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.cpp 2009-03-12 23:00:19 UTC (rev 603)
@@ -62,43 +62,45 @@
const GTLCore::Metadata::Group* infoList = 0;
const GTLCore::Metadata::Group* parametersList = 0;
getNextToken() ;
- if( currentToken().type != GTLCore::Token::INFERIOR ) return 0;
- getNextToken();
- while( currentToken().type != GTLCore::Token::SUPPERIOR and currentToken().type != GTLCore::Token::END_OF_FILE )
+ if( currentToken().type == GTLCore::Token::INFERIOR )
{
- if( currentToken().type == GTLCore::Token::IDENTIFIER )
+ getNextToken();
+ while( currentToken().type != GTLCore::Token::SUPPERIOR and currentToken().type != GTLCore::Token::END_OF_FILE )
{
- SHIVA_DEBUG( currentToken().string );
- GTLCore::String str = currentToken().string;
- getNextToken();
- isOfType( currentToken(), GTLCore::Token::COLON );
- getNextToken();
- if( str == "version" )
+ if( currentToken().type == GTLCore::Token::IDENTIFIER )
{
- version = parseValueEntry("version");
- } else if( str == "info" ) {
- const GTLCore::Metadata::Entry* entry = parseGroupOrParameterEntry("info", false);
- if( entry )
+ SHIVA_DEBUG( currentToken().string );
+ GTLCore::String str = currentToken().string;
+ getNextToken();
+ isOfType( currentToken(), GTLCore::Token::COLON );
+ getNextToken();
+ if( str == "version" )
{
- infoList = entry->asGroup();
- GTL_ASSERT( infoList );
+ version = parseValueEntry("version");
+ } else if( str == "info" ) {
+ const GTLCore::Metadata::Entry* entry = parseGroupOrParameterEntry("info", false);
+ if( entry )
+ {
+ infoList = entry->asGroup();
+ GTL_ASSERT( infoList );
+ }
+ } else if( str == "parameters" ) {
+ const GTLCore::Metadata::Entry* entry = parseGroupOrParameterEntry("parameters", true);
+ if( entry )
+ {
+ parametersList = entry->asGroup();
+ GTL_ASSERT( parametersList );
+ }
+ } else {
+ GTL_DEBUG("Unexpected");
+ reportUnexpected( currentToken() );
+ getNextToken();
}
- } else if( str == "parameters" ) {
- const GTLCore::Metadata::Entry* entry = parseGroupOrParameterEntry("parameters", true);
- if( entry )
- {
- parametersList = entry->asGroup();
- GTL_ASSERT( parametersList );
- }
} else {
GTL_DEBUG("Unexpected");
reportUnexpected( currentToken() );
getNextToken();
}
- } else {
- GTL_DEBUG("Unexpected");
- reportUnexpected( currentToken() );
- getNextToken();
}
}
return new Metadata( version, infoList, parametersList );
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp 2009-03-12 22:31:38 UTC (rev 602)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp 2009-03-12 23:00:19 UTC (rev 603)
@@ -23,12 +23,48 @@
#include <GTLCore/String.h>
+#include "Debug.h"
+#include "MetadataLexer_p.h"
+#include "MetadataParser_p.h"
+#include "Metadata.h"
+#include "GTLCore/ErrorMessage.h"
+
+#include "GTLCore/Metadata/Factory_p.h"
+
struct Source::Private
{
+ Private() : metadata(0), metadataCompilationFailed(false) {}
+ void compileMetaData();
GTLCore::String name;
GTLCore::String source;
+ Metadata* metadata;
+ bool metadataCompilationFailed;
+ std::list<GTLCore::ErrorMessage> compilationErrors;
};
+
+// ---- Library::Private ---- //
+
+void Source::Private::compileMetaData()
+{
+ metadata = 0;
+ compilationErrors.clear();
+ std::istringstream iss(source);
+ MetadataLexer* lexer = new MetadataLexer(&iss);
+ MetadataParser parser( lexer, "" );
+ metadata = parser.parse();
+ compilationErrors = parser.errorMessages();
+ metadataCompilationFailed = not compilationErrors.empty();
+ GTL_DEBUG( compilationErrors.size() );
+ GTL_DEBUG( parser.errorMessages().size() );
+ if( compilationErrors.size() != 0 )
+ {
+ GTLCore::Metadata::Factory::deleteEntry( metadata );
+ metadata = 0;
+ }
+}
+
+
Source::Source() : d(new Private)
{
@@ -36,13 +72,13 @@
Source::Source(const Source& _rhs) : d(new Private(*_rhs.d))
{
-
+ d->metadata = 0;
}
Source& Source::operator=(const Source& _rhs)
{
- *d = *_rhs.d;
- return *this;
+ *d = *_rhs.d;
+ return *this;
}
Source::~Source()
@@ -61,7 +97,22 @@
void Source::setSource( const GTLCore::String& _source)
{
+ GTLCore::Metadata::Factory::deleteEntry( d->metadata );
+ d->metadata = 0;
+ d->metadataCompilationFailed = false;
d->source = _source;
}
+const Metadata* Source::metadata() const
+{
+ if(not d->metadata and not d->metadataCompilationFailed)
+ {
+ d->compileMetaData();
+ }
+ return d->metadata;
+}
+const std::list<GTLCore::ErrorMessage>& Source::metadataCompilationErrors() const
+{
+ return d->compilationErrors;
+}
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Source.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Source.h 2009-03-12 22:31:38 UTC (rev 602)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Source.h 2009-03-12 23:00:19 UTC (rev 603)
@@ -20,11 +20,15 @@
#ifndef _OPENSHIVA_KERNEL_SOURCE_H_
#define _OPENSHIVA_KERNEL_SOURCE_H_
+#include <list>
+
namespace GTLCore {
+ class ErrorMessage;
class String;
}
namespace OpenShiva {
+ class Metadata;
/**
* @ingroup OpenShiva
*
@@ -40,6 +44,11 @@
const GTLCore::String& name() const;
const GTLCore::String& source() const;
void setSource( const GTLCore::String& );
+ /**
+ * @return the metadata for this kernel.
+ */
+ const Metadata* metadata() const;
+ const std::list<GTLCore::ErrorMessage>& metadataCompilationErrors() const;
private:
struct Private;
Private* const d;