summaryrefslogtreecommitdiffstats
path: root/src/pycode.l
diff options
context:
space:
mode:
authorDimitri van Heesch <doxygen@gmail.com>2021-04-11 19:22:59 (GMT)
committerDimitri van Heesch <doxygen@gmail.com>2021-04-22 17:34:13 (GMT)
commit592aaa4f17d73ec8c475df0f44efaea8cc4d575c (patch)
tree3cfd68cec756661045ee25c906a8d8f4bddf7a6a /src/pycode.l
parent98c67549bc3cd855873e0ef5eeab7c6410699d78 (diff)
downloadDoxygen-592aaa4f17d73ec8c475df0f44efaea8cc4d575c.zip
Doxygen-592aaa4f17d73ec8c475df0f44efaea8cc4d575c.tar.gz
Doxygen-592aaa4f17d73ec8c475df0f44efaea8cc4d575c.tar.bz2
Refactoring: remove implicit conversion from QCString to const char *
This commit changes the following in relation to string use - The implicit convert from 'QCString' to 'const char *' is removed - Strings parameters use 'const QCString &' as much as possible in favor over 'const char *' - 'if (s)' where s is a QCString has been replaced by 'if(!s.isEmpty())' - data() now always returns a valid C-string and not a 0-pointer. - when passing a string 's' to printf and related functions 'qPrint(s)' is used instead of 's.data()' - for empty string arguments 'QCString()' is used instead of '0' - The copy() operation has been removed - Where possible 'qstrcmp(a,b)==0' has been replaces by 'a==b' and 'qstrcmp(a,b)<0' has been replaced by 'a<b' - Parameters of string type that were default initialized with '= 0' are no initialized with '= QCString()'
Diffstat (limited to 'src/pycode.l')
-rw-r--r--src/pycode.l120
1 files changed, 61 insertions, 59 deletions
diff --git a/src/pycode.l b/src/pycode.l
index 107d855..fa65e22 100644
--- a/src/pycode.l
+++ b/src/pycode.l
@@ -118,27 +118,27 @@ static const char *stateToString(int state);
static void startCodeLine(yyscan_t yyscanner);
static int countLines(yyscan_t yyscanner);
static void setCurrentDoc(yyscan_t yyscanner, const QCString &anchor);
-static void addToSearchIndex(yyscan_t yyscanner, const char *text);
-static const ClassDef *stripClassName(yyscan_t yyscanner,const char *s,Definition *d);
-static void codify(yyscan_t yyscanner,const char* text);
+static void addToSearchIndex(yyscan_t yyscanner, const QCString &text);
+static const ClassDef *stripClassName(yyscan_t yyscanner,const QCString &s,Definition *d);
+static void codify(yyscan_t yyscanner,const QCString &text);
static void endCodeLine(yyscan_t yyscanner);
static void nextCodeLine(yyscan_t yyscanner);
-static void writeMultiLineCodeLink(yyscan_t yyscanner, CodeOutputInterface &ol, const Definition *d, const char *text);
+static void writeMultiLineCodeLink(yyscan_t yyscanner, CodeOutputInterface &ol, const Definition *d, const QCString &text);
static void startFontClass(yyscan_t yyscanner,const char *s);
static void endFontClass(yyscan_t yyscanner);
-static void codifyLines(yyscan_t yyscanner,const char *text);
+static void codifyLines(yyscan_t yyscanner,const QCString &text);
static bool getLinkInScope(yyscan_t yyscanner, const QCString &c, const QCString &m,
- const char *memberText, CodeOutputInterface &ol, const char *text);
-static bool getLink(yyscan_t yyscanner, const char *className, const char *memberName,
- CodeOutputInterface &ol, const char *text=0);
+ const QCString &memberText, CodeOutputInterface &ol, const QCString &text);
+static bool getLink(yyscan_t yyscanner, const QCString &className, const QCString &memberName,
+ CodeOutputInterface &ol, const QCString &text=QCString());
static void generateClassOrGlobalLink(yyscan_t yyscanner, CodeOutputInterface &ol,
- const char *clName, bool typeOnly=FALSE);
+ const QCString &clName, bool typeOnly=FALSE);
static void generateFunctionLink(yyscan_t yyscanner, CodeOutputInterface &ol,
- const char *funcName);
+ const QCString &funcName);
static bool findMemberLink(yyscan_t yyscanner, CodeOutputInterface &ol,
- Definition *sym, const char *symName);
+ Definition *sym, const QCString &symName);
static void findMemberLink(yyscan_t yyscanner, CodeOutputInterface &ol,
- const char *symName);
+ const QCString &symName);
static void adjustScopesAndSuites(yyscan_t yyscanner,unsigned indentLength);
static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size);
@@ -395,7 +395,7 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBU
// Push a class scope
- std::unique_ptr<ClassDef> classDefToAdd { createClassDef("<code>",1,1,yyextra->curClassName,ClassDef::Class,0,0,FALSE) };
+ std::unique_ptr<ClassDef> classDefToAdd { createClassDef("<code>",1,1,yyextra->curClassName,ClassDef::Class,QCString(),QCString(),FALSE) };
ScopedTypeVariant var(yyextra->curClassName);
for (const auto &s : yyextra->curClassBases)
{
@@ -829,7 +829,7 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBU
static void addVariable(yyscan_t yyscanner, QCString type, QCString name)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
- //printf("PyVariableContext::addVariable(%s,%s)\n",type.data(),name.data());
+ //printf("PyVariableContext::addVariable(%s,%s)\n",qPrint(type),qPrint(name));
QCString ltype = type.simplifyWhiteSpace();
QCString lname = name.simplifyWhiteSpace();
@@ -951,7 +951,7 @@ static void setCurrentDoc(yyscan_t yyscanner, const QCString &anchor)
//-------------------------------------------------------------------------------
-static void addToSearchIndex(yyscan_t yyscanner, const char *text)
+static void addToSearchIndex(yyscan_t yyscanner, const QCString &text)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
if (Doxygen::searchIndex)
@@ -963,7 +963,7 @@ static void addToSearchIndex(yyscan_t yyscanner, const char *text)
//-------------------------------------------------------------------------------
-static const ClassDef *stripClassName(yyscan_t yyscanner,const char *s,Definition *d)
+static const ClassDef *stripClassName(yyscan_t yyscanner,const QCString &s,Definition *d)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
int pos=0;
@@ -1018,9 +1018,9 @@ static void startCodeLine(yyscan_t yyscanner)
//yyextra->insideBody = FALSE;
yyextra->endComment = FALSE;
yyextra->searchingForBody = TRUE;
- yyextra->realScope = d->name().copy();
- yyextra->classScope = d->name().copy();
- //printf("Real scope: '%s'\n",yyextra->realScope.data());
+ yyextra->realScope = d->name();
+ yyextra->classScope = d->name();
+ //printf("Real scope: '%s'\n",qPrint(yyextra->realScope));
yyextra->bodyCurlyCount = 0;
QCString lineAnchor;
lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
@@ -1035,14 +1035,14 @@ static void startCodeLine(yyscan_t yyscanner)
{
yyextra->code->writeLineNumber(d->getReference(),
d->getOutputFileBase(),
- 0,yyextra->yyLineNr);
+ QCString(),yyextra->yyLineNr);
setCurrentDoc(yyscanner,lineAnchor);
}
}
else
{
//yyextra->code->codify(lineNumber);
- yyextra->code->writeLineNumber(0,0,0,yyextra->yyLineNr);
+ yyextra->code->writeLineNumber(QCString(),QCString(),QCString(),yyextra->yyLineNr);
}
//yyextra->code->endLineNumber();
}
@@ -1055,7 +1055,7 @@ static void startCodeLine(yyscan_t yyscanner)
//-------------------------------------------------------------------------------
-static void codify(yyscan_t yyscanner,const char* text)
+static void codify(yyscan_t yyscanner,const QCString &text)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
yyextra->code->codify(text);
@@ -1093,9 +1093,10 @@ static void nextCodeLine(yyscan_t yyscanner)
static void writeMultiLineCodeLink(yyscan_t yyscanner,
CodeOutputInterface &ol,
const Definition *d,
- const char *text)
+ const QCString &text)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
+ if (text.isEmpty()) return;
bool sourceTooltips = Config_getBool(SOURCE_TOOLTIPS);
TooltipManager::instance().addTooltip(ol,d);
QCString ref = d->getReference();
@@ -1107,7 +1108,7 @@ static void writeMultiLineCodeLink(yyscan_t yyscanner,
tooltip = d->briefDescriptionAsTooltip();
}
bool done=FALSE;
- char *p=(char *)text;
+ char *p=text.rawData();
while (!done)
{
char *sp=p;
@@ -1159,11 +1160,12 @@ static void endFontClass(yyscan_t yyscanner)
//-------------------------------------------------------------------------------
-static void codifyLines(yyscan_t yyscanner,const char *text)
+static void codifyLines(yyscan_t yyscanner,const QCString &text)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
+ if (text.isEmpty()) return;
//printf("codifyLines(%d,\"%s\")\n",yyextra->yyLineNr,text);
- const char *p=text,*sp=p;
+ const char *p=text.data(),*sp=p;
char c;
bool done=FALSE;
while (!done)
@@ -1194,9 +1196,9 @@ static void codifyLines(yyscan_t yyscanner,const char *text)
static bool getLinkInScope(yyscan_t yyscanner,
const QCString &c, // scope
const QCString &m, // member
- const char *memberText, // exact text
+ const QCString &memberText, // exact text
CodeOutputInterface &ol,
- const char *text
+ const QCString &text
)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
@@ -1205,7 +1207,7 @@ static bool getLinkInScope(yyscan_t yyscanner,
const FileDef *fd = 0;
const NamespaceDef *nd = 0;
const GroupDef *gd = 0;
- //printf("Trying '%s'::'%s'\n",c.data(),m.data());
+ //printf("Trying '%s'::'%s'\n",qPrint(c),qPrint(m));
if (getDefs(c,m,"()",md,cd,fd,nd,gd,FALSE,yyextra->sourceFileDef) &&
md->isLinkable())
{
@@ -1214,7 +1216,7 @@ static bool getLinkInScope(yyscan_t yyscanner,
const Definition *d = md->getOuterScope()==Doxygen::globalScope ?
md->getBodyDef() : md->getOuterScope();
- //printf("Found! d=%s\n",d?d->name().data():"<none>");
+ //printf("Found! d=%s\n",d?qPrint(d->name()):"<none>");
if (md->getGroupDef()) d = md->getGroupDef();
if (d && d->isLinkable())
{
@@ -1228,10 +1230,10 @@ static bool getLinkInScope(yyscan_t yyscanner,
std::lock_guard<std::mutex> lock(g_docCrossReferenceMutex);
addDocCrossReference(toMemberDefMutable(yyextra->currentMemberDef),toMemberDefMutable(md));
}
- //printf("d->getReference()='%s' d->getOutputBase()='%s' name='%s' member name='%s'\n",d->getReference().data(),d->getOutputFileBase().data(),d->name().data(),md->name().data());
+ //printf("d->getReference()='%s' d->getOutputBase()='%s' name='%s' member name='%s'\n",qPrint(d->getReference()),qPrint(d->getOutputFileBase()),qPrint(d->name()),qPrint(md->name()));
- writeMultiLineCodeLink(yyscanner,ol,md, text ? text : memberText);
- addToSearchIndex(yyscanner,text ? text : memberText);
+ writeMultiLineCodeLink(yyscanner,ol,md, !text.isEmpty() ? text : memberText);
+ addToSearchIndex(yyscanner,!text.isEmpty() ? text : memberText);
return TRUE;
}
}
@@ -1241,10 +1243,10 @@ static bool getLinkInScope(yyscan_t yyscanner,
//-------------------------------------------------------------------------------
static bool getLink(yyscan_t yyscanner,
- const char *className,
- const char *memberName,
+ const QCString &className,
+ const QCString &memberName,
CodeOutputInterface &ol,
- const char *text)
+ const QCString &text)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
QCString m=removeRedundantWhiteSpace(memberName);
@@ -1270,7 +1272,7 @@ static bool getLink(yyscan_t yyscanner,
*/
static void generateClassOrGlobalLink(yyscan_t yyscanner,
CodeOutputInterface &ol,
- const char *clName,
+ const QCString &clName,
bool typeOnly)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
@@ -1279,7 +1281,7 @@ static void generateClassOrGlobalLink(yyscan_t yyscanner,
// Don't do anything for empty text
if (className.isEmpty()) return;
- DBG_CTX((stderr,"generateClassOrGlobalLink(className=%s)\n",className.data()));
+ DBG_CTX((stderr,"generateClassOrGlobalLink(className=%s)\n",qPrint(className)));
const ScopedTypeVariant *lcd = 0;
const ClassDef *cd=0; // Class def that we may find
@@ -1295,9 +1297,9 @@ static void generateClassOrGlobalLink(yyscan_t yyscanner,
md = yyextra->symbolResolver.getTypedef();
DBG_CTX((stderr,"d=%s yyextra->sourceFileDef=%s\n",
- d?d->displayName().data():"<null>",
- yyextra->currentDefinition?yyextra->currentDefinition->displayName().data():"<null>"));
- DBG_CTX((stderr,"is found as a type %s\n",cd?cd->name().data():"<null>"));
+ d?qPrint(d->displayName()):"<null>",
+ yyextra->currentDefinition?qPrint(yyextra->currentDefinition->displayName()):"<null>"));
+ DBG_CTX((stderr,"is found as a type %s\n",cd?qPrint(cd->name()):"<null>"));
if (cd==0 && md==0) // also see if it is variable or enum or enum value
{
@@ -1349,7 +1351,7 @@ static void generateClassOrGlobalLink(yyscan_t yyscanner,
QCString scope = substitute(className.left(scopeEnd),".","::");
QCString locName = className.right(className.length()-scopeEnd-1);
ClassDef *mcd = getClass(scope);
- DBG_CTX((stderr,"scope=%s locName=%s mcd=%p\n",scope.data(),locName.data(),mcd));
+ DBG_CTX((stderr,"scope=%s locName=%s mcd=%p\n",qPrint(scope),qPrint(locName),mcd));
if (mcd)
{
const MemberDef *mmd = mcd->getMemberByName(locName);
@@ -1378,7 +1380,7 @@ static void generateClassOrGlobalLink(yyscan_t yyscanner,
const MemberDef *mmd=mnd->getMemberByName(locName);
if (mmd)
{
- //printf("name=%s scope=%s\n",locName.data(),scope.data());
+ //printf("name=%s scope=%s\n",qPrint(locName),qPrint(scope));
yyextra->theCallContext.setScope(ScopedTypeVariant(stripClassName(yyscanner,mmd->typeString(),mmd->getOuterScope())));
writeMultiLineCodeLink(yyscanner,ol,mmd,clName);
addToSearchIndex(yyscanner,className);
@@ -1414,26 +1416,26 @@ static void generateClassOrGlobalLink(yyscan_t yyscanner,
*/
static void generateFunctionLink(yyscan_t yyscanner,
CodeOutputInterface &ol,
- const char *funcName)
+ const QCString &funcName)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
QCString locScope=yyextra->classScope;
QCString locFunc=removeRedundantWhiteSpace(funcName);
- DBG_CTX((stdout,"*** locScope=%s locFunc=%s\n",locScope.data(),locFunc.data()));
+ DBG_CTX((stdout,"*** locScope=%s locFunc=%s\n",qPrint(locScope),qPrint(locFunc)));
int i=locFunc.findRev("::");
if (i>0)
{
locScope=locFunc.left(i);
locFunc=locFunc.right(locFunc.length()-i-2).stripWhiteSpace();
}
- //printf("generateFunctionLink(%s) classScope='%s'\n",locFunc.data(),locScope.data());
+ //printf("generateFunctionLink(%s) classScope='%s'\n",qPrint(locFunc),qPrint(locScope));
if (!locScope.isEmpty())
{
auto it = yyextra->codeClassMap.find(locScope.str());
if (it!=yyextra->codeClassMap.end())
{
ScopedTypeVariant ccd = it->second;
- //printf("using classScope %s\n",yyextra->classScope.data());
+ //printf("using classScope %s\n",qPrint(yyextra->classScope));
if (ccd.localDef() && !ccd.localDef()->baseClasses().empty())
{
for (const auto &bcName : ccd.localDef()->baseClasses())
@@ -1458,11 +1460,11 @@ static void generateFunctionLink(yyscan_t yyscanner,
static bool findMemberLink(yyscan_t yyscanner,
CodeOutputInterface &ol,
Definition *sym,
- const char *symName)
+ const QCString &symName)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
//printf("sym %s outerScope=%s equal=%d\n",
- // sym->name().data(),sym->getOuterScope()->name().data(),
+ // qPrint(sym->name()),qPrint(sym->getOuterScope()->name()),
// sym->getOuterScope()==yyextra->currentDefinition);
if (sym->getOuterScope() &&
@@ -1479,7 +1481,7 @@ static bool findMemberLink(yyscan_t yyscanner,
addDocCrossReference(toMemberDefMutable(yyextra->currentMemberDef),toMemberDefMutable(toMemberDef(sym)));
}
}
- DBG_CTX((stderr,"cd=%s thisCd=%s\n",cd?cd->name().data():"<none>",thisCd?thisCd->name().data():"<none>"));
+ DBG_CTX((stderr,"cd=%s thisCd=%s\n",cd?qPrint(cd->name()):"<none>",thisCd?qPrint(thisCd->name()):"<none>"));
// TODO: find the nearest base class in case cd is a base class of
// thisCd
@@ -1496,13 +1498,13 @@ static bool findMemberLink(yyscan_t yyscanner,
static void findMemberLink(yyscan_t yyscanner,
CodeOutputInterface &ol,
- const char *symName)
+ const QCString &symName)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
//printf("Member reference: %s scope=%s member=%s\n",
// yytext,
- // yyextra->currentDefinition?yyextra->currentDefinition->name().data():"<none>",
- // yyextra->currentMemberDef?yyextra->currentMemberDef->name().data():"<none>"
+ // yyextra->currentDefinition?qPrint(yyextra->currentDefinition->name()):"<none>",
+ // yyextra->currentMemberDef?qPrint(yyextra->currentMemberDef->name()):"<none>"
// );
if (yyextra->currentDefinition)
{
@@ -1552,11 +1554,11 @@ void PythonCodeParser::resetCodeParserState()
}
void PythonCodeParser::parseCode(CodeOutputInterface &codeOutIntf,
- const char *scopeName,
+ const QCString &scopeName,
const QCString &input,
SrcLangExt /*lang*/,
bool isExampleBlock,
- const char *exampleName,
+ const QCString &exampleName,
FileDef *fileDef,
int startLine,
int endLine,
@@ -1573,9 +1575,9 @@ void PythonCodeParser::parseCode(CodeOutputInterface &codeOutIntf,
//printf("***parseCode()\n");
if (input.isEmpty()) return;
- printlex(yy_flex_debug, TRUE, __FILE__, fileDef ? fileDef->fileName().data(): NULL);
+ printlex(yy_flex_debug, TRUE, __FILE__, fileDef ? qPrint(fileDef->fileName()): NULL);
yyextra->code = &codeOutIntf;
- yyextra->inputString = input;
+ yyextra->inputString = input.data();
yyextra->inputPosition = 0;
yyextra->currentFontClass = 0;
yyextra->needsTermination = FALSE;
@@ -1600,7 +1602,7 @@ void PythonCodeParser::parseCode(CodeOutputInterface &codeOutIntf,
if (yyextra->exampleBlock && fileDef==0)
{
// create a dummy filedef for the example
- yyextra->sourceFileDef = createFileDef("",(exampleName?exampleName:"generated"));
+ yyextra->sourceFileDef = createFileDef("",(!exampleName.isEmpty()?qPrint(exampleName):"generated"));
cleanupSourceDef = TRUE;
}
if (yyextra->sourceFileDef)
@@ -1633,7 +1635,7 @@ void PythonCodeParser::parseCode(CodeOutputInterface &codeOutIntf,
}
// write the tooltips
TooltipManager::instance().writeTooltips(codeOutIntf);
- printlex(yy_flex_debug, FALSE, __FILE__, fileDef ? fileDef->fileName().data(): NULL);
+ printlex(yy_flex_debug, FALSE, __FILE__, fileDef ? qPrint(fileDef->fileName()): NULL);
}
#if USE_STATE2STRING