Skip to content

Commit 525b87e

Browse files
committed
Refactoring: replace QMap with std::map in fortranscanner.l
1 parent 65e57b5 commit 525b87e

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

src/fortranscanner.l

+30-29
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
%{
5050

51+
#include <map>
52+
5153
#include <stdio.h>
5254
#include <stdlib.h>
5355
#include <assert.h>
@@ -202,7 +204,7 @@ struct fortranscannerYY_state
202204
//! Accumulated modifiers of current statement, eg variable declaration.
203205
SymbolModifiers currentModifiers;
204206
//! Holds program scope->symbol name->symbol modifiers.
205-
QMap<Entry*,QMap<QCString,SymbolModifiers> > modifiers;
207+
std::map<Entry*,std::map<std::string,SymbolModifiers> > modifiers;
206208
int anonCount = 0 ;
207209
};
208210

@@ -712,7 +714,7 @@ private {
712714
}
713715
{ID} {
714716
QCString name = yytext;
715-
yyextra->modifiers[yyextra->current_root][name.lower()] |= yyextra->currentModifiers;
717+
yyextra->modifiers[yyextra->current_root][name.lower().str()] |= yyextra->currentModifiers;
716718
yyextra->current->section = Entry::FUNCTION_SEC;
717719
yyextra->current->name = name;
718720
yyextra->current->fileName = yyextra->fileName;
@@ -872,7 +874,7 @@ private {
872874
QCString name=yytext;
873875
name = name.lower();
874876
/* remember attributes for the symbol */
875-
yyextra->modifiers[yyextra->current_root][name.lower()] |= yyextra->currentModifiers;
877+
yyextra->modifiers[yyextra->current_root][name.lower().str()] |= yyextra->currentModifiers;
876878
yyextra->argName= name;
877879

878880
yyextra->vtype= V_IGNORE;
@@ -913,12 +915,12 @@ private {
913915
// save, it may be function return type
914916
if (parameter)
915917
{
916-
yyextra->modifiers[yyextra->current_root][name.lower()].type = yyextra->argType;
918+
yyextra->modifiers[yyextra->current_root][name.lower().str()].type = yyextra->argType;
917919
}
918920
else
919921
{
920922
if ((yyextra->current_root->name.lower() == yyextra->argName.lower()) ||
921-
(yyextra->modifiers[yyextra->current_root->parent()][yyextra->current_root->name.lower()].returnName.lower() == yyextra->argName.lower()))
923+
(yyextra->modifiers[yyextra->current_root->parent()][yyextra->current_root->name.lower().str()].returnName.lower() == yyextra->argName.lower()))
922924
{
923925
int strt = yyextra->current_root->type.find("function");
924926
QCString lft;
@@ -956,11 +958,11 @@ private {
956958
yyextra->current_root->type += " " + yyextra->argType.stripWhiteSpace();
957959
}
958960
yyextra->current_root->type = yyextra->current_root->type.stripWhiteSpace();
959-
yyextra->modifiers[yyextra->current_root][name.lower()].type = yyextra->current_root->type;
961+
yyextra->modifiers[yyextra->current_root][name.lower().str()].type = yyextra->current_root->type;
960962
}
961963
else
962964
{
963-
yyextra->modifiers[yyextra->current_root][name.lower()].type = yyextra->argType;
965+
yyextra->modifiers[yyextra->current_root][name.lower().str()].type = yyextra->argType;
964966
}
965967
}
966968
// any accumulated doc for argument should be emptied,
@@ -974,7 +976,7 @@ private {
974976
QCString name(yyextra->argName);
975977
QCString attr("dimension");
976978
attr += yytext;
977-
yyextra->modifiers[yyextra->current_root][name.lower()] |= attr;
979+
yyextra->modifiers[yyextra->current_root][name.lower().str()] |= attr;
978980
}
979981
<Variable>{COMMA} { //printf("COMMA: %d<=..<=%d\n", yyextra->colNr-(int)yyleng, yyextra->colNr);
980982
// locate !< comment
@@ -1148,7 +1150,7 @@ private {
11481150
<Subprog>{BS} { /* ignore white space */ }
11491151
<Subprog>{ID} { yyextra->current->name = yytext;
11501152
//cout << "1a==========> got " << yyextra->current->type << " " << yytext << " " << yyextra->lineNr << endl;
1151-
yyextra->modifiers[yyextra->current_root][yyextra->current->name.lower()].returnName = yyextra->current->name.lower();
1153+
yyextra->modifiers[yyextra->current_root][yyextra->current->name.lower().str()].returnName = yyextra->current->name.lower();
11521154

11531155
if (yyextra->ifType == IF_ABSTRACT || yyextra->ifType == IF_SPECIFIC)
11541156
{
@@ -1197,7 +1199,7 @@ private {
11971199
QCString result= yytext;
11981200
result= result.right(result.length()-result.find("(")-1);
11991201
result= result.stripWhiteSpace();
1200-
yyextra->modifiers[yyextra->current_root->parent()][yyextra->current_root->name.lower()].returnName = result;
1202+
yyextra->modifiers[yyextra->current_root->parent()][yyextra->current_root->name.lower().str()].returnName = result;
12011203
}
12021204
//cout << "=====> got result " << result << endl;
12031205
}
@@ -2019,7 +2021,7 @@ static Argument *findArgument(Entry* subprog, QCString name, bool byTypeName = F
20192021

20202022

20212023
/*! Apply yyextra->modifiers stored in \a mdfs to the \a typeName string. */
2022-
static QCString applyModifiers(QCString typeName, SymbolModifiers& mdfs)
2024+
static QCString applyModifiers(QCString typeName, const SymbolModifiers& mdfs)
20232025
{
20242026
if (!mdfs.dimension.isNull())
20252027
{
@@ -2136,14 +2138,14 @@ static QCString applyModifiers(QCString typeName, SymbolModifiers& mdfs)
21362138
}
21372139

21382140
/*! Apply yyextra->modifiers stored in \a mdfs to the \a arg argument. */
2139-
static void applyModifiers(Argument *arg, SymbolModifiers& mdfs)
2141+
static void applyModifiers(Argument *arg, const SymbolModifiers& mdfs)
21402142
{
21412143
QCString tmp = arg->type;
21422144
arg->type = applyModifiers(tmp, mdfs);
21432145
}
21442146

21452147
/*! Apply yyextra->modifiers stored in \a mdfs to the \a ent entry. */
2146-
static void applyModifiers(Entry *ent, SymbolModifiers& mdfs)
2148+
static void applyModifiers(Entry *ent, const SymbolModifiers& mdfs)
21472149
{
21482150
QCString tmp = ent->type;
21492151
ent->type = applyModifiers(tmp, mdfs);
@@ -2164,8 +2166,7 @@ static void startScope(yyscan_t yyscanner,Entry *scope)
21642166
//cout<<"start scope: "<<scope->name<<endl;
21652167
yyextra->current_root= scope; /* start substructure */
21662168

2167-
QMap<QCString,SymbolModifiers> mdfMap;
2168-
yyextra->modifiers.insert(scope, mdfMap);
2169+
yyextra->modifiers.insert(std::make_pair(scope, std::map<std::string,SymbolModifiers>()));
21692170
}
21702171

21712172
/*! Ends scope in fortran program: may update subprogram arguments or module variable attributes.
@@ -2196,32 +2197,32 @@ static bool endScope(yyscan_t yyscanner,Entry *scope, bool isGlobalRoot)
21962197
}
21972198

21982199
// update variables or subprogram arguments with yyextra->modifiers
2199-
QMap<QCString,SymbolModifiers>& mdfsMap = yyextra->modifiers[scope];
2200+
std::map<std::string,SymbolModifiers>& mdfsMap = yyextra->modifiers[scope];
22002201

22012202
if (scope->section == Entry::FUNCTION_SEC)
22022203
{
22032204
// iterate all symbol yyextra->modifiers of the scope
2204-
for (QMap<QCString,SymbolModifiers>::Iterator it=mdfsMap.begin(); it!=mdfsMap.end(); it++)
2205+
for (const auto &kv : mdfsMap)
22052206
{
22062207
//cout<<it.key()<<": "<<it.data()<<endl;
2207-
Argument *arg = findArgument(scope, it.key());
2208+
Argument *arg = findArgument(scope, kv.first);
22082209

22092210
if (arg)
22102211
{
2211-
applyModifiers(arg, it.data());
2212+
applyModifiers(arg, kv.second);
22122213
}
22132214
}
22142215

22152216
// find return type for function
22162217
//cout<<"RETURN NAME "<<yyextra->modifiers[yyextra->current_root][scope->name.lower()].returnName<<endl;
2217-
QCString returnName = yyextra->modifiers[yyextra->current_root][scope->name.lower()].returnName.lower();
2218-
if (yyextra->modifiers[scope].contains(returnName))
2218+
QCString returnName = yyextra->modifiers[yyextra->current_root][scope->name.lower().str()].returnName.lower();
2219+
if (yyextra->modifiers[scope].find(returnName.str())!=yyextra->modifiers[scope].end())
22192220
{
2220-
scope->type = yyextra->modifiers[scope][returnName].type; // returning type works
2221-
applyModifiers(scope, yyextra->modifiers[scope][returnName]); // returning array works
2221+
scope->type = yyextra->modifiers[scope][returnName.str()].type; // returning type works
2222+
applyModifiers(scope, yyextra->modifiers[scope][returnName.str()]); // returning array works
22222223
}
22232224

2224-
}
2225+
}
22252226
if (scope->section == Entry::CLASS_SEC)
22262227
{ // was INTERFACE_SEC
22272228
if (scope->parent()->section == Entry::FUNCTION_SEC)
@@ -2249,7 +2250,7 @@ static bool endScope(yyscan_t yyscanner,Entry *scope, bool isGlobalRoot)
22492250
if ((count == 1) && found)
22502251
{
22512252
// clear all yyextra->modifiers of the scope
2252-
yyextra->modifiers.remove(scope);
2253+
yyextra->modifiers.erase(scope);
22532254
scope->parent()->removeSubEntry(scope);
22542255
scope = 0;
22552256
return TRUE;
@@ -2265,13 +2266,13 @@ static bool endScope(yyscan_t yyscanner,Entry *scope, bool isGlobalRoot)
22652266
continue;
22662267

22672268
//cout<<ce->name<<", "<<mdfsMap.contains(ce->name.lower())<<mdfsMap.count()<<endl;
2268-
if (mdfsMap.contains(ce->name.lower()))
2269-
applyModifiers(ce.get(), mdfsMap[ce->name.lower()]);
2269+
if (mdfsMap.find(ce->name.lower().str())!=mdfsMap.end())
2270+
applyModifiers(ce.get(), mdfsMap[ce->name.lower().str()]);
22702271
}
22712272
}
22722273

22732274
// clear all yyextra->modifiers of the scope
2274-
yyextra->modifiers.remove(scope);
2275+
yyextra->modifiers.erase(scope);
22752276

22762277
return TRUE;
22772278
}
@@ -2522,7 +2523,7 @@ static void subrHandleCommentBlock(yyscan_t yyscanner,const QCString &doc,bool b
25222523
loc_doc.stripWhiteSpace();
25232524

25242525
// direction as defined with the declaration of the parameter
2525-
int dir1 = yyextra->modifiers[yyextra->current_root][yyextra->argName.lower()].direction;
2526+
int dir1 = yyextra->modifiers[yyextra->current_root][yyextra->argName.lower().str()].direction;
25262527
// in description [in] is specified
25272528
if (loc_doc.lower().find(directionParam[SymbolModifiers::IN]) == 0)
25282529
{

0 commit comments

Comments
 (0)