Skip to content

Commit

Permalink
JSIL front-end: make parser and lexer reentrant
Browse files Browse the repository at this point in the history
This avoids hand-crafted init functions with possibly insufficient
guards against reentrant use and also removes (file-local) global
variables.
  • Loading branch information
tautschnig committed Jan 9, 2024
1 parent 09dca35 commit 800522a
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 155 deletions.
13 changes: 13 additions & 0 deletions src/jsil/jsil_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ Author: Michael Tautschnig, [email protected]
/// Jsil Language

#include "jsil_parser.h"

int yyjsillex_init_extra(jsil_parsert *, void **);
int yyjsillex_destroy(void *);
int yyjsilparse(jsil_parsert &, void *);

bool jsil_parsert::parse()

Check warning on line 18 in src/jsil/jsil_parser.cpp

View check run for this annotation

Codecov / codecov/patch

src/jsil/jsil_parser.cpp#L18

Added line #L18 was not covered by tests
{
void *scanner;
yyjsillex_init_extra(this, &scanner);
bool parse_fail = yyjsilparse(*this, scanner) != 0;
yyjsillex_destroy(scanner);
return parse_fail;

Check warning on line 24 in src/jsil/jsil_parser.cpp

View check run for this annotation

Codecov / codecov/patch

src/jsil/jsil_parser.cpp#L20-L24

Added lines #L20 - L24 were not covered by tests
}
12 changes: 2 additions & 10 deletions src/jsil/jsil_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ Author: Michael Tautschnig, [email protected]

#include "jsil_parse_tree.h"

class jsil_parsert;
int yyjsilparse(jsil_parsert &);
void jsil_scanner_init(jsil_parsert &);

class jsil_parsert:public parsert
{
public:
Expand All @@ -30,13 +26,9 @@ class jsil_parsert:public parsert

jsil_parse_treet parse_tree;

virtual bool parse() override
{
jsil_scanner_init(*this);
return yyjsilparse(*this) != 0;
}
bool parse() override;

virtual void clear() override
void clear() override

Check warning on line 31 in src/jsil/jsil_parser.h

View check run for this annotation

Codecov / codecov/patch

src/jsil/jsil_parser.h#L31

Added line #L31 was not covered by tests
{
parsert::clear();
parse_tree.clear();
Expand Down
28 changes: 14 additions & 14 deletions src/jsil/parser.y
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
%{

// #define YYDEBUG 1
#define PARSER (*jsil_parser)
#define PARSER jsil_parser

#include "jsil_parser.h"

int yyjsillex();
extern char *yyjsiltext;
int yyjsillex(unsigned *, void *);
char *yyjsilget_text(void *);

static jsil_parsert *jsil_parser;
int yyjsilparse(void);
int yyjsilparse(jsil_parsert &_jsil_parser)
int yyjsilerror(

Check warning on line 11 in src/jsil/parser.y

View check run for this annotation

Codecov / codecov/patch

src/jsil/parser.y#L11

Added line #L11 was not covered by tests
jsil_parsert &jsil_parser,
void *scanner,
const std::string &error)
{
jsil_parser = &_jsil_parser;
return yyjsilparse();
}

int yyjsilerror(const std::string &error)
{
jsil_parser->parse_error(error, yyjsiltext);
jsil_parser.parse_error(error, yyjsilget_text(scanner));

Check warning on line 16 in src/jsil/parser.y

View check run for this annotation

Codecov / codecov/patch

src/jsil/parser.y#L16

Added line #L16 was not covered by tests
return 0;
}

Expand All @@ -43,9 +38,14 @@ int yyjsilerror(const std::string &error)
// unreachable code
#pragma warning(disable:4702)
#endif
%}

%define api.pure full
%parse-param {jsil_parsert &jsil_parser}
%parse-param {void *scanner}
%lex-param {void *scanner}

/*** token declaration **************************************************/
%}

/*** special scanner reports ***/

Expand Down
Loading

0 comments on commit 800522a

Please sign in to comment.