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
char* cur;
// about the current class
char* cur;
// about the current class
bool mIsTemplate;
size_t mNestingLevel;
bool mIsTemplate;
size_t mNestingLevel;
TODO (+ means fixed)
(i) small fixes in the current version
TODO (+ means fixed)
(i) small fixes in the current version
+1. Quote special TeX characters like '&' and '_' (=> derive from wxFile)
2. Document typedefs
3. Document global variables
+1. Quote special TeX characters like '&' and '_' (=> derive from wxFile)
2. Document typedefs
3. Document global variables
(ii) plans for version 2
1. Use wxTextFile for direct file access to avoid one scan method problems
2. Use command line parsrer class for the options
(ii) plans for version 2
1. Use wxTextFile for direct file access to avoid one scan method problems
2. Use command line parsrer class for the options
*/
// =============================================================================
*/
// =============================================================================
class wxTeXFile : public wxFile
{
public:
class wxTeXFile : public wxFile
{
public:
- wxTeXFile() : wxFile() { }
bool WriteTeX(const wxString& s)
{
bool WriteTeX(const wxString& s)
{
return wxFile::Write(t);
}
return wxFile::Write(t);
}
+
+private:
+ wxTeXFile(const wxTeXFile&);
+ wxTeXFile& operator=(const wxTeXFile&);
};
class HelpGenVisitor : public spVisitor
{
public:
// ctor
};
class HelpGenVisitor : public spVisitor
{
public:
// ctor
+ HelpGenVisitor(const wxString& directoryOut) : m_directoryOut(directoryOut)
+ {
+ Reset();
+ }
virtual void VisitFile( spFile& fl );
virtual void VisitClass( spClass& cl );
virtual void VisitEnumeration( spEnumeration& en );
virtual void VisitTypeDef( spTypeDef& td );
virtual void VisitFile( spFile& fl );
virtual void VisitClass( spClass& cl );
virtual void VisitEnumeration( spEnumeration& en );
virtual void VisitTypeDef( spTypeDef& td );
- virtual void VisitPreprocessorLine( spPreprocessorLine& pd );
+ virtual void VisitPreprocessorLine( spPreprocessorLine& pd );
virtual void VisitAttribute( spAttribute& attr );
virtual void VisitOperation( spOperation& op );
virtual void VisitParameter( spParameter& param );
virtual void VisitAttribute( spAttribute& attr );
virtual void VisitOperation( spOperation& op );
virtual void VisitParameter( spParameter& param );
// write the headers for corresponding sections (only once)
void InsertDataStructuresHeader();
void InsertMethodsHeader();
// write the headers for corresponding sections (only once)
void InsertDataStructuresHeader();
void InsertMethodsHeader();
// terminate the function documentation if it was started
void CloseFunction();
// terminate the function documentation if it was started
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
bool m_inClass, // TRUE after file successfully opened
// state variables
bool m_inClass, // TRUE after file successfully opened
m_textStoredTypedefs,
m_textStoredFunctionComment;
m_textStoredTypedefs,
m_textStoredFunctionComment;
- // headers included by this file
+ // headers included by this file
+
+private:
+ HelpGenVisitor(const HelpGenVisitor&);
+ HelpGenVisitor& operator=(const HelpGenVisitor&);
};
// -----------------------------------------------------------------------------
};
// -----------------------------------------------------------------------------
// this function never returns
static void usage()
{
// this function never returns
static void usage()
{
- wxLogError("usage: HelpGen [-q|-v] <header files...>\n");
+ wxLogError("usage: HelpGen [-q|-v] [-o outdir] <header files...>\n");
+ wxString directoryOut;
+
int first;
for ( first = 1; (first < argc) && argv[first][0] == '-'; first++ ) {
int first;
for ( first = 1; (first < argc) && argv[first][0] == '-'; first++ ) {
- switch ( argv[first][1] ) {
- case 'v':
- // be verbose
- wxLog::GetActiveTarget()->SetVerbose();
- break;
+ // all options have one letter
+ if ( argv[first][2] == '\0' ) {
+ switch ( argv[first][1] ) {
+ case 'v':
+ // be verbose
+ wxLog::GetActiveTarget()->SetVerbose();
+ continue;
+
+ case 'q':
+ // be quiet
+ wxLog::GetActiveTarget()->SetVerbose(false);
+ continue;
+
+ case 'o':
+ 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;
- case 'q':
- // be quiet
- wxLog::GetActiveTarget()->SetVerbose(false);
- break;
+ default:
+ directoryOut += '/';
+ }
+ }
+ //else: it's empty, do nothing
+
+ continue;
+
+ // 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
CJSourceParser parser;
}
// create a parser object and a visitor derivation
CJSourceParser parser;
- HelpGenVisitor visitor;
+ HelpGenVisitor visitor(directoryOut);
// parse all files
for ( int i = first; i < argc; i++ ) {
// parse all files
for ( int i = first; i < argc; i++ ) {
// HelpGenVisitor implementation
// -----------------------------------------------------------------------------
// HelpGenVisitor implementation
// -----------------------------------------------------------------------------
-HelpGenVisitor::HelpGenVisitor()
-{
- Reset();
-}
-
void HelpGenVisitor::Reset()
{
m_inClass =
void HelpGenVisitor::Reset()
{
m_inClass =
// the file name is built from the class name by removing the leading "wx"
// if any and converting it to the lower case
// the file name is built from the class name by removing the leading "wx"
// if any and converting it to the lower case
- wxString filename = name;
- if ( filename(0, 2) == "wx" ) {
- filename.erase(0, 2);
+ wxString filename = m_directoryOut;
+ if ( name(0, 2) == "wx" ) {
+ filename << name.c_str() + 2;
+ }
+ else {
+ filename << name;
// write out the header
{
wxString header;
// write out the 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",
filename.c_str(), GetCurrentTime("%d/%b/%y %H:%M:%S"),
name.c_str(), wxString(name).MakeLower().c_str());
"\\section{\\class{%s}}\\label{%s}\n",
filename.c_str(), GetCurrentTime("%d/%b/%y %H:%M:%S"),
name.c_str(), wxString(name).MakeLower().c_str());
"defs",
"string",
"dynarray",
"defs",
"string",
"dynarray",
wxString baseclass = *i;
derived << "\\helpref{" << baseclass << "}";
wxString baseclass = *i;
derived << "\\helpref{" << baseclass << "}";
- derived << "{" << baseclass.MakeLower() << "}";
+ derived << "{" << baseclass.MakeLower() << "}";
}
}
totalText << derived << "\n\n";
}
}
totalText << derived << "\n\n";
wxString totalText;
const char *funcname = op.GetName().c_str();
const char *classname = op.GetClass().GetName().c_str();
wxString totalText;
const char *funcname = op.GetName().c_str();
const char *classname = op.GetClass().GetName().c_str();
// check for the special case of dtor
wxString dtor;
if ( (funcname[0] == '~') && (strcmp(funcname + 1, classname) == 0) ) {
// check for the special case of dtor
wxString dtor;
if ( (funcname[0] == '~') && (strcmp(funcname + 1, classname) == 0) ) {
- totalText.Printf("\\membersection{%s::%s}\\label{%s}\n\n"
+ totalText.Printf("\n"
+ "\\membersection{%s::%s}\\label{%s}\n"
+ "\n"
"\\%sfunc{%s%s}{%s}{",
classname, funcname,
MakeLabel(classname, funcname).c_str(),
"\\%sfunc{%s%s}{%s}{",
classname, funcname,
MakeLabel(classname, funcname).c_str(),
else {
totalText << ", ";
}
else {
totalText << ", ";
}
totalText << "\\param{" << param.mType << " }{" << param.GetName();
wxString defvalue = param.mInitVal;
if ( !defvalue.IsEmpty() ) {
totalText << " = " << defvalue;
}
totalText << "\\param{" << param.mType << " }{" << param.GetName();
wxString defvalue = param.mInitVal;
if ( !defvalue.IsEmpty() ) {
totalText << " = " << defvalue;
}
totalText << '}';
m_file.WriteTeX(totalText);
totalText << '}';
m_file.WriteTeX(totalText);
// but may be later others will be added
static const char *macros[] = { "destruct" };
static const char *replacement[] = { "dtor" };
// but may be later others will be added
static const char *macros[] = { "destruct" };
static const char *replacement[] = { "dtor" };
size_t n;
for ( n = 0; n < WXSIZEOF(macros); n++ ) {
if ( strncmp(funcname + 1, macros[n], strlen(macros[n])) == 0 ) {
size_t n;
for ( n = 0; n < WXSIZEOF(macros); n++ ) {
if ( strncmp(funcname + 1, macros[n], strlen(macros[n])) == 0 ) {
static wxString GetAllComments(const spContext& ctx)
{
static wxString GetAllComments(const spContext& ctx)
{
- wxString comment;
- const MCommentListT& comments = ctx.GetCommentList();
- for ( MCommentListT::const_iterator i = comments.begin();
- i != comments.end();
- i++ ) {
- comment << (*i)->GetText();
+ wxString comments;
+ const MCommentListT& commentsList = ctx.GetCommentList();
+ for ( MCommentListT::const_iterator i = commentsList.begin();
+ i != commentsList.end();
+ i++ ) {
+ 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;
}
static const char *GetCurrentTime(const char *timeFormat)
}
static const char *GetCurrentTime(const char *timeFormat)
// restore original character suppresed by terminating zero
*(cur + len) = tmp;
// restore original character suppresed by terminating zero
*(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,
spFile* pTopCtx = new spFile();
mpCurCtx = pTopCtx;
spFile* pTopCtx = new spFile();
mpCurCtx = pTopCtx;
mIsTemplate = 0;
mNestingLevel = 0;
mIsTemplate = 0;
mNestingLevel = 0;
- 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
// the container context (e.g. class/namespace)
{
// parses, token, if token identifies
// the container context (e.g. class/namespace)
if ( cmp_tokens_fast( cur, "virtual", len ) )
{
// probably the virtual method is in front of us;
if ( cmp_tokens_fast( cur, "virtual", len ) )
{
// probably the virtual method is in front of us;
skip_token( cur );
return;
}
skip_token( cur );
return;
}
+ bool isVirtual = false;
+ if ( get_token_str( cur ) == "virtual" )
+ isVirtual = true;
+
skip_token( cur );
if ( !get_next_token( cur ) ) return FALSE;
}
skip_token( cur );
if ( !get_next_token( cur ) ) return FALSE;
}
mpCurCtx->AddMember( pOp );
pOp->mVisibility = mCurVis;
mpCurCtx->AddMember( pOp );
pOp->mVisibility = mCurVis;
+ pOp->mIsVirtual = isVirtual;
// add comments about operation
AttachComments( *pOp, cur );
// add comments about operation
AttachComments( *pOp, cur );
if ( blocksSkipped == 0 )
{
if ( *cur == 10 ) ++_gLineNo;
if ( blocksSkipped == 0 )
{
if ( *cur == 10 ) ++_gLineNo;
break; // function without paramters
}
break; // function without paramters
}
+ // skip possible whitespace between ')' and following "const"
+ while ( isspace(*cur) )
+ cur++;
+
// check if it was really a function not a macro,
// if so, than it should be terminated with semicolon ';'
// or opening implemenetaton bracket '{'
// check if it was really a function not a macro,
// if so, than it should be terminated with semicolon ';'
// or opening implemenetaton bracket '{'
if ( cmp_tokens_fast( tok, "const", 5 ) )
{
if ( cmp_tokens_fast( tok, "const", 5 ) )
{
+ ((spOperation*)mpCurCtx)->mIsConstant = true;
+
skip_token(tok);
if ( !get_next_token(tok) ) return FALSE;
continue;
skip_token(tok);
if ( !get_next_token(tok) ) return FALSE;
continue;
spOperation::spOperation()
: mHasDefinition( FALSE )
spOperation::spOperation()
: mHasDefinition( FALSE )
+{
+ mIsConstant =
+ mIsVirtual =
+ mHasDefinition = false;
+}
string spOperation::GetFullName(MarkupTagsT tags)
{
string spOperation::GetFullName(MarkupTagsT tags)
{
{
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 *pSepUnix = strrchr(pszFileName, FILE_SEP_PATH_UNIX);
- const char *pSepDos = strrchr(pszFileName, FILE_SEP_PATH_DOS);
+ const char *pDot = strrchr(pszFileName, wxFILE_SEP_EXT);
+ const char *pSepUnix = strrchr(pszFileName, wxFILE_SEP_PATH_UNIX);
+ const char *pSepDos = strrchr(pszFileName, wxFILE_SEP_PATH_DOS);
// take the last of the two
size_t nPosUnix = pSepUnix ? pSepUnix - pszFileName : 0;
// take the last of the two
size_t nPosUnix = pSepUnix ? pSepUnix - pszFileName : 0;