Skip to content

Commit 61a0e5e

Browse files
committed
constexpr + noexcept in gpre
1 parent c4df11b commit 61a0e5e

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

src/gpre/gpre.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@
7676
// Globals
7777
GpreGlobals gpreGlob;
7878

79-
const char* const SCRATCH = "fb_query_";
79+
constexpr const char* SCRATCH = "fb_query_";
8080

81-
const char* const FOPEN_READ_TYPE = "r";
82-
const char* const FOPEN_WRITE_TYPE = "w";
81+
constexpr const char* FOPEN_READ_TYPE = "r";
82+
constexpr const char* FOPEN_WRITE_TYPE = "w";
8383

84-
static bool all_digits(const char*);
84+
static bool all_digits(const char*) noexcept;
8585
static bool arg_is_string(SLONG, TEXT**, const TEXT*);
86-
static SSHORT compare_ASCII7z(const char*, const char*);
86+
static SSHORT compare_ASCII7z(const char*, const char*) noexcept;
8787
static SLONG compile_module(SLONG, const TEXT*);
88-
static bool file_rename(TEXT*, const TEXT*, const TEXT*);
88+
static bool file_rename(TEXT*, const TEXT*, const TEXT*) noexcept;
8989
#ifdef GPRE_FORTRAN
9090
static void finish_based(act*);
9191
#endif
@@ -101,8 +101,7 @@ static void print_switches();
101101
static void remember_label(const TEXT*);
102102
#endif
103103

104-
//static FILE* reposition_file(FILE *, SLONG);
105-
static void return_char(SSHORT);
104+
static void return_char(SSHORT) noexcept;
106105
static SSHORT skip_white();
107106

108107
// Program wide globals
@@ -121,22 +120,22 @@ static act* global_last_action;
121120
static act* global_first_action;
122121
static UCHAR classes_array[256];
123122

124-
inline UCHAR get_classes(int idx)
123+
inline UCHAR get_classes(int idx) noexcept
125124
{
126125
return classes_array[(UCHAR) idx];
127126
}
128127

129-
inline UCHAR get_classes(UCHAR idx)
128+
inline UCHAR get_classes(UCHAR idx) noexcept
130129
{
131130
return classes_array[idx];
132131
}
133132

134-
inline void set_classes(int idx, UCHAR v)
133+
inline void set_classes(int idx, UCHAR v) noexcept
135134
{
136135
classes_array[(UCHAR) idx] = v;
137136
}
138137

139-
inline void set_classes(UCHAR idx, UCHAR v)
138+
inline void set_classes(UCHAR idx, UCHAR v) noexcept
140139
{
141140
classes_array[idx] = v;
142141
}
@@ -167,14 +166,14 @@ static SLONG traced_position = 0;
167166
//___________________________________________________________________
168167
// Test if input language is cpp based.
169168
//
170-
bool isLangCpp(lang_t lang)
169+
bool isLangCpp(lang_t lang) noexcept
171170
{
172171
return (lang == lang_cxx || lang == lang_internal);
173172
}
174173

175174
// Test if input language is an ANSI-85 Cobol variant
176175
#ifdef GPRE_COBOL
177-
bool isAnsiCobol(cob_t dialect)
176+
bool isAnsiCobol(cob_t dialect) noexcept
178177
{
179178
return (dialect == cob_ansi) || (dialect == cob_rmc);
180179
}
@@ -934,7 +933,7 @@ int main(int argc, char* argv[])
934933
// Mark end of a text description.
935934
//
936935

937-
void CPR_end_text(gpre_txt* text)
936+
void CPR_end_text(gpre_txt* text) noexcept
938937
{
939938
text->txt_length = (USHORT) (gpreGlob.token_global.tok_position - text->txt_position - 1);
940939
}
@@ -1236,7 +1235,7 @@ tok* CPR_token()
12361235
// Return true if the string consists entirely of digits.
12371236
//
12381237

