42
42
#include < stdio.h>
43
43
#include < assert.h>
44
44
#include < ctype.h>
45
- #include < qregexp.h>
46
- #include < qdir.h>
47
- #include < qcstringlist.h>
48
- #include " entry.h"
45
+
49
46
#include " doxygen.h"
50
47
#include " message.h"
51
48
#include " outputlist.h"
52
49
#include " util.h"
53
50
#include " membername.h"
54
- #include " searchindex.h"
55
51
#include " defargs.h"
56
- #include " memberlist.h"
57
52
#include " config.h"
58
53
#include " groupdef.h"
59
54
#include " classlist.h"
@@ -99,17 +94,15 @@ class UseEntry
99
94
{
100
95
public:
101
96
QCString module ; // just for debug
102
- QCStringList onlyNames; /* entries of the ONLY-part */
97
+ std::vector<QCString> onlyNames; /* entries of the ONLY-part */
103
98
};
104
99
105
100
/**
106
101
module name -> list of ONLY/remote entries
107
102
(module name = name of the module, which can be accessed via use-directive)
108
103
*/
109
- class UseSDict : public SDict < UseEntry>
104
+ class UseMap : public std ::map<std::string, UseEntry>
110
105
{
111
- public:
112
- UseSDict () : SDict<UseEntry>(17 ) {}
113
106
};
114
107
115
108
/**
@@ -118,7 +111,7 @@ class UseSDict : public SDict<UseEntry>
118
111
class Scope
119
112
{
120
113
public:
121
- QCStringList useNames; // !< contains names of used modules
114
+ std::vector<QCString> useNames; // !< contains names of used modules
122
115
StringUnorderedSet localVars; // !< contains names of local variables
123
116
StringUnorderedSet externalVars; // !< contains names of external entities
124
117
};
@@ -132,9 +125,9 @@ struct fortrancodeYY_state
132
125
{
133
126
QCString docBlock; // !< contents of all lines of a documentation block
134
127
QCString currentModule=0 ; // !< name of the current enclosing module
135
- UseSDict * useMembers= 0 ; // !< info about used modules
136
- UseEntry * useEntry = 0 ; // !< current use statement info
137
- QList <Scope> scopeStack;
128
+ UseMap useMembers; // !< info about used modules
129
+ UseEntry useEntry; // !< current use statement info
130
+ std::vector <Scope> scopeStack;
138
131
bool isExternal = false ;
139
132
QCString str=" " ; // !> contents of fortran string
140
133
@@ -181,7 +174,7 @@ static const char *stateToString(int state);
181
174
static bool getFortranNamespaceDefs (const QCString &mname,
182
175
NamespaceDef *&cd);
183
176
static bool getFortranTypeDefs (const QCString &tname, const QCString &moduleName,
184
- ClassDef *&cd, UseSDict *usedict= 0 );
177
+ ClassDef *&cd, const UseMap &useMap );
185
178
186
179
// ----------------------------------------------------------------------------
187
180
@@ -198,7 +191,7 @@ static void writeMultiLineCodeLink(yyscan_t yyscanner,CodeOutputInterface &ol,
198
191
static bool getGenericProcedureLink (yyscan_t yyscanner,const ClassDef *cd,
199
192
const char *memberText,
200
193
CodeOutputInterface &ol);
201
- static bool getLink (yyscan_t yyscanner,UseSDict *usedict , // dictionary with used modules
194
+ static bool getLink (yyscan_t yyscanner,const UseMap &useMap , // map with used modules
202
195
const char *memberText, // exact member text
203
196
CodeOutputInterface &ol,
204
197
const char *text);
@@ -209,7 +202,7 @@ static void endScope(yyscan_t yyscanner);
209
202
static void addUse (yyscan_t yyscanner,const QCString &moduleName);
210
203
static void addLocalVar (yyscan_t yyscanner,const QCString &varName);
211
204
static MemberDef *getFortranDefs (yyscan_t yyscanner,const QCString &memberName, const QCString &moduleName,
212
- UseSDict *usedict= 0 );
205
+ const UseMap &useMap );
213
206
static yy_size_t yyread (yyscan_t yyscanner,char *buf,yy_size_t max_size);
214
207
215
208
@@ -356,12 +349,9 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
356
349
yyextra->insideBody =FALSE ;
357
350
358
351
/* append module name to use dict */
359
- yyextra->useEntry = new UseEntry ();
360
- // yyextra->useEntry->module = yytext;
361
- // yyextra->useMembers->append(yytext, yyextra->useEntry);
362
- // addUse(yytext);
363
- yyextra->useEntry ->module = tmp;
364
- yyextra->useMembers ->append (tmp, yyextra->useEntry );
352
+ yyextra->useEntry = UseEntry ();
353
+ yyextra->useEntry .module = tmp;
354
+ yyextra->useMembers .insert (std::make_pair (tmp.str (), yyextra->useEntry ));
365
355
addUse (yyscanner,tmp);
366
356
}
367
357
<Use ,UseOnly ,Import >{BS },{BS } { codifyLines (yyscanner,yytext); }
@@ -371,7 +361,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")
371
361
<UseOnly >{ID } {
372
362
QCString tmp = yytext;
373
363
tmp = tmp.lower ();
374
- yyextra->useEntry -> onlyNames .append (tmp);
364
+ yyextra->useEntry . onlyNames .push_back (tmp);
375
365
yyextra->insideBody =TRUE ;
376
366
generateLink (yyscanner,*yyextra->code , yytext);
377
367
yyextra->insideBody =FALSE ;
@@ -1081,7 +1071,7 @@ static bool getFortranNamespaceDefs(const QCString &mname,
1081
1071
@returns true, if type is found
1082
1072
*/
1083
1073
static bool getFortranTypeDefs (const QCString &tname, const QCString &moduleName,
1084
- ClassDef *&cd, UseSDict *usedict )
1074
+ ClassDef *&cd, const UseMap &useMap )
1085
1075
{
1086
1076
if (tname.isEmpty ()) return FALSE ; /* empty name => nothing to link */
1087
1077
@@ -1100,10 +1090,9 @@ static bool getFortranTypeDefs(const QCString &tname, const QCString &moduleName
1100
1090
}
1101
1091
else
1102
1092
{
1103
- UseEntry *use;
1104
- for (UseSDict::Iterator di (*usedict); (use=di.current ()); ++di)
1093
+ for (const auto &kv : useMap)
1105
1094
{
1106
- if ((cd= Doxygen::classLinkedMap->find (use-> module +" ::" +tname)))
1095
+ if ((cd= Doxygen::classLinkedMap->find (kv. second . module +" ::" +tname)))
1107
1096
{
1108
1097
// cout << "=== type found in used module" << endl;
1109
1098
return TRUE ;
@@ -1122,19 +1111,18 @@ static bool getFortranTypeDefs(const QCString &tname, const QCString &moduleName
1122
1111
@returns MemberDef pointer, if found, or nullptr otherwise
1123
1112
*/
1124
1113
static MemberDef *getFortranDefs (yyscan_t yyscanner,const QCString &memberName, const QCString &moduleName,
1125
- UseSDict *usedict )
1114
+ const UseMap &useMap )
1126
1115
{
1127
1116
struct yyguts_t *yyg = (struct yyguts_t *)yyscanner;
1128
1117
if (memberName.isEmpty ()) return nullptr ; /* empty name => nothing to link */
1129
1118
1130
1119
// look in local variables
1131
- QListIterator<Scope> it (yyextra->scopeStack );
1132
- Scope *scope;
1133
- for (it.toLast ();(scope=it.current ());--it)
1120
+ for (auto it = yyextra->scopeStack .rbegin (); it!=yyextra->scopeStack .rend (); ++it)
1134
1121
{
1122
+ const Scope &scope = *it;
1135
1123
std::string lowMemName = memberName.lower ().str ();
1136
- if (scope-> localVars .find (lowMemName)!=std::end (scope-> localVars ) && // local var
1137
- scope-> externalVars .find (lowMemName)==std::end (scope-> externalVars )) // and not external
1124
+ if (scope. localVars .find (lowMemName)!=std::end (scope. localVars ) && // local var
1125
+ scope. externalVars .find (lowMemName)==std::end (scope. externalVars )) // and not external
1138
1126
{
1139
1127
return nullptr ;
1140
1128
}
@@ -1177,22 +1165,22 @@ static MemberDef *getFortranDefs(yyscan_t yyscanner,const QCString &memberName,
1177
1165
else
1178
1166
{ // else search in used modules
1179
1167
QCString usedModuleName= nspace->name ();
1180
- UseEntry *ue= usedict-> find (usedModuleName);
1181
- if (ue )
1168
+ auto use_it = useMap. find (usedModuleName. str () );
1169
+ if (use_it!=useMap. end () )
1182
1170
{
1171
+ const UseEntry &ue = use_it->second ;
1183
1172
// check if only-list exists and if current entry exists is this list
1184
- QCStringList &only= ue->onlyNames ;
1185
- if (only.isEmpty ())
1173
+ if (ue.onlyNames .empty ())
1186
1174
{
1187
1175
// cout << " found in module " << usedModuleName << " entry " << memberName << endl;
1188
1176
return md.get (); // whole module used
1189
1177
}
1190
1178
else
1191
1179
{
1192
- for ( QCStringList::Iterator lit = only. begin (); lit != only. end (); ++lit )
1180
+ for ( const auto &name : ue. onlyNames )
1193
1181
{
1194
1182
// cout << " search in only: " << usedModuleName << ":: " << memberName << "==" << (*it)<< endl;
1195
- if (memberName == *lit )
1183
+ if (memberName == name )
1196
1184
{
1197
1185
return md.get (); // found in ONLY-part of use list
1198
1186
}
@@ -1220,7 +1208,7 @@ static bool getGenericProcedureLink(yyscan_t yyscanner,const ClassDef *cd,
1220
1208
return FALSE ;
1221
1209
}
1222
1210
1223
- static bool getLink (yyscan_t yyscanner,UseSDict *usedict , // dictionary with used modules
1211
+ static bool getLink (yyscan_t yyscanner,const UseMap &useMap , // dictionary with used modules
1224
1212
const char *memberText, // exact member text
1225
1213
CodeOutputInterface &ol,
1226
1214
const char *text)
@@ -1229,7 +1217,7 @@ static bool getLink(yyscan_t yyscanner,UseSDict *usedict, // dictionary with use
1229
1217
MemberDef *md=0 ;
1230
1218
QCString memberName= removeRedundantWhiteSpace (memberText);
1231
1219
1232
- if ((md=getFortranDefs (yyscanner,memberName, yyextra->currentModule , usedict )) && md->isLinkable ())
1220
+ if ((md=getFortranDefs (yyscanner,memberName, yyextra->currentModule , useMap )) && md->isLinkable ())
1233
1221
{
1234
1222
if (md->isVariable () && (md->getLanguage ()!=SrcLangExt_Fortran)) return FALSE ; // Non Fortran variables aren't handled yet,
1235
1223
// see also linkifyText in util.cpp
@@ -1324,45 +1312,43 @@ static void startScope(yyscan_t yyscanner)
1324
1312
{
1325
1313
struct yyguts_t *yyg = (struct yyguts_t *)yyscanner;
1326
1314
DBG_CTX ((stderr, " ===> startScope %s" ,yytext));
1327
- Scope *scope = new Scope;
1328
- yyextra->scopeStack .append (scope);
1315
+ yyextra->scopeStack .push_back (Scope ());
1329
1316
}
1330
1317
1331
1318
/** end scope */
1332
1319
static void endScope (yyscan_t yyscanner)
1333
1320
{
1334
1321
struct yyguts_t *yyg = (struct yyguts_t *)yyscanner;
1335
1322
DBG_CTX ((stderr," ===> endScope %s" ,yytext));
1336
- if (yyextra->scopeStack .isEmpty ())
1323
+ if (yyextra->scopeStack .empty ())
1337
1324
{
1338
1325
DBG_CTX ((stderr," WARNING: fortrancode.l: stack empty!\n " ));
1339
1326
return ;
1340
1327
}
1341
1328
1342
- Scope *scope = yyextra->scopeStack .getLast ();
1343
- yyextra->scopeStack .removeLast ();
1344
- for ( QCStringList::Iterator it = scope->useNames .begin (); it != scope->useNames .end (); ++it)
1329
+ Scope &scope = yyextra->scopeStack .back ();
1330
+ for ( const auto &name : scope.useNames )
1345
1331
{
1346
- yyextra->useMembers -> remove (*it );
1332
+ yyextra->useMembers . erase (name. str () );
1347
1333
}
1348
- delete scope ;
1334
+ yyextra-> scopeStack . pop_back () ;
1349
1335
}
1350
1336
1351
1337
static void addUse (yyscan_t yyscanner,const QCString &moduleName)
1352
1338
{
1353
1339
struct yyguts_t *yyg = (struct yyguts_t *)yyscanner;
1354
- if (!yyextra->scopeStack .isEmpty ())
1355
- yyextra->scopeStack .getLast ()-> useNames .append (moduleName);
1340
+ if (!yyextra->scopeStack .empty ())
1341
+ yyextra->scopeStack .back (). useNames .push_back (moduleName);
1356
1342
}
1357
1343
1358
1344
static void addLocalVar (yyscan_t yyscanner,const QCString &varName)
1359
1345
{
1360
1346
struct yyguts_t *yyg = (struct yyguts_t *)yyscanner;
1361
- if (!yyextra->scopeStack .isEmpty ())
1347
+ if (!yyextra->scopeStack .empty ())
1362
1348
{
1363
1349
std::string lowVarName = varName.lower ().str ();
1364
- yyextra->scopeStack .getLast ()-> localVars .insert (lowVarName);
1365
- if (yyextra->isExternal ) yyextra->scopeStack .getLast ()-> externalVars .insert (lowVarName);
1350
+ yyextra->scopeStack .back (). localVars .insert (lowVarName);
1351
+ if (yyextra->isExternal ) yyextra->scopeStack .back (). externalVars .insert (lowVarName);
1366
1352
}
1367
1353
}
1368
1354
@@ -1418,12 +1404,10 @@ FortranCodeParser::FortranCodeParser(FortranFormat format) : p(std::make_unique<
1418
1404
fortrancodeYYset_debug (1 ,p->yyscanner );
1419
1405
#endif
1420
1406
resetCodeParserState ();
1421
- p->state .useMembers = new UseSDict;
1422
1407
}
1423
1408
1424
1409
FortranCodeParser::~FortranCodeParser ()
1425
1410
{
1426
- delete p->state .useMembers ;
1427
1411
fortrancodeYYlex_destroy (p->yyscanner );
1428
1412
}
1429
1413
0 commit comments