From 66136699891ed7d5997c760d659f5420566a97ce Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Fri, 17 Apr 2020 14:09:37 -0500 Subject: [PATCH] Fix trick_exclude_typename Closes #985 --- .../Interface_Code_Gen/CommentSaver.cpp | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp b/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp index ef96cc0f..fbfd2915 100644 --- a/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp +++ b/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp @@ -196,46 +196,48 @@ bool CommentSaver::hasICGNoComment( std::string file_name ) { std::set< std::string > CommentSaver::getIgnoreTypes( std::string file_name ) { std::set< std::string > ignore_types ; std::string th_str = getTrickHeaderComment(file_name) ; - if ( ! th_str.empty() ) { - int ret ; - regex_t reg_expr ; - regmatch_t pmatch[10] ; - //std::cout << "here in getIgnoreTypes\n" << th_str << std::endl ; - size_t start = 0 ; - start = th_str.find( "trick_exclude_typename") ; - while ( start != std::string::npos ) { - start += strlen("trick_exclude_typename") ; - std::string temp_str = th_str.substr(start) ; - memset(pmatch , 0 , sizeof(pmatch)) ; - regcomp( ®_expr , "^\\s*\\{\\s*(\\S+)\\s*\\}" , REG_EXTENDED ) ; - ret = regexec( ®_expr , temp_str.c_str() , 10 , pmatch , 0 ) ; - regfree(®_expr) ; - if ( ret == 0 ) { - std::string item = temp_str.substr(pmatch[1].rm_so, pmatch[1].rm_eo) ; - // regular expression leaving trailing space and brace. Why? - item.erase(item.find_first_of(" \t}")) ; - //std::cout << "icg_ignore_types " << item << std::endl ; - ignore_types.insert(item) ; - } - start = th_str.find( "trick_exclude_typename", start ) ; - } + if ( th_str.empty() ) { + return ignore_types; + } - //std::transform(th_str.begin(), th_str.end(), th_str.begin(), ::toupper) ; + int ret ; + regex_t reg_expr ; + regmatch_t pmatch[10] ; + //std::cout << "here in getIgnoreTypes\n" << th_str << std::endl ; + size_t start = 0 ; + start = th_str.find( "trick_exclude_typename") ; + while ( start != std::string::npos ) { + start += strlen("trick_exclude_typename") ; + std::string temp_str = th_str.substr(start) ; memset(pmatch , 0 , sizeof(pmatch)) ; - - /* POSIX regular expressions are always greedy, making our job harder. - We have to use several regular expressions to get the types. This was - so much easier in perl! */ - - /* find the start of the ICG_IGNORE_TYPES field */ - regcomp( ®_expr , "(ICG[ _]IGNORE[ _]TYPE(S)?:)" , REG_EXTENDED | REG_ICASE ) ; - ret = regexec( ®_expr , th_str.c_str() , 10 , pmatch , 0 ) ; + regcomp( ®_expr , "^\\s*\\{\\s*(\\S+)\\s*\\}" , REG_EXTENDED ) ; + ret = regexec( ®_expr , temp_str.c_str() , 10 , pmatch , 0 ) ; regfree(®_expr) ; - if ( ret != 0 ) { - return std::set< std::string >() ; + if ( ret == 0 ) { + std::string item = temp_str.substr(pmatch[1].rm_so, pmatch[1].rm_eo) ; + // regular expression leaving trailing space and brace. Why? + item.erase(item.find_first_of(" \t}")) ; + //std::cout << "icg_ignore_types " << item << std::endl ; + ignore_types.insert(item) ; } + start = th_str.find( "trick_exclude_typename", start ) ; + } + + //std::transform(th_str.begin(), th_str.end(), th_str.begin(), ::toupper) ; + + memset(pmatch , 0 , sizeof(pmatch)) ; + + /* POSIX regular expressions are always greedy, making our job harder. + We have to use several regular expressions to get the types. This was + so much easier in perl! */ + + /* find the start of the ICG_IGNORE_TYPES field */ + regcomp( ®_expr , "(ICG[ _]IGNORE[ _]TYPE(S)?:)" , REG_EXTENDED | REG_ICASE ) ; + ret = regexec( ®_expr , th_str.c_str() , 10 , pmatch , 0 ) ; + regfree(®_expr) ; + if ( !ret ) { th_str = th_str.substr(pmatch[1].rm_eo) ; /* find the end of the ICG_IGNORE_TYPES field */ @@ -243,23 +245,21 @@ std::set< std::string > CommentSaver::getIgnoreTypes( std::string file_name ) { regcomp( ®_expr , "(\\)\\s*\\))" , REG_EXTENDED ) ; ret = regexec( ®_expr , th_str.c_str() , 10 , pmatch , 0 ) ; regfree(®_expr) ; - if ( ret != 0 ) { - return std::set< std::string >() ; - } - th_str = th_str.substr(0 , pmatch[1].rm_so) ; - std::replace( th_str.begin(), th_str.end(), '(', ' '); - std::replace( th_str.begin(), th_str.end(), ')', ' '); - std::replace( th_str.begin(), th_str.end(), '\n', ' '); + if ( !ret ) { + th_str = th_str.substr(0 , pmatch[1].rm_so) ; + std::replace( th_str.begin(), th_str.end(), '(', ' '); + std::replace( th_str.begin(), th_str.end(), ')', ' '); + std::replace( th_str.begin(), th_str.end(), '\n', ' '); - std::stringstream ss(th_str); - std::string item; - while (std::getline(ss, item, ' ')) { - if ( ! item.empty() ) { - //std::cout << "icg_ignore_types " << item << std::endl ; - ignore_types.insert(item) ; + std::stringstream ss(th_str); + std::string item; + while (std::getline(ss, item, ' ')) { + if ( ! item.empty() ) { + //std::cout << "icg_ignore_types " << item << std::endl ; + ignore_types.insert(item) ; + } } } - } return ignore_types ;