Skip to content

Commit f0621ab

Browse files
committed
Refactoring: replace QDict by std::set for classifying keywords in vhdldocgen
1 parent 525b87e commit f0621ab

File tree

3 files changed

+34
-86
lines changed

3 files changed

+34
-86
lines changed

Diff for: src/vhdlcode.l

+2-2
Original file line numberDiff line numberDiff line change
@@ -1532,10 +1532,10 @@ static void writeProcessProto(yyscan_t yyscanner)
15321532
static bool writeColoredWord(yyscan_t yyscanner,QCString& word )
15331533
{
15341534
QCString qcs=word.lower();
1535-
QCString *ss=VhdlDocGen::findKeyWord(qcs);
1535+
const char *ss=VhdlDocGen::findKeyWord(qcs);
15361536
if (ss)
15371537
{
1538-
writeFont(yyscanner,ss->data(),word.data());
1538+
writeFont(yyscanner,ss,word.data());
15391539
return true;
15401540
}
15411541
return false;

Diff for: src/vhdldocgen.cpp

+31-83
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@
6464
//#define DEBUGFLOW
6565
#define theTranslator_vhdlType theTranslator->trVhdlType
6666

67-
static QDict<QCString> g_vhdlKeyDict0(17,FALSE);
68-
static QDict<QCString> g_vhdlKeyDict1(17,FALSE);
69-
static QDict<QCString> g_vhdlKeyDict2(17,FALSE);
70-
static QDict<QCString> g_vhdlKeyDict3(17,FALSE);
71-
7267
static void initUCF(Entry* root,const char* type,QCString & qcs,int line,QCString & fileName,QCString & brief);
7368
static void writeUCFLink(const MemberDef* mdef,OutputList &ol);
7469
static void addInstance(ClassDefMutable* entity, ClassDefMutable* arch, ClassDefMutable *inst,
@@ -562,11 +557,8 @@ VhdlDocGen::~VhdlDocGen()
562557
{
563558
}
564559

565-
void VhdlDocGen::init()
566-
{
567-
568560
// vhdl keywords included VHDL 2008
569-
const char* g_vhdlKeyWordMap0[] =
561+
static const std::set< std::string > g_vhdlKeyWordSet0 =
570562
{
571563
"abs","access","after","alias","all","and","architecture","array","assert","assume","assume_guarantee","attribute",
572564
"begin","block","body","buffer","bus",
@@ -587,100 +579,57 @@ const char* g_vhdlKeyWordMap0[] =
587579
"unaffected","units","until","use",
588580
"variable","vmode","vprop","vunit",
589581
"wait","when","while","with",
590-
"xor","xnor",
591-
0
582+
"xor","xnor"
592583
};
593584

594585

595586
// type
596-
const char* g_vhdlKeyWordMap1[] =
587+
static const std::set< std::string> g_vhdlKeyWordSet1 =
597588
{
598589
"natural","unsigned","signed","string","boolean", "bit","bit_vector","character",
599590
"std_ulogic","std_ulogic_vector","std_logic","std_logic_vector","integer",
600-
"real","float","ufixed","sfixed","time","positive",0
591+
"real","float","ufixed","sfixed","time","positive"
601592
};
602593

603594
// logic
604-
const char* g_vhdlKeyWordMap2[] =
595+
static const std::set< std::string > g_vhdlKeyWordSet2 =
605596
{
606-
"abs","and","or","not","mod", "xor","rem","xnor","ror","rol","sla",
607-
"sll",0
597+
"abs","and","or","not","mod","xor","rem","xnor","ror","rol","sla","sll"
608598
};
609599

610600
// predefined attributes
611-
const char* g_vhdlKeyWordMap3[] =
601+
static const std::set< std::string > g_vhdlKeyWordSet3 =
612602
{
613-
"base","left","right","high","low","ascending",
614-
"image","value","pos","val","succ","pred","leftof","rightof","left","right","high","low",
615-
"range","reverse_range","length","ascending","delayed","stable","quiet","transaction","event",
616-
"active","last_event","last_active","last_value","driving","driving_value","simple_name","instance_name","path_name",0
603+
"base","left","right","high","low","ascending",
604+
"image","value","pos","val","succ","pred","leftof","rightof","left","right","high","low",
605+
"range","reverse_range","length","ascending","delayed","stable","quiet","transaction","event",
606+
"active","last_event","last_active","last_value","driving","driving_value","simple_name","instance_name","path_name"
617607
};
618608

619-
int j=0;
620-
g_vhdlKeyDict0.setAutoDelete(TRUE);
621-
g_vhdlKeyDict1.setAutoDelete(TRUE);
622-
g_vhdlKeyDict2.setAutoDelete(TRUE);
623-
g_vhdlKeyDict3.setAutoDelete(TRUE);
624-
625-
while (g_vhdlKeyWordMap0[j])
626-
{
627-
g_vhdlKeyDict0.insert(g_vhdlKeyWordMap0[j],
628-
new QCString(g_vhdlKeyWordMap0[j]));
629-
j++;
630-
}
631-
632-
j=0;
633-
while (g_vhdlKeyWordMap1[j])
634-
{
635-
g_vhdlKeyDict1.insert(g_vhdlKeyWordMap1[j],
636-
new QCString(g_vhdlKeyWordMap1[j]));
637-
j++;
638-
}
639-
640-
j=0;
641-
while (g_vhdlKeyWordMap2[j])
642-
{
643-
g_vhdlKeyDict2.insert(g_vhdlKeyWordMap2[j],
644-
new QCString(g_vhdlKeyWordMap2[j]));
645-
j++;
646-
}
647-
648-
j=0;
649-
while (g_vhdlKeyWordMap3[j])
650-
{
651-
g_vhdlKeyDict3.insert(g_vhdlKeyWordMap3[j],
652-
new QCString(g_vhdlKeyWordMap3[j]));
653-
j++;
654-
}
655-
656-
}// buildKeyMap
609+
void VhdlDocGen::init()
610+
{
611+
}
657612

658613
/*!
659614
* returns the color of a keyword
660615
*/
661-
662-
QCString* VhdlDocGen::findKeyWord(const QCString& tmp)
616+
const char* VhdlDocGen::findKeyWord(const QCString& kw)
663617
{
664-
static QCString vhdlkeyword("vhdlkeyword");
665-
static QCString vhdltype("keywordtype");
666-
static QCString vhdllogic("vhdllogic");
667-
static QCString preprocessor("keywordflow");
668-
669-
QCString word=tmp.lower();
618+
std::string word=kw.lower().str();
670619

671-
if (word.isEmpty() || word.at(0)=='\0') return 0;
620+
if (word.empty()) return 0;
672621

673-
if (g_vhdlKeyDict0.find(word))
674-
return &preprocessor;
622+
if (g_vhdlKeyWordSet0.find(word)!=g_vhdlKeyWordSet0.end())
623+
return "keywordflow";
675624

676-
if (g_vhdlKeyDict1.find(word))
677-
return &vhdltype;
625+
if (g_vhdlKeyWordSet1.find(word)!=g_vhdlKeyWordSet1.end())
626+
return "keywordtype";
678627

679-
if (g_vhdlKeyDict2.find(word))
680-
return &vhdllogic;
628+
if (g_vhdlKeyWordSet2.find(word)!=g_vhdlKeyWordSet2.end())
629+
return "vhdllogic";
681630

682-
if (g_vhdlKeyDict3.find(word))
683-
return &vhdlkeyword;
631+
if (g_vhdlKeyWordSet3.find(word)!=g_vhdlKeyWordSet3.end())
632+
return "vhdlkeyword";
684633

685634
return 0;
686635
}
@@ -1267,7 +1216,6 @@ void VhdlDocGen::writeFormatString(const QCString& s,OutputList&ol,const MemberD
12671216
QRegExp reg("[\\[\\]\\.\\/\\:\\<\\>\\:\\s\\,\\;\\'\\+\\-\\*\\|\\&\\=\\(\\)\"]");
12681217
QCString qcs = s;
12691218
qcs+=QCString(" ");// parsing the last sign
1270-
QCString *ss;
12711219
QCString find=qcs;
12721220
QCString temp=qcs;
12731221
char buf[2];
@@ -1284,7 +1232,7 @@ void VhdlDocGen::writeFormatString(const QCString& s,OutputList&ol,const MemberD
12841232
{
12851233
find=find.left(j);
12861234
buf[0]=temp[j];
1287-
ss=VhdlDocGen::findKeyWord(find);
1235+
const char *ss=VhdlDocGen::findKeyWord(find);
12881236
bool k=isNumber(find); // is this a number
12891237
if (k)
12901238
{
@@ -1294,7 +1242,7 @@ void VhdlDocGen::writeFormatString(const QCString& s,OutputList&ol,const MemberD
12941242
}
12951243
else if (j != 0 && ss)
12961244
{
1297-
startFonts(find,ss->data(),ol);
1245+
startFonts(find,ss,ol);
12981246
}
12991247
else
13001248
{
@@ -1430,11 +1378,11 @@ void VhdlDocGen::writeProcedureProto(OutputList& ol,const ArgumentList &al,const
14301378
nn+=": ";
14311379

14321380
QCString defval = arg.defval;
1433-
QCString *str=VhdlDocGen::findKeyWord(defval);
1381+
const char *str=VhdlDocGen::findKeyWord(defval);
14341382
defval+=" ";
14351383
if (str)
14361384
{
1437-
startFonts(defval,str->data(),ol);
1385+
startFonts(defval,str,ol);
14381386
}
14391387
else
14401388
{
@@ -1495,7 +1443,7 @@ void VhdlDocGen::writeFunctionProto(OutputList& ol,const ArgumentList &al,const
14951443
}
14961444
if (!att.isEmpty())
14971445
{
1498-
QCString *str=VhdlDocGen::findKeyWord(att);
1446+
const char *str=VhdlDocGen::findKeyWord(att);
14991447
att+=" ";
15001448
if (str)
15011449
VhdlDocGen::formatString(att,ol,mdef);
@@ -1509,7 +1457,7 @@ void VhdlDocGen::writeFunctionProto(OutputList& ol,const ArgumentList &al,const
15091457
QCString w=ss.stripWhiteSpace();//.upper();
15101458
startFonts(nn,"vhdlchar",ol);
15111459
startFonts("in ","stringliteral",ol);
1512-
QCString *str=VhdlDocGen::findKeyWord(ss);
1460+
const char *str=VhdlDocGen::findKeyWord(ss);
15131461
if (str)
15141462
VhdlDocGen::formatString(w,ol,mdef);
15151463
else

Diff for: src/vhdldocgen.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class VhdlDocGen
130130

131131
static void computeVhdlComponentRelations();
132132

133-
static QCString* findKeyWord(const QCString& word);
133+
static const char* findKeyWord(const QCString& word);
134134

135135
static ClassDef* getPackageName(const QCString& name);
136136
static MemberDef* findMember(const QCString& className,

0 commit comments

Comments
 (0)