Skip to content

Commit

Permalink
Refactoring: replace Doxygen::namespaceAliasDict by Doxygen::namespac…
Browse files Browse the repository at this point in the history
…eAliasMap
  • Loading branch information
doxygen committed Apr 29, 2020
1 parent e0e5f73 commit 6ca67aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 31 deletions.
12 changes: 4 additions & 8 deletions src/doxygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ FileNameLinkedMap *Doxygen::imageNameLinkedMap = 0; // images
FileNameLinkedMap *Doxygen::dotFileNameLinkedMap = 0; // dot files
FileNameLinkedMap *Doxygen::mscFileNameLinkedMap = 0; // msc files
FileNameLinkedMap *Doxygen::diaFileNameLinkedMap = 0; // dia files
StringDict Doxygen::namespaceAliasDict(257); // all namespace aliases
StringMap Doxygen::namespaceAliasMap; // all namespace aliases
StringDict Doxygen::tagDestinationDict(257); // all tag locations
std::unordered_set<std::string> Doxygen::expandAsDefinedSet; // all macros that should be expanded
QIntDict<MemberGroupInfo> Doxygen::memGrpInfoDict(1009); // dictionary of the member groups heading
Expand Down Expand Up @@ -267,9 +267,6 @@ void statistics()
//g_excludeNameDict.statistics();
fprintf(stderr,"--- aliasDict stats ----\n");
Doxygen::aliasDict.statistics();
fprintf(stderr,"--- typedefDict stats ----\n");
fprintf(stderr,"--- namespaceAliasDict stats ----\n");
Doxygen::namespaceAliasDict.statistics();
fprintf(stderr,"--- tagDestinationDict stats ----\n");
Doxygen::tagDestinationDict.statistics();
fprintf(stderr,"--- g_compoundKeywordDict stats ----\n");
Expand Down Expand Up @@ -4430,10 +4427,10 @@ static bool findClassRelation(
{
// for PHP the "use A\B as C" construct map class C to A::B, so we lookup
// the class name also in the alias mapping.
QCString *aliasName = Doxygen::namespaceAliasDict[baseClassName];
if (aliasName) // see if it is indeed a class.
auto it = Doxygen::namespaceAliasMap.find(baseClassName.data());
if (it!=Doxygen::namespaceAliasMap.end()) // see if it is indeed a class.
{
baseClass=getClass(*aliasName);
baseClass=getClass(it->second.c_str());
found = baseClass!=0 && baseClass!=cd;
}
}
Expand Down Expand Up @@ -9722,7 +9719,6 @@ void initDoxygen()
Doxygen::exampleSDict->setAutoDelete(TRUE);
Doxygen::memGrpInfoDict.setAutoDelete(TRUE);
Doxygen::tagDestinationDict.setAutoDelete(TRUE);
Doxygen::namespaceAliasDict.setAutoDelete(TRUE);
Doxygen::dirRelations.setAutoDelete(TRUE);
Doxygen::genericsDict = new GenericsSDict;
Doxygen::indexList = new IndexList;
Expand Down
5 changes: 4 additions & 1 deletion src/doxygen.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <set>
#include <unordered_set>
#include <unordered_map>

#include "ftextstream.h"
#include "sortdict.h"
Expand Down Expand Up @@ -84,6 +85,8 @@ struct LookupInfo
QCString resolvedType;
};

using StringMap = std::unordered_map<std::string,std::string>;

extern QCString g_spaces;

/*! \brief This class serves as a namespace for global variables used by doxygen.
Expand All @@ -110,7 +113,7 @@ class Doxygen
static MemberNameLinkedMap *memberNameLinkedMap;
static MemberNameLinkedMap *functionNameLinkedMap;
static QStrList tagfileList;
static StringDict namespaceAliasDict;
static StringMap namespaceAliasMap;
static GroupSDict *groupSDict;
static NamespaceSDict *namespaceSDict;
static StringDict tagDestinationDict;
Expand Down
16 changes: 4 additions & 12 deletions src/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -1642,17 +1642,9 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
}
<NSAliasArg>({ID}"::")*{ID} {
//printf("Inserting namespace alias %s::%s->%s\n",yyextra->current_root->name.data(),yyextra->aliasName.data(),yytext);
//if (yyextra->current_root->name.isEmpty())
//{
// TODO: namespace aliases are now treated as global entities
// while they should be aware of the scope they are in
Doxygen::namespaceAliasDict.insert(yyextra->aliasName,new QCString(yytext));
//}
//else
//{
// Doxygen::namespaceAliasDict.insert(yyextra->current_root->name+"::"+yyextra->aliasName,
// new QCString(yyextra->current_root->name+"::"+yytext));
//}
Doxygen::namespaceAliasMap.insert({yyextra->aliasName.data(),std::string(yytext)});
}
<NSAliasArg>";" {
BEGIN( FindMembers );
Expand Down Expand Up @@ -1685,9 +1677,9 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
//printf("PHP: adding use as relation: %s->%s\n",yytext,yyextra->aliasName.data());
if (!yyextra->aliasName.isEmpty())
{
Doxygen::namespaceAliasDict.insert(yytext,
new QCString(removeRedundantWhiteSpace(
substitute(yyextra->aliasName,"\\","::"))));
Doxygen::namespaceAliasMap.insert({yytext,
std::string(removeRedundantWhiteSpace(
substitute(yyextra->aliasName,"\\","::")).data())});
}
yyextra->aliasName.resize(0);
}
Expand Down
24 changes: 14 additions & 10 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,21 +482,22 @@ ClassDef *getClass(const char *n)
NamespaceDef *getResolvedNamespace(const char *name)
{
if (name==0 || name[0]=='\0') return 0;
QCString *subst = Doxygen::namespaceAliasDict[name];
if (subst)
auto it = Doxygen::namespaceAliasMap.find(name);
if (it!=Doxygen::namespaceAliasMap.end())
{
int count=0; // recursion detection guard
QCString *newSubst;
while ((newSubst=Doxygen::namespaceAliasDict[*subst]) && count<10)
StringMap::iterator it2;
while ((it2=Doxygen::namespaceAliasMap.find(it->second))!=Doxygen::namespaceAliasMap.end() &&
count<10)
{
subst=newSubst;
it=it2;
count++;
}
if (count==10)
{
warn_uncond("possible recursive namespace alias detected for %s!\n",name);
}
return Doxygen::namespaceSDict->find(subst->data());
return Doxygen::namespaceSDict->find(it->second.data());
}
else
{
Expand Down Expand Up @@ -6619,11 +6620,14 @@ void replaceNamespaceAliases(QCString &scope,int i)
while (i>0)
{
QCString ns = scope.left(i);
QCString *s = Doxygen::namespaceAliasDict[ns];
if (s)
if (!ns.isEmpty())
{
scope=*s+scope.right(scope.length()-i);
i=s->length();
auto it = Doxygen::namespaceAliasMap.find(ns.data());
if (it!=Doxygen::namespaceAliasMap.end())
{
scope=it->second.data()+scope.right(scope.length()-i);
i=it->second.length();
}
}
if (i>0 && ns==scope.left(i)) break;
}
Expand Down

0 comments on commit 6ca67aa

Please sign in to comment.