refactored DoxygenEntity class

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-doxygen@13724 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marko Klopcic 2012-08-26 15:34:46 +00:00
commit c9eda79264
7 changed files with 155 additions and 253 deletions

View file

@ -14,182 +14,66 @@
#include "DoxygenEntity.h" #include "DoxygenEntity.h"
#include <iostream> #include <iostream>
DoxygenEntity::DoxygenEntity(std::string typeEnt) { using std::cout;
typeOfEntity = typeEnt;
data = ""; DoxygenEntity::DoxygenEntity(const std::string &typeEnt) :
isLeaf = true; typeOfEntity(typeEnt),
} isLeaf(true)
{}
/* Basic node for commands that have /* Basic node for commands that have
* only 1 thing after them * only 1 item after them
* example: \b word * example: \b word
* OR holding a std::string * OR holding a std::string
*/ */
DoxygenEntity::DoxygenEntity(std::string typeEnt, std::string param1) { DoxygenEntity::DoxygenEntity(const std::string &typeEnt,
typeOfEntity = typeEnt; const std::string &param1) :
data = param1; typeOfEntity(typeEnt),
isLeaf = true; data(param1),
} isLeaf(true)
{}
/* Nonterminal node /* Nonterminal node
* contains * contains
*/ */
DoxygenEntity::DoxygenEntity(std::string typeEnt, std::list < DoxygenEntity > &entList) { DoxygenEntity::DoxygenEntity(const std::string &typeEnt,
typeOfEntity = typeEnt; const DoxygenEntityList &entList) :
data = ""; typeOfEntity(typeEnt),
isLeaf = false; isLeaf(false),
entityList = entList; entityList(entList)
} {}
void DoxygenEntity::printEntity(int level) const { void DoxygenEntity::printEntity(int level) const {
int thisLevel = level; int thisLevel = level;
if (isLeaf) { if (isLeaf) {
for (int i = 0; i < thisLevel; i++) { for (int i = 0; i < thisLevel; i++) {
std::cout << "\t"; cout << "\t";
} }
std::cout << "Node Command: " << typeOfEntity << " "; cout << "Node Command: " << typeOfEntity << " ";
if (data.compare("") != 0) { if (!data.empty()) {
std::cout << "Node Data: " << data; cout << "Node Data: " << data;
} }
std::cout << std::endl; cout << std::endl;
} else { } else {
for (int i = 0; i < thisLevel; i++) { for (int i = 0; i < thisLevel; i++) {
std::cout << "\t"; cout << "\t";
} }
std::cout << "Node Command : " << typeOfEntity << std::endl; cout << "Node Command : " << typeOfEntity << std::endl;
std::list < DoxygenEntity >::const_iterator p = entityList.begin();
thisLevel++; thisLevel++;
while (p != entityList.end()) { for (DoxygenEntityListCIt p = entityList.begin(); p != entityList.end(); p++) {
(*p).printEntity(thisLevel); p->printEntity(thisLevel);
p++;
} }
} }
} }
// not used, completely wrong - currently std lib reports 'invalid operator <'
bool CompareDoxygenEntities::operator() (DoxygenEntity & first, DoxygenEntity & second) {
// return first.typeOfEntity < second.typeOfEntity;
if (first.typeOfEntity.compare("brief") == 0)
return true;
if (second.typeOfEntity.compare("brief") == 0)
return false;
if (first.typeOfEntity.compare("details") == 0)
return true;
if (second.typeOfEntity.compare("details") == 0)
return false;
if (first.typeOfEntity.compare("partofdescription") == 0)
return true;
if (second.typeOfEntity.compare("partofdescription") == 0)
return false;
if (first.typeOfEntity.compare("plainstd::string") == 0)
return true;
if (second.typeOfEntity.compare("plainstd::string") == 0)
return false;
if (first.typeOfEntity.compare("param") == 0) {
if (second.typeOfEntity.compare("param") == 0)
return true;
if (second.typeOfEntity.compare("return") == 0)
return true;
if (second.typeOfEntity.compare("exception") == 0)
return true;
if (second.typeOfEntity.compare("author") == 0)
return true;
if (second.typeOfEntity.compare("version") == 0)
return true;
if (second.typeOfEntity.compare("see") == 0)
return true;
if (second.typeOfEntity.compare("since") == 0)
return true;
if (second.typeOfEntity.compare("deprecated") == 0)
return true;
return false;
}
if (first.typeOfEntity.compare("return") == 0) {
if (second.typeOfEntity.compare("return") == 0)
return true;
if (second.typeOfEntity.compare("exception") == 0)
return true;
if (second.typeOfEntity.compare("author") == 0)
return true;
if (second.typeOfEntity.compare("version") == 0)
return true;
if (second.typeOfEntity.compare("see") == 0)
return true;
if (second.typeOfEntity.compare("since") == 0)
return true;
if (second.typeOfEntity.compare("deprecated") == 0)
return true;
return false;
}
if (first.typeOfEntity.compare("exception") == 0) {
if (second.typeOfEntity.compare("exception") == 0)
return true;
if (second.typeOfEntity.compare("author") == 0)
return true;
if (second.typeOfEntity.compare("version") == 0)
return true;
if (second.typeOfEntity.compare("see") == 0)
return true;
if (second.typeOfEntity.compare("since") == 0)
return true;
if (second.typeOfEntity.compare("deprecated") == 0)
return true;
return false;
}
if (first.typeOfEntity.compare("author") == 0) {
if (second.typeOfEntity.compare("author") == 0)
return true;
if (second.typeOfEntity.compare("version") == 0)
return true;
if (second.typeOfEntity.compare("see") == 0)
return true;
if (second.typeOfEntity.compare("since") == 0)
return true;
if (second.typeOfEntity.compare("deprecated") == 0)
return true;
return false;
}
if (first.typeOfEntity.compare("version") == 0) {
if (second.typeOfEntity.compare("version") == 0)
return true;
if (second.typeOfEntity.compare("see") == 0)
return true;
if (second.typeOfEntity.compare("since") == 0)
return true;
if (second.typeOfEntity.compare("deprecated") == 0)
return true;
return false;
}
if (first.typeOfEntity.compare("see") == 0 || first.typeOfEntity.compare("sa") == 0) {
if (second.typeOfEntity.compare("see") == 0)
return true;
if (second.typeOfEntity.compare("sa") == 0)
return true;
if (second.typeOfEntity.compare("since") == 0)
return true;
if (second.typeOfEntity.compare("deprecated") == 0)
return true;
return false;
}
if (first.typeOfEntity.compare("since") == 0) {
if (second.typeOfEntity.compare("since") == 0)
return true;
if (second.typeOfEntity.compare("deprecated") == 0)
return true;
return false;
}
if (first.typeOfEntity.compare("deprecated") == 0) {
if (second.typeOfEntity.compare("deprecated") == 0)
return true;
return false;
}
return true;
}

