Skip to content

Commit

Permalink
refactor: Use 'bool' type for many internal flags
Browse files Browse the repository at this point in the history
They were 'int' type variables that should be modernized to use 'bool'.
Also limit variable scope if they are used in only one file.
  • Loading branch information
Explorer09 authored and westes committed Apr 29, 2024
1 parent dca87d9 commit b7d76db
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/flexdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ extern struct env_bundle_t env;
* reject_really_used - same for REJECT
*/

extern int syntaxerror, eofseen;
extern bool syntaxerror, eofseen;
extern int yymore_used, reject, real_reject, continued_action, in_rule;

/* Variables used in the flex input routines:
Expand Down Expand Up @@ -568,7 +568,7 @@ extern int current_state_type;
/* True if the input rules include a rule with both variable-length head
* and trailing context, false otherwise.
*/
extern int variable_trailing_context_rules;
extern bool variable_trailing_context_rules;


/* Variables for protos:
Expand Down Expand Up @@ -945,7 +945,7 @@ extern int copysingl(int, int);
extern void dumpnfa(int);

/* Finish up the processing for a rule. */
extern void finish_rule(int, int, int, int, int);
extern void finish_rule(int, bool, int, int, int);

/* Connect two machines together. */
extern int link_machines(int, int);
Expand Down
7 changes: 4 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void readin(void);
void set_up_initial_allocations(void);

/* these globals are all defined and commented in flexdef.h */
int syntaxerror, eofseen;
bool syntaxerror, eofseen;
int yymore_used, reject, real_reject, continued_action, in_rule;
int datapos, dataline, linenum;
FILE *skelfile = NULL;
Expand All @@ -65,7 +65,7 @@ int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
int *accptnum, *assoc_rule, *state_type;
int *rule_type, *rule_linenum, *rule_useful;
int current_state_type;
int variable_trailing_context_rules;
bool variable_trailing_context_rules;
int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs,
Expand Down Expand Up @@ -1166,7 +1166,8 @@ void flexinit (int argc, char **argv)
numas = numsnpairs = tmpuses = 0;
numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst =
0;
numuniq = numdup = hshsave = eofseen = datapos = dataline = 0;
numuniq = numdup = hshsave = datapos = dataline = 0;
eofseen = false;
num_backing_up = onesp = numprots = 0;
variable_trailing_context_rules = bol_needed = false;

Expand Down
2 changes: 1 addition & 1 deletion src/nfa.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ int dupmachine (int mach)
* context has variable length.
*/

void finish_rule (int mach, int variable_trail_rule, int headcnt, int trailcnt,
void finish_rule (int mach, bool variable_trail_rule, int headcnt, int trailcnt,
int pcont_act)
{
char action_text[MAXLINE];
Expand Down
4 changes: 3 additions & 1 deletion src/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
#include "tables.h"

int pat, scnum, eps, headcnt, trailcnt, lastchar, i, rulelen;
int trlcontxt, xcluflg, currccl, cclsorted, varlength, variable_trail_rule;
static int currccl;
bool trlcontxt;
static bool xcluflg, cclsorted, varlength, variable_trail_rule;

int *scon_stk;
int scon_stk_ptr;
Expand Down
12 changes: 6 additions & 6 deletions src/scan.l
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include "parse.h"
extern bool tablesverify, tablesext;
extern int trlcontxt; /* Set in parse.y for each rule. */
extern bool trlcontxt; /* Set in parse.y for each rule. */
extern const char *escaped_qstart, *escaped_qend;

#define M4QSTART "[""["
Expand Down Expand Up @@ -155,10 +155,10 @@ void context_member(char *, const char *);
%}
%%
static int bracelevel, didadef, indented_code;
static int doing_rule_action = false;
static int option_sense;
static bool doing_rule_action = false;
static bool option_sense;

int doing_codeblock = false;
static bool doing_codeblock = false;
int brace_depth=0, brace_start_line=0;
char nmdef[MAXLINE];

Expand Down Expand Up @@ -395,7 +395,7 @@ void context_member(char *, const char *);
main {
ctrl.do_main = option_sense;
/* Override yywrap */
if( option_sense == true )
if (option_sense)
ctrl.do_yywrap = false;
}
meta-ecs ctrl.usemecs = option_sense;
Expand Down Expand Up @@ -471,7 +471,7 @@ void context_member(char *, const char *);
tables-file return TOK_TABLES_FILE;
tables-verify {
tablesverify = option_sense;
if(!tablesext && option_sense)
if (!tablesext && option_sense)
tablesext = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/yylex.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int yylex (void)
toktype = flexscan ();
}
if (toktype == EOF || toktype == 0) {
eofseen = 1;
eofseen = true;

if (sectnum == 1) {
synerr (_("premature EOF"));
Expand Down

0 comments on commit b7d76db

Please sign in to comment.