diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt
index 376cb462f..e30f20038 100644
--- a/opm/parser/eclipse/CMakeLists.txt
+++ b/opm/parser/eclipse/CMakeLists.txt
@@ -1,5 +1,8 @@
+include_directories(${PROJECT_BINARY_DIR}/generated-source/include)
+
add_subdirectory(OpmLog/tests)
add_subdirectory(Parser/tests)
+add_subdirectory(Generator/tests)
add_subdirectory(RawDeck/tests)
add_subdirectory(Deck/tests)
add_subdirectory(IntegrationTests)
@@ -53,10 +56,12 @@ Parser/ParserIntItem.cpp
Parser/ParserFloatItem.cpp
Parser/ParserDoubleItem.cpp
Parser/ParserStringItem.cpp
-${PROJECT_BINARY_DIR}/generated-source/DefaultKeywordList.cpp
+${PROJECT_BINARY_DIR}/generated-source/ParserKeywords.cpp
)
-SET_SOURCE_FILES_PROPERTIES(${PROJECT_BINARY_DIR}/generated-source/DefaultKeywordList.cpp PROPERTIES GENERATED TRUE)
+set( generator_source
+Generator/KeywordGenerator.cpp
+Generator/KeywordLoader.cpp )
set( build_parser_source
Parser/ParserEnums.cpp
@@ -67,6 +72,7 @@ Parser/ParserIntItem.cpp
Parser/ParserFloatItem.cpp
Parser/ParserDoubleItem.cpp
Parser/ParserStringItem.cpp
+${generator_source}
)
set (state_source
@@ -143,7 +149,9 @@ Parser/ParserIntItem.hpp
Parser/ParserFloatItem.hpp
Parser/ParserDoubleItem.hpp
Parser/ParserStringItem.hpp
-Parser/ParserKeywords.hpp # PlaceHolder for future generated header
+#
+Generator/KeywordLoader.hpp
+Generator/KeywordGenerator.hpp
#
Units/UnitSystem.hpp
Units/Dimension.hpp
@@ -243,7 +251,7 @@ Utility/EquilWrapper.hpp
Utility/EndscaleWrapper.hpp
Utility/ScalecrsWrapper.hpp)
-add_library(buildParser STATIC ${rawdeck_source} ${build_parser_source} ${deck_source} ${unit_source})
+add_library(buildParser STATIC ${rawdeck_source} ${build_parser_source} ${deck_source} ${unit_source} ${generator_source})
target_link_libraries(buildParser opmjson ${Boost_LIBRARIES})
#-----------------------------------------------------------------
@@ -264,19 +272,27 @@ target_link_libraries( createDefaultKeywordList buildParser opmjson ${Boost_LIBR
# This target will always run - the dependency "management" is
# implicitly handled in the createDefaultKeywordList application.
-add_custom_target( generatedCode ALL
- COMMAND createDefaultKeywordList
- ${PROJECT_SOURCE_DIR}/opm/parser/share/keywords
- ${PROJECT_BINARY_DIR}/generated-source/DefaultKeywordList.cpp
- ${PROJECT_BINARY_DIR}/generated-source/inlineKeywordTest.cpp
- ${PROJECT_BINARY_DIR}/generated-source/DefaultKeywordList.signature )
+add_custom_target( generatedCode ALL COMMAND createDefaultKeywordList
+ ${PROJECT_SOURCE_DIR}/opm/parser/share/keywords
+ ${PROJECT_BINARY_DIR}/generated-source/ParserKeywords.cpp
+ ${PROJECT_BINARY_DIR}/generated-source/include/opm/parser/eclipse/Parser/ParserKeywords.hpp
+ ${PROJECT_BINARY_DIR}/generated-source/inlineKeywordTest.cpp )
+
+set_source_files_properties(${PROJECT_BINARY_DIR}/generated-source/ParserKeywords.cpp PROPERTIES GENERATED TRUE)
+set_source_files_properties(${PROJECT_BINARY_DIR}/generated-source/inlcude/opm/parser/eclipse/Parser/ParserKeywords.hpp PROPERTIES GENERATED TRUE)
+set_source_files_properties(${PROJECT_BINARY_DIR}/generated-source/inlineKeywordTest.cpp PROPERTIES GENERATED TRUE)
+
+opm_add_test( runInlineKeywordTest SOURCES ${PROJECT_BINARY_DIR}/generated-source/inlineKeywordTest.cpp
+ LIBRARIES opmparser ${Boost_LIBRARIES}
+ DEPENDS generatedCode )
#-----------------------------------------------------------------
-add_library(opmparser ${rawdeck_source} ${parser_source} ${deck_source} ${state_source} ${unit_source} ${log_source})
-add_dependencies(opmparser generatedCode)
+add_library(opmparser ${rawdeck_source} ${parser_source} ${deck_source} ${state_source} ${unit_source} ${log_source} ${generator_source})
+add_dependencies( opmparser generatedCode )
target_link_libraries(opmparser opmjson ${Boost_LIBRARIES} ${ERT_LIBRARIES})
include( ${PROJECT_SOURCE_DIR}/cmake/Modules/install_headers.cmake )
install_headers( "${HEADER_FILES}" "${CMAKE_INSTALL_PREFIX}" )
install( TARGETS opmparser DESTINATION ${CMAKE_INSTALL_LIBDIR} )
+install( FILES ${PROJECT_BINARY_DIR}/generated-source/include/opm/parser/eclipse/Parser/ParserKeywords.hpp DESTINATION "include/opm/parser/eclipse/Parser")
diff --git a/opm/parser/eclipse/Generator/KeywordGenerator.cpp b/opm/parser/eclipse/Generator/KeywordGenerator.cpp
new file mode 100644
index 000000000..2e47d39fb
--- /dev/null
+++ b/opm/parser/eclipse/Generator/KeywordGenerator.cpp
@@ -0,0 +1,212 @@
+/*
+ Copyright 2015 Statoil ASA.
+
+ This file is part of the Open Porous Media project (OPM).
+
+ OPM is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OPM 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OPM. If not, see .
+*/
+
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+#include
+
+namespace Opm {
+
+ KeywordGenerator::KeywordGenerator(bool verbose)
+ : m_verbose( verbose )
+ {
+ }
+
+
+
+
+ std::string testHeader() {
+ std::string header = "#define BOOST_TEST_MODULE\n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "using namespace Opm;\n"
+ "std::shared_ptr unitSystem( UnitSystem::newMETRIC() );\n";
+
+ return header;
+ }
+
+
+ std::string KeywordGenerator::sourceHeader() {
+ std::string header = "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n\n\n"
+ "namespace Opm {\n"
+ "namespace ParserKeywords {\n\n";
+
+ return header;
+ }
+
+ std::string KeywordGenerator::headerHeader() {
+ std::string header = "#ifndef PARSER_KEYWORDS_HPP\n"
+ "#define PARSER_KEYWORDS_HPP\n"
+ "#include \n"
+ "namespace Opm {\n"
+ "namespace ParserKeywords {\n\n";
+
+ return header;
+ }
+
+ void KeywordGenerator::ensurePath( const std::string& file_name) {
+ boost::filesystem::path file(file_name);
+ if (!boost::filesystem::is_directory( file.parent_path()))
+ boost::filesystem::create_directories( file.parent_path());
+ }
+
+ bool KeywordGenerator::updateFile(std::stringstream& newContent , const std::string& filename) {
+ std::ifstream stream(filename.c_str());
+ bool update = true;
+
+ ensurePath( filename );
+ if (stream.is_open()) {
+ std::stringstream oldContent;
+ oldContent << stream.rdbuf( );
+ if (oldContent.str() == newContent.str())
+ update = false;
+ }
+
+ if (update) {
+ std::fstream stream(filename.c_str() , std::fstream::out);
+ stream << newContent.str();
+ stream.close();
+ }
+
+ return update;
+ }
+
+
+ bool KeywordGenerator::updateSource(const KeywordLoader& loader , const std::string& sourceFile) const {
+ std::stringstream newSource;
+
+ newSource << sourceHeader();
+ for (auto iter = loader.keyword_begin(); iter != loader.keyword_end(); ++iter) {
+ std::shared_ptr keyword = (*iter).second;
+ newSource << keyword->createCode() << std::endl;
+ }
+ newSource << "}" << std::endl;
+ {
+ newSource << "void Parser::addDefaultKeywords() {" << std::endl;
+ for (auto iter = loader.keyword_begin(); iter != loader.keyword_end(); ++iter) {
+ std::shared_ptr keyword = (*iter).second;
+ newSource << " addParserKeyword( std::shared_ptr( new ParserKeywords::" << keyword->className() << "()));" << std::endl;
+ }
+ newSource << "}" << std::endl;
+ }
+ newSource << "}" << std::endl;
+
+ {
+ bool update = updateFile( newSource , sourceFile );
+ if (m_verbose) {
+ if (update)
+ std::cout << "Updated source file written to: " << sourceFile << std::endl;
+ else
+ std::cout << "No changes to source file: " << sourceFile << std::endl;
+ }
+ return update;
+ }
+ }
+
+
+ bool KeywordGenerator::updateHeader(const KeywordLoader& loader , const std::string& headerFile) const {
+ std::stringstream stream;
+
+ stream << headerHeader();
+ for (auto iter = loader.keyword_begin(); iter != loader.keyword_end(); ++iter) {
+ std::shared_ptr keyword = (*iter).second;
+ stream << keyword->createDeclaration(" ") << std::endl;
+ }
+ stream << "}" << std::endl << "}" << std::endl;
+ stream << "#endif" << std::endl;
+
+ {
+ bool update = updateFile( stream , headerFile );
+ if (m_verbose) {
+ if (update)
+ std::cout << "Updated header file written to: " << headerFile << std::endl;
+ else
+ std::cout << "No changes to header file: " << headerFile << std::endl;
+ }
+ return update;
+ }
+ }
+
+
+ std::string KeywordGenerator::startTest(const std::string& keyword_name) {
+ return std::string("BOOST_AUTO_TEST_CASE(TEST") + keyword_name + std::string("Keyword) {\n");
+ }
+
+
+ std::string KeywordGenerator::endTest() {
+ return "}\n\n";
+ }
+
+
+
+ bool KeywordGenerator::updateTest(const KeywordLoader& loader , const std::string& testFile) const {
+ std::stringstream stream;
+
+ stream << testHeader();
+ for (auto iter = loader.keyword_begin(); iter != loader.keyword_end(); ++iter) {
+ const std::string& keywordName = (*iter).first;
+ std::shared_ptr keyword = (*iter).second;
+ stream << startTest(keywordName);
+ stream << " std::string jsonFile = \"" << loader.getJsonFile( keywordName) << "\";" << std::endl;
+ stream << " boost::filesystem::path jsonPath( jsonFile );" << std::endl;
+ stream << " Json::JsonObject jsonConfig( jsonPath );" << std::endl;
+ stream << " ParserKeyword jsonKeyword(jsonConfig);" << std::endl;
+ stream << " ParserKeywords::" << keywordName << " inlineKeyword;" << std::endl;
+ stream << " BOOST_CHECK( jsonKeyword.equal( inlineKeyword ));" << std::endl;
+ stream << " if (jsonKeyword.hasDimension()) {" <size(); i++){ " << std::endl;
+ stream << " ParserItemConstPtr item = parserRecord->get( i );" << std::endl;
+ stream << " for (size_t j=0; j < item->numDimensions(); j++) {" << std::endl;
+ stream << " std::string dimString = item->getDimension(j);" << std::endl;
+ stream << " BOOST_CHECK_NO_THROW( unitSystem->getNewDimension( dimString ));" << std::endl;
+ stream << " }" << std::endl;
+ stream << " }" << std::endl;
+ stream << " }" << std::endl;
+ stream << endTest( );
+ }
+
+ return updateFile( stream , testFile );
+ }
+}
+
+
diff --git a/opm/parser/eclipse/Generator/KeywordGenerator.hpp b/opm/parser/eclipse/Generator/KeywordGenerator.hpp
new file mode 100644
index 000000000..e93024e41
--- /dev/null
+++ b/opm/parser/eclipse/Generator/KeywordGenerator.hpp
@@ -0,0 +1,53 @@
+/*
+ Copyright 2015 Statoil ASA.
+
+ This file is part of the Open Porous Media project (OPM).
+
+ OPM is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OPM 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OPM. If not, see .
+*/
+
+
+#ifndef KEYWORD_GENERATOR_HPP
+#define KEYWORD_GENERATOR_HPP
+#include
+#include
+#include