View file

@ -36,29 +36,28 @@ typedef enum {
COMMAND COMMAND
} DoxyCommandEnum; } DoxyCommandEnum;
class DoxygenEntity;
typedef std::list <DoxygenEntity> DoxygenEntityList;
typedef DoxygenEntityList::iterator DoxygenEntityListIt;
typedef DoxygenEntityList::const_iterator DoxygenEntityListCIt;
/* /*
* Structure to represent a doxygen comment entry * Structure to represent a doxygen comment entry
*/ */
struct DoxygenEntity { class DoxygenEntity {
public:
std::string typeOfEntity; std::string typeOfEntity;
std::list < DoxygenEntity > entityList;
std::string data; std::string data;
bool isLeaf; bool isLeaf;
DoxygenEntityList entityList;
DoxygenEntity(std::string typeEnt); DoxygenEntity(const std::string &typeEnt);
DoxygenEntity(std::string typeEnt, std::string param1); DoxygenEntity(const std::string &typeEnt, const std::string &param1);
DoxygenEntity(std::string typeEnt, std::list < DoxygenEntity > &entList); DoxygenEntity(const std::string & typeEnt, const DoxygenEntityList &entList);
void printEntity(int level) const; void printEntity(int level) const;
}; };
/*
* Functor that sorts entities by javaDoc standard order for commands.
* NOTE: will not behave entirely properly until "First level" comments
* such as brief descriptions are TAGGED as such
*/
struct CompareDoxygenEntities {
bool operator() (DoxygenEntity & first, DoxygenEntity & second);
};
#endif #endif

View file

