Merge branch 'master' into doxygen

Merge with ~3.0.1 sources from master.
This commit is contained in:
Vadim Zeitlin 2014-04-30 18:37:57 +02:00
commit 1ebd2334b8
1593 changed files with 51732 additions and 28076 deletions

View file

@ -25,13 +25,16 @@ extern "C" {
extern String *cparse_file;
extern int cparse_line;
extern int cparse_cplusplus;
extern int cparse_cplusplusout;
extern int cparse_start_line;
extern int scan_doxygen_comments;
extern void Swig_cparse_cplusplus(int);
extern void Swig_cparse_cplusplusout(int);
extern void scanner_file(File *);
extern void scanner_next_token(int);
extern void skip_balanced(int startchar, int endchar);
extern String *get_raw_text_balanced(int startchar, int endchar);
extern void skip_decl(void);
extern void scanner_check_typedef(void);
extern void scanner_ignore_typedef(void);

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>
@ -39,6 +37,9 @@ int cparse_start_line = 0;
/* C++ mode */
int cparse_cplusplus = 0;
/* Generate C++ compatible code when wrapping C code */
int cparse_cplusplusout = 0;
/* Private vars */
static int scan_init = 0;
static int num_brace = 0;
@ -57,6 +58,14 @@ void Swig_cparse_cplusplus(int v) {
cparse_cplusplus = v;
}
/* -----------------------------------------------------------------------------
* Swig_cparse_cplusplusout()
* ----------------------------------------------------------------------------- */
void Swig_cparse_cplusplusout(int v) {
cparse_cplusplusout = v;
}
/* ----------------------------------------------------------------------------
* scanner_init()
*
@ -106,10 +115,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;
}
@ -122,6 +132,16 @@ void skip_balanced(int startchar, int endchar) {
return;
}
/* -----------------------------------------------------------------------------
* get_raw_text_balanced()
*
* Returns raw text between 2 braces
* ----------------------------------------------------------------------------- */
String *get_raw_text_balanced(int startchar, int endchar) {
return Scanner_get_raw_text_balanced(scan, startchar, endchar);
}
/* ----------------------------------------------------------------------------
* void skip_decl(void)
*
@ -250,6 +270,8 @@ static int yylook(void) {
return GREATERTHANOREQUALTO;
case SWIG_TOKEN_RSHIFT:
return RSHIFT;
case SWIG_TOKEN_ARROW:
return ARROW;
case SWIG_TOKEN_PERIOD:
return PERIOD;
case SWIG_TOKEN_MODULO:
@ -287,15 +309,25 @@ static int yylook(void) {
case SWIG_TOKEN_STRING:
yylval.id = Swig_copy_string(Char(Scanner_text(scan)));
return STRING;
case SWIG_TOKEN_WSTRING:
yylval.id = Swig_copy_string(Char(Scanner_text(scan)));
return WSTRING;
case SWIG_TOKEN_CHAR:
yylval.str = NewString(Scanner_text(scan));
if (Len(yylval.str) == 0) {
Swig_error(cparse_file, cparse_line, "Empty character constant\n");
Printf(stdout,"%d\n", Len(Scanner_text(scan)));
}
return CHARCONST;
case SWIG_TOKEN_WCHAR:
yylval.str = NewString(Scanner_text(scan));
if (Len(yylval.str) == 0) {
Swig_error(cparse_file, cparse_line, "Empty character constant\n");
}
return WCHARCONST;
/* Numbers */
case SWIG_TOKEN_INT:
@ -394,7 +426,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;
@ -565,8 +597,16 @@ int yylex(void) {
return (PROTECTED);
if (strcmp(yytext, "friend") == 0)
return (FRIEND);
if (strcmp(yytext, "constexpr") == 0)
return (CONSTEXPR);
if (strcmp(yytext, "thread_local") == 0)
return (THREAD_LOCAL);
if (strcmp(yytext, "decltype") == 0)
return (DECLTYPE);
if (strcmp(yytext, "virtual") == 0)
return (VIRTUAL);
if (strcmp(yytext, "static_assert") == 0)
return (STATIC_ASSERT);
if (strcmp(yytext, "operator") == 0) {
int nexttok;
String *s = NewString("operator ");
@ -615,6 +655,11 @@ int yylex(void) {
yylval.str = s;
return OPERATOR;
}
} else if (nexttok == SWIG_TOKEN_STRING) {
/* Operator "" or user-defined string literal ""_suffix */
Append(s,"\"\"");
yylval.str = s;
return OPERATOR;
} else if (nexttok == SWIG_TOKEN_ID) {
/* We have an identifier. This could be any number of things. It could be a named version of
an operator (e.g., 'and_eq') or it could be a conversion operator. To deal with this, we're
@ -701,6 +746,8 @@ int yylex(void) {
}
if (strcmp(yytext, "throw") == 0)
return (THROW);
if (strcmp(yytext, "noexcept") == 0)
return (NOEXCEPT);
if (strcmp(yytext, "try") == 0)
return (yylex());
if (strcmp(yytext, "catch") == 0)
@ -711,6 +758,8 @@ int yylex(void) {
return (yylex());
if (strcmp(yytext, "explicit") == 0)
return (EXPLICIT);
if (strcmp(yytext, "auto") == 0)
return (AUTO);
if (strcmp(yytext, "export") == 0)
return (yylex());
if (strcmp(yytext, "typename") == 0)
@ -719,15 +768,18 @@ int yylex(void) {
yylval.intvalue = cparse_line;
return (TEMPLATE);
}
if (strcmp(yytext, "delete") == 0) {
if (strcmp(yytext, "delete") == 0)
return (DELETE_KW);
}
if (strcmp(yytext, "using") == 0) {
if (strcmp(yytext, "default") == 0)
return (DEFAULT);
if (strcmp(yytext, "using") == 0)
return (USING);
}
if (strcmp(yytext, "namespace") == 0) {
if (strcmp(yytext, "namespace") == 0)
return (NAMESPACE);
}
if (strcmp(yytext, "override") == 0)
return (OVERRIDE);
if (strcmp(yytext, "final") == 0)
return (FINAL);
} else {
if (strcmp(yytext, "class") == 0) {
Swig_warning(WARN_PARSE_CLASS_KEYWORD, cparse_file, cparse_line, "class keyword used, but not in C++ mode.\n");

File diff suppressed because it is too large Load diff

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")));
}
}
@ -831,7 +825,7 @@ Node *Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) {
/* If not a templated class we must have a templated function.
The template found is not necessarily the one we want when dealing with templated
functions. We don't want any specialized templated functions as they won't have
the default parameters. Lets look for the unspecialized template. Also make sure
the default parameters. Let's look for the unspecialized template. Also make sure
the number of template parameters is correct as it is possible to overload a
templated function with different numbers of template parameters. */

View file

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

View file

@ -51,7 +51,7 @@ Sequence Operations
-------------------
Getitem(list,index) Get an item
Setitem(list,index,val) Set an item
Delitem(list,index,val) Delete an item
Delitem(list,index) Delete an item
Insert(list,index,val) Insert an item
Append(list,val) Append to end
Push(list,val) Insert at beginning
@ -65,11 +65,11 @@ Putc(ch,obj) Put a character
Ungetc(ch,obj) Put character back on input stream
Seek(obj,offset,whence) Seek
Tell(obj) Return file pointer
Close(obj) Close
Delete(obj) Decrease the reference count, close file if zero
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()
@ -947,11 +947,12 @@ int DohGetmark(DOH *ho) {
DOH *DohCall(DOH *func, DOH *args) {
DOH *result;
DOH *(*builtin) (DOH *);
DohFuncPtr_t builtin;
builtin = (DOH *(*)(DOH *)) GetVoid(func, "builtin");
if (!builtin)
builtin.p = GetVoid(func, "builtin");
if (!builtin.p)
return 0;
result = (*builtin) (args);
result = (*builtin.func) (args);
return result;
}

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);
@ -333,6 +336,12 @@ extern DOHList *DohSplit(DOHFile * input, char ch, int nsplits);
extern DOHList *DohSplitLines(DOHFile * input);
extern DOH *DohNone;
/* Helper union for converting between function and object pointers. */
typedef union DohFuncPtr {
void* p;
DOH *(*func)(DOH *);
} DohFuncPtr_t;
extern void DohMemoryDebug(void);
#ifndef DOH_LONG_NAMES

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
@ -23,7 +21,7 @@ static DOH *encodings = 0; /* Encoding hash */
/* -----------------------------------------------------------------------------
* Writen()
*
* Write's N characters of output and retries until all characters are
* Writes N characters of output and retries until all characters are
* written. This is useful should a write operation encounter a spurious signal.
* ----------------------------------------------------------------------------- */
@ -47,16 +45,20 @@ 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)) {
DohFuncPtr_t fp;
if (!encodings)
encodings = NewHash();
Setattr(encodings, (void *) name, NewVoid((void *) fn, 0));
fp.func = fn;
Setattr(encodings, (void *) name, NewVoid(fp.p, 0));
}
/* internal function for processing an encoding */
static DOH *encode(char *name, DOH *s) {
DOH *handle, *ns;
DOH *(*fn) (DOH *);
DohFuncPtr_t fp;
long pos;
char *cfmt = strchr(name, ':');
DOH *tmp = 0;
@ -74,9 +76,11 @@ static DOH *encode(char *name, DOH *s) {
s = tmp;
pos = Tell(s);
Seek(s, 0, SEEK_SET);
fn = (DOH *(*)(DOH *)) Data(handle);
ns = (*fn) (s);
Seek(s, pos, SEEK_SET);
fp.p = Data(handle);
ns = (*fp.func) (s);
assert(pos != -1);
(void)Seek(s, pos, SEEK_SET);
if (tmp)
Delete(tmp);
return ns;
@ -101,7 +105,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 +484,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 +584,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

@ -52,6 +52,7 @@
#define WARN_DEPRECATED_NODEFAULT 123
#define WARN_DEPRECATED_TYPEMAP_LANG 124
#define WARN_DEPRECATED_INPUT_FILE 125
#define WARN_DEPRECATED_NESTED_WORKAROUND 126
/* -- Preprocessor -- */
@ -89,6 +90,12 @@
#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_CPP11_LAMBDA 340
#define WARN_CPP11_ALIAS_DECLARATION 341
#define WARN_CPP11_ALIAS_TEMPLATE 342
#define WARN_CPP11_VARIADIC_TEMPLATE 343
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */
@ -169,6 +176,8 @@
#define WARN_TYPEMAP_DIRECTOROUT_PTR 473
#define WARN_TYPEMAP_OUT_OPTIMAL_IGNORED 474
#define WARN_TYPEMAP_OUT_OPTIMAL_MULTIPLE 475
#define WARN_TYPEMAP_INITIALIZER_LIST 476
#define WARN_TYPEMAP_DIRECTORTHROWS_UNDEF 477
/* -- Fragments -- */
#define WARN_FRAGMENT_NOT_FOUND 490
@ -196,6 +205,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) -- */
@ -249,6 +260,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

@ -54,6 +54,7 @@ eswig_SOURCES = CParse/cscanner.c \
Modules/modula3.cxx \
Modules/module.cxx \
Modules/mzscheme.cxx \
Modules/nested.cxx \
Modules/ocaml.cxx \
Modules/octave.cxx \
Modules/overload.cxx \
@ -126,7 +127,7 @@ distclean-local:
# swig executable as a way of checking before and after the 'beautifying'.
# Single files can be beautified with the beautify-file target, eg: 'make beautify-file INDENTFILE=chosenfile.c'
SWIGTYPEDEFS=-T bool -T File -T DohObjInfo -T Parm -T Language -T List -T Typetab -T ModuleFactory -T ErrorMessageFormat -T Symtab -T Hash -T String -T DohBase -T Node -T String_or_char -T SwigType -T Dispatcher -T Wrapper -T DohStringMethods -T DohFileMethods -T DohListMethods -T DohHashMethods -T DOH -T DohIterator -T ParmList -T FILE -T HashNode -T DOHString_or_char
SWIGTYPEDEFS=-T bool -T File -T DohObjInfo -T Parm -T Language -T List -T Typetab -T ModuleFactory -T ErrorMessageFormat -T Symtab -T Hash -T Scanner -T String -T DohBase -T Node -T String_or_char -T SwigType -T Dispatcher -T Wrapper -T DohStringMethods -T DohFileMethods -T DohListMethods -T DohHashMethods -T DOH -T DohIterator -T ParmList -T FILE -T HashNode -T DOHObj_or_char -T DOHFile -T DOHString -T DOHString_or_char -T UpcallData
INDENTBAKSDIR=../IndentBaks
beautify:
@ -150,8 +151,6 @@ beautify-file:
test -n "$(INDENTFILE)" || (echo INDENTFILE not defined && exit 1;)
test -e $(INDENTFILE) || (echo File does not exist: $(INDENTFILE) && exit 1;)
cp $(INDENTFILE) $(INDENTBAKSDIR)/$(INDENTFILE);
unix2dos $(INDENTFILE)
dos2unix $(INDENTFILE)
indent -kr --honour-newlines --line-length160 --indent-level2 --braces-on-func-def-line --leave-optional-blank-lines $(SWIGTYPEDEFS) $(INDENTFILE) -o $(INDENTFILE).tmp;
cat $(INDENTFILE).tmp | sed -e 's/const const /const /' > $(INDENTFILE);
rm $(INDENTFILE).tmp;

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>
@ -22,7 +20,7 @@ char cvsroot_allegrocl_cxx[] = "$Id$";
// #define ALLEGROCL_TYPE_DEBUG
// #define ALLEGROCL_CLASS_DEBUG
static const char *usage = (char *) "\
static const char *usage = "\
Allegro CL Options (available with -allegrocl)\n\
-identifier-converter <type or funcname> - \n\
Specifies the type of conversion to do on C identifiers to convert\n\
@ -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;
}
@ -425,7 +421,7 @@ class Allocate:public Dispatcher {
while (cc) {
Node *cp = cc;
if (classname) {
Setattr(cp, "classname", classname);
Setattr(cp, "extendsmartclassname", classname);
}
Setattr(cp, "allocate:smartpointeraccess", "1");
/* If constant, we have to be careful */
@ -563,7 +559,11 @@ Allocate():
virtual int classDeclaration(Node *n) {
Symtab *symtab = Swig_symbol_current();
Swig_symbol_setscope(Getattr(n, "symtab"));
save_value<Node*> oldInclass(inclass);
save_value<AccessMode> oldAcessMode(cplus_mode);
save_value<int> oldExtendMode(extendmode);
if (Getattr(n, "template"))
extendmode = 0;
if (!CPlusPlus) {
/* Always have default constructors/destructors in C */
Setattr(n, "allocate:default_constructor", "1");
@ -584,7 +584,6 @@ Allocate():
}
}
}
inclass = n;
String *kind = Getattr(n, "kind");
if (Strcmp(kind, "class") == 0) {
@ -598,19 +597,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 +619,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 +640,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")) {
@ -663,7 +662,7 @@ Allocate():
}
if (!Getattr(n, "allocate:has_destructor")) {
/* No destructor was defined. We need to check a few things here too */
/* No destructor was defined */
List *bases = Getattr(n, "allbases");
int allows_destruct = 1;
@ -680,13 +679,13 @@ Allocate():
}
if (!Getattr(n, "allocate:has_assign")) {
/* No destructor was defined. We need to check a few things here too */
/* No assignment operator was defined */
List *bases = Getattr(n, "allbases");
int allows_assign = 1;
for (int i = 0; i < Len(bases); i++) {
Node *n = Getitem(bases, i);
/* If base class does not allow default destructor, we don't allow it either */
/* If base class does not allow assignment, we don't allow it either */
if (Getattr(n, "allocate:has_assign")) {
allows_assign = !Getattr(n, "allocate:noassign");
}
@ -697,13 +696,13 @@ Allocate():
}
if (!Getattr(n, "allocate:has_new")) {
/* No destructor was defined. We need to check a few things here too */
/* No new operator was defined */
List *bases = Getattr(n, "allbases");
int allows_new = 1;
for (int i = 0; i < Len(bases); i++) {
Node *n = Getitem(bases, i);
/* If base class does not allow default destructor, we don't allow it either */
/* If base class does not allow new operator, we don't allow it either */
if (Getattr(n, "allocate:has_new")) {
allows_new = !Getattr(n, "allocate:nonew");
}
@ -715,7 +714,7 @@ Allocate():
/* Check if base classes allow smart pointers, but might be hidden */
if (!Getattr(n, "allocate:smartpointer")) {
Node *sp = Swig_symbol_clookup((char *) "operator ->", 0);
Node *sp = Swig_symbol_clookup("operator ->", 0);
if (sp) {
/* Look for parent */
Node *p = parentNode(sp);
@ -732,7 +731,6 @@ Allocate():
/* Only care about default behavior. Remove temporary values */
Setattr(n, "allocate:visit", "1");
inclass = 0;
Swig_symbol_setscope(symtab);
return SWIG_OK;
}
@ -775,7 +773,7 @@ Allocate():
/* Check to see if this is a static member or not. If so, we add an attribute
cplus:staticbase that saves the current class */
if (checkAttribute(n, "storage", "static")) {
if (Swig_storage_isstatic(n)) {
Setattr(n, "cplus:staticbase", inclass);
}
@ -783,18 +781,26 @@ Allocate():
if (cplus_mode != PUBLIC) {
if (Strcmp(name, "operator =") == 0) {
/* Look for a private assignment operator */
Setattr(inclass, "allocate:has_assign", "1");
if (!GetFlag(n, "deleted"))
Setattr(inclass, "allocate:has_assign", "1");
Setattr(inclass, "allocate:noassign", "1");
} else if (Strcmp(name, "operator new") == 0) {
/* Look for a private new operator */
Setattr(inclass, "allocate:has_new", "1");
if (!GetFlag(n, "deleted"))
Setattr(inclass, "allocate:has_new", "1");
Setattr(inclass, "allocate:nonew", "1");
}
} else {
if (Strcmp(name, "operator =") == 0) {
Setattr(inclass, "allocate:has_assign", "1");
if (!GetFlag(n, "deleted"))
Setattr(inclass, "allocate:has_assign", "1");
else
Setattr(inclass, "allocate:noassign", "1");
} else if (Strcmp(name, "operator new") == 0) {
Setattr(inclass, "allocate:has_new", "1");
if (!GetFlag(n, "deleted"))
Setattr(inclass, "allocate:has_new", "1");
else
Setattr(inclass, "allocate:nonew", "1");
}
/* Look for smart pointer operator */
if ((Strcmp(name, "operator ->") == 0) && (!GetFlag(n, "feature:ignore"))) {
@ -821,13 +827,13 @@ Allocate():
}
List *methods = smart_pointer_methods(sc, 0, isconst);
Setattr(inclass, "allocate:smartpointer", methods);
Setattr(inclass, "allocate:smartpointerbase", base);
Setattr(inclass, "allocate:smartpointerpointeeclassname", Getattr(sc, "name"));
} else {
/* Hmmm. The return value is not a pointer. If the type is a value
or reference. We're going to chase it to see if another operator->()
can be found */
if ((SwigType_check_decl(type, "")) || (SwigType_check_decl(type, "r."))) {
Node *nn = Swig_symbol_clookup((char *) "operator ->", Getattr(sc, "symtab"));
Node *nn = Swig_symbol_clookup("operator ->", Getattr(sc, "symtab"));
if (nn) {
Delete(base);
Delete(type);

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);
}
@ -138,6 +136,12 @@ public:
return SWIG_OK;
}
virtual int lambdaDeclaration(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int enumDeclaration(Node *n) {
show_attributes(n);
emit_children(n);
@ -184,9 +188,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 +259,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 +287,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 +307,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 +323,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 +347,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 +369,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>
@ -20,7 +18,7 @@ char cvsroot_cffi_cxx[] = "$Id$";
//#define CFFI_DEBUG
//#define CFFI_WRAP_DEBUG
static const char *usage = (char *) "\
static const char *usage = "\
CFFI Options (available with -cffi)\n\
-generate-typedef - Use defctype to generate shortcuts according to the\n\
typedefs in the input.\n\
@ -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");
@ -510,11 +506,6 @@ int CFFI::functionWrapper(Node *n) {
void CFFI::emit_defun(Node *n, String *name) {
// String *storage=Getattr(n,"storage");
// if(!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc")))
// return SWIG_OK;
String *func_name = Getattr(n, "sym:name");
ParmList *pl = Getattr(n, "parms");
@ -567,7 +558,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)
@ -581,12 +578,6 @@ int CFFI::constantWrapper(Node *n) {
}
int CFFI::variableWrapper(Node *n) {
// String *storage=Getattr(n,"storage");
// Printf(stdout,"\"%s\" %s)\n",storage,Getattr(n, "sym:name"));
// if(!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc")))
// return SWIG_OK;
String *var_name = Getattr(n, "sym:name");
String *lisp_type = Swig_typemap_lookup("cin", n, "", 0);
String *lisp_name = lispify_name(n, var_name, "'variable");
@ -671,7 +662,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");
@ -685,7 +676,7 @@ void CFFI::emit_class(Node *n) {
if (!first)
Printf(supers, " ");
String *s = Getattr(i.item, "name");
Printf(supers, "%s", lispify_name(i.item, s, "'classname"));
Printf(supers, "%s", lispify_name(i.item, lispy_name(Char(s)), "'classname"));
}
} else {
// Printf(supers,"ff:foreign-pointer");
@ -837,7 +828,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 +1014,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 +1024,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 +1047,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,13 +11,11 @@
* CHICKEN language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_chicken_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
static const char *usage = (char *) "\
static const char *usage = "\
\
CHICKEN Options (available with -chicken)\n\
-closprefix <prefix> - Prepend <prefix> to all clos identifiers\n\
@ -31,7 +29,7 @@ CHICKEN Options (available with -chicken)\n\
\n";
static char *module = 0;
static char *chicken_path = (char *) "chicken";
static const char *chicken_path = "chicken";
static int num_methods = 0;
static File *f_begin = 0;
@ -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;
@ -625,7 +620,7 @@ int CHICKEN::functionWrapper(Node *n) {
if (in_class)
clos_name = NewString(member_name);
else
clos_name = chickenNameMapping(scmname, (char *) "");
clos_name = chickenNameMapping(scmname, "");
if (!any_specialized_arg) {
method_def = NewString("");
@ -780,7 +775,7 @@ int CHICKEN::variableWrapper(Node *n) {
if (in_class)
clos_name = NewString(member_name);
else
clos_name = chickenNameMapping(scmname, (char *) "");
clos_name = chickenNameMapping(scmname, "");
Node *class_node = classLookup(t);
String *clos_code = Getattr(n, "tmap:varin:closcode");
@ -947,7 +942,7 @@ int CHICKEN::constantWrapper(Node *n) {
if (in_class)
clos_name = NewString(member_name);
else
clos_name = chickenNameMapping(scmname, (char *) "");
clos_name = chickenNameMapping(scmname, "");
if (GetFlag(n, "feature:constasvar")) {
Printv(clos_methods, "(define ", clos_name, " (", chickenPrimitiveName(scmname), "))\n", NIL);
Printv(scm_const_defs, "(set! ", scmname, " (", scmname, "))\n", NIL);
@ -1377,7 +1372,7 @@ void CHICKEN::dispatchFunction(Node *n) {
} else if (in_class)
clos_name = NewString(member_name);
else
clos_name = chickenNameMapping(scmname, (char *) "");
clos_name = chickenNameMapping(scmname, "");
Iterator f;
List *prev = 0;

View file

@ -11,11 +11,9 @@
* clisp language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_clisp_cxx[] = "$Id$";
#include "swigmod.h"
static const char *usage = (char *) "\
static const char *usage = "\
CLISP Options (available with -clisp)\n\
-extern-all - Create clisp definitions for all the functions and\n\
global variables otherwise only definitions for\n\
@ -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;
}
@ -151,7 +148,7 @@ int CLISP::top(Node *n) {
int CLISP::functionWrapper(Node *n) {
is_function = 1;
String *storage = Getattr(n, "storage");
if (!extern_all_flag && (!storage || (Strcmp(storage, "extern") && Strcmp(storage, "externc"))))
if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && !Swig_storage_isexternc(n))))
return SWIG_OK;
String *func_name = Getattr(n, "sym:name");
@ -220,10 +217,9 @@ int CLISP::constantWrapper(Node *n) {
int CLISP::variableWrapper(Node *n) {
is_function = 0;
// SwigType *type=;
String *storage = Getattr(n, "storage");
if (!extern_all_flag && (!storage || (Strcmp(storage, "extern") && Strcmp(storage, "externc"))))
if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && !Swig_storage_isexternc(n))))
return SWIG_OK;
String *var_name = Getattr(n, "sym:name");

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
@ -309,7 +307,7 @@ int Contracts::cDeclaration(Node *n) {
return SWIG_OK;
if (Getattr(n, "feature:contract"))
ret = emit_contract(n, (InClass && !checkAttribute(n, "storage", "static")));
ret = emit_contract(n, InClass && !Swig_storage_isstatic(n));
return ret;
}
@ -344,11 +342,13 @@ int Contracts::namespaceDeclaration(Node *n) {
int Contracts::classDeclaration(Node *n) {
int ret = SWIG_OK;
int oldInClass = InClass;
Node *oldClass = CurrentClass;
InClass = 1;
CurrentClass = n;
emit_children(n);
InClass = 0;
CurrentClass = 0;
InClass = oldInClass;
CurrentClass = oldClass;
return ret;
}

File diff suppressed because it is too large Load diff

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.
@ -566,12 +568,11 @@ public:
writeTypeWrapperClass(swig_type.key, swig_type.item);
}
// Add the proxy functions (and classes, if they are not written to a
// seperate file).
// Add the proxy functions (and classes, if they are not written to a separate file).
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 +599,7 @@ public:
replaceModuleVariables(code);
Printv(file, code, NIL);
Close(file);
Delete(file);
Delete(module_name);
}
@ -693,7 +694,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 +707,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -868,7 +867,6 @@ public:
Printv(class_file, proxy_enum_code, NIL);
Close(class_file);
Delete(class_file);
} else {
String *nspace = Getattr(n, "sym:nspace");
@ -1363,7 +1361,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);
@ -1401,7 +1398,7 @@ public:
// generates a getter function (which is the same as a read only property
// in D) which retrieves the value via by calling the C wrapper.
// Note that this is only called for global constants, static member
// constants are already handeled in staticmemberfunctionHandler().
// constants are already handled in staticmemberfunctionHandler().
Swig_save("constantWrapper", n, "value", NIL);
Swig_save("constantWrapper", n, "tmap:ctype:out", "tmap:imtype:out", "tmap:dtype:out", "tmap:out:null", "tmap:imtype:outattributes", "tmap:dtype:outattributes", NIL);
@ -1440,7 +1437,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 +1580,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 +1692,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 +1894,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 +1926,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 +1942,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 +1965,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 +2120,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 +2201,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 +2221,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 +2247,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 +2267,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 +2280,6 @@ public:
output_director = false;
}
Delete(tp);
Delete(jresult_str);
Delete(result_str);
}
@ -2368,8 +2344,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 +2355,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 +2370,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 +2398,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 +2422,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 +2437,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 +2446,7 @@ public:
Delete(sub);
Delete(supername);
Delete(parms);
Delete(dirclassname);
return Language::classDirectorConstructor(n);
}
@ -2476,18 +2454,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 +2474,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 +2490,7 @@ public:
Wrapper_print(w, f_directors);
DelWrapper(w);
Delete(classname);
Delete(dirclassname);
return SWIG_OK;
}
@ -2521,7 +2499,7 @@ public:
* --------------------------------------------------------------------------- */
virtual int classDirectorEnd(Node *n) {
int i;
String *director_classname = getDirectorClassName(n);
String *director_classname = directorClassName(n);
Wrapper *w = NewWrapper();
@ -2550,7 +2528,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 +3308,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 +3468,6 @@ private:
Printv(class_file, code_target, NIL);
Delete(code_target);
Close(class_file);
Delete(class_file);
}
@ -3498,12 +3475,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 +3494,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 +3535,8 @@ private:
director_callback_pointers = NULL;
Delete(director_dcallbacks_code);
director_dcallbacks_code = NULL;
Delete(dirClassName);
Delete(connect_name);
}
/* ---------------------------------------------------------------------------
@ -3571,7 +3553,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 +3566,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 +3575,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 +3590,7 @@ private:
DelWrapper(code_wrap);
Delete(connect_name);
Delete(dirClassName);
}
/* ---------------------------------------------------------------------------
@ -3618,7 +3601,7 @@ private:
* package if one is set.
*
* This is only used for dependencies created in generated code, user-
* (i.e. typemap-) specified import statements are handeled seperately.
* (i.e. typemap-) specified import statements are handled separately.
* --------------------------------------------------------------------------- */
void requireDType(const String *nspace, const String *symname) {
String *dmodule = createModuleName(nspace, symname);
@ -3648,7 +3631,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 +3675,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 +3703,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);
@ -3760,7 +3742,7 @@ private:
String *nspace = getNSpace();
if (nspace) {
// Check the root package/outermost namespace (a class A in module
// A.B leads to problems if another module A.C is also imported)…
// A.B leads to problems if another module A.C is also imported)
if (Len(package) > 0) {
String *dotless_package = NewStringWithSize(package, Len(package) - 1);
if (Cmp(class_name, dotless_package) == 0) {
@ -3971,7 +3953,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
@ -4071,10 +4053,10 @@ private:
// TODO: Fix const-correctness of methods called in here and make type const.
// We make use of the fact that this function is called at least once for
// every type encountered which is written to a seperate file, which allows
// every type encountered which is written to a separate file, which allows
// us to handle imports here.
// When working in split proxy module mode, each generated proxy class/enum
// is written to a seperate module. This requires us to add a corresponding
// is written to a separate module. This requires us to add a corresponding
// import when a type is used in another generated module. If we are not
// working in split proxy module mode, this is not relevant and the
// generated module name is discarded.
@ -4083,35 +4065,39 @@ private:
if (SwigType_isenum(type)) {
// RESEARCH: Make sure that we really cannot get here for anonymous enums.
Node *n = enumLookup(type);
String *enum_name = Getattr(n, "sym:name");
if (n) {
String *enum_name = Getattr(n, "sym:name");
Node *p = parentNode(n);
if (p && !Strcmp(nodeType(p), "class")) {
// This is a nested enum.
String *parent_name = Getattr(p, "sym:name");
String *nspace = Getattr(p, "sym:nspace");
Node *p = parentNode(n);
if (p && !Strcmp(nodeType(p), "class")) {
// This is a nested enum.
String *parent_name = Getattr(p, "sym:name");
String *nspace = Getattr(p, "sym:nspace");
// An enum nested in a class is not written to a seperate module (this
// would not even be possible in D), so just import the parent.
requireDType(nspace, parent_name);
// An enum nested in a class is not written to a separate module (this
// would not even be possible in D), so just import the parent.
requireDType(nspace, parent_name);
String *module = createModuleName(nspace, parent_name);
if (inProxyModule(module)) {
type_name = NewStringf("%s.%s", parent_name, enum_name);
String *module = createModuleName(nspace, parent_name);
if (inProxyModule(module)) {
type_name = NewStringf("%s.%s", parent_name, enum_name);
} else {
type_name = NewStringf("%s%s.%s.%s", package, module, parent_name, enum_name);
}
} else {
type_name = NewStringf("%s%s.%s.%s", package, module, parent_name, enum_name);
// A non-nested enum is written to a separate module, import it.
String *nspace = Getattr(n, "sym:nspace");
requireDType(nspace, enum_name);
String *module = createModuleName(nspace, enum_name);
if (inProxyModule(module)) {
type_name = Copy(enum_name);
} else {
type_name = NewStringf("%s%s.%s", package, module, enum_name);
}
}
} else {
// A non-nested enum is written to a seperate module, import it.
String *nspace = Getattr(n, "sym:nspace");
requireDType(nspace, enum_name);
String *module = createModuleName(nspace, enum_name);
if (inProxyModule(module)) {
type_name = Copy(enum_name);
} else {
type_name = NewStringf("%s%s.%s", package, module, enum_name);
}
type_name = NewStringf("int");
}
} else {
Node *n = classLookup(type);
@ -4313,23 +4299,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 +4402,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;
}
}
}
@ -4676,7 +4649,7 @@ extern "C" Language *swig_d(void) {
/* -----------------------------------------------------------------------------
* Usage information displayed at the command line.
* ----------------------------------------------------------------------------- */
const char *D::usage = (char *) "\
const char *D::usage = "\
D Options (available with -d)\n\
-d2 - Generate code for D2/Phobos (default: D1/Tango)\n\
-package <pkg> - Write generated D modules into package <pkg>\n\

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);
}
@ -276,13 +275,14 @@ String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_c
void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f) {
// TODO: why is the storage element removed in staticmemberfunctionHandler ??
if ((!is_public(n) && (is_member_director(n) || GetFlag(n, "explicitcall"))) ||
(is_non_virtual_protected_access(n) && !(checkAttribute(n, "staticmemberfunctionHandler:storage", "static") ||
checkAttribute(n, "storage", "static"))
(is_non_virtual_protected_access(n) && !(Swig_storage_isstatic_custom(n, "staticmemberfunctionHandler:storage") ||
Swig_storage_isstatic(n))
&& !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");
}
}

File diff suppressed because it is too large Load diff

View file

@ -11,23 +11,20 @@
* Guile language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_guile_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
// Note string broken in half for compilers that can't handle long strings
static const char *usage = (char *) "\
static const char *usage = "\
Guile Options (available with -guile)\n\
-emitsetters - Emit procedures-with-setters for variables\n\
and structure slots.\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\
-Linkage <lstyle> - Use linkage protocol <lstyle> (default `simple')\n\
Use `module' for native Guile module linking\n\
(requires Guile >= 1.5.0). Use `passive' for\n\
passive linking (no C-level module-handling code),\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);
@ -1068,7 +1018,7 @@ public:
if (in_class)
goops_name = NewString(memberfunction_name);
else
goops_name = goopsNameMapping(proc_name, (char *) "");
goops_name = goopsNameMapping(proc_name, "");
String *primitive_name = NewString("");
if (primRenamer)
Printv(primitive_name, "primitive:", proc_name, NIL);
@ -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);
@ -1263,7 +1204,7 @@ public:
// export wrapper into goops file
if (!in_class) { // only if the variable is not part of a class
String *class_name = SwigType_typedef_resolve_all(SwigType_base(t));
String *goops_name = goopsNameMapping(proc_name, (char *) "");
String *goops_name = goopsNameMapping(proc_name, "");
String *primitive_name = NewString("");
if (primRenamer)
Printv(primitive_name, "primitive:", NIL);
@ -1409,7 +1350,7 @@ public:
Printv(f_header, tm, "\n", NIL);
} else {
// Create variable and assign it a value
Printf(f_header, "static %s = %s;\n", SwigType_lstr(nctype, var_name), rvalue);
Printf(f_header, "static %s = %s;\n", SwigType_str(type, var_name), rvalue);
}
{
/* Hack alert: will cleanup later -- Dave */
@ -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");
}
};

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -11,8 +11,6 @@
* Main entry point to the SWIG core.
* ----------------------------------------------------------------------------- */
char cvsroot_main_cxx[] = "$Id$";
#include "swigconfig.h"
#if defined(_WIN32)
@ -51,6 +49,7 @@ int SwigRuntime = 0; // 0 = no option, 1 = -runtime, 2 = -noruntime
extern "C" {
extern String *ModuleName;
extern int ignore_nested_classes;
}
/* usage string split into multiple parts otherwise string is too big for some compilers */
@ -109,6 +108,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\
@ -160,9 +160,9 @@ static String *SwigLib = 0; // Library directory
static String *SwigLibWinUnix = 0; // Extra library directory on Windows
static int freeze = 0;
static String *lang_config = 0;
static char *hpp_extension = (char *) "h";
static char *cpp_extension = (char *) "cxx";
static char *depends_extension = (char *) "d";
static const char *hpp_extension = "h";
static const char *cpp_extension = "cxx";
static const char *depends_extension = "d";
static String *outdir = 0;
static String *xmlout = 0;
static int outcurrentdir = 0;
@ -187,6 +187,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 +200,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 +286,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);
@ -320,7 +324,7 @@ const String *SWIG_output_directory() {
}
void SWIG_config_cppext(const char *ext) {
cpp_extension = (char *) ext;
cpp_extension = ext;
}
List *SWIG_output_files() {
@ -403,7 +407,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 +416,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 +425,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 +438,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);
}
@ -462,7 +465,7 @@ void SWIG_getoptions(int argc, char *argv[]) {
Swig_mark_arg(i);
} else if (strncmp(argv[i], "-D", 2) == 0) {
String *d = NewString(argv[i] + 2);
Replace(d, (char *) "=", (char *) " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Replace(d, "=", " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Preprocessor_define((DOH *) d, 0);
Delete(d);
// Create a symbol
@ -481,6 +484,10 @@ void SWIG_getoptions(int argc, char *argv[]) {
Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
Swig_cparse_cplusplus(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-c++out") == 0) {
// Undocumented
Swig_cparse_cplusplusout(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-fcompact") == 0) {
Wrapper_compact_print_mode_set(1);
Swig_mark_arg(i);
@ -496,9 +503,6 @@ void SWIG_getoptions(int argc, char *argv[]) {
} else if (strcmp(argv[i], "-naturalvar") == 0) {
Wrapper_naturalvar_mode_set(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nonaturalvar") == 0) {
Wrapper_naturalvar_mode_set(0);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-directors") == 0) {
SWIG_setfeature("feature:director", "1");
Wrapper_director_mode_set(1);
@ -712,6 +716,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]) {
@ -850,10 +857,6 @@ void SWIG_getoptions(int argc, char *argv[]) {
}
}
int SWIG_main(int argc, char *argv[], Language *l) {
char *c;
@ -898,6 +901,9 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Wrapper_director_mode_set(0);
Wrapper_director_protected_mode_set(1);
// Inform the parser if the nested classes should be ignored unless explicitly told otherwise via feature:flatnested
ignore_nested_classes = l->nestedClassesSupport() == Language::NCS_Unknown ? 1 : 0;
// Create Library search directories
// Check for SWIG_LIB environment variable
@ -942,6 +948,11 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// Don't check for an input file if -external-runtime is passed
Swig_check_options(external_runtime ? 0 : 1);
if (CPlusPlus && cparse_cplusplusout) {
Printf(stderr, "The -c++out option is for C input but C++ input has been requested via -c++\n");
SWIG_exit(EXIT_FAILURE);
}
install_opts(argc, argv);
// Add language dependent directory to the search path
@ -1009,7 +1020,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 +1080,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 +1112,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
@ -1142,6 +1167,11 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Printf(stdout, "debug-module stage 1\n");
Swig_print_tree(Getattr(top, "module"));
}
if (!CPlusPlus) {
if (Verbose)
Printf(stdout, "Processing unnamed structs...\n");
Swig_nested_name_unnamed_c_structs(top);
}
if (Verbose) {
Printf(stdout, "Processing types...\n");
@ -1162,6 +1192,12 @@ int SWIG_main(int argc, char *argv[], Language *l) {
}
Swig_default_allocators(top);
if (CPlusPlus) {
if (Verbose)
Printf(stdout, "Processing nested classes...\n");
Swig_nested_process_classes(top);
}
if (dump_top & STAGE3) {
Printf(stdout, "debug-top stage 3\n");
Swig_print_tree(top);
@ -1221,7 +1257,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 +1273,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 +1324,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);
}
@ -3973,7 +3956,7 @@ extern "C" Language *swig_modula3(void) {
* Static member variables
* ----------------------------------------------------------------------------- */
const char *MODULA3::usage = (char *) "\
const char *MODULA3::usage = "\
Modula 3 Options (available with -modula3)\n\
-generateconst <file> - Generate code for computing numeric values of constants\n\
-generaterename <file> - Generate suggestions for %rename\n\

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,13 +11,11 @@
* Mzscheme language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_mzscheme_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
static const char *usage = (char *) "\
static const char *usage = "\
Mzscheme Options (available with -mzscheme)\n\
-declaremodule - Create extension that declares a module\n\
-dynamic-load <library>,[library,...] - Do not link with these libraries, dynamic load\n\
@ -33,14 +31,12 @@ 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 const char *mzscheme_path = "mzscheme";
static String *init_func_def = 0;
static File *f_begin = 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)

446
Source/Modules/nested.cxx Normal file
View file

@ -0,0 +1,446 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* nested.cxx
*
* Nested structs support
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
#include "cparse.h"
// Nested classes processing section
static Hash *classhash = 0;
static String *make_name(Node *n, String *name, SwigType *decl) {
int destructor = name && (*(Char(name)) == '~');
if (String *yyrename = Getattr(n, "class_rename")) {
String *s = NewString(yyrename);
Delattr(n, "class_rename");
if (destructor && (*(Char(s)) != '~')) {
Insert(s, 0, "~");
}
return s;
}
if (!name)
return 0;
return Swig_name_make(n, 0, name, decl, 0);
}
// C version of add_symbols()
static void add_symbols_c(Node *n) {
String *decl;
String *wrn = 0;
String *symname = 0;
int iscdecl = Cmp(nodeType(n), "cdecl") == 0;
Setattr(n, "ismember", "1");
Setattr(n, "access", "public");
if (Getattr(n, "sym:name"))
return;
decl = Getattr(n, "decl");
if (!SwigType_isfunction(decl)) {
String *name = Getattr(n, "name");
String *makename = Getattr(n, "parser:makename");
if (iscdecl) {
String *storage = Getattr(n, "storage");
if (Cmp(storage, "typedef") == 0) {
Setattr(n, "kind", "typedef");
} else {
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
Setattr(n, "kind", "variable");
if (value && Len(value)) {
Setattr(n, "hasvalue", "1");
}
if (type) {
SwigType *ty;
SwigType *tmp = 0;
if (decl) {
ty = tmp = Copy(type);
SwigType_push(ty, decl);
} else {
ty = type;
}
if (!SwigType_ismutable(ty)) {
SetFlag(n, "hasconsttype");
SetFlag(n, "feature:immutable");
}
if (tmp)
Delete(tmp);
}
if (!type) {
Printf(stderr, "notype name %s\n", name);
}
}
}
Swig_features_get(Swig_cparse_features(), 0, name, 0, n);
if (makename) {
symname = make_name(n, makename, 0);
Delattr(n, "parser:makename"); /* temporary information, don't leave it hanging around */
} else {
makename = name;
symname = make_name(n, makename, 0);
}
if (!symname) {
symname = Copy(Getattr(n, "unnamed"));
}
if (symname) {
wrn = Swig_name_warning(n, 0, symname, 0);
}
} else {
String *name = Getattr(n, "name");
SwigType *fdecl = Copy(decl);
SwigType *fun = SwigType_pop_function(fdecl);
if (iscdecl) {
Setattr(n, "kind", "function");
}
Swig_features_get(Swig_cparse_features(), 0, name, fun, n);
symname = make_name(n, name, fun);
wrn = Swig_name_warning(n, 0, symname, fun);
Delete(fdecl);
Delete(fun);
}
if (!symname)
return;
if (GetFlag(n, "feature:ignore")) {
/* Only add to C symbol table and continue */
Swig_symbol_add(0, n);
} else if (strncmp(Char(symname), "$ignore", 7) == 0) {
char *c = Char(symname) + 7;
SetFlag(n, "feature:ignore");
if (strlen(c)) {
SWIG_WARN_NODE_BEGIN(n);
Swig_warning(0, Getfile(n), Getline(n), "%s\n", c + 1);
SWIG_WARN_NODE_END(n);
}
Swig_symbol_add(0, n);
} else {
Node *c;
if ((wrn) && (Len(wrn))) {
String *metaname = symname;
if (!Getmeta(metaname, "already_warned")) {
SWIG_WARN_NODE_BEGIN(n);
Swig_warning(0, Getfile(n), Getline(n), "%s\n", wrn);
SWIG_WARN_NODE_END(n);
Setmeta(metaname, "already_warned", "1");
}
}
c = Swig_symbol_add(symname, n);
if (c != n) {
/* symbol conflict attempting to add in the new symbol */
if (Getattr(n, "sym:weak")) {
Setattr(n, "sym:name", symname);
} else {
String *e = NewStringEmpty();
String *en = NewStringEmpty();
String *ec = NewStringEmpty();
int redefined = Swig_need_redefined_warn(n, c, true);
if (redefined) {
Printf(en, "Identifier '%s' redefined (ignored)", symname);
Printf(ec, "previous definition of '%s'", symname);
} else {
Printf(en, "Redundant redeclaration of '%s'", symname);
Printf(ec, "previous declaration of '%s'", symname);
}
if (Cmp(symname, Getattr(n, "name"))) {
Printf(en, " (Renamed from '%s')", SwigType_namestr(Getattr(n, "name")));
}
Printf(en, ",");
if (Cmp(symname, Getattr(c, "name"))) {
Printf(ec, " (Renamed from '%s')", SwigType_namestr(Getattr(c, "name")));
}
Printf(ec, ".");
SWIG_WARN_NODE_BEGIN(n);
if (redefined) {
Swig_warning(WARN_PARSE_REDEFINED, Getfile(n), Getline(n), "%s\n", en);
Swig_warning(WARN_PARSE_REDEFINED, Getfile(c), Getline(c), "%s\n", ec);
} else {
Swig_warning(WARN_PARSE_REDUNDANT, Getfile(n), Getline(n), "%s\n", en);
Swig_warning(WARN_PARSE_REDUNDANT, Getfile(c), Getline(c), "%s\n", ec);
}
SWIG_WARN_NODE_END(n);
Printf(e, "%s:%d:%s\n%s:%d:%s\n", Getfile(n), Getline(n), en, Getfile(c), Getline(c), ec);
Setattr(n, "error", e);
Delete(e);
Delete(en);
Delete(ec);
}
}
}
Delete(symname);
}
/* Strips C-style and C++-style comments from string in-place. */
static void strip_comments(char *string) {
int state = 0;
/*
* 0 - not in comment
* 1 - in c-style comment
* 2 - in c++-style comment
* 3 - in string
* 4 - after reading / not in comments
* 5 - after reading * in c-style comments
* 6 - after reading \ in strings
*/
char *c = string;
while (*c) {
switch (state) {
case 0:
if (*c == '\"')
state = 3;
else if (*c == '/')
state = 4;
break;
case 1:
if (*c == '*')
state = 5;
*c = ' ';
break;
case 2:
if (*c == '\n')
state = 0;
else
*c = ' ';
break;
case 3:
if (*c == '\"')
state = 0;
else if (*c == '\\')
state = 6;
break;
case 4:
if (*c == '/') {
*(c - 1) = ' ';
*c = ' ';
state = 2;
} else if (*c == '*') {
*(c - 1) = ' ';
*c = ' ';
state = 1;
} else
state = 0;
break;
case 5:
if (*c == '/')
state = 0;
else
state = 1;
*c = ' ';
break;
case 6:
state = 3;
break;
}
++c;
}
}
// Create a %insert with a typedef to make a new name visible to C
static Node *create_insert(Node *n, bool noTypedef = false) {
// format a typedef
String *ccode = Getattr(n, "code");
Push(ccode, " ");
if (noTypedef) {
Push(ccode, Getattr(n, "name"));
Push(ccode, " ");
Push(ccode, Getattr(n, "kind"));
} else {
Push(ccode, Getattr(n, "kind"));
Push(ccode, "typedef ");
Append(ccode, " ");
Append(ccode, Getattr(n, "tdname"));
}
Append(ccode, ";");
/* Strip comments - further code may break in presence of comments. */
strip_comments(Char(ccode));
/* Make all SWIG created typedef structs/unions/classes unnamed else
redefinition errors occur - nasty hack alert. */
if (!noTypedef) {
const char *types_array[3] = { "struct", "union", "class" };
for (int i = 0; i < 3; i++) {
char *code_ptr = Char(ccode);
while (code_ptr) {
/* Replace struct name (as in 'struct name {...}' ) with whitespace
name will be between struct and opening brace */
code_ptr = strstr(code_ptr, types_array[i]);
if (code_ptr) {
char *open_bracket_pos;
code_ptr += strlen(types_array[i]);
open_bracket_pos = strchr(code_ptr, '{');
if (open_bracket_pos) {
/* Make sure we don't have something like struct A a; */
char *semi_colon_pos = strchr(code_ptr, ';');
if (!(semi_colon_pos && (semi_colon_pos < open_bracket_pos)))
while (code_ptr < open_bracket_pos)
*code_ptr++ = ' ';
}
}
}
}
}
{
/* Remove SWIG directive %constant which may be left in the SWIG created typedefs */
char *code_ptr = Char(ccode);
while (code_ptr) {
code_ptr = strstr(code_ptr, "%constant");
if (code_ptr) {
char *directive_end_pos = strchr(code_ptr, ';');
if (directive_end_pos) {
while (code_ptr <= directive_end_pos)
*code_ptr++ = ' ';
}
}
}
}
Node *newnode = NewHash();
set_nodeType(newnode, "insert");
Setfile(newnode, Getfile(n));
Setline(newnode, Getline(n));
String *code = NewStringEmpty();
Wrapper_pretty_print(ccode, code);
Setattr(newnode, "code", code);
Delete(code);
Delattr(n, "code");
return newnode;
}
static void insertNodeAfter(Node *n, Node *c) {
Node *g = parentNode(n);
set_parentNode(c, g);
Node *ns = nextSibling(n);
if (Node *outer = Getattr(c, "nested:outer")) {
while (ns && outer == Getattr(ns, "nested:outer")) {
n = ns;
ns = nextSibling(n);
}
}
if (!ns) {
set_lastChild(g, c);
} else {
set_nextSibling(c, ns);
set_previousSibling(ns, c);
}
set_nextSibling(n, c);
set_previousSibling(c, n);
}
void Swig_nested_name_unnamed_c_structs(Node *n) {
if (!classhash)
classhash = Getattr(n, "classes");
Node *c = firstChild(n);
while (c) {
Node *next = nextSibling(c);
if (String *declName = Getattr(c, "nested:unnamed")) {
if (Node *outer = Getattr(c, "nested:outer")) {
// generate a name
String *name = NewStringf("%s_%s", Getattr(outer, "name"), declName);
Delattr(c, "nested:unnamed");
// set the name to the class and symbol table
Setattr(c, "tdname", name);
Setattr(c, "name", name);
Swig_symbol_setscope(Getattr(c, "symtab"));
Swig_symbol_setscopename(name);
// now that we have a name - gather base symbols
if (List *publicBases = Getattr(c, "baselist")) {
List *bases = Swig_make_inherit_list(name, publicBases, 0);
Swig_inherit_base_symbols(bases);
Delete(bases);
}
Setattr(classhash, name, c);
Swig_symbol_popscope();
// process declarations following this type (assign correct new type)
SwigType *ty = Copy(name);
Node *decl = nextSibling(c);
List *declList = NewList();
while (decl && Getattr(decl, "nested:unnamedtype") == c) {
Setattr(decl, "type", ty);
Append(declList, decl);
Delattr(decl, "nested:unnamedtype");
SetFlag(decl, "feature:immutable");
add_symbols_c(decl);
decl = nextSibling(decl);
}
Delete(ty);
// Check for extensions
/* // TODO: we can save extensions hash like class hash and move check_extensions() after nesting processing
if (extendhash) {
if (Node *am = Getattr(extendhash, name)) {
// Merge the extension into the symbol table
merge_extensions(c, am);
append_previous_extension(c, am);
Delattr(extendhash, clsname);
}
}*/
Swig_symbol_setscope(Swig_symbol_global_scope());
add_symbols_c(c);
Node *ins = create_insert(c);
insertNodeAfter(c, ins);
removeNode(c);
insertNodeAfter(n, c);
Delete(ins);
Delattr(c, "nested:outer");
} else {
// global unnamed struct - ignore it
c = next;
continue;
}
} else if (cparse_cplusplusout) {
if (Getattr(c, "nested:outer")) {
Node *ins = create_insert(c, true);
insertNodeAfter(c, ins);
Delete(ins);
Delattr(c, "nested:outer");
}
}
// process children
Swig_nested_name_unnamed_c_structs(c);
c = next;
}
}
static void remove_outer_class_reference(Node *n) {
for (Node *c = firstChild(n); c; c = nextSibling(c)) {
if (GetFlag(c, "feature:flatnested") || Language::instance()->nestedClassesSupport() == Language::NCS_None) {
Delattr(c, "nested:outer");
remove_outer_class_reference(c);
}
}
}
void Swig_nested_process_classes(Node *n) {
Node *c = firstChild(n);
while (c) {
Node *next = nextSibling(c);
if (!Getattr(c, "templatetype")) {
if (GetFlag(c, "nested") && (GetFlag(c, "feature:flatnested") || Language::instance()->nestedClassesSupport() == Language::NCS_None)) {
removeNode(c);
if (!checkAttribute(c, "access", "public"))
SetFlag(c, "feature:ignore");
else if (Strcmp(nodeType(n),"extend") == 0 && Strcmp(nodeType(parentNode(n)),"class") == 0)
insertNodeAfter(parentNode(n), c);
else
insertNodeAfter(n, c);
}
Swig_nested_process_classes(c);
}
c = next;
}
remove_outer_class_reference(n);
}

View file

@ -11,13 +11,11 @@
* Ocaml language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_ocaml_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
static const char *usage = (char *) "\
static const char *usage = "\
Ocaml Options (available with -ocaml)\n\
-oldvarnames - Old intermediary method names for variable wrappers\n\
-prefix <name> - Set a prefix <name> to be prepended to all names\n\
@ -30,8 +28,8 @@ 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 char *ocaml_path = (char *) "ocaml";
static String *prefix = 0;
static const char *ocaml_path = "ocaml";
static bool old_variable_names = false;
static String *classname = 0;
static String *module = 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);
}
}
@ -1534,7 +1503,7 @@ public:
/* if necessary, cast away const since Python doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", pname);
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
@ -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,16 @@
* Octave language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_octave_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
static bool global_load = true;
static String *global_name = 0;
static String *op_prefix = 0;
static const char *usage = (char *) "\
static const char *usage = "\
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 +46,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 +94,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]);
@ -111,6 +133,10 @@ public:
SWIG_config_file("octave.swg");
SWIG_typemap_lang("octave");
allow_overloading();
// Octave API is C++, so output must be C++ compatibile even when wrapping C code
if (!cparse_cplusplus)
Swig_cparse_cplusplusout(1);
}
virtual int top(Node *n) {
@ -169,10 +195,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 +210,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 +226,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 +250,6 @@ public:
Delete(f_header);
Delete(f_directors);
Delete(f_directors_h);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -270,7 +293,7 @@ public:
String *escaped_doc_str = texinfo_escape(doc_str);
if (Len(doc_str)>0) {
Printf(f_doc,"const char* %s_texinfo = ",wrap_name);
Printf(f_doc,"static const char* %s_texinfo = ",wrap_name);
Printf(f_doc,"\"-*- texinfo -*-\\n\\\n%s", escaped_doc_str);
if (Len(decl_info))
Printf(f_doc,"\\n\\\n@end deftypefn");
@ -293,14 +316,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 +360,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 +392,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);
}
@ -504,13 +523,9 @@ public:
else
return v;
}
if (Strcmp(v, "NULL") == 0)
if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 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 +534,6 @@ public:
}
virtual int functionWrapper(Node *n) {
Wrapper *f = NewWrapper();
Parm *p;
String *tm;
int j;
@ -543,7 +557,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 +749,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 +766,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 +788,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 +822,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 +851,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 +870,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 +967,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 +1080,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 +1166,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 +1263,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 +1287,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 +1319,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 +1343,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 +1377,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 +1443,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 +1459,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 +1486,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 +1523,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
@ -28,6 +26,7 @@ struct Overloaded {
int argc; /* Argument count */
ParmList *parms; /* Parameters used for overload check */
int error; /* Ambiguity error */
bool implicitconv_function; /* For ordering implicitconv functions*/
};
static int fast_dispatch_mode = 0;
@ -42,6 +41,32 @@ void Wrapper_cast_dispatch_mode_set(int flag) {
cast_dispatch_mode = flag;
}
/* -----------------------------------------------------------------------------
* mark_implicitconv_function()
*
* Mark function if it contains an implicitconv type in the parameter list
* ----------------------------------------------------------------------------- */
static void mark_implicitconv_function(Overloaded& onode) {
Parm *parms = onode.parms;
if (parms) {
bool is_implicitconv_function = false;
Parm *p = parms;
while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
continue;
}
if (GetFlag(p, "implicitconv")) {
is_implicitconv_function = true;
break;
}
p = nextSibling(p);
}
if (is_implicitconv_function)
onode.implicitconv_function = true;
}
}
/* -----------------------------------------------------------------------------
* Swig_overload_rank()
*
@ -87,6 +112,9 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
nodes[nnodes].parms = Getattr(c, "wrap:parms");
nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms);
nodes[nnodes].error = 0;
nodes[nnodes].implicitconv_function = false;
mark_implicitconv_function(nodes[nnodes]);
nnodes++;
}
c = Getattr(c, "sym:nextSibling");
@ -289,12 +317,30 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
List *result = NewList();
{
int i;
int argc_changed_index = -1;
for (i = 0; i < nnodes; i++) {
if (nodes[i].error)
Setattr(nodes[i].n, "overload:ignore", "1");
Append(result, nodes[i].n);
// Printf(stdout,"[ %d ] %s\n", i, ParmList_errorstr(nodes[i].parms));
// Swig_print_node(nodes[i].n);
// Printf(stdout,"[ %d ] %d %s\n", i, nodes[i].implicitconv_function, ParmList_errorstr(nodes[i].parms));
// Swig_print_node(nodes[i].n);
if (i == nnodes-1 || nodes[i].argc != nodes[i+1].argc) {
if (argc_changed_index+2 < nnodes && (nodes[argc_changed_index+1].argc == nodes[argc_changed_index+2].argc)) {
// Add additional implicitconv functions in same order as already ranked.
// Consider overloaded functions by argument count... only add additional implicitconv functions if
// the number of functions with the same arg count > 1, ie, only if overloaded by same argument count.
int j;
for (j = argc_changed_index + 1; j <= i; j++) {
if (nodes[j].implicitconv_function) {
SetFlag(nodes[j].n, "implicitconvtypecheckoff");
Append(result, nodes[j].n);
// Printf(stdout,"[ %d ] %d + %s\n", j, nodes[j].implicitconv_function, ParmList_errorstr(nodes[j].parms));
// Swig_print_node(nodes[j].n);
}
}
}
argc_changed_index = i;
}
}
}
return result;
@ -304,20 +350,22 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
// * print_typecheck()
// * ----------------------------------------------------------------------------- */
static bool print_typecheck(String *f, int j, Parm *pj) {
static bool print_typecheck(String *f, int j, Parm *pj, bool implicitconvtypecheckoff) {
char tmp[256];
sprintf(tmp, Char(argv_template_string), j);
String *tm = Getattr(pj, "tmap:typecheck");
if (tm) {
tm = Copy(tm);
Replaceid(tm, Getattr(pj, "lname"), "_v");
String *conv = Getattr(pj, "implicitconv");
if (conv) {
if (conv && !implicitconvtypecheckoff) {
Replaceall(tm, "$implicitconv", conv);
} else {
Replaceall(tm, "$implicitconv", "0");
}
Replaceall(tm, "$input", tmp);
Printv(f, tm, "\n", NIL);
Delete(tm);
return true;
} else
return false;
@ -717,6 +765,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
for (i = 0; i < nfunc; i++) {
Node *ni = Getitem(dispatch, i);
Parm *pi = Getattr(ni, "wrap:parms");
bool implicitconvtypecheckoff = GetFlag(ni, "implicitconvtypecheckoff") != 0;
int num_required = emit_num_required(pi);
int num_arguments = emit_num_arguments(pi);
if (GetFlag(n, "wrap:this")) {
@ -751,7 +800,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
Printf(f, "}\n");
Delete(lfmt);
}
if (print_typecheck(f, (GetFlag(n, "wrap:this") ? j + 1 : j), pj)) {
if (print_typecheck(f, (GetFlag(n, "wrap:this") ? j + 1 : j), pj, implicitconvtypecheckoff)) {
Printf(f, "if (_v) {\n");
num_braces++;
}
@ -775,6 +824,8 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
for ( /* empty */ ; num_braces > 0; num_braces--)
Printf(f, "}\n");
Printf(f, "}\n"); /* braces closes "if" for this method */
if (implicitconvtypecheckoff)
Delattr(ni, "implicitconvtypecheckoff");
}
Delete(dispatch);
return f;

View file

@ -11,15 +11,13 @@
* Perl5 language module for SWIG.
* ------------------------------------------------------------------------- */
char cvsroot_perl5_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
#include <ctype.h>
static const char *usage = (char *) "\
static const char *usage = "\
Perl5 Options (available with -perl5)\n\
-compat - Compatibility mode\n\
-const - Wrap constants as constants and not variables (implies -proxy)\n\
@ -81,8 +79,11 @@ static String *variable_tab = 0;
static File *f_begin = 0;
static File *f_runtime = 0;
static File *f_runtime_h = 0;
static File *f_header = 0;
static File *f_wrappers = 0;
static File *f_directors = 0;
static File *f_directors_h = 0;
static File *f_init = 0;
static File *f_pm = 0;
static String *pm; /* Package initialization code */
@ -126,13 +127,14 @@ public:
Printv(argc_template_string, "items", NIL);
Clear(argv_template_string);
Printv(argv_template_string, "ST(%d)", NIL);
director_language = 1;
}
/* Test to see if a type corresponds to something wrapped with a shadow class */
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);
@ -221,9 +223,63 @@ public:
* ------------------------------------------------------------ */
virtual int top(Node *n) {
/* check if directors are enabled for this module. note: this
* is a "master" switch, without which no director code will be
* emitted. %feature("director") statements are also required
* to enable directors for individual classes or methods.
*
* use %module(directors="1") modulename at the start of the
* interface file to enable director generation.
*
* TODO: directors are disallowed in conjunction with many command
* line options. Some of them are probably safe, but it will take
* some effort to validate each one.
*/
{
Node *mod = Getattr(n, "module");
if (mod) {
Node *options = Getattr(mod, "options");
if (options) {
int dirprot = 0;
if (Getattr(options, "dirprot"))
dirprot = 1;
if (Getattr(options, "nodirprot"))
dirprot = 0;
if (Getattr(options, "directors")) {
int allow = 1;
if (export_all) {
Printv(stderr, "*** directors are not supported with -exportall\n", NIL);
allow = 0;
}
if (staticoption) {
Printv(stderr, "*** directors are not supported with -static\n", NIL);
allow = 0;
}
if (!blessed) {
Printv(stderr, "*** directors are not supported with -noproxy\n", NIL);
allow = 0;
}
if (no_pmfile) {
Printv(stderr, "*** directors are not supported with -nopm\n", NIL);
allow = 0;
}
if (compat) {
Printv(stderr, "*** directors are not supported with -compat\n", NIL);
allow = 0;
}
if (allow) {
allow_directors();
if (dirprot)
allow_dirprot();
}
}
}
}
}
/* Initialize all of the output files */
String *outfile = Getattr(n, "outfile");
String *outfile_h = Getattr(n, "outfile_h");
f_begin = NewFile(outfile, "w", SWIG_output_files());
if (!f_begin) {
@ -234,6 +290,16 @@ public:
f_init = NewString("");
f_header = NewString("");
f_wrappers = NewString("");
f_directors_h = NewString("");
f_directors = NewString("");
if (directorsEnabled()) {
f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files());
if (!f_runtime_h) {
FileErrorDisplay(outfile_h);
SWIG_exit(EXIT_FAILURE);
}
}
/* Register file targets with the SWIG file handler */
Swig_register_filebyname("header", f_header);
@ -241,6 +307,8 @@ public:
Swig_register_filebyname("begin", f_begin);
Swig_register_filebyname("runtime", f_runtime);
Swig_register_filebyname("init", f_init);
Swig_register_filebyname("director", f_directors);
Swig_register_filebyname("director_h", f_directors_h);
classlist = NewList();
@ -261,6 +329,9 @@ public:
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGPERL\n");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");
}
Printf(f_runtime, "#define SWIG_CASTRANK_MODE\n");
Printf(f_runtime, "\n");
@ -271,6 +342,27 @@ public:
Node *options = Getattr(mod, "options");
module = Copy(Getattr(n,"name"));
if (directorsEnabled()) {
Swig_banner(f_directors_h);
Printf(f_directors_h, "\n");
Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", module);
Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module);
if (dirprot_mode()) {
Printf(f_directors_h, "#include <map>\n");
Printf(f_directors_h, "#include <string>\n\n");
}
Printf(f_directors, "\n\n");
Printf(f_directors, "/* ---------------------------------------------------\n");
Printf(f_directors, " * C++ director class methods\n");
Printf(f_directors, " * --------------------------------------------------- */\n\n");
if (outfile_h) {
String *filename = Swig_file_filename(outfile_h);
Printf(magic, "#include \"%s\"\n\n", filename);
Delete(filename);
}
}
if (verbose > 0) {
fprintf(stdout, "top: using module: %s\n", Char(module));
}
@ -376,6 +468,11 @@ public:
/* emit wrappers */
Language::top(n);
if (directorsEnabled()) {
// Insert director runtime into the f_runtime file (make it occur before %header section)
Swig_insert_file("director.swg", f_runtime);
}
String *base = NewString("");
/* Dump out variable wrappers */
@ -520,7 +617,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);
@ -529,12 +625,21 @@ public:
/* Close all of the files */
Dump(f_runtime, f_begin);
Dump(f_header, f_begin);
if (directorsEnabled()) {
Dump(f_directors_h, f_runtime_h);
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
Dump(f_directors, f_begin);
}
Dump(f_wrappers, f_begin);
Wrapper_pretty_print(f_init, f_begin);
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_directors);
Delete(f_directors_h);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -564,6 +669,7 @@ public:
SwigType *d = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
String *overname = 0;
int director_method = 0;
Parm *p;
int i;
@ -614,7 +720,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 */
@ -725,11 +830,36 @@ public:
Wrapper_add_localv(f, "_saved", "SV *", temp, NIL);
}
director_method = is_member_director(n) && !is_smart_pointer() && 0 != Cmp(nodeType(n), "destructor");
if (director_method) {
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Append(f->code, "director = SWIG_DIRECTOR_CAST(arg1);\n");
if (dirprot_mode() && !is_public(n)) {
Printf(f->code, "if (!director || !(director->swig_get_inner(\"%s\"))) {\n", name);
Printf(f->code, "SWIG_exception_fail(SWIG_RuntimeError, \"accessing protected member %s\");\n", name);
Append(f->code, "}\n");
}
Wrapper_add_local(f, "upcall", "bool upcall = false");
Printf(f->code, "upcall = director && SvSTASH(SvRV(ST(0))) == gv_stashpv(director->swig_get_class(), 0);\n");
}
/* Emit the function call */
if (director_method) {
Append(f->code, "try {\n");
}
/* Now write code to make the function call */
Swig_director_emit_dynamic_cast(n, f);
String *actioncode = emit_action(n);
if (director_method) {
Append(actioncode, "} catch (Swig::DirectorException& swig_err) {\n");
Append(actioncode, " sv_setsv(ERRSV, swig_err.getNative());\n");
Append(actioncode, " SWIG_fail;\n");
Append(actioncode, "}\n");
}
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
SwigType *t = Getattr(n, "type");
Replaceall(tm, "$source", Swig_cresult_name());
@ -870,6 +1000,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");
@ -1338,17 +1470,67 @@ public:
/* Output methods for managing ownership */
String *director_disown;
if (Getattr(n, "perl5:directordisown")) {
director_disown = NewStringf("%s%s($self);\n", tab4, Getattr(n, "perl5:directordisown"));
} else {
director_disown = NewString("");
}
Printv(pm,
"sub DISOWN {\n",
tab4, "my $self = shift;\n",
director_disown,
tab4, "my $ptr = tied(%$self);\n",
tab4, "delete $OWNER{$ptr};\n",
"}\n\n", "sub ACQUIRE {\n", tab4, "my $self = shift;\n", tab4, "my $ptr = tied(%$self);\n", tab4, "$OWNER{$ptr} = 1;\n", "}\n\n", NIL);
Delete(director_disown);
/* Only output the following methods if a class has member data */
Delete(operators);
operators = 0;
if (Swig_directorclass(n)) {
/* director classes need a way to recover subclass instance attributes */
Node *get_attr = NewHash();
String *mrename;
String *symname = Getattr(n, "sym:name");
mrename = Swig_name_disown(NSPACE_TODO, symname);
Replaceall(mrename, "disown", "swig_get_attr");
String *type = NewString(getClassType());
String *name = NewString("self");
SwigType_add_pointer(type);
Parm *p = NewParm(type, name, n);
Delete(name);
Delete(type);
type = NewString("SV");
SwigType_add_pointer(type);
String *action = NewString("");
Printv(action, "{\n", " Swig::Director *director = SWIG_DIRECTOR_CAST(arg1);\n",
" result = sv_newmortal();\n" " if (director) sv_setsv(result, director->swig_get_self());\n", "}\n", NIL);
Setfile(get_attr, Getfile(n));
Setline(get_attr, Getline(n));
Setattr(get_attr, "wrap:action", action);
Setattr(get_attr, "name", mrename);
Setattr(get_attr, "sym:name", mrename);
Setattr(get_attr, "type", type);
Setattr(get_attr, "parms", p);
Delete(action);
Delete(type);
Delete(p);
member_func = 1;
functionWrapper(get_attr);
member_func = 0;
Delete(get_attr);
Printv(pm, "sub FETCH {\n", tab4, "my ($self,$field) = @_;\n", tab4, "my $member_func = \"swig_${field}_get\";\n", tab4,
"if (not $self->can($member_func)) {\n", tab8, "my $h = ", cmodule, "::", mrename, "($self);\n", tab8, "return $h->{$field} if $h;\n",
tab4, "}\n", tab4, "return $self->$member_func;\n", "}\n", "\n", "sub STORE {\n", tab4, "my ($self,$field,$newval) = @_;\n", tab4,
"my $member_func = \"swig_${field}_set\";\n", tab4, "if (not $self->can($member_func)) {\n", tab8, "my $h = ", cmodule, "::", mrename,
"($self);\n", tab8, "return $h->{$field} = $newval if $h;\n", tab4, "}\n", tab4, "return $self->$member_func($newval);\n", "}\n", NIL);
Delete(mrename);
}
}
return SWIG_OK;
}
@ -1497,7 +1679,37 @@ public:
String *symname = Getattr(n, "sym:name");
member_func = 1;
Swig_save("perl5:constructorHandler", n, "parms", NIL);
if (Swig_directorclass(n)) {
Parm *parms = Getattr(n, "parms");
Parm *self;
String *name = NewString("self");
String *type = NewString("SV");
SwigType_add_pointer(type);
self = NewParm(type, name, n);
Delete(type);
Delete(name);
Setattr(self, "lname", "O");
if (parms)
set_nextSibling(self, parms);
Setattr(n, "parms", self);
Setattr(n, "wrap:self", "1");
Setattr(n, "hidden", "1");
Delete(self);
}
String *saved_nc = none_comparison;
none_comparison = NewStringf("strcmp(SvPV_nolen(ST(0)), \"%s::%s\") != 0", module, class_name);
String *saved_director_prot_ctor_code = director_prot_ctor_code;
director_prot_ctor_code = NewStringf("if ($comparison) { /* subclassed */\n" " $director_new\n" "} else {\n"
"SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" "}\n");
Language::constructorHandler(n);
Delete(none_comparison);
none_comparison = saved_nc;
Delete(director_prot_ctor_code);
director_prot_ctor_code = saved_director_prot_ctor_code;
Swig_restore(n);
if ((blessed) && (!Getattr(n, "sym:nextSibling"))) {
if (Getattr(n, "feature:shadow")) {
@ -1515,8 +1727,9 @@ public:
Printv(pcode, "sub ", Swig_name_construct(NSPACE_TODO, symname), " {\n", NIL);
}
const char *pkg = getCurrentClass() && Swig_directorclass(getCurrentClass())? "$_[0]" : "shift";
Printv(pcode,
tab4, "my $pkg = shift;\n",
tab4, "my $pkg = ", pkg, ";\n",
tab4, "my $self = ", cmodule, "::", Swig_name_construct(NSPACE_TODO, symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL);
have_constructor = 1;
@ -1638,8 +1851,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 +1882,7 @@ public:
}
/* Split the input text into lines */
List *clist = DohSplitLines(temp);
List *clist = SplitLines(temp);
Delete(temp);
int initial = 0;
String *s = 0;
@ -1755,6 +1968,543 @@ public:
String *defaultExternalRuntimeFilename() {
return NewString("swigperlrun.h");
}
virtual int classDirectorInit(Node *n) {
String *declaration = Swig_director_declaration(n);
Printf(f_directors_h, "\n");
Printf(f_directors_h, "%s\n", declaration);
Printf(f_directors_h, "public:\n");
Delete(declaration);
return Language::classDirectorInit(n);
}
virtual int classDirectorEnd(Node *n) {
if (dirprot_mode()) {
/*
This implementation uses a std::map<std::string,int>.
It should be possible to rewrite it using a more elegant way,
like copying the Java approach for the 'override' array.
But for now, this seems to be the least intrusive way.
*/
Printf(f_directors_h, "\n");
Printf(f_directors_h, "/* Internal director utilities */\n");
Printf(f_directors_h, "public:\n");
Printf(f_directors_h, " bool swig_get_inner(const char *swig_protected_method_name) const {\n");
Printf(f_directors_h, " std::map<std::string, bool>::const_iterator iv = swig_inner.find(swig_protected_method_name);\n");
Printf(f_directors_h, " return (iv != swig_inner.end() ? iv->second : false);\n");
Printf(f_directors_h, " }\n");
Printf(f_directors_h, " void swig_set_inner(const char *swig_protected_method_name, bool val) const {\n");
Printf(f_directors_h, " swig_inner[swig_protected_method_name] = val;\n");
Printf(f_directors_h, " }\n");
Printf(f_directors_h, "private:\n");
Printf(f_directors_h, " mutable std::map<std::string, bool> swig_inner;\n");
}
Printf(f_directors_h, "};\n");
return Language::classDirectorEnd(n);
}
virtual int classDirectorConstructor(Node *n) {
Node *parent = Getattr(n, "parentNode");
String *sub = NewString("");
String *decl = Getattr(n, "decl");
String *supername = Swig_class_name(parent);
String *classname = NewString("");
Printf(classname, "SwigDirector_%s", supername);
/* insert self parameter */
Parm *p;
ParmList *superparms = Getattr(n, "parms");
ParmList *parms = CopyParmList(superparms);
String *type = NewString("SV");
SwigType_add_pointer(type);
p = NewParm(type, NewString("self"), n);
set_nextSibling(p, parms);
parms = p;
if (!Getattr(n, "defaultargs")) {
/* constructor */
{
Wrapper *w = NewWrapper();
String *call;
String *basetype = Getattr(parent, "classtype");
String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, Swig::Director(self) { \n", classname, target, call);
Printf(w->def, " SWIG_DIRECTOR_RGTR((%s *)this, this); \n", basetype);
Append(w->def, "}\n");
Delete(target);
Wrapper_print(w, f_directors);
Delete(call);
DelWrapper(w);
}
/* constructor header */
{
String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
Printf(f_directors_h, " %s;\n", target);
Delete(target);
}
}
Delete(sub);
Delete(classname);
Delete(supername);
Delete(parms);
return Language::classDirectorConstructor(n);
}
virtual int classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
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 = NewString("");
ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *returntype = Getattr(n, "type");
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");
bool pure_virtual = false;
int status = SWIG_OK;
int idx;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
if (Cmp(storage, "virtual") == 0) {
if (Cmp(value, "0") == 0) {
pure_virtual = true;
}
}
/* determine if the method returns a pointer */
is_pointer = SwigType_ispointer_return(decl);
is_void = (!Cmp(returntype, "void") && !is_pointer);
/* virtual method definition */
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
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);
Delete(target);
/* header declaration */
target = Swig_method_decl(rtype, decl, name, l, 0, 1);
Printf(declaration, " virtual %s", target);
Delete(target);
// Get any exception classes in the throws typemap
ParmList *throw_parm_list = 0;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
Parm *p;
int gencomma = 0;
Append(w->def, " throw(");
Append(declaration, " throw(");
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if (Getattr(p, "tmap:throws")) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
}
String *str = SwigType_str(Getattr(p, "type"), 0);
Append(w->def, str);
Append(declaration, str);
Delete(str);
}
}
Append(w->def, ")");
Append(declaration, ")");
}
Append(w->def, " {");
Append(declaration, ";\n");
/* declare method return value
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
String *pres = NewStringf("SV *%s", Swig_cresult_name());
Wrapper_add_local(w, Swig_cresult_name(), pres);
Delete(pres);
}
}
if (ignored_method) {
if (!pure_virtual) {
if (!is_void)
Printf(w->code, "return ");
String *super_call = Swig_method_call(super, l);
Printf(w->code, "%s;\n", super_call);
Delete(super_call);
} else {
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
SwigType_namestr(name));
}
} else {
/* attach typemaps to arguments (C/C++ -> Perl) */
String *parse_args = NewString("");
String *pstack = NewString("");
Swig_director_parms_fixup(l);
/* remove the wrapper 'w' since it was producing spurious temps */
Swig_typemap_attach_parms("in", l, 0);
Swig_typemap_attach_parms("directorin", l, 0);
Swig_typemap_attach_parms("directorargout", l, w);
Wrapper_add_local(w, "SP", "dSP");
{
String *ptype = Copy(getClassType());
SwigType_add_pointer(ptype);
String *mangle = SwigType_manglestr(ptype);
Wrapper_add_local(w, "self", "SV *self");
Printf(w->code, "self = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE%s, SWIG_SHADOW);\n", mangle);
Printf(w->code, "sv_bless(self, gv_stashpv(swig_get_class(), 0));\n");
Delete(mangle);
Delete(ptype);
Append(pstack, "XPUSHs(self);\n");
}
Parm *p;
char source[256];
int outputs = 0;
if (!is_void)
outputs++;
/* build argument list and type conversion string */
idx = 0;
p = l;
while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
continue;
}
/* old style? caused segfaults without the p!=0 check
in the for() condition, and seems dangerous in the
while loop as well.
while (Getattr(p, "tmap:ignore")) {
p = Getattr(p, "tmap:ignore:next");
}
*/
if (Getattr(p, "tmap:directorargout") != 0)
outputs++;
String *pname = Getattr(p, "name");
String *ptype = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:directorin")) != 0) {
sprintf(source, "obj%d", idx++);
String *input = NewString(source);
Setattr(p, "emit:directorinput", input);
Replaceall(tm, "$input", input);
Delete(input);
Replaceall(tm, "$owner", "0");
Replaceall(tm, "$shadow", "0");
/* Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); */
Printv(wrap_args, "SV *", source, ";\n", NIL);
Printv(wrap_args, tm, "\n", NIL);
Putc('O', parse_args);
Printv(pstack, "XPUSHs(", source, ");\n", NIL);
p = Getattr(p, "tmap:directorin:next");
continue;
} else if (Cmp(ptype, "void")) {
/* special handling for pointers to other C++ director classes.
* ideally this would be left to a typemap, but there is currently no
* way to selectively apply the dynamic_cast<> to classes that have
* directors. in other words, the type "SwigDirector_$1_lname" only exists
* for classes with directors. we avoid the problem here by checking
* module.wrap::directormap, but it's not clear how to get a typemap to
* do something similar. perhaps a new default typemap (in addition
* to SWIGTYPE) called DIRECTORTYPE?
*/
if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) {
Node *module = Getattr(parent, "module");
Node *target = Swig_directormap(module, ptype);
sprintf(source, "obj%d", idx++);
String *nonconst = 0;
/* strip pointer/reference --- should move to Swig/stype.c */
String *nptype = NewString(Char(ptype) + 2);
/* name as pointer */
String *ppname = Copy(pname);
if (SwigType_isreference(ptype)) {
Insert(ppname, 0, "&");
}
/* if necessary, cast away const since Python doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", pname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
"Target language argument '%s' discards const in director method %s::%s.\n",
SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name));
} else {
nonconst = Copy(ppname);
}
Delete(nptype);
Delete(ppname);
String *mangle = SwigType_manglestr(ptype);
if (target) {
String *director = NewStringf("director_%s", mangle);
Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL);
Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
Printf(wrap_args, "if (!%s) {\n", director);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Append(wrap_args, "} else {\n");
Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
Printf(wrap_args, "SvREFCNT_inc((SV *)%s);\n", source);
Append(wrap_args, "}\n");
Delete(director);
} else {
Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Printf(pstack, "XPUSHs(sv_2mortal(%s));\n", source);
}
Putc('O', parse_args);
Delete(mangle);
Delete(nonconst);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
"Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0),
SwigType_namestr(c_classname), SwigType_namestr(name));
status = SWIG_NOWRAP;
break;
}
}
p = nextSibling(p);
}
/* add the method name as a PyString */
String *pyname = Getattr(n, "sym:name");
/* wrap complex arguments to PyObjects */
Printv(w->code, wrap_args, NIL);
/* pass the method call on to the Python object */
if (dirprot_mode() && !is_public(n)) {
Printf(w->code, "swig_set_inner(\"%s\", true);\n", name);
}
Append(w->code, "ENTER;\n");
Append(w->code, "SAVETMPS;\n");
Append(w->code, "PUSHMARK(SP);\n");
Append(w->code, pstack);
Delete(pstack);
Append(w->code, "PUTBACK;\n");
Printf(w->code, "call_method(\"%s\", G_EVAL | G_SCALAR);\n", pyname);
if (dirprot_mode() && !is_public(n))
Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
/* exception handling */
tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0);
if (!tm) {
tm = Getattr(n, "feature:director:except");
if (tm)
tm = Copy(tm);
}
Append(w->code, "if (SvTRUE(ERRSV)) {\n");
Append(w->code, " PUTBACK;\n FREETMPS;\n LEAVE;\n");
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
Replaceall(tm, "$error", "ERRSV");
Printv(w->code, Str(tm), "\n", NIL);
} else {
Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n", classname, pyname);
}
Append(w->code, "}\n");
Delete(tm);
/*
* Python method may return a simple object, or a tuple.
* for in/out aruments, we have to extract the appropriate PyObjects from the tuple,
* then marshal everything back to C/C++ (return value and output arguments).
*
*/
/* marshal return value and other outputs (if any) from PyObject to C/C++ type */
String *cleanup = NewString("");
String *outarg = NewString("");
if (outputs > 1) {
Wrapper_add_local(w, "output", "SV *output");
Printf(w->code, "if (count != %d) {\n", outputs);
Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Perl method %s.%sfailed to return a list.\");\n", classname, pyname);
Append(w->code, "}\n");
}
idx = 0;
/* marshal return value */
if (!is_void) {
Append(w->code, "SPAGAIN;\n");
Printf(w->code, "%s = POPs;\n", Swig_cresult_name());
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
if (tm != 0) {
if (outputs > 1) {
Printf(w->code, "output = POPs;\n");
Replaceall(tm, "$input", "output");
} else {
Replaceall(tm, "$input", Swig_cresult_name());
}
char temp[24];
sprintf(temp, "%d", idx);
Replaceall(tm, "$argnum", temp);
/* TODO check this */
if (Getattr(n, "wrap:disown")) {
Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
} else {
Replaceall(tm, "$disown", "0");
}
Replaceall(tm, "$result", "c_result");
Printv(w->code, tm, "\n", NIL);
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(returntype, 0),
SwigType_namestr(c_classname), SwigType_namestr(name));
status = SWIG_ERROR;
}
}
/* marshal outputs */
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
if (outputs > 1) {
Printf(w->code, "output = POPs;\n");
Replaceall(tm, "$result", "output");
} else {
Replaceall(tm, "$result", Swig_cresult_name());
}
Replaceall(tm, "$input", Getattr(p, "emit:directorinput"));
Printv(w->code, tm, "\n", NIL);
p = Getattr(p, "tmap:directorargout:next");
} else {
p = nextSibling(p);
}
}
Delete(parse_args);
Delete(cleanup);
Delete(outarg);
}
if (!ignored_method) {
Append(w->code, "PUTBACK;\n");
Append(w->code, "FREETMPS;\n");
Append(w->code, "LEAVE;\n");
}
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
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);
}
Delete(rettype);
}
}
Append(w->code, "}\n");
// We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
String *inline_extra_method = NewString("");
if (dirprot_mode() && !is_public(n) && !pure_virtual) {
Printv(inline_extra_method, declaration, NIL);
String *extra_method_name = NewStringf("%sSwigPublic", name);
Replaceall(inline_extra_method, name, extra_method_name);
Replaceall(inline_extra_method, ";\n", " {\n ");
if (!is_void)
Printf(inline_extra_method, "return ");
String *methodcall = Swig_method_call(super, l);
Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
Delete(methodcall);
Delete(extra_method_name);
}
/* emit the director method */
if (status == SWIG_OK) {
if (!Getattr(n, "defaultargs")) {
Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_directors);
Printv(f_directors_h, declaration, NIL);
Printv(f_directors_h, inline_extra_method, NIL);
}
}
/* clean up */
Delete(wrap_args);
Delete(pclassname);
DelWrapper(w);
return status;
}
int classDirectorDisown(Node *n) {
int rv;
member_func = 1;
rv = Language::classDirectorDisown(n);
member_func = 0;
if (rv == SWIG_OK && Swig_directorclass(n)) {
String *symname = Getattr(n, "sym:name");
String *disown = Swig_name_disown(NSPACE_TODO, symname);
Setattr(n, "perl5:directordisown", NewStringf("%s::%s", cmodule, disown));
}
return rv;
}
int classDirectorDestructor(Node *n) {
/* TODO: it would be nice if this didn't have to copy the body of Language::classDirectorDestructor() */
String *DirectorClassName = directorClassName(getCurrentClass());
String *body = NewString("\n");
String *ptype = Copy(getClassType());
SwigType_add_pointer(ptype);
String *mangle = SwigType_manglestr(ptype);
Printv(body, tab4, "dSP;\n", tab4, "SV *self = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE", mangle, ", SWIG_SHADOW);\n", tab4, "\n", tab4,
"sv_bless(self, gv_stashpv(swig_get_class(), 0));\n", tab4, "ENTER;\n", tab4, "SAVETMPS;\n", tab4, "PUSHMARK(SP);\n", tab4,
"XPUSHs(self);\n", tab4, "XPUSHs(&PL_sv_yes);\n", tab4, "PUTBACK;\n", tab4, "call_method(\"DESTROY\", G_EVAL | G_VOID);\n", tab4,
"FREETMPS;\n", tab4, "LEAVE;\n", NIL);
Delete(mangle);
Delete(ptype);
if (Getattr(n, "throw")) {
Printf(f_directors_h, " virtual ~%s() throw ();\n", DirectorClassName);
Printf(f_directors, "%s::~%s() throw () {%s}\n\n", DirectorClassName, DirectorClassName, body);
} else {
Printf(f_directors_h, " virtual ~%s();\n", DirectorClassName);
Printf(f_directors, "%s::~%s() {%s}\n\n", DirectorClassName, DirectorClassName, body);
}
return SWIG_OK;
}
};
/* -----------------------------------------------------------------------------

View file

@ -37,14 +37,12 @@
* (may need to add more WARN_PHP_xxx codes...)
*/
char cvsroot_php_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
#include <errno.h>
static const char *usage = (char *) "\
static const char *usage = "\
PHP Options (available with -php)\n\
-cppext <ext> - Change C++ file extension to <ext> (default is cpp)\n\
-noproxy - Don't generate proxy classes.\n\
@ -92,6 +90,7 @@ static String *s_vinit; // varinit initialization code.
static String *s_vdecl;
static String *s_cinit; // consttab initialization code.
static String *s_oinit;
static String *s_arginfo;
static String *s_entry;
static String *cs_entry;
static String *all_cs_entry;
@ -354,7 +353,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 +410,19 @@ 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(TSRMLS_D) __attribute__ ((__noreturn__));\n");
Append(s_header, "#endif\n\n");
Append(s_header, "static void SWIG_FAIL(TSRMLS_D) {\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");
@ -423,8 +432,7 @@ public:
Printf(s_header, "static void %s_destroy_globals(zend_%s_globals * globals) { (void)globals; }\n", module, module);
Printf(s_header, "\n");
Printf(s_header, "static void SWIG_ResetError() {\n");
Printf(s_header, " TSRMLS_FETCH();\n");
Printf(s_header, "static void SWIG_ResetError(TSRMLS_D) {\n");
Printf(s_header, " SWIG_ErrorMsg() = default_error_msg;\n");
Printf(s_header, " SWIG_ErrorCode() = default_error_code;\n");
Printf(s_header, "}\n");
@ -434,9 +442,8 @@ public:
Append(s_header, " zval **args[2];\n");
Append(s_header, " swig_object_wrapper *value;\n");
Append(s_header, " int type;\n");
Append(s_header, " int thisown;\n");
Append(s_header, "\n");
Append(s_header, " SWIG_ResetError();\n");
Append(s_header, " SWIG_ResetError(TSRMLS_C);\n");
Append(s_header, " if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_array_ex(2, args) != SUCCESS) {\n");
Append(s_header, " WRONG_PARAM_COUNT;\n");
Append(s_header, " }\n");
@ -451,7 +458,7 @@ public:
Append(s_header, " swig_object_wrapper *value;\n");
Append(s_header, " int type;\n");
Append(s_header, "\n");
Append(s_header, " SWIG_ResetError();\n");
Append(s_header, " SWIG_ResetError(TSRMLS_C);\n");
Append(s_header, " if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_array_ex(1, args) != SUCCESS) {\n");
Append(s_header, " WRONG_PARAM_COUNT;\n");
Append(s_header, " }\n");
@ -463,10 +470,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");
@ -513,6 +516,9 @@ public:
Printf(f_h, "PHP_RSHUTDOWN_FUNCTION(%s);\n", module);
Printf(f_h, "PHP_MINFO_FUNCTION(%s);\n\n", module);
/* start the arginfo section */
s_arginfo = NewString("/* arginfo subsection */\n");
/* start the function entry section */
s_entry = NewString("/* entry subsection */\n");
@ -528,7 +534,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 +543,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 +617,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 +632,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");
@ -640,7 +645,7 @@ public:
Dump(f_directors, f_begin);
}
Printv(f_begin, s_vdecl, s_wrappers, NIL);
Printv(f_begin, all_cs_entry, "\n\n", s_entry,
Printv(f_begin, all_cs_entry, "\n\n", s_arginfo, "\n\n", s_entry,
" SWIG_ZEND_NAMED_FE(swig_", module, "_alter_newobject,_wrap_swig_", module, "_alter_newobject,NULL)\n"
" SWIG_ZEND_NAMED_FE(swig_", module, "_get_newobject,_wrap_swig_", module, "_get_newobject,NULL)\n"
"{NULL, NULL, NULL}\n};\n\n", NIL);
@ -651,7 +656,7 @@ public:
Delete(s_vdecl);
Delete(all_cs_entry);
Delete(s_entry);
Close(f_begin);
Delete(s_arginfo);
Delete(f_runtime);
Delete(f_begin);
@ -664,18 +669,31 @@ public:
s_fakeoowrappers = NULL;
}
Printf(f_phpcode, "%s\n?>\n", s_phpclasses);
Close(f_phpcode);
Delete(f_phpcode);
return SWIG_OK;
}
/* Just need to append function names to function table to register with PHP. */
void create_command(String *cname, String *iname) {
void create_command(String *cname, String *iname, Node *n) {
// This is for the single main zend_function_entry record
Printf(f_h, "ZEND_NAMED_FUNCTION(%s);\n", iname);
String * s = cs_entry;
if (!s) s = s_entry;
Printf(s, " SWIG_ZEND_NAMED_FE(%(lower)s,%s,NULL)\n", cname, iname);
Printf(s, " SWIG_ZEND_NAMED_FE(%(lower)s,%s,swig_arginfo_%(lower)s)\n", cname, iname, cname);
// This is the above referenced arginfo structure.
ParmList *l = Getattr(n, "parms");
Printf(s_arginfo, "ZEND_BEGIN_ARG_INFO_EX(swig_arginfo_%(lower)s, 0, 0, 0)\n", cname);
for (Parm *p = l; p; p = Getattr(p, "tmap:in:next")) {
/* Ignored parameters */
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
continue;
}
int byref = GetFlag(p, "tmap:in:byref");
Printf(s_arginfo, " ZEND_ARG_PASS_INFO(%d)\n", byref);
}
Printf(s_arginfo, "ZEND_END_ARG_INFO()\n");
}
/* ------------------------------------------------------------
@ -698,7 +716,7 @@ public:
String *symname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(symname);
create_command(symname, wname);
create_command(symname, wname, n);
Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL);
Wrapper_add_local(f, "argc", "int argc");
@ -716,7 +734,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(TSRMLS_C);\n", NIL);
Printv(f->code, "}\n", NIL);
Wrapper_print(f, s_wrappers);
@ -784,21 +802,20 @@ public:
}
f = NewWrapper();
numopt = 0;
String *outarg = NewStringEmpty();
String *cleanup = NewStringEmpty();
// Not issued for overloaded functions.
if (!overloaded) {
create_command(iname, wname);
}
Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL);
emit_parameter_variables(l, f);
/* Attach standard typemaps */
emit_attach_parmmaps(l, f);
// Not issued for overloaded functions.
if (!overloaded) {
create_command(iname, wname, n);
}
// wrap:parms is used by overload resolution.
Setattr(n, "wrap:parms", l);
@ -835,7 +852,7 @@ public:
// NOTE: possible we ignore this_ptr as a param for native constructor
Printf(f->code, "SWIG_ResetError();\n");
Printf(f->code, "SWIG_ResetError(TSRMLS_C);\n");
if (numopt > 0) { // membervariable wrappers do not have optional args
Wrapper_add_local(f, "arg_count", "int arg_count");
@ -1000,11 +1017,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(TSRMLS_C);\n");
Printf(f->code, "}\n");
@ -1033,7 +1046,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 +1104,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 +1136,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 +1186,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);
}
}
}
@ -1335,6 +1339,7 @@ public:
break;
}
case T_REFERENCE:
case T_RVALUE_REFERENCE:
case T_USER:
case T_ARRAY:
Clear(value);
@ -1377,6 +1382,7 @@ public:
}
}
if (Strcmp(value, "NULL") == 0 ||
Strcmp(value, "nullptr") == 0 ||
Strcmp(value, "0") == 0 ||
Strcmp(value, "0L") == 0) {
Clear(value);
@ -1582,7 +1588,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 +1710,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 +1752,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 +2019,6 @@ done:
classnode = 0;
if (shadow) {
DOH *key;
List *baselist = Getattr(n, "bases");
Iterator ki, base;
@ -2026,7 +2031,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 +2061,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 +2112,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);
@ -2258,8 +2272,8 @@ done:
if (i) {
Insert(args, 0, ", ");
}
Printf(director_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0%s TSRMLS_CC);\n}\n", Swig_cresult_name(), ctype, sname, args);
Printf(director_prot_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0%s TSRMLS_CC);\n}\n", Swig_cresult_name(), ctype, sname, args);
Printf(director_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0 TSRMLS_CC%s);\n}\n", Swig_cresult_name(), ctype, sname, args);
Printf(director_prot_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0 TSRMLS_CC%s);\n}\n", Swig_cresult_name(), ctype, sname, args);
Delete(args);
wrapperType = directorconstructor;
@ -2320,14 +2334,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(TSRMLS_C);\n");
Printf(f->code, "}\n");
Wrapper_print(f, s_wrappers);
DelWrapper(f);
return SWIG_OK;
}
@ -2374,17 +2385,23 @@ done:
parms = p;
if (!Getattr(n, "defaultargs")) {
// There should always be a "self" parameter first.
assert(ParmList_len(parms) > 0);
/* constructor */
{
Wrapper *w = NewWrapper();
String *call;
String *basetype = Getattr(parent, "classtype");
// We put TSRMLS_DC after the self parameter in order to cope with
// any default parameters.
String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
if (((const char *)Char(target))[Len(target) - 2] == '(') {
Insert(target, Len(target) - 1, "TSRMLS_D");
} else {
Insert(target, Len(target) - 1, " TSRMLS_DC");
}
const char * p = Char(target);
const char * comma = strchr(p, ',');
size_t ins = comma ? comma - p : Len(target) - 1;
Insert(target, ins, " TSRMLS_DC");
call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, Swig::Director(self TSRMLS_CC) {", classname, target, call);
Append(w->def, "}");
@ -2396,12 +2413,14 @@ done:
/* constructor header */
{
// We put TSRMLS_DC after the self parameter in order to cope with
// any default parameters.
String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
if (((const char *)Char(target))[Len(target) - 2] == '(') {
Insert(target, Len(target) - 1, "TSRMLS_D");
} else {
Insert(target, Len(target) - 1, " TSRMLS_DC");
}
const char * p = Char(target);
const char * comma = strchr(p, ',');
size_t ins = comma ? comma - p : Len(target) - 1;
Insert(target, ins, " TSRMLS_DC");
Printf(f_directors_h, " %s;\n", target);
Delete(target);
}
@ -2412,18 +2431,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 +2455,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 +2486,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 +2513,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 +2574,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 +2616,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");
@ -2630,8 +2631,8 @@ done:
/* wrap complex arguments to zvals */
Printv(w->code, wrap_args, NIL);
Append(w->code, "call_user_function(EG(function_table), (zval**)&swig_self, &funcname,\n");
Printf(w->code, " %s, %d, args TSRMLS_CC);\n", Swig_cresult_name(), idx);
Append(w->code, "call_user_function(EG(function_table), (zval**)&swig_self, &funcname,");
Printf(w->code, " %s, %d, args TSRMLS_CC);\n", Swig_cresult_name(), idx);
if (tm) {
Printv(w->code, Str(tm), "\n", NIL);
@ -2647,19 +2648,9 @@ 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);
Replaceall(tm, "$input", Swig_cresult_name());
char temp[24];
sprintf(temp, "%d", idx);
Replaceall(tm, "$argnum", temp);
@ -2675,7 +2666,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 +2693,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 +2706,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(TSRMLS_C);\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 +2736,6 @@ done:
/* clean up */
Delete(wrap_args);
Delete(return_type);
Delete(pclassname);
DelWrapper(w);
return status;

View file

@ -29,13 +29,11 @@
*
*/
char cvsroot_pike_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h> // for isalnum()
static const char *usage = (char *) "\
static const char *usage = "\
Pike Options (available with -pike)\n\
[no additional options]\n\
\n";
@ -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"
@ -46,6 +44,7 @@ static File *f_directors_h = 0;
static File *f_init = 0;
static File *f_shadow_py = 0;
static String *f_shadow = 0;
static String *f_shadow_begin = 0;
static Hash *f_shadow_imports = 0;
static String *f_shadow_builtin_imports = 0;
static String *f_shadow_stubs = 0;
@ -98,6 +97,7 @@ static int castmode = 0;
static int extranative = 0;
static int outputtuple = 0;
static int nortti = 0;
static int relativeimport = 0;
/* flags for the make_autodoc function */
enum autodoc_t {
@ -110,7 +110,7 @@ enum autodoc_t {
};
static const char *usage1 = (char *) "\
static const char *usage1 = "\
Python Options (available with -python)\n\
-aliasobj0 - Alias obj0 when using fastunpack, needed for some old typemaps \n\
-buildnone - Use Py_BuildValue(" ") to obtain Py_None (default in Windows)\n\
@ -133,7 +133,7 @@ Python Options (available with -python)\n\
-keyword - Use keyword arguments\n\
-modern - Use modern python features only, without compatibility code\n\
-modernargs - Use \"modern\" args mechanism to pack/unpack the function arguments\n";
static const char *usage2 = (char *) "\
static const char *usage2 = "\
-newrepr - Use more informative version of __repr__ in proxy classes (default) \n\
-newvwm - New value wrapper mode, use only when everything else fails \n\
-noaliasobj0 - Don't generate an obj0 alias when using fastunpack (default) \n\
@ -150,7 +150,7 @@ static const char *usage2 = (char *) "\
-noh - Don't generate the output header file\n\
-nomodern - Don't use modern python features which are not backwards compatible \n\
-nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n";
static const char *usage3 = (char *) "\
static const char *usage3 = "\
-noolddefs - Don't emit the old method definitions even when using fastproxy (default) \n\
-nooutputtuple - Use a PyList for appending output values (default) \n\
-noproxy - Don't generate proxy classes \n\
@ -163,6 +163,7 @@ static const char *usage3 = (char *) "\
-oldrepr - Use shorter and old version of __repr__ in proxy classes\n\
-outputtuple - Use a PyTuple for outputs instead of a PyList (use carefully with legacy interfaces) \n\
-proxydel - Generate a __del__ method even though it is now redundant (default) \n\
-relativeimport - Use relative python imports \n\
-safecstrings - Use safer (but slower) C string mapping, generating copies from Python -> C/C++\n\
-threads - Add thread support for all the interface\n\
-O - Enable the following optimization options: \n\
@ -540,6 +541,9 @@ public:
builtin = 1;
Preprocessor_define("SWIGPYTHON_BUILTIN", 0);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-relativeimport") == 0) {
relativeimport = 1;
Swig_mark_arg(i);
}
}
@ -785,8 +789,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" */
@ -805,6 +812,7 @@ public:
filen = NULL;
f_shadow = NewString("");
f_shadow_begin = NewString("");
f_shadow_imports = NewHash();
f_shadow_builtin_imports = NewString("");
f_shadow_stubs = NewString("");
@ -998,10 +1006,10 @@ public:
if (!modern) {
Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
}
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
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);
}
@ -1014,7 +1022,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);
}
@ -1029,8 +1037,6 @@ public:
Delete(f_init);
Delete(f_directors);
Delete(f_directors_h);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -1049,6 +1055,267 @@ public:
return 0;
}
/* ------------------------------------------------------------
* subpkg_tail()
*
* Return the name of 'other' package relative to 'base'.
*
* 1. If 'other' is a sub-package of 'base', returns the 'other' relative to
* 'base'.
* 2. If 'other' and 'base' are equal, returns empty string "".
* 3. In any other case, NULL pointer is returned.
*
* The 'base' and 'other' are expected to be fully qualified names.
*
* NOTE: none of 'base' nor 'other' can be null.
*
* Examples:
*
* # base other tail
* -- ---- ----- ----
* 1 "Foo" "Foo.Bar" -> "Bar"
* 2 "Foo" "Foo." -> ""
* 3 "Foo" "FooB.ar" -> NULL
* 4 "Foo.Bar" "Foo.Bar" -> ""
* 5 "Foo.Bar" "Foo" -> NULL
* 6 "Foo.Bar" "Foo.Gez" -> NULL
*
* NOTE: the example #2 is actually a syntax error (at input). I believe
* swig parser prevents us from this case happening here.
* ------------------------------------------------------------ */
static String *subpkg_tail(const String *base, const String *other) {
int baselen = Len(base);
int otherlen = Len(other);
if (Strncmp(other, base, baselen) == 0) {
if ((baselen < otherlen) && (Char(other))[baselen] == '.') {
return NewString((Char(other)) + baselen + 1);
} else if (baselen == otherlen) {
return NewString("");
} else {
return 0;
}
} else {
return 0;
}
}
/* ------------------------------------------------------------
* abs_import_directive_string()
*
* Return a string containing python code to import module.
*
* pkg package name or the module being imported
* mod module name of the module being imported
* pfx optional prefix to module name
*
* NOTE: keep this function consistent with abs_import_name_string().
* ------------------------------------------------------------ */
static String *abs_import_directive_string(const String *pkg, const String *mod, const char *pfx = "") {
String *out = NewString("");
if (pkg && *Char(pkg)) {
Printf(out, "import %s.%s%s\n", pkg, pfx, mod);
} else {
Printf(out, "import %s%s\n", pfx, mod);
}
return out;
}
/* ------------------------------------------------------------
* rel_import_directive_string()
*
* Return a string containing python code to import module that
* is potentially within a package.
*
* mainpkg package name of the module which imports the other module
* pkg package name or the module being imported
* mod module name of the module being imported
* pfx optional prefix to module name
*
* NOTE: keep this function consistent with rel_import_name_string().
* ------------------------------------------------------------ */
static String *rel_import_directive_string(const String *mainpkg, const String *pkg, const String *mod, const char *pfx = "") {
/* NOTE: things are not so trivial. This is what we do here (by examples):
*
* 0. To import module 'foo', which is not in any package, we do absolute
* import:
*
* import foo
*
* 1. To import 'pkg1.pkg2.foo', when mainpkg != "pkg1" and
* mainpkg != "pkg1.pkg2" or when mainpkg is not given we do absolute
* import:
*
* import pkg1.pkg2.foo
*
* 2. To import module pkg1.foo, when mainpkg == "pkg1", we do:
*
* - for py3 = 0:
*
* import foo
*
* - for py3 = 1:
*
* from . import foo
*
* 3. To import "pkg1.pkg2.pkg3.foo", when mainpkg = "pkg1", we do:
*
* - for py3 == 0:
*
* import pkg2.pkg3.foo
*
* - for py3 == 1:
*
* from . import pkg2 # [1]
* import pkg1.pkg2.pkg3.foo
*
* NOTE: [1] is necessary for pkg2.foo to be present in the importing module
*/
String *apkg = 0; // absolute (FQDN) package name of pkg
String *rpkg = 0; // relative package name
int py3_rlen1 = 0; // length of 1st level sub-package name, used by py3
String *out = NewString("");
if (pkg && *Char(pkg)) {
if (mainpkg) {
String *tail = subpkg_tail(mainpkg, pkg);
if (tail) {
if (*Char(tail)) {
rpkg = NewString(tail);
const char *py3_end1 = Strchr(rpkg, '.');
if (!py3_end1)
py3_end1 = (Char(rpkg)) + Len(rpkg);
py3_rlen1 = py3_end1 - (Char(rpkg));
} else {
rpkg = NewString("");
}
Delete(tail);
} else {
apkg = NewString(pkg);
}
} else {
apkg = NewString(pkg);
}
} else {
apkg = NewString("");
}
if (apkg) {
Printf(out, "import %s%s%s%s\n", apkg, *Char(apkg) ? "." : "", pfx, mod);
Delete(apkg);
} else {
if (py3) {
if (py3_rlen1)
Printf(out, "from . import %.*s\n", py3_rlen1, rpkg);
Printf(out, "from .%s import %s%s\n", rpkg, pfx, mod);
} else {
Printf(out, "import %s%s%s%s\n", rpkg, *Char(rpkg) ? "." : "", pfx, mod);
}
Delete(rpkg);
}
return out;
}
/* ------------------------------------------------------------
* import_directive_string()
* ------------------------------------------------------------ */
static String *import_directive_string(const String *mainpkg, const String *pkg, const String *mod, const char *pfx = "") {
if (!relativeimport) {
return abs_import_directive_string(pkg, mod, pfx);
} else {
return rel_import_directive_string(mainpkg, pkg, mod, pfx);
}
}
/* ------------------------------------------------------------
* abs_import_name_string()
*
* Return a string with the name of a symbol (perhaps imported
* from external module by absolute import directive).
*
* mainpkg package name of current module
* mainmod module name of current module
* pkg package name of (perhaps other) module
* mod module name of (perhaps other) module
* sym symbol name
*
* NOTE: mainmod, mod, and sym can't be NULL.
* NOTE: keep this function consistent with abs_import_directive_string()
* ------------------------------------------------------------ */
static String *abs_import_name_string(const String *mainpkg, const String *mainmod, const String *pkg, const String *mod, const String *sym) {
String *out = NewString("");
if (pkg && *Char(pkg)) {
if (mainpkg && *Char(mainpkg)) {
if (Strcmp(mainpkg,pkg) != 0 || Strcmp(mainmod, mod) != 0) {
Printf(out, "%s.%s.", pkg, mod);
}
} else {
Printf(out, "%s.%s.", pkg, mod);
}
} else if ((mainpkg && *Char(mainpkg)) || Strcmp(mainmod, mod) != 0) {
Printf(out, "%s.", mod);
}
Append(out, sym);
return out;
}
/* ------------------------------------------------------------
* rel_import_name_string()
*
* Return a string with the name of a symbol (perhaps imported
* from external module by relative import directive).
*
* mainpkg package name of current module
* mainmod module name of current module
* pkg package name of (perhaps other) module
* mod module name of (perhaps other) module
* sym symbol name
*
* NOTE: mainmod, mod, and sym can't be NULL.
* NOTE: keep this function consistent with rel_import_directive_string()
* ------------------------------------------------------------ */
static String *rel_import_name_string(const String *mainpkg, const String *mainmod, const String *pkg, const String *mod, const String *sym) {
String *out = NewString("");
if (pkg && *Char(pkg)) {
String *tail = 0;
if (mainpkg)
tail = subpkg_tail(mainpkg, pkg);
if (!tail)
tail = NewString(pkg);
if (*Char(tail)) {
Printf(out, "%s.%s.", tail, mod);
} else if (Strcmp(mainmod, mod) != 0) {
Printf(out, "%s.", mod);
}
Delete(tail);
} else if ((mainpkg && *Char(mainpkg)) || Strcmp(mainmod, mod) != 0) {
Printf(out, "%s.", mod);
}
Append(out, sym);
return out;
}
/* ------------------------------------------------------------
* import_name_string()
* ------------------------------------------------------------ */
static String *import_name_string(const String *mainpkg, const String *mainmod, const String *pkg, const String *mod, const String *sym) {
if (!relativeimport) {
return abs_import_name_string(mainpkg,mainmod,pkg,mod,sym);
} else {
return rel_import_name_string(mainpkg,mainmod,pkg,mod,sym);
}
}
/* ------------------------------------------------------------
* importDirective()
* ------------------------------------------------------------ */
@ -1058,38 +1325,26 @@ public:
String *modname = Getattr(n, "module");
if (modname) {
String *import = NewString("import ");
// Find the module node for this imported module. It should be the
// first child but search just in case.
Node *mod = firstChild(n);
while (mod && Strcmp(nodeType(mod), "module") != 0)
mod = nextSibling(mod);
// Is the imported module in another package? (IOW, does it use the
// %module(package="name") option and it's different than the package
// of this module.)
Node *options = Getattr(mod, "options");
String *pkg = options ? Getattr(options, "package") : 0;
if (pkg && (!package || Strcmp(pkg, package) != 0)) {
Printf(import, "%s.", pkg);
}
// finally, output the name of the imported module
if (shadowimport) {
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)) {
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);
}
SetFlag(f_shadow_imports, import);
String *_import = import_directive_string(package, pkg, modname, "_");
if (!GetFlagAttr(f_shadow_imports, _import)) {
String *import = import_directive_string(package, pkg, modname);
Printf(builtin ? f_shadow_builtin_imports : f_shadow, "%s", import);
Delete(import);
SetFlag(f_shadow_imports, _import);
}
Delete(_import);
}
}
Delete(import);
}
}
return Language::importDirective(n);
@ -1129,7 +1384,7 @@ public:
}
/* Split the input text into lines */
List *clist = DohSplitLines(temp);
List *clist = SplitLines(temp);
Delete(temp);
int initial = 0;
String *s = 0;
@ -1185,9 +1440,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) {
@ -1602,11 +1857,11 @@ 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");
if (Strcmp(v, "NULL") == 0)
if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0)
return SwigType_ispointer(t) ? NewString("None") : NewString("0");
}
return 0;
@ -2354,7 +2609,7 @@ public:
Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", iname, num_fixed_arguments, tuple_arguments);
}
}
} else if (tuple_arguments > 0) {
} else {
Printf(parse_args, "if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, num_fixed_arguments, tuple_arguments);
Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL);
}
@ -2660,7 +2915,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");
@ -3117,22 +3372,23 @@ public:
But for now, this seems to be the least intrusive way.
*/
Printf(f_directors_h, "\n\n");
Printf(f_directors_h, "/* Internal Director utilities */\n");
Printf(f_directors_h, "\n");
Printf(f_directors_h, "/* Internal director utilities */\n");
Printf(f_directors_h, "public:\n");
Printf(f_directors_h, " bool swig_get_inner(const char* swig_protected_method_name) const {\n");
Printf(f_directors_h, " bool swig_get_inner(const char *swig_protected_method_name) const {\n");
Printf(f_directors_h, " std::map<std::string, bool>::const_iterator iv = swig_inner.find(swig_protected_method_name);\n");
Printf(f_directors_h, " return (iv != swig_inner.end() ? iv->second : false);\n");
Printf(f_directors_h, " }\n\n");
Printf(f_directors_h, " }\n");
Printf(f_directors_h, " void swig_set_inner(const char* swig_protected_method_name, bool val) const\n");
Printf(f_directors_h, " { swig_inner[swig_protected_method_name] = val;}\n\n");
Printf(f_directors_h, " void swig_set_inner(const char *swig_protected_method_name, bool val) const {\n");
Printf(f_directors_h, " swig_inner[swig_protected_method_name] = val;\n");
Printf(f_directors_h, " }\n");
Printf(f_directors_h, "private:\n");
Printf(f_directors_h, " mutable std::map<std::string, bool> swig_inner;\n");
}
if (director_method_index) {
Printf(f_directors_h, "\n\n");
Printf(f_directors_h, "\n");
Printf(f_directors_h, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n");
Printf(f_directors_h, "/* VTable implementation */\n");
Printf(f_directors_h, " PyObject *swig_get_method(size_t method_index, const char *method_name) const {\n");
@ -3206,19 +3462,13 @@ public:
if (shadow && !Getattr(n, "feature:onlychildren")) {
Node *mod = Getattr(n, "module");
if (mod) {
String *importname = NewString("");
String *modname = Getattr(mod, "name");
if (Strcmp(modname, mainmodule) != 0) {
// 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)) {
Printf(importname, "%s.", pkg);
}
Printf(importname, "%s.", modname);
}
Append(importname, Getattr(n, "sym:name"));
Node *options = Getattr(mod, "options");
String *pkg = options ? Getattr(options, "package") : 0;
String *sym = Getattr(n, "sym:name");
String *importname = import_name_string(package, mainmodule, pkg, modname, sym);
Setattr(n, "python:proxy", importname);
Delete(importname);
}
}
int result = Language::classDeclaration(n);
@ -3386,7 +3636,20 @@ public:
if (GetFlag(n, "feature:python:nondynamic"))
Setattr(n, "feature:python:tp_setattro", "SWIG_Python_NonDynamicSetAttr");
String *quoted_symname = NewStringf("\"%s\"", symname);
Node *mod = Getattr(n, "module");
String *modname = mod ? Getattr(mod, "name") : 0;
String *quoted_symname;
if (package) {
if (modname)
quoted_symname = NewStringf("\"%s.%s.%s\"", package, modname, symname);
else
quoted_symname = NewStringf("\"%s.%s\"", package, symname);
} else {
if (modname)
quoted_symname = NewStringf("\"%s.%s\"", modname, symname);
else
quoted_symname = NewStringf("\"%s\"", symname);
}
String *quoted_rname = NewStringf("\"%s\"", rname);
char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "SwigPyBuiltin_BadInit";
String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES");
@ -3444,7 +3707,7 @@ public:
printSlot(f, getSlot(n, "feature:python:tp_dict"), "tp_dict");
printSlot(f, getSlot(n, "feature:python:tp_descr_get"), "tp_descr_get", "descrgetfunc");
printSlot(f, getSlot(n, "feature:python:tp_descr_set"), "tp_descr_set", "descrsetfunc");
Printf(f, " (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */\n");
Printf(f, " (Py_ssize_t)offsetof(SwigPyObject, dict), /* tp_dictoffset */\n");
printSlot(f, tp_init, "tp_init", "initproc");
printSlot(f, getSlot(n, "feature:python:tp_alloc"), "tp_alloc", "allocfunc");
printSlot(f, "0", "tp_new", "newfunc");
@ -3773,7 +4036,7 @@ public:
if (builtin)
builtin_pre_decl(n);
/* Overide the shadow file so we can capture its methods */
/* Override the shadow file so we can capture its methods */
f_shadow = NewString("");
// Set up type check for director class constructor
@ -3840,7 +4103,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);
@ -3855,7 +4118,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);
}
@ -4500,12 +4763,16 @@ public:
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) {
if (!ImportMode && (Cmp(section, "python") == 0 || Cmp(section, "shadow") == 0)) {
if (shadow) {
String *pycode = pythoncode(code, shadow_indent);
Printv(f_shadow, pycode, NIL);
Delete(pycode);
}
} else if (!ImportMode && (Cmp(section, "pythonbegin") == 0)) {
String *pycode = pythoncode(code, "");
Printv(f_shadow_begin, pycode, NIL);
Delete(pycode);
} else {
Language::insertDirective(n);
}
@ -4575,18 +4842,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;
@ -4600,35 +4866,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);
@ -4651,7 +4897,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, ", ");
@ -4676,7 +4922,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);
}
@ -4794,7 +5040,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
/* if necessary, cast away const since Python doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", pname);
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
@ -4945,16 +5191,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++);
@ -4980,7 +5217,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;
}
@ -5017,8 +5254,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);
@ -5056,7 +5293,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,12 +11,9 @@
* R language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_r_cxx[] = "$Id$";
#include "swigmod.h"
static const double DEFAULT_NUMBER = .0000123456712312312323;
static const int MAX_OVERLOAD_ARGS = 5;
static String* replaceInitialDash(const String *name)
{
@ -208,7 +205,7 @@ static void writeListByLine(List *l, File *out, bool quote = 0) {
}
static const char *usage = (char *)"\
static const char *usage = "\
R Options (available with -r)\n\
-copystruct - Emit R code to copy C structs (on by default)\n\
-cppcast - Enable C++ casting operators (default) \n\
@ -572,7 +569,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 +679,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 +723,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
Delete(rtype);
Delete(rettype);
Delete(funcparams);
DelWrapper(f);
return funName;
}
@ -837,7 +835,6 @@ int R::top(Node *n) {
Delete(f_init);
Delete(s_header);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -871,8 +868,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 +882,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 +902,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 +1606,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 +1622,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 +1843,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 +1901,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 +2112,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");
}
@ -2160,7 +2160,7 @@ int R::functionWrapper(Node *n) {
/* If we are dealing with a method in an C++ class, then
add the name of the R function and its definition.
XXX need to figure out how to store the Wrapper if possible in the hash/list.
Would like to be able to do this so that we can potentialy insert
Would like to be able to do this so that we can potentially insert
*/
if(processing_member_access_function || processing_class_member_function) {
addAccessor(member_name, sfun, iname);
@ -2298,7 +2298,7 @@ int R::classDeclaration(Node *n) {
/* If we have a typedef union { ... } U, then we never get to see the typedef
via a regular call to typedefHandler. Instead, */
if(Getattr(n, "unnamed") && Strcmp(Getattr(n, "storage"), "typedef") == 0
if(Getattr(n, "unnamed") && Getattr(n, "storage") && Strcmp(Getattr(n, "storage"), "typedef") == 0
&& Getattr(n, "tdname") && Strcmp(Getattr(n, "tdname"), name) == 0) {
if (debugMode)
Printf(stdout, "Typedef in the class declaration for %s\n", name);
@ -2348,7 +2348,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 +2450,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,10 +126,11 @@ enum autodoc_t {
AUTODOC_FUNC,
AUTODOC_METHOD,
AUTODOC_GETTER,
AUTODOC_SETTER
AUTODOC_SETTER,
AUTODOC_NONE
};
static const char *usage = (char *) "\
static const char *usage = "\
Ruby Options (available with -ruby)\n\
-autorename - Enable renaming of classes and methods to follow Ruby coding standards\n\
-cppcast - Enable C++ casting operators (default)\n\
@ -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:
@ -789,13 +788,9 @@ private:
else
return v;
}
if (Strcmp(v, "NULL") == 0)
if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 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()
@ -1111,7 +1111,7 @@ public:
/* typedef void *VALUE */
SwigType *value = NewSwigType(T_VOID);
SwigType_add_pointer(value);
SwigType_typedef(value, (char *) "VALUE");
SwigType_typedef(value, "VALUE");
Delete(value);
/* Set module name */
@ -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);
}
}
@ -3218,7 +3201,7 @@ public:
/* if necessary, cast away const since Ruby doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", parameterName);
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(parameterType, 0), ppname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(parameterType, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(parameterType, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
@ -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

@ -103,6 +103,7 @@ public:
virtual int usingDeclaration(Node *n);
virtual int namespaceDeclaration(Node *n);
virtual int templateDeclaration(Node *n);
virtual int lambdaDeclaration(Node *n);
enum AccessMode { PUBLIC, PRIVATE, PROTECTED };
@ -124,6 +125,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[]);
@ -219,8 +222,11 @@ public:
virtual int validIdentifier(String *s); /* valid identifier? */
virtual int addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope = ""); /* Add symbol */
virtual void dumpSymbols();
virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */
virtual Node *classLookup(const SwigType *s); /* Class lookup */
virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */
virtual Hash* symbolAddScope(const_String_or_char_ptr scope);
virtual Hash* symbolScopeLookup(const_String_or_char_ptr scope);
virtual Hash* symbolScopePseudoSymbolLookup(const_String_or_char_ptr scope);
virtual Node *classLookup(const SwigType *s) const; /* Class lookup */
virtual Node *enumLookup(SwigType *s); /* Enum lookup */
virtual int abstractClassTest(Node *n); /* Is class really abstract? */
virtual int is_assignable(Node *n); /* Is variable assignable? */
@ -301,6 +307,29 @@ protected:
/* Some language modules require additional wrappers for virtual methods not declared in sub-classes */
virtual bool extraDirectorProtectedCPPMethodsRequired() const;
public:
enum NestedClassSupport {
NCS_None, // Target language does not have an equivalent to nested classes
NCS_Full, // Target language does have an equivalent to nested classes and is fully implemented
NCS_Unknown // Target language may or may not have an equivalent to nested classes. If it does, it has not been implemented yet.
};
/* Does target language support nested classes? Default is NCS_Unknown.
If NCS_Unknown is returned, then the nested classes will be ignored unless
%feature "flatnested" is applied to them, in which case they will appear in global space.
If the target language does not support the notion of class
nesting, the language module should return NCS_None from this function, and
the nested classes will be moved to the global scope (like implicit global %feature "flatnested").
*/
virtual NestedClassSupport nestedClassesSupport() const;
protected:
/* 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;
/* Identify if a wrapped global or member variable n should use the naturalvar feature */
int use_naturalvar_mode(Node *n) const;
/* Director subclass comparison test */
String *none_comparison;
@ -383,7 +412,6 @@ int is_protected(Node *n);
int is_member_director(Node *parentnode, Node *member);
int is_member_director(Node *member);
int is_non_virtual_protected_access(Node *n); /* Check if the non-virtual protected members are required (for directors) */
int use_naturalvar_mode(Node *n);
void Wrapper_virtual_elimination_mode_set(int);
void Wrapper_fast_dispatch_mode_set(int);
@ -410,5 +438,19 @@ int Swig_contract_mode_get();
void Swig_browser(Node *n, int);
void Swig_default_allocators(Node *n);
void Swig_process_types(Node *n);
void Swig_nested_process_classes(Node *n);
void Swig_nested_name_unnamed_c_structs(Node *n);
template <class T> class save_value {
T _value;
T& _value_ptr;
save_value(const save_value&);
save_value& operator=(const save_value&);
public:
save_value(T& value) : _value(value), _value_ptr(value) {}
save_value(T& value, T new_val) : _value(value), _value_ptr(value) { value = new_val; }
~save_value() { _value_ptr = _value; }
};
#endif

