Merge remote-tracking branch 'origin/master' into gsoc2012-scilab

Conflicts:
	Examples/Makefile.in
This commit is contained in:
Sylvestre Ledru 2013-08-06 10:06:31 +02:00
commit 21e17eaa73
795 changed files with 16905 additions and 11792 deletions

View file

@ -9,14 +9,12 @@
* scanner.c
*
* SWIG tokenizer. This file is a wrapper around the generic C scanner
* found in Swig/scanner.c. Extra logic is added both to accomodate the
* found in Swig/scanner.c. Extra logic is added both to accommodate the
* bison-based grammar and certain peculiarities of C++ parsing (e.g.,
* operator overloading, typedef resolution, etc.). This code also splits
* C identifiers up into keywords and SWIG directives.
* ----------------------------------------------------------------------------- */
char cvsroot_cscanner_c[] = "$Id$";
#include "cparse.h"
#include "parser.h"
#include <string.h>
@ -103,10 +101,11 @@ void start_inline(char *text, int line) {
* ----------------------------------------------------------------------------- */
void skip_balanced(int startchar, int endchar) {
int start_line = Scanner_line(scan);
Clear(scanner_ccode);
if (Scanner_skip_balanced(scan,startchar,endchar) < 0) {
Swig_error(Scanner_file(scan),Scanner_errline(scan), "Missing '%c'. Reached end of input.\n", endchar);
Swig_error(cparse_file, start_line, "Missing '%c'. Reached end of input.\n", endchar);
return;
}
@ -372,7 +371,7 @@ void scanner_clear_rename() {
rename_active = 0;
}
/* Used to push a ficticious token into the scanner */
/* Used to push a fictitious token into the scanner */
static int next_token = 0;
void scanner_next_token(int tok) {
next_token = tok;

View file

@ -17,8 +17,6 @@
#define yylex yylex
char cvsroot_parser_y[] = "$Id$";
#include "swig.h"
#include "cparse.h"
#include "preprocessor.h"
@ -40,6 +38,7 @@ static Node *top = 0; /* Top of the generated parse tree */
static int unnamed = 0; /* Unnamed datatype counter */
static Hash *extendhash = 0; /* Hash table of added methods */
static Hash *classes = 0; /* Hash table of classes */
static Hash *classes_typedefs = 0; /* Hash table of typedef classes: typedef struct X {...} Y; */
static Symtab *prev_symtab = 0;
static Node *current_class = 0;
String *ModuleName = 0;
@ -205,7 +204,7 @@ static String *yyrename = 0;
/* Forward renaming operator */
static String *resolve_node_scope(String *cname);
static String *resolve_create_node_scope(String *cname);
Hash *Swig_cparse_features(void) {
@ -720,7 +719,7 @@ static void check_extensions() {
for (ki = First(extendhash); ki.key; ki = Next(ki)) {
if (!Strchr(ki.key,'<')) {
SWIG_WARN_NODE_BEGIN(ki.item);
Swig_warning(WARN_PARSE_EXTEND_UNDEF,Getfile(ki.item), Getline(ki.item), "%%extend defined for an undeclared class %s.\n", ki.key);
Swig_warning(WARN_PARSE_EXTEND_UNDEF,Getfile(ki.item), Getline(ki.item), "%%extend defined for an undeclared class %s.\n", SwigType_namestr(ki.key));
SWIG_WARN_NODE_END(ki.item);
}
}
@ -728,33 +727,33 @@ static void check_extensions() {
/* Check a set of declarations to see if any are pure-abstract */
static List *pure_abstract(Node *n) {
List *abs = 0;
static List *pure_abstracts(Node *n) {
List *abstracts = 0;
while (n) {
if (Cmp(nodeType(n),"cdecl") == 0) {
String *decl = Getattr(n,"decl");
if (SwigType_isfunction(decl)) {
String *init = Getattr(n,"value");
if (Cmp(init,"0") == 0) {
if (!abs) {
abs = NewList();
if (!abstracts) {
abstracts = NewList();
}
Append(abs,n);
Setattr(n,"abstract","1");
Append(abstracts,n);
SetFlag(n,"abstract");
}
}
} else if (Cmp(nodeType(n),"destructor") == 0) {
if (Cmp(Getattr(n,"value"),"0") == 0) {
if (!abs) {
abs = NewList();
if (!abstracts) {
abstracts = NewList();
}
Append(abs,n);
Setattr(n,"abstract","1");
Append(abstracts,n);
SetFlag(n,"abstract");
}
}
n = nextSibling(n);
}
return abs;
return abstracts;
}
/* Make a classname */
@ -867,26 +866,85 @@ static Node *nscope = 0;
static Node *nscope_inner = 0;
/* Remove the scope prefix from cname and return the base name without the prefix.
* The scopes specified in the prefix are found, or created in the current namespace.
* So ultimately the scope is changed to that required for the base name.
* The scopes required for the symbol name are resolved and/or created, if required.
* For example AA::BB::CC as input returns CC and creates the namespace AA then inner
* namespace BB in the current scope. If no scope separator (::) in the input, then nothing happens! */
static String *resolve_node_scope(String *cname) {
* namespace BB in the current scope. If cname is found to already exist as a weak symbol
* (forward reference) then the scope might be changed to match, such as when a symbol match
* is made via a using reference. */
static String *resolve_create_node_scope(String *cname) {
Symtab *gscope = 0;
Node *cname_node = 0;
int skip_lookup = 0;
nscope = 0;
nscope_inner = 0;
if (Strncmp(cname,"::",2) == 0)
skip_lookup = 1;
cname_node = skip_lookup ? 0 : Swig_symbol_clookup_no_inherit(cname, 0);
if (cname_node) {
/* The symbol has been defined already or is in another scope.
If it is a weak symbol, it needs replacing and if it was brought into the current scope
via a using declaration, the scope needs adjusting appropriately for the new symbol.
Similarly for defined templates. */
Symtab *symtab = Getattr(cname_node, "sym:symtab");
Node *sym_weak = Getattr(cname_node, "sym:weak");
if ((symtab && sym_weak) || Equal(nodeType(cname_node), "template")) {
/* Check if the scope is the current scope */
String *current_scopename = Swig_symbol_qualifiedscopename(0);
String *found_scopename = Swig_symbol_qualifiedscopename(symtab);
int len;
if (!current_scopename)
current_scopename = NewString("");
if (!found_scopename)
found_scopename = NewString("");
len = Len(current_scopename);
if ((len > 0) && (Strncmp(current_scopename, found_scopename, len) == 0)) {
if (Len(found_scopename) > len + 2) {
/* A matching weak symbol was found in non-global scope, some scope adjustment may be required */
String *new_cname = NewString(Char(found_scopename) + len + 2); /* skip over "::" prefix */
String *base = Swig_scopename_last(cname);
Printf(new_cname, "::%s", base);
cname = new_cname;
Delete(base);
} else {
/* A matching weak symbol was found in the same non-global local scope, no scope adjustment required */
assert(len == Len(found_scopename));
}
} else {
String *base = Swig_scopename_last(cname);
if (Len(found_scopename) > 0) {
/* A matching weak symbol was found in a different scope to the local scope - probably via a using declaration */
cname = NewStringf("%s::%s", found_scopename, base);
} else {
/* Either:
1) A matching weak symbol was found in a different scope to the local scope - this is actually a
symbol with the same name in a different scope which we don't want, so no adjustment required.
2) A matching weak symbol was found in the global scope - no adjustment required.
*/
cname = Copy(base);
}
Delete(base);
}
Delete(current_scopename);
Delete(found_scopename);
}
}
if (Swig_scopename_check(cname)) {
Node *ns;
String *prefix = Swig_scopename_prefix(cname);
String *base = Swig_scopename_last(cname);
if (prefix && (Strncmp(prefix,"::",2) == 0)) {
/* I don't think we can use :: global scope to declare classes and hence neither %template. - consider reporting error instead - wsfulton. */
/* Use the global scope */
String *nprefix = NewString(Char(prefix)+2);
Delete(prefix);
prefix= nprefix;
gscope = set_scope_to_global();
}
if (!prefix || (Len(prefix) == 0)) {
}
if (Len(prefix) == 0) {
/* Use the global scope, but we need to add a 'global' namespace. */
if (!gscope) gscope = set_scope_to_global();
/* note that this namespace is not the "unnamed" one,
@ -904,8 +962,7 @@ static String *resolve_node_scope(String *cname) {
} else {
Symtab *nstab = Getattr(ns,"symtab");
if (!nstab) {
Swig_error(cparse_file,cparse_line,
"'%s' is not defined as a valid scope.\n", prefix);
Swig_error(cparse_file,cparse_line, "'%s' is not defined as a valid scope.\n", prefix);
ns = 0;
} else {
/* Check if the node scope is the current scope */
@ -946,7 +1003,6 @@ static String *resolve_node_scope(String *cname) {
} else {
/* now this last part is a class */
si = Next(si);
ns1 = Swig_symbol_clookup(sname,0);
/* or a nested class tree, which is unrolled here */
for (; si.item; si = Next(si)) {
if (si.item) {
@ -986,6 +1042,7 @@ static String *resolve_node_scope(String *cname) {
}
Delete(prefix);
}
return cname;
}
@ -1095,15 +1152,13 @@ static void nested_new_struct(const char *kind, String *struct_code, Node *cpp_o
* nested class solution is implemented.
* ----------------------------------------------------------------------------- */
static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, const char *name, Node *cpp_opt_declarators) {
static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, String *name, Node *cpp_opt_declarators) {
Node *nn = 0;
int warned = 0;
if (sname) {
/* Add forward declaration of the nested type */
Node *n = new_node("classforward");
Setfile(n, cparse_file);
Setline(n, cparse_line);
Setattr(n, "kind", kind);
Setattr(n, "name", sname);
Setattr(n, "storage", storage);
@ -1120,7 +1175,7 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S
if (!variable_of_anonymous_type) {
int anonymous_typedef = !sname && (storage && (strcmp(storage, "typedef") == 0));
Node *n = cpp_opt_declarators;
SwigType *type = NewString(name);
SwigType *type = name;
while (n) {
Setattr(n, "type", type);
Setattr(n, "storage", storage);
@ -1130,7 +1185,6 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S
}
n = nextSibling(n);
}
Delete(type);
add_symbols(cpp_opt_declarators);
if (nn) {
@ -1734,6 +1788,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) {
%type <ptype> type_specifier primitive_type_list ;
%type <node> fname stringtype;
%type <node> featattr;
%type <node> optional_constant_directive;
%%
@ -1856,20 +1911,34 @@ extend_directive : EXTEND options idcolon LBRACE {
String *clsname;
cplus_mode = CPLUS_PUBLIC;
if (!classes) classes = NewHash();
if (!classes_typedefs) classes_typedefs = NewHash();
if (!extendhash) extendhash = NewHash();
clsname = make_class_name($3);
cls = Getattr(classes,clsname);
if (!cls) {
/* No previous definition. Create a new scope */
Node *am = Getattr(extendhash,clsname);
if (!am) {
Swig_symbol_newscope();
Swig_symbol_setscopename($3);
prev_symtab = 0;
cls = Getattr(classes_typedefs, clsname);
if (!cls) {
/* No previous definition. Create a new scope */
Node *am = Getattr(extendhash,clsname);
if (!am) {
Swig_symbol_newscope();
Swig_symbol_setscopename($3);
prev_symtab = 0;
} else {
prev_symtab = Swig_symbol_setscope(Getattr(am,"symtab"));
}
current_class = 0;
} else {
prev_symtab = Swig_symbol_setscope(Getattr(am,"symtab"));
/* Previous typedef class definition. Use its symbol table.
Deprecated, just the real name should be used.
Note that %extend before the class typedef never worked, only %extend after the class typdef. */
prev_symtab = Swig_symbol_setscope(Getattr(cls, "symtab"));
current_class = cls;
extendmode = 1;
SWIG_WARN_NODE_BEGIN(cls);
Swig_warning(WARN_PARSE_EXTEND_NAME, cparse_file, cparse_line, "Deprecated %%extend name used - the %s name '%s' should be used instead of the typedef name '%s'.\n", Getattr(cls, "kind"), SwigType_namestr(Getattr(cls, "name")), $3);
SWIG_WARN_NODE_END(cls);
}
current_class = 0;
} else {
/* Previous class definition. Use its symbol table */
prev_symtab = Swig_symbol_setscope(Getattr(cls,"symtab"));
@ -2784,7 +2853,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
/* If the class name is qualified, we need to create or lookup namespace entries */
if (!inclass) {
$5 = resolve_node_scope($5);
$5 = resolve_create_node_scope($5);
}
/*
@ -2944,7 +3013,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
if (Strcmp(nodeType(templnode),"class") == 0) {
/* Identify pure abstract methods */
Setattr(templnode,"abstract", pure_abstract(firstChild(templnode)));
Setattr(templnode,"abstracts", pure_abstracts(firstChild(templnode)));
/* Set up inheritance in symbol table */
{
@ -2988,7 +3057,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
if (am) {
Symtab *st = Swig_symbol_current();
Swig_symbol_setscope(Getattr(templnode,"symtab"));
/* Printf(stdout,"%s: %s %x %x\n", Getattr(templnode,"name"), clsname, Swig_symbol_current(), Getattr(templnode,"symtab")); */
/* Printf(stdout,"%s: %s %p %p\n", Getattr(templnode,"name"), clsname, Swig_symbol_current(), Getattr(templnode,"symtab")); */
merge_extensions(templnode,am);
Swig_symbol_setscope(st);
append_previous_extension(templnode,am);
@ -3081,7 +3150,7 @@ c_declaration : c_decl {
appendChild($$,n);
while (n) {
SwigType *decl = Getattr(n,"decl");
if (SwigType_isfunction(decl) && Strcmp(Getattr(n, "storage"), "typedef") != 0) {
if (SwigType_isfunction(decl) && !Equal(Getattr(n, "storage"), "typedef")) {
Setattr(n,"storage","externc");
}
n = nextSibling(n);
@ -3406,7 +3475,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
prev_symtab = Swig_symbol_current();
/* If the class name is qualified. We need to create or lookup namespace/scope entries */
scope = resolve_node_scope($3);
scope = resolve_create_node_scope($3);
Setfile(scope,cparse_file);
Setline(scope,cparse_line);
$3 = scope;
@ -3516,7 +3585,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
inclass = 0;
/* Check for pure-abstract class */
Setattr($$,"abstract", pure_abstract($7));
Setattr($$,"abstracts", pure_abstracts($7));
/* This bit of code merges in a previously defined %extend directive (if any) */
@ -3532,7 +3601,6 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
if (!classes) classes = NewHash();
scpname = Swig_symbol_qualifiedscopename(0);
Setattr(classes,scpname,$$);
Delete(scpname);
appendChild($$,$7);
@ -3553,7 +3621,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
Setattr(p,"type",ty);
p = nextSibling(p);
}
/* Dump nested classes */
/* Class typedefs */
{
String *name = $3;
if ($9) {
@ -3573,8 +3641,9 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
Delete(class_rename);
class_rename = NewString(name);
}
if (!Getattr(classes,tdscopename)) {
Setattr(classes,tdscopename,$$);
if (!classes_typedefs) classes_typedefs = NewHash();
if (!Equal(scpname, tdscopename) && !Getattr(classes_typedefs, tdscopename)) {
Setattr(classes_typedefs, tdscopename, $$);
}
Setattr($$,"decl",decltype);
Delete(class_scope);
@ -3585,6 +3654,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
}
appendChild($$,dump_nested(Char(name)));
}
Delete(scpname);
if (cplus_mode != CPLUS_PUBLIC) {
/* we 'open' the class at the end, to allow %template
@ -3679,7 +3749,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
unnamed = Getattr($$,"unnamed");
/* Check for pure-abstract class */
Setattr($$,"abstract", pure_abstract($5));
Setattr($$,"abstracts", pure_abstracts($5));
n = new_node("cdecl");
Setattr(n,"name",$7.id);
@ -3777,8 +3847,6 @@ cpp_forward_class_decl : storage_class cpptype idcolon SEMI {
$$ = 0;
} else {
$$ = new_node("classforward");
Setfile($$,cparse_file);
Setline($$,cparse_line);
Setattr($$,"kind",$2);
Setattr($$,"name",$3);
Setattr($$,"sym:weak", "1");
@ -4415,17 +4483,7 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end {
| VIRTUAL NOT idtemplate LPAREN parms RPAREN cpp_vend {
String *name;
char *c = 0;
$$ = new_node("destructor");
/* Check for template names. If the class is a template
and the constructor is missing the template part, we
add it */
if (Classprefix) {
c = strchr(Char(Classprefix),'<');
if (c && !Strchr($3,'<')) {
$3 = NewStringf("%s%s",$3,c);
}
}
Setattr($$,"storage","virtual");
name = NewStringf("%s",$3);
if (*(Char(name)) != '~') Insert(name,0,"~");
@ -4576,7 +4634,8 @@ cpp_nested : storage_class cpptype idcolon inherit LBRACE {
$$ = 0;
if (cplus_mode == CPLUS_PUBLIC) {
if (cparse_cplusplus) {
$$ = nested_forward_declaration($1, $2, $3, $3, $7);
String *name = Copy($3);
$$ = nested_forward_declaration($1, $2, $3, name, $7);
} else if ($7) {
nested_new_struct($2, $<str>6, $7);
}
@ -4602,7 +4661,7 @@ cpp_nested : storage_class cpptype idcolon inherit LBRACE {
$$ = 0;
if (cplus_mode == CPLUS_PUBLIC) {
if (cparse_cplusplus) {
const char *name = $6 ? Getattr($6, "name") : 0;
String *name = $6 ? Copy(Getattr($6, "name")) : 0;
$$ = nested_forward_declaration($1, $2, 0, name, $6);
} else {
if ($6) {
@ -5589,29 +5648,31 @@ definetype : { /* scanner_check_typedef(); */ } expr {
/* Some stuff for handling enums */
ename : ID { $$ = $1; }
| empty { $$ = (char *) 0;}
;
| empty { $$ = (char *) 0;}
;
enumlist : enumlist COMMA edecl {
optional_constant_directive : constant_directive { $$ = $1; }
| empty { $$ = 0; }
;
/* Ignore if there is a trailing comma in the enum list */
if ($3) {
Node *leftSibling = Getattr($1,"_last");
if (!leftSibling) {
leftSibling=$1;
}
set_nextSibling(leftSibling,$3);
Setattr($1,"_last",$3);
}
$$ = $1;
}
| edecl {
$$ = $1;
if ($1) {
Setattr($1,"_last",$1);
}
}
;
/* Enum lists - any #define macros (constant directives) within the enum list are ignored. Trailing commas accepted. */
enumlist : enumlist COMMA optional_constant_directive edecl optional_constant_directive {
Node *leftSibling = Getattr($1,"_last");
set_nextSibling(leftSibling,$4);
Setattr($1,"_last",$4);
$$ = $1;
}
| enumlist COMMA optional_constant_directive {
$$ = $1;
}
| optional_constant_directive edecl optional_constant_directive {
Setattr($2,"_last",$2);
$$ = $2;
}
| optional_constant_directive {
$$ = 0;
}
;
edecl : ID {
SwigType *type = NewSwigType(T_INT);
@ -5631,7 +5692,6 @@ edecl : ID {
Setattr($$,"value",$1);
Delete(type);
}
| empty { $$ = 0; }
;
etype : expr {

View file

@ -11,8 +11,6 @@
* Expands a template into a specialized version.
* ----------------------------------------------------------------------------- */
char cvsroot_templ_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
@ -319,14 +317,13 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab
if (tp) {
Symtab *tsdecl = Getattr(n, "sym:symtab");
while (p && tp) {
String *name, *value, *valuestr, *tydef, *tmp, *tmpr;
String *name, *value, *valuestr, *tmp, *tmpr;
int sz, i;
String *dvalue = 0;
String *qvalue = 0;
name = Getattr(tp, "name");
value = Getattr(p, "value");
tydef = Getattr(p, "typedef");
if (name) {
if (!value)
@ -367,9 +364,6 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab
/* Printf(stdout,"'%s'\n", s); */
}
if (!tydef) {
tydef = dvalue;
}
tmp = NewStringf("#%s", name);
tmpr = NewStringf("\"%s\"", valuestr);
@ -377,7 +371,6 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab
for (i = 0; i < sz; i++) {
String *s = Getitem(cpatchlist, i);
Replace(s, tmp, tmpr, DOH_REPLACE_ID);
/* Replace(s,name,tydef, DOH_REPLACE_ID); */
Replace(s, name, valuestr, DOH_REPLACE_ID);
}
Delete(tmp);
@ -766,6 +759,7 @@ static Node *template_locate(String *name, Parm *tparms, Symtab *tscope) {
for (i = 1; i < posslen; i++) {
String *templcsymname = Getattr(Getitem(possiblepartials, i), "templcsymname");
Node *ignored_node = Swig_symbol_clookup_local(templcsymname, primary_scope);
assert(ignored_node);
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, Getfile(ignored_node), Getline(ignored_node), " instantiation '%s' ignored.\n", SwigType_namestr(Getattr(ignored_node, "name")));
}
}

View file

@ -11,8 +11,6 @@
* Parsing utilities.
* ----------------------------------------------------------------------------- */
char cvsroot_util_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"

View file

@ -69,7 +69,7 @@ Close(obj) Close
String Operations
-----------------
Replace(obj, orig, rep, flags) Replace occurences of orig with rep.
Replace(obj, orig, rep, flags) Replace occurrences of orig with rep.
Chop(obj) Remove trailing whitespace
flags is one of the following:

View file

@ -12,8 +12,6 @@
* DOH objects. A number of small utility functions are also included.
* ----------------------------------------------------------------------------- */
char cvsroot_base_c[] = "$Id$";
#include "dohint.h"
/* -----------------------------------------------------------------------------
@ -761,6 +759,7 @@ int DohUngetc(int ch, DOH *obj) {
* DohClose()
* ----------------------------------------------------------------------------- */
/*
int DohClose(DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
@ -773,6 +772,7 @@ int DohClose(DOH *obj) {
}
return fclose((FILE *) obj);
}
*/
/* -----------------------------------------------------------------------------
* DohIsString()

View file

@ -254,7 +254,7 @@ extern int DohDelmeta(DOH *, const DOH *);
/* Utility functions */
extern void DohEncoding(char *name, DOH *(*fn) (DOH *s));
extern void DohEncoding(const char *name, DOH *(*fn) (DOH *s));
extern int DohPrintf(DOHFile * obj, const char *format, ...);
extern int DohvPrintf(DOHFile * obj, const char *format, va_list ap);
extern int DohPrintv(DOHFile * obj, ...);
@ -307,7 +307,10 @@ extern DOHFile *DohNewFile(DOH *filename, const char *mode, DOHList *outfiles);
extern DOHFile *DohNewFileFromFile(FILE *f);
extern DOHFile *DohNewFileFromFd(int fd);
extern void DohFileErrorDisplay(DOHString * filename);
/*
Deprecated, just use DohDelete
extern int DohClose(DOH *file);
*/
extern int DohCopyto(DOHFile * input, DOHFile * output);

View file

@ -63,7 +63,7 @@ typedef struct {
* ----------------------------------------------------------------------------- */
typedef struct DohObjInfo {
char *objname; /* Object name */
const char *objname; /* Object name */
/* Basic object methods */
void (*doh_del) (DOH *obj); /* Delete object */

View file

@ -12,8 +12,6 @@
* ordinary FILE * or integer file descriptor.
* ----------------------------------------------------------------------------- */
char cvsroot_file_c[] = "$Id$";
#include "dohint.h"
#ifdef DOH_INTFILE

View file

@ -12,8 +12,6 @@
* formatted output, readline, and splitting.
* ----------------------------------------------------------------------------- */
char cvsroot_fio_c[] = "$Id$";
#include "dohint.h"
#define OBUFLEN 512
@ -47,7 +45,7 @@ static int Writen(DOH *out, void *buffer, int len) {
* two file-like objects and operate as a filter.
* ----------------------------------------------------------------------------- */
void DohEncoding(char *name, DOH *(*fn) (DOH *s)) {
void DohEncoding(const char *name, DOH *(*fn) (DOH *s)) {
if (!encodings)
encodings = NewHash();
Setattr(encodings, (void *) name, NewVoid((void *) fn, 0));
@ -76,7 +74,8 @@ static DOH *encode(char *name, DOH *s) {
Seek(s, 0, SEEK_SET);
fn = (DOH *(*)(DOH *)) Data(handle);
ns = (*fn) (s);
Seek(s, pos, SEEK_SET);
assert(pos != -1);
(void)Seek(s, pos, SEEK_SET);
if (tmp)
Delete(tmp);
return ns;
@ -101,7 +100,7 @@ static DOH *encode(char *name, DOH *s) {
* ----------------------------------------------------------------------------- */
int DohvPrintf(DOH *so, const char *format, va_list ap) {
static char *fmt_codes = "dioxXucsSfeEgGpn";
static const char *fmt_codes = "dioxXucsSfeEgGpn";
int state = 0;
const char *p = format;
char newformat[256];
@ -480,16 +479,19 @@ int DohCopyto(DOH *in, DOH *out) {
cw = buffer;
while (nwrite) {
wret = Write(out, cw, nwrite);
if (wret < 0)
return -1;
if (wret < 0) {
nbytes = -1;
break;
}
nwrite = nwrite - wret;
cw += wret;
}
nbytes += ret;
} else {
return nbytes;
break;
}
}
return nbytes;
}
@ -577,15 +579,16 @@ DOH *DohReadline(DOH *in) {
if (Read(in, &c, 1) < 0) {
if (n == 0) {
Delete(s);
return 0;
s = 0;
}
return s;
break;
}
if (c == '\n')
return s;
break;
if (c == '\r')
continue;
Putc(c, s);
n++;
}
return s;
}

View file

@ -11,8 +11,6 @@
* Implements a simple hash table object.
* ----------------------------------------------------------------------------- */
char cvsroot_hash_c[] = "$Id$";
#include "dohint.h"
extern DohObjInfo DohHashType;
@ -415,12 +413,12 @@ static DOH *Hash_str(DOH *ho) {
s = NewStringEmpty();
if (ObjGetMark(ho)) {
Printf(s, "Hash(0x%x)", ho);
Printf(s, "Hash(%p)", ho);
return s;
}
if (expanded >= max_expand) {
/* replace each hash attribute with a '.' */
Printf(s, "Hash(0x%x) {", ho);
Printf(s, "Hash(%p) {", ho);
for (i = 0; i < h->hashsize; i++) {
n = h->hashtable[i];
while (n) {
@ -432,7 +430,7 @@ static DOH *Hash_str(DOH *ho) {
return s;
}
ObjSetMark(ho, 1);
Printf(s, "Hash(0x%x) {\n", ho);
Printf(s, "Hash(%p) {\n", ho);
for (i = 0; i < h->hashsize; i++) {
n = h->hashtable[i];
while (n) {

View file

@ -11,8 +11,6 @@
* Implements a simple list object.
* ----------------------------------------------------------------------------- */
char cvsroot_list_c[] = "$Id$";
#include "dohint.h"
typedef struct List {
@ -242,7 +240,7 @@ static DOH *List_str(DOH *lo) {
List *l = (List *) ObjData(lo);
s = NewStringEmpty();
if (ObjGetMark(lo)) {
Printf(s, "List(%x)", lo);
Printf(s, "List(%p)", lo);
return s;
}
ObjSetMark(lo, 1);

View file

@ -12,14 +12,17 @@
* of objects and checking of objects.
* ----------------------------------------------------------------------------- */
char cvsroot_memory_c[] = "$Id$";
#include "dohint.h"
#ifndef DOH_POOL_SIZE
#define DOH_POOL_SIZE 16384
#endif
/* Checks stale DOH object use - will use a lot more memory as pool memory is not re-used. */
/*
#define DOH_DEBUG_MEMORY_POOLS
*/
static int PoolSize = DOH_POOL_SIZE;
DOH *DohNone = 0; /* The DOH None object */
@ -81,8 +84,14 @@ int DohCheck(const DOH *ptr) {
register Pool *p = Pools;
register char *cptr = (char *) ptr;
while (p) {
if ((cptr >= p->pbeg) && (cptr < p->pend))
if ((cptr >= p->pbeg) && (cptr < p->pend)) {
#ifdef DOH_DEBUG_MEMORY_POOLS
DohBase *b = (DohBase *) ptr;
int DOH_object_already_deleted = b->type == 0;
assert(!DOH_object_already_deleted);
#endif
return 1;
}
/*
pptr = (char *) p->ptr;
if ((cptr >= pptr) && (cptr < (pptr+(p->current*sizeof(DohBase))))) return 1; */
@ -110,16 +119,20 @@ DOH *DohObjMalloc(DohObjInfo *type, void *data) {
DohBase *obj;
if (!pools_initialized)
InitPools();
#ifndef DOH_DEBUG_MEMORY_POOLS
if (FreeList) {
obj = FreeList;
FreeList = (DohBase *) obj->data;
} else {
#endif
while (Pools->current == Pools->len) {
CreatePool();
}
obj = Pools->ptr + Pools->current;
++Pools->current;
#ifndef DOH_DEBUG_MEMORY_POOLS
}
#endif
obj->type = type;
obj->data = data;
obj->meta = 0;
@ -144,6 +157,7 @@ void DohObjFree(DOH *ptr) {
b->data = (void *) FreeList;
b->meta = 0;
b->type = 0;
b->refcount = 0;
FreeList = b;
if (meta) {
Delete(meta);

View file

@ -12,8 +12,6 @@
* file semantics.
* ----------------------------------------------------------------------------- */
char cvsroot_string_c[] = "$Id$";
#include "dohint.h"
extern DohObjInfo DohStringType;
@ -1153,11 +1151,7 @@ DOHString *DohNewStringf(const DOHString_or_char *fmt, ...) {
int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2) {
const char *c1 = Char(s1);
const char *c2 = Char(s2);
if (c1 && c2) {
return strcmp(c1, c2);
} else {
return c1 < c2;
}
return strcmp(c1, c2);
}
int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n) {

View file

@ -12,8 +12,6 @@
* an arbitrary C object represented as a void *.
* ----------------------------------------------------------------------------- */
char cvsroot_void_c[] = "$Id$";
#include "dohint.h"
typedef struct {

View file

@ -89,6 +89,7 @@
#define WARN_PARSE_REC_INHERITANCE 323
#define WARN_PARSE_NESTED_TEMPLATE 324
#define WARN_PARSE_NAMED_NESTED_CLASS 325
#define WARN_PARSE_EXTEND_NAME 326
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */
@ -196,6 +197,8 @@
#define WARN_LANG_TEMPLATE_METHOD_IGNORE 519
#define WARN_LANG_SMARTPTR_MISSING 520
#define WARN_LANG_ILLEGAL_DESTRUCTOR 521
#define WARN_LANG_EXTEND_CONSTRUCTOR 522
#define WARN_LANG_EXTEND_DESTRUCTOR 523
/* -- Reserved (600-799) -- */
@ -241,6 +244,7 @@
#define WARN_JAVA_TYPEMAP_JAVACONSTRUCT_UNDEF 823
#define WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC 824
#define WARN_JAVA_NO_DIRECTORCONNECT_ATTR 825
#define WARN_JAVA_NSPACE_WITHOUT_PACKAGE 826
/* please leave 810-829 free for Java */

View file

@ -11,8 +11,6 @@
* ALLEGROCL language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_allegrocl_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
@ -48,7 +46,7 @@ static File *f_cxx_wrapper = 0;
static String *module_name = 0;
static String *swig_package = 0;
const char *identifier_converter = "identifier-convert-null";
static String *identifier_converter = NewString("identifier-convert-null");
static bool CWrap = true; // generate wrapper file for C code by default. most correct.
static bool Generate_Wrapper = false;
@ -162,51 +160,12 @@ String *namespaced_name(Node *n, String *ns = current_namespace) {
// "Namespace::Nested::Class2::Baz" -> "Baz"
static String *strip_namespaces(String *str) {
SwigType *new_type = Copy(str);
SwigType *leading_type = SwigType_pop(new_type);
char *result = Char(leading_type);
if(SwigType_istemplate(leading_type)) {
result = Char(SwigType_templateprefix(leading_type));
} else {
if (!SwigType_issimple(leading_type))
return NewString(str);
}
String *stripped_one;
while ((stripped_one = Strstr(result, "::")))
result = Char(stripped_one) + 2;
if(SwigType_istemplate(leading_type)) {
SwigType_push(new_type, NewStringf("%s%s%s", result, SwigType_templateargs(leading_type),
SwigType_templatesuffix(leading_type)));
return new_type;
}
return NewString(result);
}
static String *namespace_of(String *str) {
char *p = Char(str);
char *start = Char(str);
char *result = 0;
String *stripped_one;
while ((stripped_one = Strstr(p, "::"))) {
p = Char(stripped_one) + 2;
}
if (p > start) {
int len = p - start - 1;
result = (char *) malloc(len);
strncpy(result, start, len - 1);
result[len - 1] = 0;
}
return Char(result);
return Swig_scopename_last(str);
}
void add_linked_type(Node *n) {
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "Adding linked node of type: %s(%s) %s(%x)\n\n", nodeType(n), Getattr(n, "storage"), Getattr(n, "name"), n);
Printf(stderr, "Adding linked node of type: %s(%s) %s(%p)\n\n", nodeType(n), Getattr(n, "storage"), Getattr(n, "name"), n);
// Swig_print_node(n);
#endif
if (!first_linked_type) {
@ -300,13 +259,13 @@ Node *get_primary_synonym_of(Node *n) {
Node *p = Getattr(n, "allegrocl:synonym-of");
Node *prim = n;
// Printf(stderr, "getting primary synonym of %x\n", n);
// Printf(stderr, "getting primary synonym of %p\n", n);
while (p) {
// Printf(stderr, " found one! %x\n", p);
// Printf(stderr, " found one! %p\n", p);
prim = p;
p = Getattr(p, "allegrocl:synonym-of");
}
// Printf(stderr,"get_primary_syn: DONE. returning %s(%x)\n", Getattr(prim,"name"),prim);
// Printf(stderr,"get_primary_syn: DONE. returning %s(%p)\n", Getattr(prim,"name"),prim);
return prim;
}
@ -331,7 +290,7 @@ void add_forward_referenced_type(Node *n, int overwrite = 0) {
// , name);
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "Linking forward reference type = %s(%x)\n", k, n);
Printf(stderr, "Linking forward reference type = %s(%p)\n", k, n);
#endif
add_linked_type(n);
}
@ -346,8 +305,8 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
String *cDeclName = n ? Getattr(n, "name") : 0;
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "IN A-D-F-T. (n=%x, ow=%d, k=%s, name=%s, ns=%s\n", n, overwrite, k, name, ns);
Printf(stderr, " templated = '%x', classDecl = '%x'\n", templated, cDeclName);
Printf(stderr, "IN A-D-F-T. (n=%p, ow=%d, k=%s, name=%s, ns=%s\n", n, overwrite, k, name, ns);
Printf(stderr, " templated = '%p', classDecl = '%p'\n", templated, cDeclName);
#endif
if (n) {
if (!name)
@ -456,11 +415,12 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
}
}
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "looking to add %s/%s(%x) to linked_type_list...\n", k, name, n);
Printf(stderr, "looking to add %s/%s(%p) to linked_type_list...\n", k, name, n);
#endif
if (is_fwd_ref) {
// Printf(stderr,"*** 1\n");
add_linked_type(n);
if (n)
add_linked_type(n);
} else {
// Printf(stderr,"*** 1-a\n");
if (SwigType_istemplate(k)) {
@ -509,7 +469,7 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
Setattr(new_node, "allegrocl:synonym:is-primary", "1");
} else {
// a synonym type was found (held in variable 'match')
// Printf(stderr, "setting primary synonym of %x to %x\n", new_node, match);
// Printf(stderr, "setting primary synonym of %p to %p\n", new_node, match);
if (new_node == match)
Printf(stderr, "Hey-4 * - '%s' is a synonym of iteself!\n", Getattr(new_node, "name"));
Setattr(new_node, "allegrocl:synonym-of", match);
@ -556,8 +516,8 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
Setattr(n, "allegrocl:synonym-of", match);
Setattr(n, "real-name", Copy(lookup_type));
// Printf(stderr, "*** pre-5: found match of '%s'(%x)\n", Getattr(match,"name"),match);
// if(n == match) Printf(stderr, "Hey-5 *** setting synonym of %x to %x\n", n, match);
// Printf(stderr, "*** pre-5: found match of '%s'(%p)\n", Getattr(match,"name"),match);
// if(n == match) Printf(stderr, "Hey-5 *** setting synonym of %p to %p\n", n, match);
// Printf(stderr,"*** 5\n");
add_linked_type(n);
} else {
@ -615,7 +575,7 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
match = find_linked_type_by_name(resolved);
if (!match) {
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "found no implicit instantiation of %%template node %s(%x)\n", Getattr(n, "name"), n);
Printf(stderr, "found no implicit instantiation of %%template node %s(%p)\n", Getattr(n, "name"), n);
#endif
add_linked_type(n);
} else {
@ -624,14 +584,14 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
Setattr(n, "allegrocl:synonym:is-primary", "1");
Delattr(primary, "allegrocl:synonym:is-primary");
if (n == match)
Printf(stderr, "Hey-7 * setting synonym of %x to %x\n (match = %x)", primary, n, match);
Printf(stderr, "Hey-7 * setting synonym of %p to %p\n (match = %p)", primary, n, match);
Setattr(primary, "allegrocl:synonym-of", n);
// Printf(stderr,"*** 7\n");
add_linked_type(n);
}
} else {
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "linking type '%s'(%x)\n", k, n);
Printf(stderr, "linking type '%s'(%p)\n", k, n);
#endif
// Printf(stderr,"*** 8\n");
add_linked_type(n);
@ -663,7 +623,7 @@ void note_implicit_template_instantiation(SwigType *t) {
#endif
SwigType *type = Copy(t);
SwigType *tok = SwigType_pop(type);
String *implicit_ns = SwigType_istemplate(tok) ? namespace_of(SwigType_templateprefix(tok)) : 0;
String *implicit_ns = SwigType_istemplate(tok) ? Swig_scopename_prefix(SwigType_templateprefix(tok)) : 0;
add_defined_foreign_type(0, 0, t, t, implicit_ns ? implicit_ns : current_namespace);
Delete(type);
@ -821,7 +781,7 @@ String *compose_foreign_type(Node *n, SwigType *ty, String * /*id*/ = 0) {
Printf(stderr, "compose_foreign_type: ENTER (%s)...\n ", ty);
// Printf(stderr, "compose_foreign_type: ENTER (%s)(%s)...\n ", ty, (id ? id : 0));
/* String *id_ref = SwigType_str(ty, id);
Printf(stderr, "looking up typemap for %s, found '%s'(%x)\n",
Printf(stderr, "looking up typemap for %s, found '%s'(%p)\n",
id_ref, lookup_res ? Getattr(lookup_res, "code") : 0, lookup_res);
if (lookup_res) Swig_print_node(lookup_res);
*/
@ -860,7 +820,7 @@ void update_package_if_needed(Node *n, File *f = f_clwrap) {
Printf(stderr, "update_package: ENTER... \n");
Printf(stderr, " current_package = '%s'\n", current_package);
Printf(stderr, " node_package = '%s'\n", Getattr(n, "allegrocl:package"));
Printf(stderr, " node(%x) = '%s'\n", n, Getattr(n, "name"));
Printf(stderr, " node(%p) = '%s'\n", n, Getattr(n, "name"));
#endif
String *node_package = Getattr(n, "allegrocl:package");
if (Strcmp(current_package, node_package)) {
@ -1119,7 +1079,7 @@ String *convert_literal(String *literal, String *type, bool try_to_split) {
void emit_stub_class(Node *n) {
#ifdef ALLEGROCL_WRAP_DEBUG
Printf(stderr, "emit_stub_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n);
Printf(stderr, "emit_stub_class: ENTER... '%s'(%p)\n", Getattr(n, "sym:name"), n);
Swig_print_node(n);
#endif
@ -1157,7 +1117,7 @@ void emit_synonym(Node *synonym) {
Printf(stderr, "emit_synonym: ENTER... \n");
#endif
// Printf(stderr,"in emit_synonym for %s(%x)\n", Getattr(synonym,"name"),synonym);
// Printf(stderr,"in emit_synonym for %s(%p)\n", Getattr(synonym,"name"),synonym);
int is_tempInst = !Strcmp(nodeType(synonym), "templateInst");
String *synonym_type;
@ -1181,13 +1141,14 @@ void emit_synonym(Node *synonym) {
String *of_name = namespaced_name(of, of_ns);
if (CPlusPlus && !Strcmp(nodeType(synonym), "cdecl")) {
syn_ltype = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)",
strip_namespaces(Getattr(synonym, "real-name")), synonym_ns);
syn_type = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)",
strip_namespaces(Getattr(synonym, "real-name")), synonym_ns);
String *real_name = Getattr(synonym, "real-name");
if (!real_name)
real_name = NewString("Unknown"); // TODO: fix
syn_ltype = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", strip_namespaces(real_name), synonym_ns);
syn_type = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)", strip_namespaces(real_name), synonym_ns);
} else {
syn_ltype = lookup_defined_foreign_ltype(synonym_type);
syn_type = lookup_defined_foreign_type(synonym_type);
syn_ltype = lookup_defined_foreign_ltype(synonym_type);
syn_type = lookup_defined_foreign_type(synonym_type);
}
of_ltype = lookup_defined_foreign_ltype(of_name);
@ -1214,7 +1175,7 @@ void emit_full_class(Node *n) {
String *name = Getattr(n, "sym:name");
String *kind = Getattr(n, "kind");
// Printf(stderr,"in emit_full_class: '%s'(%x).", Getattr(n,"name"),n);
// Printf(stderr,"in emit_full_class: '%s'(%p).", Getattr(n,"name"),n);
if (Getattr(n, "allegrocl:synonym-of")) {
// Printf(stderr,"but it's a synonym of something.\n");
update_package_if_needed(n, f_clhead);
@ -1262,7 +1223,7 @@ void emit_full_class(Node *n) {
// hack. why would decl have a value of "variableHandler" and now "0"?
String *childDecl = Getattr(c, "decl");
// Printf(stderr,"childDecl = '%s' (%s)\n", childDecl, Getattr(c,"view"));
if (!Strcmp(childDecl, "0"))
if (!childDecl || !Strcmp(childDecl, "0"))
childDecl = NewString("");
SwigType *childType;
@ -1314,7 +1275,7 @@ void emit_full_class(Node *n) {
void emit_class(Node *n) {
#ifdef ALLEGROCL_WRAP_DEBUG
Printf(stderr, "emit_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n);
Printf(stderr, "emit_class: ENTER... '%s'(%p)\n", Getattr(n, "sym:name"), n);
#endif
int is_tempInst = !Strcmp(nodeType(n), "templateInst");
@ -1373,7 +1334,7 @@ void emit_typedef(Node *n) {
Delete(type);
Node *in_class = Getattr(n, "allegrocl:typedef:in-class");
// Printf(stderr,"in emit_typedef: '%s'(%x).",Getattr(n,"name"),n);
// Printf(stderr,"in emit_typedef: '%s'(%p).",Getattr(n,"name"),n);
if (Getattr(n, "allegrocl:synonym-of")) {
// Printf(stderr," but it's a synonym of something.\n");
emit_synonym(n);
@ -1536,11 +1497,11 @@ void dump_linked_types(File *f) {
Node *n = first_linked_type;
int i = 0;
while (n) {
Printf(f, "%d: (%x) node '%s' name '%s'\n", i++, n, nodeType(n), Getattr(n, "sym:name"));
Printf(f, "%d: (%p) node '%s' name '%s'\n", i++, n, nodeType(n), Getattr(n, "sym:name"));
Node *t = Getattr(n, "allegrocl:synonym-of");
if (t)
Printf(f, " synonym-of %s(%x)\n", Getattr(t, "name"), t);
Printf(f, " synonym-of %s(%p)\n", Getattr(t, "name"), t);
n = Getattr(n, "allegrocl:next_linked_type");
}
}
@ -1556,7 +1517,7 @@ void emit_linked_types() {
while (n) {
String *node_type = nodeType(n);
// Printf(stderr,"emitting node %s(%x) of type %s.", Getattr(n,"name"),n, nodeType(n));
// Printf(stderr,"emitting node %s(%p) of type %s.", Getattr(n,"name"),n, nodeType(n));
if (!Strcmp(node_type, "class") || !Strcmp(node_type, "templateInst")) {
// may need to emit a stub, so it will update the package itself.
// Printf(stderr," Passing to emit_class.");
@ -1604,14 +1565,15 @@ void ALLEGROCL::main(int argc, char *argv[]) {
/* check for built-ins */
if (!strcmp(conv, "lispify")) {
identifier_converter = "identifier-convert-lispify";
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-lispify");
} else if (!strcmp(conv, "null")) {
identifier_converter = "identifier-convert-null";
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-null");
} else {
/* Must be user defined */
char *idconv = new char[strlen(conv) + 1];
strcpy(idconv, conv);
identifier_converter = idconv;
Delete(identifier_converter);
identifier_converter = NewString(conv);
}
} else if (!strcmp(argv[i], "-cwrap")) {
CWrap = true;
@ -1653,7 +1615,6 @@ int ALLEGROCL::top(Node *n) {
if (Generate_Wrapper) {
f_begin = NewFile(cxx_filename, "w", SWIG_output_files());
if (!f_begin) {
Close(f_cl);
Delete(f_cl);
Printf(stderr, "Unable to open %s for writing\n", cxx_filename);
SWIG_exit(EXIT_FAILURE);
@ -1710,15 +1671,13 @@ int ALLEGROCL::top(Node *n) {
Printf(f_cl, "%s\n", f_clhead);
Printf(f_cl, "%s\n", f_clwrap);
Close(f_cl);
Delete(f_cl); // Delete the handle, not the file
Delete(f_cl);
Delete(f_clhead);
Delete(f_clwrap);
Dump(f_runtime, f_begin);
Printf(f_begin, "%s\n", f_cxx_wrapper);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
Delete(f_cxx_wrapper);
@ -2049,7 +2008,7 @@ int emit_num_lin_arguments(ParmList *parms) {
int nargs = 0;
while (p) {
// Printf(stderr,"enla: '%s' lin='%x' numinputs='%s'\n", Getattr(p,"name"), Getattr(p,"tmap:lin"), Getattr(p,"tmap:lin:numinputs"));
// Printf(stderr,"enla: '%s' lin='%p' numinputs='%s'\n", Getattr(p,"name"), Getattr(p,"tmap:lin"), Getattr(p,"tmap:lin:numinputs"));
if (Getattr(p, "tmap:lin")) {
nargs += GetInt(p, "tmap:lin:numinputs");
p = Getattr(p, "tmap:lin:next");
@ -2283,7 +2242,7 @@ IDargs *id_converter_arguments(Node *n) {
result->arity = NewStringf("%d",
// emit_num_arguments(Getattr(n, "wrap:parms")));
emit_num_lin_arguments(Getattr(n, "wrap:parms")));
// Printf(stderr, "got arity of '%s' node '%s' '%x'\n", result->arity, Getattr(n,"name"), Getattr(n,"wrap:parms"));
// Printf(stderr, "got arity of '%s' node '%s' '%p'\n", result->arity, Getattr(n,"name"), Getattr(n,"wrap:parms"));
}
SetVoid(n, "allegrocl:id-converter-args", result);
@ -2361,7 +2320,7 @@ int ALLEGROCL::emit_dispatch_defun(Node *n) {
#endif
List *overloads = Swig_overload_rank(n, true);
// Printf(stderr,"\ndispatch node=%x\n\n", n);
// Printf(stderr,"\ndispatch node=%p\n\n", n);
// Swig_print_node(n);
Node *overloaded_from = Getattr(n,"sym:overloaded");
@ -2669,7 +2628,7 @@ int ALLEGROCL::functionWrapper(Node *n) {
if (Getattr(n, "overload:ignore")) {
// if we're the last overload, make sure to force the emit
// of the rest of the overloads before we leave.
// Printf(stderr, "ignored overload %s(%x)\n", name, Getattr(n, "sym:nextSibling"));
// Printf(stderr, "ignored overload %s(%p)\n", name, Getattr(n, "sym:nextSibling"));
if (!Getattr(n, "sym:nextSibling")) {
update_package_if_needed(n);
emit_buffered_defuns(n);
@ -2749,7 +2708,7 @@ int ALLEGROCL::functionWrapper(Node *n) {
String *actioncode = emit_action(n);
String *tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode);
if (!is_void_return && tm) {
if (!is_void_return) {
if (tm) {
Replaceall(tm, "$result", "lresult");
Printf(f->code, "%s\n", tm);
@ -2798,7 +2757,7 @@ int ALLEGROCL::functionWrapper(Node *n) {
int ALLEGROCL::namespaceDeclaration(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "namespaceDecl: '%s'(0x%x) (fc=0x%x)\n", Getattr(n, "sym:name"), n, firstChild(n));
Printf(stderr, "namespaceDecl: '%s'(%p) (fc=%p)\n", Getattr(n, "sym:name"), n, firstChild(n));
#endif
/* don't wrap a namespace with no contents. package bloat.
@ -3018,7 +2977,7 @@ int ALLEGROCL::typedefHandler(Node *n) {
if (in_class) {
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, " typedef in class '%s'(%x)\n", Getattr(in_class, "sym:name"), in_class);
Printf(stderr, " typedef in class '%s'(%p)\n", Getattr(in_class, "sym:name"), in_class);
#endif
Setattr(n, "allegrocl:typedef:in-class", in_class);
@ -3036,7 +2995,7 @@ int ALLEGROCL::typedefHandler(Node *n) {
String *lookup = lookup_defined_foreign_type(typedef_type);
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "** lookup='%s'(%x), typedef_type='%s', strcmp = '%d' strstr = '%d'\n", lookup, lookup, typedef_type, Strcmp(typedef_type,"void"), Strstr(ff_type,"__SWIGACL_FwdReference"));
Printf(stderr, "** lookup='%s'(%p), typedef_type='%s', strcmp = '%d' strstr = '%d'\n", lookup, lookup, typedef_type, Strcmp(typedef_type,"void"), Strstr(ff_type,"__SWIGACL_FwdReference"));
#endif
if(lookup || (!lookup && Strcmp(typedef_type,"void")) ||
@ -3162,7 +3121,7 @@ int ALLEGROCL::cppClassHandler(Node *n) {
SwigType *childType = NewStringf("%s%s", Getattr(c, "decl"),
Getattr(c, "type"));
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "looking at child '%x' of type '%s' '%d'\n", c, childType, SwigType_isfunction(childType));
Printf(stderr, "looking at child '%p' of type '%s' '%d'\n", c, childType, SwigType_isfunction(childType));
// Swig_print_node(c);
#endif
if (!SwigType_isfunction(childType))

View file

@ -15,8 +15,6 @@
* Doc/Manual/SWIGPlus.html for details.
* ----------------------------------------------------------------------------- */
char cvsroot_allocate_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
@ -43,7 +41,7 @@ extern "C" {
SwigType *decl1 = SwigType_typedef_resolve_all(decl);
SwigType *decl2 = SwigType_pop_function(decl1);
if (Strcmp(decl2, search_decl) == 0) {
if (!Getattr(n, "abstract")) {
if (!GetFlag(n, "abstract")) {
Delete(decl1);
Delete(decl2);
return 1;
@ -327,38 +325,36 @@ class Allocate:public Dispatcher {
Swig_symbol_setscope(oldtab);
return ret;
}
List *abstract = Getattr(base, "abstract");
if (abstract) {
List *abstracts = Getattr(base, "abstracts");
if (abstracts) {
int dabstract = 0;
int len = Len(abstract);
int len = Len(abstracts);
for (int i = 0; i < len; i++) {
Node *nn = Getitem(abstract, i);
Node *nn = Getitem(abstracts, i);
String *name = Getattr(nn, "name");
if (!name)
continue;
if (Strchr(name, '~'))
continue; /* Don't care about destructors */
String *base_decl = Getattr(nn, "decl");
if (base_decl)
base_decl = SwigType_typedef_resolve_all(base_decl);
if (Strchr(name, '~'))
continue; /* Don't care about destructors */
if (SwigType_isfunction(base_decl)) {
if (SwigType_isfunction(base_decl))
search_decl = SwigType_pop_function(base_decl);
}
Node *dn = Swig_symbol_clookup_local_check(name, 0, check_implemented);
Delete(search_decl);
Delete(base_decl);
if (!dn) {
List *nabstract = Getattr(n, "abstract");
if (!nabstract) {
nabstract = NewList();
Setattr(n, "abstract", nabstract);
Delete(nabstract);
List *nabstracts = Getattr(n, "abstracts");
if (!nabstracts) {
nabstracts = NewList();
Setattr(n, "abstracts", nabstracts);
Delete(nabstracts);
}
Append(nabstract, nn);
if (!Getattr(n, "abstract:firstnode")) {
Setattr(n, "abstract:firstnode", nn);
Append(nabstracts, nn);
if (!Getattr(n, "abstracts:firstnode")) {
Setattr(n, "abstracts:firstnode", nn);
}
dabstract = base != n;
}
@ -415,7 +411,7 @@ class Allocate:public Dispatcher {
match = 1;
break;
}
if ((!symname || (!Getattr(e, "sym:name"))) && (Cmp(name, Getattr(e, "name")) == 0)) {
if (!Getattr(e, "sym:name") && (Cmp(name, Getattr(e, "name")) == 0)) {
match = 1;
break;
}
@ -598,19 +594,19 @@ Allocate():
/* Check if the class is abstract via inheritance. This might occur if a class didn't have
any pure virtual methods of its own, but it didn't implement all of the pure methods in
a base class */
if (!Getattr(n, "abstract") && is_abstract_inherit(n)) {
if (!Getattr(n, "abstracts") && is_abstract_inherit(n)) {
if (((Getattr(n, "allocate:public_constructor") || (!GetFlag(n, "feature:nodefault") && !Getattr(n, "allocate:has_constructor"))))) {
if (!GetFlag(n, "feature:notabstract")) {
Node *na = Getattr(n, "abstract:firstnode");
Node *na = Getattr(n, "abstracts:firstnode");
if (na) {
Swig_warning(WARN_TYPE_ABSTRACT, Getfile(n), Getline(n),
"Class '%s' might be abstract, " "no constructors generated,\n", SwigType_namestr(Getattr(n, "name")));
Swig_warning(WARN_TYPE_ABSTRACT, Getfile(na), Getline(na), "Method %s might not be implemented.\n", Swig_name_decl(na));
if (!Getattr(n, "abstract")) {
List *abstract = NewList();
Append(abstract, na);
Setattr(n, "abstract", abstract);
Delete(abstract);
if (!Getattr(n, "abstracts")) {
List *abstracts = NewList();
Append(abstracts, na);
Setattr(n, "abstracts", abstracts);
Delete(abstracts);
}
}
}
@ -620,7 +616,7 @@ Allocate():
if (!Getattr(n, "allocate:has_constructor")) {
/* No constructor is defined. We need to check a few things */
/* If class is abstract. No default constructor. Sorry */
if (Getattr(n, "abstract")) {
if (Getattr(n, "abstracts")) {
Delattr(n, "allocate:default_constructor");
}
if (!Getattr(n, "allocate:default_constructor")) {
@ -641,7 +637,7 @@ Allocate():
}
}
if (!Getattr(n, "allocate:has_copy_constructor")) {
if (Getattr(n, "abstract")) {
if (Getattr(n, "abstracts")) {
Delattr(n, "allocate:copy_constructor");
}
if (!Getattr(n, "allocate:copy_constructor")) {

View file

@ -12,8 +12,6 @@
* feature that's normally disabled.
* ----------------------------------------------------------------------------- */
char cvsroot_browser_cxx[] = "$Id$";
#include "swigmod.h"
#ifdef SWIG_SWILL
@ -29,9 +27,9 @@ class Browser:public Dispatcher {
v = 1;
}
if (v) {
Printf(out, "<a name=\"n%x\"></a>[<a href=\"hide.html?node=0x%x&hn=0x%x#n%x\">-</a>] ", n, t, n, n);
Printf(out, "<a name=\"n%p\"></a>[<a href=\"hide.html?node=%p&hn=%p#n%p\">-</a>] ", n, t, n, n);
} else {
Printf(out, "<a name=\"n%x\"></a>[<a href=\"show.html?node=0x%x&hn=0x%x#n%x\">+</a>] ", n, t, n, n);
Printf(out, "<a name=\"n%p\"></a>[<a href=\"show.html?node=%p&hn=%p#n%p\">+</a>] ", n, t, n, n);
}
}
void show_attributes(Node *obj) {
@ -52,7 +50,7 @@ class Browser:public Dispatcher {
Replaceall(o, "&", "&amp;");
Replaceall(o, "<", "&lt;");
Replaceall(o, ">", "&gt;");
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj, k), k, o);
Printf(os, "<a href=\"data.html?n=%p\">?</a> %-12s - %s\n", Getattr(obj, k), k, o);
Delete(o);
} else {
DOH *o;
@ -64,10 +62,10 @@ class Browser:public Dispatcher {
}
Replaceall(o, "&", "&amp;");
Replaceall(o, "<", "&lt;");
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Printf(os, "<a href=\"data.html?n=%p\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Delete(o);
} else {
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
Printf(os, "<a href=\"data.html?n=%p\">?</a> %-12s - %p\n", Getattr(obj, k), k, Getattr(obj, k));
}
}
ki = Next(ki);
@ -84,7 +82,7 @@ public:
char *name = GetChar(n, "name");
show_checkbox(view_top, n);
Printf(out, "<b><a href=\"index.html?node=0x%x\">%s</a></b>", n, tag);
Printf(out, "<b><a href=\"index.html?node=%p\">%s</a></b>", n, tag);
if (name) {
Printf(out, " (%s)", name);
}
@ -184,9 +182,9 @@ static void display(FILE *f, Node *n) {
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", Swig_package_version());
Printf(f, "<b>SWIG-%s</b><br>\n", Swig_package_version());
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, " [ <a href=\"index.html?node=%p\">Top</a> ]", tree_top);
if (n != tree_top) {
Printf(f, " [ <a href=\"index.html?node=0x%x\">Up</a> ]", parentNode(n));
Printf(f, " [ <a href=\"index.html?node=%p\">Up</a> ]", parentNode(n));
}
Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f, "<br><hr><p>\n");
@ -255,10 +253,10 @@ void raw_data(FILE *out, Node *obj) {
trunc = "...";
}
Replaceall(o, "<", "&lt;");
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Printf(os, " <a href=\"data.html?n=%p\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Delete(o);
} else {
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
Printf(os, " <a href=\"data.html?n=%p\">?</a> %-12s - %p\n", Getattr(obj, k), k, Getattr(obj, k));
}
ki = Next(ki);
}
@ -283,10 +281,10 @@ void raw_data(FILE *out, Node *obj) {
trunc = "...";
}
Replaceall(o, "<", "&lt;");
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc);
Printf(os, " <a href=\"data.html?n=%p\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc);
Delete(s);
} else {
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
Printf(os, " <a href=\"data.html?n=%p\">?</a> [%d] - %p\n", o, i, o);
}
}
Printf(os, "\n]\n");
@ -303,7 +301,7 @@ void data_handler(FILE *f) {
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", Swig_package_version());
Printf(f, "<b>SWIG-%s</b><br>\n", Swig_package_version());
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, " [ <a href=\"index.html?node=%p\">Top</a> ]", tree_top);
Printf(f, "<br><hr><p>\n");
if (n) {
raw_data(f, n);
@ -319,7 +317,7 @@ void symbol_handler(FILE *f) {
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", Swig_package_version());
Printf(f, "<b>SWIG-%s</b><br>\n", Swig_package_version());
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, " [ <a href=\"index.html?node=%p\">Top</a> ]", tree_top);
Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f, "<br><hr><p>\n");
@ -343,7 +341,7 @@ void symbol_handler(FILE *f) {
fprintf(f, "<p><form action=\"symbol.html\" method=GET>\n");
fprintf(f, "Symbol lookup: <input type=text name=name size=40></input><br>\n");
fprintf(f, "<input type=hidden name=sym value=\"0x%x\">\n", sym);
fprintf(f, "<input type=hidden name=sym value=\"%p\">\n", sym);
fprintf(f, "Submit : <input type=submit></input>\n");
fprintf(f, "</form>");
@ -365,7 +363,7 @@ void symbol_handler(FILE *f) {
Hash *h;
h = firstChild(sym);
while (h) {
Printf(f, "<a href=\"symbol.html?sym=0x%x\">%s</a>\n", h, Getattr(h, "name"));
Printf(f, "<a href=\"symbol.html?sym=%p\">%s</a>\n", h, Getattr(h, "name"));
h = nextSibling(h);
}
}

View file

@ -11,8 +11,6 @@
* cffi language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_cffi_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
@ -137,7 +135,6 @@ int CFFI::top(Node *n) {
if (CPlusPlus || CWrap) {
f_begin = NewFile(cxx_filename, "w", SWIG_output_files());
if (!f_begin) {
Close(f_lisp);
Delete(f_lisp);
Printf(stderr, "Unable to open %s for writing\n", cxx_filename);
SWIG_exit(EXIT_FAILURE);
@ -147,7 +144,6 @@ int CFFI::top(Node *n) {
Printf(clos_filename, "%s%s-clos.lisp", SWIG_output_directory(), module);
f_clos = NewFile(clos_filename, "w", SWIG_output_files());
if (!f_clos) {
Close(f_lisp);
Delete(f_lisp);
Printf(stderr, "Unable to open %s for writing\n", cxx_filename);
SWIG_exit(EXIT_FAILURE);
@ -184,13 +180,11 @@ int CFFI::top(Node *n) {
Printf(f_lisp, "%s\n", f_cl);
Printf(f_lisp, "%s\n", f_clwrap);
Close(f_lisp);
Delete(f_lisp); // Deletes the handle, not the file
Delete(f_lisp);
Delete(f_cl);
Delete(f_clhead);
Delete(f_clwrap);
Dump(f_runtime, f_begin);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
Delete(f_cxx_wrapper);
@ -326,7 +320,7 @@ void CFFI::emit_initialize_instance(Node *n) {
else
Printf(args_placeholder, " %s", argname);
if (Strcmp(ffitype, lispify_name(parent, lispy_name(Char(Getattr(parent, "sym:name"))), "'classname")) == 0)
if (ffitype && Strcmp(ffitype, lispify_name(parent, lispy_name(Char(Getattr(parent, "sym:name"))), "'classname")) == 0)
Printf(args_call, " (ff-pointer %s)", argname);
else
Printf(args_call, " %s", argname);
@ -462,10 +456,12 @@ int CFFI::functionWrapper(Node *n) {
String *actioncode = emit_action(n);
String *result_convert = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode);
Replaceall(result_convert, "$result", "lresult");
Printf(f->code, "%s\n", result_convert);
if(!is_void_return) Printf(f->code, " return lresult;\n");
Delete(result_convert);
if (result_convert) {
Replaceall(result_convert, "$result", "lresult");
Printf(f->code, "%s\n", result_convert);
if(!is_void_return) Printf(f->code, " return lresult;\n");
Delete(result_convert);
}
emit_return_variable(n, Getattr(n, "type"), f);
Printf(f->code, " } catch (...) {\n");
@ -567,7 +563,13 @@ void CFFI::emit_defun(Node *n, String *name) {
int CFFI::constantWrapper(Node *n) {
String *type = Getattr(n, "type");
String *converted_value = convert_literal(Getattr(n, "value"), type);
String *converted_value;
if (SwigType_type(type) == T_STRING) {
converted_value = NewString(Getattr(n, "rawval"));
} else {
converted_value = convert_literal(Getattr(n, "value"), type);
}
String *name = lispify_name(n, Getattr(n, "sym:name"), "'constant");
if (Strcmp(name, "t") == 0 || Strcmp(name, "T") == 0)
@ -671,7 +673,7 @@ int CFFI::enumDeclaration(Node *n) {
void CFFI::emit_class(Node *n) {
#ifdef CFFI_WRAP_DEBUG
Printf(stderr, "emit_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n);
Printf(stderr, "emit_class: ENTER... '%s'(%p)\n", Getattr(n, "sym:name"), n);
#endif
String *name = Getattr(n, "sym:name");
@ -837,7 +839,7 @@ void CFFI::emit_struct_union(Node *n, bool un = false) {
String *typespec = tm ? NewString(tm) : NewString("");
String *slot_name = lispify_name(c, Getattr(c, "sym:name"), "'slotname");
if (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0)
if (slot_name && (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0))
slot_name = NewStringf("t_var");
Printf(f_cl, "\n\t(%s %s)", slot_name, typespec);
@ -1023,9 +1025,8 @@ String *CFFI::convert_literal(String *literal, String *type, bool try_to_split)
return num;
} else if (SwigType_type(type) == T_CHAR) {
/* Use CL syntax for character literals */
String* result = NewStringf("#\\%c", s[2]);
String* result = NewStringf("#\\%c", s[0]);
Delete(num);
// Printf(stderr, "%s %c %d", s, s[2], s);
return result;
} else if (SwigType_type(type) == T_STRING) {
/* Use CL syntax for string literals */
@ -1034,10 +1035,14 @@ String *CFFI::convert_literal(String *literal, String *type, bool try_to_split)
return result;
} else if (SwigType_type(type) == T_INT || SwigType_type(type) == T_UINT) {
// Printf(stderr, "Is a T_INT or T_UINT %s, before replaceall\n", s);
Replaceall(num, "u", "");
Replaceall(num, "U", "");
Replaceall(num, "l", "");
Replaceall(num, "L", "");
const char *num_start = Char(num);
bool is_literal = isdigit(*num_start) || (*num_start == '.') || (*num_start == '+') || (*num_start == '-');
if (is_literal) {
Replaceall(num, "u", "");
Replaceall(num, "U", "");
Replaceall(num, "l", "");
Replaceall(num, "L", "");
}
int i, j;
if (sscanf(s, "%d >> %d", &i, &j) == 2) {
@ -1053,10 +1058,10 @@ String *CFFI::convert_literal(String *literal, String *type, bool try_to_split)
if (Len(num) >= 2 && s[0] == '0') { /* octal or hex */
if (s[1] == 'x'){
DohReplace(num,"0","#",DOH_REPLACE_FIRST);
Replace(num,"0","#",DOH_REPLACE_FIRST);
}
else{
DohReplace(num,"0","#o",DOH_REPLACE_FIRST);
Replace(num,"0","#o",DOH_REPLACE_FIRST);
}
}
return num;

View file

@ -11,8 +11,6 @@
* CHICKEN language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_chicken_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
@ -290,8 +288,6 @@ int CHICKEN::top(Node *n) {
Printf(f_scm, "%s\n", chickentext);
Close(f_scm);
Delete(f_scm);
char buftmp[20];
@ -324,7 +320,6 @@ int CHICKEN::top(Node *n) {
Delete(f_wrappers);
Delete(f_sym_size);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;

View file

@ -11,8 +11,6 @@
* clisp language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_clisp_cxx[] = "$Id$";
#include "swigmod.h"
static const char *usage = (char *) "\
@ -78,13 +76,13 @@ int CLISP::top(Node *n) {
/* Get the output file name */
String *outfile = Getattr(n, "outfile");
if (!outfile)
output_filename = outfile;
else {
output_filename = NewString("");
Printf(output_filename, "%s%s.lisp", SWIG_output_directory(), module);
if (!outfile) {
Printf(stderr, "Unable to determine outfile\n");
SWIG_exit(EXIT_FAILURE);
}
output_filename = NewStringf("%s%s.lisp", SWIG_output_directory(), module);
f_cl = NewFile(output_filename, "w+", SWIG_output_files());
if (!f_cl) {
FileErrorDisplay(output_filename);
@ -132,17 +130,16 @@ int CLISP::top(Node *n) {
for (len--; len >= 0; len--) {
end--;
Seek(f_cl, len, SEEK_SET);
(void)Seek(f_cl, len, SEEK_SET);
int ch = Getc(f_cl);
Seek(f_cl, end, SEEK_SET);
(void)Seek(f_cl, end, SEEK_SET);
Putc(ch, f_cl);
}
Seek(f_cl, 0, SEEK_SET);
Write(f_cl, Char(header), Len(header));
Close(f_cl);
Delete(f_cl); // Deletes the handle, not the file
Delete(f_cl);
return SWIG_OK;
}

View file

@ -11,8 +11,6 @@
* Support for Wrap by Contract in SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_contract_cxx[] = "$Id$";
#include "swigmod.h"
/* Contract structure. This holds rules about the different kinds of contract sections

View file

@ -11,8 +11,6 @@
* C# language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_csharp_cxx[] = "$Id$";
#include "swigmod.h"
#include <limits.h> // for INT_MAX
#include "cparse.h"
@ -156,7 +154,9 @@ public:
dmethods_seq(NULL),
dmethods_table(NULL),
n_dmethods(0),
n_directors(0) {
n_directors(0),
first_class_dmethod(0),
curr_class_dmethod(0) {
/* for now, multiple inheritance in directors is disabled, this
should be easy to implement though */
director_multiple_inheritance = 0;
@ -196,24 +196,6 @@ public:
return proxyname;
}
/* -----------------------------------------------------------------------------
* directorClassName()
* ----------------------------------------------------------------------------- */
String *directorClassName(Node *n) {
String *dirclassname;
const char *attrib = "director:classname";
if (!(dirclassname = Getattr(n, attrib))) {
String *classname = Getattr(n, "sym:name");
dirclassname = NewStringf("SwigDirector_%s", classname);
Setattr(n, attrib, dirclassname);
}
return dirclassname;
}
/* ------------------------------------------------------------
* main()
* ------------------------------------------------------------ */
@ -359,8 +341,10 @@ public:
}
// module class and intermediary classes are always created
addSymbol(imclass_name, n);
addSymbol(module_class_name, n);
if (!addSymbol(imclass_name, n))
return SWIG_ERROR;
if (!addSymbol(module_class_name, n))
return SWIG_ERROR;
imclass_class_code = NewString("");
proxy_class_def = NewString("");
@ -403,8 +387,11 @@ public:
Printf(f_directors, "/* ---------------------------------------------------\n");
Printf(f_directors, " * C++ director class methods\n");
Printf(f_directors, " * --------------------------------------------------- */\n\n");
if (outfile_h)
Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
if (outfile_h) {
String *filename = Swig_file_filename(outfile_h);
Printf(f_directors, "#include \"%s\"\n\n", filename);
Delete(filename);
}
}
Printf(f_runtime, "\n");
@ -467,7 +454,7 @@ public:
Printf(f_im, "}\n");
addCloseNamespace(0, f_im);
Close(f_im);
Delete(f_im);
}
// Generate the C# module class
@ -519,7 +506,7 @@ public:
Printf(f_module, "}\n");
addCloseNamespace(0, f_module);
Close(f_module);
Delete(f_module);
}
if (upcasts_code)
@ -610,7 +597,6 @@ public:
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
Close(f_runtime_h);
Delete(f_runtime_h);
f_runtime_h = NULL;
Delete(f_directors);
@ -624,7 +610,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -645,23 +630,14 @@ public:
*----------------------------------------------------------------------*/
UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *decl, String *overloaded_name) {
UpcallData *udata;
String *class_methodidx;
Hash *new_udata;
String *key = NewStringf("%s|%s", imclass_method, decl);
++curr_class_dmethod;
/* Do we know about this director class already? */
if ((udata = Getattr(dmethods_table, key))) {
Delete(key);
return Getattr(udata, "methodoff");
}
class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
n_dmethods++;
new_udata = NewHash();
Hash *new_udata = NewHash();
Append(dmethods_seq, new_udata);
Setattr(dmethods_table, key, new_udata);
@ -794,8 +770,10 @@ public:
if (Getattr(n, "sym:overloaded")) {
// Emit warnings for the few cases that can't be overloaded in C# and give up on generating wrapper
Swig_overload_check(n);
if (Getattr(n, "overload:ignore"))
if (Getattr(n, "overload:ignore")) {
DelWrapper(f);
return SWIG_OK;
}
}
Printv(imclass_class_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL);
@ -918,7 +896,7 @@ public:
if ((throw_parm_list = Getattr(n, "catchlist"))) {
Swig_typemap_attach_parms("throws", throw_parm_list, f);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
canThrow(n, "throws", p);
}
}
@ -1225,7 +1203,7 @@ public:
"\n", enum_code, "\n", NIL);
addCloseNamespace(nspace, f_enum);
Close(f_enum);
Delete(f_enum);
Delete(output_directory);
}
} else {
@ -1955,7 +1933,7 @@ public:
Printf(f_proxy, "}\n");
addCloseNamespace(nspace, f_proxy);
Close(f_proxy);
Delete(f_proxy);
f_proxy = NULL;
/* Output the downcast method, if necessary. Note: There's no other really
@ -2323,14 +2301,18 @@ public:
// Get the C# variable type - obtained differently depending on whether a setter is required.
String *variable_type = return_type;
if (setter_flag) {
p = last_parm; // (last parameter is the only parameter for properties)
SwigType *pt = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:cstype"))) {
substituteClassname(pt, tm);
String *cstypeout = Getattr(p, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
variable_type = cstypeout ? cstypeout : tm;
assert(last_parm); // (last parameter is the only parameter for properties)
/* Get variable type - ensure the variable name is fully resolved during typemap lookup via the symbol table set in NewParmNode */
SwigType *cvariable_type = Getattr(last_parm, "type");
Parm *variable_parm = NewParmNode(cvariable_type, n);
if ((tm = Swig_typemap_lookup("cstype", variable_parm, "", 0))) {
String *cstypeout = Getattr(variable_parm, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
if (cstypeout)
tm = cstypeout;
substituteClassname(cvariable_type, tm);
variable_type = tm;
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0));
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(cvariable_type, 0));
}
}
const String *csattributes = Getattr(n, "feature:cs:attributes");
@ -2345,16 +2327,17 @@ public:
if (setter_flag) {
// Setter method
p = last_parm; // (last parameter is the only parameter for properties)
SwigType *pt = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:csvarin"))) {
substituteClassname(pt, tm);
assert(last_parm); // (last parameter is the only parameter for properties)
SwigType *cvariable_type = Getattr(last_parm, "type");
Parm *variable_parm = NewParmNode(cvariable_type, n);
if ((tm = Swig_typemap_lookup("csvarin", variable_parm, "", 0))) {
substituteClassname(cvariable_type, tm);
Replaceall(tm, "$csinput", "value");
Replaceall(tm, "$imcall", imcall);
excodeSubstitute(n, tm, "csvarin", p);
excodeSubstitute(n, tm, "csvarin", variable_parm);
Printf(proxy_class_code, "%s", tm);
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0));
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(cvariable_type, 0));
}
} else {
// Getter method
@ -3227,7 +3210,7 @@ public:
addCloseNamespace(0, f_swigtype);
Close(f_swigtype);
Delete(f_swigtype);
Delete(swigtype);
Delete(n);
}
@ -3398,6 +3381,8 @@ public:
String *sym_name = Getattr(n, "sym:name");
String *qualified_classname = Copy(sym_name);
String *nspace = getNSpace();
String *dirClassName = directorClassName(n);
String *smartptr = Getattr(n, "feature:smartptr");
if (nspace)
Insert(qualified_classname, 0, NewStringf("%s.", nspace));
@ -3408,8 +3393,17 @@ public:
Wrapper *code_wrap = NewWrapper();
Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL %s(void *objarg", wname);
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name);
Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name);
if (Len(smartptr)) {
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", smartptr, smartptr);
Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n");
Printf(code_wrap->code, " // Avoids using smart pointer specific API.\n");
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName);
}
else {
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name);
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName);
}
// TODO: if statement not needed?? - Java too
Printf(code_wrap->code, " if (director) {\n");
Printf(code_wrap->code, " director->swig_connect_director(");
@ -3421,7 +3415,7 @@ public:
Printf(code_wrap->def, ", ");
if (i != first_class_dmethod)
Printf(code_wrap->code, ", ");
Printf(code_wrap->def, "SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid);
Printf(code_wrap->def, "%s::SWIG_Callback%s_t callback%s", dirClassName, methid, methid);
Printf(code_wrap->code, "callback%s", methid);
Printf(imclass_class_code, ", %s.SwigDelegate%s_%s delegate%s", qualified_classname, sym_name, methid, methid);
}
@ -3438,6 +3432,7 @@ public:
Delete(wname);
Delete(swig_director_connect);
Delete(qualified_classname);
Delete(dirClassName);
}
/* ---------------------------------------------------------------
@ -3449,25 +3444,26 @@ public:
* --------------------------------------------------------------- */
int classDirectorMethod(Node *n, Node *parent, String *super) {
String *empty_str = NewString("");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
SwigType *returntype = Getattr(n, "returntype");
SwigType *returntype = Getattr(n, "type");
String *overloaded_name = getOverloadedName(n);
String *storage = Getattr(n, "storage");
String *value = Getattr(n, "value");
String *decl = Getattr(n, "decl");
String *declaration = NewString("");
String *pre_code = NewString("");
String *post_code = NewString("");
String *terminator_code = NewString("");
String *tm;
Parm *p;
int i;
Wrapper *w = NewWrapper();
ParmList *l = Getattr(n, "parms");
bool is_void = !(Cmp(returntype, "void"));
String *qualified_return = NewString("");
String *qualified_return = 0;
bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0")));
int status = SWIG_OK;
bool output_director = true;
@ -3491,94 +3487,85 @@ public:
imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name));
if (returntype) {
qualified_return = SwigType_rcaststr(returntype, "c_result");
qualified_return = SwigType_rcaststr(returntype, "c_result");
if (!is_void && !ignored_method) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
String *base_typename = SwigType_base(returntype);
String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
Symtab *symtab = Getattr(n, "sym:symtab");
Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) {
/* initialize pointers to something sane. Same for abstract
classes when a reference is returned. */
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
} else {
/* If returning a reference, initialize the pointer to a sane
default - if a C# exception occurs, then the pointer returns
something other than a NULL-initialized reference. */
String *non_ref_type = Copy(returntype);
/* Remove reference and const qualifiers */
Replaceall(non_ref_type, "r.", "");
Replaceall(non_ref_type, "q(const).", "");
Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL);
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL);
Delete(non_ref_type);
}
Delete(base_typename);
Delete(resolved_typename);
}
if (!is_void && !ignored_method) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
SwigType *vt;
String *base_typename = SwigType_base(returntype);
String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
Symtab *symtab = Getattr(n, "sym:symtab");
Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
vt = cplus_value_type(returntype);
if (!vt) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstracts"))) {
/* initialize pointers to something sane. Same for abstract
classes when a reference is returned. */
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL);
Delete(vt);
/* If returning a reference, initialize the pointer to a sane
default - if a C# exception occurs, then the pointer returns
something other than a NULL-initialized reference. */
String *non_ref_type = Copy(returntype);
/* Remove reference and const qualifiers */
Replaceall(non_ref_type, "r.", "");
Replaceall(non_ref_type, "q(const).", "");
Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL);
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL);
Delete(non_ref_type);
}
Delete(base_typename);
Delete(resolved_typename);
}
} else {
SwigType *vt;
vt = cplus_value_type(returntype);
if (!vt) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL);
Delete(vt);
}
}
}
/* Create the intermediate class wrapper */
Parm *tp = NewParm(returntype, empty_str, n);
tm = Swig_typemap_lookup("imtype", tp, "", 0);
if (tm) {
String *imtypeout = Getattr(tp, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap
if (imtypeout)
tm = imtypeout;
const String *im_directoroutattributes = Getattr(tp, "tmap:imtype:directoroutattributes");
if (im_directoroutattributes) {
Printf(callback_def, " %s\n", im_directoroutattributes);
Printf(director_delegate_definitions, " %s\n", im_directoroutattributes);
}
Printf(callback_def, " private %s SwigDirector%s(", tm, overloaded_name);
/* Create the intermediate class wrapper */
tm = Swig_typemap_lookup("imtype", n, "", 0);
if (tm) {
String *imtypeout = Getattr(n, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap
if (imtypeout)
tm = imtypeout;
const String *im_directoroutattributes = Getattr(n, "tmap:imtype:directoroutattributes");
if (im_directoroutattributes) {
Printf(callback_def, " %s\n", im_directoroutattributes);
if (!ignored_method)
Printf(director_delegate_definitions, " public delegate %s", tm);
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
Printf(director_delegate_definitions, " %s\n", im_directoroutattributes);
}
Parm *retpm = NewParm(returntype, empty_str, n);
Printf(callback_def, " private %s SwigDirector%s(", tm, overloaded_name);
if (!ignored_method)
Printf(director_delegate_definitions, " public delegate %s", tm);
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
if ((c_ret_type = Swig_typemap_lookup("ctype", retpm, "", 0))) {
if (!is_void && !ignored_method) {
String *jretval_decl = NewStringf("%s jresult", c_ret_type);
Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
Delete(jretval_decl);
}
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) {
if (!is_void && !ignored_method) {
String *jretval_decl = NewStringf("%s jresult", c_ret_type);
Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
Delete(jretval_decl);
}
Delete(retpm);
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
Swig_director_parms_fixup(l);
@ -3655,8 +3642,6 @@ public:
if (!ignored_method)
Printf(w->code, "%s\n", tm);
Delete(tm);
/* Add C type to callback typedef */
if (i > 0)
Printf(callback_typedef_parms, ", ");
@ -3679,6 +3664,32 @@ public:
substituteClassname(pt, din);
Replaceall(din, "$iminput", ln);
// pre and post attribute support
String *pre = Getattr(p, "tmap:csdirectorin:pre");
if (pre) {
substituteClassname(pt, pre);
Replaceall(pre, "$iminput", ln);
if (Len(pre_code) > 0)
Printf(pre_code, "\n");
Printv(pre_code, pre, NIL);
}
String *post = Getattr(p, "tmap:csdirectorin:post");
if (post) {
substituteClassname(pt, post);
Replaceall(post, "$iminput", ln);
if (Len(post_code) > 0)
Printf(post_code, "\n");
Printv(post_code, post, NIL);
}
String *terminator = Getattr(p, "tmap:csdirectorin:terminator");
if (terminator) {
substituteClassname(pt, terminator);
Replaceall(terminator, "$iminput", ln);
if (Len(terminator_code) > 0)
Insert(terminator_code, 0, "\n");
Insert(terminator_code, 0, terminator);
}
if (i > 0) {
Printf(delegate_parms, ", ");
Printf(proxy_method_types, ", ");
@ -3694,7 +3705,15 @@ public:
/* Get the C# parameter type */
if ((tm = Getattr(p, "tmap:cstype"))) {
substituteClassname(pt, tm);
Printf(proxy_method_types, "typeof(%s)", tm);
if (Strncmp(tm, "ref ", 4) == 0) {
Replace(tm, "ref ", "", DOH_REPLACE_FIRST);
Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
} else if (Strncmp(tm, "out ", 4) == 0) {
Replace(tm, "out ", "", DOH_REPLACE_FIRST);
Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
} else {
Printf(proxy_method_types, "typeof(%s)", tm);
}
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(pt, 0));
}
@ -3728,12 +3747,11 @@ public:
Delete(ln);
Delete(arg);
Delete(c_decl);
Delete(c_param_type);
}
/* header declaration, start wrapper definition */
String *target;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s", target);
Delete(qualified_name);
@ -3753,7 +3771,7 @@ public:
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
@ -3779,20 +3797,28 @@ public:
String *upcall = NewStringf("%s(%s)", symname, imcall_args);
if (!is_void) {
Parm *tp = NewParm(returntype, empty_str, n);
if ((tm = Swig_typemap_lookup("csdirectorout", n, "", 0))) {
substituteClassname(returntype, tm);
Replaceall(tm, "$cscall", upcall);
if (!is_void)
Insert(tm, 0, "return ");
Replaceall(tm, "\n ", "\n "); // add extra indentation to code in typemap
if ((tm = Swig_typemap_lookup("csdirectorout", tp, "", 0))) {
substituteClassname(returntype, tm);
Replaceall(tm, "$cscall", upcall);
Printf(callback_code, " return %s;\n", tm);
}
Delete(tm);
Delete(tp);
} else
Printf(callback_code, " %s;\n", upcall);
// pre and post attribute support
bool is_pre_code = Len(pre_code) > 0;
bool is_post_code = Len(post_code) > 0;
bool is_terminator_code = Len(terminator_code) > 0;
if (is_pre_code && is_post_code)
Printf(callback_code, "%s\n try {\n %s;\n } finally {\n%s\n }\n", pre_code, tm, post_code);
else if (is_pre_code)
Printf(callback_code, "%s\n %s;\n", pre_code, tm);
else if (is_post_code)
Printf(callback_code, " try {\n %s;\n } finally {\n%s\n }\n", tm, post_code);
else
Printf(callback_code, " %s;\n", tm);
if (is_terminator_code)
Printv(callback_code, "\n", terminator_code, NIL);
}
Printf(callback_code, " }\n");
Delete(upcall);
@ -3806,10 +3832,9 @@ public:
if (!is_void) {
String *jresult_str = NewString("jresult");
String *result_str = NewString("c_result");
Parm *tp = NewParm(returntype, result_str, n);
/* Copy jresult into c_result... */
if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) {
if ((tm = Swig_typemap_lookup("directorout", n, result_str, w))) {
Replaceall(tm, "$input", jresult_str);
Replaceall(tm, "$result", result_str);
Printf(w->code, "%s\n", tm);
@ -3820,7 +3845,6 @@ public:
output_director = false;
}
Delete(tp);
Delete(jresult_str);
Delete(result_str);
}
@ -3897,8 +3921,10 @@ public:
Printf(director_connect_parms, "SwigDirector%s%s delegate%s", classname, methid, methid);
}
Delete(pre_code);
Delete(post_code);
Delete(terminator_code);
Delete(qualified_return);
Delete(c_ret_type);
Delete(declaration);
Delete(callback_typedef_parms);
Delete(delegate_parms);
@ -3918,7 +3944,7 @@ public:
Node *parent = parentNode(n);
String *decl = Getattr(n, "decl");
String *supername = Swig_class_name(parent);
String *classname = directorClassName(parent);
String *dirclassname = directorClassName(parent);
String *sub = NewString("");
Parm *p;
ParmList *superparms = Getattr(n, "parms");
@ -3942,11 +3968,11 @@ public:
/* constructor */
{
String *basetype = Getattr(parent, "classtype");
String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0);
String *call = Swig_csuperclass_call(0, basetype, superparms);
String *classtype = SwigType_namestr(Getattr(n, "name"));
Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor"));
Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor"));
Printf(f_directors, " swig_init_callbacks();\n");
Printf(f_directors, "}\n\n");
@ -3957,7 +3983,7 @@ public:
/* constructor header */
{
String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1);
Printf(f_directors_h, " %s;\n", target);
Delete(target);
}
@ -3966,6 +3992,7 @@ public:
Delete(sub);
Delete(supername);
Delete(parms);
Delete(dirclassname);
return Language::classDirectorConstructor(n);
}
@ -3974,18 +4001,18 @@ public:
* ------------------------------------------------------------ */
int classDirectorDefaultConstructor(Node *n) {
String *classname = Swig_class_name(n);
String *dirclassname = directorClassName(n);
String *classtype = SwigType_namestr(Getattr(n, "name"));
Wrapper *w = NewWrapper();
Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor"));
Printf(w->def, "%s::%s() : %s {", dirclassname, dirclassname, Getattr(n, "director:ctor"));
Printf(w->code, "}\n");
Wrapper_print(w, f_directors);
Printf(f_directors_h, " SwigDirector_%s();\n", classname);
Printf(f_directors_h, " %s();\n", dirclassname);
DelWrapper(w);
Delete(classtype);
Delete(classname);
Delete(dirclassname);
return Language::classDirectorDefaultConstructor(n);
}
@ -4026,15 +4053,15 @@ public:
int classDirectorDestructor(Node *n) {
Node *current_class = getCurrentClass();
String *classname = Swig_class_name(current_class);
String *dirclassname = directorClassName(current_class);
Wrapper *w = NewWrapper();
if (Getattr(n, "throw")) {
Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname);
Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname);
Printf(f_directors_h, " virtual ~%s() throw ();\n", dirclassname);
Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname);
} else {
Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname);
Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname);
Printf(f_directors_h, " virtual ~%s();\n", dirclassname);
Printf(w->def, "%s::~%s() {\n", dirclassname, dirclassname);
}
Printv(w->code, "}\n", NIL);
@ -4042,7 +4069,7 @@ public:
Wrapper_print(w, f_directors);
DelWrapper(w);
Delete(classname);
Delete(dirclassname);
return SWIG_OK;
}
@ -4082,7 +4109,7 @@ public:
Printf(w->def, ") {");
if (Len(director_callback_typedefs) > 0) {
if (Len(director_callbacks) > 0) {
Printf(f_directors_h, "\nprivate:\n%s", director_callbacks);
}
Printf(f_directors_h, " void swig_init_callbacks();\n");
@ -4132,8 +4159,7 @@ public:
String *base = Getattr(n, "classtype");
String *class_ctor = NewString("Swig::Director()");
String *classname = Swig_class_name(n);
String *directorname = NewStringf("SwigDirector_%s", classname);
String *directorname = directorClassName(n);
String *declaration = Swig_class_declaration(n, directorname);
Printf(declaration, " : public %s, public Swig::Director", base);
@ -4141,6 +4167,8 @@ public:
// Stash stuff for later.
Setattr(n, "director:decl", declaration);
Setattr(n, "director:ctor", class_ctor);
Delete(directorname);
}
}; /* class CSHARP */

View file

@ -11,8 +11,6 @@
* D language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_d_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
@ -25,7 +23,6 @@ class D : public Language {
const String *empty_string;
const String *public_string;
const String *protected_string;
const String *static_string;
/*
* Files and file sections containing C/C++ code.
@ -274,6 +271,8 @@ public:
dmethods_seq(NULL),
dmethods_table(NULL),
n_dmethods(0),
first_class_dmethod(0),
curr_class_dmethod(0),
unknown_types(NULL) {
// For now, multiple inheritance with directors is not possible. It should be
@ -489,8 +488,11 @@ public:
Printf(f_directors, "/* ---------------------------------------------------\n");
Printf(f_directors, " * C++ director class methods\n");
Printf(f_directors, " * --------------------------------------------------- */\n\n");
if (outfile_h)
Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
if (outfile_h) {
String *filename = Swig_file_filename(outfile_h);
Printf(f_directors, "#include \"%s\"\n\n", filename);
Delete(filename);
}
}
Printf(f_runtime, "\n");
@ -538,7 +540,7 @@ public:
replaceModuleVariables(im_dmodule_code);
Printv(im_d_file, im_dmodule_code, NIL);
Close(im_d_file);
Delete(im_d_file);
}
// Generate the main D proxy module.
@ -571,7 +573,7 @@ public:
replaceModuleVariables(proxy_dmodule_code);
Printv(proxy_d_file, proxy_dmodule_code, NIL);
Close(proxy_d_file);
Delete(proxy_d_file);
}
// Generate the additional proxy modules for nspace support.
@ -598,7 +600,7 @@ public:
replaceModuleVariables(code);
Printv(file, code, NIL);
Close(file);
Delete(file);
Delete(module_name);
}
@ -693,7 +695,6 @@ public:
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
Close(f_runtime_h);
Delete(f_runtime_h);
f_runtime_h = NULL;
Delete(f_directors);
@ -707,7 +708,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -868,7 +868,6 @@ public:
Printv(class_file, proxy_enum_code, NIL);
Close(class_file);
Delete(class_file);
} else {
String *nspace = Getattr(n, "sym:nspace");
@ -1363,7 +1362,6 @@ public:
replaceModuleVariables(proxy_class_code);
Printv(class_file, proxy_class_code, NIL);
Close(class_file);
Delete(class_file);
} else {
Printv(proxyImportsBuffer(getNSpace()), proxy_class_imports, NIL);
@ -1440,7 +1438,7 @@ public:
// The type in the out attribute of the typemap overrides the type
// in the dtype typemap.
tm = dtypeout;
replaceClassname(tm, t);
replaceClassname(tm, t);
}
Printf(return_type, "%s", tm);
} else {
@ -1583,8 +1581,10 @@ public:
if (Getattr(n, "sym:overloaded")) {
// Emit warnings for the few cases that can't be overloaded in D and give up on generating wrapper
Swig_overload_check(n);
if (Getattr(n, "overload:ignore"))
if (Getattr(n, "overload:ignore")) {
DelWrapper(f);
return SWIG_OK;
}
}
// Collect the parameter list for the intermediary D module declaration of
@ -1693,7 +1693,7 @@ public:
if ((throw_parm_list = Getattr(n, "catchlist"))) {
Swig_typemap_attach_parms("throws", throw_parm_list, f);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
canThrow(n, "throws", p);
}
}
@ -1895,7 +1895,7 @@ public:
// Write C++ director class declaration, for example:
// class SwigDirector_myclass : public myclass, public Swig::Director {
String *classname = Swig_class_name(n);
String *directorname = NewStringf("SwigDirector_%s", classname);
String *directorname = directorClassName(n);
String *declaration = Swig_class_declaration(n, directorname);
const String *base = Getattr(n, "classtype");
@ -1927,13 +1927,11 @@ public:
* underlying D object.
* --------------------------------------------------------------------------- */
virtual int classDirectorMethod(Node *n, Node *parent, String *super) {
String *empty_str = NewString("");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
SwigType *returntype = Getattr(n, "returntype");
SwigType *returntype = Getattr(n, "type");
String *overloaded_name = getOverloadedName(n);
String *storage = Getattr(n, "storage");
String *value = Getattr(n, "value");
@ -1945,11 +1943,11 @@ public:
Wrapper *w = NewWrapper();
ParmList *l = Getattr(n, "parms");
bool is_void = !(Cmp(returntype, "void"));
String *qualified_return = NewString("");
String *qualified_return = 0;
bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0")));
int status = SWIG_OK;
bool output_director = true;
String *dirclassname = getDirectorClassName(parent);
String *dirclassname = directorClassName(parent);
String *qualified_name = NewStringf("%s::%s", dirclassname, name);
SwigType *c_ret_type = NULL;
String *dcallback_call_args = NewString("");
@ -1968,93 +1966,84 @@ public:
// we're consistent with the sym:overload name in functionWrapper. (?? when
// does the overloaded method name get set?)
imclass_dmethod = NewStringf("SwigDirector_%s",
Swig_name_member(getNSpace(), classname, overloaded_name));
imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name));
if (returntype) {
qualified_return = SwigType_rcaststr(returntype, "c_result");
qualified_return = SwigType_rcaststr(returntype, "c_result");
if (!is_void && !ignored_method) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
String *base_typename = SwigType_base(returntype);
String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
Symtab *symtab = Getattr(n, "sym:symtab");
Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) {
/* initialize pointers to something sane. Same for abstract
classes when a reference is returned. */
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
} else {
/* If returning a reference, initialize the pointer to a sane
default - if a D exception occurs, then the pointer returns
something other than a NULL-initialized reference. */
String *non_ref_type = Copy(returntype);
/* Remove reference and const qualifiers */
Replaceall(non_ref_type, "r.", "");
Replaceall(non_ref_type, "q(const).", "");
Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL);
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL);
Delete(non_ref_type);
}
Delete(base_typename);
Delete(resolved_typename);
}
if (!is_void && !ignored_method) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
SwigType *vt;
String *base_typename = SwigType_base(returntype);
String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
Symtab *symtab = Getattr(n, "sym:symtab");
Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
vt = cplus_value_type(returntype);
if (!vt) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstracts"))) {
/* initialize pointers to something sane. Same for abstract
classes when a reference is returned. */
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL);
Delete(vt);
/* If returning a reference, initialize the pointer to a sane
default - if a D exception occurs, then the pointer returns
something other than a NULL-initialized reference. */
String *non_ref_type = Copy(returntype);
/* Remove reference and const qualifiers */
Replaceall(non_ref_type, "r.", "");
Replaceall(non_ref_type, "q(const).", "");
Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL);
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL);
Delete(non_ref_type);
}
}
}
/* Create the intermediate class wrapper */
Parm *tp = NewParm(returntype, empty_str, n);
tm = lookupDTypemap(tp, "imtype");
if (tm) {
String *imtypeout = Getattr(tp, "tmap:imtype:out");
if (imtypeout) {
// The type in the imtype typemap's out attribute overrides the type
// in the typemap.
tm = imtypeout;
}
Printf(callback_def, "\nprivate extern(C) %s swigDirectorCallback_%s_%s(void* dObject", tm, classname, overloaded_name);
Printv(proxy_callback_return_type, tm, NIL);
} else {
Swig_warning(WARN_D_TYPEMAP_IMTYPE_UNDEF, input_file, line_number,
"No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
Parm *retpm = NewParm(returntype, empty_str, n);
if ((c_ret_type = Swig_typemap_lookup("ctype", retpm, "", 0))) {
if (!is_void && !ignored_method) {
String *jretval_decl = NewStringf("%s jresult", c_ret_type);
Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
Delete(jretval_decl);
Delete(base_typename);
Delete(resolved_typename);
}
} else {
Swig_warning(WARN_D_TYPEMAP_CTYPE_UNDEF, input_file, line_number,
"No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
SwigType *vt;
Delete(retpm);
vt = cplus_value_type(returntype);
if (!vt) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL);
Delete(vt);
}
}
}
/* Create the intermediate class wrapper */
tm = lookupDTypemap(n, "imtype");
if (tm) {
String *imtypeout = Getattr(n, "tmap:imtype:out");
if (imtypeout) {
// The type in the imtype typemap's out attribute overrides the type
// in the typemap.
tm = imtypeout;
}
Printf(callback_def, "\nprivate extern(C) %s swigDirectorCallback_%s_%s(void* dObject", tm, classname, overloaded_name);
Printv(proxy_callback_return_type, tm, NIL);
} else {
Swig_warning(WARN_D_TYPEMAP_IMTYPE_UNDEF, input_file, line_number,
"No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) {
if (!is_void && !ignored_method) {
String *jretval_decl = NewStringf("%s jresult", c_ret_type);
Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
Delete(jretval_decl);
}
} else {
Swig_warning(WARN_D_TYPEMAP_CTYPE_UNDEF, input_file, line_number,
"No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
Swig_director_parms_fixup(l);
@ -2132,8 +2121,6 @@ public:
if (!ignored_method)
Printf(w->code, "%s\n", tm);
Delete(tm);
// Add parameter type to the C typedef for the D callback function.
Printf(callback_typedef_parms, ", %s", c_param_type);
@ -2215,7 +2202,7 @@ public:
/* header declaration, start wrapper definition */
String *target;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s", target);
Delete(qualified_name);
@ -2235,7 +2222,7 @@ public:
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
@ -2261,17 +2248,10 @@ public:
String *upcall = NewStringf("(cast(%s)dObject).%s(%s)", classname, symname, imcall_args);
if (!is_void) {
Parm *tp = NewParm(returntype, empty_str, n);
// RESEARCH: What happens if there is no ddirectorout typemap?
if ((tm = lookupDTypemap(tp, "ddirectorout"))) {
if ((tm = lookupDTypemap(n, "ddirectorout"))) {
Replaceall(tm, "$dcall", upcall);
Printf(callback_code, " return %s;\n", tm);
}
Delete(tm);
Delete(tp);
} else {
Printf(callback_code, " %s;\n", upcall);
}
@ -2288,11 +2268,9 @@ public:
if (!is_void) {
String *jresult_str = NewString("jresult");
String *result_str = NewString("c_result");
Parm *tp = NewParm(returntype, result_str, n);
/* Copy jresult into c_result... */
// FIXME: lookupDTypemap?
if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) {
if ((tm = Swig_typemap_lookup("directorout", n, result_str, w))) {
Replaceall(tm, "$input", jresult_str);
Replaceall(tm, "$result", result_str);
Printf(w->code, "%s\n", tm);
@ -2303,7 +2281,6 @@ public:
output_director = false;
}
Delete(tp);
Delete(jresult_str);
Delete(result_str);
}
@ -2368,8 +2345,7 @@ public:
// We cannot directly use n here because its »type« attribute does not
// the full return type any longer after Language::functionHandler has
// returned.
Parm *tp = NewParm(returntype, empty_str, n);
String *dp_return_type = lookupDTypemap(tp, "dtype");
String *dp_return_type = lookupDTypemap(n, "dtype");
if (dp_return_type) {
String *dtypeout = Getattr(n, "tmap:dtype:out");
if (dtypeout) {
@ -2380,7 +2356,7 @@ public:
}
} else {
Swig_warning(WARN_D_TYPEMAP_DTYPE_UNDEF, input_file, line_number,
"No dtype typemap defined for %s\n", SwigType_str(type, 0));
"No dtype typemap defined for %s\n", SwigType_str(returntype, 0));
dp_return_type = NewString("");
}
@ -2395,10 +2371,12 @@ public:
Printf(director_callback_pointers, " SWIG_Callback%s_t swig_callback_%s;\n", methid, overloaded_name);
// Write the type alias for the callback to the intermediary D module.
String* proxy_callback_type = NewString("");
Printf(proxy_callback_type, "SwigDirector_%s_Callback%s", classname, methid);
String *proxy_callback_type = NewString("");
String *dirClassName = directorClassName(parent);
Printf(proxy_callback_type, "%s_Callback%s", dirClassName, methid);
Printf(im_dmodule_code, "alias extern(C) %s function(void*%s) %s;\n", proxy_callback_return_type, delegate_parms, proxy_callback_type);
Delete(proxy_callback_type);
Delete(dirClassName);
}
Delete(qualified_return);
@ -2421,7 +2399,7 @@ public:
Node *parent = parentNode(n);
String *decl = Getattr(n, "decl");;
String *supername = Swig_class_name(parent);
String *classname = getDirectorClassName(parent);
String *dirclassname = directorClassName(parent);
String *sub = NewString("");
Parm *p;
ParmList *superparms = Getattr(n, "parms");
@ -2445,11 +2423,11 @@ public:
/* constructor */
{
String *basetype = Getattr(parent, "classtype");
String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0);
String *call = Swig_csuperclass_call(0, basetype, superparms);
String *classtype = SwigType_namestr(Getattr(n, "name"));
Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor"));
Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor"));
Printf(f_directors, " swig_init_callbacks();\n");
Printf(f_directors, "}\n\n");
@ -2460,7 +2438,7 @@ public:
/* constructor header */
{
String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1);
Printf(f_directors_h, " %s;\n", target);
Delete(target);
}
@ -2469,6 +2447,7 @@ public:
Delete(sub);
Delete(supername);
Delete(parms);
Delete(dirclassname);
return Language::classDirectorConstructor(n);
}
@ -2476,18 +2455,18 @@ public:
* D::classDirectorDefaultConstructor()
* --------------------------------------------------------------------------- */
virtual int classDirectorDefaultConstructor(Node *n) {
String *classname = Swig_class_name(n);
String *dirclassname = directorClassName(n);
String *classtype = SwigType_namestr(Getattr(n, "name"));
Wrapper *w = NewWrapper();
Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor"));
Printf(w->def, "%s::%s() : %s {", dirclassname, dirclassname, Getattr(n, "director:ctor"));
Printf(w->code, "}\n");
Wrapper_print(w, f_directors);
Printf(f_directors_h, " SwigDirector_%s();\n", classname);
Printf(f_directors_h, " %s();\n", dirclassname);
DelWrapper(w);
Delete(classtype);
Delete(classname);
Delete(dirclassname);
return Language::classDirectorDefaultConstructor(n);
}
@ -2496,15 +2475,15 @@ public:
* --------------------------------------------------------------------------- */
virtual int classDirectorDestructor(Node *n) {
Node *current_class = getCurrentClass();
String *classname = Swig_class_name(current_class);
String *dirclassname = directorClassName(current_class);
Wrapper *w = NewWrapper();
if (Getattr(n, "throw")) {
Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname);
Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname);
Printf(f_directors_h, " virtual ~%s() throw ();\n", dirclassname);
Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname);
} else {
Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname);
Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname);
Printf(f_directors_h, " virtual ~%s();\n", dirclassname);
Printf(w->def, "%s::~%s() {\n", dirclassname, dirclassname);
}
Printv(w->code, "}\n", NIL);
@ -2512,7 +2491,7 @@ public:
Wrapper_print(w, f_directors);
DelWrapper(w);
Delete(classname);
Delete(dirclassname);
return SWIG_OK;
}
@ -2521,7 +2500,7 @@ public:
* --------------------------------------------------------------------------- */
virtual int classDirectorEnd(Node *n) {
int i;
String *director_classname = getDirectorClassName(n);
String *director_classname = directorClassName(n);
Wrapper *w = NewWrapper();
@ -2550,7 +2529,7 @@ public:
Printf(f_directors_h, "\nprivate:\n");
Printf(f_directors_h, " void swig_init_callbacks();\n");
Printf(f_directors_h, " void *d_object;\n");
if (Len(director_callback_typedefs) > 0) {
if (Len(director_callback_pointers) > 0) {
Printf(f_directors_h, "%s", director_callback_pointers);
}
Printf(f_directors_h, "};\n\n");
@ -3330,7 +3309,7 @@ private:
// If directors are enabled for the current class, generate the
// director connect helper function which is called from the constructor
// and write it to the class body.
writeDirectorConnectProxy();
writeDirectorConnectProxy(n);
}
// Write all constants and enumerations first to prevent forward reference
@ -3490,7 +3469,6 @@ private:
Printv(class_file, code_target, NIL);
Delete(code_target);
Close(class_file);
Delete(class_file);
}
@ -3498,12 +3476,15 @@ private:
}
/* ---------------------------------------------------------------------------
* D::writeDirectorConnectProxy()
* D::writeDirectorConnectProxy(Node *classNode)
*
* Writes the helper method which registers the director callbacks by calling
* the director connect function from the D side to the proxy class.
* --------------------------------------------------------------------------- */
void writeDirectorConnectProxy() {
void writeDirectorConnectProxy(Node* classNode) {
String *dirClassName = directorClassName(classNode);
String *connect_name = Swig_name_member(getNSpace(),
proxy_class_name, "director_connect");
Printf(proxy_class_body_code, "\nprivate void swigDirectorConnect() {\n");
int i;
@ -3514,12 +3495,12 @@ private:
String *return_type = Getattr(udata, "return_type");
String *param_list = Getattr(udata, "param_list");
String *methid = Getattr(udata, "class_methodidx");
Printf(proxy_class_body_code, " %s.SwigDirector_%s_Callback%s callback%s;\n", im_dmodule_fq_name, proxy_class_name, methid, methid);
Printf(proxy_class_body_code, " %s.%s_Callback%s callback%s;\n", im_dmodule_fq_name, dirClassName, methid, methid);
Printf(proxy_class_body_code, " if (swigIsMethodOverridden!(%s delegate(%s), %s function(%s), %s)()) {\n", return_type, param_list, return_type, param_list, method);
Printf(proxy_class_body_code, " callback%s = &swigDirectorCallback_%s_%s;\n", methid, proxy_class_name, overloaded_name);
Printf(proxy_class_body_code, " }\n\n");
}
Printf(proxy_class_body_code, " %s.%s_director_connect(cast(void*)swigCPtr, cast(void*)this", im_dmodule_fq_name, proxy_class_name);
Printf(proxy_class_body_code, " %s.%s(cast(void*)swigCPtr, cast(void*)this", im_dmodule_fq_name, connect_name);
for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
UpcallData *udata = Getitem(dmethods_seq, i);
String *methid = Getattr(udata, "class_methodidx");
@ -3555,6 +3536,8 @@ private:
director_callback_pointers = NULL;
Delete(director_dcallbacks_code);
director_dcallbacks_code = NULL;
Delete(dirClassName);
Delete(connect_name);
}
/* ---------------------------------------------------------------------------
@ -3571,7 +3554,7 @@ private:
String *norm_name = SwigType_namestr(Getattr(n, "name"));
String *connect_name = Swig_name_member(getNSpace(),
proxy_class_name, "director_connect");
String *sym_name = Getattr(n, "sym:name");
String *dirClassName = directorClassName(n);
Wrapper *code_wrap;
Printv(wrapper_loader_bind_code, wrapper_loader_bind_command, NIL);
@ -3584,7 +3567,7 @@ private:
Printf(code_wrap->def, "SWIGEXPORT void D_%s(void *objarg, void *dobj", connect_name);
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name);
Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name);
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName);
Printf(code_wrap->code, " if (director) {\n");
Printf(code_wrap->code, " director->swig_connect_director(dobj");
@ -3593,9 +3576,9 @@ private:
UpcallData *udata = Getitem(dmethods_seq, i);
String *methid = Getattr(udata, "class_methodidx");
Printf(code_wrap->def, ", SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid);
Printf(code_wrap->def, ", %s::SWIG_Callback%s_t callback%s", dirClassName, methid, methid);
Printf(code_wrap->code, ", callback%s", methid);
Printf(im_dmodule_code, ", SwigDirector_%s_Callback%s callback%s", sym_name, methid, methid);
Printf(im_dmodule_code, ", %s_Callback%s callback%s", dirClassName, methid, methid);
}
Printf(code_wrap->def, ") {\n");
@ -3608,6 +3591,7 @@ private:
DelWrapper(code_wrap);
Delete(connect_name);
Delete(dirClassName);
}
/* ---------------------------------------------------------------------------
@ -3648,7 +3632,7 @@ private:
// If the import statement has been found in the target string, we have to
// check if the previous import was static, which would lead to problems
// if this import is not.
// Thus, we check if the seven characters in front of the occurence are
// Thus, we check if the seven characters in front of the occurrence are
// »static «. If the import string passed is also static, the checks fail
// even if the found statement is also static because the last seven
// characters would be part of the previous import statement then.
@ -3692,7 +3676,15 @@ private:
bool inProxyModule(const String *type_name) const {
if (!split_proxy_dmodule) {
String *nspace = createOuterNamespaceNames(type_name);
bool result = (getNSpace() || !nspace) && (Strcmp(nspace, getNSpace()) == 0);
// Check if strings are either both null (no namespace) or are both
// non-null and have the same contents. Cannot use Strcmp for this
// directly because of its strange way of handling the case where only
// one argument is 0 ("<").
bool result = !nspace && !getNSpace();
if (nspace && getNSpace())
result = (Strcmp(nspace, getNSpace()) == 0);
Delete(nspace);
return result;
}
@ -3712,23 +3704,14 @@ private:
UpcallData *addUpcallMethod(String *imclass_method, String *class_method,
String *decl, String *overloaded_name, String *return_type, String *param_list) {
UpcallData *udata;
String *class_methodidx;
Hash *new_udata;
String *key = NewStringf("%s|%s", imclass_method, decl);
++curr_class_dmethod;
/* Do we know about this director class already? */
if ((udata = Getattr(dmethods_table, key))) {
Delete(key);
return Getattr(udata, "methodoff");
}
class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
n_dmethods++;
new_udata = NewHash();
Hash *new_udata = NewHash();
Append(dmethods_seq, new_udata);
Setattr(dmethods_table, key, new_udata);
@ -3971,7 +3954,7 @@ private:
if (attached) {
String *attr_name = NewStringf("tmap:%s", method);
result = Getattr(n, attr_name);
result = Copy(Getattr(n, attr_name));
Delete(attr_name);
} else {
// FIXME: As a workaround for a bug so far only surfacing in the
@ -4313,23 +4296,6 @@ private:
return proxyname;
}
/* ---------------------------------------------------------------------------
* D::directorClassName()
* --------------------------------------------------------------------------- */
String *getDirectorClassName(Node *n) const {
String *dirclassname;
const char *attrib = "director:classname";
if (!(dirclassname = Getattr(n, attrib))) {
String *classname = Getattr(n, "sym:name");
dirclassname = NewStringf("SwigDirector_%s", classname);
Setattr(n, attrib, dirclassname);
}
return dirclassname;
}
/* ---------------------------------------------------------------------------
* D::makeParameterName()
*
@ -4433,10 +4399,14 @@ private:
// so we can progress up the inheritance hierachy even if there have been
// new overloads introduced after the topmost class.
Node *base_function = NULL;
for (Node *tmp = firstChild(base_class); tmp; tmp = nextSibling(tmp)) {
if (Strcmp(Getattr(tmp, "sym:name"), Getattr(n, "sym:name")) == 0) {
base_function = tmp;
break;
String *symname = Getattr(n, "sym:name");
if (symname) {
for (Node *tmp = firstChild(base_class); tmp; tmp = nextSibling(tmp)) {
String *child_symname = Getattr(tmp, "sym:name");
if (child_symname && (Strcmp(child_symname, symname) == 0)) {
base_function = tmp;
break;
}
}
}

View file

@ -13,8 +13,6 @@
* in SWIG. --MR
* ----------------------------------------------------------------------------- */
char cvsroot_directors_cxx[] = "$Id";
#include "swigmod.h"
/* Swig_csuperclass_call()
@ -78,9 +76,10 @@ String *Swig_class_name(Node *n) {
String *Swig_director_declaration(Node *n) {
String *classname = Swig_class_name(n);
String *directorname = NewStringf("SwigDirector_%s", classname);
String *directorname = Language::instance()->directorClassName(n);
String *base = Getattr(n, "classtype");
String *declaration = Swig_class_declaration(n, directorname);
Printf(declaration, " : public %s, public Swig::Director {\n", base);
Delete(classname);
Delete(directorname);
@ -132,7 +131,7 @@ String *Swig_method_call(const_String_or_char_ptr name, ParmList *parms) {
*
*/
String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_char_ptr id, List *args, int strip, int values) {
String *Swig_method_decl(SwigType *rettype, SwigType *decl, const_String_or_char_ptr id, List *args, int strip, int values) {
String *result;
List *elements;
String *element = 0, *nextelement;
@ -203,7 +202,7 @@ String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_c
Append(result, ", ");
}
Append(result, ")");
} else if (returntype) { // This check is intended for conversion operators to a pointer/reference which needs the pointer/reference ignoring in the declaration
} else if (rettype) { // This check is intended for conversion operators to a pointer/reference which needs the pointer/reference ignoring in the declaration
if (SwigType_ispointer(element)) {
Insert(result, 0, "*");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
@ -256,9 +255,9 @@ String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_c
Chop(result);
if (returntype) {
if (rettype) {
Insert(result, 0, " ");
String *rtype = SwigType_str(returntype, 0);
String *rtype = SwigType_str(rettype, 0);
Insert(result, 0, rtype);
Delete(rtype);
}
@ -280,9 +279,10 @@ void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f) {
checkAttribute(n, "storage", "static"))
&& !Equal(nodeType(n), "constructor"))) {
Node *parent = Getattr(n, "parentNode");
String *symname = Getattr(parent, "sym:name");
String *dirname = NewStringf("SwigDirector_%s", symname);
String *dirdecl = NewStringf("%s *darg = 0", dirname);
String *dirname;
String *dirdecl;
dirname = Language::instance()->directorClassName(parent);
dirdecl = NewStringf("%s *darg = 0", dirname);
Wrapper_add_local(f, "darg", dirdecl);
Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n", dirname);
Delete(dirname);

View file

@ -11,8 +11,6 @@
* Useful functions for emitting various pieces of code.
* ----------------------------------------------------------------------------- */
char cvsroot_emit_cxx[] = "$Id$";
#include "swigmod.h"
/* -----------------------------------------------------------------------------
@ -363,24 +361,9 @@ int emit_action_code(Node *n, String *wrappercode, String *eaction) {
tm = Copy(tm);
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
if (Strstr(tm, "$")) {
Replaceall(tm, "$name", Getattr(n, "name"));
Replaceall(tm, "$symname", Getattr(n, "sym:name"));
Swig_replace_special_variables(n, parentNode(n), tm);
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(wrappercode, tm, "\n", NIL);
Delete(tm);
@ -470,6 +453,7 @@ String *emit_action(Node *n) {
if (catchlist) {
int unknown_catch = 0;
int has_varargs = 0;
Printf(eaction, "}\n");
for (Parm *ep = catchlist; ep; ep = nextSibling(ep)) {
String *em = Swig_typemap_lookup("throws", ep, "_e", 0);
@ -480,6 +464,7 @@ String *emit_action(Node *n) {
Printf(eaction, "catch(%s) {", SwigType_str(et, "_e"));
} else if (SwigType_isvarargs(etr)) {
Printf(eaction, "catch(...) {");
has_varargs = 1;
} else {
Printf(eaction, "catch(%s) {", SwigType_str(et, "&_e"));
}
@ -490,8 +475,8 @@ String *emit_action(Node *n) {
unknown_catch = 1;
}
}
if (unknown_catch) {
Printf(eaction, "catch(...) { throw; }\n");
if (unknown_catch && !has_varargs) {
Printf(eaction, "catch(...) { throw; }\n");
}
}

View file

@ -7,33 +7,27 @@
* Go language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_go_cxx[] = "$Id";
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
#ifdef HAVE_GCCGO_46
#define GCCGO_46_DEFAULT true
#else
#define GCCGO_46_DEFAULT false
#endif
class GO:public Language {
static const char *const usage;
// Go package name.
String *package;
// SWIG module name.
String *module;
// Flag for generating gccgo output.
bool gccgo_flag;
// Flag for generating gccgo 4.6 output.
bool gccgo_46_flag;
// Prefix to use with gccgo.
String *go_prefix;
// Name of shared library to import.
String *soname;
// Size in bits of the C type "long".
int long_type_size;
// Size in bits of the Go type "int". 0 if not specified.
int intgo_type_size;
/* Output files */
File *f_c_begin;
@ -89,11 +83,12 @@ class GO:public Language {
public:
GO():package(NULL),
module(NULL),
gccgo_flag(false),
gccgo_46_flag(GCCGO_46_DEFAULT),
go_prefix(NULL),
soname(NULL),
long_type_size(32),
intgo_type_size(0),
f_c_begin(NULL),
f_go_begin(NULL),
f_gc_begin(NULL),
@ -132,6 +127,7 @@ private:
virtual void main(int argc, char *argv[]) {
SWIG_library_directory("go");
bool display_help = false;
// Process command line options.
for (int i = 1; i < argc; i++) {
@ -148,12 +144,6 @@ private:
} else if (strcmp(argv[i], "-gccgo") == 0) {
Swig_mark_arg(i);
gccgo_flag = true;
} else if (strcmp(argv[i], "-gccgo-46") == 0) {
Swig_mark_arg(i);
gccgo_46_flag = true;
} else if (strcmp(argv[i], "-no-gccgo-46") == 0) {
Swig_mark_arg(i);
gccgo_46_flag = false;
} else if (strcmp(argv[i], "-go-prefix") == 0) {
if (argv[i + 1]) {
go_prefix = NewString(argv[i + 1]);
@ -185,7 +175,21 @@ private:
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-intgosize") == 0) {
if (argv[i + 1]) {
intgo_type_size = atoi(argv[i + 1]);
if (intgo_type_size != 32 && intgo_type_size != 64) {
Printf(stderr, "-intgosize not 32 or 64\n");
Swig_arg_error();
}
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
++i;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-help") == 0) {
display_help = true;
Printf(stdout, "%s\n", usage);
}
}
@ -208,6 +212,22 @@ private:
Preprocessor_define("SWIGGO_LONG_TYPE_SIZE 64", 0);
}
// This test may be removed in the future, when we can assume that
// everybody has upgraded to Go 1.1. The code below is prepared
// for this test to simply be taken out.
if (intgo_type_size == 0 && !display_help) {
Printf(stderr, "SWIG -go: -intgosize option required but not specified\n");
SWIG_exit(EXIT_FAILURE);
}
if (intgo_type_size == 32) {
Preprocessor_define("SWIGGO_INTGO_SIZE 32", 0);
} else if (intgo_type_size == 64) {
Preprocessor_define("SWIGGO_INTGO_SIZE 64", 0);
} else {
Preprocessor_define("SWIGGO_INTGO_SIZE 0", 0);
}
// Add typemap definitions.
SWIG_typemap_lang("go");
SWIG_config_file("go.swg");
@ -250,7 +270,7 @@ private:
allow_allprotected(GetFlag(optionsnode, "allprotected"));
}
String *module = Getattr(n, "name");
module = Getattr(n, "name");
if (!package) {
package = Copy(module);
}
@ -341,6 +361,8 @@ private:
Swig_banner(f_c_begin);
Printf(f_c_runtime, "#define SWIGMODULE %s\n", module);
if (directorsEnabled()) {
Printf(f_c_runtime, "#define SWIG_DIRECTORS\n");
@ -349,7 +371,9 @@ private:
Printf(f_c_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module);
Printf(f_c_directors, "\n// C++ director class methods.\n");
Printf(f_c_directors, "#include \"%s\"\n\n", Swig_file_filename(c_filename_h));
String *filename = Swig_file_filename(c_filename_h);
Printf(f_c_directors, "#include \"%s\"\n\n", filename);
Delete(filename);
}
Swig_banner(f_go_begin);
@ -364,6 +388,15 @@ private:
Printf(f_go_begin, "\npackage %s\n\n", package);
Printf(f_go_runtime, "//extern %sSwigCgocall\n", module);
Printf(f_go_runtime, "func SwigCgocall()\n");
Printf(f_go_runtime, "//extern %sSwigCgocallDone\n", module);
Printf(f_go_runtime, "func SwigCgocallDone()\n");
Printf(f_go_runtime, "//extern %sSwigCgocallBack\n", module);
Printf(f_go_runtime, "func SwigCgocallBack()\n");
Printf(f_go_runtime, "//extern %sSwigCgocallBackDone\n", module);
Printf(f_go_runtime, "func SwigCgocallBackDone()\n\n");
// All the C++ wrappers should be extern "C".
Printv(f_c_wrappers, "#ifdef __cplusplus\n", "extern \"C\" {\n", "#endif\n\n", NULL);
@ -406,12 +439,10 @@ private:
if (directorsEnabled()) {
Printf(f_c_directors_h, "#endif\n");
Close(f_c_directors_h);
Delete(f_c_directors_h);
f_c_directors_h = NULL;
Dump(f_c_directors, f_c_runtime);
Close(f_c_directors);
Delete(f_c_directors);
f_c_directors = NULL;
}
@ -444,12 +475,9 @@ private:
Delete(f_gc_wrappers);
}
Close(f_c_begin);
Delete(f_c_begin);
Close(f_go_begin);
Delete(f_go_begin);
if (!gccgo_flag) {
Close(f_gc_begin);
Delete(f_gc_begin);
}
@ -794,7 +822,7 @@ private:
if (needs_wrapper) {
wrapper_name = buildGoWrapperName(name, overname);
if (gccgo_flag && !gccgo_46_flag) {
if (gccgo_flag) {
Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL);
}
@ -845,16 +873,12 @@ private:
}
}
if (gccgo_flag && gccgo_46_flag) {
Printv(f_go_wrappers, " __asm__ (\"", go_prefix, "_", wname, "\")", NULL);
}
Printv(f_go_wrappers, "\n\n", NULL);
}
// Start defining the Go function.
if (!needs_wrapper && gccgo_flag && !gccgo_46_flag) {
if (!needs_wrapper && gccgo_flag) {
Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL);
}
@ -959,14 +983,33 @@ private:
}
}
if (gccgo_flag && !gccgo_46_flag) {
Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL);
Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL);
if (gccgo_flag) {
if (!is_constructor) {
Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
} else {
// For a constructor the wrapper function will return a
// uintptr but we will return an interface. We want to
// convert the uintptr to the interface after calling
// SwigCgocallDone, so that we don't try to allocate memory
// while the Go scheduler can't see us.
Printv(f_go_wrappers, "\tvar done bool\n", NULL);
Printv(f_go_wrappers, "\tdefer func() {\n", NULL);
Printv(f_go_wrappers, "\t\tif !done {\n", NULL);
Printv(f_go_wrappers, "\t\t\tSwigCgocallDone()\n", NULL);
Printv(f_go_wrappers, "\t\t}\n", NULL);
Printv(f_go_wrappers, "\t}()\n", NULL);
Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
}
}
Printv(f_go_wrappers, "\t", NULL);
if (SwigType_type(result) != T_VOID) {
Printv(f_go_wrappers, "return ", NULL);
if (gccgo_flag && is_constructor) {
Printv(f_go_wrappers, "swig_r := ", NULL);
} else {
Printv(f_go_wrappers, "return ", NULL);
}
}
Printv(f_go_wrappers, wrapper_name, "(", NULL);
@ -1002,11 +1045,14 @@ private:
p = nextParm(p);
}
Printv(f_go_wrappers, ")\n", NULL);
Printv(f_go_wrappers, "}\n", NULL);
} else {
if (gccgo_flag && gccgo_46_flag) {
Printv(f_go_wrappers, " __asm__ (\"", go_prefix, "_", wname, "\")\n", NULL);
if (gccgo_flag && is_constructor) {
Printv(f_go_wrappers, "\tSwigCgocallDone()\n", NULL);
Printv(f_go_wrappers, "\tdone = true\n", NULL);
Printv(f_go_wrappers, "\treturn swig_r\n", NULL);
}
Printv(f_go_wrappers, "}\n", NULL);
}
Printv(f_go_wrappers, "\n", NULL);
@ -1113,9 +1159,8 @@ private:
// A string has a pointer and a length.
Append(orig, "(2 * SWIG_PARM_SIZE)");
} else if (Strncmp(go, "[]", 2) == 0) {
// A slice has a pointer, a length, and a capacity. The
// length and capacity are always 4 bytes.
Append(orig, "(SWIG_PARM_SIZE + 8)");
// A slice has a pointer, a length, and a capacity.
Append(orig, "(3 * SWIG_PARM_SIZE)");
} else if (Strcmp(go, "float64") == 0) {
Append(orig, "8");
} else if (Strcmp(go, "complex64") == 0) {
@ -1169,7 +1214,7 @@ private:
Printv(f->code, "\tstruct swigargs {\n", NULL);
if (parm_count > required_count) {
Printv(f->code, "\t\tint _swig_optargc;\n", NULL);
Printv(f->code, "\t\tintgo _swig_optargc;\n", NULL);
}
Parm *p = parms;
@ -1281,7 +1326,7 @@ private:
Printv(fnname, go_prefix, "_", wname, "(", NULL);
if (parm_count > required_count) {
Printv(fnname, "int _swig_optargc", NULL);
Printv(fnname, "intgo _swig_optargc", NULL);
}
Parm *p = parms;
@ -1941,11 +1986,11 @@ private:
}
String *type = Getattr(ni, "nodeType");
if (Strcmp(type, "constructor") == 0 || Strcmp(type, "destructor") == 0 || Strcmp(type, "enum") == 0 || Strcmp(type, "using") == 0 || Strcmp(type, "classforward") == 0) {
if (Strcmp(type, "constructor") == 0 || Strcmp(type, "destructor") == 0 || Strcmp(type, "enum") == 0 || Strcmp(type, "using") == 0 || Strcmp(type, "classforward") == 0 || Strcmp(type, "template") == 0) {
continue;
}
String *storage = Getattr(ni, "storage");
if (Strcmp(storage, "typedef") == 0 || Strcmp(storage, "friend") == 0) {
if (storage && (Strcmp(storage, "typedef") == 0 || Strcmp(storage, "friend") == 0)) {
continue;
}
@ -2111,7 +2156,7 @@ private:
}
int flags = Extend | SmartPointer | use_naturalvar_mode(var);
if (is_non_virtual_protected_access(var)) {
if (isNonVirtualProtectedAccess(var)) {
flags |= CWRAP_ALL_PROTECTED_ACCESS;
}
@ -2330,14 +2375,14 @@ private:
Iterator b = First(baselist);
if (is_base_first) {
if (!b.item) {
return;
}
if (!GetFlag(b.item, "feature:ignore")) {
addParentExtraBaseInterfaces(n, parents, b.item, true, sf);
}
b = Next(b);
if (!b.item) {
return;
}
}
String *go_name = buildGoName(Getattr(n, "sym:name"), false, false);
@ -2522,7 +2567,7 @@ private:
if (!is_ignored) {
// Declare the C++ wrapper.
if (gccgo_flag && !gccgo_46_flag) {
if (gccgo_flag) {
Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL);
}
@ -2541,13 +2586,7 @@ private:
p = nextParm(p);
}
Printv(f_go_wrappers, ") ", go_type_name, NULL);
if (gccgo_flag && gccgo_46_flag) {
Printv(f_go_wrappers, " __asm__(\"", go_prefix, "_", wname, "\")", NULL);
}
Printv(f_go_wrappers, "\n\n", NULL);
Printv(f_go_wrappers, ") ", go_type_name, "\n\n", NULL);
Printv(f_go_wrappers, "func ", func_with_over_name, "(v interface{}", NULL);
@ -2566,9 +2605,9 @@ private:
Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", NULL);
if (gccgo_flag && !gccgo_46_flag) {
Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL);
Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL);
if (gccgo_flag) {
Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
}
Printv(f_go_wrappers, "\tp.", class_receiver, " = ", fn_name, NULL);
@ -2811,7 +2850,6 @@ private:
int classDirectorMethod(Node *n, Node *parent, String *super) {
bool is_ignored = GetFlag(n, "feature:ignore") ? true : false;
bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 && Cmp(Getattr(n, "value"), "0") == 0);
// We don't need explicit calls.
if (GetFlag(n, "explicitcall")) {
@ -2824,18 +2862,8 @@ private:
name = Getattr(n, "name");
}
if (Getattr(class_methods, name)) {
// We need to emit a pure virtual function, even if it is
// overloaded. Otherwise we won't be able to create an instance
// of the director class. The function doesn't need to actually
// do anything.
if (!is_pure_virtual || Getattr(n, "sym:overloaded")) {
return SWIG_OK;
}
}
Setattr(class_methods, name, NewString(""));
if (!Getattr(n, "sym:overloaded")) {
bool overloaded = Getattr(n, "sym:overloaded") && !Getattr(n, "explicitcallnode");
if (!overloaded) {
int r = oneClassDirectorMethod(n, parent, super);
if (r != SWIG_OK) {
return r;
@ -2846,47 +2874,54 @@ private:
// class_methods so that we correctly handle cases where a
// function in one class hides a function of the same name in a
// parent class.
for (Node *on = Getattr(n, "sym:overloaded"); on; on = Getattr(on, "sym:nextSibling")) {
int r = oneClassDirectorMethod(on, parent, super);
if (!Getattr(class_methods, name)) {
for (Node *on = Getattr(n, "sym:overloaded"); on; on = Getattr(on, "sym:nextSibling")) {
// Swig_overload_rank expects wrap:name and wrap:parms to be
// set.
String *wn = Swig_name_wrapper(Getattr(on, "sym:name"));
Append(wn, Getattr(on, "sym:overname"));
Setattr(on, "wrap:name", wn);
Delete(wn);
Setattr(on, "wrap:parms", Getattr(on, "parms"));
}
}
int r = oneClassDirectorMethod(n, parent, super);
if (r != SWIG_OK) {
return r;
}
if (!Getattr(n, "sym:nextSibling"))
{
// Last overloaded function
Node *on = Getattr(n, "sym:overloaded");
bool is_static = isStatic(on);
String *cn = exportedName(Getattr(parent, "sym:name"));
String *go_name = buildGoName(name, is_static, false);
String *director_struct_name = NewString("_swig_Director");
Append(director_struct_name, cn);
int r = makeDispatchFunction(on, go_name, director_struct_name, is_static, director_struct_name, false);
if (r != SWIG_OK) {
return r;
}
// Swig_overload_rank expects wrap:name and wrap:parms to be
// set.
String *wn = Swig_name_wrapper(Getattr(on, "sym:name"));
Append(wn, Getattr(on, "sym:overname"));
Setattr(on, "wrap:name", wn);
Delete(wn);
Setattr(on, "wrap:parms", Getattr(on, "parms"));
String *go_upcall = NewString("Director");
Append(go_upcall, cn);
Append(go_upcall, go_name);
r = makeDispatchFunction(on, go_upcall, director_struct_name, is_static, director_struct_name, true);
if (r != SWIG_OK) {
return r;
}
Delete(cn);
Delete(go_name);
Delete(director_struct_name);
Delete(go_upcall);
}
bool is_static = isStatic(n);
String *cn = exportedName(Getattr(parent, "sym:name"));
String *go_name = buildGoName(name, is_static, false);
String *director_struct_name = NewString("_swig_Director");
Append(director_struct_name, cn);
int r = makeDispatchFunction(n, go_name, director_struct_name, is_static, director_struct_name, false);
if (r != SWIG_OK) {
return r;
}
String *go_upcall = NewString("Director");
Append(go_upcall, cn);
Append(go_upcall, go_name);
r = makeDispatchFunction(n, go_upcall, director_struct_name, is_static, director_struct_name, true);
if (r != SWIG_OK) {
return r;
}
Delete(cn);
Delete(go_name);
Delete(director_struct_name);
Delete(go_upcall);
}
Setattr(class_methods, name, NewString(""));
return SWIG_OK;
}
@ -2938,17 +2973,7 @@ private:
Swig_typemap_attach_parms("gotype", parms, NULL);
int parm_count = emit_num_arguments(parms);
SwigType *result = Getattr(n, "returntype");
if (!result) {
// This can happen when following overloads.
result = NewString(Getattr(n, "type"));
SwigType_push(result, Getattr(n, "decl"));
if (SwigType_isqualifier(result)) {
Delete(SwigType_pop(result));
}
Delete(SwigType_pop_function(result));
Setattr(n, "returntype", result);
}
SwigType *result = Getattr(n, "type");
// Save the type for overload processing.
Setattr(n, "go:type", result);
@ -3026,7 +3051,7 @@ private:
String *upcall_gc_name = buildGoWrapperName(upcall_name, overname);
if (gccgo_flag && !gccgo_46_flag) {
if (gccgo_flag) {
Printv(f_go_wrappers, "//extern ", go_prefix, "_", upcall_wname, "\n", NULL);
}
@ -3049,10 +3074,6 @@ private:
Delete(tm);
}
if (gccgo_flag && gccgo_46_flag) {
Printv(f_go_wrappers, " __asm__(\"", go_prefix, "_", upcall_wname, "\")", NULL);
}
Printv(f_go_wrappers, "\n", NULL);
// Define the method on the director class in Go.
@ -3082,11 +3103,6 @@ private:
Printv(f_go_wrappers, " {\n", NULL);
if (gccgo_flag && !gccgo_46_flag) {
Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL);
Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL);
}
Printv(f_go_wrappers, "\tif swig_g, swig_ok := swig_p.v.(", interface_name, "); swig_ok {\n", NULL);
Printv(f_go_wrappers, "\t\t", NULL);
if (SwigType_type(result) != T_VOID) {
@ -3109,6 +3125,12 @@ private:
Printv(f_go_wrappers, "\t\treturn\n", NULL);
}
Printv(f_go_wrappers, "\t}\n", NULL);
if (gccgo_flag) {
Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
}
Printv(f_go_wrappers, "\t", NULL);
if (SwigType_type(result) != T_VOID) {
Printv(f_go_wrappers, "return ", NULL);
@ -3138,7 +3160,8 @@ private:
if (overname) {
Append(upcall_method_name, overname);
}
String *upcall_decl = Swig_method_decl(Getattr(n, "type"), Getattr(n, "decl"), upcall_method_name, parms, 0, 0);
SwigType *rtype = Getattr(n, "classDirectorMethods:type");
String *upcall_decl = Swig_method_decl(rtype, Getattr(n, "decl"), upcall_method_name, parms, 0, 0);
Printv(f_c_directors_h, " ", upcall_decl, " {\n", NULL);
Delete(upcall_decl);
@ -3254,9 +3277,9 @@ private:
Printv(f_go_wrappers, " {\n", NULL);
if (gccgo_flag && !gccgo_46_flag) {
Printv(f_go_wrappers, "\tsyscall.Entersyscall()\n", NULL);
Printv(f_go_wrappers, "\tdefer syscall.Exitsyscall()\n", NULL);
if (gccgo_flag) {
Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
}
Printv(f_go_wrappers, "\t", NULL);
@ -3301,9 +3324,9 @@ private:
}
Printv(f_go_wrappers, "{\n", NULL);
if (gccgo_flag && !gccgo_46_flag) {
Printv(f_go_wrappers, "\tsyscall.Exitsyscall()\n", NULL);
Printv(f_go_wrappers, "\tdefer syscall.Entersyscall()\n", NULL);
if (gccgo_flag) {
Printv(f_go_wrappers, "\tSwigCgocallBack()\n", NULL);
Printv(f_go_wrappers, "\tdefer SwigCgocallBackDone()\n", NULL);
}
Printv(f_go_wrappers, "\t", NULL);
@ -3411,7 +3434,7 @@ private:
if (!is_ignored || is_pure_virtual) {
// Declare the method for the director class.
SwigType *rtype = (Getattr(n, "conversion_operator") ? NULL : Getattr(n, "type"));
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
String *decl = Swig_method_decl(rtype, Getattr(n, "decl"), Getattr(n, "name"), parms, 0, 0);
Printv(f_c_directors_h, " virtual ", decl, NULL);
Delete(decl);
@ -3435,7 +3458,7 @@ private:
Printv(w->def, " {\n", NULL);
if (SwigType_type(result) != T_VOID) {
Wrapper_add_local(w, "c_result", SwigType_lstr(Getattr(n, "returntype"), "c_result"));
Wrapper_add_local(w, "c_result", SwigType_lstr(result, "c_result"));
}
if (!is_ignored) {
@ -3491,9 +3514,8 @@ private:
Printv(w->code, " crosscall2(", callback_wname, ", &swig_a, (int) sizeof swig_a);\n", NULL);
if (SwigType_type(result) != T_VOID) {
String *rname = NewString("c_result");
Parm *rp = NewParm(Getattr(n, "returntype"), rname, n);
String *tm = Swig_typemap_lookup("directorout", rp, rname, NULL);
String *result_str = NewString("c_result");
String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL);
if (!tm) {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use type %s as director method result\n", SwigType_str(result, 0));
@ -3502,13 +3524,12 @@ private:
Replaceall(tm, "$input", swig_a_result);
Replaceall(tm, "$result", "c_result");
Printv(w->code, " ", tm, "\n", NULL);
String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), "c_result");
String *retstr = SwigType_rcaststr(result, "c_result");
Printv(w->code, " return ", retstr, ";\n", NULL);
Delete(retstr);
Delete(tm);
}
Delete(rp);
Delete(rname);
Delete(result_str);
}
// The C wrapper code which calls the Go function.
@ -3566,9 +3587,8 @@ private:
Printv(w->code, callback_wname, "(go_val", args, ");\n", NULL);
if (SwigType_type(result) != T_VOID) {
String *rname = NewString("c_result");
Parm *rp = NewParm(Getattr(n, "returntype"), rname, n);
String *tm = Swig_typemap_lookup("directorout", rp, rname, NULL);
String *result_str = NewString("c_result");
String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL);
if (!tm) {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use type %s as director method result\n", SwigType_str(result, 0));
@ -3576,13 +3596,12 @@ private:
Replaceall(tm, "$input", Swig_cresult_name());
Replaceall(tm, "$result", "c_result");
Printv(w->code, " ", tm, "\n", NULL);
String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), "c_result");
String *retstr = SwigType_rcaststr(result, "c_result");
Printv(w->code, " return ", retstr, ";\n", NULL);
Delete(retstr);
Delete(tm);
}
Delete(rp);
Delete(rname);
Delete(result_str);
}
}
@ -3602,7 +3621,7 @@ private:
assert(is_pure_virtual);
Printv(w->code, " _swig_gopanic(\"call to pure virtual function ", Getattr(parent, "sym:name"), name, "\");\n", NULL);
if (SwigType_type(result) != T_VOID) {
String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), "c_result");
String *retstr = SwigType_rcaststr(result, "c_result");
Printv(w->code, " return ", retstr, ";\n", NULL);
Delete(retstr);
}
@ -3612,8 +3631,6 @@ private:
Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_c_directors);
DelWrapper(w);
}
Delete(cn);
@ -3623,6 +3640,7 @@ private:
Delete(upcall_name);
Delete(callback_wname);
Delete(go_name);
DelWrapper(w);
return SWIG_OK;
}
@ -3734,9 +3752,9 @@ private:
if (is_constructor) {
assert(!is_upcall);
if (!is_director) {
all_result = Getattr(class_node, "classtypeobj");
all_result = Copy(Getattr(class_node, "classtypeobj"));
} else {
all_result = director_struct;
all_result = Copy(director_struct);
}
mismatch = false;
} else {
@ -3744,7 +3762,8 @@ private:
mismatch = false;
bool any_void = false;
for (int i = 0; i < nfunc; ++i) {
Node *ni = Getitem(dispatch, i);
Node *nn = Getitem(dispatch, i);
Node *ni = Getattr(nn, "directorNode") ? Getattr(nn, "directorNode") : nn;
SwigType *result = Getattr(ni, "go:type");
assert(result);
@ -3823,7 +3842,8 @@ private:
for (int i = 0; i < nfunc; ++i) {
int fn = 0;
Node *ni = Getitem(dispatch, i);
Node *nn = Getitem(dispatch, i);
Node *ni = Getattr(nn, "directorNode") ? Getattr(nn, "directorNode") : nn;
Parm *pi = Getattr(ni, "wrap:parms");
// If we are using a receiver, we want to ignore a leading self
@ -3853,7 +3873,8 @@ private:
// Build list of collisions with the same number of arguments.
List *coll = NewList();
for (int k = i + 1; k < nfunc; ++k) {
Node *nk = Getitem(dispatch, k);
Node *nnk = Getitem(dispatch, k);
Node *nk = Getattr(nnk, "directorNode") ? Getattr(nnk, "directorNode") : nnk;
Parm *pk = Getattr(nk, "wrap:parms");
if (use_receiver && pk && Getattr(pk, "self")) {
pk = getParm(pk);
@ -4363,7 +4384,7 @@ private:
Delete(p);
}
if (Strstr(ret, "$gotypename") != 0) {
if (ret && Strstr(ret, "$gotypename") != 0) {
ret = NULL;
}
@ -4392,7 +4413,7 @@ private:
ret = exportedName(ret);
Node *cnmod = Getattr(cn, "module");
if (!cnmod || Strcmp(Getattr(cnmod, "name"), package) == 0) {
if (!cnmod || Strcmp(Getattr(cnmod, "name"), module) == 0) {
Setattr(undefined_types, t, t);
} else {
String *nw = NewString("");
@ -4574,7 +4595,7 @@ private:
}
ex = exportedName(cname);
Node *cnmod = Getattr(cn, "module");
if (!cnmod || Strcmp(Getattr(cnmod, "name"), package) == 0) {
if (!cnmod || Strcmp(Getattr(cnmod, "name"), module) == 0) {
if (add_to_hash) {
Setattr(undefined_types, ty, ty);
}
@ -4606,19 +4627,20 @@ private:
bool is_member = Strcmp(gt, "_swig_memberptr") == 0;
bool is_complex64 = Strcmp(gt, "complex64") == 0;
bool is_complex128 = Strcmp(gt, "complex128") == 0;
bool is_char = false;
bool is_short = false;
bool is_int = false;
bool is_long = false;
bool is_float = false;
bool is_double = false;
bool is_int8 = false;
bool is_int16 = false;
bool is_int = Strcmp(gt, "int") == 0 || Strcmp(gt, "uint") == 0;
bool is_int32 = false;
bool is_int64 = false;
bool is_float32 = false;
bool is_float64 = false;
if ((n != NULL && Getattr(n, "tmap:gotype") != NULL) || hasGoTypemap(n, type)) {
is_char = Strcmp(gt, "int8") == 0 || Strcmp(gt, "uint8") == 0 || Strcmp(gt, "byte") == 0;
is_short = Strcmp(gt, "int16") == 0 || Strcmp(gt, "uint16") == 0;
is_int = Strcmp(gt, "int") == 0 || Strcmp(gt, "int32") == 0 || Strcmp(gt, "uint32") == 0;
is_long = Strcmp(gt, "int64") == 0 || Strcmp(gt, "uint64") == 0;
is_float = Strcmp(gt, "float32") == 0;
is_double = Strcmp(gt, "float64") == 0;
is_int8 = Strcmp(gt, "int8") == 0 || Strcmp(gt, "uint8") == 0 || Strcmp(gt, "byte") == 0;
is_int16 = Strcmp(gt, "int16") == 0 || Strcmp(gt, "uint16") == 0;
is_int32 = Strcmp(gt, "int32") == 0 || Strcmp(gt, "uint32") == 0;
is_int64 = Strcmp(gt, "int64") == 0 || Strcmp(gt, "uint64") == 0;
is_float32 = Strcmp(gt, "float32") == 0;
is_float64 = Strcmp(gt, "float64") == 0;
}
Delete(gt);
@ -4630,7 +4652,11 @@ private:
Append(ret, name);
return ret;
} else if (is_slice) {
// Slices are always passed as a _goslice_, whether or not references
// are involved.
ret = NewString("_goslice_ ");
Append(ret, name);
return ret;
} else if (is_function || is_member) {
ret = NewString("void *");
Append(ret, name);
@ -4665,7 +4691,12 @@ private:
if (Strcmp(q, "const") == 0) {
SwigType_del_qualifier(t);
if (hasGoTypemap(n, t) || SwigType_ispointer(t)) {
ret = SwigType_lstr(t, name);
if (is_int) {
ret = NewString("intgo ");
Append(ret, name);
} else {
ret = SwigType_lstr(t, name);
}
Delete(q);
Delete(t);
return ret;
@ -4674,18 +4705,25 @@ private:
Delete(q);
}
}
if (Language::enumLookup(t) != NULL || Strcmp(t, "enum ") == 0) {
is_int = true;
}
Delete(t);
if (is_char) {
if (is_int8) {
ret = NewString("char ");
} else if (is_short) {
} else if (is_int16) {
ret = NewString("short ");
} else if (is_int) {
ret = NewString("intgo ");
} else if (is_int32) {
ret = NewString("int ");
} else if (is_long) {
} else if (is_int64) {
ret = NewString("long long ");
} else if (is_float) {
} else if (is_float32) {
ret = NewString("float ");
} else if (is_double) {
} else if (is_float64) {
ret = NewString("double ");
} else {
return SwigType_lstr(type, name);
@ -4754,7 +4792,7 @@ private:
return Copy(ret);
}
if (Strcmp(Getattr(n, "type"), "enum ") == 0) {
if (Equal(Getattr(n, "type"), "enum ")) {
return NewString("int");
}
@ -4859,6 +4897,7 @@ Go Options (available with -go)\n\
-gccgo - Generate code for gccgo rather than 6g/8g\n\
-go-prefix <p> - Like gccgo -fgo-prefix option\n\
-longsize <s> - Set size of C/C++ long type--32 or 64 bits\n\
-intgosize <s> - Set size of Go int type--32 or 64 bits\n\
-package <name> - Set name of the Go package to <name>\n\
-soname <name> - Set shared library holding C/C++ code to <name>\n\
\n";

View file

@ -11,8 +11,6 @@
* Guile language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_guile_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
@ -25,7 +23,6 @@ Guile Options (available with -guile)\n\
-emitslotaccessors - Emit accessor methods for all GOOPS slots\n" "\
-exportprimitive - Add the (export ...) code from scmstub into the\n\
GOOPS file.\n\
-gh - Use the gh_ Guile API. (Guile <= 1.8) \n\
-goopsprefix <prefix> - Prepend <prefix> to all goops identifiers\n\
-linkage <lstyle> - Use linkage protocol <lstyle> (default `simple')\n\
Use `module' for native Guile module linking\n\
@ -46,7 +43,6 @@ Guile Options (available with -guile)\n\
-proxy - Export GOOPS class definitions\n\
-primsuffix <suffix> - Name appended to primitive module when exporting\n\
GOOPS classes. (default = \"primitive\")\n\
-scm - Use the scm Guile API. (Guile >= 1.6, default) \n\
-scmstub - Output Scheme file with module declaration and\n\
exports; only with `passive' and `simple' linkage\n\
-useclassprefix - Prepend the class name to all goops identifiers\n\
@ -59,9 +55,9 @@ static File *f_wrappers = 0;
static File *f_init = 0;
static char *prefix = (char *) "gswig_";
static String *prefix = NewString("gswig_");
static char *module = 0;
static char *package = 0;
static String *package = 0;
static enum {
GUILE_LSTYLE_SIMPLE, // call `SWIG_init()'
GUILE_LSTYLE_PASSIVE, // passive linking (no module code)
@ -96,7 +92,6 @@ static String *return_multi_doc = 0;
static String *exported_symbols = 0;
static int use_scm_interface = 1;
static int exporting_destructor = 0;
static String *swigtype_ptr = 0;
@ -127,7 +122,7 @@ public:
* ------------------------------------------------------------ */
virtual void main(int argc, char *argv[]) {
int i, orig_len;
int i;
SWIG_library_directory("guile");
SWIG_typemap_lang("guile");
@ -140,8 +135,7 @@ public:
SWIG_exit(EXIT_SUCCESS);
} else if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) {
prefix = new char[strlen(argv[i + 1]) + 2];
strcpy(prefix, argv[i + 1]);
prefix = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
@ -150,8 +144,7 @@ public:
}
} else if (strcmp(argv[i], "-package") == 0) {
if (argv[i + 1]) {
package = new char[strlen(argv[i + 1]) + 2];
strcpy(package, argv[i + 1]);
package = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
@ -220,10 +213,10 @@ public:
goops = true;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-gh") == 0) {
use_scm_interface = 0;
Printf(stderr, "Deprecated command line option: -gh. Wrappers are always generated for the SCM interface. See documentation for more information regarding the deprecated GH interface.\n");
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-scm") == 0) {
use_scm_interface = 1;
Printf(stderr, "Deprecated command line option: -scm. Wrappers are always generated for the SCM interface. See documentation for more information regarding the deprecated GH interface.\n");
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-primsuffix") == 0) {
if (argv[i + 1]) {
@ -278,21 +271,18 @@ public:
// should use Swig_warning() ?
Printf(stderr, "guile: Warning: -exportprimitive only makes sense with passive linkage without a scmstub.\n");
}
// Make sure `prefix' ends in an underscore
orig_len = strlen(prefix);
if (prefix[orig_len - 1] != '_') {
prefix[1 + orig_len] = 0;
prefix[orig_len] = '_';
// Make sure `prefix' ends in an underscore
if (prefix) {
const char *px = Char(prefix);
if (px[Len(prefix) - 1] != '_')
Printf(prefix, "_");
}
/* Add a symbol for this module */
Preprocessor_define("SWIGGUILE 1", 0);
/* Read in default typemaps */
if (use_scm_interface)
SWIG_config_file("guile_scm.swg");
else
SWIG_config_file("guile_gh.swg");
SWIG_config_file("guile_scm.swg");
allow_overloading();
}
@ -335,13 +325,6 @@ public:
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGGUILE\n");
if (!use_scm_interface) {
if (SwigRuntime == 1)
Printf(f_runtime, "#define SWIG_GLOBAL\n");
if (SwigRuntime == 2)
Printf(f_runtime, "#define SWIG_NOINCLUDE\n");
}
/* Write out directives and declarations */
module = Swig_copy_string(Char(Getattr(n, "name")));
@ -409,7 +392,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -856,7 +838,7 @@ public:
}
}
if (use_scm_interface && exporting_destructor) {
if (exporting_destructor) {
/* Mark the destructor's argument as destroyed. */
String *tm = NewString("SWIG_Guile_MarkPointerDestroyed($input);");
Replaceall(tm, "$input", Getattr(l, "emit:input"));
@ -873,14 +855,8 @@ public:
Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL);
// Now write code to make the function call
if (!use_scm_interface)
Printv(f->code, tab4, "gh_defer_ints();\n", NIL);
String *actioncode = emit_action(n);
if (!use_scm_interface)
Printv(actioncode, tab4, "gh_allow_ints();\n", NIL);
// Now have return value, figure out what to do with it.
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$result", "gswig_result");
@ -963,11 +939,7 @@ public:
Printv(f_wrappers, ");\n", NIL);
Printv(f_wrappers, "}\n", NIL);
/* Register it */
if (use_scm_interface) {
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s_rest);\n", proc_name, wname);
} else {
Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s_rest, 0, 0, 1);\n", proc_name, wname);
}
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s_rest);\n", proc_name, wname);
} else if (emit_setters && struct_member && strlen(Char(proc_name)) > 3) {
int len = Len(proc_name);
const char *pc = Char(proc_name);
@ -978,19 +950,13 @@ public:
struct_member = 2; /* have a setter */
} else
Printf(f_init, "SCM getter = ");
if (use_scm_interface) {
/* GOOPS support uses the MEMBER-set and MEMBER-get functions,
so ignore only_setters in this case. */
if (only_setters && !goops)
Printf(f_init, "scm_c_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
else
Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
} else {
if (only_setters && !goops)
Printf(f_init, "scm_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
else
Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, %d, %d, 0);\n", proc_name, wname, numreq, numargs - numreq);
}
/* GOOPS support uses the MEMBER-set and MEMBER-get functions,
so ignore only_setters in this case. */
if (only_setters && !goops)
Printf(f_init, "scm_c_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
else
Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
if (!is_setter) {
/* Strip off "-get" */
char *pws_name = (char *) malloc(sizeof(char) * (len - 3));
@ -998,19 +964,11 @@ public:
pws_name[len - 4] = 0;
if (struct_member == 2) {
/* There was a setter, so create a procedure with setter */
if (use_scm_interface) {
Printf(f_init, "scm_c_define");
} else {
Printf(f_init, "gh_define");
}
Printf(f_init, "scm_c_define");
Printf(f_init, "(\"%s\", " "scm_make_procedure_with_setter(getter, setter));\n", pws_name);
} else {
/* There was no setter, so make an alias to the getter */
if (use_scm_interface) {
Printf(f_init, "scm_c_define");
} else {
Printf(f_init, "gh_define");
}
Printf(f_init, "scm_c_define");
Printf(f_init, "(\"%s\", getter);\n", pws_name);
}
Printf(exported_symbols, "\"%s\", ", pws_name);
@ -1018,15 +976,11 @@ public:
}
} else {
/* Register the function */
if (use_scm_interface) {
if (exporting_destructor) {
Printf(f_init, "((swig_guile_clientdata *)(SWIGTYPE%s->clientdata))->destroy = (guile_destructor) %s;\n", swigtype_ptr, wname);
//Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname);
}
Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
} else {
Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, %d, %d, 0);\n", proc_name, wname, numreq, numargs - numreq);
if (exporting_destructor) {
Printf(f_init, "((swig_guile_clientdata *)(SWIGTYPE%s->clientdata))->destroy = (guile_destructor) %s;\n", swigtype_ptr, wname);
//Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname);
}
Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
}
} else { /* overloaded function; don't export the single methods */
if (!Getattr(n, "sym:nextSibling")) {
@ -1049,11 +1003,7 @@ public:
Printf(df->code, "#undef FUNC_NAME\n");
Printv(df->code, "}\n", NIL);
Wrapper_print(df, f_wrappers);
if (use_scm_interface) {
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s);\n", proc_name, dname);
} else {
Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, 0, 1);\n", proc_name, dname);
}
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s);\n", proc_name, dname);
DelWrapper(df);
Delete(dispatch);
Delete(dname);
@ -1226,36 +1176,27 @@ public:
/* Read-only variables become a simple procedure returning the
value; read-write variables become a simple procedure with
an optional argument. */
if (use_scm_interface) {
if (!goops && GetFlag(n, "feature:constasvar")) {
/* need to export this function as a variable instead of a procedure */
if (scmstub) {
/* export the function in the wrapper, and (set!) it in scmstub */
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name);
Printf(scmtext, "(set! %s (%s))\n", proc_name, proc_name);
} else {
/* export the variable directly */
Printf(f_init, "scm_c_define(\"%s\", %s(SCM_UNDEFINED));\n", proc_name, var_name);
}
} else {
/* Export the function as normal */
if (!goops && GetFlag(n, "feature:constasvar")) {
/* need to export this function as a variable instead of a procedure */
if (scmstub) {
/* export the function in the wrapper, and (set!) it in scmstub */
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name);
Printf(scmtext, "(set! %s (%s))\n", proc_name, proc_name);
} else {
/* export the variable directly */
Printf(f_init, "scm_c_define(\"%s\", %s(SCM_UNDEFINED));\n", proc_name, var_name);
}
} else {
Printf(f_init, "\t gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, %d, 0);\n", proc_name, var_name, !GetFlag(n, "feature:immutable"));
/* Export the function as normal */
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name);
}
} else {
/* Read/write variables become a procedure with setter. */
if (use_scm_interface) {
Printf(f_init, "{ SCM p = scm_c_define_gsubr(\"%s\", 0, 1, 0, (swig_guile_proc) %s);\n", proc_name, var_name);
Printf(f_init, "scm_c_define");
} else {
Printf(f_init, "\t{ SCM p = gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, 1, 0);\n", proc_name, var_name);
Printf(f_init, "gh_define");
}
Printf(f_init, "{ SCM p = scm_c_define_gsubr(\"%s\", 0, 1, 0, (swig_guile_proc) %s);\n", proc_name, var_name);
Printf(f_init, "scm_c_define");
Printf(f_init, "(\"%s\", " "scm_make_procedure_with_setter(p, p)); }\n", proc_name);
}
Printf(exported_symbols, "\"%s\", ", proc_name);
@ -1489,12 +1430,10 @@ public:
String *mangled_classname = Swig_name_mangle(Getattr(n, "sym:name"));
/* Export clientdata structure */
if (use_scm_interface) {
Printf(f_runtime, "static swig_guile_clientdata _swig_guile_clientdata%s = { NULL, SCM_EOL };\n", mangled_classname);
Printf(f_runtime, "static swig_guile_clientdata _swig_guile_clientdata%s = { NULL, SCM_EOL };\n", mangled_classname);
Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", swigtype_ptr, ", (void *) &_swig_guile_clientdata", mangled_classname, ");\n", NIL);
SwigType_remember(ct);
}
Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", swigtype_ptr, ", (void *) &_swig_guile_clientdata", mangled_classname, ");\n", NIL);
SwigType_remember(ct);
Delete(ct);
/* Emit all of the members */
@ -1730,28 +1669,16 @@ public:
String *runtimeCode() {
String *s;
if (use_scm_interface) {
s = Swig_include_sys("guile_scm_run.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'guile_scm_run.swg");
s = NewString("");
}
} else {
s = Swig_include_sys("guile_gh_run.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'guile_gh_run.swg");
s = NewString("");
}
s = Swig_include_sys("guile_scm_run.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'guile_scm_run.swg");
s = NewString("");
}
return s;
}
String *defaultExternalRuntimeFilename() {
if (use_scm_interface) {
return NewString("swigguilerun.h");
} else {
return NewString("swigguileghrun.h");
}
return NewString("swigguilerun.h");
}
};

View file

@ -11,8 +11,6 @@
* Java language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_java_cxx[] = "$Id$";
#include "swigmod.h"
#include <limits.h> // for INT_MAX
#include "cparse.h"
@ -69,6 +67,7 @@ class JAVA:public Language {
String *imclass_imports; //intermediary class imports from %pragma
String *module_imports; //module imports from %pragma
String *imclass_baseclass; //inheritance for intermediary class class from %pragma
String *imclass_package; //package in which to generate the intermediary class
String *module_baseclass; //inheritance for module class from %pragma
String *imclass_interfaces; //interfaces for intermediary class class from %pragma
String *module_interfaces; //interfaces for module class from %pragma
@ -132,12 +131,14 @@ public:
variable_name(NULL),
proxy_class_constants_code(NULL),
module_class_constants_code(NULL),
enum_code(NULL),
package(NULL),
jnipackage(NULL),
package_path(NULL),
imclass_imports(NULL),
module_imports(NULL),
imclass_baseclass(NULL),
imclass_package(NULL),
module_baseclass(NULL),
imclass_interfaces(NULL),
module_interfaces(NULL),
@ -151,13 +152,41 @@ public:
dmethods_seq(NULL),
dmethods_table(NULL),
n_dmethods(0),
n_directors(0) {
n_directors(0),
first_class_dmethod(0),
curr_class_dmethod(0) {
/* for now, multiple inheritance in directors is disabled, this
should be easy to implement though */
director_multiple_inheritance = 0;
director_language = 1;
}
/* -----------------------------------------------------------------------------
* constructIntermediateClassName()
*
* Construct the fully qualified name of the intermidiate class and set
* the full_imclass_name attribute accordingly.
* ----------------------------------------------------------------------------- */
void constructIntermediateClassName(Node *n) {
String *nspace = Getattr(n, "sym:nspace");
if (imclass_package && package)
full_imclass_name = NewStringf("%s.%s.%s", package, imclass_package, imclass_name);
else if (package && nspace)
full_imclass_name = NewStringf("%s.%s", package, imclass_name);
else if (imclass_package)
full_imclass_name = NewStringf("%s.%s", imclass_package, imclass_name);
else
full_imclass_name = NewStringf("%s", imclass_name);
if (nspace && !package) {
String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString("<unnamed>");
Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n),
"The nspace feature is used on '%s' without -package. "
"The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name);
}
}
/* -----------------------------------------------------------------------------
* getProxyName()
*
@ -201,24 +230,6 @@ public:
return valid_jni_name;
}
/* -----------------------------------------------------------------------------
* directorClassName()
* ----------------------------------------------------------------------------- */
String *directorClassName(Node *n) {
String *dirclassname;
const char *attrib = "director:classname";
if (!(dirclassname = Getattr(n, attrib))) {
String *classname = Getattr(n, "sym:name");
dirclassname = NewStringf("SwigDirector_%s", classname);
Setattr(n, attrib, dirclassname);
}
return dirclassname;
}
/* ------------------------------------------------------------
* main()
* ------------------------------------------------------------ */
@ -371,14 +382,17 @@ public:
constants_interface_name = NewStringf("%sConstants", module_class_name);
// module class and intermediary classes are always created
addSymbol(imclass_name, n);
addSymbol(module_class_name, n);
if (!addSymbol(imclass_name, n))
return SWIG_ERROR;
if (!addSymbol(module_class_name, n))
return SWIG_ERROR;
imclass_class_code = NewString("");
proxy_class_def = NewString("");
proxy_class_code = NewString("");
module_class_constants_code = NewString("");
imclass_baseclass = NewString("");
imclass_package = NULL;
imclass_interfaces = NewString("");
imclass_class_modifiers = NewString("");
module_class_code = NewString("");
@ -414,8 +428,11 @@ public:
Printf(f_directors, "/* ---------------------------------------------------\n");
Printf(f_directors, " * C++ director class methods\n");
Printf(f_directors, " * --------------------------------------------------- */\n\n");
if (outfile_h)
Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
if (outfile_h) {
String *filename = Swig_file_filename(outfile_h);
Printf(f_directors, "#include \"%s\"\n\n", filename);
Delete(filename);
}
}
Printf(f_runtime, "\n");
@ -456,7 +473,7 @@ public:
}
// Generate the intermediary class
{
String *filen = NewStringf("%s%s.java", SWIG_output_directory(), imclass_name);
String *filen = NewStringf("%s%s.java", outputDirectory(imclass_package), imclass_name);
File *f_im = NewFile(filen, "w", SWIG_output_files());
if (!f_im) {
FileErrorDisplay(filen);
@ -469,8 +486,12 @@ public:
// Start writing out the intermediary class file
emitBanner(f_im);
if (package)
Printf(f_im, "package %s;\n", package);
if (imclass_package && package)
Printf(f_im, "package %s.%s;", package, imclass_package);
else if (imclass_package)
Printf(f_im, "package %s;", imclass_package);
else if (package)
Printf(f_im, "package %s;\n", package);
if (imclass_imports)
Printf(f_im, "%s\n", imclass_imports);
@ -502,7 +523,7 @@ public:
}
// Finish off the class
Printf(f_im, "}\n");
Close(f_im);
Delete(f_im);
}
// Generate the Java module class
@ -554,7 +575,7 @@ public:
// Finish off the class
Printf(f_module, "}\n");
Close(f_module);
Delete(f_module);
}
// Generate the Java constants interface
@ -585,7 +606,7 @@ public:
// Finish off the Java interface
Printf(f_module, "}\n");
Close(f_module);
Delete(f_module);
}
if (upcasts_code)
@ -637,6 +658,8 @@ public:
module_class_constants_code = NULL;
Delete(imclass_baseclass);
imclass_baseclass = NULL;
Delete(imclass_package);
imclass_package = NULL;
Delete(imclass_interfaces);
imclass_interfaces = NULL;
Delete(imclass_class_modifiers);
@ -685,7 +708,6 @@ public:
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
Close(f_runtime_h);
Delete(f_runtime_h);
f_runtime_h = NULL;
Delete(f_directors);
@ -701,7 +723,6 @@ public:
Delete(f_init);
Dump(f_runtime, f_begin);
Delete(f_runtime);
Close(f_begin);
Delete(f_begin);
return SWIG_OK;
}
@ -721,25 +742,15 @@ public:
*----------------------------------------------------------------------*/
UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *imclass_desc, String *class_desc, String *decl) {
UpcallData *udata;
String *imclass_methodidx;
String *class_methodidx;
Hash *new_udata;
String *key = NewStringf("%s|%s", imclass_method, decl);
++curr_class_dmethod;
/* Do we know about this director class already? */
if ((udata = Getattr(dmethods_table, key))) {
Delete(key);
return Getattr(udata, "methodoff");
}
imclass_methodidx = NewStringf("%d", n_dmethods);
class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
String *imclass_methodidx = NewStringf("%d", n_dmethods);
String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
n_dmethods++;
new_udata = NewHash();
Hash *new_udata = NewHash();
Append(dmethods_seq, new_udata);
Setattr(dmethods_table, key, new_udata);
@ -878,8 +889,10 @@ public:
if (Getattr(n, "sym:overloaded")) {
// Emit warnings for the few cases that can't be overloaded in Java and give up on generating wrapper
Swig_overload_check(n);
if (Getattr(n, "overload:ignore"))
if (Getattr(n, "overload:ignore")) {
DelWrapper(f);
return SWIG_OK;
}
}
Printf(imclass_class_code, " public final static native %s %s(", im_return_type, overloaded_name);
@ -1008,7 +1021,7 @@ public:
if ((throw_parm_list = Getattr(n, "catchlist"))) {
Swig_typemap_attach_parms("throws", throw_parm_list, f);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
addThrows(n, "tmap:throws", p);
}
}
@ -1190,18 +1203,7 @@ public:
if (proxy_flag && !is_wrapping_class()) {
// Global enums / enums in a namespace
assert(!full_imclass_name);
if (!nspace) {
full_imclass_name = NewStringf("%s", imclass_name);
} else {
if (package) {
full_imclass_name = NewStringf("%s.%s", package, imclass_name);
} else {
String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString("<unnamed>");
Swig_error(Getfile(n), Getline(n), "The nspace feature used on '%s' is not supported unless a package is specified with -package - Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name);
SWIG_exit(EXIT_FAILURE);
}
}
constructIntermediateClassName(n);
}
enum_code = NewString("");
@ -1300,7 +1302,7 @@ public:
"\n", enum_code, "\n", NIL);
Printf(f_enum, "\n");
Close(f_enum);
Delete(f_enum);
Delete(output_directory);
}
} else {
@ -1587,6 +1589,7 @@ public:
*
* Valid Pragmas:
* jniclassbase - base (extends) for the intermediary class
* jniclasspackage - package in which to generate the intermediary class
* jniclassclassmodifiers - class modifiers for the intermediary class
* jniclasscode - text (java code) is copied verbatim to the intermediary class
* jniclassimports - import statements for the intermediary class
@ -1614,6 +1617,24 @@ public:
if (Strcmp(code, "jniclassbase") == 0) {
Delete(imclass_baseclass);
imclass_baseclass = Copy(strvalue);
} else if (Strcmp(code, "jniclasspackage") == 0) {
Delete(imclass_package);
imclass_package = Copy(strvalue);
String *imclass_class_package_jniname = makeValidJniName(imclass_package);
Printv(jnipackage, imclass_class_package_jniname, NIL);
Delete(imclass_class_package_jniname);
Replaceall(jnipackage, NSPACE_SEPARATOR, "_");
Append(jnipackage, "_");
String *wrapper_name = NewString("");
String *imclass_class_jniname = makeValidJniName(imclass_name);
Printf(wrapper_name, "Java_%s%s_%%f", jnipackage, imclass_class_jniname);
Delete(imclass_class_jniname);
Swig_name_unregister("wrapper");
Swig_name_register("wrapper", Char(wrapper_name));
Delete(wrapper_name);
} else if (Strcmp(code, "jniclassclassmodifiers") == 0) {
Delete(imclass_class_modifiers);
imclass_class_modifiers = Copy(strvalue);
@ -1887,10 +1908,11 @@ public:
if (proxy_flag) {
proxy_class_name = NewString(Getattr(n, "sym:name"));
String *nspace = getNSpace();
constructIntermediateClassName(n);
if (!nspace) {
full_proxy_class_name = NewStringf("%s", proxy_class_name);
full_imclass_name = NewStringf("%s", imclass_name);
if (Cmp(proxy_class_name, imclass_name) == 0) {
Printf(stderr, "Class name cannot be equal to intermediary class name: %s\n", proxy_class_name);
SWIG_exit(EXIT_FAILURE);
@ -1901,14 +1923,10 @@ public:
SWIG_exit(EXIT_FAILURE);
}
} else {
if (package) {
if (package)
full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name);
full_imclass_name = NewStringf("%s.%s", package, imclass_name);
} else {
String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString("<unnamed>");
Swig_error(Getfile(n), Getline(n), "The nspace feature used on '%s' is not supported unless a package is specified with -package - Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name);
SWIG_exit(EXIT_FAILURE);
}
else
full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name);
}
if (!addSymbol(proxy_class_name, n, nspace))
@ -1977,7 +1995,7 @@ public:
Printv(f_proxy, proxy_class_constants_code, NIL);
Printf(f_proxy, "}\n");
Close(f_proxy);
Delete(f_proxy);
f_proxy = NULL;
/* Output the downcast method, if necessary. Note: There's no other really
@ -3069,7 +3087,7 @@ public:
Replaceall(swigtype, "$imclassname", imclass_name);
Printv(f_swigtype, swigtype, NIL);
Close(f_swigtype);
Delete(f_swigtype);
Delete(swigtype);
Delete(n);
}
@ -3372,7 +3390,8 @@ public:
String *norm_name = SwigType_namestr(Getattr(n, "name"));
String *swig_director_connect = Swig_name_member(getNSpace(), proxy_class_name, "director_connect");
String *swig_director_connect_jni = makeValidJniName(swig_director_connect);
String *sym_name = Getattr(n, "sym:name");
String *smartptr = Getattr(n, "feature:smartptr");
String *dirClassName = directorClassName(n);
Wrapper *code_wrap;
Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean mem_own, boolean weak_global);\n",
@ -3382,9 +3401,20 @@ public:
Printf(code_wrap->def,
"SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, "
"jboolean jweak_global) {\n", jnipackage, jni_imclass_name, swig_director_connect_jni);
Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name);
Printf(code_wrap->code, " (void)jcls;\n");
Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name);
if (Len(smartptr)) {
Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr, smartptr);
Printf(code_wrap->code, " (void)jcls;\n");
Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n");
Printf(code_wrap->code, " // Avoids using smart pointer specific API.\n");
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName);
}
else {
Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name);
Printf(code_wrap->code, " (void)jcls;\n");
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName);
}
Printf(code_wrap->code, " if (director) {\n");
Printf(code_wrap->code, " director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), "
"(jswig_mem_own == JNI_TRUE), (jweak_global == JNI_TRUE));\n");
@ -3408,7 +3438,7 @@ public:
"SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jtake_or_release) {\n",
jnipackage, jni_imclass_name, changeown_jnimethod_name);
Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name);
Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name);
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName);
Printf(code_wrap->code, " (void)jcls;\n");
Printf(code_wrap->code, " if (director) {\n");
Printf(code_wrap->code, " director->swig_java_change_ownership(jenv, jself, jtake_or_release ? true : false);\n");
@ -3421,6 +3451,7 @@ public:
Delete(changeown_method_name);
Delete(changeown_jnimethod_name);
Delete(norm_name);
Delete(dirClassName);
Delete(jni_imclass_name);
}
@ -3483,7 +3514,7 @@ public:
String *pkg_path = Swig_typemap_lookup("javapackage", p, "", 0);
SwigType *type = Getattr(p, "type");
if (pkg_path || Len(pkg_path) == 0)
if (!pkg_path || Len(pkg_path) == 0)
pkg_path = package_path;
String *descriptor_out = Copy(descriptor_in);
@ -3514,13 +3545,11 @@ public:
* --------------------------------------------------------------- */
int classDirectorMethod(Node *n, Node *parent, String *super) {
String *empty_str = NewString("");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
SwigType *returntype = Getattr(n, "returntype");
SwigType *returntype = Getattr(n, "type");
String *overloaded_name = getOverloadedName(n);
String *storage = Getattr(n, "storage");
String *value = Getattr(n, "value");
@ -3532,7 +3561,7 @@ public:
Wrapper *w = NewWrapper();
ParmList *l = Getattr(n, "parms");
bool is_void = !(Cmp(returntype, "void"));
String *qualified_return = NewString("");
String *qualified_return = 0;
bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0")));
int status = SWIG_OK;
bool output_director = true;
@ -3553,141 +3582,135 @@ public:
String *qualified_classname = Copy(classname);
String *nspace = getNSpace();
if (nspace)
if (nspace && package)
Insert(qualified_classname, 0, NewStringf("%s.%s.", package, nspace));
else if(nspace)
Insert(qualified_classname, 0, NewStringf("%s.", nspace));
// Kludge Alert: functionWrapper sets sym:overload properly, but it
// isn't at this point, so we have to manufacture it ourselves. At least
// we're consistent with the sym:overload name in functionWrapper. (?? when
// does the overloaded method name get set?)
imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name));
imclass_dmethod = NewStringf("%s", Swig_name_member(getNSpace(), dirclassname, overloaded_name));
if (returntype) {
qualified_return = SwigType_rcaststr(returntype, "c_result");
qualified_return = SwigType_rcaststr(returntype, "c_result");
if (!is_void && (!ignored_method || pure_virtual)) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
String *base_typename = SwigType_base(returntype);
String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
Symtab *symtab = Getattr(n, "sym:symtab");
Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) {
/* initialize pointers to something sane. Same for abstract
classes when a reference is returned. */
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
} else {
/* If returning a reference, initialize the pointer to a sane
default - if a Java exception occurs, then the pointer returns
something other than a NULL-initialized reference. */
String *non_ref_type = Copy(returntype);
/* Remove reference and const qualifiers */
Replaceall(non_ref_type, "r.", "");
Replaceall(non_ref_type, "q(const).", "");
Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL);
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL);
Delete(non_ref_type);
}
Delete(base_typename);
Delete(resolved_typename);
}
if (!is_void && (!ignored_method || pure_virtual)) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
SwigType *vt;
String *base_typename = SwigType_base(returntype);
String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
Symtab *symtab = Getattr(n, "sym:symtab");
Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
vt = cplus_value_type(returntype);
if (!vt) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstracts"))) {
/* initialize pointers to something sane. Same for abstract
classes when a reference is returned. */
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL);
Delete(vt);
/* If returning a reference, initialize the pointer to a sane
default - if a Java exception occurs, then the pointer returns
something other than a NULL-initialized reference. */
String *non_ref_type = Copy(returntype);
/* Remove reference and const qualifiers */
Replaceall(non_ref_type, "r.", "");
Replaceall(non_ref_type, "q(const).", "");
Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL);
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL);
Delete(non_ref_type);
}
Delete(base_typename);
Delete(resolved_typename);
}
} else {
SwigType *vt;
vt = cplus_value_type(returntype);
if (!vt) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL);
Delete(vt);
}
}
}
/* Create the intermediate class wrapper */
Parm *tp = NewParm(returntype, empty_str, n);
/* Create the intermediate class wrapper */
tm = Swig_typemap_lookup("jtype", n, "", 0);
if (tm) {
Printf(callback_def, " public static %s %s(%s self", tm, imclass_dmethod, qualified_classname);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
tm = Swig_typemap_lookup("jtype", tp, "", 0);
if (tm) {
Printf(callback_def, " public static %s %s(%s self", tm, imclass_dmethod, qualified_classname);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0));
String *cdesc = NULL;
SwigType *covariant = Getattr(n, "covariant");
SwigType *adjustedreturntype = covariant ? covariant : returntype;
Parm *adjustedreturntypeparm = NewParmNode(adjustedreturntype, n);
if (Swig_typemap_lookup("directorin", adjustedreturntypeparm, "", 0)
&& (cdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor"))) {
// Note that in the case of polymorphic (covariant) return types, the
// method's return type is changed to be the base of the C++ return
// type
String *jnidesc_canon = canonicalizeJNIDescriptor(cdesc, adjustedreturntypeparm);
Append(classret_desc, jnidesc_canon);
Delete(jnidesc_canon);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
/* Get the JNI field descriptor for this return type, add the JNI field descriptor
to jniret_desc */
if ((c_ret_type = Swig_typemap_lookup("jni", n, "", 0))) {
Parm *tp = NewParmNode(c_ret_type, n);
if (!is_void && !ignored_method) {
String *jretval_decl = NewStringf("%s jresult", c_ret_type);
Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
Delete(jretval_decl);
}
String *cdesc = NULL;
SwigType *covariant = Getattr(n, "covariant");
SwigType *adjustedreturntype = covariant ? covariant : returntype;
Parm *adjustedreturntypeparm = NewParm(adjustedreturntype, empty_str, n);
String *jdesc = NULL;
if (Swig_typemap_lookup("directorin", tp, "", 0)
&& (jdesc = Getattr(tp, "tmap:directorin:descriptor"))) {
if ((tm = Swig_typemap_lookup("directorin", adjustedreturntypeparm, "", 0))
&& (cdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor"))) {
// Note that in the case of polymorphic (covariant) return types, the
// method's return type is changed to be the base of the C++ return
// type
String *jnidesc_canon = canonicalizeJNIDescriptor(cdesc, adjustedreturntypeparm);
Append(classret_desc, jnidesc_canon);
// Objects marshalled passing a Java class across JNI boundary use jobject - the nouse flag indicates this
// We need the specific Java class name instead of the generic 'Ljava/lang/Object;'
if (GetFlag(tp, "tmap:directorin:nouse"))
jdesc = cdesc;
String *jnidesc_canon = canonicalizeJNIDescriptor(jdesc, tp);
Append(jniret_desc, jnidesc_canon);
Delete(jnidesc_canon);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(c_ret_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
/* Get the JNI field descriptor for this return type, add the JNI field descriptor
to jniret_desc */
Parm *retpm = NewParm(returntype, empty_str, n);
if ((c_ret_type = Swig_typemap_lookup("jni", retpm, "", 0))) {
Parm *tp = NewParm(c_ret_type, empty_str, n);
if (!is_void && !ignored_method) {
String *jretval_decl = NewStringf("%s jresult", c_ret_type);
Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
Delete(jretval_decl);
}
String *jdesc = NULL;
if ((tm = Swig_typemap_lookup("directorin", tp, "", 0))
&& (jdesc = Getattr(tp, "tmap:directorin:descriptor"))) {
// Objects marshalled passing a Java class across JNI boundary use jobject - the nouse flag indicates this
// We need the specific Java class name instead of the generic 'Ljava/lang/Object;'
if (GetFlag(tp, "tmap:directorin:nouse"))
jdesc = cdesc;
String *jnidesc_canon = canonicalizeJNIDescriptor(jdesc, tp);
Append(jniret_desc, jnidesc_canon);
Delete(jnidesc_canon);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(c_ret_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
Delete(tp);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
Delete(adjustedreturntypeparm);
Delete(retpm);
Delete(qualified_classname);
Delete(tp);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
Delete(adjustedreturntypeparm);
Delete(qualified_classname);
Swig_director_parms_fixup(l);
/* Attach the standard typemaps */
@ -3742,7 +3765,7 @@ public:
}
/* Start the Java field descriptor for the intermediate class's upcall (insert self object) */
Parm *tp = NewParm(c_classname, empty_str, n);
Parm *tp = NewParmNode(c_classname, n);
String *jdesc;
if ((tm = Swig_typemap_lookup("directorin", tp, "", 0))
@ -3754,7 +3777,7 @@ public:
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap for type %s for use in %s::%s (skipping director method)\n",
SwigType_str(type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
@ -3784,7 +3807,7 @@ public:
/* Get parameter's intermediary C type */
if ((c_param_type = Getattr(p, "tmap:jni"))) {
Parm *tp = NewParm(c_param_type, empty_str, n);
Parm *tp = NewParm(c_param_type, Getattr(p, "name"), n);
String *desc_tm = NULL, *jdesc = NULL, *cdesc = NULL;
/* Add to local variables */
@ -3814,8 +3837,6 @@ public:
if (!ignored_method)
Printf(w->code, "%s\n", tm);
Delete(tm);
/* Add parameter to the intermediate class code if generating the
* intermediate's upcall code */
if ((tm = Getattr(p, "tmap:jtype"))) {
@ -3880,7 +3901,6 @@ public:
output_director = false;
}
Delete(tp);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
@ -3890,13 +3910,12 @@ public:
Delete(arg);
Delete(c_decl);
Delete(c_param_type);
Delete(ln);
}
/* header declaration, start wrapper definition */
String *target;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s", target);
Delete(qualified_name);
@ -3918,7 +3937,7 @@ public:
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
addThrows(n, "tmap:throws", p);
if (gencomma++) {
@ -3946,21 +3965,18 @@ public:
addThrows(n, "feature:except", n);
if (!is_void) {
Parm *tp = NewParm(returntype, empty_str, n);
if ((tm = Swig_typemap_lookup("javadirectorout", tp, "", 0))) {
addThrows(n, "tmap:javadirectorout", tp);
if ((tm = Swig_typemap_lookup("javadirectorout", n, "", 0))) {
addThrows(n, "tmap:javadirectorout", n);
substituteClassname(returntype, tm);
Replaceall(tm, "$javacall", upcall);
Printf(callback_code, " return %s;\n", tm);
}
if ((tm = Swig_typemap_lookup("out", tp, "", 0)))
addThrows(n, "tmap:out", tp);
if ((tm = Swig_typemap_lookup("out", n, "", 0)))
addThrows(n, "tmap:out", n);
Delete(tm);
Delete(tp);
} else
Printf(callback_code, " %s;\n", upcall);
@ -3990,11 +4006,10 @@ public:
if (!is_void) {
String *jresult_str = NewString("jresult");
String *result_str = NewString("c_result");
Parm *tp = NewParm(returntype, result_str, n);
/* Copy jresult into c_result... */
if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) {
addThrows(n, "tmap:directorout", tp);
if ((tm = Swig_typemap_lookup("directorout", n, result_str, w))) {
addThrows(n, "tmap:directorout", n);
Replaceall(tm, "$input", jresult_str);
Replaceall(tm, "$result", result_str);
Printf(w->code, "%s\n", tm);
@ -4005,7 +4020,6 @@ public:
output_director = false;
}
Delete(tp);
Delete(jresult_str);
Delete(result_str);
}
@ -4112,7 +4126,7 @@ public:
Node *parent = parentNode(n);
String *decl = Getattr(n, "decl");
String *supername = Swig_class_name(parent);
String *classname = directorClassName(parent);
String *dirclassname = directorClassName(parent);
String *sub = NewString("");
Parm *p;
ParmList *superparms = Getattr(n, "parms");
@ -4144,11 +4158,11 @@ public:
/* constructor */
{
String *basetype = Getattr(parent, "classtype");
String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0);
String *call = Swig_csuperclass_call(0, basetype, superparms);
String *classtype = SwigType_namestr(Getattr(n, "name"));
Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor"));
Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor"));
Printf(f_directors, "}\n\n");
Delete(classtype);
@ -4158,7 +4172,7 @@ public:
/* constructor header */
{
String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1);
Printf(f_directors_h, " %s;\n", target);
Delete(target);
}
@ -4168,6 +4182,7 @@ public:
Delete(supername);
Delete(jenv_type);
Delete(parms);
Delete(dirclassname);
return Language::classDirectorConstructor(n);
}
@ -4178,16 +4193,18 @@ public:
int classDirectorDefaultConstructor(Node *n) {
String *classname = Swig_class_name(n);
String *classtype = SwigType_namestr(Getattr(n, "name"));
String *dirClassName = directorClassName(n);
Wrapper *w = NewWrapper();
Printf(w->def, "SwigDirector_%s::SwigDirector_%s(JNIEnv *jenv) : %s {", classname, classname, Getattr(n, "director:ctor"));
Printf(w->def, "%s::%s(JNIEnv *jenv) : %s {", dirClassName, dirClassName, Getattr(n, "director:ctor"));
Printf(w->code, "}\n");
Wrapper_print(w, f_directors);
Printf(f_directors_h, " SwigDirector_%s(JNIEnv *jenv);\n", classname);
Printf(f_directors_h, " %s(JNIEnv *jenv);\n", dirClassName);
DelWrapper(w);
Delete(classtype);
Delete(classname);
Delete(dirClassName);
directorPrefixArgs(n);
return Language::classDirectorDefaultConstructor(n);
}
@ -4224,14 +4241,15 @@ public:
Node *current_class = getCurrentClass();
String *full_classname = Getattr(current_class, "name");
String *classname = Swig_class_name(current_class);
String *dirClassName = directorClassName(current_class);
Wrapper *w = NewWrapper();
if (Getattr(n, "throw")) {
Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname);
Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname);
Printf(f_directors_h, " virtual ~%s() throw ();\n", dirClassName);
Printf(w->def, "%s::~%s() throw () {\n", dirClassName, dirClassName);
} else {
Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname);
Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname);
Printf(f_directors_h, " virtual ~%s();\n", dirClassName);
Printf(w->def, "%s::~%s() {\n", dirClassName, dirClassName);
}
/* Ensure that correct directordisconnect typemap's method name is called
@ -4250,6 +4268,7 @@ public:
DelWrapper(w);
Delete(disconn_attr);
Delete(classname);
Delete(dirClassName);
return SWIG_OK;
}
@ -4264,14 +4283,19 @@ public:
Wrapper *w = NewWrapper();
if (Len(package_path) > 0)
if (Len(getNSpace()) > 0)
internal_classname = NewStringf("%s/%s/%s", package_path, getNSpace(), classname);
else
internal_classname = NewStringf("%s/%s", package_path, classname);
if (Len(package_path) > 0 && Len(getNSpace()) > 0)
internal_classname = NewStringf("%s/%s/%s", package_path, getNSpace(), classname);
else if (Len(package_path) > 0)
internal_classname = NewStringf("%s/%s", package_path, classname);
else if (Len(getNSpace()) > 0)
internal_classname = NewStringf("%s/%s", getNSpace(), classname);
else
internal_classname = NewStringf("%s", classname);
// If the namespace is multiple levels, the result of getNSpace() will have inserted
// .'s to delimit namespaces, so we need to replace those with /'s
Replace(internal_classname, NSPACE_SEPARATOR, "/", DOH_REPLACE_ANY);
Wrapper_add_localv(w, "baseclass", "static jclass baseclass", "= 0", NIL);
Printf(w->def, "void %s::swig_connect_director(JNIEnv *jenv, jobject jself, jclass jcls, bool swig_mem_own, bool weak_global) {", director_classname);
@ -4320,12 +4344,30 @@ public:
Printf(w->code, " methods[i].base_methid = jenv->GetMethodID(baseclass, methods[i].mname, methods[i].mdesc);\n");
Printf(w->code, " if (!methods[i].base_methid) return;\n");
Printf(w->code, " }\n");
Printf(w->code, " swig_override[i] = false;\n");
Printf(w->code, " if (derived) {\n");
Printf(w->code, " jmethodID methid = jenv->GetMethodID(jcls, methods[i].mname, methods[i].mdesc);\n");
Printf(w->code, " swig_override[i] = (methid != methods[i].base_methid);\n");
Printf(w->code, " jenv->ExceptionClear();\n");
Printf(w->code, " }\n");
// Generally, derived classes have a mix of overridden and
// non-overridden methods and it is worth making a GetMethodID
// check during initialization to determine if each method is
// overridden, thus avoiding unnecessary calls into Java.
//
// On the other hand, when derived classes are
// expected to override all director methods then the
// GetMethodID calls are inefficient, and it is better to let
// the director unconditionally call up into Java. The resulting code
// will still behave correctly (though less efficiently) when Java
// code doesn't override a given method.
//
// The assumeoverride feature on a director controls whether or not
// overrides are assumed.
if (GetFlag(n, "feature:director:assumeoverride")) {
Printf(w->code, " swig_override[i] = derived;\n");
} else {
Printf(w->code, " swig_override[i] = false;\n");
Printf(w->code, " if (derived) {\n");
Printf(w->code, " jmethodID methid = jenv->GetMethodID(jcls, methods[i].mname, methods[i].mdesc);\n");
Printf(w->code, " swig_override[i] = (methid != methods[i].base_methid);\n");
Printf(w->code, " jenv->ExceptionClear();\n");
Printf(w->code, " }\n");
}
Printf(w->code, "}\n");
} else {
Printf(f_directors_h, "public:\n");
@ -4373,8 +4415,7 @@ public:
String *base = Getattr(n, "classtype");
String *class_ctor = NewString("Swig::Director(jenv)");
String *classname = Swig_class_name(n);
String *directorname = NewStringf("SwigDirector_%s", classname);
String *directorname = directorClassName(n);
String *declaration = Swig_class_declaration(n, directorname);
Printf(declaration, " : public %s, public Swig::Director", base);

View file

@ -11,8 +11,6 @@
* Language base class functions. Default C++ handling is also implemented here.
* ----------------------------------------------------------------------------- */
char cvsroot_lang_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
@ -90,7 +88,6 @@ extern int AddExtern;
* ---------------------------------------------------------------------- */
int Dispatcher::emit_one(Node *n) {
String *wrn;
int ret = SWIG_OK;
char *tag = Char(nodeType(n));
@ -106,10 +103,9 @@ int Dispatcher::emit_one(Node *n) {
return SWIG_OK;
/* Look for warnings */
wrn = Getattr(n, "feature:warnfilter");
if (wrn) {
String *wrn = Getattr(n, "feature:warnfilter");
if (wrn)
Swig_warnfilter(wrn, 1);
}
/* ============================================================
* C/C++ parsing
@ -183,9 +179,8 @@ int Dispatcher::emit_one(Node *n) {
Swig_error(input_file, line_number, "Unrecognized parse tree node type '%s'\n", tag);
ret = SWIG_ERROR;
}
if (wrn) {
if (wrn)
Swig_warnfilter(wrn, 0);
}
return ret;
}
@ -347,6 +342,27 @@ Language::~Language() {
this_ = 0;
}
/* -----------------------------------------------------------------------------
* directorClassName()
* ----------------------------------------------------------------------------- */
String *Language::directorClassName(Node *n) {
String *dirclassname;
String *nspace = NewString(Getattr(n, "sym:nspace"));
const char *attrib = "director:classname";
String *classname = Getattr(n, "sym:name");
Replace(nspace, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
if (Len(nspace) > 0)
dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname);
else
dirclassname = NewStringf("SwigDirector_%s", classname);
Setattr(n, attrib, dirclassname);
Delete(nspace);
return dirclassname;
}
/* ----------------------------------------------------------------------
emit_one()
---------------------------------------------------------------------- */
@ -834,14 +850,29 @@ int Language::cDeclaration(Node *n) {
File *f_header = 0;
SwigType *ty, *fullty;
if (Getattr(n, "feature:onlychildren")) {
if (GetFlag(n, "feature:ignore")) {
return SWIG_NOWRAP;
} else {
// Found an unignored templated method that has an empty template instantiation (%template())
// Ignore it unless it has been %rename'd
if (Strncmp(symname, "__dummy_", 8) == 0) {
SetFlag(n, "feature:ignore");
Swig_warning(WARN_LANG_TEMPLATE_METHOD_IGNORE, input_file, line_number,
"%%template() contains no name. Template method ignored: %s\n", Swig_name_decl(n));
return SWIG_NOWRAP;
}
}
}
/* discards nodes following the access control rules */
if (cplus_mode != PUBLIC || !is_public(n)) {
/* except for friends, they are not affected by access control */
int isfriend = storage && (Cmp(storage, "friend") == 0);
int isfriend = Cmp(storage, "friend") == 0;
if (!isfriend) {
/* Check what the director needs. If the method is pure virtual, it is always needed.
* Also wrap non-virtual protected members if asked for (allprotected mode). */
if (!(directorsEnabled() && ((is_member_director(CurrentClass, n) && need_nonpublic_member(n)) || is_non_virtual_protected_access(n)))) {
if (!(directorsEnabled() && ((is_member_director(CurrentClass, n) && need_nonpublic_member(n)) || isNonVirtualProtectedAccess(n)))) {
return SWIG_NOWRAP;
}
// Prevent wrapping protected overloaded director methods more than once -
@ -894,7 +925,7 @@ int Language::cDeclaration(Node *n) {
}
}
if (symname && !validIdentifier(symname)) {
if (!validIdentifier(symname)) {
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", symname);
return SWIG_NOWRAP;
}
@ -964,17 +995,9 @@ int Language::cDeclaration(Node *n) {
Delete(SwigType_pop_function(ty));
DohIncref(type);
Setattr(n, "type", ty);
if (GetFlag(n, "feature:onlychildren") && !GetFlag(n, "feature:ignore")) {
// Found an unignored templated method that has a an empty template instantiation (%template())
// Ignore it unless it has been %rename'd
if (Strncmp(symname, "__dummy_", 8) == 0) {
SetFlag(n, "feature:ignore");
Swig_warning(WARN_LANG_TEMPLATE_METHOD_IGNORE, input_file, line_number,
"%%template() contains no name. Template method ignored: %s\n", Swig_name_decl(n));
}
}
if (!GetFlag(n, "feature:ignore"))
functionHandler(n);
functionHandler(n);
Setattr(n, "type", type);
Delete(ty);
Delete(type);
@ -1127,22 +1150,15 @@ int Language::globalfunctionHandler(Node *n) {
int Language::callbackfunctionHandler(Node *n) {
Swig_require("callbackfunctionHandler", n, "name", "*sym:name", "*type", "?value", NIL);
String *symname = Getattr(n, "sym:name");
String *type = Getattr(n, "type");
String *name = Getattr(n, "name");
String *parms = Getattr(n, "parms");
String *cb = GetFlagAttr(n, "feature:callback");
String *cbname = Getattr(n, "feature:callback:name");
String *calltype = NewStringf("(%s (*)(%s))(%s)", SwigType_str(type, 0), ParmList_str(parms), SwigType_namestr(name));
SwigType *cbty = Copy(type);
SwigType_add_function(cbty, parms);
SwigType_add_pointer(cbty);
if (!cbname) {
cbname = NewStringf(cb, symname);
Setattr(n, "feature:callback:name", cbname);
}
Setattr(n, "sym:name", cbname);
Setattr(n, "type", cbty);
Setattr(n, "value", calltype);
@ -1151,7 +1167,6 @@ int Language::callbackfunctionHandler(Node *n) {
if (!ns)
constantWrapper(n);
Delete(cbname);
Delete(cbty);
Swig_restore(n);
@ -1224,7 +1239,7 @@ int Language::memberfunctionHandler(Node *n) {
// Set up the type for the cast to this class for use when wrapping const director (virtual) methods.
// Note: protected director methods or when allprotected mode turned on.
String *director_type = 0;
if (!is_public(n) && (is_member_director(CurrentClass, n) || GetFlag(n, "explicitcall") || is_non_virtual_protected_access(n))) {
if (!is_public(n) && (is_member_director(CurrentClass, n) || GetFlag(n, "explicitcall") || isNonVirtualProtectedAccess(n))) {
director_type = Copy(DirectorClassName);
String *qualifier = Getattr(n, "qualifier");
if (qualifier)
@ -1270,7 +1285,7 @@ int Language::staticmemberfunctionHandler(Node *n) {
if (!Extend) {
Node *sb = Getattr(n, "cplus:staticbase");
String *sname = Getattr(sb, "name");
if (is_non_virtual_protected_access(n))
if (isNonVirtualProtectedAccess(n))
cname = NewStringf("%s::%s", DirectorClassName, name);
else
cname = NewStringf("%s::%s", sname, name);
@ -1415,14 +1430,19 @@ int Language::membervariableHandler(Node *n) {
Delete(pname);
}
} else {
String *pname = is_non_virtual_protected_access(n) ? NewString("darg") : Swig_cparm_name(0, 0);
String *pname = isNonVirtualProtectedAccess(n) ? NewString("darg") : Swig_cparm_name(0, 0);
target = NewStringf("%s->%s", pname, name);
Delete(pname);
}
tm = Swig_typemap_lookup("memberin", n, target, 0);
// This is an input type typemap lookup and so it should not use Node n
// otherwise qualification is done on the parameter name for the setter function
Parm *nin = NewParm(type, name, n);
tm = Swig_typemap_lookup("memberin", nin, target, 0);
Delete(nin);
}
int flags = Extend | SmartPointer | use_naturalvar_mode(n);
if (is_non_virtual_protected_access(n))
if (isNonVirtualProtectedAccess(n))
flags = flags | CWRAP_ALL_PROTECTED_ACCESS;
Swig_MembersetToFunction(n, ClassType, flags);
@ -1470,7 +1490,7 @@ int Language::membervariableHandler(Node *n) {
/* Emit get function */
{
int flags = Extend | SmartPointer | use_naturalvar_mode(n);
if (is_non_virtual_protected_access(n))
if (isNonVirtualProtectedAccess(n))
flags = flags | CWRAP_ALL_PROTECTED_ACCESS;
Swig_MembergetToFunction(n, ClassType, flags);
Setattr(n, "sym:name", mrename_get);
@ -1530,7 +1550,7 @@ int Language::membervariableHandler(Node *n) {
int Language::staticmembervariableHandler(Node *n) {
Swig_require("staticmembervariableHandler", n, "*name", "*sym:name", "*type", "?value", NIL);
String *value = Getattr(n, "value");
String *classname = !SmartPointer ? (is_non_virtual_protected_access(n) ? DirectorClassName : ClassName) : Getattr(CurrentClass, "allocate:smartpointerbase");
String *classname = !SmartPointer ? (isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName) : Getattr(CurrentClass, "allocate:smartpointerbase");
if (!value || !Getattr(n, "hasconsttype")) {
String *name = Getattr(n, "name");
@ -1664,6 +1684,8 @@ int Language::enumvalueDeclaration(Node *n) {
int Language::enumforwardDeclaration(Node *n) {
(void) n;
if (GetFlag(n, "enumMissing"))
enumDeclaration(n); // Generate an empty enum in target language
return SWIG_OK;
}
@ -1693,7 +1715,7 @@ int Language::memberconstantHandler(Node *n) {
if (Extend)
new_name = Copy(value);
else
new_name = NewStringf("%s::%s", is_non_virtual_protected_access(n) ? DirectorClassName : ClassName, name);
new_name = NewStringf("%s::%s", isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName, name);
Setattr(n, "name", new_name);
constantWrapper(n);
@ -1970,6 +1992,9 @@ int Language::classDirectorConstructors(Node *n) {
for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {
nodeType = Getattr(ni, "nodeType");
if (Cmp(nodeType, "constructor") == 0) {
if (GetFlag(ni, "feature:ignore"))
continue;
Parm *parms = Getattr(ni, "parms");
if (is_public(ni)) {
/* emit public constructor */
@ -2035,14 +2060,23 @@ int Language::classDirectorMethods(Node *n) {
if (GetFlag(method, "feature:nodirector"))
continue;
String *wrn = Getattr(method, "feature:warnfilter");
if (wrn)
Swig_warnfilter(wrn, 1);
String *type = Getattr(method, "nodeType");
if (!Cmp(type, "destructor")) {
classDirectorDestructor(method);
} else {
if (classDirectorMethod(method, n, fqdname) == SWIG_OK) {
Setattr(item, "director", "1");
}
Swig_require("classDirectorMethods", method, "*type", NIL);
assert(Getattr(method, "returntype"));
Setattr(method, "type", Getattr(method, "returntype"));
if (classDirectorMethod(method, n, fqdname) == SWIG_OK)
SetFlag(item, "director");
Swig_restore(method);
}
if (wrn)
Swig_warnfilter(wrn, 0);
}
return SWIG_OK;
@ -2114,7 +2148,7 @@ int Language::classDirector(Node *n) {
Node *nodeType = Getattr(ni, "nodeType");
bool cdeclaration = (Cmp(nodeType, "cdecl") == 0);
if (cdeclaration && !GetFlag(ni, "feature:ignore")) {
if (is_non_virtual_protected_access(ni)) {
if (isNonVirtualProtectedAccess(ni)) {
Node *overloaded = Getattr(ni, "sym:overloaded");
// emit the using base::member statement (but only once if the method is overloaded)
if (!overloaded || (overloaded && (overloaded == ni)))
@ -2160,12 +2194,10 @@ static void addCopyConstructor(Node *n) {
String *cname = Getattr(n, "name");
SwigType *type = Copy(cname);
String *last = Swig_scopename_last(cname);
String *name = NewStringf("%s::%s", cname, last);
String *name = Swig_scopename_last(cname);
String *cc = NewStringf("r.q(const).%s", type);
String *decl = NewStringf("f(%s).", cc);
String *csymname = Getattr(n, "sym:name");
String *oldname = csymname;
String *oldname = Getattr(n, "sym:name");
if (Getattr(n, "allocate:has_constructor")) {
// to work properly with '%rename Class', we must look
@ -2186,11 +2218,8 @@ static void addCopyConstructor(Node *n) {
}
}
String *symname = Swig_name_make(cn, cname, last, decl, oldname);
String *symname = Swig_name_make(cn, cname, name, decl, oldname);
if (Strcmp(symname, "$ignore") != 0) {
if (!symname) {
symname = Copy(csymname);
}
Parm *p = NewParm(cc, "other", n);
Setattr(cn, "name", name);
@ -2203,8 +2232,8 @@ static void addCopyConstructor(Node *n) {
Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab"));
Node *on = Swig_symbol_add(symname, cn);
Swig_features_get(Swig_cparse_features(), Swig_symbol_qualifiedscopename(0), name, decl, cn);
Swig_symbol_setscope(oldscope);
Swig_features_get(Swig_cparse_features(), 0, name, decl, cn);
if (on == cn) {
Node *access = NewHash();
@ -2219,7 +2248,6 @@ static void addCopyConstructor(Node *n) {
}
}
Delete(cn);
Delete(last);
Delete(name);
Delete(decl);
Delete(symname);
@ -2233,28 +2261,21 @@ static void addDefaultConstructor(Node *n) {
Setline(cn, Getline(n));
String *cname = Getattr(n, "name");
String *last = Swig_scopename_last(cname);
String *name = NewStringf("%s::%s", cname, last);
String *name = Swig_scopename_last(cname);
String *decl = NewString("f().");
String *csymname = Getattr(n, "sym:name");
String *oldname = csymname;
String *symname = Swig_name_make(cn, cname, last, decl, oldname);
String *oldname = Getattr(n, "sym:name");
String *symname = Swig_name_make(cn, cname, name, decl, oldname);
if (Strcmp(symname, "$ignore") != 0) {
if (!symname) {
symname = Copy(csymname);
}
Setattr(cn, "name", name);
Setattr(cn, "sym:name", symname);
SetFlag(cn, "feature:new");
Setattr(cn, "decl", decl);
Setattr(cn, "parentNode", n);
Setattr(cn, "default_constructor", "1");
Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab"));
Node *on = Swig_symbol_add(symname, cn);
Swig_features_get(Swig_cparse_features(), Swig_symbol_qualifiedscopename(0), name, decl, cn);
Swig_symbol_setscope(oldscope);
Swig_features_get(Swig_cparse_features(), 0, name, decl, cn);
if (on == cn) {
Node *access = NewHash();
@ -2268,7 +2289,6 @@ static void addDefaultConstructor(Node *n) {
}
}
Delete(cn);
Delete(last);
Delete(name);
Delete(decl);
Delete(symname);
@ -2282,11 +2302,10 @@ static void addDestructor(Node *n) {
Setline(cn, Getline(n));
String *cname = Getattr(n, "name");
String *last = Swig_scopename_last(cname);
Insert(last, 0, "~");
String *name = NewStringf("%s::%s", cname, last);
String *name = Swig_scopename_last(cname);
Insert(name, 0, "~");
String *decl = NewString("f().");
String *symname = Swig_name_make(cn, cname, last, decl, 0);
String *symname = Swig_name_make(cn, cname, name, decl, 0);
if (Strcmp(symname, "$ignore") != 0) {
String *possible_nonstandard_symname = NewStringf("~%s", Getattr(n, "sym:name"));
@ -2298,8 +2317,8 @@ static void addDestructor(Node *n) {
Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab"));
Node *nonstandard_destructor = Equal(possible_nonstandard_symname, symname) ? 0 : Swig_symbol_clookup(possible_nonstandard_symname, 0);
Node *on = Swig_symbol_add(symname, cn);
Swig_features_get(Swig_cparse_features(), Swig_symbol_qualifiedscopename(0), name, decl, cn);
Swig_symbol_setscope(oldscope);
Swig_features_get(Swig_cparse_features(), 0, name, decl, cn);
if (on == cn) {
// SWIG accepts a non-standard named destructor in %extend that uses a typedef for the destructor name
@ -2319,7 +2338,6 @@ static void addDestructor(Node *n) {
Delete(possible_nonstandard_symname);
}
Delete(cn);
Delete(last);
Delete(name);
Delete(decl);
Delete(symname);
@ -2412,7 +2430,7 @@ int Language::classDeclaration(Node *n) {
}
if (dir) {
DirectorClassName = NewStringf("SwigDirector_%s", symname);
DirectorClassName = directorClassName(n);
classDirector(n);
}
/* check for abstract after resolving directors */
@ -2610,18 +2628,33 @@ int Language::constructorDeclaration(Node *n) {
}
} else {
String *expected_name = ClassName;
if (name && (!Equal(Swig_scopename_last(name), Swig_scopename_last(expected_name))) && !(Getattr(n, "template"))) {
String *scope = Swig_scopename_check(ClassName) ? Swig_scopename_prefix(ClassName) : 0;
String *actual_name = scope ? NewStringf("%s::%s", scope, name) : NewString(name);
Delete(scope);
if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) {
bool illegal_name = true;
if (Extend) {
// SWIG extension - allow typedef names as constructor name in %extend - an unnamed struct declared with a typedef can thus be given a 'constructor'.
SwigType *name_resolved = SwigType_typedef_resolve_all(name);
// Check for typedef names used as a constructor name in %extend. This is deprecated except for anonymous
// typedef structs which have had their symbol names adjusted to the typedef name in the parser.
SwigType *name_resolved = SwigType_typedef_resolve_all(actual_name);
SwigType *expected_name_resolved = SwigType_typedef_resolve_all(expected_name);
if (!CPlusPlus) {
if (Strncmp(name_resolved, "struct ", 7) == 0)
Replace(name_resolved, "struct ", "", DOH_REPLACE_FIRST);
else if (Strncmp(name_resolved, "union ", 6) == 0)
Replace(name_resolved, "union ", "", DOH_REPLACE_FIRST);
}
illegal_name = !Equal(name_resolved, expected_name_resolved);
if (!illegal_name)
Swig_warning(WARN_LANG_EXTEND_CONSTRUCTOR, input_file, line_number, "Use of an illegal constructor name '%s' in %%extend is deprecated, the constructor name should be '%s'.\n",
SwigType_str(Swig_scopename_last(actual_name), 0), SwigType_str(Swig_scopename_last(expected_name), 0));
Delete(name_resolved);
Delete(expected_name_resolved);
}
if (illegal_name) {
Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type. Ignored.\n", SwigType_namestr(name));
Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type. Ignored.\n", Swig_name_decl(n));
Swig_restore(n);
return SWIG_NOWRAP;
}
@ -2639,23 +2672,25 @@ int Language::constructorDeclaration(Node *n) {
* get_director_ctor_code()
* ---------------------------------------------------------------------- */
static String *get_director_ctor_code(Node *n, String *director_ctor_code, String *director_prot_ctor_code, List *&abstract) {
static String *get_director_ctor_code(Node *n, String *director_ctor_code, String *director_prot_ctor_code, List *&abstracts) {
String *director_ctor = director_ctor_code;
int use_director = Swig_directorclass(n);
if (use_director) {
Node *pn = Swig_methodclass(n);
abstract = Getattr(pn, "abstract");
abstracts = Getattr(pn, "abstracts");
if (director_prot_ctor_code) {
int is_notabstract = GetFlag(pn, "feature:notabstract");
int is_abstract = abstract && !is_notabstract;
int is_abstract = abstracts && !is_notabstract;
if (is_protected(n) || is_abstract) {
director_ctor = director_prot_ctor_code;
Delattr(pn, "abstract");
abstracts = Copy(abstracts);
Delattr(pn, "abstracts");
} else {
if (is_notabstract) {
Delattr(pn, "abstract");
abstracts = Copy(abstracts);
Delattr(pn, "abstracts");
} else {
abstract = 0;
abstracts = 0;
}
}
}
@ -2674,10 +2709,10 @@ int Language::constructorHandler(Node *n) {
String *mrename = Swig_name_construct(NSpace, symname);
String *nodeType = Getattr(n, "nodeType");
int constructor = (!Cmp(nodeType, "constructor"));
List *abstract = 0;
List *abstracts = 0;
String *director_ctor = get_director_ctor_code(n, director_ctor_code,
director_prot_ctor_code,
abstract);
abstracts);
if (!constructor) {
/* if not originally a constructor, still handle it as one */
Setattr(n, "handled_as_constructor", "1");
@ -2688,8 +2723,8 @@ int Language::constructorHandler(Node *n) {
functionWrapper(n);
Delete(mrename);
Swig_restore(n);
if (abstract)
Setattr(Swig_methodclass(n), "abstract", abstract);
if (abstracts)
Setattr(Swig_methodclass(n), "abstracts", abstracts);
return SWIG_OK;
}
@ -2701,17 +2736,17 @@ int Language::copyconstructorHandler(Node *n) {
Swig_require("copyconstructorHandler", n, "?name", "*sym:name", "?type", "?parms", NIL);
String *symname = Getattr(n, "sym:name");
String *mrename = Swig_name_copyconstructor(NSpace, symname);
List *abstract = 0;
List *abstracts = 0;
String *director_ctor = get_director_ctor_code(n, director_ctor_code,
director_prot_ctor_code,
abstract);
abstracts);
Swig_ConstructorToFunction(n, NSpace, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend);
Setattr(n, "sym:name", mrename);
functionWrapper(n);
Delete(mrename);
Swig_restore(n);
if (abstract)
Setattr(Swig_methodclass(n), "abstract", abstract);
if (abstracts)
Setattr(Swig_methodclass(n), "abstracts", abstracts);
return SWIG_OK;
}
@ -2742,25 +2777,37 @@ int Language::destructorDeclaration(Node *n) {
Setattr(n, "sym:name", ClassPrefix);
}
String *expected_name = NewString(ClassName);
Replace(expected_name, "~", "", DOH_REPLACE_FIRST);
String *actual_name = NewString(name);
String *expected_name = ClassName;
String *scope = Swig_scopename_check(ClassName) ? Swig_scopename_prefix(ClassName) : 0;
String *actual_name = scope ? NewStringf("%s::%s", scope, name) : NewString(name);
Delete(scope);
Replace(actual_name, "~", "", DOH_REPLACE_FIRST);
if (name && (!Equal(Swig_scopename_last(actual_name), Swig_scopename_last(expected_name))) && !(Getattr(n, "template"))) {
if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) {
bool illegal_name = true;
if (Extend) {
// SWIG extension - allow typedef names as destructor name in %extend - an unnamed struct declared with a typedef can thus be given a 'destructor'.
// Check for typedef names used as a destructor name in %extend. This is deprecated except for anonymous
// typedef structs which have had their symbol names adjusted to the typedef name in the parser.
SwigType *name_resolved = SwigType_typedef_resolve_all(actual_name);
SwigType *expected_name_resolved = SwigType_typedef_resolve_all(expected_name);
if (!CPlusPlus) {
if (Strncmp(name_resolved, "struct ", 7) == 0)
Replace(name_resolved, "struct ", "", DOH_REPLACE_FIRST);
else if (Strncmp(name_resolved, "union ", 6) == 0)
Replace(name_resolved, "union ", "", DOH_REPLACE_FIRST);
}
illegal_name = !Equal(name_resolved, expected_name_resolved);
if (!illegal_name)
Swig_warning(WARN_LANG_EXTEND_DESTRUCTOR, input_file, line_number, "Use of an illegal destructor name '%s' in %%extend is deprecated, the destructor name should be '%s'.\n",
SwigType_str(Swig_scopename_last(actual_name), 0), SwigType_str(Swig_scopename_last(expected_name), 0));
Delete(name_resolved);
Delete(expected_name_resolved);
}
if (illegal_name) {
Swig_warning(WARN_LANG_ILLEGAL_DESTRUCTOR, input_file, line_number, "Illegal destructor name %s. Ignored.\n", SwigType_namestr(name));
Swig_warning(WARN_LANG_ILLEGAL_DESTRUCTOR, input_file, line_number, "Illegal destructor name %s. Ignored.\n", Swig_name_decl(n));
Swig_restore(n);
Delete(expected_name);
return SWIG_NOWRAP;
}
}
@ -2768,7 +2815,6 @@ int Language::destructorDeclaration(Node *n) {
Setattr(CurrentClass, "has_destructor", "1");
Swig_restore(n);
Delete(expected_name);
return SWIG_OK;
}
@ -2783,7 +2829,7 @@ int Language::destructorHandler(Node *n) {
String *symname = Getattr(n, "sym:name");
String *mrename;
char *csymname = Char(symname);
if (csymname && (*csymname == '~'))
if (*csymname == '~')
csymname += 1;
mrename = Swig_name_destroy(NSpace, csymname);
@ -2987,8 +3033,8 @@ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr
} else {
Node *c = Getattr(symbols, s);
if (c && (c != n)) {
if (scope)
Swig_error(input_file, line_number, "'%s' is multiply defined in the generated target language module in scope %s.\n", s, scope);
if (scope && Len(scope) > 0)
Swig_error(input_file, line_number, "'%s' is multiply defined in the generated target language module in scope '%s'.\n", s, scope);
else
Swig_error(input_file, line_number, "'%s' is multiply defined in the generated target language module.\n", s);
Swig_error(Getfile(c), Getline(c), "Previous declaration of '%s'\n", s);
@ -3156,7 +3202,9 @@ Node *Language::enumLookup(SwigType *s) {
n = Swig_symbol_clookup(base, stab);
if (!n)
break;
if (Strcmp(nodeType(n), "enum") == 0)
if (Equal(nodeType(n), "enum"))
break;
if (Equal(nodeType(n), "enumforward") && GetFlag(n, "enumMissing"))
break;
n = parentNode(n);
if (!n)
@ -3327,7 +3375,7 @@ int Language::need_nonpublic_ctor(Node *n) {
* Language::need_nonpublic_member()
* ----------------------------------------------------------------------------- */
int Language::need_nonpublic_member(Node *n) {
if (directorsEnabled()) {
if (directorsEnabled() && DirectorClassName) {
if (is_protected(n)) {
if (dirprot_mode()) {
/* when using dirprot mode, the protected members are always needed. */
@ -3351,6 +3399,16 @@ int Language::is_smart_pointer() const {
return SmartPointer;
}
/* -----------------------------------------------------------------------------
* Language::()
* ----------------------------------------------------------------------------- */
bool Language::isNonVirtualProtectedAccess(Node *n) const {
// Ideally is_non_virtual_protected_access() would contain all this logic, see
// comments therein about vtable.
return DirectorClassName && is_non_virtual_protected_access(n);
}
/* -----------------------------------------------------------------------------
* Language::extraDirectorProtectedCPPMethodsRequired()
* ----------------------------------------------------------------------------- */
@ -3418,17 +3476,17 @@ int Language::abstractClassTest(Node *n) {
if (Getattr(n, "allocate:nonew"))
return 1;
/* now check for the rest */
List *abstract = Getattr(n, "abstract");
if (!abstract)
List *abstracts = Getattr(n, "abstracts");
if (!abstracts)
return 0;
int labs = Len(abstract);
int labs = Len(abstracts);
#ifdef SWIG_DEBUG
List *bases = Getattr(n, "allbases");
Printf(stderr, "testing %s %d %d\n", Getattr(n, "name"), labs, Len(bases));
#endif
if (!labs)
return 0; /*strange, but need to be fixed */
if (abstract && !directorsEnabled())
if (abstracts && !directorsEnabled())
return 1;
if (!GetFlag(n, "feature:director"))
return 1;
@ -3440,7 +3498,7 @@ int Language::abstractClassTest(Node *n) {
Printf(stderr, "vtable %s %d %d\n", Getattr(n, "name"), Len(vtable), labs);
#endif
for (int i = 0; i < labs; i++) {
Node *ni = Getitem(abstract, i);
Node *ni = Getitem(abstracts, i);
Node *method_id = vtable_method_id(ni);
if (!method_id)
continue;
@ -3477,7 +3535,7 @@ int Language::abstractClassTest(Node *n) {
} else {
return 1;
}
return dirabstract ? 1 : 0;
return 0;
}
void Language::setSubclassInstanceCheck(String *nc) {

View file

@ -44,8 +44,6 @@
Added support for embedded Lua. Try swig -lua -help for more information
*/
char cvsroot_lua_cxx[] = "$Id$";
#include "swigmod.h"
/**** Diagnostics:
@ -62,7 +60,7 @@ char cvsroot_lua_cxx[] = "$Id$";
void display_mapping(DOH *d) {
if (d == 0 || !DohIsMapping(d))
return;
for (DohIterator it = DohFirst(d); it.item; it = DohNext(it)) {
for (Iterator it = First(d); it.item; it = Next(it)) {
if (DohIsString(it.item))
Printf(stdout, " %s = %s\n", it.key, it.item);
else if (DohIsMapping(it.item))
@ -108,12 +106,11 @@ private:
File *f_wrappers;
File *f_init;
File *f_initbeforefunc;
String *PrefixPlusUnderscore;
String *s_cmd_tab; // table of command names
String *s_var_tab; // table of global variables
String *s_const_tab; // table of global constants
String *s_methods_tab; // table of class methods
String *s_attr_tab; // table of class atributes
String *s_attr_tab; // table of class attributes
String *s_luacode; // luacode to be called during init
String *s_dot_get; // table of variable 'get' functions
String *s_dot_set; // table of variable 'set' functions
@ -145,17 +142,28 @@ public:
* Initialize member data
* --------------------------------------------------------------------- */
LUA() {
f_begin = 0;
f_runtime = 0;
f_header = 0;
f_wrappers = 0;
f_init = 0;
f_initbeforefunc = 0;
PrefixPlusUnderscore = 0;
s_cmd_tab = s_var_tab = s_const_tab = s_luacode = 0;
current=NO_CPP;
LUA() :
f_begin(0),
f_runtime(0),
f_header(0),
f_wrappers(0),
f_init(0),
f_initbeforefunc(0),
s_cmd_tab(0),
s_var_tab(0),
s_const_tab(0),
s_methods_tab(0),
s_attr_tab(0),
s_luacode(0),
s_dot_get(0),
s_dot_set(0),
s_vars_meta_tab(0),
have_constructor(0),
have_destructor(0),
destructor_action(0),
class_name(0),
constructor_name(0),
current(NO_CPP) {
}
/* NEW LANGUAGE NOTE:***********************************************
@ -284,12 +292,7 @@ public:
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGLUA\n");
if (elua_ltr)
Printf(f_runtime, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUA\n");
else if (eluac_ltr)
Printf(f_runtime, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUAC\n");
else
Printf(f_runtime, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_LUA\n");
emitLuaFlavor(f_runtime);
if (nomoduleglobal) {
Printf(f_runtime, "#define SWIG_LUA_NO_MODULE_GLOBAL\n");
@ -401,7 +404,6 @@ public:
Delete(f_wrappers);
Delete(f_init);
Delete(f_initbeforefunc);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
Delete(s_dot_get);
@ -1269,6 +1271,9 @@ public:
String *runtimeCode() {
String *s = NewString("");
const char *filenames[] = { "luarun.swg", 0 } ; // must be 0 terminated
emitLuaFlavor(s);
String *sfile;
for (int i = 0; filenames[i] != 0; i++) {
sfile = Swig_include_sys(filenames[i]);
@ -1279,6 +1284,7 @@ public:
Delete(sfile);
}
}
return s;
}
@ -1290,6 +1296,16 @@ public:
* helpers
* --------------------------------------------------------------------- */
void emitLuaFlavor(String *s) {
if (elua_ltr)
Printf(s, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUA\n");
else if (eluac_ltr)
Printf(s, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_ELUAC\n");
else
Printf(s, "#define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_LUA\n");
}
/* This is to convert the string of Lua code into a proper string, which can then be
emitted into the C/C++ code.
Basically is is a lot of search & replacing of odd sequences

View file

@ -11,8 +11,6 @@
* Main entry point to the SWIG core.
* ----------------------------------------------------------------------------- */
char cvsroot_main_cxx[] = "$Id$";
#include "swigconfig.h"
#if defined(_WIN32)
@ -109,6 +107,7 @@ static const char *usage2 = (const char *) "\
-MM - List dependencies, but omit files in SWIG library\n\
-MMD - Like `-MD', but omit files in SWIG library\n\
-module <name> - Set module name to <name>\n\
-MP - Generate phony targets for all dependencies\n\
-MT <target> - Set the target of the rule emitted by dependency generation\n\
-nocontract - Turn off contract checking\n\
-nocpperraswarn - Do not treat the preprocessor #error statement as #warning\n\
@ -187,6 +186,7 @@ static int dump_classes = 0;
static int werror = 0;
static int depend = 0;
static int depend_only = 0;
static int depend_phony = 0;
static int memory_debug = 0;
static int allkw = 0;
static DOH *cpps = 0;
@ -199,22 +199,24 @@ static List *libfiles = 0;
static List *all_output_files = 0;
/* -----------------------------------------------------------------------------
* check_suffix()
* check_extension()
*
* Checks the suffix of a file to see if we should emit extern declarations.
* Checks the extension of a file to see if we should emit extern declarations.
* ----------------------------------------------------------------------------- */
static int check_suffix(String *filename) {
static bool check_extension(String *filename) {
bool wanted = false;
const char *name = Char(filename);
const char *c;
if (!name)
return 0;
c = Swig_file_suffix(name);
String *extension = Swig_file_extension(name);
const char *c = Char(extension);
if ((strcmp(c, ".c") == 0) ||
(strcmp(c, ".C") == 0) || (strcmp(c, ".cc") == 0) || (strcmp(c, ".cxx") == 0) || (strcmp(c, ".c++") == 0) || (strcmp(c, ".cpp") == 0)) {
return 1;
wanted = true;
}
return 0;
Delete(extension);
return wanted;
}
/* -----------------------------------------------------------------------------
@ -283,15 +285,16 @@ static unsigned int decode_numbers_list(String *numlist) {
}
/* -----------------------------------------------------------------------------
* Sets the output directory for language specific (proxy) files if not set and
* corrects the directory name and adds trailing file separator if necessary.
* Sets the output directory for language specific (proxy) files from the
* C wrapper file if not set and corrects the directory name and adds a trailing
* file separator if necessary.
* ----------------------------------------------------------------------------- */
static void configure_outdir(const String *c_wrapper_file_dir) {
static void configure_outdir(const String *c_wrapper_outfile) {
// Use the C wrapper file's directory if the output directory has not been set by user
if (!outdir || Len(outdir) == 0)
outdir = NewString(c_wrapper_file_dir);
outdir = Swig_file_dirname(c_wrapper_outfile);
Swig_filename_correct(outdir);
@ -403,7 +406,7 @@ static void SWIG_dump_runtime() {
s = Swig_include_sys("swiglabels.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'swiglabels.swg'\n");
Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_FAILURE);
}
Printf(runtime, "%s", s);
@ -412,7 +415,7 @@ static void SWIG_dump_runtime() {
s = Swig_include_sys("swigerrors.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'swigerrors.swg'\n");
Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_FAILURE);
}
Printf(runtime, "%s", s);
@ -421,7 +424,7 @@ static void SWIG_dump_runtime() {
s = Swig_include_sys("swigrun.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'swigrun.swg'\n");
Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_FAILURE);
}
Printf(runtime, "%s", s);
@ -434,13 +437,12 @@ static void SWIG_dump_runtime() {
s = Swig_include_sys("runtime.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'runtime.swg'\n");
Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_FAILURE);
}
Printf(runtime, "%s", s);
Delete(s);
Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_SUCCESS);
}
@ -712,6 +714,9 @@ void SWIG_getoptions(int argc, char *argv[]) {
} else if (strcmp(argv[i], "-MMD") == 0) {
depend = 2;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-MP") == 0) {
depend_phony = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-MT") == 0) {
Swig_mark_arg(i);
if (argv[i + 1]) {
@ -1009,7 +1014,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (Verbose)
Printf(stdout, "'%s' checked out from the SWIG library.\n", outfile);
Printv(f_outfile, s, NIL);
Close(f_outfile);
Delete(f_outfile);
}
}
}
@ -1069,7 +1074,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
String *outfile;
File *f_dependencies_file = 0;
char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(input_file): Char(input_file));
String *inputfile_filename = outcurrentdir ? Swig_file_filename(input_file): Copy(input_file);
String *basename = Swig_file_basename(inputfile_filename);
if (!outfile_name) {
if (CPlusPlus || lang->cplus_runtime_mode()) {
outfile = NewStringf("%s_wrap.%s", basename, cpp_extension);
@ -1100,20 +1106,33 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Printf(f_dependencies_file, "%s: ", outfile);
}
List *files = Preprocessor_depend();
List *phony_targets = NewList();
for (int i = 0; i < Len(files); i++) {
int use_file = 1;
if (depend == 2) {
if ((Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) == 0) || (SwigLibWinUnix && (Strncmp(Getitem(files, i), SwigLibWinUnix, Len(SwigLibWinUnix)) == 0)))
use_file = 0;
}
if (use_file)
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
if (use_file) {
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
if (depend_phony)
Append(phony_targets, Getitem(files, i));
}
}
Printf(f_dependencies_file, "\n");
if (depend_phony) {
for (int i = 0; i < Len(phony_targets); i++) {
Printf(f_dependencies_file, "\n%s:\n", Getitem(phony_targets, i));
}
}
if (f_dependencies_file != stdout)
Close(f_dependencies_file);
Delete(f_dependencies_file);
if (depend_only)
SWIG_exit(EXIT_SUCCESS);
Delete(inputfile_filename);
Delete(basename);
Delete(phony_targets);
} else {
Printf(stderr, "Cannot generate dependencies with -nopreprocess\n");
// Actually we could but it would be inefficient when just generating dependencies, as it would be done after Swig_cparse
@ -1221,7 +1240,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Setattr(top, "infile", infile); // Note: if nopreprocess then infile is the original input file, otherwise input_file
Setattr(top, "inputfile", input_file);
char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(infile): Char(infile));
String *infile_filename = outcurrentdir ? Swig_file_filename(infile): Copy(infile);
String *basename = Swig_file_basename(infile_filename);
if (!outfile_name) {
if (CPlusPlus || lang->cplus_runtime_mode()) {
Setattr(top, "outfile", NewStringf("%s_wrap.%s", basename, cpp_extension));
@ -1236,19 +1256,21 @@ int SWIG_main(int argc, char *argv[], Language *l) {
} else {
Setattr(top, "outfile_h", outfile_name_h);
}
configure_outdir(Swig_file_dirname(Getattr(top, "outfile")));
configure_outdir(Getattr(top, "outfile"));
if (Swig_contract_mode_get()) {
Swig_contracts(top);
}
// Check the suffix for a c/c++ file. If so, we're going to declare everything we see as "extern"
ForceExtern = check_suffix(input_file);
// Check the extension for a c/c++ file. If so, we're going to declare everything we see as "extern"
ForceExtern = check_extension(input_file);
lang->top(top);
if (browse) {
Swig_browser(top, 0);
}
Delete(infile_filename);
Delete(basename);
}
}
if (dump_lang_symbols) {
@ -1285,7 +1307,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
int i;
for (i = 0; i < Len(all_output_files); i++)
Printf(f_outfiles, "%s\n", Getitem(all_output_files, i));
Close(f_outfiles);
Delete(f_outfiles);
}
}

View file

@ -11,8 +11,6 @@
* Modula3 language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_modula3_cxx[] = "$Id$";
/*
Text formatted with
indent -sob -br -ce -nut -npsl
@ -206,9 +204,6 @@ private:
String *proxy_class_name;
String *variable_name; //Name of a variable being wrapped
String *variable_type; //Type of this variable
String *enumeration_name; //Name of the current enumeration type
Hash *enumeration_items; //and its members
int enumeration_max;
Hash *enumeration_coll; //Collection of all enumerations.
/* The items are nodes with members:
"items" - hash of with key 'itemname' and content 'itemvalue'
@ -270,9 +265,6 @@ MODULA3():
proxy_class_name(NULL),
variable_name(NULL),
variable_type(NULL),
enumeration_name(NULL),
enumeration_items(NULL),
enumeration_max(0),
enumeration_coll(NULL),
constant_values(NULL),
constantfilename(NULL),
@ -835,7 +827,7 @@ MODULA3():
scanConstant(file, n);
Printf(file, " return 0;\n");
Printf(file, "}\n");
Close(file);
Delete(file);
return SWIG_OK;
}
@ -870,7 +862,7 @@ MODULA3():
by SWIG with option -generaterename. */\n\
\n", input_file);
scanRename(file, n);
Close(file);
Delete(file);
return SWIG_OK;
}
@ -900,7 +892,7 @@ MODULA3():
by SWIG with option -generatetypemap. */\n\
\n", input_file);
scanTypemap(file, n);
Close(file);
Delete(file);
return SWIG_OK;
}
@ -991,7 +983,7 @@ MODULA3():
// Generate m3makefile
// This will be unnecessary if SWIG is invoked from Quake.
{
File *file = openWriteFile(NewStringf("%sm3makefile", Swig_file_dirname(outfile)));
File *file = openWriteFile(NewStringf("%sm3makefile", SWIG_output_directory()));
Printf(file, "%% automatically generated quake file for %s\n\n", name);
@ -1009,12 +1001,12 @@ MODULA3():
} else {
Printf(file, "library(\"m3%s\")\n", name);
}
Close(file);
Delete(file);
}
// Generate the raw interface
{
File *file = openWriteFile(NewStringf("%s%s.i3", Swig_file_dirname(outfile), m3raw_name));
File *file = openWriteFile(NewStringf("%s%s.i3", SWIG_output_directory(), m3raw_name));
emitBanner(file);
@ -1027,12 +1019,12 @@ MODULA3():
Printv(file, m3raw_intf.f, NIL);
Printf(file, "\nEND %s.\n", m3raw_name);
Close(file);
Delete(file);
}
// Generate the raw module
{
File *file = openWriteFile(NewStringf("%s%s.m3", Swig_file_dirname(outfile), m3raw_name));
File *file = openWriteFile(NewStringf("%s%s.m3", SWIG_output_directory(), m3raw_name));
emitBanner(file);
@ -1045,12 +1037,12 @@ MODULA3():
Printv(file, m3raw_impl.f, NIL);
Printf(file, "BEGIN\nEND %s.\n", m3raw_name);
Close(file);
Delete(file);
}
// Generate the interface for the comfort wrappers
{
File *file = openWriteFile(NewStringf("%s%s.i3", Swig_file_dirname(outfile), m3wrap_name));
File *file = openWriteFile(NewStringf("%s%s.i3", SWIG_output_directory(), m3wrap_name));
emitBanner(file);
@ -1075,12 +1067,12 @@ MODULA3():
// Finish off the class
Printf(file, "\nEND %s.\n", m3wrap_name);
Close(file);
Delete(file);
}
// Generate the wrapper routines implemented in Modula 3
{
File *file = openWriteFile(NewStringf("%s%s.m3", Swig_file_dirname(outfile), m3wrap_name));
File *file = openWriteFile(NewStringf("%s%s.m3", SWIG_output_directory(), m3wrap_name));
emitBanner(file);
@ -1096,7 +1088,7 @@ MODULA3():
Printv(file, m3wrap_impl.f, NIL);
Printf(file, "\nBEGIN\nEND %s.\n", m3wrap_name);
Close(file);
Delete(file);
}
if (upcasts_code)
@ -1162,7 +1154,6 @@ MODULA3():
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -1787,19 +1778,6 @@ MODULA3():
}
}
#if 0
void generateEnumerationItem(const String *name, const String *value, int numvalue) {
String *oldsymname = Getattr(enumeration_items, value);
if (oldsymname != NIL) {
Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "The value <%s> is already assigned to <%s>.\n", value, oldsymname);
}
Setattr(enumeration_items, value, name);
if (enumeration_max < numvalue) {
enumeration_max = numvalue;
}
}
#endif
void emitEnumeration(File *file, String *name, Node *n) {
Printf(file, "%s = {", name);
int i;
@ -2030,7 +2008,7 @@ MODULA3():
if (oldname != NIL) {
Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "The value <%s> is already assigned to <%s>.\n", value, oldname);
}
//printf("items %lx, set %s = %s\n", (long) items, Char(newvalue), Char(m3name));
//printf("items %p, set %s = %s\n", items, Char(newvalue), Char(m3name));
Setattr(items, newvalue, m3name);
if (max < numvalue) {
max = numvalue;
@ -2097,7 +2075,7 @@ MODULA3():
stem += Len(pat.prefix);
}
String *newname;
if (Strcmp(srcstyle, "underscore") == 0) {
if (srcstyle && Strcmp(srcstyle, "underscore") == 0) {
if (newprefix != NIL) {
String *newstem = nameToModula3(stem, true);
newname = NewStringf("%s%s", newprefix, newstem);
@ -2215,16 +2193,18 @@ MODULA3():
List *baselist = Getattr(n, "bases");
if (baselist != NIL) {
Iterator base = First(baselist);
c_baseclassname = Getattr(base.item, "name");
baseclass = Copy(getProxyName(c_baseclassname));
if (baseclass) {
c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
}
base = Next(base);
if (base.item != NIL) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n",
name, Getattr(base.item, "name"));
if (base.item) {
c_baseclassname = Getattr(base.item, "name");
baseclass = Copy(getProxyName(c_baseclassname));
if (baseclass) {
c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
}
base = Next(base);
if (base.item != NIL) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n",
name, Getattr(base.item, "name"));
}
}
}
@ -2388,7 +2368,7 @@ MODULA3():
SWIG_exit(EXIT_FAILURE);
}
String *filen = NewStringf("%s%s.m3", Swig_file_dirname(outfile), proxy_class_name);
String *filen = NewStringf("%s%s.m3", SWIG_output_directory(), proxy_class_name);
f_proxy = NewFile(filen, "w", SWIG_output_files());
if (!f_proxy) {
FileErrorDisplay(filen);
@ -2461,12 +2441,14 @@ MODULA3():
/* Look for the first (principal?) base class -
Modula 3 does not support multiple inheritance */
Iterator base = First(baselist);
Append(baseclassname, Getattr(base.item, "sym:name"));
base = Next(base);
if (base.item != NIL) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n",
proxy_class_name, Getattr(base.item, "name"));
if (base.item) {
Append(baseclassname, Getattr(base.item, "sym:name"));
base = Next(base);
if (base.item) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n",
proxy_class_name, Getattr(base.item, "name"));
}
}
}
}
@ -2555,7 +2537,7 @@ MODULA3():
Printv(f_proxy, proxy_class_def, proxy_class_code, NIL);
Printf(f_proxy, "}\n");
Close(f_proxy);
Delete(f_proxy);
f_proxy = NULL;
Delete(proxy_class_name);
@ -3528,6 +3510,7 @@ MODULA3():
m3wrap_impl.enterBlock(no_block);
if (proxy_flag && global_variable_flag) {
setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(NSPACE_TODO, variable_name)) == 0);
// Properties
if (setter_flag) {
// Setter method
@ -3781,7 +3764,7 @@ MODULA3():
Setfile(n, input_file);
Setline(n, line_number);
String *filen = NewStringf("%s%s.m3", Swig_file_dirname(outfile), classname);
String *filen = NewStringf("%s%s.m3", SWIG_output_directory(), classname);
File *f_swigtype = NewFile(filen, "w", SWIG_output_files());
if (!f_swigtype) {
FileErrorDisplay(filen);
@ -3811,7 +3794,7 @@ MODULA3():
Replaceall(swigtype, "$m3classname", classname);
Printv(f_swigtype, swigtype, NIL);
Close(f_swigtype);
Delete(f_swigtype);
Delete(filen);
Delete(swigtype);
}

View file

@ -11,8 +11,6 @@
* This file is responsible for the module system.
* ----------------------------------------------------------------------------- */
char cvsroot_module_cxx[] = "$Id$";
#include "swigmod.h"
struct Module {

View file

@ -11,8 +11,6 @@
* Mzscheme language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_mzscheme_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
@ -33,12 +31,10 @@ static String *convert_proto_tab = 0;
static String *struct_name = 0;
static String *mangled_struct_name = 0;
static char *prefix = 0;
static String *prefix = 0;
static bool declaremodule = false;
static bool noinit = false;
//DLOPEN PATCH
static char *load_libraries = NULL;
//DLOPEN PATCH
static String *load_libraries = NULL;
static String *module = 0;
static char *mzscheme_path = (char *) "mzscheme";
static String *init_func_def = 0;
@ -75,8 +71,7 @@ public:
SWIG_exit(0);
} else if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) {
prefix = new char[strlen(argv[i + 1]) + 2];
strcpy(prefix, argv[i + 1]);
prefix = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
@ -90,26 +85,26 @@ public:
noinit = true;
Swig_mark_arg(i);
}
// DLOPEN PATCH
else if (strcmp(argv[i], "-dynamic-load") == 0) {
load_libraries = new char[strlen(argv[i + 1]) + 2];
strcpy(load_libraries, argv[i + 1]);
Swig_mark_arg(i++);
Swig_mark_arg(i);
if (argv[i + 1]) {
Delete(load_libraries);
load_libraries = NewString(argv[i + 1]);
Swig_mark_arg(i++);
Swig_mark_arg(i);
} else {
Swig_arg_error();
}
}
// DLOPEN PATCH
}
}
// If a prefix has been specified make sure it ends in a '_'
// If a prefix has been specified make sure it ends in a '_' (not actually used!)
if (prefix) {
if (prefix[strlen(prefix)] != '_') {
prefix[strlen(prefix) + 1] = 0;
prefix[strlen(prefix)] = '_';
}
const char *px = Char(prefix);
if (px[Len(prefix) - 1] != '_')
Printf(prefix, "_");
} else
prefix = (char *) "swig_";
prefix = NewString("swig_");
// Add a symbol for this module
@ -177,11 +172,9 @@ public:
Printf(f_init, "\treturn scheme_void;\n}\n");
Printf(f_init, "Scheme_Object *scheme_initialize(Scheme_Env *env) {\n");
// DLOPEN PATCH
if (load_libraries) {
Printf(f_init, "mz_set_dlopen_libraries(\"%s\");\n", load_libraries);
}
// DLOPEN PATCH
Printf(f_init, "\treturn scheme_reload(env);\n");
Printf(f_init, "}\n");
@ -203,7 +196,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -245,14 +237,12 @@ public:
int numreq;
String *overname = 0;
// PATCH DLOPEN
if (load_libraries) {
ParmList *parms = Getattr(n, "parms");
SwigType *type = Getattr(n, "type");
String *name = NewString("caller");
Setattr(n, "wrap:action", Swig_cresult(type, Swig_cresult_name(), Swig_cfunction_call(name, parms)));
}
// PATCH DLOPEN
// Make a wrapper name for this
String *wname = Swig_name_wrapper(iname);
@ -292,7 +282,6 @@ public:
numargs = emit_num_arguments(l);
numreq = emit_num_required(l);
// DLOPEN PATCH
/* Add the holder for the pointer to the function to be opened */
if (load_libraries) {
Wrapper_add_local(f, "_function_loaded", "static int _function_loaded=(1==0)");
@ -303,19 +292,16 @@ public:
Wrapper_add_local(f, "caller", SwigType_lstr(d, func)); /*"(*caller)()")); */
}
}
// DLOPEN PATCH
// adds local variables
Wrapper_add_local(f, "lenv", "int lenv = 1");
Wrapper_add_local(f, "values", "Scheme_Object *values[MAXVALUES]");
// DLOPEN PATCH
if (load_libraries) {
Printf(f->code, "if (!_function_loaded) { _the_function=mz_load_function(\"%s\");_function_loaded=(1==1); }\n", iname);
Printf(f->code, "if (!_the_function) { scheme_signal_error(\"Cannot load C function '%s'\"); }\n", iname);
Printf(f->code, "caller=_the_function;\n");
}
// DLOPEN PATCH
// Now write code to extract the parameters (this is super ugly)

View file

@ -11,8 +11,6 @@
* Ocaml language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_ocaml_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
@ -30,7 +28,7 @@ static int in_constructor = 0, in_destructor = 0, in_copyconst = 0;
static int const_enum = 0;
static int static_member_function = 0;
static int generate_sizeof = 0;
static char *prefix = 0;
static String *prefix = 0;
static char *ocaml_path = (char *) "ocaml";
static bool old_variable_names = false;
static String *classname = 0;
@ -107,8 +105,7 @@ public:
SWIG_exit(0);
} else if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) {
prefix = new char[strlen(argv[i + 1]) + 2];
strcpy(prefix, argv[i + 1]);
prefix = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
@ -130,15 +127,13 @@ public:
}
}
// If a prefix has been specified make sure it ends in a '_'
// If a prefix has been specified make sure it ends in a '_' (not actually used!)
if (prefix) {
if (prefix[strlen(prefix)] != '_') {
prefix[strlen(prefix) + 1] = 0;
prefix[strlen(prefix)] = '_';
}
const char *px = Char(prefix);
if (px[Len(prefix) - 1] != '_')
Printf(prefix, "_");
} else
prefix = (char *) "swig_";
prefix = NewString("swig_");
// Add a symbol for this module
@ -343,7 +338,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -357,14 +351,12 @@ public:
Dump(f_class_ctors, f_mlout);
Dump(f_class_ctors_end, f_mlout);
Dump(f_mltail, f_mlout);
Close(f_mlout);
Delete(f_mlout);
Dump(f_enumtypes_type, f_mliout);
Dump(f_enumtypes_value, f_mliout);
Dump(f_mlibody, f_mliout);
Dump(f_mlitail, f_mliout);
Close(f_mliout);
Delete(f_mliout);
return SWIG_OK;
@ -1261,13 +1253,12 @@ public:
Printv(qtype, name, NIL);
}
if (const_enum && name && !Getattr(seen_enumvalues, name)) {
if (const_enum && qtype && name && !Getattr(seen_enumvalues, name)) {
Setattr(seen_enumvalues, name, "true");
SetFlag(n, "feature:immutable");
Setattr(n, "feature:enumvalue", "1"); // this does not appear to be used
if (qtype)
Setattr(n, "qualified:name", SwigType_namestr(qtype));
Setattr(n, "qualified:name", SwigType_namestr(qtype));
String *evname = SwigType_manglestr(qtype);
Insert(evname, 0, "SWIG_ENUM_");
@ -1380,63 +1371,41 @@ public:
int classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
String *storage;
String *value;
String *decl;
String *type;
String *name;
String *classname;
String *storage = Getattr(n, "storage");
String *value = Getattr(n, "value");
String *decl = Getattr(n, "decl");
String *returntype = Getattr(n, "type");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *symname = Getattr(n, "sym:name");
String *declaration;
ParmList *l;
Wrapper *w;
String *declaration = NewString("");
ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *return_type;
int status = SWIG_OK;
int idx;
bool pure_virtual = false;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
storage = Getattr(n, "storage");
value = Getattr(n, "value");
classname = Getattr(parent, "sym:name");
type = Getattr(n, "type");
name = Getattr(n, "name");
if (Cmp(storage, "virtual") == 0) {
if (Cmp(value, "0") == 0) {
pure_virtual = true;
}
}
w = NewWrapper();
declaration = NewString("");
Wrapper_add_local(w, "swig_result", "CAMLparam0();\n" "SWIG_CAMLlocal2(swig_result,args)");
/* determine if the method returns a pointer */
decl = Getattr(n, "decl");
is_pointer = SwigType_ispointer_return(decl);
is_void = (!Cmp(type, "void") && !is_pointer);
/* form complete return type */
return_type = Copy(type);
{
SwigType *t = Copy(decl);
SwigType *f = 0;
f = SwigType_pop_function(t);
SwigType_push(return_type, t);
Delete(f);
Delete(t);
}
is_void = (!Cmp(returntype, "void") && !is_pointer);
/* virtual method definition */
l = Getattr(n, "parms");
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s {", target);
Delete(qualified_name);
@ -1452,7 +1421,7 @@ public:
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL);
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
}
}
@ -1614,18 +1583,7 @@ public:
String *cleanup = NewString("");
String *outarg = NewString("");
idx = 0;
/* this seems really silly. the node's type excludes
* qualifier/pointer/reference markers, which have to be retrieved
* from the decl field to construct return_type. but the typemap
* lookup routine uses the node's type, so we have to swap in and
* out the correct type. it's not just me, similar silliness also
* occurs in Language::cDeclaration().
*/
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, "c_result", w);
Setattr(n, "type", type);
if (tm != 0) {
Replaceall(tm, "$input", "swig_result");
/* TODO check this */
@ -1660,15 +1618,15 @@ public:
if (!(ignored_method && !pure_virtual)) {
/* A little explanation:
* The director_enum test case makes a method whose return type
* is an enum type. return_type here is "int". gcc complains
* is an enum type. returntype here is "int". gcc complains
* about an implicit enum conversion, and although i don't strictly
* agree with it, I'm working on fixing the error:
*
* Below is what I came up with. It's not great but it should
* always essentially work.
*/
if (!SwigType_isreference(return_type)) {
Printf(w->code, "CAMLreturn_type((%s)c_result);\n", SwigType_lstr(return_type, ""));
if (!SwigType_isreference(returntype)) {
Printf(w->code, "CAMLreturn_type((%s)c_result);\n", SwigType_lstr(returntype, ""));
} else {
Printf(w->code, "CAMLreturn_type(*c_result);\n");
}
@ -1704,7 +1662,6 @@ public:
/* clean up */
Delete(wrap_args);
Delete(return_type);
Delete(pclassname);
DelWrapper(w);
return status;
@ -1783,7 +1740,6 @@ public:
p = NewParm(type, NewString("self"), n);
q = Copy(p);
set_nextSibling(p, parms);
parms = p;
{
Wrapper *w = NewWrapper();

View file

@ -11,20 +11,15 @@
* Octave language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_octave_cxx[] = "$Id$";
#include "swigmod.h"
static bool global_load = true;
static String *global_name = 0;
static String *op_prefix = 0;
static const char *usage = (char *) "\
Octave Options (available with -octave)\n\
-global - Load all symbols into the global namespace [default]\n\
-globals <name> - Set <name> used to access C global variables [default: 'cvar']\n\
- Use '.' to load C global variables into module namespace\n\
-noglobal - Do not load all symbols into the global namespace\n\
Use '.' to load C global variables into module namespace\n\
-opprefix <str> - Prefix <str> for global operator functions [default: 'op_']\n\
\n";
@ -50,10 +45,35 @@ private:
Hash *docs;
void Octave_begin_function(Node *n, File *f, const_String_or_char_ptr cname, const_String_or_char_ptr wname, bool dld) {
if (dld) {
String *tname = texinfo_name(n, "std::string()");
Printf(f, "SWIG_DEFUN( %s, %s, %s ) {", cname, wname, tname);
}
else {
Printf(f, "static octave_value_list %s (const octave_value_list& args, int nargout) {", wname);
}
}
public:
OCTAVE():f_begin(0), f_runtime(0), f_header(0), f_doc(0), f_wrappers(0),
f_init(0), f_initbeforefunc(0), f_directors(0), f_directors_h(0),
s_global_tab(0), s_members_tab(0), class_name(0) {
OCTAVE():
f_begin(0),
f_runtime(0),
f_header(0),
f_doc(0),
f_wrappers(0),
f_init(0),
f_initbeforefunc(0),
f_directors(0),
f_directors_h(0),
s_global_tab(0),
s_members_tab(0),
class_name(0),
have_constructor(0),
have_destructor(0),
constructor_name(0),
docs(0)
{
/* Add code to manage protected constructors and directors */
director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code,
@ -73,12 +93,13 @@ public:
if (argv[i]) {
if (strcmp(argv[i], "-help") == 0) {
fputs(usage, stdout);
} else if (strcmp(argv[i], "-global") == 0) {
global_load = true;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noglobal") == 0) {
global_load = false;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-global") == 0 ||
strcmp(argv[i], "-noglobal") == 0) {
Printv(stderr,
"*** -global/-noglobal are no longer supported\n"
"*** global load behaviour is now determined at module load\n"
"*** see the Perl section in the manual for details.\n", NIL);
SWIG_exit(EXIT_FAILURE);
} else if (strcmp(argv[i], "-globals") == 0) {
if (argv[i + 1]) {
global_name = NewString(argv[i + 1]);
@ -169,10 +190,8 @@ public:
Printf(f_runtime, "#define SWIG_name %s\n", module);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIG_global_load %s\n", global_load ? "true" : "false");
Printf(f_runtime, "#define SWIG_global_name \"%s\"\n", global_name);
Printf(f_runtime, "#define SWIG_op_prefix \"%s\"\n", op_prefix);
Printf(f_runtime, "#define SWIG_atexit_func swig_atexit_%s\n", module);
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");
@ -186,7 +205,7 @@ public:
Printf(f_runtime, "\n");
Printf(s_global_tab, "\nstatic const struct swig_octave_member swig_globals[] = {\n");
Printf(f_init, "static void SWIG_init_user(octave_swig_type* module_ns)\n{\n");
Printf(f_init, "static bool SWIG_init_user(octave_swig_type* module_ns)\n{\n");
if (!CPlusPlus)
Printf(f_header,"extern \"C\" {\n");
@ -202,7 +221,7 @@ public:
if (directorsEnabled())
Swig_insert_file("director.swg", f_runtime);
Printf(f_init, "}\n");
Printf(f_init, "return true;\n}\n");
Printf(s_global_tab, "{0,0,0,0,0}\n};\n");
Printv(f_wrappers, s_global_tab, NIL);
@ -226,7 +245,6 @@ public:
Delete(f_header);
Delete(f_directors);
Delete(f_directors_h);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -293,14 +311,14 @@ public:
return !Len(synopsis) && !Len(decl_info) &&
!Len(cdecl_info) && !Len(args_info);
}
String *texinfo_name(Node* n) {
String *texinfo_name(Node* n, const char* defval = "0") {
String *tname = NewString("");
String *iname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(iname);
Node* d = Getattr(docs, wname);
if (is_empty_doc_node(d))
Printf(tname, "0");
Printf(tname, defval);
else
Printf(tname, "%s_texinfo", wname);
@ -337,14 +355,10 @@ public:
SwigType *type = Getattr(n, "type");
if (type && Strcmp(type, "void")) {
type = SwigType_base(type);
Node *lookup = Swig_symbol_clookup(type, 0);
if (lookup)
type = Getattr(lookup, "sym:name");
Node *nn = classLookup(Getattr(n, "type"));
String *type_str = nn ? Copy(Getattr(nn, "sym:name")) : SwigType_str(type, 0);
Append(decl_info, "@var{retval} = ");
String *type_str = NewString("");
Printf(type_str, "@var{retval} is of type %s. ", type);
Append(args_str, type_str);
Printf(args_str, "%s@var{retval} is of type %s. ", args_str, type_str);
Delete(type_str);
}
@ -373,7 +387,7 @@ public:
virtual int importDirective(Node *n) {
String *modname = Getattr(n, "module");
if (modname)
Printf(f_init, "feval(\"%s\",octave_value_list(),0);\n", modname);
Printf(f_init, "if (!SWIG_Octave_LoadModule(\"%s\")) return false;\n", modname);
return Language::importDirective(n);
}
@ -506,11 +520,7 @@ public:
}
if (Strcmp(v, "NULL") == 0)
return SwigType_ispointer(t) ? NewString("nil") : NewString("0");
else if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
return NewString("true");
else if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("false");
if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0)
if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
return NewString("true");
if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("false");
@ -519,7 +529,6 @@ public:
}
virtual int functionWrapper(Node *n) {
Wrapper *f = NewWrapper();
Parm *p;
String *tm;
int j;
@ -543,7 +552,11 @@ public:
if (overloaded)
Append(overname, Getattr(n, "sym:overname"));
Printv(f->def, "static octave_value_list ", overname, " (const octave_value_list& args, int nargout) {", NIL);
if (!overloaded || last_overload)
process_autodoc(n);
Wrapper *f = NewWrapper();
Octave_begin_function(n, f->def, iname, overname, !overloaded);
emit_parameter_variables(l, f);
emit_attach_parmmaps(l, f);
@ -731,10 +744,15 @@ public:
Delete(tm);
}
Printf(f->code, "fail:\n"); // we should free locals etc if this happens
Printf(f->code, "return _out;\n");
Printf(f->code, "fail:\n"); // we should free locals etc if this happens
Printv(f->code, cleanup, NIL);
Printf(f->code, "return octave_value_list();\n");
Printf(f->code, "}\n");
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
Replaceall(f->code, "$symname", iname);
Wrapper_print(f, f_wrappers);
DelWrapper(f);
@ -743,7 +761,6 @@ public:
dispatchFunction(n);
if (!overloaded || last_overload) {
process_autodoc(n);
String *tname = texinfo_name(n);
Printf(s_global_tab, "{\"%s\",%s,0,0,2,%s},\n", iname, wname, tname);
Delete(tname);
@ -766,7 +783,7 @@ public:
String *dispatch = Swig_overload_dispatch(n, "return %s(args, nargout);", &maxargs);
String *tmp = NewString("");
Printv(f->def, "static octave_value_list ", wname, " (const octave_value_list& args, int nargout) {", NIL);
Octave_begin_function(n, f->def, iname, wname, true);
Wrapper_add_local(f, "argc", "int argc = args.length()");
Printf(tmp, "octave_value_ref argv[%d]={", maxargs);
for (int j = 0; j < maxargs; ++j)
@ -800,7 +817,10 @@ public:
String *getname = Swig_name_get(NSPACE_TODO, iname);
String *setname = Swig_name_set(NSPACE_TODO, iname);
Printf(setf->def, "static octave_value_list _wrap_%s(const octave_value_list& args,int nargout) {", setname);
String *getwname = Swig_name_wrapper(getname);
String *setwname = Swig_name_wrapper(setname);
Octave_begin_function(n, setf->def, setname, setwname, true);
Printf(setf->def, "if (!SWIG_check_num_args(\"%s_set\",args.length(),1,1,0)) return octave_value_list();", iname);
if (is_assignable(n)) {
Setattr(n, "wrap:name", setname);
@ -826,7 +846,7 @@ public:
Setattr(n, "wrap:name", getname);
int addfail = 0;
Printf(getf->def, "static octave_value_list _wrap_%s(const octave_value_list& args,int nargout) {", getname);
Octave_begin_function(n, getf->def, getname, getwname, true);
Wrapper_add_local(getf, "obj", "octave_value obj");
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
@ -845,7 +865,12 @@ public:
Append(getf->code, "}\n");
Wrapper_print(getf, f_wrappers);
Printf(s_global_tab, "{\"%s\",0,_wrap_%s,_wrap_%s,2,0},\n", iname, getname, setname);
Printf(s_global_tab, "{\"%s\",0,%s,%s,2,0},\n", iname, getwname, setwname);
Delete(getwname);
Delete(setwname);
DelWrapper(setf);
DelWrapper(getf);
return SWIG_OK;
}
@ -937,20 +962,21 @@ public:
String *nspace = Getattr(n, "sym:nspace");
String *cname = Swig_name_disown(nspace, class_name);
String *wcname = Swig_name_wrapper(cname);
String *disown_shadow = NewString("");
Printf(disown_shadow, "static octave_value_list %s_shadow " "(const octave_value_list& args, int nargout) {\n", wcname);
Printf(disown_shadow, " if (args.length()!=1) {\n");
Printf(disown_shadow, " error(\"disown takes no arguments\");\n");
Printf(disown_shadow, " return octave_value_list();\n");
Printf(disown_shadow, " }\n");
Printf(disown_shadow, " %s (args, nargout);\n", wcname);
Printf(disown_shadow, " return args;\n");
Printf(disown_shadow, "}\n");
Printv(f_wrappers, disown_shadow, NIL);
Delete(disown_shadow);
Printf(s_members_tab, "{\"__disown\",%s_shadow,0,0,0,0},\n", wcname);
String *cnameshdw = NewStringf("%s_shadow", cname);
String *wcnameshdw = Swig_name_wrapper(cnameshdw);
Octave_begin_function(n, f_wrappers, cnameshdw, wcnameshdw, true);
Printf(f_wrappers, " if (args.length()!=1) {\n");
Printf(f_wrappers, " error(\"disown takes no arguments\");\n");
Printf(f_wrappers, " return octave_value_list();\n");
Printf(f_wrappers, " }\n");
Printf(f_wrappers, " %s (args, nargout);\n", wcname);
Printf(f_wrappers, " return args;\n");
Printf(f_wrappers, "}\n");
Printf(s_members_tab, "{\"__disown\",%s,0,0,0,0},\n", wcnameshdw);
Delete(wcname);
Delete(cname);
Delete(wcnameshdw);
Delete(cnameshdw);
}
Printf(s_members_tab, "{0,0,0,0}\n};\n");
@ -1049,15 +1075,18 @@ public:
assert(s_members_tab);
assert(class_name);
String *symname = Getattr(n, "sym:name");
String *getname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)));
String *setname = GetFlag(n, "feature:immutable") ?
NewString("octave_set_immutable") : Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)));
String *getname = Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname));
String *setname = Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname));
String *getwname = Swig_name_wrapper(getname);
String *setwname = GetFlag(n, "feature:immutable") ? NewString("octave_set_immutable") : Swig_name_wrapper(setname);
assert(s_members_tab);
Printf(s_members_tab, "{\"%s\",0,%s,%s,0,0},\n", symname, getname, setname);
Printf(s_members_tab, "{\"%s\",0,%s,%s,0,0},\n", symname, getwname, setwname);
Delete(getname);
Delete(setname);
Delete(getwname);
Delete(setwname);
return SWIG_OK;
}
@ -1132,15 +1161,18 @@ public:
assert(s_members_tab);
assert(class_name);
String *symname = Getattr(n, "sym:name");
String *getname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)));
String *setname = GetFlag(n, "feature:immutable") ?
NewString("octave_set_immutable") : Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)));
String *getname = Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname));
String *setname = Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname));
String *getwname = Swig_name_wrapper(getname);
String *setwname = GetFlag(n, "feature:immutable") ? NewString("octave_set_immutable") : Swig_name_wrapper(setname);
assert(s_members_tab);
Printf(s_members_tab, "{\"%s\",0,%s,%s,1,0},\n", symname, getname, setname);
Printf(s_members_tab, "{\"%s\",0,%s,%s,1,0},\n", symname, getwname, setwname);
Delete(getname);
Delete(setname);
Delete(getwname);
Delete(setwname);
}
return SWIG_OK;
}
@ -1226,18 +1258,17 @@ public:
int classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
String *decl;
String *type;
String *name;
String *classname;
String *decl = Getattr(n, "decl");
String *returntype = Getattr(n, "type");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *symname = Getattr(n, "sym:name");
String *declaration;
ParmList *l;
Wrapper *w;
String *declaration = NewString("");
ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *return_type;
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");
bool pure_virtual = false;
@ -1251,35 +1282,15 @@ public:
}
}
classname = Getattr(parent, "sym:name");
type = Getattr(n, "type");
name = Getattr(n, "name");
w = NewWrapper();
declaration = NewString("");
// determine if the method returns a pointer
decl = Getattr(n, "decl");
is_pointer = SwigType_ispointer_return(decl);
is_void = (!Cmp(type, "void") && !is_pointer);
// form complete return type
return_type = Copy(type);
{
SwigType *t = Copy(decl);
SwigType *f = 0;
f = SwigType_pop_function(t);
SwigType_push(return_type, t);
Delete(f);
Delete(t);
}
is_void = (!Cmp(returntype, "void") && !is_pointer);
// virtual method definition
l = Getattr(n, "parms");
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s", target);
Delete(qualified_name);
@ -1303,7 +1314,7 @@ public:
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
@ -1327,7 +1338,7 @@ public:
// handle it, including declaration of c_result ($result).
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *cres = SwigType_lstr(return_type, "c_result");
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
@ -1361,7 +1372,6 @@ public:
outputs++;
// build argument list and type conversion string
idx = 0;
p = l;
while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
@ -1428,9 +1438,7 @@ public:
"method %s.%s failed to return the required number " "of arguments.\");\n", classname, method_name);
Printf(w->code, "}\n");
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
Setattr(n, "type", type);
if (tm != 0) {
char temp[24];
sprintf(temp, "out(%d)", idx);
@ -1446,7 +1454,7 @@ public:
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n",
SwigType_str(return_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
status = SWIG_ERROR;
}
}
@ -1473,8 +1481,8 @@ public:
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *rettype = SwigType_str(return_type, 0);
if (!SwigType_isreference(return_type)) {
String *rettype = SwigType_str(returntype, 0);
if (!SwigType_isreference(returntype)) {
Printf(w->code, "return (%s) c_result;\n", rettype);
} else {
Printf(w->code, "return (%s) *c_result;\n", rettype);
@ -1510,7 +1518,6 @@ public:
}
// clean up
Delete(wrap_args);
Delete(return_type);
Delete(pclassname);
DelWrapper(w);
return status;

View file

@ -13,8 +13,6 @@
* building a dispatch function.
* ----------------------------------------------------------------------------- */
char cvsroot_overload_cxx[] = "$Id$";
#include "swigmod.h"
#define MAX_OVERLOAD 4096

View file

@ -11,8 +11,6 @@
* Perl5 language module for SWIG.
* ------------------------------------------------------------------------- */
char cvsroot_perl5_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
@ -132,7 +130,7 @@ public:
Node *is_shadow(SwigType *t) {
Node *n;
n = classLookup(t);
/* Printf(stdout,"'%s' --> '%x'\n", t, n); */
/* Printf(stdout,"'%s' --> '%p'\n", t, n); */
if (n) {
if (!Getattr(n, "perl5:proxy")) {
setclassname(n);
@ -520,7 +518,6 @@ public:
Printf(f_pm, "%s", additional_perl_code);
Printf(f_pm, "1;\n");
Close(f_pm);
Delete(f_pm);
Delete(base);
Delete(dest_package);
@ -534,7 +531,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -614,7 +610,6 @@ public:
Printf(f->code, "}\n");
/* Write code to extract parameters. */
i = 0;
for (i = 0, p = l; i < num_arguments; i++) {
/* Skip ignored arguments */
@ -870,6 +865,8 @@ public:
emit_action_code(n, setf->code, tm);
} else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0));
DelWrapper(setf);
DelWrapper(getf);
return SWIG_NOWRAP;
}
Printf(setf->code, "fail:\n");
@ -1638,8 +1635,8 @@ public:
while (fgets(buffer, 4095, f)) {
Printf(pragma_include, "%s", buffer);
}
fclose(f);
}
fclose(f);
}
} else {
Swig_error(input_file, line_number, "Unrecognized pragma.\n");
@ -1669,7 +1666,7 @@ public:
}
/* Split the input text into lines */
List *clist = DohSplitLines(temp);
List *clist = SplitLines(temp);
Delete(temp);
int initial = 0;
String *s = 0;

View file

@ -37,8 +37,6 @@
* (may need to add more WARN_PHP_xxx codes...)
*/
char cvsroot_php_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
@ -354,7 +352,9 @@ public:
Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", cap_module);
Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", cap_module);
Printf(f_directors, "\n#include \"%s\"\n\n", Swig_file_filename(outfile_h));
String *filename = Swig_file_filename(outfile_h);
Printf(f_directors, "\n#include \"%s\"\n\n", filename);
Delete(filename);
}
/* PHP module file */
@ -409,11 +409,20 @@ public:
Printf(s_header, "#define SWIG_ErrorCode() (%s_globals.error_code)\n", module);
Printf(s_header, "#endif\n\n");
Printf(s_header, "// Allow the user to workaround a PHP bug on some platforms/architectures by\n");
Printf(s_header, "// compiling with -DSWIG_ZEND_ERROR_NORETURN=zend_error\n");
Printf(s_header, "#ifndef SWIG_ZEND_ERROR_NORETURN\n");
Printf(s_header, "# define SWIG_ZEND_ERROR_NORETURN zend_error_noreturn\n");
Printf(s_header, "#endif\n\n");
/* The following can't go in Lib/php/phprun.swg as it uses SWIG_ErrorMsg(), etc
* which has to be dynamically generated as it depends on the module name.
*/
Append(s_header, "#ifdef __GNUC__\n");
Append(s_header, "static void SWIG_FAIL() __attribute__ ((__noreturn__));\n");
Append(s_header, "#endif\n\n");
Append(s_header, "static void SWIG_FAIL() {\n");
Append(s_header, " TSRMLS_FETCH();\n");
Append(s_header, " zend_error(SWIG_ErrorCode(), \"%s\", SWIG_ErrorMsg());\n");
// zend_error() should never return with the parameters we pass, but if it
// does, we really don't want to let SWIG_FAIL() return. This also avoids
// a warning about returning from a function marked as "__noreturn__".
Append(s_header, " abort();\n");
Append(s_header, "}\n\n");
Printf(s_header, "static void %s_init_globals(zend_%s_globals *globals ) {\n", module, module);
Printf(s_header, " globals->error_msg = default_error_msg;\n");
@ -463,10 +472,6 @@ public:
Append(s_header, "}\n");
Printf(s_header, "#define SWIG_name \"%s\"\n", module);
/* Printf(s_header,"#ifdef HAVE_CONFIG_H\n");
Printf(s_header,"#include \"config.h\"\n");
Printf(s_header,"#endif\n\n");
*/
Printf(s_header, "#ifdef __cplusplus\n");
Printf(s_header, "extern \"C\" {\n");
Printf(s_header, "#endif\n");
@ -528,7 +533,8 @@ public:
Append(s_init, "#undef ZEND_MODULE_BUILD_ID\n");
Append(s_init, "#define ZEND_MODULE_BUILD_ID (char*)\"API\" ZEND_TOSTR(ZEND_MODULE_API_NO) ZEND_BUILD_TS ZEND_BUILD_DEBUG ZEND_BUILD_SYSTEM ZEND_BUILD_EXTRA\n");
Append(s_init, "#endif\n");
Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n" "#if ZEND_MODULE_API_NO > 20010900\n" " STANDARD_MODULE_HEADER,\n" "#endif\n", NIL);
Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n", NIL);
Printf(s_init, " STANDARD_MODULE_HEADER,\n");
Printf(s_init, " (char*)\"%s\",\n", module);
Printf(s_init, " %s_functions,\n", module);
Printf(s_init, " PHP_MINIT(%s),\n", module);
@ -536,9 +542,7 @@ public:
Printf(s_init, " PHP_RINIT(%s),\n", module);
Printf(s_init, " PHP_RSHUTDOWN(%s),\n", module);
Printf(s_init, " PHP_MINFO(%s),\n", module);
Printf(s_init, "#if ZEND_MODULE_API_NO > 20010900\n");
Printf(s_init, " NO_VERSION_YET,\n");
Printf(s_init, "#endif\n");
Printf(s_init, " STANDARD_MODULE_PROPERTIES\n");
Printf(s_init, "};\n");
Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module);
@ -612,7 +616,7 @@ public:
Printf(f_h, "#endif /* PHP_%s_H */\n", cap_module);
Close(f_h);
Delete(f_h);
String *type_table = NewStringEmpty();
SwigType_emit_type_table(f_runtime, type_table);
@ -627,7 +631,7 @@ public:
Dump(f_directors_h, f_runtime_h);
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
Close(f_runtime_h);
Delete(f_runtime_h);
}
Printf(s_header, "/* end header section */\n");
@ -651,7 +655,6 @@ public:
Delete(s_vdecl);
Delete(all_cs_entry);
Delete(s_entry);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -664,7 +667,7 @@ public:
s_fakeoowrappers = NULL;
}
Printf(f_phpcode, "%s\n?>\n", s_phpclasses);
Close(f_phpcode);
Delete(f_phpcode);
return SWIG_OK;
}
@ -716,7 +719,7 @@ public:
Printf(f->code, "SWIG_ErrorCode() = E_ERROR;\n");
Printf(f->code, "SWIG_ErrorMsg() = \"No matching function for overloaded '%s'\";\n", symname);
Printv(f->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n", NIL);
Printv(f->code, "SWIG_FAIL();\n", NIL);
Printv(f->code, "}\n", NIL);
Wrapper_print(f, s_wrappers);
@ -784,7 +787,6 @@ public:
}
f = NewWrapper();
numopt = 0;
String *outarg = NewStringEmpty();
String *cleanup = NewStringEmpty();
@ -1000,11 +1002,7 @@ public:
/* Error handling code */
Printf(f->code, "fail:\n");
Printv(f->code, cleanup, NIL);
/* This could be zend_error_noreturn(), but that's buggy in PHP ~5.3 and
* using zend_error() here shouldn't generate a warning, so just use that.
* At worst this may result in slightly less good code.
*/
Printv(f->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());", NIL);
Append(f->code, "SWIG_FAIL();\n");
Printf(f->code, "}\n");
@ -1033,7 +1031,7 @@ public:
p += strlen(p) - 4;
String *varname = Getattr(n, "membervariableHandler:sym:name");
if (strcmp(p, "_get") == 0) {
Setattr(shadow_get_vars, varname, iname);
Setattr(shadow_get_vars, varname, Getattr(n, "type"));
} else if (strcmp(p, "_set") == 0) {
Setattr(shadow_set_vars, varname, iname);
}
@ -1091,9 +1089,6 @@ public:
int min_num_of_arguments = emit_num_required(l);
int max_num_of_arguments = emit_num_arguments(l);
// For a function with default arguments, we end up with the fullest
// parmlist in full_parmlist.
ParmList *full_parmlist = l;
Hash *ret_types = NewHash();
Setattr(ret_types, d, d);
@ -1126,7 +1121,6 @@ public:
if (num_arguments > max_num_of_arguments) {
max_num_of_arguments = num_arguments;
full_parmlist = l2;
}
o = Getattr(o, "sym:nextSibling");
}
@ -1177,11 +1171,6 @@ public:
if (!o) {
// This "overloaded method" is really just one with default args.
really_overloaded = false;
if (l != full_parmlist) {
l = full_parmlist;
if (wrapperType == memberfn)
l = nextSibling(l);
}
}
}
@ -1582,7 +1571,8 @@ public:
while (i.item) {
Node *j = firstChild(i.item);
while (j) {
if (Strcmp(Getattr(j, "name"), Getattr(n, "name")) != 0) {
String *jname = Getattr(j, "name");
if (!jname || Strcmp(jname, Getattr(n, "name")) != 0) {
j = nextSibling(j);
continue;
}
@ -1703,9 +1693,9 @@ public:
Printf(output, "\t\t$r=%s;\n", invoke);
if (Len(ret_types) == 1) {
/* If d is abstract we can't create a new wrapper type d. */
Node * d_class = classLookup(d);
Node *d_class = classLookup(d);
int is_abstract = 0;
if (Getattr(d_class, "abstract")) {
if (Getattr(d_class, "abstracts")) {
is_abstract = 1;
}
if (newobject || !is_abstract) {
@ -1745,7 +1735,6 @@ public:
if (!class_node) {
/* This is needed when we're returning a pointer to a type
* rather than returning the type by value or reference. */
class_node = current_class;
Delete(mangled);
mangled = NewString(SwigType_manglestr(ret_type));
class_node = Getattr(zend_types, mangled);
@ -2013,7 +2002,6 @@ done:
classnode = 0;
if (shadow) {
DOH *key;
List *baselist = Getattr(n, "bases");
Iterator ki, base;
@ -2026,7 +2014,7 @@ done:
base.item = NULL;
}
if (Getattr(n, "abstract") && !GetFlag(n, "feature:notabstract")) {
if (Getattr(n, "abstracts") && !GetFlag(n, "feature:notabstract")) {
Printf(s_phpclasses, "abstract ");
}
@ -2056,10 +2044,10 @@ done:
// FIXME: tune this threshold...
if (Len(shadow_set_vars) <= 2) {
// Not many setters, so avoid call_user_func.
while (ki.key) {
key = ki.key;
Printf(s_phpclasses, "\t\tif ($var === '%s') return %s($this->%s,$value);\n", key, ki.item, SWIG_PTR);
ki = Next(ki);
for (; ki.key; ki = Next(ki)) {
DOH *key = ki.key;
String *iname = ki.item;
Printf(s_phpclasses, "\t\tif ($var === '%s') return %s($this->%s,$value);\n", key, iname, SWIG_PTR);
}
} else {
Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_set';\n", shadow_classname);
@ -2107,21 +2095,30 @@ done:
if (ki.key) {
// This class has getters.
Printf(s_phpclasses, "\n\tfunction __get($var) {\n");
// FIXME: Currently we always use call_user_func for __get, so we can
// check and wrap the result. This is needless if all the properties
// are primitive types. Also this doesn't handle all the cases which
// a method returning an object does.
Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname);
Printf(s_phpclasses, "\t\tif (function_exists($func)) {\n");
Printf(s_phpclasses, "\t\t\t$r = call_user_func($func,$this->%s);\n", SWIG_PTR);
Printf(s_phpclasses, "\t\t\tif (!is_resource($r)) return $r;\n");
if (Len(prefix) == 0) {
Printf(s_phpclasses, "\t\t\t$c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n");
} else {
Printf(s_phpclasses, "\t\t\t$c='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix);
int non_class_getters = 0;
for (; ki.key; ki = Next(ki)) {
DOH *key = ki.key;
SwigType *d = ki.item;
if (!is_class(d)) {
++non_class_getters;
continue;
}
Printv(s_phpclasses, "\t\tif ($var === '", key, "') return new ", prefix, Getattr(classLookup(d), "sym:name"), "(", shadow_classname, "_", key, "_get($this->", SWIG_PTR, "));\n", NIL);
}
// FIXME: tune this threshold...
if (non_class_getters <= 2) {
// Not many non-class getters, so avoid call_user_func.
for (ki = First(shadow_get_vars); non_class_getters && ki.key; ki = Next(ki)) {
DOH *key = ki.key;
SwigType *d = ki.item;
if (is_class(d)) continue;
Printv(s_phpclasses, "\t\tif ($var === '", key, "') return ", shadow_classname, "_", key, "_get($this->", SWIG_PTR, ");\n", NIL);
--non_class_getters;
}
} else {
Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname);
Printf(s_phpclasses, "\t\tif (function_exists($func)) return call_user_func($func,$this->%s);\n", SWIG_PTR);
}
Printf(s_phpclasses, "\t\t\treturn new $c($r);\n");
Printf(s_phpclasses, "\t\t}\n");
Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR);
if (baseclass) {
Printf(s_phpclasses, "\t\treturn %s%s::__get($var);\n", prefix, baseclass);
@ -2320,14 +2317,11 @@ done:
Append(f->code, "return;\n");
Append(f->code, "fail:\n");
/* This could be zend_error_noreturn(), but that's buggy in PHP ~5.3 and
* using zend_error() here shouldn't generate a warning, so just use that.
* At worst this may result in slightly less good code.
*/
Append(f->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n");
Append(f->code, "SWIG_FAIL();\n");
Printf(f->code, "}\n");
Wrapper_print(f, s_wrappers);
DelWrapper(f);
return SWIG_OK;
}
@ -2412,18 +2406,17 @@ done:
int classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
String *decl;
String *type;
String *name;
String *classname;
String *decl = Getattr(n, "decl");
String *returntype = Getattr(n, "type");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *symname = Getattr(n, "sym:name");
String *declaration;
ParmList *l;
Wrapper *w;
String *declaration = NewStringEmpty();
ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewStringEmpty();
String *return_type;
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");
bool pure_virtual = false;
@ -2437,34 +2430,15 @@ done:
}
}
classname = Getattr(parent, "sym:name");
type = Getattr(n, "type");
name = Getattr(n, "name");
w = NewWrapper();
declaration = NewStringEmpty();
/* determine if the method returns a pointer */
decl = Getattr(n, "decl");
is_pointer = SwigType_ispointer_return(decl);
is_void = (Cmp(type, "void") == 0 && !is_pointer);
/* form complete return type */
return_type = Copy(type);
{
SwigType *t = Copy(decl);
SwigType *f = SwigType_pop_function(t);
SwigType_push(return_type, t);
Delete(f);
Delete(t);
}
is_void = (Cmp(returntype, "void") == 0 && !is_pointer);
/* virtual method definition */
l = Getattr(n, "parms");
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s", target);
Delete(qualified_name);
@ -2487,7 +2461,7 @@ done:
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
@ -2514,7 +2488,7 @@ done:
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *cres = SwigType_lstr(return_type, "c_result");
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
@ -2575,6 +2549,7 @@ done:
Replaceall(tm, "$owner", "0");
Printv(wrap_args, "zval ", source, ";\n", NIL);
Printf(wrap_args, "args[%d] = &%s;\n", idx - 1, source);
Printv(wrap_args, "INIT_ZVAL(", source, ");\n", NIL);
Printv(wrap_args, tm, "\n", NIL);
Putc('O', parse_args);
@ -2616,13 +2591,14 @@ done:
}
if (!idx) {
Printf(w->code, "zval **args = NULL;\n", idx);
Printf(w->code, "zval **args = NULL;\n");
} else {
Printf(w->code, "zval *args[%d];\n", idx);
}
Printf(w->code, "zval *%s, funcname;\n", Swig_cresult_name());
Printf(w->code, "MAKE_STD_ZVAL(%s);\n", Swig_cresult_name());
Printf(w->code, "ZVAL_STRING(&funcname, (char *)\"%s\", 0);\n", GetChar(n, "sym:name"));
const char * funcname = GetChar(n, "sym:name");
Printf(w->code, "ZVAL_STRINGL(&funcname, (char *)\"%s\", %d, 0);\n", funcname, strlen(funcname));
Append(w->code, "if (!swig_self) {\n");
Append(w->code, " SWIG_PHP_Error(E_ERROR, \"this pointer is NULL\");");
Append(w->code, "}\n\n");
@ -2647,16 +2623,7 @@ done:
/* marshal return value */
if (!is_void) {
/* this seems really silly. the node's type excludes
* qualifier/pointer/reference markers, which have to be retrieved
* from the decl field to construct return_type. but the typemap
* lookup routine uses the node's type, so we have to swap in and
* out the correct type. it's not just me, similar silliness also
* occurs in Language::cDeclaration().
*/
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
Setattr(n, "type", type);
if (tm != 0) {
static const String *amp_result = NewStringf("&%s", Swig_cresult_name());
Replaceall(tm, "$input", amp_result);
@ -2675,7 +2642,7 @@ done:
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname),
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname),
SwigType_namestr(name));
status = SWIG_ERROR;
}
@ -2702,8 +2669,8 @@ done:
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *rettype = SwigType_str(return_type, 0);
if (!SwigType_isreference(return_type)) {
String *rettype = SwigType_str(returntype, 0);
if (!SwigType_isreference(returntype)) {
Printf(w->code, "return (%s) c_result;\n", rettype);
} else {
Printf(w->code, "return (%s) *c_result;\n", rettype);
@ -2715,15 +2682,7 @@ done:
}
Append(w->code, "fail:\n");
if (!is_void) {
Append(w->code, "SWIG_ZEND_ERROR_NORETURN(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n");
} else {
/* This could be zend_error_noreturn(), but that's buggy in PHP ~5.3 and
* using zend_error() here shouldn't generate a warning, so just use that.
* At worst this may result in slightly less good code.
*/
Append(w->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n");
}
Append(w->code, "SWIG_FAIL();\n");
Append(w->code, "}\n");
// We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
@ -2753,7 +2712,6 @@ done:
/* clean up */
Delete(wrap_args);
Delete(return_type);
Delete(pclassname);
DelWrapper(w);
return status;

View file

@ -29,8 +29,6 @@
*
*/
char cvsroot_pike_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h> // for isalnum()
@ -182,8 +180,6 @@ public:
Delete(f_wrappers);
Delete(f_init);
Delete(f_classInit);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);

View file

@ -11,8 +11,6 @@
* Python language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_python_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
@ -763,8 +761,11 @@ public:
Printf(f_directors, "/* ---------------------------------------------------\n");
Printf(f_directors, " * C++ director class methods\n");
Printf(f_directors, " * --------------------------------------------------- */\n\n");
if (outfile_h)
Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
if (outfile_h) {
String *filename = Swig_file_filename(outfile_h);
Printf(f_directors, "#include \"%s\"\n\n", filename);
Delete(filename);
}
}
/* If shadow classing is enabled, we're going to change the module name to "_module" */
@ -979,7 +980,6 @@ public:
Printv(f_shadow_py, "\n", f_shadow_builtin_imports, "\n", NIL);
Printv(f_shadow_py, f_shadow, "\n", NIL);
Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
Close(f_shadow_py);
Delete(f_shadow_py);
}
@ -992,7 +992,7 @@ public:
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
if (f_runtime_h != f_begin)
Close(f_runtime_h);
Delete(f_runtime_h);
Dump(f_directors, f_begin);
}
@ -1007,8 +1007,6 @@ public:
Delete(f_init);
Delete(f_directors);
Delete(f_directors_h);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -1049,7 +1047,7 @@ public:
// of this module.)
Node *options = Getattr(mod, "options");
String *pkg = options ? Getattr(options, "package") : 0;
if (pkg && (!package || Strcmp(pkg, package) != 0)) {
if (pkg) {
Printf(import, "%s.", pkg);
}
// finally, output the name of the imported module
@ -1057,7 +1055,7 @@ public:
if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) {
Printf(import, "_%s\n", modname);
if (!GetFlagAttr(f_shadow_imports, import)) {
if (pkg && (!package || Strcmp(pkg, package) != 0)) {
if (pkg) {
Printf(builtin ? f_shadow_builtin_imports : f_shadow, "import %s.%s\n", pkg, modname);
} else {
Printf(builtin ? f_shadow_builtin_imports : f_shadow, "import %s\n", modname);
@ -1107,7 +1105,7 @@ public:
}
/* Split the input text into lines */
List *clist = DohSplitLines(temp);
List *clist = SplitLines(temp);
Delete(temp);
int initial = 0;
String *s = 0;
@ -1163,9 +1161,9 @@ public:
autodoc_l autodoc_level(String *autodoc) {
autodoc_l dlevel = NO_AUTODOC;
if (autodoc) {
char *c = Char(autodoc);
if (c && isdigit(c[0])) {
char *c = Char(autodoc);
if (c) {
if (isdigit(c[0])) {
dlevel = (autodoc_l) atoi(c);
} else {
if (strcmp(c, "extended") == 0) {
@ -1558,7 +1556,7 @@ public:
else
return v;
}
if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0)
if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
return NewString("True");
if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("False");
@ -2616,7 +2614,7 @@ public:
Printf(f->code, "}\n");
} else {
Printf(f->code, "newargs = PyTuple_GetSlice(args,0,%d);\n", num_fixed_arguments);
Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_fixed_arguments);
Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args));\n", num_fixed_arguments);
}
Printf(f->code, "resultobj = %s__varargs__(%s,newargs,varargs);\n", wname, builtin ? "self" : "NULL");
Append(f->code, "Py_XDECREF(newargs);\n");
@ -3168,7 +3166,7 @@ public:
// check if the module has a package option
Node *options = Getattr(mod, "options");
String *pkg = options ? Getattr(options, "package") : 0;
if (pkg && (!package || Strcmp(pkg, package) != 0)) {
if (pkg) {
Printf(importname, "%s.", pkg);
}
Printf(importname, "%s.", modname);
@ -3794,7 +3792,7 @@ public:
if (!have_constructor) {
if (!builtin)
Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined",
(Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
(Getattr(n, "abstracts") ? " - class is abstract" : ""), "\")\n", NIL);
} else if (fastinit && !builtin) {
Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
@ -3809,7 +3807,7 @@ public:
if (new_repr) {
Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL);
} else {
Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"<C ", rname, " instance at 0x%x>\" % (self.this,)\n", NIL);
Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"<C ", rname, " instance at %p>\" % (self.this,)\n", NIL);
}
Delete(rname);
}
@ -4528,18 +4526,17 @@ int PYTHON::classDirectorMethods(Node *n) {
int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
String *decl;
String *type;
String *name;
String *classname;
String *decl = Getattr(n, "decl");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *symname = Getattr(n, "sym:name");
String *declaration;
ParmList *l;
Wrapper *w;
String *declaration = NewString("");
ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *return_type;
String *returntype = Getattr(n, "type");
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");
bool pure_virtual = false;
@ -4553,35 +4550,15 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
}
}
classname = Getattr(parent, "sym:name");
type = Getattr(n, "type");
name = Getattr(n, "name");
w = NewWrapper();
declaration = NewString("");
/* determine if the method returns a pointer */
decl = Getattr(n, "decl");
is_pointer = SwigType_ispointer_return(decl);
is_void = (!Cmp(type, "void") && !is_pointer);
/* form complete return type */
return_type = Copy(type);
{
SwigType *t = Copy(decl);
SwigType *f = 0;
f = SwigType_pop_function(t);
SwigType_push(return_type, t);
Delete(f);
Delete(t);
}
is_void = (!Cmp(returntype, "void") && !is_pointer);
/* virtual method definition */
l = Getattr(n, "parms");
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s", target);
Delete(qualified_name);
@ -4604,7 +4581,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
@ -4629,7 +4606,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *cres = SwigType_lstr(return_type, "c_result");
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
@ -4898,16 +4875,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
/* marshal return value */
if (!is_void) {
/* this seems really silly. the node's type excludes
* qualifier/pointer/reference markers, which have to be retrieved
* from the decl field to construct return_type. but the typemap
* lookup routine uses the node's type, so we have to swap in and
* out the correct type. it's not just me, similar silliness also
* occurs in Language::cDeclaration().
*/
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
Setattr(n, "type", type);
if (tm != 0) {
if (outputs > 1) {
Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++);
@ -4933,7 +4901,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname),
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname),
SwigType_namestr(name));
status = SWIG_ERROR;
}
@ -4970,8 +4938,8 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *rettype = SwigType_str(return_type, 0);
if (!SwigType_isreference(return_type)) {
String *rettype = SwigType_str(returntype, 0);
if (!SwigType_isreference(returntype)) {
Printf(w->code, "return (%s) c_result;\n", rettype);
} else {
Printf(w->code, "return (%s) *c_result;\n", rettype);
@ -5009,7 +4977,6 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
/* clean up */
Delete(wrap_args);
Delete(return_type);
Delete(pclassname);
DelWrapper(w);
return status;

View file

@ -11,8 +11,6 @@
* R language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_r_cxx[] = "$Id$";
#include "swigmod.h"
static const double DEFAULT_NUMBER = .0000123456712312312323;
@ -572,7 +570,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
Parm *p = parms;
for (i = 0; p; p = nextSibling(p), ++i) {
String *arg = Getattr(p, "name");
String *lname = NewString("");
String *lname;
if (!arg && Cmp(Getattr(p, "type"), "void")) {
lname = NewStringf("s_arg%d", i+1);
@ -682,7 +680,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
XXX Have to be a little more clever so that we can deal with struct A * - the * is getting lost.
Is this still true? If so, will a SwigType_push() solve things?
*/
Parm *bbase = NewParm(rettype, Swig_cresult_name(), n);
Parm *bbase = NewParmNode(rettype, n);
String *returnTM = Swig_typemap_lookup("in", bbase, Swig_cresult_name(), f);
if(returnTM) {
String *tm = returnTM;
@ -726,6 +724,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
Delete(rtype);
Delete(rettype);
Delete(funcparams);
DelWrapper(f);
return funName;
}
@ -837,7 +836,6 @@ int R::top(Node *n) {
Delete(f_init);
Delete(s_header);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -871,8 +869,7 @@ int R::DumpCode(Node *n) {
Printf(scode, "%s\n\n", s_classes);
Printf(scode, "%s\n", sfile);
Close(scode);
// Delete(scode);
Delete(scode);
String *outfile = Getattr(n,"outfile");
File *runtime = NewFile(outfile,"w", SWIG_output_files());
if (!runtime) {
@ -886,7 +883,6 @@ int R::DumpCode(Node *n) {
Printf(runtime, "%s\n", f_wrapper);
Printf(runtime, "%s\n", f_init);
Close(runtime);
Delete(runtime);
if(outputNamespaceInfo) {
@ -907,7 +903,6 @@ int R::DumpCode(Node *n) {
Printf(ns, "\nexportMethods(\n");
writeListByLine(namespaceFunctions, ns, 1);
Printf(ns, ")\n");
Close(ns);
Delete(ns);
Delete(s_namespace);
}
@ -1612,7 +1607,6 @@ void R::dispatchFunction(Node *n) {
String *tmcheck = Swig_typemap_lookup("rtypecheck", p, "", 0);
if (tmcheck) {
String *tmp = NewString("");
Printf(tmp, "argv[[%d]]", j+1);
Replaceall(tmcheck, "$arg", tmp);
@ -1629,32 +1623,34 @@ void R::dispatchFunction(Node *n) {
tmcheck);
p = Getattr(p, "tmap:in:next");
continue;
}
if (DohStrcmp(tm,"numeric")==0) {
}
if (tm) {
if (Strcmp(tm,"numeric")==0) {
Printf(f->code, "%sis.numeric(argv[[%d]])",
j == 0 ? "" : " && ",
j+1);
j == 0 ? "" : " && ",
j+1);
}
else if (DohStrcmp(tm,"integer")==0) {
else if (Strcmp(tm,"integer")==0) {
Printf(f->code, "%s(is.integer(argv[[%d]]) || is.numeric(argv[[%d]]))",
j == 0 ? "" : " && ",
j+1, j+1);
j == 0 ? "" : " && ",
j+1, j+1);
}
else if (DohStrcmp(tm,"character")==0) {
else if (Strcmp(tm,"character")==0) {
Printf(f->code, "%sis.character(argv[[%d]])",
j == 0 ? "" : " && ",
j+1);
j == 0 ? "" : " && ",
j+1);
}
else {
Printf(f->code, "%sextends(argtypes[%d], '%s')",
j == 0 ? "" : " && ",
j+1,
tm);
}
if (!SwigType_ispointer(Getattr(p, "type"))) {
Printf(f->code, " && length(argv[[%d]]) == 1",
j+1);
j == 0 ? "" : " && ",
j+1,
tm);
}
}
if (!SwigType_ispointer(Getattr(p, "type"))) {
Printf(f->code, " && length(argv[[%d]]) == 1",
j+1);
}
p = Getattr(p, "tmap:in:next");
}
Printf(f->code, ") { f <- %s%s; }\n", sfname, overname);
@ -1848,18 +1844,21 @@ int R::functionWrapper(Node *n) {
String *lname = Getattr(p,"lname");
// R keyword renaming
if (name && Swig_name_warning(p, 0, name, 0))
name = 0;
/* If we have a :: in the parameter name because we are accessing a static member of a class, say, then
we need to remove that prefix. */
while (Strstr(name, "::")) {
//XXX need to free.
name = NewStringf("%s", Strchr(name, ':') + 2);
if (debugMode)
Printf(stdout, "+++ parameter name with :: in it %s\n", name);
if (name) {
if (Swig_name_warning(p, 0, name, 0)) {
name = 0;
} else {
/* If we have a :: in the parameter name because we are accessing a static member of a class, say, then
we need to remove that prefix. */
while (Strstr(name, "::")) {
//XXX need to free.
name = NewStringf("%s", Strchr(name, ':') + 2);
if (debugMode)
Printf(stdout, "+++ parameter name with :: in it %s\n", name);
}
}
}
if (Len(name) == 0)
if (!name || Len(name) == 0)
name = NewStringf("s_arg%d", i+1);
name = replaceInitialDash(name);
@ -1903,6 +1902,8 @@ int R::functionWrapper(Node *n) {
"\n};\n",
"if(is(", name, ", \"NativeSymbolInfo\")) {\n",
name, " = ", name, "$address", ";\n}\n",
"if(is(", name, ", \"ExternalReference\")) {\n",
name, " = ", name, "@ref;\n}\n",
"}; \n",
NIL);
} else {
@ -2112,7 +2113,7 @@ int R::functionWrapper(Node *n) {
{
String *finalizer = NewString(iname);
Replace(finalizer, "new_", "", DOH_REPLACE_FIRST);
Printf(sfun->code, "reg.finalizer(ans, delete_%s)\n", finalizer);
Printf(sfun->code, "reg.finalizer(ans@ref, delete_%s)\n", finalizer);
}
Printf(sfun->code, "ans\n");
}
@ -2348,7 +2349,7 @@ int R::classDeclaration(Node *n) {
elName = Getattr(c, "name");
String *elKind = Getattr(c, "kind");
if (Strcmp(elKind, "variable") != 0) {
if (!Equal(elKind, "variable")) {
c = nextSibling(c);
continue;
}
@ -2450,8 +2451,7 @@ int R::generateCopyRoutines(Node *n) {
continue;
}
String *elKind = Getattr(c, "kind");
if (Strcmp(elKind, "variable") != 0) {
Delete(elKind);
if (!Equal(elKind, "variable")) {
continue;
}

View file

@ -11,8 +11,6 @@
* Ruby language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_ruby_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
@ -128,7 +126,8 @@ enum autodoc_t {
AUTODOC_FUNC,
AUTODOC_METHOD,
AUTODOC_GETTER,
AUTODOC_SETTER
AUTODOC_SETTER,
AUTODOC_NONE
};
static const char *usage = (char *) "\
@ -203,13 +202,11 @@ private:
autodoc_t last_mode;
String* last_autodoc;
autodoc_l autodoc_level(String *autodoc) {
autodoc_l dlevel = NO_AUTODOC;
if (autodoc) {
char *c = Char(autodoc);
if (c && isdigit(c[0])) {
char *c = Char(autodoc);
if (c) {
if (isdigit(c[0])) {
dlevel = (autodoc_l) atoi(c);
} else {
if (strcmp(c, "extended") == 0) {
@ -496,7 +493,7 @@ private:
String* full_name;
if ( module ) {
full_name = NewString(module);
if (class_name && Len(class_name) > 0)
if (Len(class_name) > 0)
Append(full_name, "::");
}
else
@ -602,6 +599,8 @@ private:
case AUTODOC_SETTER:
Printf(doc, " Document-method: %s.%s=\n\n", full_name, symname);
break;
case AUTODOC_NONE:
break;
}
}
@ -689,6 +688,8 @@ private:
Printf(doc, " -> %s", type_str);
break;
}
case AUTODOC_NONE:
break;
}
}
@ -723,6 +724,8 @@ private:
case AUTODOC_SETTER:
Printf(doc, "Set new value for attribute.\n");
break;
case AUTODOC_NONE:
break;
}
}
@ -732,10 +735,6 @@ private:
String *autodoc = Getattr(n, "feature:autodoc");
autodoc_l dlevel = autodoc_level(autodoc);
symname = Getattr(n, "sym:name");
if ( Getattr( special_methods, symname ) )
symname = Getattr( special_methods, symname );
switch (dlevel) {
case NO_AUTODOC:
case NAMES_AUTODOC:
@ -791,11 +790,7 @@ private:
}
if (Strcmp(v, "NULL") == 0)
return SwigType_ispointer(t) ? NewString("nil") : NewString("0");
else if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
return NewString("true");
else if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("false");
if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0)
if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
return NewString("True");
if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("False");
@ -810,33 +805,38 @@ public:
*
* Initialize member data
* --------------------------------------------------------------------- */
RUBY() {
module = 0;
modvar = 0;
feature = 0;
prefix = 0;
last_autodoc = NewString("");
current = NO_CPP;
classes = 0;
klass = 0;
special_methods = 0;
f_begin = 0;
f_runtime = 0;
f_header = 0;
f_wrappers = 0;
f_init = 0;
f_initbeforefunc = 0;
useGlobalModule = false;
multipleInheritance = false;
director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code,
"if ( $comparison ) { /* subclassed */\n",
" $director_new \n",
"} else {\n", " rb_raise(rb_eRuntimeError,\"accessing abstract class or protected constructor\"); \n", " return Qnil;\n", "}\n", NIL);
director_multiple_inheritance = 0;
director_language = 1;
}
RUBY() :
module(0),
modvar(0),
feature(0),
prefix(0),
current(0),
classes(0),
klass(0),
special_methods(0),
f_directors(0),
f_directors_h(0),
f_directors_helpers(0),
f_begin(0),
f_runtime(0),
f_runtime_h(0),
f_header(0),
f_wrappers(0),
f_init(0),
f_initbeforefunc(0),
useGlobalModule(false),
multipleInheritance(false),
last_mode(AUTODOC_NONE),
last_autodoc(NewString("")) {
current = NO_CPP;
director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code,
"if ( $comparison ) { /* subclassed */\n",
" $director_new \n",
"} else {\n", " rb_raise(rb_eRuntimeError,\"accessing abstract class or protected constructor\"); \n", " return Qnil;\n", "}\n", NIL);
director_multiple_inheritance = 0;
director_language = 1;
}
/* ---------------------------------------------------------------------
* main()
@ -1138,8 +1138,11 @@ public:
Printf(f_directors, "/* ---------------------------------------------------\n");
Printf(f_directors, " * C++ director class methods\n");
Printf(f_directors, " * --------------------------------------------------- */\n\n");
if (outfile_h)
Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
if (outfile_h) {
String *filename = Swig_file_filename(outfile_h);
Printf(f_directors, "#include \"%s\"\n\n", filename);
Delete(filename);
}
Delete(module_macro);
}
@ -1185,7 +1188,7 @@ public:
Dump(f_directors_h, f_runtime_h);
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
Close(f_runtime_h);
Delete(f_runtime_h);
}
Dump(f_wrappers, f_begin);
@ -1196,7 +1199,6 @@ public:
Delete(f_wrappers);
Delete(f_init);
Delete(f_initbeforefunc);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -1271,13 +1273,15 @@ public:
}
m = Next(m);
}
if (feature == 0) {
feature = Copy(last);
if (last) {
if (feature == 0) {
feature = Copy(last);
}
(Char(last))[0] = (char)toupper((Char(last))[0]);
modvar = NewStringf("m%s", last);
}
(Char(last))[0] = (char)toupper((Char(last))[0]);
modvar = NewStringf("m%s", last);
Delete(modules);
}
Delete(modules);
}
Delete(mod_name);
}
@ -3017,18 +3021,17 @@ public:
virtual int classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
String *decl;
String *type;
String *name;
String *classname;
String *decl = Getattr(n, "decl");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *symname = Getattr(n, "sym:name");
String *declaration;
ParmList *l;
Wrapper *w;
String *declaration = NewString("");
ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *return_type;
String *returntype = Getattr(n, "type");
Parm *p;
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");
@ -3049,35 +3052,15 @@ public:
Printf(overnametmp, "::%s", Getattr(n, "sym:overname"));
}
classname = Getattr(parent, "sym:name");
type = Getattr(n, "type");
name = Getattr(n, "name");
w = NewWrapper();
declaration = NewString("");
/* determine if the method returns a pointer */
decl = Getattr(n, "decl");
is_pointer = SwigType_ispointer_return(decl);
is_void = (!Cmp(type, "void") && !is_pointer);
/* form complete return type */
return_type = Copy(type);
{
SwigType *t = Copy(decl);
SwigType *f = 0;
f = SwigType_pop_function(t);
SwigType_push(return_type, t);
Delete(f);
Delete(t);
}
is_void = (!Cmp(returntype, "void") && !is_pointer);
/* virtual method definition */
l = Getattr(n, "parms");
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s", target);
Delete(qualified_name);
@ -3100,7 +3083,7 @@ public:
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
@ -3128,7 +3111,7 @@ public:
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL);
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
}
}
@ -3295,14 +3278,7 @@ public:
/* Marshal return value */
if (!is_void) {
/* This seems really silly. The node's type excludes qualifier/pointer/reference markers,
* which have to be retrieved from the decl field to construct return_type. But the typemap
* lookup routine uses the node's type, so we have to swap in and out the correct type.
* It's not just me, similar silliness also occurs in Language::cDeclaration().
*/
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
Setattr(n, "type", type);
if (tm != 0) {
if (outputs > 1 && !asvoid ) {
Printf(w->code, "output = rb_ary_entry(%s, %d);\n", Swig_cresult_name(), idx++);
@ -3320,7 +3296,7 @@ public:
Printv(w->code, tm, "\n", NIL);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0),
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0),
SwigType_namestr(c_classname), SwigType_namestr(name));
status = SWIG_ERROR;
}
@ -3351,8 +3327,8 @@ public:
/* any existing helper functions to handle this? */
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *rettype = SwigType_str(return_type, 0);
if (!SwigType_isreference(return_type)) {
String *rettype = SwigType_str(returntype, 0);
if (!SwigType_isreference(returntype)) {
Printf(w->code, "return (%s) c_result;\n", rettype);
} else {
Printf(w->code, "return (%s) *c_result;\n", rettype);
@ -3390,7 +3366,6 @@ public:
/* clean up */
Delete(wrap_args);
Delete(return_type);
Delete(pclassname);
DelWrapper(w);
return status;

View file

@ -11,8 +11,6 @@
* A parse tree represented as Lisp s-expressions.
* ----------------------------------------------------------------------------- */
char cvsroot_s_exp_cxx[] = "$Id$";
#include "swigmod.h"
#include "dohint.h"
@ -24,9 +22,21 @@ S-Exp Options (available with -sexp)\n\
static File *out = 0;
class Sexp:public Language {
public:
int indent_level;
Sexp():indent_level(0) {
DOHHash *print_circle_hash;
int print_circle_count;
int hanging_parens;
bool need_whitespace;
bool need_newline;
public:
Sexp():
indent_level(0),
print_circle_hash(0),
print_circle_count(0),
hanging_parens(0),
need_whitespace(0),
need_newline(0) {
}
virtual ~ Sexp() {
@ -51,12 +61,6 @@ public:
}
}
DOHHash *print_circle_hash;
int print_circle_count;
int hanging_parens;
bool need_whitespace;
bool need_newline;
/* Top of the parse tree */
virtual int top(Node *n) {
if (out == 0) {
@ -81,7 +85,7 @@ public:
Language::top(n);
Printf(out, "\n");
Printf(out, ";;; Lisp parse tree produced by SWIG\n");
print_circle_hash = DohNewHash();
print_circle_hash = NewHash();
print_circle_count = 0;
hanging_parens = 0;
need_whitespace = 0;
@ -310,7 +314,7 @@ public:
close_paren();
} else {
// What is it?
Printf(out, "#<DOH %s %x>", ObjType(obj)->objname, obj);
Printf(out, "#<DOH %s %p>", ObjType(obj)->objname, obj);
}
}
}

View file

@ -16,8 +16,6 @@
* to SWIG, you would modify this file.
* ----------------------------------------------------------------------------- */
char cvsroot_swigmain_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>

View file

@ -120,6 +120,8 @@ public:
virtual ~Language();
virtual int emit_one(Node *n);
String *directorClassName(Node *n);
/* Parse command line options */
virtual void main(int argc, char *argv[]);
@ -294,6 +296,10 @@ protected:
/* Some language modules require additional wrappers for virtual methods not declared in sub-classes */
virtual bool extraDirectorProtectedCPPMethodsRequired() const;
/* Identifies if a protected members that are generated when the allprotected option is used.
This does not include protected virtual methods as they are turned on with the dirprot option. */
bool isNonVirtualProtectedAccess(Node *n) const;
/* Director subclass comparison test */
String *none_comparison;

View file

@ -11,8 +11,6 @@
* Tcl8 language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_tcl8_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
@ -185,7 +183,7 @@ public:
/* If shadow classing is enabled, we're going to change the module name to "_module" */
if (itcl) {
String *filen;
filen = NewStringf("%s%s.itcl", Swig_file_dirname(outfile), module);
filen = NewStringf("%s%s.itcl", SWIG_output_directory(), module);
Insert(module, 0, "_");
@ -248,7 +246,6 @@ public:
if (itcl) {
Printv(f_shadow, f_shadow_stubs, "\n", NIL);
Close(f_shadow);
Delete(f_shadow);
}
@ -259,7 +256,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -748,6 +744,7 @@ public:
have_constructor = 0;
have_destructor = 0;
destructor_action = 0;
constructor_name = 0;
if (itcl) {
constructor = NewString("");
@ -944,7 +941,7 @@ public:
Printv(f_shadow, " constructor { } {\n", NIL);
Printv(f_shadow, " # This constructor will fail if called directly\n", NIL);
Printv(f_shadow, " if { [info class] == \"::", class_name, "\" } {\n", NIL);
Printv(f_shadow, " error \"No constructor for class ", class_name, (Getattr(n, "abstract") ? " - class is abstract" : ""), "\"\n", NIL);
Printv(f_shadow, " error \"No constructor for class ", class_name, (Getattr(n, "abstracts") ? " - class is abstract" : ""), "\"\n", NIL);
Printv(f_shadow, " }\n", NIL);
Printv(f_shadow, " }\n", NIL);
}
@ -1206,7 +1203,8 @@ public:
}
}
constructor_name = NewString(Getattr(n, "sym:name"));
if (!have_constructor)
constructor_name = NewString(Getattr(n, "sym:name"));
have_constructor = 1;
return SWIG_OK;
}

View file

@ -16,8 +16,6 @@
* and other information needed for compilation.
* ----------------------------------------------------------------------------- */
char cvsroot_typepass_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
@ -40,7 +38,14 @@ class TypePass:private Dispatcher {
Hash *classhash;
List *normalize;
TypePass() {
TypePass() :
inclass(0),
module(0),
importmode(0),
nsname(0),
nssymname(0),
classhash(0),
normalize(0) {
}
/* Normalize a type. Replaces type with fully qualified version */
@ -185,9 +190,14 @@ class TypePass:private Dispatcher {
bcls = 0;
} else {
if (Getattr(bcls, "typepass:visit")) {
if (!ilist)
ilist = alist = NewList();
Append(ilist, bcls);
if (!Getattr(bcls, "feature:onlychildren")) {
if (!ilist)
ilist = alist = NewList();
Append(ilist, bcls);
} else {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
}
} else {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' undefined.\n", SwigType_namestr(bname));
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "'%s' must be defined before it is used as a base class.\n", SwigType_namestr(bname));
@ -560,12 +570,9 @@ class TypePass:private Dispatcher {
if (alias) {
Typetab *ts = Getattr(n, "typescope");
if (!ts) {
Node *ns;
/* Create a empty scope for the alias */
ns = Getattr(n, "namespace");
if (ns) {
SwigType_scope_alias(name, Getattr(ns, "typescope"));
}
/* Create an empty scope for the alias */
Node *ns = Getattr(n, "namespace");
SwigType_scope_alias(name, Getattr(ns, "typescope"));
ts = Getattr(ns, "typescope");
Setattr(n, "typescope", ts);
}
@ -697,11 +704,6 @@ class TypePass:private Dispatcher {
normalize_parms(Getattr(n, "parms"));
normalize_parms(Getattr(n, "throws"));
/* If in a namespace, patch the class name */
if (nsname) {
String *nname = NewStringf("%s::%s", nsname, Getattr(n, "name"));
Setattr(n, "name", nname);
}
clean_overloaded(n);
return SWIG_OK;
}
@ -710,12 +712,7 @@ class TypePass:private Dispatcher {
* destructorDeclaration()
* ------------------------------------------------------------ */
virtual int destructorDeclaration(Node *n) {
/* If in a namespace, patch the class name */
if (nsname) {
String *nname = NewStringf("%s::%s", nsname, Getattr(n, "name"));
Setattr(n, "name", nname);
}
virtual int destructorDeclaration(Node *) {
return SWIG_OK;
}
@ -886,7 +883,22 @@ class TypePass:private Dispatcher {
// Use enumDeclaration() to do all the hard work.
// Note that no children can be emitted in a forward declaration as there aren't any.
return enumDeclaration(n);
int result = enumDeclaration(n);
if (result == SWIG_OK) {
// Detect when the real enum matching the forward enum declaration has not been parsed/declared
SwigType *ty = SwigType_typedef_resolve_all(Getattr(n, "type"));
Replaceall(ty, "enum ", "");
Node *nn = Swig_symbol_clookup(ty, 0);
String *nodetype = nn ? nodeType(nn) : 0;
if (nodetype) {
if (Equal(nodetype, "enumforward")) {
SetFlag(nn, "enumMissing");
} // if a real enum was declared this would be an "enum" node type
}
Delete(ty);
}
return result;
}
#ifdef DEBUG_OVERLOADED
@ -1144,6 +1156,11 @@ class TypePass:private Dispatcher {
SwigType_typedef_using(uname);
} else if (Strcmp(ntype, "enum") == 0) {
SwigType_typedef_using(Getattr(n, "uname"));
} else if (Strcmp(ntype, "template") == 0) {
/*
Printf(stdout, "usingDeclaration template %s --- %s\n", Getattr(n, "name"), Getattr(n, "uname"));
SwigType_typedef_using(Getattr(n, "uname"));
*/
}
}
}

View file

@ -13,8 +13,6 @@
// TODO: remove remnants of lisptype
char cvsroot_uffi_cxx[] = "$Id$";
#include "swigmod.h"
static const char *usage = (char *) "\
@ -47,7 +45,7 @@ static struct {
String **entries;
} defined_foreign_types;
static const char *identifier_converter = "identifier-convert-null";
static String *identifier_converter = NewString("identifier-convert-null");
static int any_varargs(ParmList *pl) {
Parm *p;
@ -221,14 +219,15 @@ void UFFI::main(int argc, char *argv[]) {
/* check for built-ins */
if (!strcmp(conv, "lispify")) {
identifier_converter = "identifier-convert-lispify";
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-lispify");
} else if (!strcmp(conv, "null")) {
identifier_converter = "identifier-convert-null";
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-null");
} else {
/* Must be user defined */
char *idconv = new char[strlen(conv) + 1];
strcpy(idconv, conv);
identifier_converter = idconv;
Delete(identifier_converter);
identifier_converter = NewString(conv);
}
}
@ -266,9 +265,7 @@ int UFFI::top(Node *n) {
Language::top(n);
Close(f_cl);
Delete(f_cl); // Delete the handle, not the file
Close(f_null);
Delete(f_null);
return SWIG_OK;

View file

@ -11,8 +11,6 @@
* Various utility functions.
* ----------------------------------------------------------------------------- */
char cvsroot_utils_cxx[] = "$Id$";
#include <swigmod.h>
int is_public(Node *n) {

View file

@ -11,8 +11,6 @@
* An Xml parse tree generator.
* ----------------------------------------------------------------------------- */
char cvsroot_xml_cxx[] = "$Id$";
#include "swigmod.h"
static const char *usage = "\
@ -118,7 +116,7 @@ public:
String *k;
indent_level += 4;
print_indent(0);
Printf(out, "<attributelist id=\"%ld\" addr=\"%x\" >\n", ++id, obj);
Printf(out, "<attributelist id=\"%ld\" addr=\"%p\" >\n", ++id, obj);
indent_level += 4;
Iterator ki;
ki = First(obj);
@ -160,14 +158,14 @@ public:
Replaceall(o, "\"", "&quot;");
Replaceall(o, "\\", "\\\\");
Replaceall(o, "\n", "&#10;");
Printf(out, "<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o);
Printf(out, "<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%p\" />\n", ck, o, ++id, o);
Delete(o);
Delete(ck);
} else {
o = Getattr(obj, k);
String *ck = NewString(k);
Replaceall(ck, ":", "_");
Printf(out, "<attribute name=\"%s\" value=\"%x\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o);
Printf(out, "<attribute name=\"%s\" value=\"%p\" id=\"%ld\" addr=\"%p\" />\n", ck, o, ++id, o);
Delete(ck);
}
}
@ -183,7 +181,7 @@ public:
Node *cobj;
print_indent(0);
Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", nodeType(obj), ++id, obj);
Printf(out, "<%s id=\"%ld\" addr=\"%p\" >\n", nodeType(obj), ++id, obj);
Xml_print_attributes(obj);
cobj = firstChild(obj);
if (cobj) {
@ -203,7 +201,7 @@ public:
void Xml_print_parmlist(ParmList *p, const char* markup = "parmlist") {
print_indent(0);
Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p);
Printf(out, "<%s id=\"%ld\" addr=\"%p\" >\n", markup, ++id, p);
indent_level += 4;
while (p) {
print_indent(0);
@ -221,13 +219,13 @@ public:
void Xml_print_baselist(List *p) {
print_indent(0);
Printf(out, "<baselist id=\"%ld\" addr=\"%x\" >\n", ++id, p);
Printf(out, "<baselist id=\"%ld\" addr=\"%p\" >\n", ++id, p);
indent_level += 4;
Iterator s;
for (s = First(p); s.item; s = Next(s)) {
print_indent(0);
String *item_name = Xml_escape_string(s.item);
Printf(out, "<base name=\"%s\" id=\"%ld\" addr=\"%x\" />\n", item_name, ++id, s.item);
Printf(out, "<base name=\"%s\" id=\"%ld\" addr=\"%p\" />\n", item_name, ++id, s.item);
Delete(item_name);
}
indent_level -= 4;
@ -251,7 +249,7 @@ public:
void Xml_print_module(Node *p) {
print_indent(0);
Printf(out, "<attribute name=\"module\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", Getattr(p, "name"), ++id, p);
Printf(out, "<attribute name=\"module\" value=\"%s\" id=\"%ld\" addr=\"%p\" />\n", Getattr(p, "name"), ++id, p);
}
void Xml_print_kwargs(Hash *p) {
@ -272,13 +270,13 @@ public:
void Xml_print_hash(Hash *p, const char *markup) {
print_indent(0);
Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p);
Printf(out, "<%s id=\"%ld\" addr=\"%p\" >\n", markup, ++id, p);
Xml_print_attributes(p);
indent_level += 4;
Iterator n = First(p);
while (n.key) {
print_indent(0);
Printf(out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item);
Printf(out, "<%ssitem id=\"%ld\" addr=\"%p\" >\n", markup, ++id, n.item);
Xml_print_attributes(n.item);
print_indent(0);
Printf(out, "</%ssitem >\n", markup);

View file

@ -17,8 +17,6 @@
* - Lines beginning with %# are stripped down to #... and passed through.
* ----------------------------------------------------------------------------- */
char cvsroot_cpp_c[] = "$Id$";
#include "swig.h"
#include "preprocessor.h"
#include <ctype.h>
@ -583,7 +581,8 @@ static List *find_args(String *s, int ismacro, String *macro_name) {
c = Getc(s);
if (c != '(') {
/* Not a macro, bail out now! */
Seek(s, pos, SEEK_SET);
assert(pos != -1);
(void)Seek(s, pos, SEEK_SET);
Delete(args);
return 0;
}
@ -1213,13 +1212,10 @@ static DOH *Preprocessor_replace(DOH *s) {
Replaceall(fn, "\\", "\\\\");
Printf(ns, "\"%s\"", fn);
Delete(fn);
} else if ((m = Getattr(symbols, id))) {
} else if (Getattr(symbols, id)) {
DOH *e;
/* Yes. There is a macro here */
/* See if the macro expects arguments */
/* if (Getattr(m,"args")) {
Swig_error(Getfile(id),Getline(id),"Macro arguments expected.\n");
} */
e = expand_macro(id, 0, s);
if (e)
Append(ns, e);
@ -1639,7 +1635,7 @@ String *Preprocessor_parse(String *s) {
if (Len(sval) > 0) {
val = Preprocessor_expr(sval, &e);
if (e) {
char *msg = Preprocessor_expr_error();
const char *msg = Preprocessor_expr_error();
Seek(value, 0, SEEK_SET);
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Could not evaluate expression '%s'\n", value);
if (msg)
@ -1673,7 +1669,7 @@ String *Preprocessor_parse(String *s) {
if (Len(sval) > 0) {
val = Preprocessor_expr(sval, &e);
if (e) {
char *msg = Preprocessor_expr_error();
const char *msg = Preprocessor_expr_error();
Seek(value, 0, SEEK_SET);
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Could not evaluate expression '%s'\n", value);
if (msg)
@ -1708,7 +1704,7 @@ String *Preprocessor_parse(String *s) {
} else if (Equal(id, kpp_include)) {
if (((include_all) || (import_all)) && (allow)) {
String *s1, *s2, *fn;
char *dirname;
String *dirname;
int sysfile = 0;
if (include_all && import_all) {
Swig_warning(WARN_PP_INCLUDEALL_IMPORTALL, Getfile(s), Getline(id), "Both includeall and importall are defined: using includeall.\n");
@ -1727,10 +1723,13 @@ String *Preprocessor_parse(String *s) {
/* See if the filename has a directory component */
dirname = Swig_file_dirname(Swig_last_file());
if (sysfile || !strlen(dirname))
if (sysfile || !Len(dirname)) {
Delete(dirname);
dirname = 0;
}
if (dirname) {
dirname[strlen(dirname) - 1] = 0; /* Kill trailing directory delimiter */
int len = Len(dirname);
Delslice(dirname, len - 1, len); /* Kill trailing directory delimiter */
Swig_push_directory(dirname);
}
s2 = Preprocessor_parse(s1);
@ -1743,6 +1742,7 @@ String *Preprocessor_parse(String *s) {
pop_imported();
}
Delete(s2);
Delete(dirname);
Delete(s1);
}
Delete(fn);
@ -1860,7 +1860,7 @@ String *Preprocessor_parse(String *s) {
fn = get_filename(s, &sysfile);
s1 = cpp_include(fn, sysfile);
if (s1) {
char *dirname;
String *dirname;
copy_location(s, chunk);
add_chunk(ns, chunk, allow);
Printf(ns, "%sfile%s%s%s\"%s\" %%beginfile\n", decl, options_whitespace, opt, filename_whitespace, Swig_filename_escape(Swig_last_file()));
@ -1868,10 +1868,13 @@ String *Preprocessor_parse(String *s) {
push_imported();
}
dirname = Swig_file_dirname(Swig_last_file());
if (sysfile || !strlen(dirname))
if (sysfile || !Len(dirname)) {
Delete(dirname);
dirname = 0;
}
if (dirname) {
dirname[strlen(dirname) - 1] = 0; /* Kill trailing directory delimiter */
int len = Len(dirname);
Delslice(dirname, len - 1, len); /* Kill trailing directory delimiter */
Swig_push_directory(dirname);
}
s2 = Preprocessor_parse(s1);
@ -1884,6 +1887,7 @@ String *Preprocessor_parse(String *s) {
addline(ns, s2, allow);
Append(ns, "%endoffile");
Delete(s2);
Delete(dirname);
Delete(s1);
}
Delete(fn);

View file

@ -12,8 +12,6 @@
* encountered during preprocessing.
* ----------------------------------------------------------------------------- */
char cvsroot_expr_c[] = "$Id$";
#include "swig.h"
#include "preprocessor.h"
@ -35,7 +33,7 @@ static exprval stack[256]; /* Parsing stack */
static int sp = 0; /* Stack pointer */
static int prec[256]; /* Precedence rules */
static int expr_init = 0; /* Initialization flag */
static char *errmsg = 0; /* Parsing error */
static const char *errmsg = 0; /* Parsing error */
/* Initialize the precedence table for various operators. Low values have higher precedence */
static void init_precedence() {
@ -435,6 +433,6 @@ extra_rparen:
* Return error message set by the evaluator (if any)
* ----------------------------------------------------------------------------- */
char *Preprocessor_expr_error() {
const char *Preprocessor_expr_error() {
return errmsg;
}

View file

@ -20,7 +20,7 @@
extern "C" {
#endif
extern int Preprocessor_expr(String *s, int *error);
extern char *Preprocessor_expr_error(void);
extern const char *Preprocessor_expr_error(void);
extern Hash *Preprocessor_define(const_String_or_char_ptr str, int swigmacro);
extern void Preprocessor_undef(const_String_or_char_ptr name);
extern void Preprocessor_init(void);

View file

@ -12,8 +12,6 @@
* the naming of local variables, calling conventions, and so forth.
* ----------------------------------------------------------------------------- */
char cvsroot_cwrap_c[] = "$Id$";
#include "swig.h"
extern int cparse_cplusplus;
@ -759,6 +757,46 @@ String *Swig_cmemberget_call(const_String_or_char_ptr name, SwigType *t, String
return func;
}
/* -----------------------------------------------------------------------------
* Swig_replace_special_variables()
*
* Replaces special variables with a value from the supplied node
* ----------------------------------------------------------------------------- */
void Swig_replace_special_variables(Node *n, Node *parentnode, String *code) {
Node *parentclass = parentnode;
String *overloaded = Getattr(n, "sym:overloaded");
Replaceall(code, "$name", Getattr(n, "name"));
Replaceall(code, "$symname", Getattr(n, "sym:name"));
Replaceall(code, "$wrapname", Getattr(n, "wrap:name"));
Replaceall(code, "$overname", overloaded ? Char(Getattr(n, "sym:overname")) : "");
if (Strstr(code, "$decl")) {
String *decl = Swig_name_decl(n);
Replaceall(code, "$decl", decl);
Delete(decl);
}
if (Strstr(code, "$fulldecl")) {
String *fulldecl = Swig_name_fulldecl(n);
Replaceall(code, "$fulldecl", fulldecl);
Delete(fulldecl);
}
if (parentclass && !Equal(nodeType(parentclass), "class"))
parentclass = 0;
if (Strstr(code, "$parentclasssymname")) {
String *parentclasssymname = 0;
if (parentclass)
parentclasssymname = Getattr(parentclass, "sym:name");
Replaceall(code, "$parentclasssymname", parentclasssymname ? parentclasssymname : "");
}
if (Strstr(code, "$parentclassname")) {
String *parentclassname = 0;
if (parentclass)
parentclassname = Getattr(parentclass, "name");
Replaceall(code, "$parentclassname", parentclassname ? parentclassname : "");
}
}
/* -----------------------------------------------------------------------------
* extension_code()
*
@ -767,14 +805,17 @@ String *Swig_cmemberget_call(const_String_or_char_ptr name, SwigType *t, String
* return_type function_name(parms) code
*
* ----------------------------------------------------------------------------- */
static String *extension_code(const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) {
static String *extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) {
String *parms_str = cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms);
String *sig = NewStringf("%s(%s)", function_name, parms_str);
String *sig = NewStringf("%s(%s)", function_name, (cplusplus || Len(parms_str)) ? parms_str : "void");
String *rt_sig = SwigType_str(return_type, sig);
String *body = NewStringf("SWIGINTERN %s", rt_sig);
Printv(body, code, "\n", NIL);
if (self)
Replaceall(body, "$self", self);
if (Strstr(body, "$")) {
Swig_replace_special_variables(n, parentNode(parentNode(n)), body);
if (self)
Replaceall(body, "$self", self);
}
Delete(parms_str);
Delete(sig);
Delete(rt_sig);
@ -791,7 +832,7 @@ static String *extension_code(const String *function_name, ParmList *parms, Swig
*
* ----------------------------------------------------------------------------- */
int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) {
String *body = extension_code(function_name, parms, return_type, code, cplusplus, self);
String *body = extension_code(n, function_name, parms, return_type, code, cplusplus, self);
Setattr(n, "wrap:code", body);
Delete(body);
return SWIG_OK;
@ -812,6 +853,9 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
String *self = 0;
int is_smart_pointer_overload = 0;
String *qualifier = Getattr(n, "qualifier");
String *directorScope = NewString(nspace);
Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
/* If smart pointer without const overload or mutable method, change self dereferencing */
if (flags & CWRAP_SMART_POINTER) {
@ -894,7 +938,10 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
/* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */
String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname"));
explicitcall_name = NewStringf("%sSwigPublic", name);
explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp);
if (Len(directorScope) > 0)
explicit_qualifier = NewStringf("SwigDirector_%s_%s", directorScope, explicit_qualifier_tmp);
else
explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp);
Delete(explicit_qualifier_tmp);
} else {
explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname"));
@ -1014,6 +1061,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
Delete(p);
Delete(self);
Delete(parms);
Delete(directorScope);
return SWIG_OK;
}
@ -1064,6 +1112,9 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
ParmList *directorparms;
SwigType *type;
int use_director;
String *directorScope = NewString(nspace);
Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
use_director = Swig_directorclass(n);
@ -1122,14 +1173,19 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
/* if a C++ director class exists, create it rather than the original class */
if (use_director) {
Node *parent = Swig_methodclass(n);
int abstract = Getattr(parent, "abstract") != 0;
int abstract = Getattr(parent, "abstracts") != 0;
String *name = Getattr(parent, "sym:name");
String *directorname = NewStringf("SwigDirector_%s", name);
String *directorname;
String *action = NewStringEmpty();
String *tmp_none_comparison = Copy(none_comparison);
String *director_call;
String *nodirector_call;
if (Len(directorScope) > 0)
directorname = NewStringf("SwigDirector_%s_%s", directorScope, name);
else
directorname = NewStringf("SwigDirector_%s", name);
Replaceall(tmp_none_comparison, "$arg", "arg1");
director_call = Swig_cppconstructor_director_call(directorname, directorparms);
@ -1190,6 +1246,7 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
if (directorparms != parms)
Delete(directorparms);
Delete(parms);
Delete(directorScope);
return SWIG_OK;
}

View file

@ -13,8 +13,6 @@
* that the function and/or API needs to be changed in some future release.
* ----------------------------------------------------------------------------- */
char cvsroot_deprecate_c[] = "$Id: parms.c 9630 2007-01-02 21:17:19Z beazley $";
#include "swig.h"
/* ---------------------------------------------------------------------

View file

@ -12,8 +12,6 @@
* error messages.
* ----------------------------------------------------------------------------- */
char cvsroot_error_c[] = "$Id$";
#include "swig.h"
#include <stdarg.h>
#include <ctype.h>

View file

@ -16,10 +16,9 @@
* wrapper code and to generate cleaner wrapper files.
* ----------------------------------------------------------------------------- */
char cvsroot_fragment_c[] = "$Id$";
#include "swig.h"
#include "swigwarn.h"
#include "cparse.h"
static Hash *fragments = 0;
static Hash *looking_fragments = 0;
@ -62,6 +61,8 @@ void Swig_fragment_register(Node *fragment) {
}
Setfile(ccode, Getfile(fragment));
Setline(ccode, Getline(fragment));
/* Replace $descriptor() macros */
Swig_cparse_replace_descriptor(ccode);
Setattr(fragments, name, ccode);
if (debug)
Printf(stdout, "registering fragment %s %s\n", name, section);

View file

@ -20,8 +20,6 @@
* Should have cleaner error handling in general.
* ----------------------------------------------------------------------------- */
char cvsroot_getopt_c[] = "$Id$";
#include "swig.h"
static char **args;

View file

@ -13,8 +13,6 @@
* are provided.
* ----------------------------------------------------------------------------- */
char cvsroot_include_c[] = "$Id$";
#include "swig.h"
static List *directories = 0; /* List of include directories */
@ -317,58 +315,41 @@ File *Swig_filebyname(const_String_or_char_ptr filename) {
}
/* -----------------------------------------------------------------------------
* Swig_file_suffix()
* Swig_file_extension()
*
* Returns the suffix of a file
* Returns the extension of a file
* ----------------------------------------------------------------------------- */
char *Swig_file_suffix(const_String_or_char_ptr filename) {
char *d;
char *c = Char(filename);
int len = Len(filename);
if (strlen(c)) {
d = c + len - 1;
while (d != c) {
if (*d == '.')
return d;
d--;
}
return c + len;
}
return c;
String *Swig_file_extension(const_String_or_char_ptr filename) {
String *name = Swig_file_filename(filename);
const char *c = strrchr(Char(name), '.');
String *extension = c ? NewString(c) : NewString("");
Delete(name);
return extension;
}
/* -----------------------------------------------------------------------------
* Swig_file_basename()
*
* Returns the filename with no suffix attached.
* Returns the filename with the extension removed.
* ----------------------------------------------------------------------------- */
char *Swig_file_basename(const_String_or_char_ptr filename) {
static char tmp[1024];
char *c;
strcpy(tmp, Char(filename));
c = Swig_file_suffix(tmp);
*c = 0;
return tmp;
String *Swig_file_basename(const_String_or_char_ptr filename) {
String *extension = Swig_file_extension(filename);
String *basename = NewStringWithSize(filename, Len(filename) - Len(extension));
Delete(extension);
return basename;
}
/* -----------------------------------------------------------------------------
* Swig_file_filename()
*
* Return the file with any leading path stripped off
* Return the file name with any leading path stripped off
* ----------------------------------------------------------------------------- */
char *Swig_file_filename(const_String_or_char_ptr filename) {
static char tmp[1024];
String *Swig_file_filename(const_String_or_char_ptr filename) {
const char *delim = SWIG_FILE_DELIMITER;
char *c;
strcpy(tmp, Char(filename));
c = strrchr(tmp, *delim);
if (c)
return c + 1;
else
return tmp;
const char *c = strrchr(Char(filename), *delim);
return c ? NewString(c + 1) : NewString(filename);
}
/* -----------------------------------------------------------------------------
@ -376,19 +357,10 @@ char *Swig_file_filename(const_String_or_char_ptr filename) {
*
* Return the name of the directory associated with a file
* ----------------------------------------------------------------------------- */
char *Swig_file_dirname(const_String_or_char_ptr filename) {
static char tmp[1024];
String *Swig_file_dirname(const_String_or_char_ptr filename) {
const char *delim = SWIG_FILE_DELIMITER;
char *c;
strcpy(tmp, Char(filename));
if (!strstr(tmp, delim)) {
return "";
}
c = tmp + strlen(tmp) - 1;
while (*c != *delim)
c--;
*(++c) = 0;
return tmp;
const char *c = strrchr(Char(filename), *delim);
return c ? NewStringWithSize(filename, c - Char(filename) + 1) : NewString("");
}
/*

View file

@ -11,8 +11,6 @@
* Miscellaneous functions that don't really fit anywhere else.
* ----------------------------------------------------------------------------- */
char cvsroot_misc_c[] = "$Id$";
#include "swig.h"
#include <errno.h>
#include <ctype.h>
@ -167,44 +165,36 @@ static int is_directory(String *directory) {
* Swig_new_subdirectory()
*
* Create the subdirectory only if the basedirectory already exists as a directory.
* basedirectory can be NULL or empty to indicate current directory.
* basedirectory can be empty to indicate current directory but not NULL.
* ----------------------------------------------------------------------------- */
String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) {
String *error = 0;
struct stat st;
int current_directory = basedirectory ? (Len(basedirectory) == 0 ? 1 : 0) : 0;
int current_directory = Len(basedirectory) == 0;
if (current_directory || is_directory(basedirectory)) {
Iterator it;
String *dir = basedirectory ? NewString(basedirectory) : NewString("");
String *dir = NewString(basedirectory);
List *subdirs = Split(subdirectory, SWIG_FILE_DELIMITER[0], INT_MAX);
for (it = First(subdirs); it.item; it = Next(it)) {
int statdir;
int result;
String *subdirectory = it.item;
Printf(dir, "%s", subdirectory);
statdir = stat(Char(dir), &st);
if (statdir == 0) {
Printf(dir, SWIG_FILE_DELIMITER);
if (S_ISDIR(st.st_mode)) {
continue;
} else {
error = NewStringf("Cannot create directory %s", dir);
break;
}
} else {
#ifdef _WIN32
int result = _mkdir(Char(dir));
result = _mkdir(Char(dir));
#else
int result = mkdir(Char(dir), 0777);
result = mkdir(Char(dir), 0777);
#endif
Printf(dir, SWIG_FILE_DELIMITER);
if (result != 0 && errno != EEXIST) {
error = NewStringf("Cannot create directory %s", dir);
break;
}
if (result != 0 && errno != EEXIST) {
error = NewStringf("Cannot create directory %s: %s", dir, strerror(errno));
break;
}
if (!is_directory(dir)) {
error = NewStringf("Cannot create directory %s: it may already exist but not be a directory", dir);
break;
}
Printf(dir, SWIG_FILE_DELIMITER);
}
} else {
error = NewStringf("Cannot create subdirectory %s under the base directory %s. Either the base does not exist as a directory or it is not readable.", subdirectory, basedirectory);
@ -880,8 +870,8 @@ String *Swig_scopename_last(const String *s) {
while (*c) {
if ((*c == ':') && (*(c + 1) == ':')) {
cc = c;
c += 2;
cc = c;
} else {
if (*c == '<') {
int level = 1;
@ -898,7 +888,7 @@ String *Swig_scopename_last(const String *s) {
}
}
}
return NewString(cc + 2);
return NewString(cc);
}
/* -----------------------------------------------------------------------------

View file

@ -20,8 +20,6 @@
* %v - variable name is substituted
* ----------------------------------------------------------------------------- */
char cvsroot_naming_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
#include <ctype.h>
@ -883,13 +881,16 @@ List *Swig_name_rename_list() {
int Swig_need_name_warning(Node *n) {
int need = 1;
/*
we don't use name warnings for:
We don't use name warnings for:
- class forwards, no symbol is generated at the target language.
- template declarations, only for real instances using %template(name).
- typedefs, they have no effect at the target language.
- typedefs, have no effect at the target language.
- using declarations and using directives, have no effect at the target language.
*/
if (checkAttribute(n, "nodeType", "classforward")) {
need = 0;
} else if (checkAttribute(n, "nodeType", "using")) {
need = 0;
} else if (checkAttribute(n, "storage", "typedef")) {
need = 0;
} else if (Getattr(n, "hidden")) {

View file

@ -11,21 +11,19 @@
* Parameter list class.
* ----------------------------------------------------------------------------- */
char cvsroot_parms_c[] = "$Id$";
#include "swig.h"
/* ------------------------------------------------------------------------
* NewParm()
*
* Create a new parameter from datatype 'type' and name 'name' copying
* the file and line number from the Node file_line_node.
* the file and line number from the Node from_node.
* ------------------------------------------------------------------------ */
Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *file_line_node) {
Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *from_node) {
Parm *p = NewParmWithoutFileLineInfo(type, name);
Setfile(p, Getfile(file_line_node));
Setline(p, Getline(file_line_node));
Setfile(p, Getfile(from_node));
Setline(p, Getline(from_node));
return p;
}
@ -48,6 +46,20 @@ Parm *NewParmWithoutFileLineInfo(SwigType *type, const_String_or_char_ptr name)
return p;
}
/* ------------------------------------------------------------------------
* NewParmNode()
*
* Create a new parameter from datatype 'type' and name and symbol table as
* well as file and line number from the 'from_node'.
* The resulting Parm will be similar to a Node used for typemap lookups.
* ------------------------------------------------------------------------ */
Parm *NewParmNode(SwigType *type, Node *from_node) {
Parm *p = NewParm(type, Getattr(from_node, "name"), from_node);
Setattr(p, "sym:symtab", Getattr(from_node, "sym:symtab"));
return p;
}
/* ------------------------------------------------------------------------
* CopyParm()
* ------------------------------------------------------------------------ */

View file

@ -14,8 +14,6 @@
* to easily construct yacc-compatible scanners.
* ----------------------------------------------------------------------------- */
char cvsroot_scanner_c[] = "$Id$";
#include "swig.h"
#include <ctype.h>
@ -65,6 +63,7 @@ Scanner *NewScanner(void) {
s->text = NewStringEmpty();
s->str = 0;
s->error = 0;
s->error_line = 0;
s->freeze_line = 0;
return s;
}
@ -104,6 +103,12 @@ void Scanner_clear(Scanner * s) {
s->nexttoken = -1;
s->start_line = 0;
s->yylen = 0;
/* Should these be cleared too?
s->idstart;
s->file;
s->error_line;
s->freeze_line;
*/
}
/* -----------------------------------------------------------------------------
@ -209,10 +214,8 @@ static char nextchar(Scanner * s) {
if (Len(s->scanobjs) == 0)
return 0;
s->str = Getitem(s->scanobjs, 0);
if (s->str) {
s->line = Getline(s->str);
DohIncref(s->str);
}
s->line = Getline(s->str);
DohIncref(s->str);
}
if ((nc == '\n') && (!s->freeze_line))
s->line++;
@ -273,7 +276,7 @@ static void retract(Scanner * s, int n) {
if (str[l - 1] == '\n') {
if (!s->freeze_line) s->line--;
}
Seek(s->str, -1, SEEK_CUR);
(void)Seek(s->str, -1, SEEK_CUR);
Delitem(s->text, DOH_END);
}
}
@ -1138,7 +1141,7 @@ void Scanner_skip_line(Scanner * s) {
if ((c = nextchar(s)) == 0)
return;
if (c == '\\') {
c = nextchar(s);
nextchar(s);
} else if (c == '\n') {
done = 1;
}
@ -1319,7 +1322,7 @@ void Scanner_locator(Scanner *s, String *loc) {
} else {
int c;
Locator *l;
Seek(loc, 7, SEEK_SET);
(void)Seek(loc, 7, SEEK_SET);
c = Getc(loc);
if (c == '@') {
/* Empty locator. We pop the last location off */

View file

@ -12,8 +12,6 @@
* the form of simple strings.
* ----------------------------------------------------------------------------- */
char cvsroot_stype_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
#include <ctype.h>
@ -642,7 +640,6 @@ SwigType *SwigType_ltype(const SwigType *s) {
if (td && (SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) {
/* We need to use the typedef type */
Delete(tt);
tt = td;
break;
} else if (td) {
Delete(tt);

View file

@ -227,6 +227,7 @@ extern "C" {
extern void Swig_symbol_cadd(const_String_or_char_ptr symname, Node *node);
extern Node *Swig_symbol_clookup(const_String_or_char_ptr symname, Symtab *tab);
extern Node *Swig_symbol_clookup_check(const_String_or_char_ptr symname, Symtab *tab, int (*check) (Node *));
extern Node *Swig_symbol_clookup_no_inherit(const_String_or_char_ptr name, Symtab *n);
extern Symtab *Swig_symbol_cscope(const_String_or_char_ptr symname, Symtab *tab);
extern Node *Swig_symbol_clookup_local(const_String_or_char_ptr symname, Symtab *tab);
extern Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr symname, Symtab *tab, int (*check) (Node *));
@ -353,6 +354,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern String *Swig_cmemberget_call(const_String_or_char_ptr name, SwigType *t, String *self, int varcref);
extern int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self);
extern void Swig_replace_special_variables(Node *n, Node *parentnode, String *code);
/* --- Transformations --- */

View file

@ -26,10 +26,10 @@ extern void Swig_set_push_dir(int dopush);
extern int Swig_get_push_dir(void);
extern void Swig_register_filebyname(const_String_or_char_ptr filename, File *outfile);
extern File *Swig_filebyname(const_String_or_char_ptr filename);
extern char *Swig_file_suffix(const_String_or_char_ptr filename);
extern char *Swig_file_basename(const_String_or_char_ptr filename);
extern char *Swig_file_filename(const_String_or_char_ptr filename);
extern char *Swig_file_dirname(const_String_or_char_ptr filename);
extern String *Swig_file_extension(const_String_or_char_ptr filename);
extern String *Swig_file_basename(const_String_or_char_ptr filename);
extern String *Swig_file_filename(const_String_or_char_ptr filename);
extern String *Swig_file_dirname(const_String_or_char_ptr filename);
extern void Swig_file_debug_set();
/* Delimiter used in accessing files and directories */

View file

@ -13,8 +13,9 @@
* ----------------------------------------------------------------------------- */
/* Individual parameters */
extern Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *file_line_node);
extern Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *from_node);
extern Parm *NewParmWithoutFileLineInfo(SwigType *type, const_String_or_char_ptr name);
extern Parm *NewParmNode(SwigType *type, Node *from_node);
extern Parm *CopyParm(Parm *p);
/* Parameter lists */

View file

@ -11,8 +11,6 @@
* This file implements the SWIG symbol table. See details below.
* ----------------------------------------------------------------------------- */
char cvsroot_symbol_c[] = "$Id$";
#include "swig.h"
#include "swigwarn.h"
#include <ctype.h>
@ -176,6 +174,8 @@ static Hash *current_symtab = 0; /* Current symbol table node */
static Hash *symtabs = 0; /* Hash of all symbol tables by fully-qualified name */
static Hash *global_scope = 0; /* Global scope */
static int use_inherit = 1;
/* common attribute keys, to avoid calling find_key all the times */
@ -222,7 +222,7 @@ static void symbol_print_symbols(const char *symboltabletype) {
Iterator it = First(symtab);
while (it.key) {
String *symname = it.key;
Printf(stdout, " %s\n", symname);
Printf(stdout, " %s (%s)\n", symname, nodeType(it.item));
/*
Printf(stdout, " %s - %p (%s)\n", symname, it.item, Getattr(it.item, "name"));
*/
@ -463,6 +463,7 @@ Symtab *Swig_symbol_current(void) {
* Swig_symbol_alias()
*
* Makes an alias for a symbol in the global symbol table.
* Primarily for namespace aliases such as 'namespace X = Y;'.
* ----------------------------------------------------------------------------- */
void Swig_symbol_alias(const_String_or_char_ptr aliasname, Symtab *s) {
@ -481,7 +482,9 @@ void Swig_symbol_alias(const_String_or_char_ptr aliasname, Symtab *s) {
/* -----------------------------------------------------------------------------
* Swig_symbol_inherit()
*
* Inherit symbols from another scope.
* Inherit symbols from another scope. Primarily for C++ inheritance and
* for using directives, such as 'using namespace X;'
* but not for using declarations, such as 'using A;'.
* ----------------------------------------------------------------------------- */
void Swig_symbol_inherit(Symtab *s) {
@ -535,6 +538,7 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
if (!name)
return;
if (SwigType_istemplate(name)) {
String *cname = NewString(name);
String *dname = Swig_symbol_template_deftype(cname, 0);
@ -545,7 +549,7 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
Delete(cname);
}
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_cadd %s %x\n", name, n);
Printf(stderr, "symbol_cadd %s %p\n", name, n);
#endif
cn = Getattr(ccurrent, name);
@ -880,7 +884,7 @@ Node *Swig_symbol_add(const_String_or_char_ptr symname, Node *n) {
/* Well, we made it this far. Guess we can drop the symbol in place */
Setattr(n, "sym:symtab", current_symtab);
Setattr(n, "sym:name", symname);
/* Printf(stdout,"%s %x\n", Getattr(n,"sym:overname"), current_symtab); */
/* Printf(stdout,"%s %p\n", Getattr(n,"sym:overname"), current_symtab); */
assert(!Getattr(n, "sym:overname"));
overname = NewStringf("__SWIG_%d", pn);
Setattr(n, "sym:overname", overname);
@ -927,11 +931,10 @@ static Node *_symbol_lookup(const String *name, Symtab *symtab, int (*check) (No
return 0;
Setmark(symtab, 1);
n = Getattr(sym, name);
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_look %s %x %x %s\n", name, n, symtab, Getattr(symtab, "name"));
Printf(stderr, "symbol_look %s %p %p %s\n", name, n, symtab, Getattr(symtab, "name"));
#endif
if (n) {
@ -967,7 +970,7 @@ static Node *_symbol_lookup(const String *name, Symtab *symtab, int (*check) (No
}
inherit = Getattr(symtab, "inherit");
if (inherit) {
if (inherit && use_inherit) {
int i, len;
len = Len(inherit);
for (i = 0; i < len; i++) {
@ -1053,6 +1056,25 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt
Node *pn = Getattr(symtab, "parentNode");
if (pn)
n = symbol_lookup_qualified(name, pn, prefix, local, checkfunc);
/* Check inherited scopes */
if (!n) {
List *inherit = Getattr(symtab, "inherit");
if (inherit && use_inherit) {
int i, len;
len = Len(inherit);
for (i = 0; i < len; i++) {
Node *prefix_node = symbol_lookup(prefix, Getitem(inherit, i), checkfunc);
if (prefix_node) {
Node *prefix_symtab = Getattr(prefix_node, "symtab");
if (prefix_symtab) {
n = symbol_lookup(name, prefix_symtab, checkfunc);
break;
}
}
}
}
}
} else {
n = 0;
}
@ -1065,8 +1087,9 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt
* Swig_symbol_clookup()
*
* Look up a symbol in the symbol table. This uses the C name, not scripting
* names. Note: If we come across a using a directive, we follow it to
* to get the real node.
* names. Note: If we come across a using declaration, we follow it to
* to get the real node. Any using directives are also followed (but this is
* implemented in symbol_lookup()).
* ----------------------------------------------------------------------------- */
Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) {
@ -1207,6 +1230,9 @@ Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (*
/* -----------------------------------------------------------------------------
* Swig_symbol_clookup_local()
*
* Same as Swig_symbol_clookup but parent nodes are not searched, that is, just
* this symbol table is searched.
* ----------------------------------------------------------------------------- */
Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) {
@ -1301,6 +1327,20 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n,
return s;
}
/* -----------------------------------------------------------------------------
* Swig_symbol_clookup_no_inherit()
*
* Symbol lookup like Swig_symbol_clookup but does not follow using declarations.
* ----------------------------------------------------------------------------- */
Node *Swig_symbol_clookup_no_inherit(const_String_or_char_ptr name, Symtab *n) {
Node *s = 0;
assert(use_inherit==1);
use_inherit = 0;
s = Swig_symbol_clookup(name, n);
use_inherit = 1;
return s;
}
/* -----------------------------------------------------------------------------
* Swig_symbol_cscope()
@ -1411,7 +1451,7 @@ String *Swig_symbol_qualified(Node *n) {
if (!symtab)
return NewStringEmpty();
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_qscope %s %x %s\n", Getattr(n, "name"), symtab, Getattr(symtab, "name"));
Printf(stderr, "symbol_qscope %s %p %s\n", Getattr(n, "name"), symtab, Getattr(symtab, "name"));
#endif
return Swig_symbol_qualifiedscopename(symtab);
}
@ -1427,14 +1467,14 @@ Node *Swig_symbol_isoverloaded(Node *n) {
}
/* -----------------------------------------------------------------------------
* Swig_symbol_type_qualify()
* symbol_template_qualify()
*
* Create a fully qualified type name
* Internal function to create a fully qualified type name for templates
* ----------------------------------------------------------------------------- */
/* This cache produces problems with OSS, don't active it */
/* #define SWIG_TEMPLATE_QUALIFY_CACHE */
static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) {
static SwigType *symbol_template_qualify(const SwigType *e, Symtab *st) {
String *tprefix, *tsuffix;
SwigType *qprefix;
List *targs;
@ -1499,10 +1539,17 @@ static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) {
}
static int no_constructor(Node *n) {
static int symbol_no_constructor(Node *n) {
return !Checkattr(n, "nodeType", "constructor");
}
/* -----------------------------------------------------------------------------
* Swig_symbol_type_qualify()
*
* Create a fully qualified type name
* Note: Does not resolve a constructor if passed in as the 'type'.
* ----------------------------------------------------------------------------- */
SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
List *elements;
String *result = NewStringEmpty();
@ -1519,13 +1566,14 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
for (i = 0; i < len; i++) {
String *e = Getitem(elements, i);
if (SwigType_issimple(e)) {
Node *n = Swig_symbol_clookup_check(e, st, no_constructor);
/* Note: the unary scope operator (::) is being removed from the template parameters here. */
Node *n = Swig_symbol_clookup_check(e, st, symbol_no_constructor);
if (n) {
String *name = Getattr(n, "name");
Clear(e);
Append(e, name);
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_qual_ei %d %s %s %x\n", i, name, e, st);
Printf(stderr, "symbol_qual_ei %d %s %s %p\n", i, name, e, st);
#endif
if (!Swig_scopename_check(name)) {
String *qname = Swig_symbol_qualified(n);
@ -1534,12 +1582,12 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
Insert(e, 0, qname);
}
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_qual_sc %d %s %s %x\n", i, qname, e, st);
Printf(stderr, "symbol_qual_sc %d %s %s %p\n", i, qname, e, st);
#endif
Delete(qname);
}
} else if (SwigType_istemplate(e)) {
SwigType *ty = Swig_symbol_template_qualify(e, st);
SwigType *ty = symbol_template_qualify(e, st);
Clear(e);
Append(e, ty);
Delete(ty);
@ -1572,7 +1620,7 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
}
Delete(elements);
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_qualify %s %s %x %s\n", t, result, st, st ? Getattr(st, "name") : 0);
Printf(stderr, "symbol_qualify %s %s %p %s\n", t, result, st, st ? Getattr(st, "name") : 0);
#endif
return result;
@ -1751,7 +1799,7 @@ String *Swig_symbol_string_qualify(String *s, Symtab *st) {
char *c = Char(s);
int first_char = 1;
while (*c) {
if (isalpha((int) *c) || (*c == '_') || (*c == ':') || (isdigit((int) *c) && !first_char)) {
if (isalpha((int) *c) || (*c == '_') || (*c == ':') || (*c == '~' && first_char) || (isdigit((int) *c) && !first_char)) {
Putc(*c, id);
have_id = 1;
} else {

View file

@ -12,8 +12,6 @@
* parse trees.
* ----------------------------------------------------------------------------- */
char cvsroot_tree_c[] = "$Id$";
#include "swig.h"
#include <stdarg.h>
#include <assert.h>
@ -77,12 +75,12 @@ void Swig_print_node(Node *obj) {
if ((Cmp(k, "nodeType") == 0) || (Cmp(k, "firstChild") == 0) || (Cmp(k, "lastChild") == 0) ||
(Cmp(k, "parentNode") == 0) || (Cmp(k, "nextSibling") == 0) || (Cmp(k, "previousSibling") == 0) || (*(Char(k)) == '$')) {
/* Do nothing */
} else if (Cmp(k, "parms") == 0) {
} else if (Cmp(k, "parms") == 0 || Cmp(k, "wrap:parms") == 0) {
print_indent(2);
Printf(stdout, "%-12s - %s\n", k, ParmList_protostr(Getattr(obj, k)));
Printf(stdout, "%-12s - %s\n", k, ParmList_str_defaultargs(Getattr(obj, k)));
} else {
DOH *o;
char *trunc = "";
const char *trunc = "";
print_indent(2);
if (DohIsString(Getattr(obj, k))) {
o = Str(Getattr(obj, k));
@ -92,7 +90,7 @@ void Swig_print_node(Node *obj) {
Printf(stdout, "%-12s - \"%(escape)-0.80s%s\"\n", k, o, trunc);
Delete(o);
} else {
Printf(stdout, "%-12s - 0x%x\n", k, Getattr(obj, k));
Printf(stdout, "%-12s - %p\n", k, Getattr(obj, k));
}
}
ki = Next(ki);

View file

@ -11,8 +11,6 @@
* A somewhat generalized implementation of SWIG1.1 typemaps.
* ----------------------------------------------------------------------------- */
char cvsroot_typemap_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
#include <ctype.h>
@ -89,13 +87,16 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) {
return tm;
}
static void set_typemap(int tm_scope, const SwigType *type, Hash *tm) {
static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) {
SwigType *hashtype = 0;
Hash *new_tm = 0;
assert(*tmhash == 0);
if (SwigType_istemplate(type)) {
SwigType *rty = SwigType_typedef_resolve_all(type);
String *ty = Swig_symbol_template_deftype(rty, 0);
String *tyq = Swig_symbol_type_qualify(ty, 0);
hashtype = SwigType_remove_global_scope_prefix(tyq);
*tmhash = Getattr(typemaps[tm_scope], hashtype);
Delete(rty);
Delete(tyq);
Delete(ty);
@ -103,10 +104,17 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash *tm) {
hashtype = SwigType_remove_global_scope_prefix(type);
}
if (!*tmhash) {
/* this type has not been seen before even after resolving template parameter types */
new_tm = NewHash();
*tmhash = new_tm;
}
/* note that the unary scope operator (::) prefix indicating global scope has been removed from the type */
Setattr(typemaps[tm_scope], hashtype, tm);
Setattr(typemaps[tm_scope], hashtype, *tmhash);
Delete(hashtype);
Delete(new_tm);
}
@ -210,9 +218,7 @@ static void typemap_register(const_String_or_char_ptr tmap_method, ParmList *par
/* See if this type has been seen before */
tm = get_typemap(tm_scope, type);
if (!tm) {
tm = NewHash();
set_typemap(tm_scope, type, tm);
Delete(tm);
set_typemap(tm_scope, type, &tm);
}
if (pname) {
/* See if parameter has been seen before */
@ -476,9 +482,7 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
type = Getattr(lastdp, "type");
tm = get_typemap(tm_scope, type);
if (!tm) {
tm = NewHash();
set_typemap(tm_scope, type, tm);
Delete(tm);
set_typemap(tm_scope, type, &tm);
}
name = Getattr(lastdp, "name");
if (name) {
@ -1300,6 +1304,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
SwigType *mtype = 0;
String *pname;
String *qpname = 0;
String *noscope_pname = 0;
Hash *tm = 0;
String *s = 0;
String *sdef = 0;
@ -1323,7 +1328,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
/* Special hook (hack!). Check for the 'ref' feature and add code it contains to any 'newfree' typemap code.
* We could choose to put this hook into a number of different typemaps, not necessarily 'newfree'...
* Rather confusingly 'newfree' is used to release memory and the 'ref' feature is used to add in memory references - yuck! */
if (node && Cmp(tmap_method, "newfree") == 0) {
if (Cmp(tmap_method, "newfree") == 0) {
String *base = SwigType_base(type);
Node *typenode = Swig_symbol_clookup(base, 0);
if (typenode)
@ -1332,21 +1337,32 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
}
pname = Getattr(node, "name");
noscope_pname = Copy(pname);
if (pname && node && checkAttribute(node, "kind", "function")) {
/*
For functions, add on a qualified name search, for example
struct Foo {
int *foo(int bar) -> Foo::foo
};
if (pname && Getattr(node, "sym:symtab")) {
/* Add on a qualified name search for any symbol in the symbol table, for example:
* struct Foo {
* int *foo(int bar) -> Foo::foo
* };
* Note that if node is a parameter (Parm *) then there will be no symbol table attached to the Parm *.
*/
Symtab *st = Getattr(node, "sym:symtab");
String *qsn = st ? Swig_symbol_string_qualify(pname, st) : 0;
if (qsn && Len(qsn) && !Equal(qsn, pname))
qpname = qsn;
String *qsn;
if (Swig_scopename_check(pname)) {
/* sometimes pname is qualified, so we remove all the scope for the lookup */
Delete(noscope_pname);
noscope_pname = Swig_scopename_last(pname);
/*
Printf(stdout, "Removed scope: %s => %s\n", pname, noscope_pname);
*/
}
qsn = Swig_symbol_qualified(node);
if (qsn && Len(qsn)) {
qpname = NewStringf("%s::%s", qsn, noscope_pname);
Delete(qsn);
}
}
tm = typemap_search(tmap_method, type, pname, qpname, &mtype, node);
tm = typemap_search(tmap_method, type, noscope_pname, qpname, &mtype, node);
if (typemap_search_debug)
debug_search_result_display(tm);
if (typemaps_used_debug && tm) {
@ -1359,6 +1375,8 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
Delete(qpname);
qpname = 0;
Delete(noscope_pname);
noscope_pname = 0;
if (!tm)
return sdef;

View file

@ -14,10 +14,9 @@
* like typedef, namespaces, etc.
* ----------------------------------------------------------------------------- */
char cvsroot_typeobj_c[] = "$Id$";
#include "swig.h"
#include <ctype.h>
#include <limits.h>
/* -----------------------------------------------------------------------------
* Synopsis
@ -427,62 +426,62 @@ int SwigType_isreference(const SwigType *t) {
* Repeated qualifications have no effect. Moreover, the order of qualifications
* is alphabetical---meaning that "const volatile" and "volatile const" are
* stored in exactly the same way as "q(const volatile)".
* 'qual' can be a list of multiple qualifiers in any order, separated by spaces.
* ----------------------------------------------------------------------------- */
SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) {
char temp[256], newq[256];
int sz, added = 0;
char *q, *cqual;
List *qlist;
String *allq, *newq;
int i, sz;
const char *cqprev = 0;
const char *c = Char(t);
const char *cqual = Char(qual);
char *c = Char(t);
cqual = Char(qual);
if (!(strncmp(c, "q(", 2) == 0)) {
sprintf(temp, "q(%s).", cqual);
/* if 't' has no qualifiers and 'qual' is a single qualifier, simply add it */
if ((strncmp(c, "q(", 2) != 0) && (strstr(cqual, " ") == 0)) {
String *temp = NewStringf("q(%s).", cqual);
Insert(t, 0, temp);
Delete(temp);
return t;
}
/* The type already has a qualifier on it. In this case, we first check to
see if the qualifier is already specified. In that case do nothing.
If it is a new qualifier, we add it to the qualifier list in alphabetical
order */
sz = element_size(c);
strncpy(temp, c, (sz < 256) ? sz : 256);
if (strstr(temp, cqual)) {
/* Qualifier already added */
return t;
/* create string of all qualifiers */
if (strncmp(c, "q(", 2) == 0) {
allq = SwigType_parm(t);
Append(allq, " ");
SwigType_del_element(t); /* delete old qualifier list from 't' */
} else {
allq = NewStringEmpty();
}
Append(allq, qual);
/* Add the qualifier to the existing list. */
/* create list of all qualifiers from string */
qlist = Split(allq, ' ', INT_MAX);
Delete(allq);
strcpy(newq, "q(");
q = temp + 2;
q = strtok(q, " ).");
while (q) {
if (strcmp(cqual, q) < 0) {
/* New qualifier is less that current qualifier. We need to insert it */
strcat(newq, cqual);
strcat(newq, " ");
strcat(newq, q);
added = 1;
} else {
strcat(newq, q);
}
q = strtok(NULL, " ).");
if (q) {
strcat(newq, " ");
/* sort in alphabetical order */
SortList(qlist, Strcmp);
/* create new qualifier string from unique elements of list */
sz = Len(qlist);
newq = NewString("q(");
for (i = 0; i < sz; ++i) {
String *q = Getitem(qlist, i);
const char *cq = Char(q);
if (cqprev == 0 || strcmp(cqprev, cq) != 0) {
if (i > 0) {
Append(newq, " ");
}
Append(newq, q);
cqprev = cq;
}
}
if (!added) {
strcat(newq, " ");
strcat(newq, cqual);
}
strcat(newq, ").");
Delslice(t, 0, sz);
Append(newq, ").");
Delete(qlist);
/* replace qualifier string with new one */
Insert(t, 0, newq);
Delete(newq);
return t;
}
@ -590,11 +589,11 @@ int SwigType_ismemberpointer(const SwigType *t) {
* ----------------------------------------------------------------------------- */
SwigType *SwigType_add_array(SwigType *t, const_String_or_char_ptr size) {
char temp[512];
strcpy(temp, "a(");
strcat(temp, Char(size));
strcat(temp, ").");
String *temp = NewString("a(");
Append(temp, size);
Append(temp, ").");
Insert(t, 0, temp);
Delete(temp);
return t;
}
@ -627,8 +626,8 @@ int SwigType_prefix_is_simple_1D_array(const SwigType *t) {
if (c && (strncmp(c, "a(", 2) == 0)) {
c = strchr(c, '.');
c++;
return (*c == 0);
if (c)
return (*(++c) == 0);
}
return 0;
}
@ -654,8 +653,10 @@ int SwigType_array_ndim(const SwigType *t) {
while (c && (strncmp(c, "a(", 2) == 0)) {
c = strchr(c, '.');
c++;
ndim++;
if (c) {
c++;
ndim++;
}
}
return ndim;
}
@ -665,8 +666,10 @@ String *SwigType_array_getdim(const SwigType *t, int n) {
char *c = Char(t);
while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) {
c = strchr(c, '.');
c++;
n--;
if (c) {
c++;
n--;
}
}
if (n == 0) {
String *dim = SwigType_parm(c);
@ -695,8 +698,10 @@ void SwigType_array_setdim(SwigType *t, int n, const_String_or_char_ptr rep) {
while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) {
c = strchr(c, '.');
c++;
n--;
if (c) {
c++;
n--;
}
}
if (n == 0) {
temp = *c;
@ -741,7 +746,6 @@ SwigType *SwigType_add_function(SwigType *t, ParmList *parms) {
Insert(t, 0, ").");
pstr = NewString("f(");
p = parms;
for (p = parms; p; p = nextSibling(p)) {
if (p != parms)
Putc(',', pstr);
@ -839,7 +843,6 @@ SwigType *SwigType_add_template(SwigType *t, ParmList *parms) {
Parm *p;
Append(t, "<(");
p = parms;
for (p = parms; p; p = nextSibling(p)) {
String *v;
if (Getattr(p, "default"))

View file

@ -14,8 +14,6 @@
* run-time type checker is also handled here.
* ----------------------------------------------------------------------------- */
char cvsroot_typesys_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
@ -297,7 +295,7 @@ void SwigType_inherit_scope(Typetab *scope) {
void SwigType_scope_alias(String *aliasname, Typetab *ttab) {
String *q;
/* Printf(stdout,"alias: '%s' '%x'\n", aliasname, ttab); */
/* Printf(stdout,"alias: '%s' '%p'\n", aliasname, ttab); */
q = SwigType_scope_name(current_scope);
if (Len(q)) {
Append(q, "::");
@ -398,13 +396,13 @@ void SwigType_print_scope(void) {
Printf(stdout, "-------------------------------------------------------------\n");
ttab = Getattr(i.item, "typetab");
Printf(stdout, "Type scope '%s' (%x)\n", i.key, i.item);
Printf(stdout, "Type scope '%s' (%p)\n", i.key, i.item);
{
List *inherit = Getattr(i.item, "inherit");
if (inherit) {
Iterator j;
for (j = First(inherit); j.item; j = Next(j)) {
Printf(stdout, " Inherits from '%s' (%x)\n", Getattr(j.item, "qname"), j.item);
Printf(stdout, " Inherits from '%s' (%p)\n", Getattr(j.item, "qname"), j.item);
}
}
}
@ -668,7 +666,7 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
Printf(stdout, "namebase = '%s'\n", namebase);
#endif
type = typedef_resolve(s, namebase);
if (type) {
if (type && resolved_scope) {
/* we need to look for the resolved type, this will also
fix the resolved_scope if 'type' and 'namebase' are
declared in different scopes */
@ -680,7 +678,7 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
#ifdef SWIG_DEBUG
Printf(stdout, "%s type = '%s'\n", Getattr(s, "name"), type);
#endif
if ((type) && (!Swig_scopename_check(type)) && resolved_scope) {
if (type && (!Swig_scopename_check(type)) && resolved_scope) {
Typetab *rtab = resolved_scope;
String *qname = Getattr(resolved_scope, "qname");
/* If qualified *and* the typename is defined from the resolved scope, we qualify */
@ -794,6 +792,67 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
goto return_result;
}
Delete(base);
/* If 'type' is an array, then the right-most qualifier in 'r' should
be added to 'type' after the array qualifier, so that given
a(7).q(volatile).double myarray // typedef volatile double[7] myarray;
the type
q(const).myarray // const myarray
becomes
a(7).q(const volatile).double // const volatile double[7]
and NOT
q(const).a(7).q(volatile).double // non-sensical type
*/
if (r && Len(r) && SwigType_isarray(type)) {
List *r_elem;
String *r_qual;
int r_sz;
r_elem = SwigType_split(r);
r_sz = Len(r_elem);
r_qual = Getitem(r_elem, r_sz-1);
if (SwigType_isqualifier(r_qual)) {
String *new_r;
String *new_type;
List *type_elem;
String *type_qual;
String *r_qual_arg;
int i, type_sz;
type_elem = SwigType_split(type);
type_sz = Len(type_elem);
for (i = 0; i < type_sz; ++i) {
String *e = Getitem(type_elem, i);
if (!SwigType_isarray(e))
break;
}
type_qual = Copy(Getitem(type_elem, i));
r_qual_arg = SwigType_parm(r_qual);
SwigType_add_qualifier(type_qual, r_qual_arg);
Delete(r_qual_arg);
Setitem(type_elem, i, type_qual);
new_r = NewStringEmpty();
for (i = 0; i < r_sz-1; ++i) {
Append(new_r, Getitem(r_elem, i));
}
new_type = NewStringEmpty();
for (i = 0; i < type_sz; ++i) {
Append(new_type, Getitem(type_elem, i));
}
#ifdef SWIG_DEBUG
Printf(stdout, "r+type='%s%s' new_r+new_type='%s%s'\n", r, type, new_r, new_type);
#endif
Delete(r);
r = new_r;
newtype = 1;
type = new_type;
Delete(type_elem);
}
Delete(r_elem);
}
Append(r, type);
if (newtype) {
Delete(type);
@ -898,7 +957,7 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) {
e = ty;
}
resolved_scope = 0;
if (typedef_resolve(current_scope, e)) {
if (typedef_resolve(current_scope, e) && resolved_scope) {
/* resolved_scope contains the scope that actually resolved the symbol */
String *qname = Getattr(resolved_scope, "qname");
if (qname) {
@ -955,6 +1014,10 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) {
Parm *p;
List *parms;
ty = Swig_symbol_template_deftype(e, current_symtab);
/*
String *dt = Swig_symbol_template_deftype(e, current_symtab);
ty = Swig_symbol_type_qualify(dt, 0);
*/
e = ty;
parms = SwigType_parmlist(e);
tprefix = SwigType_templateprefix(e);
@ -1021,6 +1084,9 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) {
Delete(tprefix);
Delete(qprefix);
Delete(parms);
/*
Delete(dt);
*/
}
Append(result, e);
Delete(ty);
@ -1114,14 +1180,14 @@ int SwigType_typedef_using(const_String_or_char_ptr name) {
/* See if the using name is a scope */
/* tt = SwigType_find_scope(current_scope,name);
Printf(stdout,"tt = %x, name = '%s'\n", tt, name); */
Printf(stdout,"tt = %p, name = '%s'\n", tt, name); */
/* We set up a typedef B --> A::B */
Setattr(current_typetab, base, name);
/* Find the scope name where the symbol is defined */
td = SwigType_typedef_resolve(name);
/* Printf(stdout,"td = '%s' %x\n", td, resolved_scope); */
/* Printf(stdout,"td = '%s' %p\n", td, resolved_scope); */
if (resolved_scope) {
defined_name = Getattr(resolved_scope, "qname");
if (defined_name) {
@ -1803,13 +1869,13 @@ void SwigType_inherit_equiv(File *out) {
Append(rlist, ck.key);
}
/* Printf(stdout,"rk.key = '%s'\n", rk.key);
Printf(stdout,"rh = %x '%s'\n", rh,rh); */
Printf(stdout,"rh = %p '%s'\n", rh,rh); */
bk = First(sub);
while (bk.key) {
prefix = SwigType_prefix(rk.key);
Append(prefix, bk.key);
/* Printf(stdout,"set %x = '%s' : '%s'\n", rh, SwigType_manglestr(prefix),prefix); */
/* Printf(stdout,"set %p = '%s' : '%s'\n", rh, SwigType_manglestr(prefix),prefix); */
mprefix = SwigType_manglestr(prefix);
Setattr(rh, mprefix, prefix);
mkey = SwigType_manglestr(rk.key);

View file

@ -13,8 +13,6 @@
* to be created in a piecemeal manner.
* ----------------------------------------------------------------------------- */
char cvsroot_wrapfunc_c[] = "$Id$";
#include "swig.h"
#include <ctype.h>