@ -102,8 +102,8 @@ bool DoxygenParser::isSectionIndicator(const std::string &smallString) {
} }
void DoxygenParser::printTree(const std::list <DoxygenEntity> &rootList) { void DoxygenParser::printTree(const DoxygenEntityList &rootList) {
std::list < DoxygenEntity >::const_iterator p = rootList.begin(); DoxygenEntityList::const_iterator p = rootList.begin();
while (p != rootList.end()) { while (p != rootList.end()) {
(*p).printEntity(0); (*p).printEntity(0);
p++; p++;
@ -297,7 +297,7 @@ DoxygenParser::TokenListCIt DoxygenParser::getEndCommand(const std::string & the
int DoxygenParser::addSimpleCommand(const std::string &theCommand, int DoxygenParser::addSimpleCommand(const std::string &theCommand,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
@ -308,13 +308,13 @@ int DoxygenParser::addSimpleCommand(const std::string &theCommand,
int DoxygenParser::addCommandWord(const std::string &theCommand, int DoxygenParser::addCommandWord(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(tokList); std::string name = getNextWord(tokList);
if (!name.empty()) { if (!name.empty()) {
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList.push_back(DoxygenEntity("plainstd::string", name)); aNewList.push_back(DoxygenEntity("plainstd::string", name));
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
return 1; return 1;
@ -327,11 +327,11 @@ int DoxygenParser::addCommandWord(const std::string &theCommand,
int DoxygenParser::addCommandLine(const std::string &theCommand, int DoxygenParser::addCommandLine(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
TokenListCIt endOfLine = getOneLine(tokList); TokenListCIt endOfLine = getOneLine(tokList);
std::list < DoxygenEntity > aNewList = parse(endOfLine, tokList); DoxygenEntityList aNewList = parse(endOfLine, tokList);
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
return 1; return 1;
} }
@ -339,12 +339,12 @@ int DoxygenParser::addCommandLine(const std::string &theCommand,
int DoxygenParser::addCommandParagraph(const std::string &theCommand, int DoxygenParser::addCommandParagraph(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
TokenListCIt endOfParagraph = getEndOfParagraph(tokList); TokenListCIt endOfParagraph = getEndOfParagraph(tokList);
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList = parse(endOfParagraph, tokList); aNewList = parse(endOfParagraph, tokList);
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
return 1; return 1;
@ -353,7 +353,7 @@ int DoxygenParser::addCommandParagraph(const std::string &theCommand,
int DoxygenParser::addCommandEndCommand(const std::string &theCommand, int DoxygenParser::addCommandEndCommand(const std::string &theCommand,
const TokenList & tokList, const TokenList & tokList,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
TokenListCIt endCommand = getEndCommand("end" + theCommand, tokList); TokenListCIt endCommand = getEndCommand("end" + theCommand, tokList);
@ -361,7 +361,7 @@ int DoxygenParser::addCommandEndCommand(const std::string &theCommand,
printListError(WARN_DOXYGEN_COMMAND_EXPECTED, "Expected end" + theCommand); printListError(WARN_DOXYGEN_COMMAND_EXPECTED, "Expected end" + theCommand);
return 0; return 0;
} }
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList = parse(endCommand, tokList); aNewList = parse(endCommand, tokList);
m_tokenListIt++; m_tokenListIt++;
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
@ -371,7 +371,7 @@ int DoxygenParser::addCommandEndCommand(const std::string &theCommand,
int DoxygenParser::addCommandWordParagraph(const std::string &theCommand, int DoxygenParser::addCommandWordParagraph(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
@ -382,7 +382,7 @@ int DoxygenParser::addCommandWordParagraph(const std::string &theCommand,
return 0; return 0;
} }
TokenListCIt endOfParagraph = getEndOfParagraph(tokList); TokenListCIt endOfParagraph = getEndOfParagraph(tokList);
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList = parse(endOfParagraph, tokList); aNewList = parse(endOfParagraph, tokList);
aNewList.push_front(DoxygenEntity("plainstd::string", name)); aNewList.push_front(DoxygenEntity("plainstd::string", name));
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
@ -391,7 +391,7 @@ int DoxygenParser::addCommandWordParagraph(const std::string &theCommand,
int DoxygenParser::addCommandWordLine(const std::string &theCommand, int DoxygenParser::addCommandWordLine(const std::string &theCommand,
const TokenList & tokList, const TokenList & tokList,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(tokList); std::string name = getNextWord(tokList);
@ -401,7 +401,7 @@ int DoxygenParser::addCommandWordLine(const std::string &theCommand,
} }
TokenListCIt endOfLine = getOneLine(tokList); TokenListCIt endOfLine = getOneLine(tokList);
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList = parse(endOfLine, tokList); aNewList = parse(endOfLine, tokList);
aNewList.push_front(DoxygenEntity("plainstd::string", name)); aNewList.push_front(DoxygenEntity("plainstd::string", name));
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
@ -411,7 +411,7 @@ int DoxygenParser::addCommandWordLine(const std::string &theCommand,
int DoxygenParser::addCommandWordOWordOWord(const std::string &theCommand, int DoxygenParser::addCommandWordOWordOWord(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
@ -422,7 +422,7 @@ int DoxygenParser::addCommandWordOWordOWord(const std::string &theCommand,
} }
std::string headerfile = getNextWord(tokList); std::string headerfile = getNextWord(tokList);
std::string headername = getNextWord(tokList); std::string headername = getNextWord(tokList);
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList.push_back(DoxygenEntity("plainstd::string", name)); aNewList.push_back(DoxygenEntity("plainstd::string", name));
if (!headerfile.empty()) if (!headerfile.empty())
aNewList.push_back(DoxygenEntity("plainstd::string", headerfile)); aNewList.push_back(DoxygenEntity("plainstd::string", headerfile));
@ -435,12 +435,12 @@ int DoxygenParser::addCommandWordOWordOWord(const std::string &theCommand,
int DoxygenParser::addCommandOWord(const std::string &theCommand, int DoxygenParser::addCommandOWord(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(tokList); std::string name = getNextWord(tokList);
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList.push_back(DoxygenEntity("plainstd::string", name)); aNewList.push_back(DoxygenEntity("plainstd::string", name));
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
return 1; return 1;
@ -449,7 +449,7 @@ int DoxygenParser::addCommandOWord(const std::string &theCommand,
int DoxygenParser::addCommandErrorThrow(const std::string &theCommand, int DoxygenParser::addCommandErrorThrow(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &) { DoxygenEntityList &) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "Encountered: " + theCommand + printListError(WARN_DOXYGEN_COMMAND_ERROR, "Encountered: " + theCommand +
"\nThis command should not have been encountered. Behaviour past this may be unpredictable"); "\nThis command should not have been encountered. Behaviour past this may be unpredictable");
@ -460,13 +460,13 @@ int DoxygenParser::addCommandErrorThrow(const std::string &theCommand,
int DoxygenParser::addCommandUnique(const std::string &theCommand, int DoxygenParser::addCommandUnique(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
static std::map<std::string, std::string> endCommands; static std::map<std::string, std::string> endCommands;
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
if (theCommand == "arg" || theCommand == "li") { if (theCommand == "arg" || theCommand == "li") {
TokenListCIt endOfSection = getEndOfSection(theCommand, tokList); TokenListCIt endOfSection = getEndOfSection(theCommand, tokList);
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList = parse(endOfSection, tokList); aNewList = parse(endOfSection, tokList);
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
} }
@ -514,7 +514,7 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
else if (theCommand == "par") { else if (theCommand == "par") {
TokenListCIt endOfLine = getOneLine(tokList); TokenListCIt endOfLine = getOneLine(tokList);
aNewList = parse(endOfLine, tokList); aNewList = parse(endOfLine, tokList);
std::list < DoxygenEntity > aNewList2; DoxygenEntityList aNewList2;
TokenListCIt endOfParagraph = getEndOfParagraph(tokList); TokenListCIt endOfParagraph = getEndOfParagraph(tokList);
aNewList2 = parse(endOfParagraph, tokList); aNewList2 = parse(endOfParagraph, tokList);
aNewList.splice(aNewList.end(), aNewList2); aNewList.splice(aNewList.end(), aNewList2);
@ -523,7 +523,7 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
} }
// \headerfile <header-file> [<header-name>] // \headerfile <header-file> [<header-name>]
else if (theCommand == "headerfile") { else if (theCommand == "headerfile") {
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
std::string name = getNextWord(tokList); std::string name = getNextWord(tokList);
aNewList.push_back(DoxygenEntity("plainstd::string", name)); aNewList.push_back(DoxygenEntity("plainstd::string", name));
name = getNextWord(tokList); name = getNextWord(tokList);
@ -536,7 +536,7 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
else if (theCommand == "overload") { else if (theCommand == "overload") {
TokenListCIt endOfLine = getOneLine(tokList); TokenListCIt endOfLine = getOneLine(tokList);
if (endOfLine != m_tokenListIt) { if (endOfLine != m_tokenListIt) {
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList = parse(endOfLine, tokList); aNewList = parse(endOfLine, tokList);
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
} else } else
@ -552,7 +552,7 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No word followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR, "No word followed " + theCommand + " command. Not added");
return 0; return 0;
} }
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
TokenListCIt endOfLine = getOneLine(tokList); TokenListCIt endOfLine = getOneLine(tokList);
if (endOfLine != m_tokenListIt) { if (endOfLine != m_tokenListIt) {
aNewList = parse(endOfLine, tokList); aNewList = parse(endOfLine, tokList);
@ -656,7 +656,7 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
std::string caption = getNextWord(tokList); std::string caption = getNextWord(tokList);
std::string size = getNextWord(tokList); std::string size = getNextWord(tokList);
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList.push_back(DoxygenEntity("plainstd::string", format)); aNewList.push_back(DoxygenEntity("plainstd::string", format));
aNewList.push_back(DoxygenEntity("plainstd::string", file)); aNewList.push_back(DoxygenEntity("plainstd::string", file));
if (!caption.empty()) if (!caption.empty())
@ -674,7 +674,7 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No word followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR, "No word followed " + theCommand + " command. Not added");
return 0; return 0;
} }
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
TokenListCIt endOfLine = getOneLine(tokList); TokenListCIt endOfLine = getOneLine(tokList);
if (endOfLine != m_tokenListIt) { if (endOfLine != m_tokenListIt) {
aNewList = parse(endOfLine, tokList); aNewList = parse(endOfLine, tokList);
@ -726,7 +726,7 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
return 0; return 0;
} }
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
aNewList = parse(endCommand, tokList); aNewList = parse(endCommand, tokList);
if (skipEndif) if (skipEndif)
m_tokenListIt++; m_tokenListIt++;
@ -740,7 +740,7 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
int DoxygenParser::addCommand(const std::string &commandString, int DoxygenParser::addCommand(const std::string &commandString,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList) { DoxygenEntityList &doxyList) {
std::string theCommand = stringToLower(commandString); std::string theCommand = stringToLower(commandString);
if (theCommand == "plainstd::string") { if (theCommand == "plainstd::string") {
@ -778,12 +778,12 @@ int DoxygenParser::addCommand(const std::string &commandString,
} }
std::list < DoxygenEntity > DoxygenParser::parse(TokenListCIt endParsingIndex, DoxygenEntityList DoxygenParser::parse(TokenListCIt endParsingIndex,
const TokenList &tokList, const TokenList &tokList,
bool root) { bool root) {
// if we are root, than any strings should be added as 'partofdescription', else as 'plainstd::string' // if we are root, than any strings should be added as 'partofdescription', else as 'plainstd::string'
std::string currPlainstringCommandType = root ? "partofdescription" : "plainstd::string"; std::string currPlainstringCommandType = root ? "partofdescription" : "plainstd::string";
std::list < DoxygenEntity > aNewList; DoxygenEntityList aNewList;
while (m_tokenListIt != endParsingIndex) { while (m_tokenListIt != endParsingIndex) {
@ -812,13 +812,13 @@ std::list < DoxygenEntity > DoxygenParser::parse(TokenListCIt endParsingIndex,
} }
std::list < DoxygenEntity > DoxygenParser::createTree(const std::string &doxygenBlob, const std::string &fileName, int lineNumber) { DoxygenEntityList DoxygenParser::createTree(const std::string &doxygenBlob, const std::string &fileName, int lineNumber) {
TokenList tokList = tokenizeDoxygenComment(doxygenBlob, fileName, lineNumber); TokenList tokList = tokenizeDoxygenComment(doxygenBlob, fileName, lineNumber);
if (noisy) { if (noisy) {
cout << "---TOKEN LIST---" << endl; cout << "---TOKEN LIST---" << endl;
printList(); printList();
} }
std::list < DoxygenEntity > rootList; DoxygenEntityList rootList;
rootList = parse(tokList.end(), tokList, true); rootList = parse(tokList.end(), tokList, true);
if (noisy) { if (noisy) {
cout << "PARSED LIST" << endl; cout << "PARSED LIST" << endl;
@ -856,7 +856,7 @@ DoxygenParser::TokenList DoxygenParser::tokenizeDoxygenComment(const std::string
pos++; pos++;
} }
// also strip the command till the first nonalpha char // also strip the command till the first nonalpha char
for (int i = 2; i < currentWord.size(); i++) { for (size_t i = 2; i < currentWord.size(); i++) {
if (!isalpha(currentWord[i])) { if (!isalpha(currentWord[i])) {
currentWord = currentWord.substr(0, i); currentWord = currentWord.substr(0, i);
// set current parsing pos back, to parse the rest of the command // set current parsing pos back, to parse the rest of the command

View file

@ -23,7 +23,6 @@ private:
/** This class contains parts of Doxygen comment as a token. */ /** This class contains parts of Doxygen comment as a token. */
class Token { class Token {
public: public:
// typedef enum {COMMAND, PLAINSTRING, END_LINE, PARAGRAPH_END} ETokenType;
DoxyCommandEnum m_tokenType; DoxyCommandEnum m_tokenType;
std::string m_tokenString; /* the data , such as param for @param */ std::string m_tokenString; /* the data , such as param for @param */
@ -132,9 +131,9 @@ private:
TokenListCIt getEndOfParagraph(const TokenList &tokList); TokenListCIt getEndOfParagraph(const TokenList &tokList);
/* /*
* Returns the end of a section, defined as the first blank line OR first encounter of the same * Returns the end of a section, defined as the first blank line OR first
* command. Example of this behaviour is \arg * encounter of the same command. Example of this behaviour is \arg.
* if no end is encountered, returns the last token of the std::list. * If no end is encountered, returns the last token of the std::list.
*/ */
TokenListCIt getEndOfSection(const std::string &theCommand, TokenListCIt getEndOfSection(const std::string &theCommand,
const TokenList &tokList); const TokenList &tokList);
@ -149,7 +148,8 @@ private:
TokenListCIt getEndCommand(const std::string &theCommand, TokenListCIt getEndCommand(const std::string &theCommand,
const TokenList &tokList); const TokenList &tokList);
/* /*
* A specialty method for commands such as \arg that end at the end of a paragraph OR when another \arg is encountered * A special method for commands such as \arg that end at the end of a
* paragraph OR when another \arg is encountered
//TODO getTilAnyCommand //TODO getTilAnyCommand
TokenListCIt getTilAnyCommand(const std::string &theCommand, TokenListCIt getTilAnyCommand(const std::string &theCommand,
const TokenList &tokList); const TokenList &tokList);
@ -162,47 +162,51 @@ private:
* \n \\ \@ \& \$ \# \< \> \% * \n \\ \@ \& \$ \# \< \> \%
*/ */
int addSimpleCommand(const std::string &theCommand, int addSimpleCommand(const std::string &theCommand,
std::list < DoxygenEntity > &doxyList); DoxygenEntityList &doxyList);
/* /*
* CommandWord * CommandWord
* Format: @command <word> * Format: @command <word>
* Commands with a single WORD after then such as @b * Commands with a single WORD after then such as @b
* "a", "b", "c", "e", "em", "p", "def", "enum", "example", "package", * "a", "b", "c", "e", "em", "p", "def", "enum", "example", "package",
* "relates", "namespace", "relatesalso","anchor", "dontinclude", "include", "includelineno" * "relates", "namespace", "relatesalso","anchor", "dontinclude", "include",
* "includelineno"
*/ */
int addCommandWord(const std::string &theCommand, int addCommandWord(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList); DoxygenEntityList &doxyList);
/* /*
* CommandLine * CommandLine
* Format: @command (line) * Format: @command (line)
* Commands with a single LINE after then such as @var * Commands with a single LINE after then such as @var
* "addindex", "fn", "name", "line", "var", "skipline", "typedef", "skip", "until", "property" * "addindex", "fn", "name", "line", "var", "skipline", "typedef", "skip",
* "until", "property"
*/ */
int addCommandLine(const std::string &theCommand, int addCommandLine(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList); DoxygenEntityList &doxyList);
/* /*
* CommandParagraph * CommandParagraph
* Format: @command {paragraph} * Format: @command {paragraph}
* Commands with a single paragraph after then such as @return * Commands with a single paragraph after then such as @return
* "return", "remarks", "since", "test", "sa", "see", "pre", "post", "details", "invariant", * "return", "remarks", "since", "test", "sa", "see", "pre", "post",
* "deprecated", "date", "note", "warning", "version", "todo", "bug", "attention", "brief", "arg", "author" * "details", "invariant", "deprecated", "date", "note", "warning",
* "version", "todo", "bug", "attention", "brief", "arg", "author"
*/ */
int addCommandParagraph(const std::string &theCommand, int addCommandParagraph(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList); DoxygenEntityList &doxyList);
/* /*
* Command EndCommand * Command EndCommand
* Format: @command and ends at @endcommand * Format: @command and ends at @endcommand
* Commands that take in a block of text such as @code * Commands that take in a block of text such as @code:
* "code", "dot", "msc", "f$", "f[", "f{environment}{", "htmlonly", "latexonly", "manonly", * "code", "dot", "msc", "f$", "f[", "f{environment}{", "htmlonly",
* "verbatim", "xmlonly", "cond", "if", "ifnot", "link" * "latexonly", "manonly", "verbatim", "xmlonly", "cond", "if", "ifnot",
* "link"
* Returns 1 if success, 0 if the endcommand is never encountered. * Returns 1 if success, 0 if the endcommand is never encountered.
*/ */
int addCommandEndCommand(const std::string &theCommand, int addCommandEndCommand(const std::string &theCommand,
const TokenList & tokList, const TokenList & tokList,
std::list < DoxygenEntity > &doxyList); DoxygenEntityList &doxyList);
/* /*
* CommandWordParagraph * CommandWordParagraph
* Format: @command <word> {paragraph} * Format: @command <word> {paragraph}
@ -211,7 +215,7 @@ private:
*/ */
int addCommandWordParagraph(const std::string &theCommand, int addCommandWordParagraph(const std::string &theCommand,
const TokenList & tokList, const TokenList & tokList,
std::list < DoxygenEntity > &doxyList); DoxygenEntityList &doxyList);
/* /*
* CommandWordLine * CommandWordLine
* Format: @command <word> (line) * Format: @command <word> (line)
@ -220,15 +224,16 @@ private:
*/ */
int addCommandWordLine(const std::string &theCommand, int addCommandWordLine(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList); DoxygenEntityList &doxyList);
/* /*
* Command Word Optional Word Optional Word * Command Word Optional Word Optional Word
* Format: @command <word> [<header-file>] [<header-name>] * Format: @command <word> [<header-file>] [<header-name>]
* Commands such as class * Commands such as class
* "category", "class", "protocol", "interface", "struct", "union" * "category", "class", "protocol", "interface", "struct", "union"
*/ */
int addCommandWordOWordOWord(const std::string &theCommand, const TokenList &tokList, int addCommandWordOWordOWord(const std::string &theCommand,
std::list < DoxygenEntity > &doxyList); const TokenList &tokList,
DoxygenEntityList &doxyList);
/* /*
* Command Optional Word * Command Optional Word
* Format: @command [<word>] * Format: @command [<word>]
@ -237,28 +242,34 @@ private:
*/ */
int addCommandOWord(const std::string &theCommand, int addCommandOWord(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList); DoxygenEntityList &doxyList);
/* /*
* Commands that should not be encountered (such as PHP only) * Commands that should not be encountered (such as PHP only)
* goes til the end of line then returns * goes til the end of line then returns
*/ */
int addCommandErrorThrow(const std::string &theCommand, int addCommandErrorThrow(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList); DoxygenEntityList &doxyList);
/* /*
*Adds the unique commands- different process for each unique command *Adds the unique commands- different process for each unique command
*/ */
int addCommandUnique(const std::string &theCommand, const TokenList &tokList, std::list < DoxygenEntity > &doxyList); int addCommandUnique(const std::string &theCommand,
const TokenList &tokList,
DoxygenEntityList &doxyList);
/* /*
* The actual "meat" of the doxygen parser. Calls the correct addCommand* function * The actual "meat" of the doxygen parser. Calls the correct addCommand...()
* function.
*/ */
int addCommand(const std::string &commandString, int addCommand(const std::string &commandString,
const TokenList &tokList, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList); DoxygenEntityList &doxyList);
std::list < DoxygenEntity > parse(TokenListCIt endParsingIndex, DoxygenEntityList parse(TokenListCIt endParsingIndex,
const TokenList &tokList, const TokenList &tokList,
bool root = false); bool root = false);
/* /*
* Fill static doxygenCommands and sectionIndicators containers * Fill static doxygenCommands and sectionIndicators containers
@ -274,9 +285,9 @@ private:
public: public:
DoxygenParser(bool noisy = false); DoxygenParser(bool noisy = false);
virtual ~DoxygenParser(); virtual ~DoxygenParser();
std::list < DoxygenEntity > createTree(const std::string &doxygen, DoxygenEntityList createTree(const std::string &doxygen,
const std::string &fileName, const std::string &fileName,
int lineNumber); int lineNumber);
}; };
#endif #endif

View file

@ -14,16 +14,21 @@
#include "DoxygenTranslator.h" #include "DoxygenTranslator.h"
DoxygenTranslator::DoxygenTranslator(bool debugTranslator, bool debugParser) DoxygenTranslator::DoxygenTranslator(bool debugTranslator, bool debugParser) :
: debug(debugTranslator), parser(debugParser) { debug(debugTranslator),
} parser(debugParser)
{}
DoxygenTranslator::~DoxygenTranslator() { DoxygenTranslator::~DoxygenTranslator() {
} }
bool DoxygenTranslator::hasDocumentation(Node *node) { bool DoxygenTranslator::hasDocumentation(Node *node) {
return getDoxygenComment(node); return getDoxygenComment(node);
} }
String *DoxygenTranslator::getDoxygenComment(Node *node) { String *DoxygenTranslator::getDoxygenComment(Node *node) {
return Getattr(node, "doxygen"); return Getattr(node, "doxygen");
} }
@ -31,16 +36,17 @@ String *DoxygenTranslator::getDoxygenComment(Node *node) {
String *DoxygenTranslator::getDocumentation(Node *node) { String *DoxygenTranslator::getDocumentation(Node *node) {
if (!hasDocumentation(node)) if (!hasDocumentation(node)) {
return NewString(""); return NewString("");
}
return makeDocumentation(node); return makeDocumentation(node);
} }
void DoxygenTranslator::printTree(std::list < DoxygenEntity > &entityList) {
std::list < DoxygenEntity >::iterator p = entityList.begin(); void DoxygenTranslator::printTree(const DoxygenEntityList &entityList) {
while (p != entityList.end()) {
(*p).printEntity(0); for (DoxygenEntityListCIt p = entityList.begin(); p != entityList.end(); p++) {
p++; p->printEntity(0);
} }
} }

View file

@ -23,8 +23,9 @@
/* /*
* A class to translate doxygen comments attached to parser nodes * This is a base class for translator classes. It defines the basic interface
* into alternative formats for use in code generated for target languages. * for translators, which convert Doxygen comments into alternative formats for
* target languages.
*/ */
class DoxygenTranslator { class DoxygenTranslator {
public: public:
@ -32,41 +33,42 @@ public:
* Constructor * Constructor
*/ */
DoxygenTranslator(bool debugTranslator = false, bool debugParser = false); DoxygenTranslator(bool debugTranslator = false, bool debugParser = false);
/* /*
* Virtual destructor. * Virtual destructor.
*/ */
virtual ~ DoxygenTranslator(); virtual ~DoxygenTranslator();
/* /*
* Return the documentation for a given node formated for the correct * Return the documentation for a given node formated for the correct
* documentation system. * documentation system.
*/ */
String *getDocumentation(Node *node); String *getDocumentation(Node *node);
/* /*
* Whether the specified node has comment or not * Returns truem is the specified node has comment attached.
*/ */
bool hasDocumentation(Node *node); bool hasDocumentation(Node *node);
/* /*
* Get original, Doxygen-format comment string * Get original comment string in Doxygen-format.
*/ */
String *getDoxygenComment(Node *node); String *getDoxygenComment(Node *node);
protected: protected:
bool debug; bool debug;
DoxygenParser parser;
/* /*
* Overridden in subclasses to return the documentation formatted for a given * Returns the documentation formatted for a target language.
* documentation system.
*/ */
virtual String *makeDocumentation(Node *node) = 0; virtual String *makeDocumentation(Node *node) = 0;
/* /*
* Prints the details of a parsed entity list to stdout (for debugging). * Prints the details of a parsed entity list to stdout (for debugging).
*/ */
void printTree(std::list < DoxygenEntity > &entityList); void printTree(const DoxygenEntityList &entityList);
/*
* Doxygen parser object
*/
DoxygenParser parser;
}; };
#endif #endif

View file

@ -458,7 +458,7 @@ int JavaDocConverter::cleanUpTree(DoxygenEntity &root, int level)
return 0; return 0;
int removedCount = 0; int removedCount = 0;
while (root.entityList.rbegin()->typeOfEntity == "plainstd::endl") { while (!root.entityList.empty() && root.entityList.rbegin()->typeOfEntity == "plainstd::endl") {
root.entityList.pop_back(); root.entityList.pop_back();
removedCount++; removedCount++;
} }