summaryrefslogtreecommitdiffstats
path: root/src/fortrancode.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/fortrancode.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/fortrancode.l')
-rw-r--r--src/fortrancode.l157
1 files changed, 82 insertions, 75 deletions
diff --git a/src/fortrancode.l b/src/fortrancode.l
index fbc1a64..67890e4 100644
--- a/src/fortrancode.l
+++ b/src/fortrancode.l
@@ -124,12 +124,12 @@ class Scope
struct fortrancodeYY_state
{
QCString docBlock; //!< contents of all lines of a documentation block
- QCString currentModule=0; //!< name of the current enclosing module
- UseMap useMembers; //!< info about used modules
+ QCString currentModule=QCString(); //!< name of the current enclosing module
+ UseMap useMembers; //!< info about used modules
UseEntry useEntry; //!< current use statement info
std::vector<Scope> scopeStack;
bool isExternal = false;
- QCString str=""; //!> contents of fortran string
+ QCString str=QCString(); //!< contents of fortran string
CodeOutputInterface * code = 0;
@@ -181,21 +181,22 @@ static bool getFortranTypeDefs(const QCString &tname, const QCString &moduleName
static void endFontClass(yyscan_t yyscanner);
static void startFontClass(yyscan_t yyscanner,const char *s);
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);
static void startCodeLine(yyscan_t yyscanner);
static void endCodeLine(yyscan_t yyscanner);
static void nextCodeLine(yyscan_t yyscanner);
-static void codifyLines(yyscan_t yyscanner,const char *text);
+static void codifyLines(yyscan_t yyscanner,const QCString &text);
static void writeMultiLineCodeLink(yyscan_t yyscanner,CodeOutputInterface &ol,
- Definition *d,const char *text);
+ Definition *d,const QCString &text);
static bool getGenericProcedureLink(yyscan_t yyscanner,const ClassDef *cd,
- const char *memberText,
+ const QCString &memberText,
CodeOutputInterface &ol);
static bool getLink(yyscan_t yyscanner,const UseMap &useMap, // map with used modules
- const char *memberText, // exact member text
+ const QCString &memberText, // exact member text
CodeOutputInterface &ol,
- const char *text);
-static void generateLink(yyscan_t yyscanner,CodeOutputInterface &ol, char *lname);
+ const QCString &text);
+static void generateLink(yyscan_t yyscanner,CodeOutputInterface &ol, const QCString &lname);
+static void generateLink(yyscan_t yyscanner,CodeOutputInterface &ol, const char *lname);
static int countLines(yyscan_t yyscanner);
static void startScope(yyscan_t yyscanner);
static void endScope(yyscan_t yyscanner);
@@ -342,7 +343,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
BEGIN(UseOnly);
}
<Use>{ID} {
- QCString tmp = yytext;
+ QCString tmp(yytext);
tmp = tmp.lower();
yyextra->insideBody=TRUE;
generateLink(yyscanner,*yyextra->code, yytext);
@@ -359,7 +360,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
yyextra->contLineNr++;
YY_FTN_RESET}
<UseOnly>{ID} {
- QCString tmp = yytext;
+ QCString tmp(yytext);
tmp = tmp.lower();
yyextra->useEntry.onlyNames.push_back(tmp);
yyextra->insideBody=TRUE;
@@ -430,10 +431,10 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
yy_pop_state(yyscanner);
}
<ClassName>({ACCESS_SPEC}|ABSTRACT|EXTENDS)/[,:( ] { //| variable declaration
- startFontClass(yyscanner,"keyword");
- yyextra->code->codify(yytext);
- endFontClass(yyscanner);
- }
+ startFontClass(yyscanner,"keyword");
+ yyextra->code->codify(QCString(yytext));
+ endFontClass(yyscanner);
+ }
<ClassName>\n { // interface may be without name
yy_pop_state(yyscanner);
YY_FTN_REJECT;
@@ -504,18 +505,18 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
yy_push_state(YY_START,yyscanner);
BEGIN(Declaration);
startFontClass(yyscanner,"keywordtype");
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
endFontClass(yyscanner);
}
<Start>{TYPE_SPEC}/[,:( ] {
- QCString typ = yytext;
+ QCString typ(yytext);
typ = removeRedundantWhiteSpace(typ.lower());
if (typ.startsWith("real")) YY_FTN_REJECT;
if (typ == "type" || typ == "class" || typ == "procedure") yyextra->inTypeDecl = 1;
yy_push_state(YY_START,yyscanner);
BEGIN(Declaration);
startFontClass(yyscanner,"keywordtype");
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
endFontClass(yyscanner);
}
<Start>{ATTR_SPEC} {
@@ -526,20 +527,20 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
yyextra->isExternal = true;
}
startFontClass(yyscanner,"keywordtype");
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
endFontClass(yyscanner);
}
<Declaration>({TYPE_SPEC}|{ATTR_SPEC})/[,:( ] { //| variable declaration
if (QCString(yytext) == "external") yyextra->isExternal = true;
startFontClass(yyscanner,"keywordtype");
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
endFontClass(yyscanner);
}
<Declaration>{ID} { // local var
if (yyextra->isFixedForm && yy_my_start == 1)
{
startFontClass(yyscanner,"comment");
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
endFontClass(yyscanner);
}
else if (yyextra->currentMemberDef &&
@@ -552,13 +553,13 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
}
else
{
- yyextra->code->codify(yytext);
- addLocalVar(yyscanner,yytext);
+ yyextra->code->codify(QCString(yytext));
+ addLocalVar(yyscanner,QCString(yytext));
}
}
<Declaration>{BS}("=>"|"="){BS} { // Procedure binding
BEGIN(DeclarationBinding);
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
}
<DeclarationBinding>{ID} { // Type bound procedure link
generateLink(yyscanner,*yyextra->code, yytext);
@@ -566,17 +567,17 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
}
<Declaration>[(] { // start of array or type / class specification
yyextra->bracketCount++;
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
}
<Declaration>[)] { // end array specification
yyextra->bracketCount--;
if (!yyextra->bracketCount) yyextra->inTypeDecl = 0;
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
}
<Declaration,DeclarationBinding>"&" { // continuation line
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
if (!yyextra->isFixedForm)
{
yy_push_state(YY_START,yyscanner);
@@ -637,12 +638,12 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
startFontClass(yyscanner,"keywordtype");
yyextra->code->codify(QCString(yytext).stripWhiteSpace());
endFontClass(yyscanner);
- yyextra->code->codify(yytext + 4);
+ yyextra->code->codify(QCString(yytext + 4));
}
else
{
yyextra->insideBody=TRUE;
- generateLink(yyscanner,*yyextra->code, yytext);
+ generateLink(yyscanner,*yyextra->code,yytext);
yyextra->insideBody=FALSE;
}
}
@@ -740,7 +741,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
/*------ variable references? -------------------------------------*/
<Start>"%"{BS}{ID} { // ignore references to elements
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
}
<Start>{ID} {
yyextra->insideBody=TRUE;
@@ -791,7 +792,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
yyextra->contLineNr++;
YY_FTN_RESET
}
-<*>^{BS}"type"{BS}"=" { yyextra->code->codify(yytext); }
+<*>^{BS}"type"{BS}"=" { yyextra->code->codify(QCString(yytext)); }
<*>[\x80-\xFF]* { // keep utf8 characters together...
if (yyextra->isFixedForm && yy_my_start > fixedCommentAfter)
@@ -801,7 +802,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
}
else
{
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
}
}
<*>. {
@@ -815,11 +816,11 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
}
else
{
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
}
}
<*>{LOG_OPER} { // Fortran logical comparison keywords
- yyextra->code->codify(yytext);
+ yyextra->code->codify(QCString(yytext));
}
<*><<EOF>> {
if (YY_START == DocBlock) {
@@ -870,7 +871,7 @@ static void startFontClass(yyscan_t yyscanner,const char *s)
if (!yyextra->currentFontClass || !s || strcmp(yyextra->currentFontClass,s))
{
endFontClass(yyscanner);
- yyextra->code->startFontClass(s);
+ yyextra->code->startFontClass(QCString(s));
yyextra->currentFontClass=s;
}
}
@@ -891,7 +892,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)
@@ -914,7 +915,7 @@ static void startCodeLine(yyscan_t yyscanner)
//lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
const Definition *d = yyextra->sourceFileDef->getSourceDefinition(yyextra->yyLineNr);
- //printf("startCodeLine %d d=%s\n", yyextra->yyLineNr,d ? d->name().data() : "<null>");
+ //printf("startCodeLine %d d=%s\n", yyextra->yyLineNr,d ? qPrint(d->name()) : "<null>");
if (!yyextra->includeCodeFragment && d)
{
yyextra->currentDefinition = d;
@@ -934,19 +935,19 @@ 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->writeLineNumber(0,0,0,yyextra->yyLineNr);
+ yyextra->code->writeLineNumber(QCString(),QCString(),QCString(),yyextra->yyLineNr);
}
}
yyextra->code->startCodeLine(yyextra->sourceFileDef);
if (yyextra->currentFontClass)
{
- yyextra->code->startFontClass(yyextra->currentFontClass);
+ yyextra->code->startFontClass(QCString(yyextra->currentFontClass));
}
}
@@ -973,11 +974,12 @@ static void nextCodeLine(yyscan_t yyscanner)
/*! write a code fragment 'text' that may span multiple lines, inserting
* line numbers for each line.
*/
-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;
//printf("codifyLines(%d,\"%s\")\n",yyextra->yyLineNr,text);
- const char *p=text,*sp=p;
+ if (text.isEmpty()) return;
+ const char *p=text.data(),*sp=p;
char c;
bool done=FALSE;
while (!done)
@@ -991,13 +993,13 @@ static void codifyLines(yyscan_t yyscanner,const char *text)
char *tmp = (char*)malloc(l+1);
memcpy(tmp,sp,l);
tmp[l]='\0';
- yyextra->code->codify(tmp);
+ yyextra->code->codify(QCString(tmp));
free(tmp);
nextCodeLine(yyscanner);
}
else
{
- yyextra->code->codify(sp);
+ yyextra->code->codify(QCString(sp));
done=TRUE;
}
}
@@ -1008,7 +1010,7 @@ static void codifyLines(yyscan_t yyscanner,const char *text)
* split into multiple links with the same destination, one for each line.
*/
static void writeMultiLineCodeLink(yyscan_t yyscanner,CodeOutputInterface &ol,
- Definition *d,const char *text)
+ Definition *d,const QCString &text)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
static bool sourceTooltips = Config_getBool(SOURCE_TOOLTIPS);
@@ -1022,7 +1024,7 @@ static void writeMultiLineCodeLink(yyscan_t yyscanner,CodeOutputInterface &ol,
tooltip = d->briefDescriptionAsTooltip();
}
bool done=FALSE;
- char *p=(char *)text;
+ char *p=text.rawData();
while (!done)
{
char *sp=p;
@@ -1033,13 +1035,13 @@ static void writeMultiLineCodeLink(yyscan_t yyscanner,CodeOutputInterface &ol,
yyextra->yyLineNr++;
*(p-1)='\0';
//printf("writeCodeLink(%s,%s,%s,%s)\n",ref,file,anchor,sp);
- ol.writeCodeLink(ref,file,anchor,sp,tooltip);
+ ol.writeCodeLink(ref,file,anchor,QCString(sp),tooltip);
nextCodeLine(yyscanner);
}
else
{
//printf("writeCodeLink(%s,%s,%s,%s)\n",ref,file,anchor,sp);
- ol.writeCodeLink(ref,file,anchor,sp,tooltip);
+ ol.writeCodeLink(ref,file,anchor,QCString(sp),tooltip);
done=TRUE;
}
}
@@ -1083,7 +1085,7 @@ static bool getFortranTypeDefs(const QCString &tname, const QCString &moduleName
//cout << "=== type found in global module" << endl;
return TRUE;
}
- else if (moduleName && (cd= Doxygen::classLinkedMap->find(moduleName+"::"+tname)))
+ else if (!moduleName.isEmpty() && (cd= Doxygen::classLinkedMap->find(moduleName+"::"+tname)))
{
//cout << "=== type found in local module" << endl;
return TRUE;
@@ -1200,7 +1202,7 @@ static MemberDef *getFortranDefs(yyscan_t yyscanner,const QCString &memberName,
@todo implementation
*/
static bool getGenericProcedureLink(yyscan_t yyscanner,const ClassDef *cd,
- const char *memberText,
+ const QCString &memberText,
CodeOutputInterface &ol)
{
(void)cd;
@@ -1210,9 +1212,9 @@ static bool getGenericProcedureLink(yyscan_t yyscanner,const ClassDef *cd,
}
static bool getLink(yyscan_t yyscanner,const UseMap &useMap, // dictionary with used modules
- const char *memberText, // exact member text
+ const QCString &memberText, // exact member text
CodeOutputInterface &ol,
- const char *text)
+ const QCString &text)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
MemberDef *md=0;
@@ -1234,8 +1236,8 @@ static bool getLink(yyscan_t yyscanner,const UseMap &useMap, // dictionary with
std::lock_guard<std::mutex> lock(g_docCrossReferenceMutex);
addDocCrossReference(toMemberDefMutable(yyextra->currentMemberDef),toMemberDefMutable(md));
}
- 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;
}
}
@@ -1243,36 +1245,36 @@ static bool getLink(yyscan_t yyscanner,const UseMap &useMap, // dictionary with
}
-static void generateLink(yyscan_t yyscanner,CodeOutputInterface &ol, char *lname)
+static void generateLink(yyscan_t yyscanner,CodeOutputInterface &ol, const QCString &lname)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
ClassDef *cd=0;
NamespaceDef *nsd=0;
- QCString tmp = lname;
- tmp = removeRedundantWhiteSpace(tmp.lower());
+ QCString name = lname;
+ name = removeRedundantWhiteSpace(name.lower());
// check if lowercase lname is a linkable type or interface
- if ( (getFortranTypeDefs(tmp, yyextra->currentModule, cd, yyextra->useMembers)) && cd->isLinkable() )
+ if ( (getFortranTypeDefs(name, yyextra->currentModule, cd, yyextra->useMembers)) && cd->isLinkable() )
{
if ( (cd->compoundType() == ClassDef::Class) && // was Entry::INTERFACE_SEC) &&
- (getGenericProcedureLink(yyscanner, cd, tmp, ol)) )
+ (getGenericProcedureLink(yyscanner, cd, name, ol)) )
{
//cout << "=== generic procedure resolved" << endl;
}
else
{ // write type or interface link
- writeMultiLineCodeLink(yyscanner, ol,cd,tmp);
- addToSearchIndex(yyscanner, tmp);
+ writeMultiLineCodeLink(yyscanner, ol,cd,name);
+ addToSearchIndex(yyscanner, name);
}
}
// check for module
- else if ( (getFortranNamespaceDefs(tmp, nsd)) && nsd->isLinkable() )
+ else if ( (getFortranNamespaceDefs(name, nsd)) && nsd->isLinkable() )
{ // write module link
- writeMultiLineCodeLink(yyscanner,ol,nsd,tmp);
- addToSearchIndex(yyscanner,tmp);
+ writeMultiLineCodeLink(yyscanner,ol,nsd,name);
+ addToSearchIndex(yyscanner,name);
}
// check for function/variable
- else if (getLink(yyscanner,yyextra->useMembers, tmp, ol, tmp))
+ else if (getLink(yyscanner,yyextra->useMembers, name, ol, name))
{
//cout << "=== found link for lowercase " << lname << endl;
}
@@ -1280,12 +1282,17 @@ static void generateLink(yyscan_t yyscanner,CodeOutputInterface &ol, char *lname
{
// nothing found, just write out the word
//startFontClass("charliteral"); //test
- codifyLines(yyscanner,tmp);
+ codifyLines(yyscanner,name);
//endFontClass(yyscanner); //test
- addToSearchIndex(yyscanner,tmp);
+ addToSearchIndex(yyscanner,name);
}
}
+static void generateLink(yyscan_t yyscanner,CodeOutputInterface &ol, const char *lname)
+{
+ generateLink(yyscanner,ol,QCString(lname));
+}
+
/*! counts the number of lines in the input */
static int countLines(yyscan_t yyscanner)
{
@@ -1423,11 +1430,11 @@ void FortranCodeParser::resetCodeParserState()
}
void FortranCodeParser::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,
@@ -1449,9 +1456,9 @@ void FortranCodeParser::parseCode(CodeOutputInterface & codeOutIntf,
// const MemberDef *,bool,const Definition *searchCtx,
// bool collectXRefs, FortranFormat format)
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->isFixedForm = recognizeFixedForm(input,p->format);
yyextra->contLineNr = 1;
@@ -1480,11 +1487,11 @@ void FortranCodeParser::parseCode(CodeOutputInterface & codeOutIntf,
if (isExampleBlock && fileDef==0)
{
// create a dummy filedef for the example
- yyextra->sourceFileDef = createFileDef("",exampleName);
+ yyextra->sourceFileDef = createFileDef(QCString(),exampleName);
}
if (yyextra->sourceFileDef)
{
- setCurrentDoc(yyscanner,"l00001");
+ setCurrentDoc(yyscanner,QCString("l00001"));
}
yyextra->currentDefinition = 0;
yyextra->currentMemberDef = 0;
@@ -1514,7 +1521,7 @@ void FortranCodeParser::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);
}
//---------------------------------------------------------