Skip to content

Commit 17a3590

Browse files
committed
Refactoring: modernize g_lexerStack
1 parent 5b01aaa commit 17a3590

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/doctokenizer.l

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
%{
2626

2727
#include <ctype.h>
28+
#include <stack>
2829

2930
#include <qfile.h>
3031
#include <qstring.h>
31-
#include <qstack.h>
3232
#include <qdict.h>
3333
#include <qregexp.h>
3434

@@ -72,6 +72,8 @@ static int g_autoListLevel;
7272

7373
struct DocLexerContext
7474
{
75+
DocLexerContext(TokenInfo *tk,int r,int lvl,yy_size_t pos,const char *s,YY_BUFFER_STATE bs)
76+
: token(tk), rule(r), autoListLevel(lvl), inputPos(pos), inputString(s), state(bs) {}
7577
TokenInfo *token;
7678
int rule;
7779
int autoListLevel;
@@ -80,7 +82,7 @@ struct DocLexerContext
8082
YY_BUFFER_STATE state;
8183
};
8284

83-
static QStack<DocLexerContext> g_lexerStack;
85+
static std::stack< std::unique_ptr<DocLexerContext> > g_lexerStack;
8486

8587
static int g_yyLineNr = 0;
8688

@@ -94,28 +96,23 @@ static const char *stateToString(int state);
9496

9597
void doctokenizerYYpushContext()
9698
{
97-
DocLexerContext *ctx = new DocLexerContext;
98-
ctx->rule = YY_START;
99-
ctx->autoListLevel = g_autoListLevel;
100-
ctx->token = g_token;
101-
ctx->inputPos = g_inputPos;
102-
ctx->inputString = g_inputString;
103-
ctx->state = YY_CURRENT_BUFFER;
104-
g_lexerStack.push(ctx);
99+
g_lexerStack.push(
100+
std::make_unique<DocLexerContext>(
101+
g_token,YY_START,g_autoListLevel,g_inputPos,g_inputString,YY_CURRENT_BUFFER));
105102
yy_switch_to_buffer(yy_create_buffer(doctokenizerYYin, YY_BUF_SIZE));
106103
}
107104

108105
bool doctokenizerYYpopContext()
109106
{
110-
if (g_lexerStack.isEmpty()) return FALSE;
111-
DocLexerContext *ctx = g_lexerStack.pop();
107+
if (g_lexerStack.empty()) return FALSE;
108+
const auto &ctx = g_lexerStack.top();
112109
g_autoListLevel = ctx->autoListLevel;
113110
g_inputPos = ctx->inputPos;
114111
g_inputString = ctx->inputString;
115112
yy_delete_buffer(YY_CURRENT_BUFFER);
116113
yy_switch_to_buffer(ctx->state);
117114
BEGIN(ctx->rule);
118-
delete ctx;
115+
g_lexerStack.pop();
119116
return TRUE;
120117
}
121118

0 commit comments

Comments
 (0)