Implemented nice error output, with filename and line number information.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-doxygen@13313 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dmitry Kabak 2012-07-10 17:17:51 +00:00
commit ed1bd4fbb9
7 changed files with 46 additions and 52 deletions

View file

@ -344,11 +344,15 @@ static int yylook(void) {
if (strncmp(loc, "/**<", 4) == 0 || strncmp(loc, "///<", 4) == 0||strncmp(loc, "/*!<", 4) == 0||strncmp(loc, "//!<", 4) == 0) {
/* printf("Doxygen Post Comment: %s lines %d-%d [%s]\n", Char(Scanner_file(scan)), Scanner_start_line(scan), Scanner_line(scan), loc); */
yylval.str = NewString(loc);
Setline(yylval.str, Scanner_start_line(scan));
Setfile(yylval.str, Scanner_file(scan));
return DOXYGENPOSTSTRING;
}
if (strncmp(loc, "/**", 3) == 0 || strncmp(loc, "///", 3) == 0||strncmp(loc, "/*!", 3) == 0||strncmp(loc, "//!", 3) == 0) {
/* printf("Doxygen Comment: %s lines %d-%d [%s]\n", Char(Scanner_file(scan)), Scanner_start_line(scan), Scanner_line(scan), loc); */
yylval.str = NewString(loc);
Setline(yylval.str, Scanner_start_line(scan));
Setfile(yylval.str, Scanner_file(scan));
return DOXYGENSTRING;
}
}

View file

