From 62dabb22779acb023b74329b6ab515f187cd4ff3 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sat, 5 Sep 2020 12:16:15 +0200 Subject: Refactoring: replaced QStack by std::stack for scopeStack --- src/code.l | 68 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/code.l b/src/code.l index 267863b..0b3b2d7 100644 --- a/src/code.l +++ b/src/code.l @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -62,9 +63,9 @@ #define YY_NO_UNISTD_H 1 -#define CLASSBLOCK (int *)4 -#define SCOPEBLOCK (int *)8 -#define INNERBLOCK (int *)12 +#define CLASSBLOCK 1 +#define SCOPEBLOCK 2 +#define INNERBLOCK 3 #define USE_STATE2STRING 0 @@ -248,8 +249,8 @@ struct codeYY_state QCString args; QCString classScope; QCString realScope; - QStack scopeStack; //!< 1 if bracket starts a scope, - // 2 for internal blocks + std::stack scopeStack; //!< 1 if bracket starts a scope, + // 2 for internal blocks int anchorCount = 0; FileDef * sourceFileDef = 0; bool lineNumbers = FALSE; @@ -286,7 +287,7 @@ struct codeYY_state bool lexInit = FALSE; - QStack classScopeLengthStack; + std::stack classScopeLengthStack; int prefixed_with_this_keyword = FALSE; const Definition *searchCtx = 0; @@ -694,12 +695,16 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER} yyextra->type.resize(0); yyextra->name.resize(0); - int *scope = yyextra->scopeStack.pop(); - DBG_CTX((stderr,"** scope stack pop SCOPEBLOCK=%d\n",scope==SCOPEBLOCK)); - if (scope==SCOPEBLOCK || scope==CLASSBLOCK) - { - popScope(yyscanner); - } + if (!yyextra->scopeStack.empty()) + { + int scope = yyextra->scopeStack.top(); + yyextra->scopeStack.pop(); + DBG_CTX((stderr,"** scope stack pop SCOPEBLOCK=%d\n",scope==SCOPEBLOCK)); + if (scope==SCOPEBLOCK || scope==CLASSBLOCK) + { + popScope(yyscanner); + } + } yyextra->code->codify(yytext); @@ -730,13 +735,17 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER} { yyextra->theVarContext.popScope(); - int *scope = yyextra->scopeStack.pop(); - DBG_CTX((stderr,"** scope stack pop SCOPEBLOCK=%d\n",scope==SCOPEBLOCK)); - if (scope==SCOPEBLOCK || scope==CLASSBLOCK) - { - popScope(yyscanner); - } - yyextra->insideBody=FALSE; + if (!yyextra->scopeStack.empty()) + { + int scope = yyextra->scopeStack.top(); + yyextra->scopeStack.pop(); + DBG_CTX((stderr,"** scope stack pop SCOPEBLOCK=%d\n",scope==SCOPEBLOCK)); + if (scope==SCOPEBLOCK || scope==CLASSBLOCK) + { + popScope(yyscanner); + } + } + yyextra->insideBody=FALSE; } startFontClass(yyscanner,"keyword"); @@ -2428,7 +2437,7 @@ const ClassDef *VariableContext::dummyContext = (ClassDef*)0x8; static void pushScope(yyscan_t yyscanner,const char *s) { struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; - yyextra->classScopeLengthStack.push(new int(yyextra->classScope.length())); + yyextra->classScopeLengthStack.push(int(yyextra->classScope.length())); if (yyextra->classScope.isEmpty() || leftScopeMatch(s,yyextra->classScope)) { yyextra->classScope = s; @@ -2446,11 +2455,11 @@ static void pushScope(yyscan_t yyscanner,const char *s) static void popScope(yyscan_t yyscanner) { struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; - if (!yyextra->classScopeLengthStack.isEmpty()) + if (!yyextra->classScopeLengthStack.empty()) { - int *pLength = yyextra->classScopeLengthStack.pop(); - yyextra->classScope.truncate(*pLength); - delete pLength; + int length = yyextra->classScopeLengthStack.top(); + yyextra->classScopeLengthStack.pop(); + yyextra->classScope.truncate(length); } else { @@ -2498,7 +2507,7 @@ static void setClassScope(yyscan_t yyscanner,const QCString &name) // remove template from scope n=n.left(ts)+n.right(n.length()-te-1); } - while (!yyextra->classScopeLengthStack.isEmpty()) + while (!yyextra->classScopeLengthStack.empty()) { popScope(yyscanner); } @@ -2817,7 +2826,7 @@ static MemberDef *setCallContextForVar(yyscan_t yyscanner,const QCString &name) if (md) { DBG_CTX((stderr,"Found member %s\n",md->name().data())); - if (yyextra->scopeStack.top()!=CLASSBLOCK) + if (yyextra->scopeStack.empty() || yyextra->scopeStack.top()!=CLASSBLOCK) { DBG_CTX((stderr,"class member '%s' mcd=%s\n",name.data(),mcd->name().data())); yyextra->theCallContext.setScope(stripClassName(yyscanner,md->typeString(),md->getOuterScope())); @@ -3967,8 +3976,6 @@ CCodeParser::CCodeParser() : p(std::make_unique()) CCodeParser::~CCodeParser() { - struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner; - yyextra->classScopeLengthStack.clear(); codeYYlex_destroy(p->yyscanner); } @@ -3978,8 +3985,7 @@ void CCodeParser::resetCodeParserState() //printf("***CodeParser::reset()\n"); yyextra->forceTagReference.resize(0); yyextra->theVarContext.clear(); - yyextra->classScopeLengthStack.setAutoDelete(TRUE); - yyextra->classScopeLengthStack.clear(); + yyextra->classScopeLengthStack = {}; yyextra->codeClassMap.clear(); yyextra->curClassBases.clear(); yyextra->anchorCount = 0; @@ -4026,7 +4032,7 @@ void CCodeParser::parseCode(CodeOutputInterface &od,const char *className,const yyextra->sharpCount = 0; yyextra->insideTemplate = FALSE; yyextra->theCallContext.clear(); - yyextra->scopeStack.clear(); + yyextra->scopeStack = {}; yyextra->classScope = className; //printf("parseCCode %s\n",className); yyextra->exampleBlock = exBlock; -- cgit v0.12