Add support function for displaying the declaration of a methods. Add special variables for use in \%exception:

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10255 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2008-02-13 23:43:34 +00:00
commit 61cc1dd334
4 changed files with 109 additions and 6 deletions

View file

@ -1,6 +1,16 @@
Version 1.3.34 (in progress)
============================
02/13/2007: wsfulton
Add new special variables for use within %exception:
$wrapname - language specific wrapper name
$overname - if a method is overloaded this contains the extra mangling used on
the overloaded method
$decl - the fully qualified C/C++ declaration of the method being wrapped
without the return type
$fulldecl - the fully qualified C/C++ declaration of the method being wrapped
including the return type
02/11/2008: mgossage
[Lua] Added a patch by Torsten Landschoff to fix the unary minus issue
Ran 'astyle --style=kr -2' across lua.cxx to neaten it up

View file

@ -342,10 +342,26 @@ int emit_action_code(Node *n, Wrapper *f, String *eaction) {
if (tm)
tm = Copy(tm);
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
Replaceall(tm, "$name", Getattr(n, "name"));
Replaceall(tm, "$symname", Getattr(n, "sym:name"));
Replaceall(tm, "$function", eaction);
Replaceall(tm, "$action", eaction);
if (Strstr(tm, "$")) {
Replaceall(tm, "$name", Getattr(n, "name"));
Replaceall(tm, "$symname", Getattr(n, "sym:name"));
Replaceall(tm, "$function", eaction); // deprecated
Replaceall(tm, "$action", eaction);
Replaceall(tm, "$wrapname", Getattr(n, "wrap:name"));
String *overloaded = Getattr(n, "sym:overloaded");
Replaceall(tm, "$overname", overloaded ? Char(Getattr(n, "sym:overname")) : "");
if (Strstr(tm, "$decl")) {
String *decl = Swig_name_decl(n);
Replaceall(tm, "$decl", decl);
Delete(decl);
}
if (Strstr(tm, "$fulldecl")) {
String *fulldecl = Swig_name_fulldecl(n);
Replaceall(tm, "$fulldecl", fulldecl);
Delete(fulldecl);
}
}
Printv(f->code, tm, "\n", NIL);
Delete(tm);
return 1;

View file

@ -1565,3 +1565,79 @@ void Swig_name_inherit(String *base, String *derived) {
Swig_name_object_inherit(Swig_name_namewarn_hash(), base, derived);
Swig_name_object_inherit(Swig_cparse_features(), base, derived);
}
/* -----------------------------------------------------------------------------
* void Swig_name_decl()
*
* Return a stringified version of a C/C++ declaration without the return type.
* The node passed in is expected to be a function. Some example return values:
* "MyNameSpace::MyTemplate<MyNameSpace::ABC >::~MyTemplate()"
* "MyNameSpace::ABC::ABC(int,double)"
* "MyNameSpace::ABC::constmethod(int) const"
*
* ----------------------------------------------------------------------------- */
String *Swig_name_decl(Node *n) {
String *qname;
String *decl;
String *qualifier = Swig_symbol_qualified(n);
String *name = Swig_scopename_last(Getattr(n, "name"));
qualifier = SwigType_namestr(qualifier);
/* Very specific hack for template constructors/destructors */
if (SwigType_istemplate(name)) {
String *nodetype = nodeType(n);
if (nodetype && (Equal(nodetype, "constructor") || Equal(nodetype, "destructor"))) {
String *nprefix = NewStringEmpty();
String *nlast = NewStringEmpty();
String *tprefix;
Swig_scopename_split(name, &nprefix, &nlast);
tprefix = SwigType_templateprefix(nlast);
Delete(nlast);
Delete(name);
name = tprefix;
}
}
qname = NewString("");
if (qualifier && Len(qualifier) > 0)
Printf(qname, "%s::", qualifier);
Printf(qname, "%s", name);
decl = NewStringf("%s(%s)%s", qname, ParmList_errorstr(Getattr(n, "parms")), SwigType_isconst(Getattr(n, "decl")) ? " const" : "");
Delete(name);
Delete(qualifier);
Delete(qname);
return decl;
}
/* -----------------------------------------------------------------------------
* void Swig_name_fulldecl()
*
* Return a stringified version of a C/C++ declaration including the return type.
* The node passed in is expected to be a function. Some example return values:
* "MyNameSpace::MyTemplate<MyNameSpace::ABC >::~MyTemplate()"
* "MyNameSpace::ABC::ABC(int,double)"
* "int * MyNameSpace::ABC::constmethod(int) const"
*
* ----------------------------------------------------------------------------- */
String *Swig_name_fulldecl(Node *n) {
String *decl = Swig_name_decl(n);
String *type = Getattr(n, "type");
String *nodetype = nodeType(n);
String *fulldecl;
/* add on the return type */
if (nodetype && (Equal(nodetype, "constructor") || Equal(nodetype, "destructor"))) {
fulldecl = decl;
} else {
String *t = SwigType_str(type, 0);
fulldecl = NewStringf("%s %s", t, decl);
Delete(decl);
Delete(t);
}
return fulldecl;
}

View file

@ -266,6 +266,8 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern String *Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, String *oldname);
extern String *Swig_name_warning(Node *n, String *prefix, String *name, SwigType *decl);
extern String *Swig_name_decl(Node *n);
extern String *Swig_name_fulldecl(Node *n);
/* --- parameterized rename functions --- */
@ -273,8 +275,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern DOH *Swig_name_object_get(Hash *namehash, String_or_char *prefix, String_or_char *name, SwigType *decl);
extern void Swig_name_object_inherit(Hash *namehash, String *base, String *derived);
extern void Swig_features_get(Hash *features, String_or_char *prefix, String_or_char *name, SwigType *decl, Node *n);
extern void Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, const String_or_char *featurename, String *value,
Hash *featureattribs);
extern void Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, const String_or_char *featurename, String *value, Hash *featureattribs);
/* --- Misc --- */
extern char *Swig_copy_string(const char *c);