Use DOH rather than standard containers for texinfo docs support.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10356 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Xavier Delacour 2008-04-06 01:15:51 +00:00
commit 8317d87031

View file

@ -10,8 +10,6 @@
char cvsroot_octave_cxx[] = "$Id$"; char cvsroot_octave_cxx[] = "$Id$";
#include "swigmod.h" #include "swigmod.h"
#include <string>
#include <map>
static const char *usage = (char *) "\ static const char *usage = (char *) "\
Octave Options (available with -octave)\n\ Octave Options (available with -octave)\n\
@ -36,38 +34,7 @@ private:
int have_destructor; int have_destructor;
String *constructor_name; String *constructor_name;
class doc_info { Hash *docs;
doc_info& operator= (const doc_info& rhs);
public:
String *decl_info;
String *cdecl_info;
String *synopsis;
String *args_info;
doc_info() {
decl_info=NewString("");
cdecl_info=NewString("");
synopsis=NewString("");
args_info=NewString("");
}
doc_info(const doc_info& x) {
decl_info = Copy(x.decl_info);
cdecl_info = Copy(x.cdecl_info);
synopsis = Copy(x.synopsis);
args_info = Copy(x.args_info);
}
~doc_info() {
Delete(decl_info);
Delete(cdecl_info);
Delete(synopsis);
Delete(args_info);
}
bool empty() const {
return !Len(decl_info) && !Len(cdecl_info) &&
!Len(synopsis) && !Len(args_info);
}
};
typedef std::map<std::string, doc_info> doc_info_map;
doc_info_map docs;
public: public:
OCTAVE():f_runtime(0), f_header(0), f_doc(0), f_wrappers(0), OCTAVE():f_runtime(0), f_header(0), f_doc(0), f_wrappers(0),
@ -77,6 +44,7 @@ public:
allow_overloading(); allow_overloading();
director_multiple_inheritance = 1; director_multiple_inheritance = 1;
director_language = 1; director_language = 1;
docs = NewHash();
} }
virtual void main(int argc, char *argv[]) { virtual void main(int argc, char *argv[]) {
@ -164,7 +132,7 @@ public:
if (!CPlusPlus) if (!CPlusPlus)
Printf(f_header,"}\n"); Printf(f_header,"}\n");
if (docs.size()) if (Len(docs))
emit_doc_texinfo(); emit_doc_texinfo();
if (directorsEnabled()) if (directorsEnabled())
@ -203,40 +171,42 @@ public:
const char* s=(const char*)Data(_s); const char* s=(const char*)Data(_s);
while (*s&&(*s=='\t'||*s=='\r'||*s=='\n'||*s==' ')) while (*s&&(*s=='\t'||*s=='\r'||*s=='\n'||*s==' '))
++s; ++s;
std::string r; String *r = NewString("");
std::string nl="\\\n";
for (int j=0;s[j];++j) { for (int j=0;s[j];++j) {
if (s[j] == '\n') if (s[j] == '\n') {
r+="\\n"+nl; Append(r, "\\n\\\n");
else if (s[j] == '\r') } else if (s[j] == '\r') {
r+="\\r"+nl; Append(r, "\\r");
else if (s[j] == '\t') } else if (s[j] == '\t') {
r+="\\t"+nl; Append(r, "\\t");
else if (s[j] == '\\') } else if (s[j] == '\\') {
r+="\\\\"+nl; Append(r, "\\\\");
else if (s[j] == '\'') } else if (s[j] == '\'') {
r+="\\\'"+nl; Append(r, "\\\'");
else if (s[j] == '\"') } else if (s[j] == '\"') {
r+="\\\""+nl; Append(r, "\\\"");
else } else
r+=s[j]; Putc(s[j], r);
} }
return NewString(r.c_str()); return r;
} }
void emit_doc_texinfo() { void emit_doc_texinfo() {
for (doc_info_map::iterator it=docs.begin(); for (Iterator it = First(docs); it.key; it = Next(it)) {
it!=docs.end();++it) { String *wrap_name = it.key;
doc_info& d=it->second;
String *wrap_name=NewString(it->first.c_str()); String *synopsis = Getattr(it.item, "synopsis");
String *decl_info = Getattr(it.item, "decl_info");
String *cdecl_info = Getattr(it.item, "cdecl_info");
String *args_info = Getattr(it.item, "args_info");
String *doc_str = NewString(""); String *doc_str = NewString("");
Printv(doc_str, d.synopsis, d.decl_info, d.cdecl_info, d.args_info, NIL); Printv(doc_str, synopsis, decl_info, cdecl_info, args_info, NIL);
String *escaped_doc_str = texinfo_escape(doc_str); String *escaped_doc_str = texinfo_escape(doc_str);
if (Len(doc_str)>0) { if (Len(doc_str)>0) {
Printf(f_doc,"const char* %s_texinfo = ",wrap_name); Printf(f_doc,"const char* %s_texinfo = ",wrap_name);
Printf(f_doc,"\"-*- texinfo -*-\\n\\\n%s", escaped_doc_str); Printf(f_doc,"\"-*- texinfo -*-\\n\\\n%s", escaped_doc_str);
if (Len(d.decl_info)) if (Len(decl_info))
Printf(f_doc,"\\n\\\n@end deftypefn"); Printf(f_doc,"\\n\\\n@end deftypefn");
Printf(f_doc,"\";\n"); Printf(f_doc,"\";\n");
} }
@ -247,13 +217,23 @@ public:
} }
Printf(f_doc,"\n"); Printf(f_doc,"\n");
} }
bool is_empty_doc_node(Node* n) {
if (!n)
return true;
String *synopsis = Getattr(n, "synopsis");
String *decl_info = Getattr(n, "decl_info");
String *cdecl_info = Getattr(n, "cdecl_info");
String *args_info = Getattr(n, "args_info");
return !Len(synopsis) && !Len(decl_info) &&
!Len(cdecl_info) && !Len(args_info);
}
String *texinfo_name(Node* n) { String *texinfo_name(Node* n) {
String *tname = NewString(""); String *tname = NewString("");
String *iname = Getattr(n, "sym:name"); String *iname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(iname); String *wname = Swig_name_wrapper(iname);
doc_info& d = docs[(const char*)Data(wname)]; Node* d = Getattr(docs, wname);
if (d.empty()) if (is_empty_doc_node(d))
Printf(tname, "0"); Printf(tname, "0");
else else
Printf(tname, "%s_texinfo", wname); Printf(tname, "%s_texinfo", wname);
@ -266,7 +246,20 @@ public:
String *wname = Swig_name_wrapper(iname); String *wname = Swig_name_wrapper(iname);
String *str = Getattr(n, "feature:docstring"); String *str = Getattr(n, "feature:docstring");
bool autodoc_enabled = !Cmp(Getattr(n, "feature:autodoc"), "1"); bool autodoc_enabled = !Cmp(Getattr(n, "feature:autodoc"), "1");
doc_info& d = docs[(const char*)Data(wname)]; Node* d = Getattr(docs, wname);
if (!d) {
d = NewHash();
Setattr(d, "synopsis", NewString(""));
Setattr(d, "decl_info", NewString(""));
Setattr(d, "cdecl_info", NewString(""));
Setattr(d, "args_info", NewString(""));
Setattr(docs, wname, d);
}
String *synopsis = Getattr(d, "synopsis");
String *decl_info = Getattr(d, "decl_info");
// String *cdecl_info = Getattr(d, "cdecl_info");
String *args_info = Getattr(d, "args_info");
// * couldn't we just emit the docs here? // * couldn't we just emit the docs here?
@ -274,7 +267,7 @@ public:
String *decl_str = NewString(""); String *decl_str = NewString("");
String *args_str = NewString(""); String *args_str = NewString("");
make_autodocParmList(n, decl_str, args_str); make_autodocParmList(n, decl_str, args_str);
Append(d.decl_info, "@deftypefn {Loadable Function} "); Append(decl_info, "@deftypefn {Loadable Function} ");
SwigType *type = Getattr(n, "type"); SwigType *type = Getattr(n, "type");
if (type && Strcmp(type, "void")) { if (type && Strcmp(type, "void")) {
@ -282,18 +275,18 @@ public:
Node *lookup = Swig_symbol_clookup(type, 0); Node *lookup = Swig_symbol_clookup(type, 0);
if (lookup) if (lookup)
type = Getattr(lookup, "sym:name"); type = Getattr(lookup, "sym:name");
Append(d.decl_info, "@var{retval} = "); Append(decl_info, "@var{retval} = ");
String *type_str = NewString(""); String *type_str = NewString("");
Printf(type_str, "@var{retval} is of type %s. ", type); Printf(type_str, "@var{retval} is of type %s. ", type);
Append(args_str, type_str); Append(args_str, type_str);
Delete(type_str); Delete(type_str);
} }
Append(d.decl_info, name); Append(decl_info, name);
Append(d.decl_info, " ("); Append(decl_info, " (");
Append(d.decl_info, decl_str); Append(decl_info, decl_str);
Append(d.decl_info, ")\n"); Append(decl_info, ")\n");
Append(d.args_info, args_str); Append(args_info, args_str);
Delete(decl_str); Delete(decl_str);
Delete(args_str); Delete(args_str);
} }
@ -307,7 +300,7 @@ public:
} }
// emit into synopsis section // emit into synopsis section
Append(d.synopsis, str); Append(synopsis, str);
} }
} }