better support for the %throws directive
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8350 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
38c8cf2cb8
commit
b044703d0d
5 changed files with 71 additions and 32 deletions
|
|
@ -15,7 +15,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%throws(E1,E2) A::barfoo(int i);
|
%throws(E1,E2*,ET<int>,ET<double>) A::barfoo(int i);
|
||||||
|
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
|
@ -31,6 +31,11 @@
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct ET
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
struct A
|
struct A
|
||||||
{
|
{
|
||||||
/* caught by the user's throw definition */
|
/* caught by the user's throw definition */
|
||||||
|
|
@ -58,10 +63,18 @@
|
||||||
{
|
{
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
throw E1();
|
throw E1();
|
||||||
} else {
|
} else if (i == 2) {
|
||||||
throw E2();
|
static E2 *ep = new E2();
|
||||||
|
throw ep;
|
||||||
|
} else if (i == 3) {
|
||||||
|
throw ET<int>();
|
||||||
|
} else {
|
||||||
|
throw ET<double>();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%template(ET_i) ET<int>;
|
||||||
|
%template(ET_d) ET<double>;
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ extern int SWIG_cparse_template_reduce(int treduce);
|
||||||
extern void Swig_cparse_replace_descriptor(String *s);
|
extern void Swig_cparse_replace_descriptor(String *s);
|
||||||
extern void cparse_normalize_void(Node *);
|
extern void cparse_normalize_void(Node *);
|
||||||
extern Parm *Swig_cparse_parm(String *s);
|
extern Parm *Swig_cparse_parm(String *s);
|
||||||
|
extern ParmList *Swig_cparse_parms(String *s);
|
||||||
|
|
||||||
|
|
||||||
/* templ.c */
|
/* templ.c */
|
||||||
|
|
|
||||||
|
|
@ -1344,7 +1344,7 @@ static void default_arguments(Node *n) {
|
||||||
%token <ivalue> TEMPLATE
|
%token <ivalue> TEMPLATE
|
||||||
%token <str> OPERATOR
|
%token <str> OPERATOR
|
||||||
%token <str> COPERATOR
|
%token <str> COPERATOR
|
||||||
%token PARSETYPE PARSEPARM
|
%token PARSETYPE PARSEPARM PARSEPARMS
|
||||||
|
|
||||||
%left CAST
|
%left CAST
|
||||||
%left LOR
|
%left LOR
|
||||||
|
|
@ -1446,6 +1446,12 @@ program : interface {
|
||||||
| PARSEPARM error {
|
| PARSEPARM error {
|
||||||
top = 0;
|
top = 0;
|
||||||
}
|
}
|
||||||
|
| PARSEPARMS LPAREN parms RPAREN SEMI {
|
||||||
|
top = $3;
|
||||||
|
}
|
||||||
|
| PARSEPARMS error SEMI {
|
||||||
|
top = 0;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
interface : interface declaration {
|
interface : interface declaration {
|
||||||
|
|
@ -5744,6 +5750,23 @@ Parm *Swig_cparse_parm(String *s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ParmList *Swig_cparse_parms(String *s) {
|
||||||
|
String *ns;
|
||||||
|
char *cs = Char(s);
|
||||||
|
if (cs && cs[0] != '(') {
|
||||||
|
ns = NewStringf("(%s);",s);
|
||||||
|
} else {
|
||||||
|
ns = NewStringf("%s;",s);
|
||||||
|
}
|
||||||
|
Seek(ns,0,SEEK_SET);
|
||||||
|
scanner_file(ns);
|
||||||
|
top = 0;
|
||||||
|
scanner_next_token(PARSEPARMS);
|
||||||
|
yyparse();
|
||||||
|
/* Printf(stdout,"typeparse: '%s' ---> '%s'\n", s, top); */
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
char cvsroot_allocate_cxx[] = "$Header$";
|
char cvsroot_allocate_cxx[] = "$Header$";
|
||||||
|
|
||||||
#include "swigmod.h"
|
#include "swigmod.h"
|
||||||
|
#include "cparse.h"
|
||||||
|
|
||||||
static int virtual_elimination_mode = 0; /* set to 0 on default */
|
static int virtual_elimination_mode = 0; /* set to 0 on default */
|
||||||
|
|
||||||
|
|
@ -463,21 +464,34 @@ class Allocate : public Dispatcher {
|
||||||
return methods;
|
return methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mark_exception_classes(ParmList *p) {
|
void mark_exception_classes(Node *n) {
|
||||||
while(p) {
|
ParmList *throws = Getattr(n,"throws");
|
||||||
SwigType *ty = Getattr(p,"type");
|
if (!throws) {
|
||||||
SwigType *t = SwigType_typedef_resolve_all(ty);
|
String *sthrows = Getattr(n,"feature:throws");
|
||||||
if (SwigType_isreference(t) || SwigType_ispointer(t) || SwigType_isarray(t)) {
|
if (sthrows) {
|
||||||
Delete(SwigType_pop(t));
|
throws = Swig_cparse_parms(sthrows);
|
||||||
}
|
if (throws) {
|
||||||
Node *c = Swig_symbol_clookup(t,0);
|
Setattr(n,"throws",throws);
|
||||||
if (c) {
|
|
||||||
if (!GetFlag(c,"feature:exceptionclass")) {
|
|
||||||
SetFlag(c,"feature:exceptionclass");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p = nextSibling(p);
|
}
|
||||||
Delete(t);
|
if (throws) {
|
||||||
|
ParmList *p = throws;
|
||||||
|
while(p) {
|
||||||
|
SwigType *ty = Getattr(p,"type");
|
||||||
|
SwigType *t = SwigType_typedef_resolve_all(ty);
|
||||||
|
if (SwigType_isreference(t) || SwigType_ispointer(t) || SwigType_isarray(t)) {
|
||||||
|
Delete(SwigType_pop(t));
|
||||||
|
}
|
||||||
|
Node *c = Swig_symbol_clookup(t,0);
|
||||||
|
if (c) {
|
||||||
|
if (!GetFlag(c,"feature:exceptionclass")) {
|
||||||
|
SetFlag(c,"feature:exceptionclass");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p = nextSibling(p);
|
||||||
|
Delete(t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -702,7 +716,7 @@ public:
|
||||||
Node *c = 0;
|
Node *c = 0;
|
||||||
for (c = firstChild(n); c; c = nextSibling(c)) {
|
for (c = firstChild(n); c; c = nextSibling(c)) {
|
||||||
if (Strcmp(nodeType(c),"cdecl") == 0) {
|
if (Strcmp(nodeType(c),"cdecl") == 0) {
|
||||||
mark_exception_classes(Getattr(c,"throws"));
|
mark_exception_classes(c);
|
||||||
|
|
||||||
if (inclass)
|
if (inclass)
|
||||||
class_member_is_defined_in_bases(c, inclass);
|
class_member_is_defined_in_bases(c, inclass);
|
||||||
|
|
@ -714,7 +728,7 @@ public:
|
||||||
|
|
||||||
virtual int cDeclaration(Node *n) {
|
virtual int cDeclaration(Node *n) {
|
||||||
|
|
||||||
mark_exception_classes(Getattr(n,"throws"));
|
mark_exception_classes(n);
|
||||||
|
|
||||||
if (inclass) {
|
if (inclass) {
|
||||||
/* check whether the member node n is defined in class node in class's bases */
|
/* check whether the member node n is defined in class node in class's bases */
|
||||||
|
|
@ -798,7 +812,7 @@ public:
|
||||||
if (!inclass) return SWIG_OK;
|
if (!inclass) return SWIG_OK;
|
||||||
Parm *parms = Getattr(n,"parms");
|
Parm *parms = Getattr(n,"parms");
|
||||||
|
|
||||||
mark_exception_classes(Getattr(n,"throws"));
|
mark_exception_classes(n);
|
||||||
if (!extendmode) {
|
if (!extendmode) {
|
||||||
if (!ParmList_numrequired(parms)) {
|
if (!ParmList_numrequired(parms)) {
|
||||||
/* Class does define a default constructor */
|
/* Class does define a default constructor */
|
||||||
|
|
|
||||||
|
|
@ -346,18 +346,6 @@ void emit_action(Node *n, Wrapper *f) {
|
||||||
String *wrap;
|
String *wrap;
|
||||||
SwigType *rt;
|
SwigType *rt;
|
||||||
ParmList *throws = Getattr(n,"throws");
|
ParmList *throws = Getattr(n,"throws");
|
||||||
if (!throws) {
|
|
||||||
String *tmp = 0;
|
|
||||||
String *sthrows = Getattr(n,"feature:throws");
|
|
||||||
if (sthrows) {
|
|
||||||
char *cthrows = Char(sthrows);
|
|
||||||
if (cthrows && cthrows[0] != '(') {
|
|
||||||
sthrows = tmp = NewStringf("(%s)",sthrows);
|
|
||||||
}
|
|
||||||
throws = SwigType_function_parms(sthrows);
|
|
||||||
if (tmp) Delete (tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Look for fragments */
|
/* Look for fragments */
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue