1. Parser improvements
a) const and virtual methods are parsed correctly (not static yet) b) "const" which is part of the return type is not swallowed 2. HelpGen improvements: -o outputdir parameter added to the cmd line, "//---------" kind comments discarded now. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1700 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -42,7 +42,7 @@ protected:
|
|||||||
char* cur;
|
char* cur;
|
||||||
|
|
||||||
// about the current class
|
// about the current class
|
||||||
bool mIsVirtaul;
|
bool mIsVirtual;
|
||||||
bool mIsTemplate;
|
bool mIsTemplate;
|
||||||
size_t mNestingLevel;
|
size_t mNestingLevel;
|
||||||
|
|
||||||
|
@@ -84,7 +84,7 @@ static const char *GetCurrentTime(const char *timeFormat);
|
|||||||
class wxTeXFile : public wxFile
|
class wxTeXFile : public wxFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxTeXFile() : wxFile() { }
|
wxTeXFile() { }
|
||||||
|
|
||||||
bool WriteTeX(const wxString& s)
|
bool WriteTeX(const wxString& s)
|
||||||
{
|
{
|
||||||
@@ -93,19 +93,26 @@ public:
|
|||||||
|
|
||||||
return wxFile::Write(t);
|
return wxFile::Write(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxTeXFile(const wxTeXFile&);
|
||||||
|
wxTeXFile& operator=(const wxTeXFile&);
|
||||||
};
|
};
|
||||||
|
|
||||||
class HelpGenVisitor : public spVisitor
|
class HelpGenVisitor : public spVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// ctor
|
// ctor
|
||||||
HelpGenVisitor();
|
HelpGenVisitor(const wxString& directoryOut) : m_directoryOut(directoryOut)
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void VisitFile( spFile& fl );
|
virtual void VisitFile( spFile& fl );
|
||||||
virtual void VisitClass( spClass& cl );
|
virtual void VisitClass( spClass& cl );
|
||||||
virtual void VisitEnumeration( spEnumeration& en );
|
virtual void VisitEnumeration( spEnumeration& en );
|
||||||
virtual void VisitTypeDef( spTypeDef& td );
|
virtual void VisitTypeDef( spTypeDef& td );
|
||||||
virtual void VisitPreprocessorLine( spPreprocessorLine& pd );
|
virtual void VisitPreprocessorLine( spPreprocessorLine& pd );
|
||||||
virtual void VisitAttribute( spAttribute& attr );
|
virtual void VisitAttribute( spAttribute& attr );
|
||||||
virtual void VisitOperation( spOperation& op );
|
virtual void VisitOperation( spOperation& op );
|
||||||
virtual void VisitParameter( spParameter& param );
|
virtual void VisitParameter( spParameter& param );
|
||||||
@@ -131,7 +138,8 @@ protected:
|
|||||||
// terminate the function documentation if it was started
|
// terminate the function documentation if it was started
|
||||||
void CloseFunction();
|
void CloseFunction();
|
||||||
|
|
||||||
wxTeXFile m_file; // file we're writing to now
|
wxString m_directoryOut; // directory for the output
|
||||||
|
wxTeXFile m_file; // file we're writing to now
|
||||||
|
|
||||||
// state variables
|
// state variables
|
||||||
bool m_inClass, // TRUE after file successfully opened
|
bool m_inClass, // TRUE after file successfully opened
|
||||||
@@ -147,6 +155,10 @@ protected:
|
|||||||
|
|
||||||
// headers included by this file
|
// headers included by this file
|
||||||
wxArrayString m_headers;
|
wxArrayString m_headers;
|
||||||
|
|
||||||
|
private:
|
||||||
|
HelpGenVisitor(const HelpGenVisitor&);
|
||||||
|
HelpGenVisitor& operator=(const HelpGenVisitor&);
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -160,7 +172,7 @@ protected:
|
|||||||
// this function never returns
|
// this function never returns
|
||||||
static void usage()
|
static void usage()
|
||||||
{
|
{
|
||||||
wxLogError("usage: HelpGen [-q|-v] <header files...>\n");
|
wxLogError("usage: HelpGen [-q|-v] [-o outdir] <header files...>\n");
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -171,27 +183,63 @@ int main(int argc, char **argv)
|
|||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString directoryOut;
|
||||||
|
|
||||||
int first;
|
int first;
|
||||||
for ( first = 1; (first < argc) && argv[first][0] == '-'; first++ ) {
|
for ( first = 1; (first < argc) && argv[first][0] == '-'; first++ ) {
|
||||||
switch ( argv[first][1] ) {
|
// all options have one letter
|
||||||
case 'v':
|
if ( argv[first][2] == '\0' ) {
|
||||||
// be verbose
|
switch ( argv[first][1] ) {
|
||||||
wxLog::GetActiveTarget()->SetVerbose();
|
case 'v':
|
||||||
break;
|
// be verbose
|
||||||
|
wxLog::GetActiveTarget()->SetVerbose();
|
||||||
|
continue;
|
||||||
|
|
||||||
case 'q':
|
case 'q':
|
||||||
// be quiet
|
// be quiet
|
||||||
wxLog::GetActiveTarget()->SetVerbose(false);
|
wxLog::GetActiveTarget()->SetVerbose(false);
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
default:
|
case 'o':
|
||||||
usage();
|
first++;
|
||||||
|
if ( first >= argc ) {
|
||||||
|
wxLogError("-o option requires an argument.");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
directoryOut = argv[first];
|
||||||
|
if ( !!directoryOut ) {
|
||||||
|
// terminate with a '/' if it doesn't have it
|
||||||
|
switch ( directoryOut.Last() ) {
|
||||||
|
case '/':
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
case '\\':
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
directoryOut += '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//else: it's empty, do nothing
|
||||||
|
|
||||||
|
continue;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only get here after a break from switch or from else branch of if
|
||||||
|
wxLogError("unknown option '%s'", argv[first]);
|
||||||
|
|
||||||
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a parser object and a visitor derivation
|
// create a parser object and a visitor derivation
|
||||||
CJSourceParser parser;
|
CJSourceParser parser;
|
||||||
HelpGenVisitor visitor;
|
HelpGenVisitor visitor(directoryOut);
|
||||||
|
|
||||||
// parse all files
|
// parse all files
|
||||||
for ( int i = first; i < argc; i++ ) {
|
for ( int i = first; i < argc; i++ ) {
|
||||||
@@ -213,11 +261,6 @@ int main(int argc, char **argv)
|
|||||||
// HelpGenVisitor implementation
|
// HelpGenVisitor implementation
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
HelpGenVisitor::HelpGenVisitor()
|
|
||||||
{
|
|
||||||
Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HelpGenVisitor::Reset()
|
void HelpGenVisitor::Reset()
|
||||||
{
|
{
|
||||||
m_inClass =
|
m_inClass =
|
||||||
@@ -301,9 +344,12 @@ void HelpGenVisitor::VisitClass( spClass& cl )
|
|||||||
|
|
||||||
// the file name is built from the class name by removing the leading "wx"
|
// the file name is built from the class name by removing the leading "wx"
|
||||||
// if any and converting it to the lower case
|
// if any and converting it to the lower case
|
||||||
wxString filename = name;
|
wxString filename = m_directoryOut;
|
||||||
if ( filename(0, 2) == "wx" ) {
|
if ( name(0, 2) == "wx" ) {
|
||||||
filename.erase(0, 2);
|
filename << name.c_str() + 2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
filename << name;
|
||||||
}
|
}
|
||||||
|
|
||||||
filename.MakeLower();
|
filename.MakeLower();
|
||||||
@@ -329,7 +375,12 @@ void HelpGenVisitor::VisitClass( spClass& cl )
|
|||||||
// write out the header
|
// write out the header
|
||||||
{
|
{
|
||||||
wxString header;
|
wxString header;
|
||||||
header.Printf("% automatically generated by HelpGen from %s at %s\n"
|
header.Printf("%%\n"
|
||||||
|
"%% automatically generated by HelpGen from\n"
|
||||||
|
"%% %s at %s\n"
|
||||||
|
"%%\n"
|
||||||
|
"\n"
|
||||||
|
"\n"
|
||||||
"\\section{\\class{%s}}\\label{%s}\n",
|
"\\section{\\class{%s}}\\label{%s}\n",
|
||||||
filename.c_str(), GetCurrentTime("%d/%b/%y %H:%M:%S"),
|
filename.c_str(), GetCurrentTime("%d/%b/%y %H:%M:%S"),
|
||||||
name.c_str(), wxString(name).MakeLower().c_str());
|
name.c_str(), wxString(name).MakeLower().c_str());
|
||||||
@@ -430,7 +481,7 @@ void HelpGenVisitor::VisitClass( spClass& cl )
|
|||||||
|
|
||||||
wxString baseclass = *i;
|
wxString baseclass = *i;
|
||||||
derived << "\\helpref{" << baseclass << "}";
|
derived << "\\helpref{" << baseclass << "}";
|
||||||
derived << "{" << baseclass.MakeLower() << "}";
|
derived << "{" << baseclass.MakeLower() << "}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
totalText << derived << "\n\n";
|
totalText << derived << "\n\n";
|
||||||
@@ -574,7 +625,9 @@ void HelpGenVisitor::VisitOperation( spOperation& op )
|
|||||||
funcname = dtor;
|
funcname = dtor;
|
||||||
}
|
}
|
||||||
|
|
||||||
totalText.Printf("\\membersection{%s::%s}\\label{%s}\n\n"
|
totalText.Printf("\n"
|
||||||
|
"\\membersection{%s::%s}\\label{%s}\n"
|
||||||
|
"\n"
|
||||||
"\\%sfunc{%s%s}{%s}{",
|
"\\%sfunc{%s%s}{%s}{",
|
||||||
classname, funcname,
|
classname, funcname,
|
||||||
MakeLabel(classname, funcname).c_str(),
|
MakeLabel(classname, funcname).c_str(),
|
||||||
@@ -665,15 +718,23 @@ static void TeXFilter(wxString* str)
|
|||||||
|
|
||||||
static wxString GetAllComments(const spContext& ctx)
|
static wxString GetAllComments(const spContext& ctx)
|
||||||
{
|
{
|
||||||
wxString comment;
|
wxString comments;
|
||||||
const MCommentListT& comments = ctx.GetCommentList();
|
const MCommentListT& commentsList = ctx.GetCommentList();
|
||||||
for ( MCommentListT::const_iterator i = comments.begin();
|
for ( MCommentListT::const_iterator i = commentsList.begin();
|
||||||
i != comments.end();
|
i != commentsList.end();
|
||||||
i++ ) {
|
i++ ) {
|
||||||
comment << (*i)->GetText();
|
wxString comment = (*i)->GetText();
|
||||||
|
|
||||||
|
// don't take comments like "// ----------" &c
|
||||||
|
comment.Trim(FALSE);
|
||||||
|
if ( !!comment &&
|
||||||
|
comment == wxString(comment[0u], comment.length() - 1) + '\n' )
|
||||||
|
comments << "\n";
|
||||||
|
else
|
||||||
|
comments << comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
return comment;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *GetCurrentTime(const char *timeFormat)
|
static const char *GetCurrentTime(const char *timeFormat)
|
||||||
|
@@ -923,7 +923,7 @@ static bool is_keyword( char* cur )
|
|||||||
// restore original character suppresed by terminating zero
|
// restore original character suppresed by terminating zero
|
||||||
*(cur + len) = tmp;
|
*(cur + len) = tmp;
|
||||||
|
|
||||||
return ( i != __gMultiLangMap.end() );
|
return i == __gMultiLangMap.end() ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void get_string_between( char* start, char* end,
|
static inline void get_string_between( char* start, char* end,
|
||||||
@@ -979,7 +979,7 @@ spFile* CJSourceParser::Parse( char* start, char* end )
|
|||||||
spFile* pTopCtx = new spFile();
|
spFile* pTopCtx = new spFile();
|
||||||
mpCurCtx = pTopCtx;
|
mpCurCtx = pTopCtx;
|
||||||
|
|
||||||
mIsVirtaul = 0;
|
mIsVirtual = 0;
|
||||||
mIsTemplate = 0;
|
mIsTemplate = 0;
|
||||||
mNestingLevel = 0;
|
mNestingLevel = 0;
|
||||||
|
|
||||||
@@ -1008,7 +1008,7 @@ spFile* CJSourceParser::Parse( char* start, char* end )
|
|||||||
) == 0
|
) == 0
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int o;
|
int o = 0;
|
||||||
++o;
|
++o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1047,7 +1047,8 @@ spFile* CJSourceParser::Parse( char* start, char* end )
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_keyword( cur ) )
|
// 'const' is a part of the return type, not a keyword here
|
||||||
|
if ( strncmp(cur, "const", 5) != 0 && is_keyword( cur ) )
|
||||||
{
|
{
|
||||||
// parses, token, if token identifies
|
// parses, token, if token identifies
|
||||||
// the container context (e.g. class/namespace)
|
// the container context (e.g. class/namespace)
|
||||||
@@ -1445,7 +1446,7 @@ void CJSourceParser::ParseKeyword( char*& cur )
|
|||||||
if ( cmp_tokens_fast( cur, "virtual", len ) )
|
if ( cmp_tokens_fast( cur, "virtual", len ) )
|
||||||
{
|
{
|
||||||
// probably the virtual method is in front of us;
|
// probably the virtual method is in front of us;
|
||||||
mIsVirtaul = 1;
|
mIsVirtual = 1;
|
||||||
skip_token( cur );
|
skip_token( cur );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1480,8 +1481,12 @@ bool CJSourceParser::ParseNameAndRetVal( char*& cur, bool& isAMacro )
|
|||||||
|
|
||||||
char* start = cur;
|
char* start = cur;
|
||||||
|
|
||||||
|
bool isVirtual = false;
|
||||||
while( *cur != '(' )
|
while( *cur != '(' )
|
||||||
{
|
{
|
||||||
|
if ( get_token_str( cur ) == "virtual" )
|
||||||
|
isVirtual = true;
|
||||||
|
|
||||||
skip_token( cur );
|
skip_token( cur );
|
||||||
if ( !get_next_token( cur ) ) return FALSE;
|
if ( !get_next_token( cur ) ) return FALSE;
|
||||||
}
|
}
|
||||||
@@ -1524,6 +1529,7 @@ bool CJSourceParser::ParseNameAndRetVal( char*& cur, bool& isAMacro )
|
|||||||
|
|
||||||
mpCurCtx->AddMember( pOp );
|
mpCurCtx->AddMember( pOp );
|
||||||
pOp->mVisibility = mCurVis;
|
pOp->mVisibility = mCurVis;
|
||||||
|
pOp->mIsVirtual = isVirtual;
|
||||||
|
|
||||||
// add comments about operation
|
// add comments about operation
|
||||||
AttachComments( *pOp, cur );
|
AttachComments( *pOp, cur );
|
||||||
@@ -1610,7 +1616,8 @@ bool CJSourceParser::ParseArguments( char*& cur )
|
|||||||
if ( blocksSkipped == 0 )
|
if ( blocksSkipped == 0 )
|
||||||
{
|
{
|
||||||
if ( *cur == 10 ) ++_gLineNo;
|
if ( *cur == 10 ) ++_gLineNo;
|
||||||
++cur;
|
++cur; // skip ')'
|
||||||
|
|
||||||
break; // function without paramters
|
break; // function without paramters
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1674,6 +1681,10 @@ bool CJSourceParser::ParseArguments( char*& cur )
|
|||||||
|
|
||||||
} while(1);
|
} while(1);
|
||||||
|
|
||||||
|
// skip possible whitespace between ')' and following "const"
|
||||||
|
while ( isspace(*cur) )
|
||||||
|
cur++;
|
||||||
|
|
||||||
// check if it was really a function not a macro,
|
// check if it was really a function not a macro,
|
||||||
// if so, than it should be terminated with semicolon ';'
|
// if so, than it should be terminated with semicolon ';'
|
||||||
// or opening implemenetaton bracket '{'
|
// or opening implemenetaton bracket '{'
|
||||||
@@ -1710,6 +1721,8 @@ bool CJSourceParser::ParseArguments( char*& cur )
|
|||||||
|
|
||||||
if ( cmp_tokens_fast( tok, "const", 5 ) )
|
if ( cmp_tokens_fast( tok, "const", 5 ) )
|
||||||
{
|
{
|
||||||
|
((spOperation*)mpCurCtx)->mIsConstant = true;
|
||||||
|
|
||||||
skip_token(tok);
|
skip_token(tok);
|
||||||
if ( !get_next_token(tok) ) return FALSE;
|
if ( !get_next_token(tok) ) return FALSE;
|
||||||
continue;
|
continue;
|
||||||
|
@@ -414,7 +414,11 @@ void spClass::SortMembers()
|
|||||||
spOperation::spOperation()
|
spOperation::spOperation()
|
||||||
|
|
||||||
: mHasDefinition( FALSE )
|
: mHasDefinition( FALSE )
|
||||||
{}
|
{
|
||||||
|
mIsConstant =
|
||||||
|
mIsVirtual =
|
||||||
|
mHasDefinition = false;
|
||||||
|
}
|
||||||
|
|
||||||
string spOperation::GetFullName(MarkupTagsT tags)
|
string spOperation::GetFullName(MarkupTagsT tags)
|
||||||
{
|
{
|
||||||
|
@@ -34,9 +34,9 @@ void WXDLLEXPORT wxSplitPath(const char *pszFileName,
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( pszFileName, _("NULL file name in wxSplitPath") );
|
wxCHECK_RET( pszFileName, _("NULL file name in wxSplitPath") );
|
||||||
|
|
||||||
const char *pDot = strrchr(pszFileName, FILE_SEP_EXT);
|
const char *pDot = strrchr(pszFileName, wxFILE_SEP_EXT);
|
||||||
const char *pSepUnix = strrchr(pszFileName, FILE_SEP_PATH_UNIX);
|
const char *pSepUnix = strrchr(pszFileName, wxFILE_SEP_PATH_UNIX);
|
||||||
const char *pSepDos = strrchr(pszFileName, FILE_SEP_PATH_DOS);
|
const char *pSepDos = strrchr(pszFileName, wxFILE_SEP_PATH_DOS);
|
||||||
|
|
||||||
// take the last of the two
|
// take the last of the two
|
||||||
size_t nPosUnix = pSepUnix ? pSepUnix - pszFileName : 0;
|
size_t nPosUnix = pSepUnix ? pSepUnix - pszFileName : 0;
|
||||||
|
Reference in New Issue
Block a user