25
25
%{
26
26
27
27
#include < ctype.h>
28
+ #include < stack>
28
29
29
30
#include < qfile.h>
30
31
#include < qstring.h>
31
- #include < qstack.h>
32
32
#include < qdict.h>
33
33
#include < qregexp.h>
34
34
@@ -72,6 +72,8 @@ static int g_autoListLevel;
72
72
73
73
struct DocLexerContext
74
74
{
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) {}
75
77
TokenInfo *token;
76
78
int rule;
77
79
int autoListLevel;
@@ -80,7 +82,7 @@ struct DocLexerContext
80
82
YY_BUFFER_STATE state;
81
83
};
82
84
83
- static QStack< DocLexerContext> g_lexerStack;
85
+ static std::stack< std::unique_ptr< DocLexerContext> > g_lexerStack;
84
86
85
87
static int g_yyLineNr = 0 ;
86
88
@@ -94,28 +96,23 @@ static const char *stateToString(int state);
94
96
95
97
void doctokenizerYYpushContext ()
96
98
{
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));
105
102
yy_switch_to_buffer (yy_create_buffer (doctokenizerYYin, YY_BUF_SIZE));
106
103
}
107
104
108
105
bool doctokenizerYYpopContext ()
109
106
{
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 ();
112
109
g_autoListLevel = ctx->autoListLevel ;
113
110
g_inputPos = ctx->inputPos ;
114
111
g_inputString = ctx->inputString ;
115
112
yy_delete_buffer (YY_CURRENT_BUFFER);
116
113
yy_switch_to_buffer (ctx->state );
117
114
BEGIN (ctx->rule );
118
- delete ctx ;
115
+ g_lexerStack. pop () ;
119
116
return TRUE ;
120
117
}
121
118
0 commit comments