From fca4b292bce12b31346f240b890f8c16e56ee172 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Wed, 13 Mar 2024 18:29:29 +0000 Subject: [PATCH] Per #2673, update the enum_to_string and flex/bison inputs to make it more compliant with the SonarQube standards. --- src/basic/enum_to_string/code.cc | 18 +-- src/basic/enum_to_string/enum_parser.yy | 4 +- src/basic/enum_to_string/enum_scanner.ll | 54 ++++---- src/basic/enum_to_string/info.cc | 2 +- src/basic/enum_to_string/info.h | 12 +- src/basic/enum_to_string/my_enum_scanner.cc | 2 +- src/basic/enum_to_string/scope.h | 6 +- src/basic/vx_config/config.tab.yy | 2 +- src/basic/vx_config/config_scanner.ll | 122 +++++++++--------- .../vx_config/configobjecttype_to_string.cc | 1 - src/libcode/vx_color/color_scanner.ll | 46 +++---- 11 files changed, 132 insertions(+), 137 deletions(-) diff --git a/src/basic/enum_to_string/code.cc b/src/basic/enum_to_string/code.cc index fb62ba003f..9b5c431f35 100644 --- a/src/basic/enum_to_string/code.cc +++ b/src/basic/enum_to_string/code.cc @@ -489,21 +489,19 @@ warning(out); out << "\n\n" << sep << "\n\n" - << "using namespace std;\n" - << "\n\n" << "#include \n" << "\n" << "#include " << L << lower << "_to_string"; if ( header_suffix ) out << header_suffix; -out << R - << "\n" +out << R + << "\n\n" + << "using namespace std;\n" << "\n\n" << sep << "\n\n"; - forward(e, lower, out); out << "\n\n" @@ -607,8 +605,6 @@ warning(out); out << "\n\n" << sep << "\n\n" - << "using namespace std;\n" - << "\n\n" << "#include \n" << "\n" << "#include " << L << lower << "_to_string"; @@ -616,12 +612,12 @@ out << "\n\n" if ( header_suffix ) out << header_suffix; out << R - << "\n" + << "\n\n" + << "using namespace std;\n" << "\n\n" << sep << "\n\n"; - forward_cs(e, lower, out); out << "\n\n" @@ -758,7 +754,7 @@ out << e.name() << " t)\n" << "{\n" << "\n"; -out << "const char * s = (const char *) 0;\n\n"; +out << "const char * s = (const char *) nullptr;\n\n"; out << "switch ( t ) {\n" << "\n"; @@ -802,7 +798,7 @@ out << "\n" << "} // switch\n" << "\n\n"; -out << "return ( ConcatString (s) );\n" +out << "return ConcatString(s);\n" << "\n"; out << "}\n"; diff --git a/src/basic/enum_to_string/enum_parser.yy b/src/basic/enum_to_string/enum_parser.yy index 61718fe01a..989ccd2702 100644 --- a/src/basic/enum_to_string/enum_parser.yy +++ b/src/basic/enum_to_string/enum_parser.yy @@ -46,7 +46,7 @@ extern bool do_concat_string; EnumInfo einfo; -const char * header_filename = (const char *) 0; +const char * header_filename = (const char *) nullptr; ScopeStack ss; @@ -171,7 +171,7 @@ void set_name(const char * text) { int j, n; -const char * c = (const char *) 0; +const char * c = (const char *) nullptr; ostringstream s; diff --git a/src/basic/enum_to_string/enum_scanner.ll b/src/basic/enum_to_string/enum_scanner.ll index f69a8e3e08..a59f4e358a 100644 --- a/src/basic/enum_to_string/enum_scanner.ll +++ b/src/basic/enum_to_string/enum_scanner.ll @@ -89,16 +89,16 @@ WS " "|"\t" %% -enum { do_enum(); return ( token(ENUM) ); } -class { do_class(); return ( token(CLASS) ); } +enum { do_enum(); return token(ENUM); } +class { do_class(); return token(CLASS); } -"{" { if ( do_left_curly() ) return ( token(L_CURLY) ); } -"}" { if ( do_right_curly() ) return ( token(R_CURLY) ); } -"=" { if ( do_equals() ) return ( token (EQ) ); } -";" { if ( do_semi() ) return ( token(';') ); } -"," { if ( do_comma() ) return ( token(',') ); } -("-"?)({DIGIT})+ { if ( do_int() ) return ( token(INTEGER) ); } -({LETTER})({LETTER}|{DIGIT})* { if ( do_id() ) return ( token(ID) ); } +"{" { if ( do_left_curly() ) return token(L_CURLY); } +"}" { if ( do_right_curly() ) return token(R_CURLY); } +"=" { if ( do_equals() ) return token (EQ); } +";" { if ( do_semi() ) return token(';'); } +"," { if ( do_comma() ) return token(','); } +("-"?)({DIGIT})+ { if ( do_int() ) return token(INTEGER); } +({LETTER})({LETTER}|{DIGIT})* { if ( do_id() ) return token(ID); } @@ -160,13 +160,13 @@ if ( enum_mode || last_was_enum || last_was_class ) { strncpy(yylval.name, yytext, sizeof(yylval.name)); - return ( 1 ); + return 1; } -return ( 0 ); +return 0; } @@ -180,13 +180,13 @@ int do_int() column += strlen(yytext); -if ( !enum_mode ) return ( 0 ); +if ( !enum_mode ) return 0; yylval.ival = atoi(yytext); -return ( 1 ); +return 1; } @@ -202,12 +202,12 @@ int do_left_curly() ++column; -if ( !enum_mode ) return ( 0 ); +if ( !enum_mode ) return 0; yylval.ival = bracket_level; -return ( 1 ); +return 1; } @@ -225,12 +225,12 @@ int do_right_curly() ss.clear_to_level(bracket_level); -if ( !enum_mode ) return ( 0 ); +if ( !enum_mode ) return 0; yylval.ival = bracket_level + 1; -return ( 1 ); +return 1; } @@ -244,10 +244,10 @@ int do_semi() ++column; -if ( enum_mode ) return ( 1 ); +if ( enum_mode ) return 1; -return ( 0 ); +return 0; } @@ -261,10 +261,10 @@ int do_equals() ++column; -if ( enum_mode ) return ( 1 ); +if ( enum_mode ) return 1; -return ( 0 ); +return 0; } @@ -278,10 +278,10 @@ int do_comma() ++column; -if ( enum_mode ) return ( 1 ); +if ( enum_mode ) return 1; -return ( 0 ); +return 0; } @@ -300,7 +300,7 @@ c1 = nextchar(); c2 = nextchar(); -while ( 1 ) { +while ( true ) { if ( (c1 == EOF) || (c2 == EOF) ) break; @@ -329,7 +329,7 @@ void do_cpp_comment() int c; -while ( 1 ) { +while ( true ) { c = nextchar(); @@ -366,7 +366,7 @@ if ( c == '\n' ) { } -return ( c ); +return c; } @@ -388,7 +388,7 @@ if ( t == CLASS ) last_was_class = 1; if ( t == ENUM ) last_was_enum = 1; -return ( t ); +return t; } diff --git a/src/basic/enum_to_string/info.cc b/src/basic/enum_to_string/info.cc index c1794c37a4..76927b8979 100644 --- a/src/basic/enum_to_string/info.cc +++ b/src/basic/enum_to_string/info.cc @@ -275,7 +275,7 @@ for (j=0; j 0 ); +return digit_count > 0; } diff --git a/src/basic/enum_to_string/scope.h b/src/basic/enum_to_string/scope.h index ee27397451..93ca9d44ec 100644 --- a/src/basic/enum_to_string/scope.h +++ b/src/basic/enum_to_string/scope.h @@ -57,9 +57,9 @@ class ScopeStackElement { //////////////////////////////////////////////////////////////////////// -inline int ScopeStackElement::level() const { return ( Level ); } +inline int ScopeStackElement::level() const { return Level; } -inline const char * ScopeStackElement::name() const { return ( Name ); } +inline const char * ScopeStackElement::name() const { return Name; } //////////////////////////////////////////////////////////////////////// @@ -113,7 +113,7 @@ class ScopeStack { //////////////////////////////////////////////////////////////////////// -inline int ScopeStack::n_elements() const { return ( N ); } +inline int ScopeStack::n_elements() const { return N; } //////////////////////////////////////////////////////////////////////// diff --git a/src/basic/vx_config/config.tab.yy b/src/basic/vx_config/config.tab.yy index 836a874747..dabe56d786 100644 --- a/src/basic/vx_config/config.tab.yy +++ b/src/basic/vx_config/config.tab.yy @@ -815,7 +815,7 @@ DictionaryEntry e; count = 0; -while ( 1 ) { +while ( true ) { v = icvs.pop(); diff --git a/src/basic/vx_config/config_scanner.ll b/src/basic/vx_config/config_scanner.ll index 515b068416..371af9971a 100644 --- a/src/basic/vx_config/config_scanner.ll +++ b/src/basic/vx_config/config_scanner.ll @@ -129,63 +129,63 @@ REAL_NUMBER (("-"?){DIGITS}{EXP})|(("-"?)"."{DIGITS}{OPT_EXP})|(("-"?){DIGITS}" %% -"<" { return ( do_comp() ); } -">" { return ( do_comp() ); } -"<=" { return ( do_comp() ); } -">=" { return ( do_comp() ); } -"==" { return ( do_comp() ); } -"!=" { return ( do_comp() ); } -"NA" { return ( do_comp() ); } +"<" { return do_comp(); } +">" { return do_comp(); } +"<=" { return do_comp(); } +">=" { return do_comp(); } +"==" { return do_comp(); } +"!=" { return do_comp(); } +"NA" { return do_comp(); } -"le"({INT_NUMBER}|{REAL_NUMBER}) { return ( do_fort_thresh() ); } -"lt"({INT_NUMBER}|{REAL_NUMBER}) { return ( do_fort_thresh() ); } -"gt"({INT_NUMBER}|{REAL_NUMBER}) { return ( do_fort_thresh() ); } -"ge"({INT_NUMBER}|{REAL_NUMBER}) { return ( do_fort_thresh() ); } -"eq"({INT_NUMBER}|{REAL_NUMBER}) { return ( do_fort_thresh() ); } -"ne"({INT_NUMBER}|{REAL_NUMBER}) { return ( do_fort_thresh() ); } +"le"({INT_NUMBER}|{REAL_NUMBER}) { return do_fort_thresh(); } +"lt"({INT_NUMBER}|{REAL_NUMBER}) { return do_fort_thresh(); } +"gt"({INT_NUMBER}|{REAL_NUMBER}) { return do_fort_thresh(); } +"ge"({INT_NUMBER}|{REAL_NUMBER}) { return do_fort_thresh(); } +"eq"({INT_NUMBER}|{REAL_NUMBER}) { return do_fort_thresh(); } +"ne"({INT_NUMBER}|{REAL_NUMBER}) { return do_fort_thresh(); } -"&&" { Column+=2; return ( LOGICAL_OP_AND ); } -"||" { Column+=2; return ( LOGICAL_OP_OR ); } +"&&" { Column+=2; return LOGICAL_OP_AND; } +"||" { Column+=2; return LOGICAL_OP_OR; } -"!" { Column+=1; return ( LOGICAL_OP_NOT ); } +"!" { Column+=1; return LOGICAL_OP_NOT; } -"[" { ++Column; is_lhs = false; dict_stack->push_array(); return ( configtext[0] ); } -"{" { ++Column; is_lhs = true; dict_stack->push(); return ( configtext[0] ); } +"[" { ++Column; is_lhs = false; dict_stack->push_array(); return configtext[0]; } +"{" { ++Column; is_lhs = true; dict_stack->push(); return configtext[0]; } -"]" { ++Column; return ( configtext[0] ); } -"}" { ++Column; return ( configtext[0] ); } +"]" { ++Column; return configtext[0]; } +"}" { ++Column; return configtext[0]; } -"(" { ++Column; return ( configtext[0] ); } -")" { ++Column; return ( configtext[0] ); } +"(" { ++Column; return configtext[0]; } +")" { ++Column; return configtext[0]; } -"+" { ++Column; return ( configtext[0] ); } -"-" { ++Column; return ( configtext[0] ); } -"/" { ++Column; return ( configtext[0] ); } -"*" { ++Column; return ( configtext[0] ); } -"^" { ++Column; return ( configtext[0] ); } +"+" { ++Column; return configtext[0]; } +"-" { ++Column; return configtext[0]; } +"/" { ++Column; return configtext[0]; } +"*" { ++Column; return configtext[0]; } +"^" { ++Column; return configtext[0]; } -"=" { ++Column; return ( configtext[0] ); } -";" { ++Column; is_lhs = true; return ( configtext[0] ); } -"," { ++Column; return ( configtext[0] ); } +"=" { ++Column; return configtext[0]; } +";" { ++Column; is_lhs = true; return configtext[0]; } +"," { ++Column; return configtext[0]; } -"\"" { do_quoted_string(); return ( QUOTED_STRING ); } +"\"" { do_quoted_string(); return QUOTED_STRING; } "${"{IDENTIFIER}"}" { do_env(); } -{IDENTIFIER} { return ( do_id() ); } +{IDENTIFIER} { return do_id(); } -{INT_NUMBER} { do_int(); return ( INTEGER ); } +{INT_NUMBER} { do_int(); return INTEGER; } -{REAL_NUMBER} { do_float(); return ( FLOAT ); } +{REAL_NUMBER} { do_float(); return FLOAT; } @@ -199,7 +199,7 @@ REAL_NUMBER (("-"?){DIGITS}{EXP})|(("-"?)"."{DIGITS}{OPT_EXP})|(("-"?){DIGITS}" "\n" { ++LineNumber; Column = 1; } -<> { if ( do_eof() ) return ( 0 ); } +<> { if ( do_eof() ) return 0; } . { ++Column; } @@ -230,7 +230,7 @@ if ( c == '\n' ) { } -return ( c ); +return c; } @@ -245,7 +245,7 @@ void do_cpp_comment() int c; -while ( 1 ) { +while ( true ) { c = nextchar(); @@ -275,7 +275,7 @@ c2 = nextchar(); comment_depth = 1; -while ( 1 ) { +while ( true ) { if ( (c1 == EOF) || (c2 == EOF) ) break; @@ -338,7 +338,7 @@ else { // done // -return ( return_value ); +return return_value; } @@ -389,7 +389,7 @@ char line[max_id_length]; n = 0; -while ( 1 ) { +while ( true ) { c = nextchar(); @@ -476,32 +476,32 @@ Column += strlen(configtext); // print? // -if ( strcmp(configtext, "print" ) == 0 ) { return ( PRINT ); } +if ( strcmp(configtext, "print" ) == 0 ) { return PRINT; } // // boolean? // -if ( strcmp(configtext, "true" ) == 0 ) { configlval.bval = true; return ( BOOLEAN ); } -if ( strcmp(configtext, "false" ) == 0 ) { configlval.bval = false; return ( BOOLEAN ); } +if ( strcmp(configtext, "true" ) == 0 ) { configlval.bval = true; return BOOLEAN; } +if ( strcmp(configtext, "false" ) == 0 ) { configlval.bval = false; return BOOLEAN; } -if ( strcmp(configtext, "TRUE" ) == 0 ) { configlval.bval = true; return ( BOOLEAN ); } -if ( strcmp(configtext, "FALSE" ) == 0 ) { configlval.bval = false; return ( BOOLEAN ); } +if ( strcmp(configtext, "TRUE" ) == 0 ) { configlval.bval = true; return BOOLEAN; } +if ( strcmp(configtext, "FALSE" ) == 0 ) { configlval.bval = false; return BOOLEAN; } // // comparison? // -if ( strcmp(configtext, "lt" ) == 0 ) { configlval.cval = thresh_lt; return ( COMPARISON ); } -if ( strcmp(configtext, "le" ) == 0 ) { configlval.cval = thresh_le; return ( COMPARISON ); } +if ( strcmp(configtext, "lt" ) == 0 ) { configlval.cval = thresh_lt; return COMPARISON; } +if ( strcmp(configtext, "le" ) == 0 ) { configlval.cval = thresh_le; return COMPARISON; } -if ( strcmp(configtext, "gt" ) == 0 ) { configlval.cval = thresh_gt; return ( COMPARISON ); } -if ( strcmp(configtext, "ge" ) == 0 ) { configlval.cval = thresh_ge; return ( COMPARISON ); } +if ( strcmp(configtext, "gt" ) == 0 ) { configlval.cval = thresh_gt; return COMPARISON; } +if ( strcmp(configtext, "ge" ) == 0 ) { configlval.cval = thresh_ge; return COMPARISON; } -if ( strcmp(configtext, "ne" ) == 0 ) { configlval.cval = thresh_ne; return ( COMPARISON ); } -if ( strcmp(configtext, "eq" ) == 0 ) { configlval.cval = thresh_eq; return ( COMPARISON ); } +if ( strcmp(configtext, "ne" ) == 0 ) { configlval.cval = thresh_ne; return COMPARISON; } +if ( strcmp(configtext, "eq" ) == 0 ) { configlval.cval = thresh_eq; return COMPARISON; } -if ( strcmp(configtext, na_str ) == 0 ) { configlval.cval = thresh_na; return ( NA_COMPARISON ); } +if ( strcmp(configtext, na_str ) == 0 ) { configlval.cval = thresh_na; return NA_COMPARISON; } // // builtin ? @@ -509,13 +509,13 @@ if ( strcmp(configtext, na_str ) == 0 ) { configlval.cval = thresh_na; return int index; -if ( (! is_lhs) && is_builtin((string)configtext, index) ) { configlval.index = index; return ( BUILTIN ); } +if ( (! is_lhs) && is_builtin((string)configtext, index) ) { configlval.index = index; return BUILTIN; } // // local variable ? // -if ( is_function_def && ida.has(configtext, index) ) { configlval.index = index; return ( LOCAL_VAR ); } +if ( is_function_def && ida.has(configtext, index) ) { configlval.index = index; return LOCAL_VAR; } // // number? @@ -529,13 +529,13 @@ if ( e && (e->is_number()) && (! is_lhs) ) { set_int(configlval.nval, e->i_value()); - return ( INTEGER ); + return INTEGER; } else { set_double(configlval.nval, e->d_value()); - return ( FLOAT ); + return FLOAT; } @@ -549,7 +549,7 @@ if ( e && (! is_lhs) && (e->type() == UserFunctionType) ) { configlval.entry = e; - return ( USER_FUNCTION ); + return USER_FUNCTION; } @@ -560,7 +560,7 @@ if ( e && (! is_lhs) && (e->type() == UserFunctionType) ) { strncpy(configlval.text, configtext, sizeof(configlval.text) - 1); -return ( IDENTIFIER ); +return IDENTIFIER; } @@ -759,7 +759,7 @@ bool do_eof() { -if ( ! reading_env ) return ( true ); +if ( ! reading_env ) return true; config_delete_buffer(YY_CURRENT_BUFFER); @@ -769,7 +769,7 @@ reading_env = false; Column += 3; -return ( false ); +return false; } @@ -844,7 +844,7 @@ int do_fort_thresh() strncpy(configlval.text, configtext, sizeof(configlval.text)); -return ( FORTRAN_THRESHOLD ); +return FORTRAN_THRESHOLD; } diff --git a/src/basic/vx_config/configobjecttype_to_string.cc b/src/basic/vx_config/configobjecttype_to_string.cc index 91d34685bc..d8088d406c 100644 --- a/src/basic/vx_config/configobjecttype_to_string.cc +++ b/src/basic/vx_config/configobjecttype_to_string.cc @@ -28,7 +28,6 @@ #include "configobjecttype_to_string.h" - using namespace std; diff --git a/src/libcode/vx_color/color_scanner.ll b/src/libcode/vx_color/color_scanner.ll index 85242c3f67..3efa922f81 100644 --- a/src/libcode/vx_color/color_scanner.ll +++ b/src/libcode/vx_color/color_scanner.ll @@ -82,38 +82,38 @@ OPT_EXP {EXP}? %% -"," { ++color_file_column; return ( ',' ); } +"," { ++color_file_column; return ','; } -"{" { ++color_file_column; return ( '{' ); } -"}" { ++color_file_column; return ( '}' ); } +"{" { ++color_file_column; return '{'; } +"}" { ++color_file_column; return '}'; } -"(" { ++color_file_column; return ( '(' ); } -")" { ++color_file_column; return ( ')' ); } +"(" { ++color_file_column; return '('; } +")" { ++color_file_column; return ')'; } -"=" { ++color_file_column; return ( '=' ); } +"=" { ++color_file_column; return '='; } -"\"" { do_quoted_string(); return ( QUOTED_STRING ); } +"\"" { do_quoted_string(); return QUOTED_STRING; } -({LETTER})({LETTER}|{DIGIT})* { return ( do_id() ); } +({LETTER})({LETTER}|{DIGIT})* { return do_id(); } -("-"?){DIGITS} { do_int(); return ( INTEGER ); } +("-"?){DIGITS} { do_int(); return INTEGER; } -("-"?){DIGITS}{EXP} { do_float(); return ( FLOAT ); } +("-"?){DIGITS}{EXP} { do_float(); return FLOAT; } -("-"?)"."{DIGITS}{OPT_EXP} { do_float(); return ( FLOAT ); } +("-"?)"."{DIGITS}{OPT_EXP} { do_float(); return FLOAT; } -("-"?){DIGITS}"."{OPT_EXP} { do_float(); return ( FLOAT ); } +("-"?){DIGITS}"."{OPT_EXP} { do_float(); return FLOAT; } -("-"?){DIGITS}"."{DIGITS}{OPT_EXP} { do_float(); return ( FLOAT ); } +("-"?){DIGITS}"."{DIGITS}{OPT_EXP} { do_float(); return FLOAT; } @@ -145,10 +145,10 @@ int do_id() color_file_column += strlen(colortext); -if ( strcmp(colortext, "blend" ) == 0 ) return ( BLEND ); -if ( strcmp(colortext, "hsv" ) == 0 ) return ( HSV ); -if ( strcmp(colortext, "cmyk" ) == 0 ) return ( CMYK ); -if ( strcmp(colortext, "grayvalue") == 0 ) return ( GRAYVALUE ); +if ( strcmp(colortext, "blend" ) == 0 ) return BLEND; +if ( strcmp(colortext, "hsv" ) == 0 ) return HSV; +if ( strcmp(colortext, "cmyk" ) == 0 ) return CMYK; +if ( strcmp(colortext, "grayvalue") == 0 ) return GRAYVALUE; int index; @@ -157,13 +157,13 @@ if ( clist.has_name(colortext, index) ) { colorlval.ival = index; - return ( COLOR_NAME ); + return COLOR_NAME; } strncpy(colorlval.text, colortext, sizeof(colorlval.text) - 1); -return ( ID ); +return ID; } @@ -215,7 +215,7 @@ c2 = nextchar(); comment_depth = 1; -while ( 1 ) { +while ( true ) { if ( (c1 == EOF) || (c2 == EOF) ) break; @@ -252,7 +252,7 @@ void do_cpp_comment() int c; -while ( 1 ) { +while ( true ) { c = nextchar(); @@ -289,7 +289,7 @@ if ( c == '\n' ) { } -return ( c ); +return c; } @@ -308,7 +308,7 @@ char line[128]; n = 0; -while ( 1 ) { +while ( true ) { c = nextchar();