From f1a7068e113e4f028f772a9978eabfa539f32e1d Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sat, 25 Apr 2020 21:19:47 +0200 Subject: Refactor: improve encapsulation for ArgumentList --- src/arguments.h | 80 ++++++++++++++++++++++++++++++++++++++++-------------- src/context.cpp | 12 ++++---- src/defargs.l | 18 ++++++------ src/doxygen.cpp | 10 +++---- src/memberdef.cpp | 18 ++++++------ src/perlmodgen.cpp | 4 +-- src/pyscanner.l | 2 +- src/scanner.l | 34 ++++++++++------------- src/util.cpp | 18 ++++++------ src/xmlgen.cpp | 8 +++--- 10 files changed, 120 insertions(+), 84 deletions(-) diff --git a/src/arguments.h b/src/arguments.h index 3464def..2da6cc9 100644 --- a/src/arguments.h +++ b/src/arguments.h @@ -3,8 +3,8 @@ * Copyright (C) 1997-2015 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -50,48 +50,88 @@ enum RefQualifierType RefQualifierRValue }; -/*! \brief This class represents an function or template argument list. +/*! \brief This class represents an function or template argument list. * * This class also stores some information about member that is typically - * put after the argument list, such as whether the member is const, + * put after the argument list, such as whether the member is const, * volatile or pure virtual. */ -class ArgumentList : public std::vector +class ArgumentList { public: + using Vec = std::vector; + using iterator = typename Vec::iterator; + using const_iterator = typename Vec::const_iterator; + /*! Does any argument of this list have documentation? */ bool hasDocumentation() const; /*! Does this list have zero or more parameters */ bool hasParameters() const { - return !empty() || noParameters; + return !empty() || m_noParameters; } void reset() { clear(); - constSpecifier = FALSE; - volatileSpecifier = FALSE; - pureSpecifier = FALSE; - trailingReturnType.resize(0); - isDeleted = FALSE; - refQualifier = RefQualifierNone; - noParameters = FALSE; + m_constSpecifier = FALSE; + m_volatileSpecifier = FALSE; + m_pureSpecifier = FALSE; + m_trailingReturnType.resize(0); + m_isDeleted = FALSE; + m_refQualifier = RefQualifierNone; + m_noParameters = FALSE; } + // make vector accessible + iterator begin() { return m_args.begin(); } + iterator end() { return m_args.end(); } + const_iterator begin() const { return m_args.cbegin(); } + const_iterator end() const { return m_args.cend(); } + bool empty() const { return m_args.empty(); } + int size() const { return m_args.size(); } + void clear() { m_args.clear(); } + void push_back(const Argument &a) { m_args.push_back(a); } + Argument &back() { return m_args.back(); } + const Argument &back() const { return m_args.back(); } + Argument &front() { return m_args.front(); } + const Argument &front() const { return m_args.front(); } + Argument &at(size_t i) { return m_args.at(i); } + const Argument &at(size_t i) const { return m_args.at(i); } + + // getters for list wide attributes + bool constSpecifier() const { return m_constSpecifier; } + bool volatileSpecifier() const { return m_volatileSpecifier; } + bool pureSpecifier() const { return m_pureSpecifier; } + QCString trailingReturnType() const { return m_trailingReturnType; } + bool isDeleted() const { return m_isDeleted; } + RefQualifierType refQualifier() const { return m_refQualifier; } + bool noParameters() const { return m_noParameters; } + + void setConstSpecifier(bool b) { m_constSpecifier = b; } + void setVolatileSpecifier(bool b) { m_volatileSpecifier = b; } + void setPureSpecifier(bool b) { m_pureSpecifier = b; } + void setTrailingReturnType(const QCString &s) { m_trailingReturnType = s; } + void setIsDeleted(bool b) { m_isDeleted = b; } + void setRefQualifier(RefQualifierType t) { m_refQualifier = t; } + void setNoParameters(bool b) { m_noParameters = b; } + + private: + std::vector m_args; /*! Does the member modify the state of the class? */ - bool constSpecifier = FALSE; + bool m_constSpecifier = FALSE; /*! Is the member volatile? */ - bool volatileSpecifier = FALSE; + bool m_volatileSpecifier = FALSE; /*! Is this a pure virtual member? */ - bool pureSpecifier = FALSE; + bool m_pureSpecifier = FALSE; /*! C++11 style Trailing return type? */ - QCString trailingReturnType; + QCString m_trailingReturnType; /*! method with =delete */ - bool isDeleted = FALSE; + bool m_isDeleted = FALSE; /*! C++11 ref qualifier */ - RefQualifierType refQualifier = RefQualifierNone; + RefQualifierType m_refQualifier = RefQualifierNone; /*! is it an explicit empty list */ - bool noParameters = FALSE; + bool m_noParameters = FALSE; + }; #endif diff --git a/src/context.cpp b/src/context.cpp index 0577531..53b63f9 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -4670,27 +4670,27 @@ class MemberContext::Private : public DefinitionContext } TemplateVariant hasConstQualifier() const { - return getDefArgList().constSpecifier; + return getDefArgList().constSpecifier(); } TemplateVariant hasVolatileQualifier() const { - return getDefArgList().volatileSpecifier; + return getDefArgList().volatileSpecifier(); } TemplateVariant hasRefQualifierLValue() const { - return getDefArgList().refQualifier==RefQualifierLValue; + return getDefArgList().refQualifier()==RefQualifierLValue; } TemplateVariant hasRefQualifierRValue() const { - return getDefArgList().refQualifier==RefQualifierRValue; + return getDefArgList().refQualifier()==RefQualifierRValue; } TemplateVariant trailingReturnType() const { const ArgumentList &al = getDefArgList(); - if (!al.trailingReturnType.isEmpty()) + if (!al.trailingReturnType().isEmpty()) { return createLinkedText(m_memberDef,relPathAsString(), - al.trailingReturnType); + al.trailingReturnType()); } else { diff --git a/src/defargs.l b/src/defargs.l index 9c58508..6ecc7ff 100644 --- a/src/defargs.l +++ b/src/defargs.l @@ -506,23 +506,23 @@ RAWEND ")"[^ \t\(\)\\]{0,16}\" yyextra->curTypeConstraint+=' '; } "const" { - yyextra->argList->constSpecifier=TRUE; + yyextra->argList->setConstSpecifier(TRUE); } "volatile" { - yyextra->argList->volatileSpecifier=TRUE; + yyextra->argList->setVolatileSpecifier(TRUE); } "&" { - yyextra->argList->refQualifier=RefQualifierLValue; + yyextra->argList->setRefQualifier(RefQualifierLValue); } "&&" { - yyextra->argList->refQualifier=RefQualifierRValue; + yyextra->argList->setRefQualifier(RefQualifierRValue); } "="{B}*"0" { - yyextra->argList->pureSpecifier=TRUE; + yyextra->argList->setPureSpecifier(TRUE); BEGIN(FuncQual); } "->" { // C++11 trailing return type - yyextra->argList->trailingReturnType=" -> "; + yyextra->argList->setTrailingReturnType(" -> "); BEGIN(TrailingReturn); } {B}/("final"|"override"){B}* { @@ -530,10 +530,10 @@ RAWEND ")"[^ \t\(\)\\]{0,16}\" BEGIN(FuncQual); } . { - yyextra->argList->trailingReturnType+=yytext; + yyextra->argList->setTrailingReturnType(yyextra->argList->trailingReturnType()+yytext); } \n { - yyextra->argList->trailingReturnType+=yytext; + yyextra->argList->setTrailingReturnType(yyextra->argList->trailingReturnType()+yytext); } ")"{B}*"["[^]]*"]" { // for functions returning a pointer to an array, // i.e. ")[]" in "int (*f(int))[4]" with argsString="(int))[4]" @@ -787,7 +787,7 @@ std::unique_ptr stringToArgumentList(SrcLangExt lang, const char * defargsYYlex(yyscanner); if (yyextra->argList->empty()) { - yyextra->argList->noParameters = TRUE; + yyextra->argList->setNoParameters(TRUE); } if (extraTypeChars) *extraTypeChars=yyextra->extraTypeChars; //printf("stringToArgumentList(%s) result=%s\n",argsString,argListToString(al).data()); diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 559e745..f94b4e2 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -5383,12 +5383,12 @@ static void substituteTemplatesInArgList( ++dstIt; } } - dst.constSpecifier = src.constSpecifier; - dst.volatileSpecifier = src.volatileSpecifier; - dst.pureSpecifier = src.pureSpecifier; - dst.trailingReturnType = substituteTemplatesInString( + dst.setConstSpecifier(src.constSpecifier()); + dst.setVolatileSpecifier(src.volatileSpecifier()); + dst.setPureSpecifier(src.pureSpecifier()); + dst.setTrailingReturnType(substituteTemplatesInString( srcTempArgLists,dstTempArgLists, - src.trailingReturnType); + src.trailingReturnType())); //printf("substituteTemplatesInArgList: replacing %s with %s\n", // argListToString(src).data(),argListToString(dst).data() // ); diff --git a/src/memberdef.cpp b/src/memberdef.cpp index 7672599..c400412 100644 --- a/src/memberdef.cpp +++ b/src/memberdef.cpp @@ -1148,29 +1148,29 @@ static bool writeDefArgumentList(OutputList &ol,const Definition *scope,const Me { ol.docify(md->extraTypeChars()); } - if (defArgList.constSpecifier) + if (defArgList.constSpecifier()) { ol.docify(" const"); } - if (defArgList.volatileSpecifier) + if (defArgList.volatileSpecifier()) { ol.docify(" volatile"); } - if (defArgList.refQualifier==RefQualifierLValue) + if (defArgList.refQualifier()==RefQualifierLValue) { ol.docify(" &"); } - else if (defArgList.refQualifier==RefQualifierRValue) + else if (defArgList.refQualifier()==RefQualifierRValue) { ol.docify(" &&"); } - if (!defArgList.trailingReturnType.isEmpty()) + if (!defArgList.trailingReturnType().isEmpty()) { linkifyText(TextGeneratorOLImpl(ol), // out scope, // scope md->getBodyDef(), // fileScope md, // self - defArgList.trailingReturnType, // text + defArgList.trailingReturnType(), // text FALSE // autoBreak ); @@ -4193,7 +4193,7 @@ bool MemberDefImpl::isDocumentedFriendClass() const bool MemberDefImpl::isDeleted() const { - return m_impl->defArgList.isDeleted; + return m_impl->defArgList.isDeleted(); } bool MemberDefImpl::hasDocumentation() const @@ -4341,8 +4341,8 @@ MemberDef *MemberDefImpl::createTemplateInstanceMember( { arg.type = substituteTemplateArgumentsInString(arg.type,formalArgs,actualArgs); } - actualArgList->trailingReturnType = - substituteTemplateArgumentsInString(actualArgList->trailingReturnType,formalArgs,actualArgs); + actualArgList->setTrailingReturnType( + substituteTemplateArgumentsInString(actualArgList->trailingReturnType(),formalArgs,actualArgs)); } else { diff --git a/src/perlmodgen.cpp b/src/perlmodgen.cpp index eb566ff..3c44b69 100644 --- a/src/perlmodgen.cpp +++ b/src/perlmodgen.cpp @@ -1615,8 +1615,8 @@ void PerlModGenerator::generatePerlModForMember(const MemberDef *md,const Defini const ArgumentList &al = md->argumentList(); if (isFunc) //function { - m_output.addFieldBoolean("const", al.constSpecifier) - .addFieldBoolean("volatile", al.volatileSpecifier); + m_output.addFieldBoolean("const", al.constSpecifier()) + .addFieldBoolean("volatile", al.volatileSpecifier()); m_output.openList("parameters"); const ArgumentList &declAl = md->declArgumentList(); diff --git a/src/pyscanner.l b/src/pyscanner.l index 15e1040..f2a315c 100644 --- a/src/pyscanner.l +++ b/src/pyscanner.l @@ -666,7 +666,7 @@ STARTDOCSYMS "##" ")" { // end of parameter list if (yyextra->current->argList.empty()) { - yyextra->current->argList.noParameters=TRUE; + yyextra->current->argList.setNoParameters(TRUE); } yyextra->current->args = argListToString(yyextra->current->argList); yyextra->funcParamsEnd = TRUE; diff --git a/src/scanner.l b/src/scanner.l index e25d268..dff6f54 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -38,7 +38,6 @@ #include #include -#include #include #include @@ -161,7 +160,6 @@ struct scannerYY_state QGString *pCopyHereDocGString = 0; QGString *pCopyRawGString = 0; QGString *pSkipVerbString = 0; - QStack autoGroupStack; bool insideFormula = false; bool insideTryBlock = false; @@ -852,7 +850,7 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) } if (yyextra->current->argList.empty()) // method without parameters { - yyextra->current->argList.noParameters = TRUE; + yyextra->current->argList.setNoParameters(TRUE); } yyextra->current->args = argListToString(yyextra->current->argList); //printf("argList=%s\n",yyextra->current->args.data()); @@ -870,7 +868,7 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) } if (yyextra->current->argList.empty()) // method without parameters { - yyextra->current->argList.noParameters = TRUE; + yyextra->current->argList.setNoParameters(TRUE); } yyextra->current->args = argListToString(yyextra->current->argList); unput('{'); @@ -4532,12 +4530,12 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) {BN}*"const"{BN}* { // const member function lineCount(yyscanner) ; yyextra->current->args += " const "; - yyextra->current->argList.constSpecifier=TRUE; + yyextra->current->argList.setConstSpecifier(TRUE); } {BN}*"volatile"{BN}* { // volatile member function lineCount(yyscanner) ; yyextra->current->args += " volatile "; - yyextra->current->argList.volatileSpecifier=TRUE; + yyextra->current->argList.setVolatileSpecifier(TRUE); } {BN}*"noexcept"{BN}* { // noexcept qualifier lineCount(yyscanner) ; @@ -4555,25 +4553,25 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) } {BN}*"&" { yyextra->current->args += " &"; - yyextra->current->argList.refQualifier=RefQualifierLValue; + yyextra->current->argList.setRefQualifier(RefQualifierLValue); } {BN}*"&&" { yyextra->current->args += " &&"; - yyextra->current->argList.refQualifier=RefQualifierRValue; + yyextra->current->argList.setRefQualifier(RefQualifierRValue); } {BN}*"="{BN}*"0"{BN}* { // pure virtual member function lineCount(yyscanner) ; yyextra->current->args += " = 0"; yyextra->current->virt = Pure; - yyextra->current->argList.pureSpecifier=TRUE; + yyextra->current->argList.setPureSpecifier(TRUE); BEGIN(FuncQual); } {BN}*"="{BN}*"delete"{BN}* { // C++11 explicitly delete member lineCount(yyscanner); yyextra->current->args += " = delete"; yyextra->current->spec |= Entry::Delete; - yyextra->current->argList.isDeleted=TRUE; + yyextra->current->argList.setIsDeleted(TRUE); BEGIN(FuncQual); } {BN}*"="{BN}*"default"{BN}* { // C++11 explicitly defaulted constructor/assignment operator @@ -4584,7 +4582,7 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) } {BN}*"->"{BN}* { lineCount(yyscanner); - yyextra->current->argList.trailingReturnType = " -> "; + yyextra->current->argList.setTrailingReturnType(" -> "); yyextra->current->args += " -> "; BEGIN(TrailingReturn); } @@ -4593,12 +4591,12 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) BEGIN(FuncQual); } . { - yyextra->current->argList.trailingReturnType+=yytext; + yyextra->current->argList.setTrailingReturnType(yyextra->current->argList.trailingReturnType()+yytext); yyextra->current->args+=yytext; } \n { lineCount(yyscanner); - yyextra->current->argList.trailingReturnType+=yytext; + yyextra->current->argList.setTrailingReturnType(yyextra->current->argList.trailingReturnType()+yytext); yyextra->current->args+=' '; } {BN}*","{BN}* { @@ -4724,7 +4722,7 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) "{" { if (yyextra->current->argList.empty()) { - yyextra->current->argList.noParameters=TRUE; + yyextra->current->argList.setNoParameters(TRUE); } yyextra->current->args = argListToString(yyextra->current->argList); unput('{'); @@ -6532,16 +6530,16 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) } {B}*"const"{B}* { yyextra->current->args += " const "; - yyextra->current->argList.constSpecifier=TRUE; + yyextra->current->argList.setConstSpecifier(TRUE); } {B}*"volatile"{B}* { yyextra->current->args += " volatile "; - yyextra->current->argList.volatileSpecifier=TRUE; + yyextra->current->argList.setVolatileSpecifier(TRUE); } {B}*"="{B}*"0"{B}* { yyextra->current->args += " = 0"; yyextra->current->virt = Pure; - yyextra->current->argList.pureSpecifier=TRUE; + yyextra->current->argList.setPureSpecifier(TRUE); } "throw"{B}*"(" { yyextra->current->exception = "throw("; @@ -6675,9 +6673,7 @@ static void initParser(yyscan_t yyscanner) yyextra->virt = Normal; yyextra->baseVirt = Normal; yyextra->isTypedef = FALSE; - yyextra->autoGroupStack.clear(); yyextra->insideTryBlock = FALSE; - yyextra->autoGroupStack.setAutoDelete(TRUE); yyextra->insideFormula = FALSE; yyextra->insideCode=FALSE; yyextra->insideCli=Config_getBool(CPP_CLI_SUPPORT); diff --git a/src/util.cpp b/src/util.cpp index 1016625..429d3b0 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -2255,12 +2255,12 @@ QCString argListToString(const ArgumentList &al,bool useCanonicalType,bool showD if (it!=al.end()) result+=", "; } result+=")"; - if (al.constSpecifier) result+=" const"; - if (al.volatileSpecifier) result+=" volatile"; - if (al.refQualifier==RefQualifierLValue) result+=" &"; - else if (al.refQualifier==RefQualifierRValue) result+=" &&"; - if (!al.trailingReturnType.isEmpty()) result+=" -> "+al.trailingReturnType; - if (al.pureSpecifier) result+=" =0"; + if (al.constSpecifier()) result+=" const"; + if (al.volatileSpecifier()) result+=" volatile"; + if (al.refQualifier()==RefQualifierLValue) result+=" &"; + else if (al.refQualifier()==RefQualifierRValue) result+=" &&"; + if (!al.trailingReturnType().isEmpty()) result+=" -> "+al.trailingReturnType(); + if (al.pureSpecifier()) result+=" =0"; return removeRedundantWhiteSpace(result); } @@ -3207,19 +3207,19 @@ bool matchArguments2(const Definition *srcScope,const FileDef *srcFileScope,cons if (checkCV) { - if (srcAl->constSpecifier != dstAl->constSpecifier) + if (srcAl->constSpecifier() != dstAl->constSpecifier()) { NOMATCH return FALSE; // one member is const, the other not -> no match } - if (srcAl->volatileSpecifier != dstAl->volatileSpecifier) + if (srcAl->volatileSpecifier() != dstAl->volatileSpecifier()) { NOMATCH return FALSE; // one member is volatile, the other not -> no match } } - if (srcAl->refQualifier != dstAl->refQualifier) + if (srcAl->refQualifier() != dstAl->refQualifier()) { NOMATCH return FALSE; // one member is has a different ref-qualifier than the other diff --git a/src/xmlgen.cpp b/src/xmlgen.cpp index 42d4426..445916f 100644 --- a/src/xmlgen.cpp +++ b/src/xmlgen.cpp @@ -586,7 +586,7 @@ static void generateXMLForMember(const MemberDef *md,FTextStream &ti,FTextStream { const ArgumentList &al = md->argumentList(); t << " const=\""; - if (al.constSpecifier) t << "yes"; else t << "no"; + if (al.constSpecifier()) t << "yes"; else t << "no"; t << "\""; t << " explicit=\""; @@ -597,10 +597,10 @@ static void generateXMLForMember(const MemberDef *md,FTextStream &ti,FTextStream if (md->isInline()) t << "yes"; else t << "no"; t << "\""; - if (al.refQualifier!=RefQualifierNone) + if (al.refQualifier()!=RefQualifierNone) { t << " refqual=\""; - if (al.refQualifier==RefQualifierLValue) t << "lvalue"; else t << "rvalue"; + if (al.refQualifier()==RefQualifierLValue) t << "lvalue"; else t << "rvalue"; t << "\""; } @@ -634,7 +634,7 @@ static void generateXMLForMember(const MemberDef *md,FTextStream &ti,FTextStream t << " noexcept=\"yes\""; } - if (al.volatileSpecifier) + if (al.volatileSpecifier()) { t << " volatile=\"yes\""; } -- cgit v0.12