@ -156,19 +156,22 @@ std::string DoxygenParser::getStringTilEndCommand(std::string theCommand, TokenL
std::string description;
if (tokList.peek().tokenType == 0)
return "";
while (tokList.next().tokenString.compare(theCommand) != 0) {
while (tokList.current() != tokList.end()) {
//TODO: it won't output doxygen commands, need a way to fix it
if (tokList.peek().tokenType == PLAINSTRING)
description += tokList.peek().tokenString + " ";
if (tokList.peek().tokenType == END_LINE)
description += "\n";
if (tokList.current() == tokList.end()) {
cout << "Error, @" << theCommand << " command expected." << endl;
break;
if (tokList.peek().tokenString.compare(theCommand) == 0) {
tokList.next();
return description;
}
tokList.next();
}
tokList.next(); // eat the end command itself
tokList.printListError(theCommand + " command expected");
return description;
}
@ -263,7 +266,7 @@ int DoxygenParser::addCommandWord(std::string theCommand, TokenList & tokList, s
doxyList.push_back(DoxygenEntity(theCommand, name));
return 1;
} else
cout << "No word followed " << theCommand << " command. Not added" << endl;
tokList.printListError("No word followed " + theCommand + " command. Not added");
return 0;
}
@ -275,7 +278,7 @@ int DoxygenParser::ignoreCommandWord(std::string theCommand, TokenList & tokList
if (!name.empty())
return 1;
else
cout << "WARNING: No word followed " << theCommand << " command." << endl;
tokList.printListError("No word followed " + theCommand + " command.");
return 0;
}
@ -329,7 +332,7 @@ int DoxygenParser::addCommandWordParagraph(std::string theCommand, TokenList & t
cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(tokList);
if (name.empty()) {
cout << "No word followed " << theCommand << " command. Not added" << endl;
tokList.printListError("No word followed " + theCommand + " command. Not added");
return 0;
}
std::list < Token >::iterator endOfParagraph = getEndOfParagraph(tokList);
@ -345,7 +348,7 @@ int DoxygenParser::addCommandWordLine(std::string theCommand, TokenList & tokLis
cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(tokList);
if (name.empty()) {
cout << "No word followed " << theCommand << " command. Not added" << endl;
tokList.printListError("No word followed " + theCommand + " command. Not added");
return 0;
}
std::list < Token >::iterator endOfLine = getOneLine(tokList);
@ -362,7 +365,7 @@ int DoxygenParser::addCommandWordOWordOWord(std::string theCommand, TokenList &
cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(tokList);
if (name.empty()) {
cout << "No word followed " << theCommand << " command. Not added" << endl;
tokList.printListError("No word followed " + theCommand + " command. Not added");
return 0;
}
std::string headerfile = getNextWord(tokList);
@ -387,10 +390,8 @@ int DoxygenParser::addCommandOWord(std::string theCommand, TokenList & tokList,
int DoxygenParser::addCommandErrorThrow(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList) {
#pragma unused(doxyList)
if (noisy) {
cout << "Encountered :" << theCommand << endl;
cout << "This command should not have been encountered. Behaviour past this may be unpredictable " << endl;
}
tokList.printListError("Encountered: " + theCommand +
"\nThis command should not have been encountered. Behaviour past this may be unpredictable");
std::list < Token >::iterator endOfLine = getOneLine(tokList);
tokList.setIterator(endOfLine);
return 0;
@ -464,7 +465,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(tokList);
if (name.empty()) {
cout << "No word followed " << theCommand << " command. Not added" << endl;
tokList.printListError("No word followed " + theCommand + " command. Not added");
return 0;
}
std::list < DoxygenEntity > aNewList;
@ -509,7 +510,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(tokList);
if (name.empty()) {
cout << "No word followed " << theCommand << " command. Not added" << endl;
tokList.printListError("No word followed " + theCommand + " command. Not added");
return 0;
}
std::list < DoxygenEntity > aNewList;
@ -611,8 +612,8 @@ std::list < DoxygenEntity > DoxygenParser::parse(std::list < Token >::iterator e
return aNewList;
}
std::list < DoxygenEntity > DoxygenParser::createTree(std::string doxygenBlob) {
TokenList tokList = TokenList(doxygenBlob);
std::list < DoxygenEntity > DoxygenParser::createTree(std::string doxygenBlob, std::string fileName, int lineNumber) {
TokenList tokList(doxygenBlob, fileName, lineNumber);
if (noisy) {
cout << "---TOKEN LIST---" << endl;
tokList.printList();

View file

@ -21,7 +21,7 @@ class DoxygenParser {
public:
DoxygenParser();
virtual ~DoxygenParser();
std::list < DoxygenEntity > createTree(std::string doxygen);
std::list < DoxygenEntity > createTree(std::string doxygen, std::string fileName, int lineNumber);
private:
/*

View file

@ -163,7 +163,9 @@ void JavaDocConverter::handleParagraph(JavaDocConverter* converter, DoxygenEntit
translatedComment += converter->formatCommand(converter->translateSubtree(tag), 0);
}
void JavaDocConverter::handlePlainString(JavaDocConverter* converter, DoxygenEntity& tag, std::string& translatedComment) {
translatedComment += tag.data + " ";
translatedComment += tag.data;
if (tag.data.size() && tag.data[tag.data.size()-1] != ' ')
translatedComment += " ";
}
String *JavaDocConverter::makeDocumentation(Node *node) {
@ -174,7 +176,7 @@ String *JavaDocConverter::makeDocumentation(Node *node) {
return NULL;
}
std::list < DoxygenEntity > entityList = parser.createTree(Char(documentation));
std::list < DoxygenEntity > entityList = parser.createTree(Char(documentation), Char(Getfile(documentation)), Getline(documentation));
// entityList.sort(CompareDoxygenEntities()); sorting currently not used,
// see CompareDoxygenEntities::operator() in DoxygenEntity.cpp

View file

@ -170,7 +170,7 @@ String *PyDocConverter::makeDocumentation(Node *n) {
while (n) {
documentation = getDoxygenComment(n);
if (!Swig_is_generated_overload(n) && documentation) {
std::list < DoxygenEntity > entityList = DoxygenParser().createTree(Char(documentation));
std::list < DoxygenEntity > entityList = parser.createTree(Char(documentation), Char(Getfile(documentation)), Getline(documentation));
allDocumentation.push_back(processEntityList(n, entityList));
}
n = Getattr(n, "sym:nextSibling");
@ -194,7 +194,7 @@ String *PyDocConverter::makeDocumentation(Node *n) {
else {
documentation = getDoxygenComment(n);
if (documentation != NULL) {
std::list < DoxygenEntity > entityList = DoxygenParser().createTree(Char(documentation));
std::list < DoxygenEntity > entityList = parser.createTree(Char(documentation), Char(Getfile(documentation)), Getline(documentation));
pyDocString = processEntityList(n, entityList);
}
}

View file

@ -14,6 +14,7 @@
#include <iostream>
#include <string>
#include <list>
#include "swig.h"
#include "Token.h"
#include "DoxygenEntity.h"
#define TOKENSPERLINE 8; //change this to change the printing behaviour of the token list
@ -22,37 +23,11 @@ using namespace std;
int noisy2 = 0;
/* The tokenizer*/
TokenList::TokenList(const std::string & doxygenStringConst) {
TokenList::TokenList(const std::string & doxygenStringConst, const std::string fileName, int fileLine)
: fileName(fileName), fileLine(fileLine) {
size_t commentPos;
string doxygenString = doxygenStringConst;
/* Comment start tokens are replaced in parser.y, see doxygen_comment and
doxygen_post_comment_item
do {
commentPos = doxygenString.find("///<");
if (commentPos != string::npos) {
doxygenString.replace(commentPos, 4, " ");
continue;
}
commentPos = doxygenString.find("/**<");
if (commentPos != string::npos) {
doxygenString.replace(commentPos, 4, " ");
continue;
}
commentPos = doxygenString.find("/*!<");
if (commentPos != string::npos) {
doxygenString.replace(commentPos, 4, " ");
continue;
}
commentPos = doxygenString.find("//!<");
if (commentPos != string::npos) {
doxygenString.replace(commentPos, 4, " ");
continue;
}
break;
} while (true);
*/
size_t currentIndex = 0;
size_t nextIndex = 0;
@ -174,3 +149,11 @@ void TokenList::printList() {
i++;
}
}
void TokenList::printListError(std::string message) {
int curLine = fileLine;
for (list< Token >::iterator it = m_tokenList.begin(); it != current(); it++)
if (it->tokenType == END_LINE)
curLine++;
Swig_error(fileName.c_str(), curLine, "Doxygen parser error: %s. \n", message.c_str());
}

View file

@ -25,9 +25,12 @@ class TokenList {
private:
std::list < Token > m_tokenList;
std::list < Token >::iterator m_tokenListIter;
// location info for error output
std::string fileName;
int fileLine;
public:
TokenList(const std::string & doxygenString); /* constructor takes a blob of Doxygen comment */
TokenList(const std::string & doxygenString, const std::string fileName, int fileLine); /* constructor takes a blob of Doxygen comment */
~TokenList();
Token peek(); /* returns next token without advancing */
@ -40,6 +43,7 @@ public:
void setIterator(list < Token >::iterator newPosition); /*moves up the iterator */
void printList(); /* prints out the sequence of tokens */
void printListError(std::string message); /* prints properly formatted error message */
};
#endif