1239-
static bool all_digits(const char* str1)
1238+
static bool all_digits(const char* str1) noexcept
12401239
{
12411240
for (; *str1; str1++)
12421241
{
@@ -1279,7 +1278,7 @@ static bool arg_is_string(SLONG argc, TEXT** argvstring, const TEXT* errstring)
12791278
// (positive) if str1 > str2
12801279
//
12811280

1282-
static SSHORT compare_ASCII7z(const char* str1, const char* str2)
1281+
static SSHORT compare_ASCII7z(const char* str1, const char* str2) noexcept
12831282
{
12841283

12851284
for (; *str1; str1++, str2++)
@@ -1371,7 +1370,7 @@ static SLONG compile_module( SLONG start_position, const TEXT* base_directory)
13711370
// new extension is given, use it.
13721371
//
13731372

1374-
static bool file_rename(TEXT* file_nameL, const TEXT* extension, const TEXT* new_extension)
1373+
static bool file_rename(TEXT* file_nameL, const TEXT* extension, const TEXT* new_extension) noexcept
13751374
{
13761375
TEXT* p = file_nameL;
13771376

@@ -2470,9 +2469,9 @@ static void pass2( SLONG start_position)
24702469
#endif
24712470

24722471
// Let's prepare for worst case: a lot of small dirs, many "\" to duplicate.
2473-
char backlash_fixed_file_name[MAXPATHLEN + MAXPATHLEN];
2472+
char backslash_fixed_file_name[MAXPATHLEN + MAXPATHLEN]{ 0 };
24742473
{ // scope
2475-
char* p = backlash_fixed_file_name;
2474+
char* p = backslash_fixed_file_name;
24762475
for (const char* q = file_name; *q;)
24772476
{
24782477
if ((*p++ = *q++) == '\\')
@@ -2482,14 +2481,14 @@ static void pass2( SLONG start_position)
24822481
} // scope
24832482

24842483
//if (sw_lines)
2485-
// fprintf (gpreGlob.out_file, "#line 1 \"%s\"\n", backlash_fixed_file_name);
2484+
// fprintf (gpreGlob.out_file, "#line 1 \"%s\"\n", backslash_fixed_file_name);
24862485

24872486
SLONG line = 0;
24882487
bool line_pending = sw_lines;
24892488
SLONG current = 1 + start_position;
24902489
SLONG column = 0;
24912490

2492-
SSHORT comment_start_len = static_cast<SSHORT>(strlen(comment_start));
2491+
const SSHORT comment_start_len = static_cast<SSHORT>(strlen(comment_start));
24932492
#if defined(GPRE_COBOL)
24942493
SSHORT to_skip = 0;
24952494
#endif
@@ -2515,9 +2514,9 @@ static void pass2( SLONG start_position)
25152514
if (line_pending)
25162515
{
25172516
if (line == 1)
2518-
fprintf(gpreGlob.out_file, "#line %" SLONGFORMAT" \"%s\"\n", line, backlash_fixed_file_name);
2517+
fprintf(gpreGlob.out_file, "#line %" SLONGFORMAT" \"%s\"\n", line, backslash_fixed_file_name);
25192518
else
2520-
fprintf(gpreGlob.out_file, "\n#line %" SLONGFORMAT" \"%s\"", line, backlash_fixed_file_name);
2519+
fprintf(gpreGlob.out_file, "\n#line %" SLONGFORMAT" \"%s\"", line, backslash_fixed_file_name);
25212520

25222521
line_pending = false;
25232522
}
@@ -2655,7 +2654,7 @@ static void pass2( SLONG start_position)
26552654

26562655
if (!line && line_pending)
26572656
{
2658-
fprintf(gpreGlob.out_file, "#line 1 \"%s\"\n", backlash_fixed_file_name);
2657+
fprintf(gpreGlob.out_file, "#line 1 \"%s\"\n", backslash_fixed_file_name);
26592658
line_pending = false;
26602659
}
26612660

@@ -2664,7 +2663,7 @@ static void pass2( SLONG start_position)
26642663
{
26652664
if (c == '\n' && line_pending)
26662665
{
2667-
fprintf(gpreGlob.out_file, "\n#line %" SLONGFORMAT" \"%s\"", line + 1, backlash_fixed_file_name);
2666+
fprintf(gpreGlob.out_file, "\n#line %" SLONGFORMAT" \"%s\"", line + 1, backslash_fixed_file_name);
26682667
line_pending = false;
26692668
}
26702669
if (c == EOF)
@@ -2738,7 +2737,7 @@ static void remember_label(const TEXT* label_string)
27382737
// Return a character to the input stream.
27392738
//
27402739

2741-
static void return_char( SSHORT c)
2740+
static void return_char(SSHORT c) noexcept
27422741
{
27432742

27442743
--position;

src/gpre/gpre.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ enum cob_t
132132
// and lang_internal.
133133
//
134134

135-
bool isLangCpp(lang_t lang);
135+
bool isLangCpp(lang_t lang) noexcept;
136136

137137
#ifdef GPRE_COBOL
138-
bool isAnsiCobol(cob_t dialect);
138+
bool isAnsiCobol(cob_t dialect) noexcept;
139139
#endif
140140

141141

src/gpre/gpre_proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
[[noreturn]] void CPR_assert(const TEXT*, int);
3232
#endif
3333
[[noreturn]] void CPR_bugcheck(const TEXT*);
34-
void CPR_end_text(gpre_txt*);
34+
void CPR_end_text(gpre_txt*) noexcept;
3535
int CPR_error(const TEXT*);
3636
[[noreturn]] void CPR_exit(int);
3737
void CPR_warn(const TEXT*);

0 commit comments

Comments
 (0)