Merge pull request #361 from flikka/keyword-folder

Put keywords in subfolders
This commit is contained in:
Joakim Hove 2014-11-19 14:55:30 +01:00
commit cc9fd8e3f7
221 changed files with 53 additions and 17 deletions

View File

@ -1,4 +1,4 @@
add_definitions( -DKEYWORD_DIRECTORY="${PROJECT_SOURCE_DIR}/opm/parser/share/keywords") add_definitions( -DKEYWORD_DIRECTORY="${PROJECT_SOURCE_DIR}/opm/parser/share/keywords/000_Eclipse100")
add_executable(runCheckDeckValidity CheckDeckValidity.cpp) add_executable(runCheckDeckValidity CheckDeckValidity.cpp)
target_link_libraries(runCheckDeckValidity Parser ${Boost_LIBRARIES}) target_link_libraries(runCheckDeckValidity Parser ${Boost_LIBRARIES})

View File

@ -88,8 +88,8 @@ static void generateKeywordSignature(std::iostream& of , KeywordMapType& keyword
{ {
for (auto iter=keywordMap.begin(); iter != keywordMap.end(); ++iter) { for (auto iter=keywordMap.begin(); iter != keywordMap.end(); ++iter) {
KeywordElementType keywordElement = *iter; KeywordElementType keywordElement = *iter;
const std::string& fileName = keywordElement.first; const std::string& keywordName = keywordElement.first;
const std::string& keywordName = keywordElement.second.first; const std::string& fileName = keywordElement.second.first;
Json::JsonObject * jsonKeyword = new Json::JsonObject(boost::filesystem::path(fileName)); Json::JsonObject * jsonKeyword = new Json::JsonObject(boost::filesystem::path(fileName));
of << keywordName << std::endl << jsonKeyword->get_content() << std::endl; of << keywordName << std::endl << jsonKeyword->get_content() << std::endl;
@ -136,8 +136,8 @@ static void testKeyword(ParserKeywordConstPtr parserKeyword , const std::string&
static void generateTestForKeyword(std::iostream& of, KeywordElementType keywordElement) { static void generateTestForKeyword(std::iostream& of, KeywordElementType keywordElement) {
const std::string& fileName = keywordElement.first; const std::string& keywordName = keywordElement.first;
const std::string& keywordName = keywordElement.second.first; const std::string& fileName = keywordElement.second.first;
ParserKeywordConstPtr parserKeyword = keywordElement.second.second; ParserKeywordConstPtr parserKeyword = keywordElement.second.second;
testKeyword( parserKeyword , keywordName , fileName , of ); testKeyword( parserKeyword , keywordName , fileName , of );
@ -157,7 +157,7 @@ static void generateKeywordTest(const char * test_file_name , KeywordMapType& ke
static void generateSourceForKeyword(std::iostream& of, KeywordElementType keywordElement) static void generateSourceForKeyword(std::iostream& of, KeywordElementType keywordElement)
{ {
const std::string& keywordName = keywordElement.second.first; const std::string& keywordName = keywordElement.first;
ParserKeywordConstPtr parserKeyword = keywordElement.second.second; ParserKeywordConstPtr parserKeyword = keywordElement.second.second;
std::string indent(" "); std::string indent(" ");
@ -179,15 +179,15 @@ static void generateKeywordSource(const char * source_file_name , KeywordMapType
// the stupid default compiler flags will cause a warning if a function is // the stupid default compiler flags will cause a warning if a function is
// defined without declaring a prototype before. So let's give the compiler a // defined without declaring a prototype before. So let's give the compiler a
// cookie to make it happy... // cookie to make it happy...
source_file_stream << "void add" << iter->second.first << "Keyword(Opm::Parser *parser);\n"; source_file_stream << "void add" << iter->first << "Keyword(Opm::Parser *parser);\n";
source_file_stream << "void add" << iter->second.first << "Keyword(Opm::Parser *parser)\n"; source_file_stream << "void add" << iter->first << "Keyword(Opm::Parser *parser)\n";
generateSourceForKeyword(source_file_stream , *iter); generateSourceForKeyword(source_file_stream , *iter);
} }
startFunction(source_file_stream); startFunction(source_file_stream);
for (auto iter=keywordMap.begin(); iter != keywordMap.end(); ++iter) for (auto iter=keywordMap.begin(); iter != keywordMap.end(); ++iter)
source_file_stream << " add" << iter->second.first << "Keyword(this);\n"; source_file_stream << " add" << iter->first << "Keyword(this);\n";
endFunction(source_file_stream); endFunction(source_file_stream);
source_file_stream << "} // end namespace Opm\n"; source_file_stream << "} // end namespace Opm\n";
@ -198,11 +198,20 @@ static void generateKeywordSource(const char * source_file_name , KeywordMapType
//----------------------------------------------------------------- //-----------------------------------------------------------------
static void scanKeyword(const boost::filesystem::path& file , KeywordMapType& keywordMap) { static void scanKeyword(const boost::filesystem::path& file , KeywordMapType& keywordMap) {
if (!ParserKeyword::validInternalName(file.filename().string())) { std::string internalName = file.filename().string();
if (!ParserKeyword::validInternalName(internalName)) {
std::cerr << "Warning: Ignoring incorrectly named file '" << file.string() << "'.\n"; std::cerr << "Warning: Ignoring incorrectly named file '" << file.string() << "'.\n";
return; return;
} }
KeywordMapType::iterator existingEntry = keywordMap.find(internalName);
bool alreadyExists = existingEntry != keywordMap.end();
if (alreadyExists) {
std::cerr << "Warning: Ignoring the the keyword " << internalName << " found in '" << existingEntry->second.first << "'," << std::endl
<< "\treplacing it with data from '" << file.string() << "'" << std::endl;
keywordMap.erase(existingEntry);
}
Json::JsonObject * jsonKeyword; Json::JsonObject * jsonKeyword;
try { try {
jsonKeyword = new Json::JsonObject(file); jsonKeyword = new Json::JsonObject(file);
@ -216,8 +225,8 @@ static void scanKeyword(const boost::filesystem::path& file , KeywordMapType& ke
if (parserKeyword->getName() != boost::filesystem::basename(file)) if (parserKeyword->getName() != boost::filesystem::basename(file))
std::cerr << "Warning: The name '" << parserKeyword->getName() << " specified in the JSON definitions of file '" << file std::cerr << "Warning: The name '" << parserKeyword->getName() << " specified in the JSON definitions of file '" << file
<< "' does not match the file's name!\n"; << "' does not match the file's name!\n";
std::pair<std::string , ParserKeywordConstPtr> elm(file.filename().string(), parserKeyword); std::pair<std::string , ParserKeywordConstPtr> elm(file.string(), parserKeyword);
std::pair<std::string , std::pair<std::string , ParserKeywordConstPtr> > pair(file.string() , elm); std::pair<std::string , std::pair<std::string , ParserKeywordConstPtr> > pair(parserKeyword->getName() , elm);
keywordMap.insert(pair); keywordMap.insert(pair);
} }
@ -226,8 +235,8 @@ static void scanKeyword(const boost::filesystem::path& file , KeywordMapType& ke
} }
static void scanAllKeywords(const boost::filesystem::path& directory , KeywordMapType& keywordMap) { static void scanAllKeywords(const boost::filesystem::path& directory , KeywordMapType& keywordMap) {
boost::filesystem::directory_iterator end; boost::filesystem::directory_iterator end_iterator;
for (boost::filesystem::directory_iterator iter(directory); iter != end; iter++) { for (boost::filesystem::directory_iterator iter(directory); iter != end_iterator; iter++) {
if (boost::filesystem::is_directory(*iter)) if (boost::filesystem::is_directory(*iter))
scanAllKeywords(*iter , keywordMap); scanAllKeywords(*iter , keywordMap);
else else
@ -241,7 +250,7 @@ static void scanAllKeywords(const boost::filesystem::path& directory , KeywordMa
static void printUsage() { static void printUsage() {
std::cout << "Generates source code for populating the parser's list of known keywords." << std::endl; std::cout << "Generates source code for populating the parser's list of known keywords." << std::endl;
std::cout << "Usage: createDefaultKeywordList <configroot> <sourcefilename> [<dumpfilename>]" << std::endl; std::cout << "Usage: createDefaultKeywordList <configroot> <sourcefilename> [<dumpfilename>]" << std::endl;
std::cout << " <configroot>: Path to keyword (JSON) files" << std::endl; std::cout << " <configroot>: Path to keyword (JSON) files, first level below this will be read in alfanumerical order. Ignoring repeated keywords." << std::endl;
std::cout << " <sourcefilename>: Path to source file to generate" << std::endl; std::cout << " <sourcefilename>: Path to source file to generate" << std::endl;
std::cout << " <testfilename> : Path to source file with keyword testing" << std::endl; std::cout << " <testfilename> : Path to source file with keyword testing" << std::endl;
std::cout << " <dumpfilename>: Path to dump file containing state of keyword list at" << std::endl; std::cout << " <dumpfilename>: Path to dump file containing state of keyword list at" << std::endl;
@ -256,6 +265,29 @@ static void ensurePath( const char * file_name ) {
} }
static std::vector<boost::filesystem::path> getPathsInAlfanumOrder(const char* config_root)
{
boost::filesystem::path root(config_root);
std::vector<std::string> paths_in_root;
boost::filesystem::directory_iterator end_iterator;
for (boost::filesystem::directory_iterator iter(root); iter != end_iterator; iter++) {
if (boost::filesystem::is_directory(*iter)) {
paths_in_root.push_back(iter->path().string());
}
}
std::sort(paths_in_root.begin(), paths_in_root.end());
std::vector<boost::filesystem::path> paths_in_alfanum_order;
std::cout << "Paths will be scanned for keyword definitions in the following order, ignoring repeats:" << std::endl;
for (auto it = paths_in_root.begin(); it != paths_in_root.end(); ++it) {
std::cerr << "-- " << *it << std::endl;
paths_in_alfanum_order.push_back(boost::filesystem::path(*it));
}
return paths_in_alfanum_order;
}
int main(int /* argc */, char ** argv) { int main(int /* argc */, char ** argv) {
const char * config_root = argv[1]; const char * config_root = argv[1];
const char * source_file_name = argv[2]; const char * source_file_name = argv[2];
@ -267,7 +299,7 @@ int main(int /* argc */, char ** argv) {
return 0; return 0;
} }
KeywordMapType keywordMap; KeywordMapType keywordMap;
boost::filesystem::path keywordPath(config_root);
bool needToGenerate = false; bool needToGenerate = false;
std::stringstream signature_stream; std::stringstream signature_stream;
@ -276,7 +308,11 @@ int main(int /* argc */, char ** argv) {
ensurePath( test_file_name ); ensurePath( test_file_name );
ensurePath( signature_file_name ); ensurePath( signature_file_name );
scanAllKeywords( config_root , keywordMap ); std::vector<boost::filesystem::path> paths_in_alfanum_order = getPathsInAlfanumOrder(config_root);
for (auto it = paths_in_alfanum_order.begin(); it != paths_in_alfanum_order.end(); ++it) {
scanAllKeywords( *it , keywordMap );
}
generateKeywordSignature(signature_stream , keywordMap); generateKeywordSignature(signature_stream , keywordMap);

Some files were not shown because too many files have changed in this diff Show More