View file

@ -11,13 +11,11 @@
* Tcl8 language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_tcl8_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
static const char *usage = (char *) "\
static const char *usage = "\
Tcl 8 Options (available with -tcl)\n\
-itcl - Enable ITcl support\n\
-nosafe - Leave out SafeInit module function.\n\
@ -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 */
@ -173,6 +178,20 @@ class TypePass:private Dispatcher {
}
continue;
}
// A case when both outer and nested classes inherit from the same parent. Constructor may be found instead of the class itself.
} else if (GetFlag(cls, "nested") && checkAttribute(bcls, "nodeType", "constructor")) {
bcls = Getattr(bcls, "parentNode");
if (Getattr(bcls, "typepass:visit")) {
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));
}
}
break;
}
if (Strcmp(nodeType(bcls), "classforward") != 0) {
Swig_error(Getfile(bname), Getline(bname), "'%s' is not a valid base class.\n", SwigType_namestr(bname));
@ -185,9 +204,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));
@ -393,7 +417,7 @@ class TypePass:private Dispatcher {
String *unnamed = Getattr(n, "unnamed");
String *storage = Getattr(n, "storage");
String *kind = Getattr(n, "kind");
Node *oldinclass = inclass;
save_value<Node*> oldinclass(inclass);
List *olist = normalize;
Symtab *symtab;
String *nname = 0;
@ -452,6 +476,17 @@ class TypePass:private Dispatcher {
if (unnamed && tdname && (Cmp(storage, "typedef") == 0)) {
SwigType_typedef(unnamed, tdname);
}
// name of the outer class should already be patched to contain its outer classes names, but not to contain namespaces
// namespace name (if present) is added after processing child nodes
if (Getattr(n, "nested:outer") && name) {
String *outerName = Getattr(Getattr(n, "nested:outer"), "name");
name = NewStringf("%s::%s", outerName, name);
Setattr(n, "name", name);
if (tdname) {
tdname = NewStringf("%s::%s", outerName, tdname);
Setattr(n, "tdname", tdname);
}
}
if (nsname && name) {
nname = NewStringf("%s::%s", nsname, name);
@ -469,7 +504,8 @@ class TypePass:private Dispatcher {
SwigType_attach_symtab(Getattr(n, "symtab"));
/* Inherit type definitions into the class */
if (name) {
if (name && !(GetFlag(n, "nested") && !checkAttribute(n, "access", "public") &&
(GetFlag(n, "feature:flatnested") || Language::instance()->nestedClassesSupport() == Language::NCS_None))) {
cplus_inherit_types(n, 0, nname ? nname : (fname ? fname : name));
}
@ -502,8 +538,6 @@ class TypePass:private Dispatcher {
normalize = olist;
inclass = oldinclass;
/* If in a namespace, patch the class name */
if (nname) {
Setattr(n, "name", nname);
@ -514,7 +548,7 @@ class TypePass:private Dispatcher {
}
/* ------------------------------------------------------------
* namespaceDeclaration()
* templateDeclaration()
* ------------------------------------------------------------ */
virtual int templateDeclaration(Node *n) {
@ -533,6 +567,14 @@ class TypePass:private Dispatcher {
return SWIG_OK;
}
/* ------------------------------------------------------------
* lambdaDeclaration()
* ------------------------------------------------------------ */
virtual int lambdaDeclaration(Node *) {
return SWIG_OK;
}
/* ------------------------------------------------------------
* classforwardDeclaration()
* ------------------------------------------------------------ */
@ -560,12 +602,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);
}
@ -638,7 +677,7 @@ class TypePass:private Dispatcher {
if (GetFlag(n, "conversion_operator")) {
/* The call to the operator in the generated wrapper must be fully qualified in order to compile */
SwigType *name = Getattr(n, "name");
SwigType *qualifiedname = Swig_symbol_string_qualify(name,0);
SwigType *qualifiedname = Swig_symbol_string_qualify(name, 0);
Clear(name);
Append(name, qualifiedname);
Delete(qualifiedname);
@ -697,11 +736,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 +744,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;
}
@ -847,16 +876,17 @@ class TypePass:private Dispatcher {
virtual int enumvalueDeclaration(Node *n) {
String *name = Getattr(n, "name");
String *value = Getattr(n, "value");
String *scopedenum = Getattr(parentNode(n), "scopedenum");
if (!value)
value = name;
if (Strcmp(value, name) == 0) {
String *new_value;
if ((nsname || inclass) && cparse_cplusplus) {
if ((nsname || inclass || scopedenum) && cparse_cplusplus) {
new_value = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value);
} else {
new_value = NewString(value);
}
if ((nsname || inclass) && !cparse_cplusplus) {
if ((nsname || inclass || scopedenum) && !cparse_cplusplus) {
String *cppvalue = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value);
Setattr(n, "cppvalue", cppvalue); /* for target languages that always generate C++ code even when wrapping C code */
}
@ -886,7 +916,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
@ -974,7 +1019,7 @@ class TypePass:private Dispatcher {
String *symname = Getattr(n, "sym:name");
while (c) {
if (Strcmp(nodeType(c), "cdecl") == 0) {
if (!(checkAttribute(c, "storage", "static")
if (!(Swig_storage_isstatic(c)
|| checkAttribute(c, "storage", "typedef")
|| checkAttribute(c, "storage", "friend")
|| (Getattr(c, "feature:extend") && !Getattr(c, "code"))
@ -1069,8 +1114,7 @@ class TypePass:private Dispatcher {
* list of overloaded methods we have just added in as child nodes to the "using" node.
* The node will still exist, it is just the symbol table linked list of overloaded methods
* which is hacked. */
if (Getattr(n, "sym:overloaded"))
{
if (Getattr(n, "sym:overloaded")) {
int cnt = 0;
#ifdef DEBUG_OVERLOADED
Node *debugnode = n;
@ -1133,7 +1177,7 @@ class TypePass:private Dispatcher {
#ifdef DEBUG_OVERLOADED
show_overloaded(debugnode);
#endif
clean_overloaded(n); // Needed?
clean_overloaded(n); // Needed?
}
}
}
@ -1144,6 +1188,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"));
*/
}
}
}
@ -1232,3 +1281,4 @@ void Swig_process_types(Node *n) {
return;
TypePass::pass(n);
}

View file

@ -13,11 +13,9 @@
// TODO: remove remnants of lisptype
char cvsroot_uffi_cxx[] = "$Id$";
#include "swigmod.h"
static const char *usage = (char *) "\
static const char *usage = "\
UFFI Options (available with -uffi)\n\
-identifier-converter <type or funcname> - \n\
Specifies the type of conversion to do on C identifiers\n\
@ -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,11 +12,9 @@
* the naming of local variables, calling conventions, and so forth.
* ----------------------------------------------------------------------------- */
char cvsroot_cwrap_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
extern int cparse_cplusplus;
static const char *cresult_variable_name = "result";
static Parm *nonvoid_parms(Parm *p) {
@ -90,6 +88,19 @@ static String *Swig_clocal(SwigType *t, const_String_or_char_ptr name, const_Str
Delete(lstrname);
}
break;
case T_RVALUE_REFERENCE:
if (value) {
String *lstrname = SwigType_lstr(t, name);
String *lstr = SwigType_lstr(t, 0);
Printf(decl, "%s = (%s) &%s_defrvalue", lstrname, lstr, name);
Delete(lstrname);
Delete(lstr);
} else {
String *lstrname = SwigType_lstr(t, name);
Printf(decl, "%s = 0", lstrname);
Delete(lstrname);
}
break;
case T_VOID:
break;
case T_VARARGS:
@ -255,7 +266,35 @@ int Swig_cargs(Wrapper *w, ParmList *p) {
Delete(defname);
Delete(defvalue);
}
} else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING))) {
} else if (tycode == T_RVALUE_REFERENCE) {
if (pvalue) {
SwigType *tvalue;
String *defname, *defvalue, *rvalue, *qvalue;
rvalue = SwigType_typedef_resolve_all(pvalue);
qvalue = SwigType_typedef_qualified(rvalue);
defname = NewStringf("%s_defrvalue", lname);
tvalue = Copy(type);
SwigType_del_rvalue_reference(tvalue);
tycode = SwigType_type(tvalue);
if (tycode != T_USER) {
/* plain primitive type, we copy the the def value */
String *lstr = SwigType_lstr(tvalue, defname);
defvalue = NewStringf("%s = %s", lstr, qvalue);
Delete(lstr);
} else {
/* user type, we copy the reference value */
String *str = SwigType_str(type, defname);
defvalue = NewStringf("%s = %s", str, qvalue);
Delete(str);
}
Wrapper_add_localv(w, defname, defvalue, NIL);
Delete(tvalue);
Delete(rvalue);
Delete(qvalue);
Delete(defname);
Delete(defvalue);
}
} else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING) || (tycode == T_WSTRING))) {
pvalue = (String *) "0";
}
if (!altty) {
@ -295,6 +334,23 @@ String *Swig_cresult(SwigType *t, const_String_or_char_ptr name, const_String_or
Delete(lstr);
}
break;
case T_RVALUE_REFERENCE:
{
String *const_lvalue_str;
String *lstr = SwigType_lstr(t, 0);
SwigType *tt = Copy(t);
SwigType_del_rvalue_reference(tt);
SwigType_add_qualifier(tt, "const");
SwigType_add_reference(tt);
const_lvalue_str = SwigType_rcaststr(tt, 0);
Printf(fcall, "%s = (%s) &%s", name, lstr, const_lvalue_str);
Delete(const_lvalue_str);
Delete(tt);
Delete(lstr);
}
break;
case T_USER:
Printf(fcall, "%s = ", name);
break;
@ -411,7 +467,7 @@ static String *Swig_cmethod_call(const_String_or_char_ptr name, ParmList *parms,
return func;
if (!self)
self = (char *) "(this)->";
self = "(this)->";
Append(func, self);
if (SwigType_istemplate(name) && (strncmp(Char(name), "operator ", 9) == 0)) {
@ -719,7 +775,25 @@ String *Swig_cmemberset_call(const_String_or_char_ptr name, SwigType *type, Stri
if (SwigType_type(type) != T_ARRAY) {
if (!Strstr(type, "enum $unnamed")) {
String *dref = Swig_wrapped_var_deref(type, pname1, varcref);
Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref);
int extra_cast = 0;
if (cparse_cplusplusout) {
/* Required for C nested structs compiled as C++ as a duplicate of the nested struct is put into the global namespace.
* We could improve this by adding the extra casts just for nested structs rather than all structs. */
String *base = SwigType_base(type);
extra_cast = SwigType_isclass(base);
Delete(base);
}
if (extra_cast) {
String *lstr;
SwigType *ptype = Copy(type);
SwigType_add_pointer(ptype);
lstr = SwigType_lstr(ptype, 0);
Printf(func, "if (%s) *(%s)&%s%s = %s", pname0, lstr, self, name, dref);
Delete(lstr);
Delete(ptype);
} else {
Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref);
}
Delete(dref);
} else {
Printf(func, "if (%s && sizeof(int) == sizeof(%s%s)) *(int*)(void*)&(%s%s) = %s", pname0, self, name, self, name, pname1);
@ -759,6 +833,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 +881,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 +908,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 +929,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) {
@ -820,8 +940,8 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
self = NewString("(*(this))->");
is_smart_pointer_overload = 1;
}
else if (Cmp(Getattr(n, "storage"), "static") == 0) {
String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname;
else if (Swig_storage_isstatic(n)) {
String *cname = Getattr(n, "extendsmartclassname") ? Getattr(n, "extendsmartclassname") : classname;
String *ctname = SwigType_namestr(cname);
self = NewStringf("(*(%s const *)this)->", ctname);
is_smart_pointer_overload = 1;
@ -894,7 +1014,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"));
@ -935,7 +1058,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
String *defaultargs = Getattr(n, "defaultargs");
String *code = Getattr(n, "code");
String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname;
String *cname = Getattr(n, "extendsmartclassname") ? Getattr(n, "extendsmartclassname") : classname;
String *membername = Swig_name_member(nspace, cname, name);
String *mangled = Swig_name_mangle(membername);
int is_smart_pointer = flags & CWRAP_SMART_POINTER;
@ -959,7 +1082,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
String *func = NewStringf("%s(", mangled);
String *cres;
if (Cmp(Getattr(n, "storage"), "static") != 0) {
if (!Swig_storage_isstatic(n)) {
String *pname = Swig_cparm_name(pp, i);
String *ctname = SwigType_namestr(cname);
String *fadd = 0;
@ -1014,6 +1137,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;
}
@ -1057,20 +1181,14 @@ Node *Swig_directormap(Node *module, String *type) {
* This function creates a C wrapper for a C constructor function.
* ----------------------------------------------------------------------------- */
int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) {
ParmList *parms;
Parm *prefix_args;
int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags, String *directorname) {
Parm *p;
ParmList *directorparms;
SwigType *type;
int use_director;
use_director = Swig_directorclass(n);
parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
int use_director = Swig_directorclass(n);
ParmList *parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
/* Prepend the list of prefix_args (if any) */
prefix_args = Getattr(n, "director:prefix_args");
Parm *prefix_args = Getattr(n, "director:prefix_args");
if (prefix_args != NIL) {
Parm *p2, *p3;
@ -1122,9 +1240,7 @@ 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;
String *name = Getattr(parent, "sym:name");
String *directorname = NewStringf("SwigDirector_%s", name);
int abstract = Getattr(parent, "abstracts") != 0;
String *action = NewStringEmpty();
String *tmp_none_comparison = Copy(none_comparison);
String *director_call;
@ -1168,7 +1284,6 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
Setattr(n, "wrap:action", action);
Delete(tmp_none_comparison);
Delete(action);
Delete(directorname);
} else {
String *call = Swig_cppconstructor_call(classname, parms);
String *cres = Swig_cresult(type, Swig_cresult_name(), call);
@ -1352,7 +1467,7 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) {
int varcref = flags & CWRAP_NATURAL_VAR;
if (flags & CWRAP_SMART_POINTER) {
if (checkAttribute(n, "storage", "static")) {
if (Swig_storage_isstatic(n)) {
Node *sn = Getattr(n, "cplus:staticbase");
String *base = Getattr(sn, "name");
self = NewStringf("%s::", base);

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);
@ -93,16 +94,16 @@ void Swig_fragment_emit(Node *n) {
String *name = 0;
String *type = 0;
name = Getattr(n, "value");
if (!name) {
name = n;
}
if (!fragments) {
Swig_warning(WARN_FRAGMENT_NOT_FOUND, Getfile(n), Getline(n), "Fragment '%s' not found.\n", name);
return;
}
name = Getattr(n, "value");
if (!name) {
name = n;
}
type = Getattr(n, "type");
if (type) {
mangle = Swig_string_mangle(type);

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 */
@ -165,7 +163,8 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_
String *filename;
List *spath = 0;
char *cname;
int i, ilen;
int i, ilen, nbytes;
char bom[3];
if (!directories)
directories = NewList();
@ -193,6 +192,14 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_
if (f) {
Delete(lastpath);
lastpath = filename;
/* Skip the UTF-8 BOM if it's present */
nbytes = fread(bom, 1, 3, f);
if (nbytes == 3 && bom[0] == (char)0xEF && bom[1] == (char)0xBB && bom[2] == (char)0xBF) {
/* skip */
} else {
fseek(f, 0, SEEK_SET);
}
}
return f;
}
@ -317,58 +324,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 +366,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>
@ -74,11 +72,11 @@ void Swig_banner(File *f) {
Printf(f, "/* ----------------------------------------------------------------------------\n\
* This file was automatically generated by SWIG (http://www.swig.org).\n\
* Version %s\n\
* \n\
* This file is not intended to be easily readable and contains a number of \n\
*\n\
* This file is not intended to be easily readable and contains a number of\n\
* coding conventions designed to improve portability and efficiency. Do not make\n\
* changes to this file unless you know what you are doing--modify the SWIG \n\
* interface file instead. \n", Swig_package_version());
* changes to this file unless you know what you are doing--modify the SWIG\n\
* interface file instead.\n", Swig_package_version());
/* String too long for ISO compliance */
Printf(f, " * ----------------------------------------------------------------------------- */\n");
@ -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);
@ -215,8 +205,8 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) {
/* -----------------------------------------------------------------------------
* Swig_filename_correct()
*
* Corrects filename paths by removing duplicate delimeters and on non-unix
* systems use the correct delimeter across the whole name.
* Corrects filename paths by removing duplicate delimiters and on non-unix
* systems use the correct delimiter across the whole name.
* ----------------------------------------------------------------------------- */
void Swig_filename_correct(String *filename) {
@ -272,6 +262,49 @@ void Swig_filename_unescape(String *filename) {
#endif
}
/* -----------------------------------------------------------------------------
* Swig_storage_isextern()
*
* Determine if the storage class specifier is extern (but not externc)
* ----------------------------------------------------------------------------- */
int Swig_storage_isextern(Node *n) {
const String *storage = Getattr(n, "storage");
return storage ? Strcmp(storage, "extern") == 0 || Strncmp(storage, "extern ", 7) == 0 : 0;
}
/* -----------------------------------------------------------------------------
* Swig_storage_isexternc()
*
* Determine if the storage class specifier is externc (but not plain extern)
* ----------------------------------------------------------------------------- */
int Swig_storage_isexternc(Node *n) {
const String *storage = Getattr(n, "storage");
return storage ? Strcmp(storage, "externc") == 0 || Strncmp(storage, "externc ", 8) == 0 : 0;
}
/* -----------------------------------------------------------------------------
* Swig_storage_isstatic_custom()
*
* Determine if the storage class specifier is static
* ----------------------------------------------------------------------------- */
int Swig_storage_isstatic_custom(Node *n, const_String_or_char_ptr storage_name) {
const String *storage = Getattr(n, storage_name);
return storage ? Strncmp(storage, "static", 6) == 0 : 0;
}
/* -----------------------------------------------------------------------------
* Swig_storage_isstatic()
*
* Determine if the storage class specifier is static
* ----------------------------------------------------------------------------- */
int Swig_storage_isstatic(Node *n) {
return Swig_storage_isstatic_custom(n, "storage");
}
/* -----------------------------------------------------------------------------
* Swig_string_escape()
*
@ -880,8 +913,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 +931,7 @@ String *Swig_scopename_last(const String *s) {
}
}
}
return NewString(cc + 2);
return NewString(cc);
}
/* -----------------------------------------------------------------------------
@ -1114,6 +1147,55 @@ String *Swig_string_strip(String *s) {
return ns;
}
/* -----------------------------------------------------------------------------
* Swig_offset_string()
*
* Insert number tabs before each new line in s
* ----------------------------------------------------------------------------- */
void Swig_offset_string(String *s, int number) {
char *res, *p, *end, *start;
/* count a number of lines in s */
int lines = 1;
int len = Len(s);
if (len == 0)
return;
start = strchr(Char(s), '\n');
while (start) {
++lines;
start = strchr(start + 1, '\n');
}
/* do not count pending new line */
if ((Char(s))[len-1] == '\n')
--lines;
/* allocate a temporary storage for a padded string */
res = (char*)malloc(len + lines * number * 2 + 1);
res[len + lines * number * 2] = 0;
/* copy lines to res, prepending tabs to each line */
p = res; /* output pointer */
start = Char(s); /* start of a current line */
end = strchr(start, '\n'); /* end of a current line */
while (end) {
memset(p, ' ', number*2);
p += number*2;
memcpy(p, start, end - start + 1);
p += end - start + 1;
start = end + 1;
end = strchr(start, '\n');
}
/* process the last line */
if (*start) {
memset(p, ' ', number*2);
p += number*2;
strcpy(p, start);
}
/* replace 's' contents with 'res' */
Clear(s);
Append(s, res);
free(res);
}
#ifdef HAVE_PCRE
#include <pcre.h>
@ -1147,8 +1229,40 @@ err_out:
exit(1);
}
/* This function copies len characters from src to dst, possibly applying case conversions to them: if convertCase is 1, to upper case and if it is -1, to lower
* case. If convertNextOnly is 1, only a single character is converted (and convertCase is reset), otherwise all of them are. */
static void copy_with_maybe_case_conversion(String *dst, const char *src, int len, int *convertCase, int convertNextOnly)
{
/* Deal with the trivial cases first. */
if (!len)
return;
if (!*convertCase) {
Write(dst, src, len);
return;
}
/* If we must convert only the first character, do it and write the rest at once. */
if (convertNextOnly) {
int src_char = *src;
Putc(*convertCase == 1 ? toupper(src_char) : tolower(src_char), dst);
*convertCase = 0;
if (len > 1) {
Write(dst, src + 1, len - 1);
}
} else {
/* We need to convert all characters. */
int i;
for (i = 0; i < len; i++, src++) {
int src_char = *src;
Putc(*convertCase == 1 ? toupper(src_char) : tolower(src_char), dst);
}
}
}
String *replace_captures(int num_captures, const char *input, String *subst, int captures[], String *pattern, String *s)
{
int convertCase = 0, convertNextOnly = 0;
String *result = NewStringEmpty();
const char *p = Char(subst);
@ -1156,10 +1270,10 @@ String *replace_captures(int num_captures, const char *input, String *subst, int
/* Copy part without substitutions */
const char *q = strchr(p, '\\');
if (!q) {
Write(result, p, strlen(p));
copy_with_maybe_case_conversion(result, p, strlen(p), &convertCase, convertNextOnly);
break;
}
Write(result, p, q - p);
copy_with_maybe_case_conversion(result, p, q - p, &convertCase, convertNextOnly);
p = q + 1;
/* Handle substitution */
@ -1170,12 +1284,39 @@ String *replace_captures(int num_captures, const char *input, String *subst, int
if (group < num_captures) {
int l = captures[group*2], r = captures[group*2 + 1];
if (l != -1) {
Write(result, input + l, r - l);
copy_with_maybe_case_conversion(result, input + l, r - l, &convertCase, convertNextOnly);
}
} else {
Swig_error("SWIG", Getline(s), "PCRE capture replacement failed while matching \"%s\" using \"%s\" - request for group %d is greater than the number of captures %d.\n",
Char(pattern), input, group, num_captures-1);
}
} else {
/* Handle Perl-like case conversion escapes. */
switch (*p) {
case 'u':
convertCase = 1;
convertNextOnly = 1;
break;
case 'U':
convertCase = 1;
convertNextOnly = 0;
break;
case 'l':
convertCase = -1;
convertNextOnly = 1;
break;
case 'L':
convertCase = -1;
convertNextOnly = 0;
break;
case 'E':
convertCase = 0;
break;
default:
Swig_error("SWIG", Getline(s), "Unrecognized escape character '%c' in the replacement string \"%s\".\n",
*p, Char(subst));
}
p++;
}
}

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>
@ -776,7 +774,7 @@ void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *d
* concatenating the feature name plus ':' plus the attribute name.
* ----------------------------------------------------------------------------- */
void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, String *value, Hash *featureattribs) {
void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, const_String_or_char_ptr value, Hash *featureattribs) {
Hash *n;
Hash *fhash;
@ -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")) {
@ -937,8 +938,7 @@ static int nodes_are_equivalent(Node *a, Node *b, int a_inclass) {
}
/* static functions */
if ((Cmp(a_storage, "static") == 0)
|| (Cmp(b_storage, "static") == 0)) {
if (Swig_storage_isstatic(a) || Swig_storage_isstatic(b)) {
if (Cmp(a_storage, b_storage) != 0)
return 0;
}
@ -1648,6 +1648,80 @@ void Swig_name_inherit(String *base, String *derived) {
Swig_name_object_inherit(Swig_cparse_features(), base, derived);
}
/* -----------------------------------------------------------------------------
* Swig_inherit_base_symbols()
* ----------------------------------------------------------------------------- */
void Swig_inherit_base_symbols(List *bases) {
if (bases) {
Iterator s;
for (s = First(bases); s.item; s = Next(s)) {
Symtab *st = Getattr(s.item, "symtab");
if (st) {
Setfile(st, Getfile(s.item));
Setline(st, Getline(s.item));
Swig_symbol_inherit(st);
}
}
Delete(bases);
}
}
/* -----------------------------------------------------------------------------
* Swig_make_inherit_list()
* ----------------------------------------------------------------------------- */
List *Swig_make_inherit_list(String *clsname, List *names, String *Namespaceprefix) {
int i, ilen;
String *derived;
List *bases = NewList();
if (Namespaceprefix)
derived = NewStringf("%s::%s", Namespaceprefix, clsname);
else
derived = NewString(clsname);
ilen = Len(names);
for (i = 0; i < ilen; i++) {
String *base;
String *n = Getitem(names, i);
/* Try to figure out where this symbol is */
Node *s = Swig_symbol_clookup(n, 0);
if (s) {
while (s && (Strcmp(nodeType(s), "class") != 0)) {
/* Not a class. Could be a typedef though. */
String *storage = Getattr(s, "storage");
if (storage && (Strcmp(storage, "typedef") == 0)) {
String *nn = Getattr(s, "type");
s = Swig_symbol_clookup(nn, Getattr(s, "sym:symtab"));
} else {
break;
}
}
if (s && ((Strcmp(nodeType(s), "class") == 0) || (Strcmp(nodeType(s), "template") == 0))) {
String *q = Swig_symbol_qualified(s);
Append(bases, s);
if (q) {
base = NewStringf("%s::%s", q, Getattr(s, "name"));
Delete(q);
} else {
base = NewString(Getattr(s, "name"));
}
} else {
base = NewString(n);
}
} else {
base = NewString(n);
}
if (base) {
Swig_name_inherit(base, derived);
Delete(base);
}
}
return bases;
}
/* -----------------------------------------------------------------------------
* void Swig_name_str()
*

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>
@ -37,6 +35,7 @@ struct Scanner {
String *error; /* Last error message (if any) */
int error_line; /* Error line number */
int freeze_line; /* Suspend line number updates */
List *brackets; /* Current level of < > brackets on each level */
};
typedef struct Locator {
@ -46,6 +45,9 @@ typedef struct Locator {
} Locator;
static int follow_locators = 0;
static void brackets_push(Scanner *);
static void brackets_clear(Scanner *);
/* -----------------------------------------------------------------------------
* NewScanner()
*
@ -65,7 +67,10 @@ Scanner *NewScanner(void) {
s->text = NewStringEmpty();
s->str = 0;
s->error = 0;
s->error_line = 0;
s->freeze_line = 0;
s->brackets = NewList();
brackets_push(s);
return s;
}
@ -75,15 +80,16 @@ Scanner *NewScanner(void) {
* Delete a scanner object.
* ----------------------------------------------------------------------------- */
void DelScanner(Scanner * s) {
void DelScanner(Scanner *s) {
assert(s);
Delete(s->scanobjs);
Delete(s->brackets);
Delete(s->text);
Delete(s->file);
Delete(s->error);
Delete(s->str);
free(s->idstart);
free(s);
free(s);
}
/* -----------------------------------------------------------------------------
@ -92,11 +98,12 @@ void DelScanner(Scanner * s) {
* Clear the contents of a scanner object.
* ----------------------------------------------------------------------------- */
void Scanner_clear(Scanner * s) {
void Scanner_clear(Scanner *s) {
assert(s);
Delete(s->str);
Clear(s->text);
Clear(s->scanobjs);
brackets_clear(s);
Delete(s->error);
s->str = 0;
s->error = 0;
@ -104,6 +111,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;
*/
}
/* -----------------------------------------------------------------------------
@ -113,7 +126,7 @@ void Scanner_clear(Scanner * s) {
* immediately before returning to the old text.
* ----------------------------------------------------------------------------- */
void Scanner_push(Scanner * s, String *txt) {
void Scanner_push(Scanner *s, String *txt) {
assert(s && txt);
Push(s->scanobjs, txt);
if (s->str) {
@ -132,7 +145,7 @@ void Scanner_push(Scanner * s, String *txt) {
* call to Scanner_token().
* ----------------------------------------------------------------------------- */
void Scanner_pushtoken(Scanner * s, int nt, const_String_or_char_ptr val) {
void Scanner_pushtoken(Scanner *s, int nt, const_String_or_char_ptr val) {
assert(s);
assert((nt >= 0) && (nt < SWIG_MAXTOKENS));
s->nexttoken = nt;
@ -148,7 +161,7 @@ void Scanner_pushtoken(Scanner * s, int nt, const_String_or_char_ptr val) {
* Set the file and line number location of the scanner.
* ----------------------------------------------------------------------------- */
void Scanner_set_location(Scanner * s, String *file, int line) {
void Scanner_set_location(Scanner *s, String *file, int line) {
Setline(s->str, line);
Setfile(s->str, file);
s->line = line;
@ -160,7 +173,7 @@ void Scanner_set_location(Scanner * s, String *file, int line) {
* Get the current file.
* ----------------------------------------------------------------------------- */
String *Scanner_file(Scanner * s) {
String *Scanner_file(Scanner *s) {
return Getfile(s->str);
}
@ -169,7 +182,7 @@ String *Scanner_file(Scanner * s) {
*
* Get the current line number
* ----------------------------------------------------------------------------- */
int Scanner_line(Scanner * s) {
int Scanner_line(Scanner *s) {
return s->line;
}
@ -178,7 +191,7 @@ int Scanner_line(Scanner * s) {
*
* Get the line number on which the current token starts
* ----------------------------------------------------------------------------- */
int Scanner_start_line(Scanner * s) {
int Scanner_start_line(Scanner *s) {
return s->start_line;
}
@ -188,7 +201,7 @@ int Scanner_start_line(Scanner * s) {
* Change the set of additional characters that can be used to start an identifier.
* ----------------------------------------------------------------------------- */
void Scanner_idstart(Scanner * s, const char *id) {
void Scanner_idstart(Scanner *s, const char *id) {
free(s->idstart);
s->idstart = Swig_copy_string(id);
}
@ -198,7 +211,7 @@ void Scanner_idstart(Scanner * s, const char *id) {
*
* Returns the next character from the scanner or 0 if end of the string.
* ----------------------------------------------------------------------------- */
static char nextchar(Scanner * s) {
static char nextchar(Scanner *s) {
int nc;
if (!s->str)
return 0;
@ -209,10 +222,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++;
@ -242,8 +253,7 @@ String *Scanner_errmsg(Scanner *s) {
return s->error;
}
int
Scanner_errline(Scanner *s) {
int Scanner_errline(Scanner *s) {
return s->error_line;
}
@ -257,12 +267,108 @@ static void freeze_line(Scanner *s, int val) {
s->freeze_line = val;
}
/* -----------------------------------------------------------------------------
* brackets_count()
*
* Returns the number of brackets at the current depth.
* A syntax error with unbalanced ) brackets will result in a NULL pointer return.
* ----------------------------------------------------------------------------- */
static int *brackets_count(Scanner *s) {
int *count;
if (Len(s->brackets) > 0)
count = (int *)Data(Getitem(s->brackets, 0));
else
count = 0;
return count;
}
/* -----------------------------------------------------------------------------
* brackets_clear()
*
* Resets the current depth and clears all brackets.
* Usually called at the end of statements;
* ----------------------------------------------------------------------------- */
static void brackets_clear(Scanner *s) {
Clear(s->brackets);
brackets_push(s); /* base bracket count should always be created */
}
/* -----------------------------------------------------------------------------
* brackets_increment()
*
* Increases the number of brackets at the current depth.
* Usually called when a single '<' is found.
* ----------------------------------------------------------------------------- */
static void brackets_increment(Scanner *s) {
int *count = brackets_count(s);
if (count)
(*count)++;
}
/* -----------------------------------------------------------------------------
* brackets_decrement()
*
* Decreases the number of brackets at the current depth.
* Usually called when a single '>' is found.
* ----------------------------------------------------------------------------- */
static void brackets_decrement(Scanner *s) {
int *count = brackets_count(s);
if (count)
(*count)--;
}
/* -----------------------------------------------------------------------------
* brackets_reset()
*
* Sets the number of '<' brackets back to zero. Called at the point where
* it is no longer possible to have a matching closing >> pair for a template.
* ----------------------------------------------------------------------------- */
static void brackets_reset(Scanner *s) {
int *count = brackets_count(s);
if (count)
*count = 0;
}
/* -----------------------------------------------------------------------------
* brackets_push()
*
* Increases the depth of brackets.
* Usually called when '(' is found.
* ----------------------------------------------------------------------------- */
static void brackets_push(Scanner *s) {
int *newInt = malloc(sizeof(int));
*newInt = 0;
Push(s->brackets, NewVoid(newInt, free));
}
/* -----------------------------------------------------------------------------
* brackets_pop()
*
* Decreases the depth of brackets.
* Usually called when ')' is found.
* ----------------------------------------------------------------------------- */
static void brackets_pop(Scanner *s) {
if (Len(s->brackets) > 0) /* protect against unbalanced ')' brackets */
Delitem(s->brackets, 0);
}
/* -----------------------------------------------------------------------------
* brackets_allow_shift()
*
* Return 1 to allow shift (>>), or 0 if (>>) should be split into (> >).
* This is for C++11 template syntax for closing templates.
* ----------------------------------------------------------------------------- */
static int brackets_allow_shift(Scanner *s) {
int *count = brackets_count(s);
return !count || (*count <= 0);
}
/* -----------------------------------------------------------------------------
* retract()
*
* Retract n characters
* ----------------------------------------------------------------------------- */
static void retract(Scanner * s, int n) {
static void retract(Scanner *s, int n) {
int i, l;
char *str;
@ -273,7 +379,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);
}
}
@ -403,14 +509,16 @@ static void get_escape(Scanner *s) {
* Return the raw value of the next token.
* ----------------------------------------------------------------------------- */
static int look(Scanner * s) {
int state;
static int look(Scanner *s) {
int state = 0;
int c = 0;
String *str_delimiter = 0;
state = 0;
Clear(s->text);
s->start_line = s->line;
Setfile(s->text, Getfile(s->str));
while (1) {
switch (state) {
case 0:
@ -432,32 +540,40 @@ static int look(Scanner * s) {
case 1000:
if ((c = nextchar(s)) == 0)
return (0);
return (0);
if (c == '%')
state = 4; /* Possibly a SWIG directive */
/* Look for possible identifiers */
/* Look for possible identifiers or unicode/delimiter strings */
else if ((isalpha(c)) || (c == '_') ||
(s->idstart && strchr(s->idstart, c)))
(s->idstart && strchr(s->idstart, c))) {
state = 7;
}
/* Look for single character symbols */
else if (c == '(')
else if (c == '(') {
brackets_push(s);
return SWIG_TOKEN_LPAREN;
else if (c == ')')
}
else if (c == ')') {
brackets_pop(s);
return SWIG_TOKEN_RPAREN;
else if (c == ';')
}
else if (c == ';') {
brackets_clear(s);
return SWIG_TOKEN_SEMI;
}
else if (c == ',')
return SWIG_TOKEN_COMMA;
else if (c == '*')
state = 220;
else if (c == '}')
return SWIG_TOKEN_RBRACE;
else if (c == '{')
else if (c == '{') {
brackets_reset(s);
return SWIG_TOKEN_LBRACE;
}
else if (c == '=')
state = 33;
else if (c == '+')
@ -499,16 +615,16 @@ static int look(Scanner * s) {
state = 1; /* Comment (maybe) */
s->start_line = s->line;
}
else if (c == '\"') {
state = 2; /* Possibly a string */
s->start_line = s->line;
Clear(s->text);
}
else if (c == ':')
state = 5; /* maybe double colon */
else if (c == '0')
state = 83; /* An octal or hex value */
else if (c == '\"') {
state = 2; /* A string constant */
s->start_line = s->line;
Clear(s->text);
}
else if (c == '\'') {
s->start_line = s->line;
Clear(s->text);
@ -587,18 +703,63 @@ static int look(Scanner * s) {
break;
case 2: /* Processing a string */
if (!str_delimiter) {
state=20;
break;
}
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated string\n");
return SWIG_TOKEN_ERROR;
}
if (c == '\"') {
Delitem(s->text, DOH_END);
return SWIG_TOKEN_STRING;
} else if (c == '\\') {
Delitem(s->text, DOH_END);
get_escape(s);
} else
state = 2;
else if (c == '(') {
state = 20;
}
else {
char temp[2] = { 0, 0 };
temp[0] = c;
Append( str_delimiter, temp );
}
break;
case 20: /* Inside the string */
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated string\n");
return SWIG_TOKEN_ERROR;
}
if (!str_delimiter) { /* Ordinary string: "value" */
if (c == '\"') {
Delitem(s->text, DOH_END);
return SWIG_TOKEN_STRING;
} else if (c == '\\') {
Delitem(s->text, DOH_END);
get_escape(s);
}
} else { /* Custom delimiter string: R"XXXX(value)XXXX" */
if (c==')') {
int i=0;
String *end_delimiter = NewStringEmpty();
while ((c = nextchar(s)) != 0 && c!='\"') {
char temp[2] = { 0, 0 };
temp[0] = c;
Append( end_delimiter, temp );
i++;
}
if (Strcmp( str_delimiter, end_delimiter )==0) {
Delete( end_delimiter ); /* Correct end delimiter )XXXX" occured */
Delete( str_delimiter );
str_delimiter = 0;
return SWIG_TOKEN_STRING;
} else { /* Incorrect end delimiter occured */
retract( s, i );
Delete( end_delimiter );
}
}
}
break;
case 3: /* Maybe a not equals */
@ -716,41 +877,137 @@ static int look(Scanner * s) {
break;
case 60: /* shift operators */
if ((c = nextchar(s)) == 0)
if ((c = nextchar(s)) == 0) {
brackets_increment(s);
return SWIG_TOKEN_LESSTHAN;
}
if (c == '<')
state = 240;
else if (c == '=')
return SWIG_TOKEN_LTEQUAL;
else {
retract(s, 1);
brackets_increment(s);
return SWIG_TOKEN_LESSTHAN;
}
break;
case 61:
if ((c = nextchar(s)) == 0)
if ((c = nextchar(s)) == 0) {
brackets_decrement(s);
return SWIG_TOKEN_GREATERTHAN;
if (c == '>')
}
if (c == '>' && brackets_allow_shift(s))
state = 250;
else if (c == '=')
return SWIG_TOKEN_GTEQUAL;
else {
retract(s, 1);
brackets_decrement(s);
return SWIG_TOKEN_GREATERTHAN;
}
break;
case 7: /* Identifier */
if ((c = nextchar(s)) == 0)
state = 71;
else if (isalnum(c) || (c == '_') || (c == '$')) {
state = 7;
} else {
case 7: /* Identifier or true/false or unicode/custom delimiter string */
if (c == 'R') { /* Possibly CUSTOM DELIMITER string */
state = 72;
break;
}
else if (c == 'L') { /* Probably identifier but may be a wide string literal */
state = 77;
break;
}
else if (c != 'u' && c != 'U') { /* Definitely an identifier */
state = 70;
break;
}
if ((c = nextchar(s)) == 0) {
state = 76;
}
else if (c == '\"') { /* Definitely u, U or L string */
retract(s, 1);
state = 1000;
}
else if (c == 'R') { /* Possibly CUSTOM DELIMITER u, U, L string */
state = 73;
}
else if (c == '8') { /* Possibly u8 string */
state = 71;
}
else {
retract(s, 1); /* Definitely an identifier */
state = 70;
}
break;
case 71: /* Identifier or true/false */
case 70: /* Identifier */
if ((c = nextchar(s)) == 0)
state = 76;
else if (isalnum(c) || (c == '_') || (c == '$')) {
state = 70;
} else {
retract(s, 1);
state = 76;
}
break;
case 71: /* Possibly u8 string */
if ((c = nextchar(s)) == 0) {
state = 76;
}
else if (c=='\"') {
retract(s, 1); /* Definitely u8 string */
state = 1000;
}
else if (c=='R') {
state = 74; /* Possibly CUSTOM DELIMITER u8 string */
}
else {
retract(s, 2); /* Definitely an identifier. Retract 8" */
state = 70;
}
break;
case 72: /* Possibly CUSTOM DELIMITER string */
case 73:
case 74:
if ((c = nextchar(s)) == 0) {
state = 76;
}
else if (c=='\"') {
retract(s, 1); /* Definitely custom delimiter u, U or L string */
str_delimiter = NewStringEmpty();
state = 1000;
}
else {
if (state==72) {
retract(s, 1); /* Definitely an identifier. Retract ? */
}
else if (state==73) {
retract(s, 2); /* Definitely an identifier. Retract R? */
}
else if (state==74) {
retract(s, 3); /* Definitely an identifier. Retract 8R? */
}
state = 70;
}
break;
case 75: /* Special identifier $ */
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_DOLLAR;
if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) {
state = 70;
} else {
retract(s,1);
if (Len(s->text) == 1) return SWIG_TOKEN_DOLLAR;
state = 76;
}
break;
case 76: /* Identifier or true/false */
if (cparse_cplusplus) {
if (Strcmp(s->text, "true") == 0)
return SWIG_TOKEN_BOOL;
@ -760,15 +1017,56 @@ static int look(Scanner * s) {
return SWIG_TOKEN_ID;
break;
case 75: /* Special identifier $ */
case 77: /*identifier or wide string literal*/
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_DOLLAR;
if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) {
return SWIG_TOKEN_ID;
else if (c == '\"') {
s->start_line = s->line;
Clear(s->text);
state = 78;
}
else if (c == '\'') {
s->start_line = s->line;
Clear(s->text);
state = 79;
}
else if (isalnum(c) || (c == '_') || (c == '$'))
state = 7;
} else {
retract(s,1);
if (Len(s->text) == 1) return SWIG_TOKEN_DOLLAR;
state = 71;
else {
retract(s, 1);
return SWIG_TOKEN_ID;
}
break;
case 78: /* Processing a wide string literal*/
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n");
return SWIG_TOKEN_ERROR;
}
if (c == '\"') {
Delitem(s->text, DOH_END);
return SWIG_TOKEN_WSTRING;
} else if (c == '\\') {
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n");
return SWIG_TOKEN_ERROR;
}
}
break;
case 79: /* Processing a wide char literal */
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide character constant\n");
return SWIG_TOKEN_ERROR;
}
if (c == '\'') {
Delitem(s->text, DOH_END);
return (SWIG_TOKEN_WCHAR);
} else if (c == '\\') {
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide character literal\n");
return SWIG_TOKEN_ERROR;
}
}
break;
@ -1094,7 +1392,7 @@ static int look(Scanner * s) {
* Real entry point to return the next token. Returns 0 if at end of input.
* ----------------------------------------------------------------------------- */
int Scanner_token(Scanner * s) {
int Scanner_token(Scanner *s) {
int t;
Delete(s->error);
if (s->nexttoken >= 0) {
@ -1118,7 +1416,7 @@ int Scanner_token(Scanner * s) {
* Return the lexene associated with the last returned token.
* ----------------------------------------------------------------------------- */
String *Scanner_text(Scanner * s) {
String *Scanner_text(Scanner *s) {
return s->text;
}
@ -1128,7 +1426,7 @@ String *Scanner_text(Scanner * s) {
* Skips to the end of a line
* ----------------------------------------------------------------------------- */
void Scanner_skip_line(Scanner * s) {
void Scanner_skip_line(Scanner *s) {
char c;
int done = 0;
Clear(s->text);
@ -1138,7 +1436,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;
}
@ -1153,7 +1451,7 @@ void Scanner_skip_line(Scanner * s) {
* (...). Ignores symbols inside comments or strings.
* ----------------------------------------------------------------------------- */
int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) {
int Scanner_skip_balanced(Scanner *s, int startchar, int endchar) {
char c;
int num_levels = 1;
int state = 0;
@ -1279,6 +1577,114 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) {
return 0;
}
/* -----------------------------------------------------------------------------
* Scanner_get_raw_text_balanced()
*
* Returns raw text between 2 braces, does not change scanner state in any way
* ----------------------------------------------------------------------------- */
String *Scanner_get_raw_text_balanced(Scanner *s, int startchar, int endchar) {
String *result = 0;
char c;
int old_line = s->line;
String *old_text = Copy(s->text);
long position = Tell(s->str);
int num_levels = 1;
int state = 0;
char temp[2] = { 0, 0 };
temp[0] = (char) startchar;
Clear(s->text);
Setfile(s->text, Getfile(s->str));
Setline(s->text, s->line);
Append(s->text, temp);
while (num_levels > 0) {
if ((c = nextchar(s)) == 0) {
Clear(s->text);
Append(s->text, old_text);
Delete(old_text);
s->line = old_line;
return 0;
}
switch (state) {
case 0:
if (c == startchar)
num_levels++;
else if (c == endchar)
num_levels--;
else if (c == '/')
state = 10;
else if (c == '\"')
state = 20;
else if (c == '\'')
state = 30;
break;
case 10:
if (c == '/')
state = 11;
else if (c == '*')
state = 12;
else if (c == startchar) {
state = 0;
num_levels++;
}
else
state = 0;
break;
case 11:
if (c == '\n')
state = 0;
else
state = 11;
break;
case 12: /* first character inside C comment */
if (c == '*')
state = 14;
else
state = 13;
break;
case 13:
if (c == '*')
state = 14;
break;
case 14: /* possible end of C comment */
if (c == '*')
state = 14;
else if (c == '/')
state = 0;
else
state = 13;
break;
case 20:
if (c == '\"')
state = 0;
else if (c == '\\')
state = 21;
break;
case 21:
state = 20;
break;
case 30:
if (c == '\'')
state = 0;
else if (c == '\\')
state = 31;
break;
case 31:
state = 30;
break;
default:
break;
}
}
Seek(s->str, position, SEEK_SET);
result = Copy(s->text);
Clear(s->text);
Append(s->text, old_text);
Delete(old_text);
s->line = old_line;
return result;
}
/* -----------------------------------------------------------------------------
* Scanner_isoperator()
*
@ -1319,7 +1725,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>
@ -43,6 +41,7 @@ char cvsroot_stype_c[] = "$Id$";
*
* 'p.' = Pointer (*)
* 'r.' = Reference (&)
* 'z.' = Rvalue reference (&&)
* 'a(n).' = Array of size n [n]
* 'f(..,..).' = Function with arguments (args)
* 'q(str).' = Qualifier (such as const or volatile) (const, volatile)
@ -130,12 +129,22 @@ SwigType *NewSwigType(int t) {
case T_UCHAR:
return NewString("unsigned char");
break;
case T_STRING:{
case T_STRING: {
SwigType *t = NewString("char");
SwigType_add_qualifier(t, "const");
SwigType_add_pointer(t);
return t;
break;
}
case T_WCHAR:
return NewString("wchar_t");
break;
case T_WSTRING: {
SwigType *t = NewString("wchar_t");
SwigType_add_pointer(t);
return t;
break;
}
case T_LONGLONG:
return NewString("long long");
break;
@ -145,6 +154,9 @@ SwigType *NewSwigType(int t) {
case T_VOID:
return NewString("void");
break;
case T_AUTO:
return NewString("auto");
break;
default:
break;
}
@ -232,7 +244,7 @@ int SwigType_isconst(const SwigType *t) {
int SwigType_ismutable(const SwigType *t) {
int r;
SwigType *qt = SwigType_typedef_resolve_all(t);
if (SwigType_isreference(qt) || SwigType_isarray(qt)) {
if (SwigType_isreference(qt) || SwigType_isrvalue_reference(qt) || SwigType_isarray(qt)) {
Delete(SwigType_pop(qt));
}
r = SwigType_isconst(qt);
@ -575,6 +587,12 @@ String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
Insert(result, 0, "(");
Append(result, ")");
}
} else if (SwigType_isrvalue_reference(element)) {
Insert(result, 0, "&&");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result, 0, "(");
Append(result, ")");
}
} else if (SwigType_isarray(element)) {
DOH *size;
Append(result, "[");
@ -639,10 +657,9 @@ SwigType *SwigType_ltype(const SwigType *s) {
SwigType *tt = Copy(tc);
td = 0;
while ((td = SwigType_typedef_resolve(tt))) {
if (td && (SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) {
if (td && (SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td) || SwigType_isrvalue_reference(td))) {
/* We need to use the typedef type */
Delete(tt);
tt = td;
break;
} else if (td) {
Delete(tt);
@ -679,6 +696,13 @@ SwigType *SwigType_ltype(const SwigType *s) {
Append(result, "p.");
}
firstarray = 0;
} else if (SwigType_isrvalue_reference(element)) {
if (notypeconv) {
Append(result, element);
} else {
Append(result, "p.");
}
firstarray = 0;
} else if (SwigType_isarray(element) && firstarray) {
if (notypeconv) {
Append(result, element);
@ -758,14 +782,14 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
rs = s;
}
if ((SwigType_isconst(rs) || SwigType_isarray(rs) || SwigType_isreference(rs))) {
if ((SwigType_isconst(rs) || SwigType_isarray(rs) || SwigType_isreference(rs) || SwigType_isrvalue_reference(rs))) {
td = 0;
} else {
td = SwigType_typedef_resolve(rs);
}
if (td) {
if ((SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) {
if ((SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td) || SwigType_isrvalue_reference(td))) {
elements = SwigType_split(td);
} else {
elements = SwigType_split(rs);
@ -824,6 +848,15 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
}
if (!isfunction)
isreference = 1;
} else if (SwigType_isrvalue_reference(element)) {
Insert(result, 0, "&&");
if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "(");
Append(result, ")");
}
if (!isfunction)
isreference = 1;
clear = 0;
} else if (SwigType_isarray(element)) {
DOH *size;
if (firstarray && !isreference) {
@ -900,6 +933,12 @@ String *SwigType_lcaststr(const SwigType *s, const_String_or_char_ptr name) {
Delete(str);
if (name)
Append(result, name);
} else if (SwigType_isrvalue_reference(s)) {
String *str = SwigType_str(s, 0);
Printf(result, "(%s)", str);
Delete(str);
if (name)
Append(result, name);
} else if (SwigType_isqualifier(s)) {
String *lstr = SwigType_lstr(s, 0);
Printf(result, "(%s)%s", lstr, name);

View file

@ -79,6 +79,7 @@ extern "C" {
#define T_FLTCPLX 23
#define T_DBLCPLX 24
#define T_NUMERIC 25
#define T_AUTO 26
#define T_COMPLEX T_DBLCPLX
@ -95,10 +96,14 @@ extern "C" {
#define T_FUNCTION 37
#define T_MPOINTER 38
#define T_VARARGS 39
#define T_RVALUE_REFERENCE 40
#define T_WSTRING 41
#define T_SYMBOL 98
#define T_ERROR 99
/* --- File interface --- */
#include "swigfile.h"
@ -124,6 +129,8 @@ extern "C" {
extern SwigType *SwigType_pop_arrays(SwigType *t);
extern SwigType *SwigType_add_reference(SwigType *t);
extern SwigType *SwigType_del_reference(SwigType *t);
extern SwigType *SwigType_add_rvalue_reference(SwigType *t);
extern SwigType *SwigType_del_rvalue_reference(SwigType *t);
extern SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual);
extern SwigType *SwigType_del_qualifier(SwigType *t);
extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms);
@ -147,6 +154,7 @@ extern "C" {
extern int SwigType_ismemberpointer(const SwigType *t);
extern int SwigType_isreference(const SwigType *t);
extern int SwigType_isreference_return(const SwigType *t);
extern int SwigType_isrvalue_reference(const SwigType *t);
extern int SwigType_isarray(const SwigType *t);
extern int SwigType_prefix_is_simple_1D_array(const SwigType *t);
extern int SwigType_isfunction(const SwigType *t);
@ -227,6 +235,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 *));
@ -277,6 +286,8 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl);
extern void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *namewrn, ParmList *declaratorparms);
extern void Swig_name_inherit(String *base, String *derived);
extern List *Swig_make_inherit_list(String *clsname, List *names, String *Namespaceprefix);
extern void Swig_inherit_base_symbols(List *bases);
extern int Swig_need_protected(Node *n);
extern int Swig_need_name_warning(Node *n);
extern int Swig_need_redefined_warn(Node *a, Node *b, int InClass);
@ -293,7 +304,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern DOH *Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *decl);
extern void Swig_name_object_inherit(Hash *namehash, String *base, String *derived);
extern void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, Node *n);
extern void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, String *value, Hash *featureattribs);
extern void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, const_String_or_char_ptr value, Hash *featureattribs);
/* --- Misc --- */
extern char *Swig_copy_string(const char *c);
@ -306,6 +317,10 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Swig_filename_correct(String *filename);
extern String *Swig_filename_escape(String *filename);
extern void Swig_filename_unescape(String *filename);
extern int Swig_storage_isextern(Node *n);
extern int Swig_storage_isexternc(Node *n);
extern int Swig_storage_isstatic_custom(Node *n, const_String_or_char_ptr storage);
extern int Swig_storage_isstatic(Node *n);
extern String *Swig_string_escape(String *s);
extern String *Swig_string_mangle(const String *s);
extern void Swig_scopename_split(const String *s, String **prefix, String **last);
@ -317,6 +332,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern String *Swig_string_lower(String *s);
extern String *Swig_string_upper(String *s);
extern String *Swig_string_title(String *s);
extern void Swig_offset_string(String *s, int number);
extern String *Swig_pcre_version(void);
extern void Swig_init(void);
extern void Swig_warn(const char *filename, int line, const char *msg);
@ -356,11 +372,12 @@ 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 --- */
extern int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int flags, SwigType *director_type, int is_director);
extern int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags);
extern int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags, String *directorname);
extern int Swig_DestructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int cplus, int flags);
extern int Swig_MembersetToFunction(Node *n, String *classname, int flags);
extern int Swig_MembergetToFunction(Node *n, String *classname, int flags);

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

@ -22,6 +22,7 @@ extern int Scanner_token(Scanner *);
extern String *Scanner_text(Scanner *);
extern void Scanner_skip_line(Scanner *);
extern int Scanner_skip_balanced(Scanner *, int startchar, int endchar);
extern String *Scanner_get_raw_text_balanced(Scanner *, int startchar, int endchar);
extern void Scanner_set_location(Scanner *, String *file, int line);
extern String *Scanner_file(Scanner *);
extern int Scanner_line(Scanner *);
@ -67,6 +68,9 @@ extern void Scanner_locator(Scanner *, String *loc);
#define SWIG_TOKEN_QUESTION 30 /* ? */
#define SWIG_TOKEN_COMMENT 31 /* C or C++ comment */
#define SWIG_TOKEN_BOOL 32 /* true or false */
#define SWIG_TOKEN_WSTRING 33 /* L"str" */
#define SWIG_TOKEN_WCHAR 34 /* L'c' */
#define SWIG_TOKEN_ILLEGAL 99
#define SWIG_TOKEN_ERROR -1

View file

@ -38,6 +38,7 @@ extern void appendChild(Node *node, Node *child);
extern void prependChild(Node *node, Node *child);
extern void removeNode(Node *node);
extern Node *copyNode(Node *node);
extern void appendSibling(Node *node, Node *child);
/* Node restoration/restore functions */

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);
@ -173,6 +171,24 @@ void prependChild(Node *node, Node *chd) {
}
}
void appendSibling(Node *node, Node *chd) {
Node *parent;
Node *lc = node;
while (nextSibling(lc))
lc = nextSibling(lc);
set_nextSibling(lc, chd);
set_previousSibling(chd, lc);
parent = parentNode(node);
if (parent) {
while (chd) {
lc = chd;
set_parentNode(chd, parent);
chd = nextSibling(chd);
}
set_lastChild(parent, lc);
}
}
/* -----------------------------------------------------------------------------
* removeNode()
*

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) {
@ -1035,13 +1039,13 @@ static int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, Swi
$*n_ltype
*/
if (SwigType_ispointer(ftype) || (SwigType_isarray(ftype)) || (SwigType_isreference(ftype))) {
if (!(SwigType_isarray(type) || SwigType_ispointer(type) || SwigType_isreference(type))) {
if (SwigType_ispointer(ftype) || (SwigType_isarray(ftype)) || (SwigType_isreference(ftype)) || (SwigType_isrvalue_reference(ftype))) {
if (!(SwigType_isarray(type) || SwigType_ispointer(type) || SwigType_isreference(type) || SwigType_isrvalue_reference(type))) {
star_type = Copy(ftype);
} else {
star_type = Copy(type);
}
if (!SwigType_isreference(star_type)) {
if (!(SwigType_isreference(star_type) || SwigType_isrvalue_reference(star_type))) {
if (SwigType_isarray(star_type)) {
SwigType_del_element(star_type);
} else {
@ -1196,7 +1200,7 @@ static int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, Swi
* creates the local variables.
* ------------------------------------------------------------------------ */
static void typemap_locals(DOHString * s, ParmList *l, Wrapper *f, int argnum) {
static void typemap_locals(String *s, ParmList *l, Wrapper *f, int argnum) {
Parm *p;
char *new_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
@ -45,6 +44,7 @@ char cvsroot_typeobj_c[] = "$Id$";
*
* 'p.' = Pointer (*)
* 'r.' = Reference (&)
* 'z.' = Rvalue reference (&&)
* 'a(n).' = Array of size n [n]
* 'f(..,..).' = Function with arguments (args)
* 'q(str).' = Qualifier (such as const or volatile) (const, volatile)
@ -78,6 +78,7 @@ char cvsroot_typeobj_c[] = "$Id$";
*
* SwigType_add_pointer()
* SwigType_add_reference()
* SwigType_add_rvalue_reference()
* SwigType_add_array()
*
* These are used to build new types. There are also functions to undo these
@ -85,12 +86,14 @@ char cvsroot_typeobj_c[] = "$Id$";
*
* SwigType_del_pointer()
* SwigType_del_reference()
* SwigType_del_rvalue_reference()
* SwigType_del_array()
*
* In addition, there are query functions
*
* SwigType_ispointer()
* SwigType_isreference()
* SwigType_isrvalue_reference()
* SwigType_isarray()
*
* Finally, there are some data extraction functions that can be used to
@ -237,7 +240,7 @@ String *SwigType_parm(const SwigType *t) {
/* -----------------------------------------------------------------------------
* SwigType_split()
*
* Splits a type into it's component parts and returns a list of string.
* Splits a type into its component parts and returns a list of string.
* ----------------------------------------------------------------------------- */
List *SwigType_split(const SwigType *t) {
@ -415,6 +418,41 @@ int SwigType_isreference(const SwigType *t) {
return 0;
}
/* -----------------------------------------------------------------------------
* Rvalue References
*
* SwigType_add_rvalue_reference()
* SwigType_del_rvalue_reference()
* SwigType_isrvalue_reference()
*
* Add, remove, and test if a type is a rvalue reference. The deletion and query
* functions take into account qualifiers (if any).
* ----------------------------------------------------------------------------- */
SwigType *SwigType_add_rvalue_reference(SwigType *t) {
Insert(t, 0, "z.");
return t;
}
SwigType *SwigType_del_rvalue_reference(SwigType *t) {
char *c = Char(t);
int check = strncmp(c, "z.", 2);
assert(check == 0);
Delslice(t, 0, 2);
return t;
}
int SwigType_isrvalue_reference(const SwigType *t) {
char *c;
if (!t)
return 0;
c = Char(t);
if (strncmp(c, "z.", 2) == 0) {
return 1;
}
return 0;
}
/* -----------------------------------------------------------------------------
* Qualifiers
*
@ -427,62 +465,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 +628,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 +665,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 +692,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 +705,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 +737,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 +785,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 +882,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);
}
}
}
@ -604,7 +602,7 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
Typetab *s;
Hash *ttab;
String *namebase = 0;
String *nameprefix = 0;
String *nameprefix = 0, *rnameprefix = 0;
int newtype = 0;
resolved_scope = 0;
@ -649,51 +647,66 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
Printf(stdout, "nameprefix = '%s'\n", nameprefix);
#endif
if (nameprefix) {
/* Name had a prefix on it. See if we can locate the proper scope for it */
String *rnameprefix = template_parameters_resolve(nameprefix);
nameprefix = rnameprefix ? Copy(rnameprefix) : nameprefix;
Delete(rnameprefix);
s = SwigType_find_scope(s, nameprefix);
/* Couldn't locate a scope for the type. */
if (!s) {
Delete(base);
Delete(namebase);
Delete(nameprefix);
r = 0;
goto return_result;
}
/* Try to locate the name starting in the scope */
rnameprefix = SwigType_typedef_resolve(nameprefix);
if(rnameprefix != NULL) {
#ifdef SWIG_DEBUG
Printf(stdout, "namebase = '%s'\n", namebase);
Printf(stdout, "nameprefix '%s' is a typedef to '%s'\n", nameprefix, rnameprefix);
#endif
type = typedef_resolve(s, namebase);
if (type) {
/* we need to look for the resolved type, this will also
fix the resolved_scope if 'type' and 'namebase' are
declared in different scopes */
String *rtype = 0;
rtype = typedef_resolve(resolved_scope, type);
if (rtype)
type = rtype;
}
#ifdef SWIG_DEBUG
Printf(stdout, "%s type = '%s'\n", Getattr(s, "name"), type);
#endif
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 */
if ((qname) && typedef_resolve(resolved_scope, type)) {
type = Copy(type);
Insert(type, 0, "::");
Insert(type, 0, qname);
#ifdef SWIG_DEBUG
Printf(stdout, "qual %s \n", type);
#endif
newtype = 1;
type = Copy(namebase);
Insert(type, 0, "::");
Insert(type, 0, rnameprefix);
if (strncmp(Char(type), "::", 2) == 0) {
Delitem(type, 0);
Delitem(type, 0);
}
newtype = 1;
} else {
/* Name had a prefix on it. See if we can locate the proper scope for it */
String *rnameprefix = template_parameters_resolve(nameprefix);
nameprefix = rnameprefix ? Copy(rnameprefix) : nameprefix;
Delete(rnameprefix);
s = SwigType_find_scope(s, nameprefix);
/* Couldn't locate a scope for the type. */
if (!s) {
Delete(base);
Delete(namebase);
Delete(nameprefix);
r = 0;
goto return_result;
}
/* Try to locate the name starting in the scope */
#ifdef SWIG_DEBUG
Printf(stdout, "namebase = '%s'\n", namebase);
#endif
type = typedef_resolve(s, namebase);
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 */
String *rtype = 0;
rtype = typedef_resolve(resolved_scope, type);
if (rtype)
type = rtype;
}
#ifdef SWIG_DEBUG
Printf(stdout, "%s type = '%s'\n", Getattr(s, "name"), type);
#endif
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 */
if ((qname) && typedef_resolve(resolved_scope, type)) {
type = Copy(type);
Insert(type, 0, "::");
Insert(type, 0, qname);
#ifdef SWIG_DEBUG
Printf(stdout, "qual %s \n", type);
#endif
newtype = 1;
}
resolved_scope = rtab;
}
resolved_scope = rtab;
}
} else {
/* Name is unqualified. */
@ -794,6 +807,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 +972,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 +1029,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 +1099,9 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) {
Delete(tprefix);
Delete(qprefix);
Delete(parms);
/*
Delete(dt);
*/
}
Append(result, e);
Delete(ty);
@ -1114,14 +1195,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) {
@ -1216,6 +1297,8 @@ int SwigType_type(const SwigType *t) {
if (strncmp(c, "p.", 2) == 0) {
if (SwigType_type(c + 2) == T_CHAR)
return T_STRING;
else if (SwigType_type(c + 2) == T_WCHAR)
return T_WSTRING;
else
return T_POINTER;
}
@ -1223,6 +1306,8 @@ int SwigType_type(const SwigType *t) {
return T_ARRAY;
if (strncmp(c, "r.", 2) == 0)
return T_REFERENCE;
if (strncmp(c, "z.", 2) == 0)
return T_RVALUE_REFERENCE;
if (strncmp(c, "m(", 2) == 0)
return T_MPOINTER;
if (strncmp(c, "q(", 2) == 0) {
@ -1256,6 +1341,8 @@ int SwigType_type(const SwigType *t) {
return T_SCHAR;
if (strcmp(c, "unsigned char") == 0)
return T_UCHAR;
if (strcmp(c, "wchar_t") == 0)
return T_WCHAR;
if (strcmp(c, "float") == 0)
return T_FLOAT;
if (strcmp(c, "double") == 0)
@ -1278,6 +1365,8 @@ int SwigType_type(const SwigType *t) {
return T_ULONGLONG;
if (strncmp(c, "enum ", 5) == 0)
return T_INT;
if (strcmp(c, "auto") == 0)
return T_AUTO;
if (strcmp(c, "v(...)") == 0)
return T_VARARGS;
@ -1307,13 +1396,13 @@ int SwigType_type(const SwigType *t) {
*
* 2.- swig doesn't mark 'type' as non-assignable.
*
* 3.- the user specify that the value wrapper is not needed by using
* the %feature("novaluewrapper"), in that case the user need to type
* 3.- the user specifies that the value wrapper is not needed by using
* %feature("novaluewrapper") like so:
*
* %feature("novaluewrapper") MyOpaqueClass;
* class MyOpaqueClass;
*
* Users can also force the use of the value wrapper by using the
* The user can also force the use of the value wrapper with
* %feature("valuewrapper").
* ----------------------------------------------------------------------------- */
@ -1555,6 +1644,11 @@ void SwigType_remember_clientdata(const SwigType *t, const_String_or_char_ptr cl
SwigType_del_reference(tt);
SwigType_add_pointer(tt);
SwigType_remember_clientdata(tt, clientdata);
} else if (SwigType_isrvalue_reference(t)) {
SwigType *tt = Copy(t);
SwigType_del_rvalue_reference(tt);
SwigType_add_pointer(tt);
SwigType_remember_clientdata(tt, clientdata);
}
}
@ -1803,13 +1897,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>