Eliminated old typemap/except code. Variety of minor bug fixes throughout.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@655 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
5100af97e4
commit
503746e964
13 changed files with 585 additions and 2286 deletions
|
|
@ -522,7 +522,7 @@ void TCL8::create_function(char *name, char *iname, SwigType *d, ParmList *l)
|
|||
if (j == (pcount-numopt))
|
||||
Putc('|',argstr);
|
||||
|
||||
if ((tm = typemap_lookup((char*)"in",(char*)"tcl8",pt,pn,source,target,f))) {
|
||||
if ((tm = Swig_typemap_lookup((char*)"in",pt,pn,source,target,f))) {
|
||||
Putc('o',argstr);
|
||||
Printf(args,",0");
|
||||
|
||||
|
|
@ -621,7 +621,7 @@ void TCL8::create_function(char *name, char *iname, SwigType *d, ParmList *l)
|
|||
}
|
||||
|
||||
// Check to see if there was any sort of a constaint typemap
|
||||
if ((tm = typemap_lookup((char*)"check",(char*)"tcl8",pt,pn,source,target,0))) {
|
||||
if ((tm = Swig_typemap_lookup((char*)"check",pt,pn,source,target,0))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(incode,"%s\n", tm);
|
||||
Replace(incode,"$argnum",argnum, DOH_REPLACE_ANY);
|
||||
|
|
@ -629,14 +629,14 @@ void TCL8::create_function(char *name, char *iname, SwigType *d, ParmList *l)
|
|||
}
|
||||
|
||||
// Check if there was any cleanup code (save it for later)
|
||||
if ((tm = typemap_lookup((char*)"freearg",(char*)"tcl8",pt,pn,target,(char*)"tcl_result",0))) {
|
||||
if ((tm = Swig_typemap_lookup((char*)"freearg",pt,pn,target,(char*)"tcl_result",0))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(cleanup,"%s\n", tm);
|
||||
Replace(cleanup,"$argnum",argnum, DOH_REPLACE_ANY);
|
||||
Replace(cleanup,"$arg",source,DOH_REPLACE_ANY);
|
||||
}
|
||||
// Look for output arguments
|
||||
if ((tm = typemap_lookup((char*)"argout",(char*)"tcl8",pt,pn,target,(char*)"tcl_result",0))) {
|
||||
if ((tm = Swig_typemap_lookup((char*)"argout",pt,pn,target,(char*)"tcl_result",0))) {
|
||||
Printf(outarg,"%s\n", tm);
|
||||
Replace(outarg,"$argnum",argnum, DOH_REPLACE_ANY);
|
||||
Replace(outarg,"$arg",source, DOH_REPLACE_ANY);
|
||||
|
|
@ -657,7 +657,7 @@ void TCL8::create_function(char *name, char *iname, SwigType *d, ParmList *l)
|
|||
|
||||
// Return value if necessary
|
||||
|
||||
if ((tm = typemap_lookup((char*)"out",(char*)"tcl8",d,name,(char*)"result",(char*)"tcl_result",0))) {
|
||||
if ((tm = Swig_typemap_lookup((char*)"out",d,name,(char*)"result",(char*)"tcl_result",0))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(f->code,"%s\n", tm);
|
||||
} else {
|
||||
|
|
@ -729,12 +729,12 @@ void TCL8::create_function(char *name, char *iname, SwigType *d, ParmList *l)
|
|||
// Look for any remaining cleanup
|
||||
|
||||
if (NewObject) {
|
||||
if ((tm = typemap_lookup((char*)"newfree",(char*)"tcl8",d,iname,(char*)"result",(char*)"",0))) {
|
||||
if ((tm = Swig_typemap_lookup((char*)"newfree",d,iname,(char*)"result",(char*)"",0))) {
|
||||
Printf(f->code,"%s\n", tm);
|
||||
}
|
||||
}
|
||||
|
||||
if ((tm = typemap_lookup((char*)"ret",(char*)"tcl8",d,name,(char*)"result",(char*)"",0))) {
|
||||
if ((tm = Swig_typemap_lookup((char*)"ret",d,name,(char*)"result",(char*)"",0))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(f->code,"%s\n", tm);
|
||||
}
|
||||
|
|
@ -772,8 +772,8 @@ void TCL8::link_variable(char *name, char *iname, SwigType *t)
|
|||
|
||||
// See if there were any typemaps
|
||||
|
||||
tm = typemap_lookup((char*)"varin",(char*)"tcl8",t,name,(char*)"",(char*)"",0);
|
||||
tm1 = typemap_lookup((char*)"varout",(char*)"tcl8",t,name,(char*)"",(char*)"",0);
|
||||
tm = Swig_typemap_lookup((char*)"varin",t,name,(char*)"",(char*)"",0);
|
||||
tm1 = Swig_typemap_lookup((char*)"varout",t,name,(char*)"",(char*)"",0);
|
||||
if (tm || tm1) {
|
||||
Printf(stderr,"%s : Line %d. Warning. varin/varout typemap methods not supported.",
|
||||
input_file, line_number);
|
||||
|
|
@ -978,7 +978,7 @@ void TCL8::declare_const(char *name, char *, SwigType *type, char *value) {
|
|||
} else {
|
||||
rvalue = NewString(value);
|
||||
}
|
||||
if ((tm = typemap_lookup((char*)"const",(char*)"tcl8",type,name,Char(rvalue),name,0))) {
|
||||
if ((tm = Swig_typemap_lookup((char*)"const",type,name,Char(rvalue),name,0))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(f_init,"%s\n",tm);
|
||||
} else {
|
||||
|
|
@ -1116,7 +1116,7 @@ char * TCL8::usage_string(char *iname, SwigType *, ParmList *l) {
|
|||
|
||||
// Only print an argument if not ignored
|
||||
|
||||
if (!typemap_check((char*)"ignore",(char*)"tcl8",pt,pn)) {
|
||||
if (!Swig_typemap_search((char*)"ignore",pt,pn)) {
|
||||
if (i >= (pcount-numopt))
|
||||
Putc('?',temp);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,11 +15,10 @@ RANLIB = @RANLIB@
|
|||
TARGET = libswig11.a
|
||||
|
||||
OBJS = parser.o main.o scanner.o \
|
||||
emit.o cplus.o lang.o typemap.o
|
||||
emit.o cplus.o lang.o
|
||||
|
||||
SRCS = main.cxx scanner.cxx \
|
||||
emit.cxx cplus.cxx lang.cxx \
|
||||
typemap.cxx
|
||||
emit.cxx cplus.cxx lang.cxx
|
||||
|
||||
PARSER = $(srcdir)/parser.yxx
|
||||
INCLUDE = -I$(srcdir)/../Include \
|
||||
|
|
|
|||
|
|
@ -50,16 +50,16 @@ int emit_args(SwigType *rt, ParmList *l, Wrapper *f) {
|
|||
pname = Getname(p);
|
||||
pvalue = Getvalue(p);
|
||||
|
||||
tm = typemap_lookup((char*)"arginit", typemap_lang, pt,pname,(char*)"",lname,f);
|
||||
tm = Swig_typemap_lookup((char*)"arginit",pt,pname,(char*)"",lname,f);
|
||||
if (tm) {
|
||||
Printv(f->code,tm,"\n",0);
|
||||
}
|
||||
/* Check for ignore or default typemaps */
|
||||
tm = typemap_lookup((char*)"default",typemap_lang,pt,pname,(char*)"",lname,f);
|
||||
tm = Swig_typemap_lookup((char*)"default",pt,pname,(char*)"",lname,f);
|
||||
if (tm) {
|
||||
Printv(f->code,tm,"\n",0);
|
||||
}
|
||||
tm = typemap_lookup((char*)"ignore",typemap_lang,pt,pname,(char*)"",lname,f);
|
||||
tm = Swig_typemap_lookup((char*)"ignore",pt,pname,(char*)"",lname,f);
|
||||
if (tm) {
|
||||
Printv(f->code,tm,"\n",0);
|
||||
Setignore(p,1);
|
||||
|
|
@ -92,10 +92,10 @@ void emit_set_action(DOHString_or_char *decl) {
|
|||
void emit_func_call(char *decl, SwigType *t, ParmList *l, Wrapper *f) {
|
||||
char *tm;
|
||||
|
||||
if ((tm = typemap_lookup((char*)"except",typemap_lang,t,decl,(char*)"result",(char*)"",0))) {
|
||||
if ((tm = Swig_typemap_lookup((char*)"except",t,decl,(char*)"result",(char*)"",0))) {
|
||||
Printv(f->code,tm,0);
|
||||
Replace(f->code,"$name",decl,DOH_REPLACE_ANY);
|
||||
} else if ((tm = fragment_lookup((char*)"except",typemap_lang))) {
|
||||
} else if ((tm = Swig_except_lookup())) {
|
||||
Printv(f->code,tm,0);
|
||||
Replace(f->code,"$name",decl,DOH_REPLACE_ANY);
|
||||
} else {
|
||||
|
|
@ -183,6 +183,36 @@ void emit_set_get(char *name, char *iname, SwigType *t) {
|
|||
DelWrapper(w);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* int check_numopt()
|
||||
*
|
||||
* Gets the number of optional arguments for a ParmList.
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
int check_numopt(ParmList *p) {
|
||||
int n = 0;
|
||||
int i = 0;
|
||||
int state = 0;
|
||||
|
||||
for (;p; p = Getnext(p),i++) {
|
||||
SwigType *pt = Gettype(p);
|
||||
String *pn = Getname(p);
|
||||
if (Getvalue(p)) {
|
||||
n++;
|
||||
state = 1;
|
||||
} else if (Swig_typemap_search((char*)"default",pt,pn)) {
|
||||
n++;
|
||||
state = 1;
|
||||
} else if (Swig_typemap_search((char*)"ignore",pt,pn)) {
|
||||
n++;
|
||||
} else {
|
||||
if (state) {
|
||||
Printf(stderr,"%s : Line %d. Argument %d must have a default value!\n", input_file,line_number,i+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ extern "C" {
|
|||
int GenerateDefault = 0; // Generate default constructors
|
||||
char *Config = 0;
|
||||
int NoInclude = 0;
|
||||
char *typemap_lang = 0; // Typemap name
|
||||
|
||||
int error_count = 0; // Error count
|
||||
int Verbose = 0;
|
||||
|
||||
|
|
@ -135,13 +135,12 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
|||
int help = 0;
|
||||
int checkout = 0;
|
||||
int cpp_only = 0;
|
||||
|
||||
int tm_debug = 0;
|
||||
char *includefiles[256];
|
||||
int includecount = 0;
|
||||
extern int check_suffix(char *);
|
||||
extern void scanner_file(DOHFile *);
|
||||
extern void parser_init(void);
|
||||
extern void typemap_initialize();
|
||||
DOH *libfiles = 0;
|
||||
|
||||
{
|
||||
|
|
@ -154,7 +153,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
|||
|
||||
// Initialize the preprocessor
|
||||
Preprocessor_init();
|
||||
typemap_initialize();
|
||||
Swig_typemap_init();
|
||||
|
||||
f_wrappers = 0;
|
||||
f_init = 0;
|
||||
f_header = 0;
|
||||
|
|
@ -259,6 +259,9 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
|||
} else if (strcmp(argv[i],"-includeall") == 0) {
|
||||
Preprocessor_include_all(1);
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-tm_debug") == 0) {
|
||||
tm_debug = 1;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-help") == 0) {
|
||||
fputs(usage,stderr);
|
||||
Swig_mark_arg(i);
|
||||
|
|
@ -414,18 +417,12 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
|||
f_init = NewString("");
|
||||
|
||||
// Set up the typemap for handling new return strings
|
||||
#ifdef OLD
|
||||
{
|
||||
DataType *temp_t = NewDataType(T_CHAR);
|
||||
DataType_add_pointer(temp_t);
|
||||
if (CPlusPlus)
|
||||
typemap_register((char*)"newfree",typemap_lang,temp_t,(char*)"",(char*)"delete [] $source;\n",0);
|
||||
Swig_typemap_register((char*)"newfree",(char*)"p.char",(char*)"",(char*)"delete [] $source;\n",0);
|
||||
else
|
||||
typemap_register((char*)"newfree",typemap_lang,temp_t,(char*)"",(char*)"free($source);\n",0);
|
||||
|
||||
DelDataType(temp_t);
|
||||
Swig_typemap_register((char*)"newfree",(char*)"p.char",(char*)"",(char*)"free($source);\n",0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// If in Objective-C mode. Load in a configuration file
|
||||
|
||||
|
|
@ -461,6 +458,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
|||
remove(input_file);
|
||||
}
|
||||
}
|
||||
if (tm_debug) Swig_typemap_debug();
|
||||
while (freeze);
|
||||
return error_count;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ extern void scanner_ignore_typedef(void);
|
|||
extern void scanner_clear_start(void);
|
||||
extern void start_inline(char *, int);
|
||||
extern void swig_pragma(char *, char *);
|
||||
char *typemap_lang = 0;
|
||||
|
||||
#include "internal.h"
|
||||
extern "C" {
|
||||
|
|
@ -1048,7 +1049,8 @@ statement : INCLUDE STRING LBRACE {
|
|||
skip_brace();
|
||||
p = $7;
|
||||
while (p) {
|
||||
typemap_register($5,$3,Gettype(p->p),Getname(p->p),Char(CCode),p->args);
|
||||
if (strcmp($3,typemap_lang) == 0)
|
||||
Swig_typemap_register($5,Gettype(p->p),Getname(p->p), CCode, p->args);
|
||||
p = p->next;
|
||||
}
|
||||
free($3);
|
||||
|
|
@ -1066,7 +1068,7 @@ statement : INCLUDE STRING LBRACE {
|
|||
skip_brace();
|
||||
p = $5;
|
||||
while (p) {
|
||||
typemap_register($3,typemap_lang,Gettype(p->p),Getname(p->p),Char(CCode),p->args);
|
||||
Swig_typemap_register($3,Gettype(p->p),Getname(p->p), CCode, p->args);
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
|
@ -1079,7 +1081,9 @@ statement : INCLUDE STRING LBRACE {
|
|||
TMParm *p;
|
||||
p = $7;
|
||||
while (p) {
|
||||
typemap_clear($5,$3,Gettype(p->p),Getname(p->p));
|
||||
if (strcmp($3,typemap_lang) == 0) {
|
||||
Swig_typemap_clear($5,Gettype(p->p),Getname(p->p));
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
free($3);
|
||||
|
|
@ -1096,7 +1100,7 @@ statement : INCLUDE STRING LBRACE {
|
|||
TMParm *p;
|
||||
p = $5;
|
||||
while (p) {
|
||||
typemap_clear($3,typemap_lang,Gettype(p->p),Getname(p->p));
|
||||
Swig_typemap_clear($3,Gettype(p->p),Getname(p->p));
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
|
@ -1109,7 +1113,9 @@ statement : INCLUDE STRING LBRACE {
|
|||
TMParm *p;
|
||||
p = $7;
|
||||
while (p) {
|
||||
typemap_copy($5,$3,Gettype($9->p),Getname($9->p),Gettype(p->p),Getname(p->p));
|
||||
if (strcmp($3,typemap_lang) == 0) {
|
||||
Swig_typemap_copy($5,Gettype($9->p),Getname($9->p),Gettype(p->p),Getname(p->p));
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
free($3);
|
||||
|
|
@ -1129,7 +1135,7 @@ statement : INCLUDE STRING LBRACE {
|
|||
TMParm *p;
|
||||
p = $5;
|
||||
while (p) {
|
||||
typemap_copy($3,typemap_lang,Gettype($7->p),Getname($7->p),Gettype(p->p),Getname(p->p));
|
||||
Swig_typemap_copy($3,Gettype($7->p),Getname($7->p),Gettype(p->p),Getname(p->p));
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
|
@ -1145,7 +1151,7 @@ statement : INCLUDE STRING LBRACE {
|
|||
TMParm *p;
|
||||
p = $4;
|
||||
while(p) {
|
||||
typemap_apply(Gettype($2->p),Getname($2->p),Gettype(p->p),Getname(p->p));
|
||||
Swig_typemap_apply(Gettype($2->p),Getname($2->p),Gettype(p->p),Getname(p->p));
|
||||
p = p->next;
|
||||
}
|
||||
free($4);
|
||||
|
|
@ -1156,7 +1162,7 @@ statement : INCLUDE STRING LBRACE {
|
|||
TMParm *p;
|
||||
p = $2;
|
||||
while (p) {
|
||||
typemap_clear_apply(Gettype(p->p), Getname(p->p));
|
||||
Swig_typemap_clear_apply(Gettype(p->p), Getname(p->p));
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
|
@ -1171,25 +1177,27 @@ statement : INCLUDE STRING LBRACE {
|
|||
/* An exception definition */
|
||||
| EXCEPT LPAREN ID RPAREN LBRACE {
|
||||
skip_brace();
|
||||
fragment_register((char *)"except",$3, Char(CCode));
|
||||
if (strcmp($3,typemap_lang) == 0) {
|
||||
Swig_except_register(CCode);
|
||||
}
|
||||
free($3);
|
||||
}
|
||||
|
||||
/* A Generic Exception (no language specified */
|
||||
| EXCEPT LBRACE {
|
||||
skip_brace();
|
||||
fragment_register((char *) "except",typemap_lang, Char(CCode));
|
||||
Swig_except_register(CCode);
|
||||
}
|
||||
|
||||
/* Clear an exception */
|
||||
|
||||
| EXCEPT LPAREN ID RPAREN SEMI {
|
||||
fragment_clear((char *) "except",$3);
|
||||
Swig_except_clear();
|
||||
}
|
||||
|
||||
/* Generic clear */
|
||||
| EXCEPT SEMI {
|
||||
fragment_clear((char *) "except",typemap_lang);
|
||||
Swig_except_clear();
|
||||
}
|
||||
|
||||
/* Miscellaenous stuff */
|
||||
|
|
|
|||
|
|
@ -267,46 +267,5 @@ extern "C" {
|
|||
extern int emit_args(SwigType *, ParmList *, Wrapper *f);
|
||||
extern void emit_func_call(char *, SwigType *, ParmList *, Wrapper *f);
|
||||
extern void SWIG_exit(int);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Typemap support
|
||||
// -----------------------------------------------------------------------
|
||||
#ifndef OLD
|
||||
extern void typemap_register(char *op, char *lang, SwigType *type, String_or_char *pname, String_or_char *code, ParmList *l = 0);
|
||||
extern char *typemap_lookup(char *op, char *lang, SwigType *type, String_or_char *pname, String_or_char *source, String_or_char *target, Wrapper *f = 0);
|
||||
extern void typemap_clear(char *op, char *lang, SwigType *type, String_or_char *pname);
|
||||
extern void typemap_copy(char *op, char *lang, SwigType *stype, String_or_char *sname,
|
||||
SwigType *ttype, String_or_char *tname);
|
||||
extern char *typemap_check(char *op, char *lang, SwigType *type, String_or_char *pname);
|
||||
extern void typemap_apply(SwigType *tm_type, String_or_char *tmname, SwigType *type, String_or_char *pname);
|
||||
extern void typemap_clear_apply(SwigType *type, String_or_char *pname);
|
||||
extern int check_numopt(ParmList *);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Code fragment support
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
extern void fragment_register(char *op, char *lang, String_or_char *code);
|
||||
extern char *fragment_lookup(char *op, char *lang);
|
||||
extern void fragment_clear(char *op, char *lang);
|
||||
|
||||
#else
|
||||
|
||||
#define typemap_register(op,lang,type,pname,code,l)
|
||||
#define typemap_register_default(op,lang,type,ptr,arraystr,code,l)
|
||||
#define typemap_lookup(op,lang,type,pname,source,target,f) 0
|
||||
|
||||
#define typemap_clear(op,lang,type,pname)
|
||||
#define typemap_copy(op,lang,stype,sname,ttype,tname)
|
||||
#define typemap_check(op,lang,type,pname) 0
|
||||
#define typemap_apply(tm,tmname,type,pname)
|
||||
#define typemap_clear_apply(type,pname)
|
||||
#define check_numopt(l) ParmList_len(l)
|
||||
#define fragment_register(op,lang,code)
|
||||
#define fragment_lookup(op,lang,age) 0
|
||||
#define fragment_clear(op,lang)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,969 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* typemap.cxx
|
||||
*
|
||||
* Typemap support.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1998-2000. The University of Chicago
|
||||
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
|
||||
* University of California.
|
||||
*
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "internal.h"
|
||||
#include <limits.h>
|
||||
|
||||
extern "C" {
|
||||
#include "doh.h"
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* This file provides universal support for typemaps. Typemaps are created
|
||||
* using the following SWIG command in an interface file:
|
||||
*
|
||||
* %typemap(lang,operation) type { code } Make a new typemap
|
||||
* %typemap(lang,operation) type; Clears any previous typemap
|
||||
*
|
||||
* lang is an identifier indicating the target language. The typemap will
|
||||
* simply be ignored if its for a different language. The code is the
|
||||
* corresponding C code for the mapping. An example typemap might look
|
||||
* like this :
|
||||
*
|
||||
* %typemap(tcl,get) double {
|
||||
* $target = atof($source);
|
||||
* }
|
||||
* %typemap(tcl,set) double {
|
||||
* sprintf($target,"%0.17f",$source);
|
||||
* }
|
||||
*
|
||||
* The variables $target and $source should be used in any type-mappings.
|
||||
* Additional local variables can be created, but this should be done
|
||||
* by enclosing the entire code fragment in an extra set of braces.
|
||||
*
|
||||
* The C++ API to the type-mapper is as follows :
|
||||
*
|
||||
* void typemap_register(char *op, char *lang, DataType *type, char *pname, String &getcode, ParmList *args)
|
||||
* char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *source, char *target);
|
||||
* void typemap_clear(char *op, char *lang, DataType *type, char *pname);
|
||||
*
|
||||
* The lookup functions return a character string corresponding to the type-mapping
|
||||
* code or NULL if none exists. The string return will have the source and target
|
||||
* strings substituted for the strings "$source" and "$target" in the type-mapping code.
|
||||
*
|
||||
* (2/19/97) This module has been extended somewhat to provide generic mappings
|
||||
* of other parts of the code--most notably exceptions.
|
||||
*
|
||||
* void fragment_register(char *op, char *lang, String &code)
|
||||
* char fragment_lookup(char *op, char *lang, int age);
|
||||
* char fragment_clear(char *op, char *lang);
|
||||
*
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
static ParmList *last_args = 0;
|
||||
char *typemap_lang = 0; // Typemap language name
|
||||
|
||||
int type_id = 0;
|
||||
|
||||
/* Structure for holding a typemap */
|
||||
|
||||
struct TypeMap {
|
||||
char *lang;
|
||||
SwigType *type;
|
||||
DOHString *code;
|
||||
int first;
|
||||
int last;
|
||||
TypeMap *next;
|
||||
TypeMap *previous; /* Previously defined typemap (if any) */
|
||||
ParmList *args; /* Local variables (if any) */
|
||||
|
||||
TypeMap(char *l, SwigType *t, String_or_char *c, ParmList *p = 0) {
|
||||
lang = Swig_copy_string(l);
|
||||
type = Copy(t);
|
||||
code = NewString(c);
|
||||
first = type_id;
|
||||
last = INT_MAX;
|
||||
next = 0;
|
||||
previous = 0;
|
||||
if (p) {
|
||||
args = CopyParmList(p);
|
||||
} else {
|
||||
args = 0;
|
||||
}
|
||||
}
|
||||
TypeMap(char *l, String_or_char *c) {
|
||||
lang = Swig_copy_string(l);
|
||||
type = 0;
|
||||
code = NewString(c);
|
||||
first = type_id;
|
||||
last = INT_MAX;
|
||||
next = 0;
|
||||
previous = 0;
|
||||
args = 0;
|
||||
}
|
||||
TypeMap(TypeMap *t) {
|
||||
lang = Swig_copy_string(t->lang);
|
||||
type = Copy(t->type);
|
||||
code = Copy(t->code);
|
||||
first = type_id;
|
||||
last = INT_MAX;
|
||||
next = 0;
|
||||
previous = t->previous;
|
||||
if (args) {
|
||||
args = CopyParmList(args);
|
||||
} else {
|
||||
args = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* Hash tables for storing type-mappings */
|
||||
|
||||
static DOH *typemap_hash = 0;
|
||||
|
||||
/* Structure for holding "applications of a typemap" */
|
||||
|
||||
struct TmMethod {
|
||||
String *name; /* Typemap name; */
|
||||
SwigType *type; /* Typemap type */
|
||||
TmMethod *next; /* Next method */
|
||||
TmMethod(String *n, SwigType *t, TmMethod *m = 0) {
|
||||
if (n) name = Copy(n);
|
||||
else name = 0;
|
||||
if (t) {
|
||||
type = Copy(t);
|
||||
} else {
|
||||
type = 0;
|
||||
}
|
||||
next = m;
|
||||
}
|
||||
};
|
||||
|
||||
/* Hash table for storing applications of a datatype */
|
||||
|
||||
static DOH *application_hash = 0;
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* void typemap_apply(DataType *tm_type, char *tm_name, DataType *type, char *pname)
|
||||
*
|
||||
* Attempts to apply a typemap given by (tm_type,tm_name) to (type,pname)
|
||||
* Called by the %apply directive.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
void typemap_apply(SwigType *tm_type, String_or_char *tm_name, SwigType *type, String_or_char *pname) {
|
||||
TmMethod *m,*m1;
|
||||
String *temp;
|
||||
|
||||
/* Form the application name */
|
||||
if (!pname) pname = (String_or_char*)"";
|
||||
temp = NewStringf("%s$%s",SwigType_str(type,0),pname);
|
||||
|
||||
/* See if there is a method already defined */
|
||||
|
||||
if (!application_hash) application_hash = NewHash();
|
||||
m = (TmMethod *) GetVoid(application_hash,temp);
|
||||
|
||||
if (!m) {
|
||||
m = new TmMethod(temp,type,0);
|
||||
SetVoid(application_hash,temp,m);
|
||||
}
|
||||
|
||||
Delete(temp);
|
||||
|
||||
/* Check to see if an array typemap has been applied to a non-array type */
|
||||
|
||||
if ((SwigType_isarray(tm_type)) && (!SwigType_isarray(type))) {
|
||||
Printf(stderr,"%s:%d: Warning. Array typemap has been applied to a non-array type.\n",
|
||||
input_file,line_number);
|
||||
}
|
||||
|
||||
/* If both are arrays, make sure they have the same dimension */
|
||||
|
||||
if ((SwigType_isarray(tm_type)) && (SwigType_isarray(type))) {
|
||||
if (SwigType_array_ndim(tm_type) != SwigType_array_ndim(type)) {
|
||||
Printf(stderr,"%s:%d: Warning. Array types have different number of dimensions.\n",
|
||||
input_file,line_number);
|
||||
} else {
|
||||
for (int i = 0; i < SwigType_array_ndim(tm_type); i++) {
|
||||
String *s1 = SwigType_array_getdim(tm_type,i);
|
||||
String *s2 = SwigType_array_getdim(type,i);
|
||||
if (Cmp(s1,"") != 0) {
|
||||
if (Cmp(s1,s2))
|
||||
Printf(stderr,"%s:%d: Warning. Array typemap applied to an array of different size.\n",
|
||||
input_file, line_number);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a new mapping corresponding to the typemap */
|
||||
m1 = new TmMethod(tm_name,tm_type,m->next);
|
||||
m->next = m1;
|
||||
|
||||
}
|
||||
/* ------------------------------------------------------------------------
|
||||
* void typemap_clear_apply(SwigType *type, char *pname)
|
||||
*
|
||||
* Clears the application of a typemap.
|
||||
* Called by the %clear directive.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
void typemap_clear_apply(SwigType *type, String_or_char *pname) {
|
||||
String *temp;
|
||||
if (!pname) pname = (String_or_char*)"";
|
||||
temp = NewStringf("%s$%s", SwigType_str(type,0), pname);
|
||||
if (!application_hash) application_hash = NewHash();
|
||||
Delattr(application_hash,temp);
|
||||
Delete(temp);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* char *typemap_string()
|
||||
*
|
||||
* Produces a character string corresponding to a lang, datatype, and
|
||||
* method. This string is used as the key for our typemap hash table.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
static char *typemap_string(char *op, SwigType *type, String_or_char *pname) {
|
||||
static char str[1024];
|
||||
sprintf(str,"%s-%s-%s",op, Char(type), Char(pname));
|
||||
return str;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* void typemap_register(char *op, char *lang, DataType *type, char *pname,
|
||||
* char *getcode, ParmList *args)
|
||||
*
|
||||
* Register a new mapping with the type-mapper.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
void typemap_register(char *op, char *lang, SwigType *type, String_or_char *pname,
|
||||
String_or_char *getcode, ParmList *args) {
|
||||
|
||||
char *key;
|
||||
TypeMap *tm, *tm_old;
|
||||
int is_default = 0;
|
||||
|
||||
if (!typemap_lang || (strcmp(typemap_lang,lang))) return;
|
||||
if (!typemap_hash) typemap_hash = NewHash();
|
||||
|
||||
tm = new TypeMap(lang,type,getcode,args);
|
||||
/* If this is a default typemap, downgrade the type! */
|
||||
|
||||
if (Cmp(pname,"SWIG_DEFAULT_TYPE") == 0) {
|
||||
tm->type = SwigType_default(tm->type);
|
||||
is_default = 1;
|
||||
}
|
||||
|
||||
key = typemap_string(op,tm->type,pname);
|
||||
|
||||
/* Get any previous setting of the typemap */
|
||||
tm_old = (TypeMap *) GetVoid(typemap_hash, key);
|
||||
if (tm_old) {
|
||||
|
||||
/* Perform a chaining operation, but only if the last typemap is active. */
|
||||
/* If found, we need to attach the old version to the new one */
|
||||
|
||||
tm->previous = tm_old;
|
||||
tm->next = tm_old;
|
||||
tm_old->last = type_id;
|
||||
}
|
||||
|
||||
/* Add new typemap to the hash table */
|
||||
SetVoid(typemap_hash,key,tm);
|
||||
|
||||
/* Just a sanity check to make sure args look okay. */
|
||||
|
||||
if (args) {
|
||||
Parm *p = tm->args;
|
||||
while (p) {
|
||||
String *pn = Getname(p);
|
||||
if (pn) {
|
||||
/* printf(" %s %s\n", pt,pn); */
|
||||
} else {
|
||||
Printf(stderr,"%s:%d: Typemap error. Local variables must have a name\n",
|
||||
input_file, line_number);
|
||||
}
|
||||
p = Getnext(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* static TypeMap *typemap_search(char *key, int id)
|
||||
*
|
||||
* An internal function for searching for a particular typemap given
|
||||
* a key value and datatype id.
|
||||
*
|
||||
* Basically this checks the hash table and then checks the id against
|
||||
* first and last values, looking for a match. This is to properly
|
||||
* handle scoping problems.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
static TypeMap *
|
||||
typemap_search(String_or_char *key, int id) {
|
||||
TypeMap *tm;
|
||||
if (!typemap_hash) typemap_hash = NewHash();
|
||||
tm = (TypeMap *) GetVoid(typemap_hash,key);
|
||||
while (tm) {
|
||||
if ((id >= tm->first) && (id < tm->last)) return tm;
|
||||
else tm = tm->next;
|
||||
}
|
||||
return tm;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname, DOHString *str)
|
||||
*
|
||||
* Performs a typemap lookup on an array type. This is abit complicated
|
||||
* because we need to look for ANY tags specifying that any array dimension
|
||||
* is valid. The resulting code will be placed in str with dimension variables
|
||||
* substituted.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
static
|
||||
TypeMap *typemap_search_array(char *op, char *lang, SwigType *type, String_or_char *pname, DOHString *str) {
|
||||
SwigType *atype;
|
||||
char *key;
|
||||
int ndim,i,j,k,n;
|
||||
TypeMap *tm;
|
||||
char temp[10];
|
||||
|
||||
if (!SwigType_isarray(type)) return 0;
|
||||
|
||||
/* First check to see if exactly this array has been mapped */
|
||||
|
||||
key = typemap_string(op,type,pname);
|
||||
tm = typemap_search(key,type_id);
|
||||
|
||||
/* Check for unnamed array of specific dimensions */
|
||||
if (!tm) {
|
||||
key = typemap_string(op,type,(char*)"");
|
||||
tm = typemap_search(key,type_id);
|
||||
}
|
||||
|
||||
if (!tm) {
|
||||
/* We're going to go search for matches with the ANY tag */
|
||||
ndim = SwigType_array_ndim(type); /* Get number of dimensions */
|
||||
j = (1 << ndim) - 1; /* Status bits */
|
||||
for (i = 0; i < (1 << ndim); i++) {
|
||||
/* Form an array string */
|
||||
atype = Copy(type);
|
||||
k = j;
|
||||
for (n = 0; n < ndim; n++) {
|
||||
if (!(k & 1)) {
|
||||
SwigType_array_setdim(atype,n,"ANY");
|
||||
}
|
||||
k = k >> 1;
|
||||
}
|
||||
key = typemap_string(op,type,pname);
|
||||
tm = typemap_search(key,type_id);
|
||||
if (!tm) {
|
||||
key = typemap_string(op,type,(char*)"");
|
||||
tm = typemap_search(key,type_id);
|
||||
}
|
||||
if (tm) {
|
||||
Delete(atype);
|
||||
break;
|
||||
}
|
||||
j--;
|
||||
Delete(atype);
|
||||
}
|
||||
}
|
||||
|
||||
if (tm) {
|
||||
Printf(str,"%s",tm->code);
|
||||
ndim = SwigType_array_ndim(type);
|
||||
sprintf(temp,"%d",ndim);
|
||||
Replace(str,"$ndim",temp, DOH_REPLACE_ANY);
|
||||
for (i = 0; i < ndim; i++) {
|
||||
sprintf(temp,"$dim%d",i);
|
||||
Replace(str,temp,SwigType_array_getdim(type,i), DOH_REPLACE_ANY);
|
||||
}
|
||||
}
|
||||
return tm;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* static typemap_locals(Datatype *t, char *pname, String &s, ParmList *l, Wrapper *f)
|
||||
*
|
||||
* Takes a string, a parameter list and a wrapper function argument and
|
||||
* starts creating local variables.
|
||||
*
|
||||
* Substitutes locals in the string with actual values used.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
static void typemap_locals(SwigType *t, String_or_char *pname, DOHString *s, ParmList *l, Wrapper *f) {
|
||||
Parm *p;
|
||||
char *new_name;
|
||||
|
||||
p = l;
|
||||
while (p) {
|
||||
SwigType *pt = Gettype(p);
|
||||
String *pn = Getname(p);
|
||||
if (pn) {
|
||||
if (Len(pn) > 0) {
|
||||
DOHString *str;
|
||||
SwigType *tt;
|
||||
|
||||
str = NewString("");
|
||||
/* If the user gave us $type as the name of the local variable, we'll use
|
||||
the passed datatype instead */
|
||||
|
||||
if (Cmp(SwigType_base(pt),"$type")==0 || Cmp(SwigType_base(pt),"$basetype")==0) {
|
||||
tt = t;
|
||||
} else {
|
||||
tt = pt;
|
||||
}
|
||||
Printf(str,"%s",pn);
|
||||
/* Substitute parameter names */
|
||||
Replace(str,"$arg",pname, DOH_REPLACE_ANY);
|
||||
if (Cmp(SwigType_base(pt),"$basetype")==0) {
|
||||
/* use $basetype */
|
||||
new_name = Wrapper_new_localv(f,str,SwigType_base(tt),str,0);
|
||||
} else {
|
||||
new_name = Wrapper_new_localv(f,str, SwigType_str(tt,str), 0);
|
||||
}
|
||||
/* Substitute */
|
||||
Replace(s,pn,new_name,DOH_REPLACE_ID);
|
||||
}
|
||||
}
|
||||
p = Getnext(l);
|
||||
}
|
||||
/* If the original datatype was an array. We're going to go through and substitute
|
||||
it's array dimensions */
|
||||
|
||||
if (SwigType_isarray(t)) {
|
||||
char temp[10];
|
||||
for (int i = 0; i < SwigType_array_ndim(t); i++) {
|
||||
sprintf(temp,"$dim%d",i);
|
||||
Replace(f->locals,temp,SwigType_array_getdim(t,i), DOH_REPLACE_ANY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *source,
|
||||
* char *target, WrapperFunction *f)
|
||||
*
|
||||
* Looks up a "get" function in the type-map and returns a character string
|
||||
* containing the appropriate translation code.
|
||||
*
|
||||
* op is string code for type of mapping
|
||||
* lang is the target language string
|
||||
* type is the datatype
|
||||
* pname is an optional parameter name
|
||||
* source is a string with the source variable
|
||||
* target is a string containing the target value
|
||||
* f is a wrapper function object (optional)
|
||||
*
|
||||
* Returns NULL if no mapping is found.
|
||||
*
|
||||
* Typemaps follow a few rules regarding naming and C pointers by checking
|
||||
* declarations in this order.
|
||||
*
|
||||
* 1. type name [] - A named array (most specific)
|
||||
* 2. type name - Named argument
|
||||
* 3. type [] - Type with array
|
||||
* 4. type - Ordinary type
|
||||
*
|
||||
* Array checking is only made if the datatype actally has an array specifier
|
||||
*
|
||||
* Array checking uses a special token "ANY" that indicates that any
|
||||
* dimension will match. Since we are passed a real datatype here, we
|
||||
* need to hack this a special case.
|
||||
*
|
||||
* Array dimensions are substituted into the variables $dim1, $dim2,...,$dim9
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
static SwigType *realtype; /* This is a gross hack */
|
||||
static String *realname = 0; /* Real parameter name */
|
||||
|
||||
static char *typemap_lookup_internal(char *op, char *lang, SwigType *type, String_or_char *pname,
|
||||
String_or_char *source, String_or_char *target, Wrapper *f) {
|
||||
String *str = 0;
|
||||
char *key = 0;
|
||||
TypeMap *tm = 0;
|
||||
|
||||
last_args = 0;
|
||||
if (!lang) {
|
||||
return 0;
|
||||
}
|
||||
str = NewString("");
|
||||
/* First check for named array */
|
||||
tm = typemap_search_array(op,lang,type,pname,str);
|
||||
|
||||
/* Check for named argument */
|
||||
if (!tm) {
|
||||
key = typemap_string(op,type,pname);
|
||||
tm = typemap_search(key,type_id);
|
||||
if (tm)
|
||||
Printf(str,"%s",tm->code);
|
||||
}
|
||||
|
||||
/* Check for unnamed type */
|
||||
if (!tm) {
|
||||
key = typemap_string(op,type,(char*)"");
|
||||
tm = typemap_search(key,type_id);
|
||||
if (tm)
|
||||
Printf(str,"%s", tm->code);
|
||||
}
|
||||
if (!tm) {
|
||||
Delete(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Now perform character replacements */
|
||||
|
||||
Replace(str,"$source",source,DOH_REPLACE_ANY);
|
||||
Replace(str,"$target",target,DOH_REPLACE_ANY);
|
||||
Replace(str,"$type",SwigType_str(realtype,0),DOH_REPLACE_ANY);
|
||||
if (realname) {
|
||||
Replace(str,"$parmname",realname,DOH_REPLACE_ANY);
|
||||
} else {
|
||||
Replace(str,"$parmname","", DOH_REPLACE_ANY);
|
||||
}
|
||||
/* Print base type (without any pointers) */
|
||||
Replace(str,"$basetype",SwigType_base(realtype), DOH_REPLACE_ANY);
|
||||
Replace(str,"$basemangle",SwigType_manglestr(SwigType_base(realtype)), DOH_REPLACE_ANY);
|
||||
Replace(str,"$mangle",SwigType_manglestr(realtype), DOH_REPLACE_ANY);
|
||||
|
||||
/* If there were locals and a wrapper function, replace */
|
||||
if ((tm->args) && f) {
|
||||
typemap_locals(realtype, pname, str,tm->args,f);
|
||||
}
|
||||
|
||||
/* Return character string */
|
||||
last_args = tm->args;
|
||||
Swig_temp_result(str);
|
||||
return Char(str);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------
|
||||
* Real function call that takes care of application mappings
|
||||
* ---------------------------------------------------------- */
|
||||
|
||||
char *typemap_lookup(char *op, char *lang, SwigType *type, String_or_char *pname, String_or_char *source,
|
||||
String_or_char *target, Wrapper *f) {
|
||||
TmMethod *m;
|
||||
char *result;
|
||||
String *temp;
|
||||
|
||||
realtype = type; /* The other half of the gross hack */
|
||||
realname = pname;
|
||||
|
||||
// Printf(stdout,"Looking up %s\n", SwigType_str(type,pname));
|
||||
|
||||
/* Try to apply typemap right away */
|
||||
|
||||
result = typemap_lookup_internal(op,lang,type,pname,source,target,f);
|
||||
|
||||
/* If not found, try to pick up anything that might have been
|
||||
specified with %apply */
|
||||
|
||||
if (!result) {
|
||||
temp = NewStringf("%s$%s", SwigType_str(type,0), pname);
|
||||
m = (TmMethod *) GetVoid(application_hash,temp);
|
||||
if (!m) {
|
||||
Clear(temp);
|
||||
Printf(temp,"%s$",SwigType_str(type,0));
|
||||
m = (TmMethod *) GetVoid(application_hash,temp);
|
||||
}
|
||||
Delete(temp);
|
||||
if (m) {
|
||||
m = m->next;
|
||||
while (m) {
|
||||
result = typemap_lookup_internal(op,lang,m->type,m->name,source,target,f);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
m = m->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Still no idea, try to find a default typemap */
|
||||
|
||||
if (!result) {
|
||||
SwigType *t = SwigType_default(type);
|
||||
result = typemap_lookup_internal(op,lang,t,(char*)"SWIG_DEFAULT_TYPE",source,target,f);
|
||||
if (result) {
|
||||
Delete(t);
|
||||
return result;
|
||||
}
|
||||
Delete(t);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* char *typemap_check(char *op, char *lang, SwigType *type, String_or_char *pname)
|
||||
*
|
||||
* Checks to see if there is a typemap. Returns typemap string if found, NULL
|
||||
* if not.
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
char *typemap_check_internal(char *op, char *lang, SwigType *type, String_or_char *pname) {
|
||||
DOHString *str = 0;
|
||||
char *key = 0;
|
||||
TypeMap *tm = 0;
|
||||
|
||||
|
||||
if (!lang) {
|
||||
return 0;
|
||||
}
|
||||
str = NewString("");
|
||||
|
||||
/* First check for named array */
|
||||
|
||||
tm = typemap_search_array(op,lang,type,pname,str);
|
||||
|
||||
/* Check for named argument */
|
||||
if (!tm) {
|
||||
key = typemap_string(op,type,pname);
|
||||
tm = typemap_search(key,type_id);
|
||||
}
|
||||
|
||||
/* Check for unnamed array */
|
||||
if ((!tm) && (SwigType_isarray(type))) {
|
||||
key = typemap_string(op,type,(char*)"");
|
||||
tm = typemap_search(key,type_id);
|
||||
}
|
||||
|
||||
/* Check for unnamed type */
|
||||
if (!tm) {
|
||||
key = typemap_string(op,type,(char*)"");
|
||||
tm = typemap_search(key,type_id);
|
||||
}
|
||||
if (!tm) {
|
||||
Delete(str);
|
||||
return 0;
|
||||
}
|
||||
Printf(str,"%s",tm->code);
|
||||
/* Return character string */
|
||||
Swig_temp_result(str);
|
||||
return Char(str);
|
||||
}
|
||||
|
||||
/** Function for checking with applications */
|
||||
|
||||
char *typemap_check(char *op, char *lang, SwigType *type, String_or_char *pname) {
|
||||
TmMethod *m;
|
||||
String *temp;
|
||||
char *result;
|
||||
|
||||
/* Try to apply typemap right away */
|
||||
|
||||
result = typemap_check_internal(op,lang,type,pname);
|
||||
|
||||
/* If not found, try to pick up anything that might have been
|
||||
specified with %apply */
|
||||
|
||||
if (!result) {
|
||||
temp = NewStringf("%s$%s", SwigType_str(type,0), pname);
|
||||
m = (TmMethod *) GetVoid(application_hash,temp);
|
||||
if (!m) {
|
||||
Clear(temp);
|
||||
Printf(temp,"%s$",SwigType_str(type,0));
|
||||
m = (TmMethod *) GetVoid(application_hash,temp);
|
||||
}
|
||||
Delete(temp);
|
||||
if (m) {
|
||||
m = m->next;
|
||||
while (m) {
|
||||
result = typemap_check_internal(op,lang,m->type,m->name);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
m = m->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If still no result, might have a default typemap */
|
||||
if (!result) {
|
||||
SwigType *t = SwigType_default(type);
|
||||
result = typemap_check_internal(op,lang,t,(char*)"SWIG_DEFAULT_TYPE");
|
||||
if (result) {
|
||||
Delete(t);
|
||||
return result;
|
||||
}
|
||||
Delete(t);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* void typemap_clear(char *op, char *lang, DataType *type, char *pname)
|
||||
*
|
||||
* Clears any previous typemap. This works like a stack. Clearing a
|
||||
* typemap returns to any previous typemap in force. If there is no
|
||||
* previous map, then don't worry about it.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
void typemap_clear(char *op, char *lang, SwigType *type, String_or_char *pname) {
|
||||
|
||||
char *key;
|
||||
TypeMap *tm;
|
||||
|
||||
if (!typemap_lang || (strcmp(lang,typemap_lang))) return;
|
||||
key = typemap_string(op,type,pname);
|
||||
|
||||
/* Look for any previous version, simply set the last id if
|
||||
applicable. */
|
||||
|
||||
if (!typemap_hash) typemap_hash = NewHash();
|
||||
tm = (TypeMap *) GetVoid(typemap_hash,key);
|
||||
if (tm) {
|
||||
if (tm->last > type_id) tm->last = type_id;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* void typemap_copy(char *op, char *lang, DataType *stype, char *sname,
|
||||
* DataType *ttype, char *tname)
|
||||
*
|
||||
* Copies the code associate with a typemap
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
void typemap_copy(char *op, char *lang, SwigType *stype, String_or_char *sname,
|
||||
SwigType *ttype, String_or_char *tname) {
|
||||
|
||||
char *key;
|
||||
TypeMap *tm;
|
||||
|
||||
/* Try to locate a previous typemap */
|
||||
if (!typemap_lang || (strcmp(typemap_lang,lang))) return;
|
||||
|
||||
key = typemap_string(op,stype,sname);
|
||||
tm = typemap_search(key,type_id);
|
||||
if (!tm) return;
|
||||
typemap_register(op,lang,ttype,tname,tm->code,tm->args);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* char *fragment_string(char *op, char *lang)
|
||||
*
|
||||
* Produces a character string corresponding to a language and method
|
||||
* This string is used as the key for our typemap hash table.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
static char *fragment_string(char *op) {
|
||||
static char str[512];
|
||||
sprintf(str,"fragment:%s", op);
|
||||
return str;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* void fragment_register(char *op, char *lang, char *code)
|
||||
*
|
||||
* Register a code fragment with the type-mapper.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
void fragment_register(char *op, char *lang, String_or_char *code) {
|
||||
|
||||
char *key;
|
||||
TypeMap *tm,*tm_old;
|
||||
char temp[256];
|
||||
|
||||
if (!typemap_lang || (strcmp(typemap_lang,lang))) return;
|
||||
|
||||
tm = new TypeMap(lang,code);
|
||||
key = fragment_string(op);
|
||||
|
||||
/* Get any previous setting of the typemap */
|
||||
|
||||
tm_old = (TypeMap *) GetVoid(typemap_hash,key);
|
||||
if (tm_old) {
|
||||
/* If found, we need to attach the old version to the new one */
|
||||
|
||||
/* Perform a chaining operation */
|
||||
|
||||
sprintf(temp,"$%s",op);
|
||||
if (type_id < tm_old->last)
|
||||
Replace(tm->code,temp,tm_old->code,DOH_REPLACE_ANY);
|
||||
|
||||
tm->next = tm_old;
|
||||
tm_old->last = type_id;
|
||||
|
||||
/* Remove the old one from the hash */
|
||||
|
||||
Delattr(typemap_hash,key);
|
||||
}
|
||||
|
||||
/* Perform a default chaining operation if needed (defaults to nothing) */
|
||||
sprintf(temp,"$%s",op);
|
||||
Replace(tm->code,temp,"", DOH_REPLACE_ANY);
|
||||
|
||||
/* Add new typemap to the hash table */
|
||||
SetVoid(typemap_hash,key,tm);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* char *fragment_lookup(char *op, char *lang)
|
||||
*
|
||||
* op is string code for type of mapping
|
||||
* lang is the target language string
|
||||
*
|
||||
* Returns NULL if no mapping is found.
|
||||
*
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
char *fragment_lookup(char *op, char *lang) {
|
||||
DOHString *str;
|
||||
char *key = 0;
|
||||
TypeMap *tm = 0;
|
||||
|
||||
if (!typemap_lang || (strcmp(typemap_lang,lang))) return 0;
|
||||
|
||||
str = NewString("");
|
||||
key = fragment_string(op);
|
||||
tm = typemap_search(key,type_id);
|
||||
|
||||
if (!tm) return 0;
|
||||
|
||||
Append(str,tm->code);
|
||||
Swig_temp_result(str);
|
||||
return Char(str);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* void fragment_clear(char *op, char *lang)
|
||||
*
|
||||
* Clears any previous fragment definition. Is a stack operation--will
|
||||
* restore any previously declared typemap.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
void fragment_clear(char *op, char *lang) {
|
||||
|
||||
char *key;
|
||||
TypeMap *tm;
|
||||
|
||||
if (!typemap_lang || (strcmp(typemap_lang,lang))) return;
|
||||
|
||||
key = fragment_string(op);
|
||||
|
||||
/* Look for any previous version, simply set the last id if
|
||||
applicable. */
|
||||
|
||||
tm = (TypeMap *) GetVoid(typemap_hash,key);
|
||||
if (tm) {
|
||||
if (tm->last > type_id) tm->last = type_id;
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* typemap_initialize()
|
||||
*
|
||||
* Initialize the hash tables
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
typemap_initialize() {
|
||||
typemap_hash = NewHash();
|
||||
application_hash = NewHash();
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* int check_numopt()
|
||||
*
|
||||
* Gets the number of optional arguments for a ParmList.
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
int check_numopt(ParmList *p) {
|
||||
int n = 0;
|
||||
int i = 0;
|
||||
int state = 0;
|
||||
|
||||
for (;p; p = Getnext(p),i++) {
|
||||
SwigType *pt = Gettype(p);
|
||||
String *pn = Getname(p);
|
||||
if (Getvalue(p)) {
|
||||
n++;
|
||||
state = 1;
|
||||
} else if (typemap_check((char*)"default",typemap_lang,pt,pn)) {
|
||||
n++;
|
||||
state = 1;
|
||||
} else if (typemap_check((char*)"ignore",typemap_lang,pt,pn)) {
|
||||
n++;
|
||||
} else {
|
||||
if (state) {
|
||||
Printf(stderr,"%s : Line %d. Argument %d must have a default value!\n", input_file,line_number,i+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* typemap_match_parms()
|
||||
*
|
||||
* Match typemaps for a list of parameters. This function is only a hack to
|
||||
* ease the migration to the new SWIG typemap system. Returns a DOH list
|
||||
* of hash table objects containing all of the matches.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOHList *
|
||||
typemap_match_parms(ParmList *l) {
|
||||
|
||||
DOHList *tl;
|
||||
DOHHash *tm;
|
||||
Parm *p;
|
||||
|
||||
char *s;
|
||||
tl = NewList();
|
||||
|
||||
p = l;
|
||||
while (p) {
|
||||
SwigType *pt = Gettype(p);
|
||||
String *pn = Getname(p);
|
||||
ParmList *vars = 0;
|
||||
|
||||
tm = NewHash();
|
||||
|
||||
/* Look up all of the argument related typemaps */
|
||||
/* "in" */
|
||||
if ((s = typemap_lookup((char*)"in",typemap_lang,pt,pn,(char *)"$source",(char *)"$target",0))) {
|
||||
Setattr(tm,"in",s);
|
||||
}
|
||||
|
||||
/* "ignore" */
|
||||
if ((s = typemap_lookup((char*)"ignore",typemap_lang,pt,pn,(char *)"$source",(char *)"$target",0))) {
|
||||
Setattr(tm,"ignore",s);
|
||||
}
|
||||
|
||||
/* "argout" */
|
||||
if ((s = typemap_lookup((char*)"argout",typemap_lang,pt,pn,(char *)"$source",(char *)"$target",0))) {
|
||||
Setattr(tm,"argout",s);
|
||||
}
|
||||
|
||||
/* "default" */
|
||||
if ((s = typemap_lookup((char*)"default",typemap_lang,pt,pn,(char *)"$source",(char *)"$target",0))) {
|
||||
Setattr(tm,"default",s);
|
||||
}
|
||||
|
||||
/* "check" */
|
||||
if ((s = typemap_lookup((char*)"check",typemap_lang,pt,pn,(char *)"$source",(char *)"$target",0))) {
|
||||
Setattr(tm,"check",s);
|
||||
}
|
||||
|
||||
/* "arginit" */
|
||||
if ((s = typemap_lookup((char*)"arginit",typemap_lang,pt,pn,(char *)"$source",(char *)"$target",0))) {
|
||||
Setattr(tm,"arginit",s);
|
||||
}
|
||||
Setattr(tm,"locals", vars);
|
||||
Append(tl,tm);
|
||||
Delete(tm);
|
||||
p = Getnext(p);
|
||||
}
|
||||
return tl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -6,9 +6,9 @@ srcdir = @srcdir@
|
|||
VPATH = @srcdir@
|
||||
|
||||
SRCS = map.c wrapfunc.c naming.c tree.c stype.c scanner.c include.c getopt.c misc.c \
|
||||
parms.c cwrap.c
|
||||
parms.c cwrap.c typemap.c
|
||||
OBJS = map.o wrapfunc.o naming.o tree.o stype.o scanner.o include.o getopt.o misc.o \
|
||||
parms.o cwrap.o
|
||||
parms.o cwrap.o typemap.o
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
|
|
|||
|
|
@ -346,3 +346,8 @@ Swig_map_match_type(Hash *ruleset, DOH *type, String_or_char *name) {
|
|||
Delete(p);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1517,7 +1517,6 @@ SwigType_emit_type_table(File *f_forward, File *f_table) {
|
|||
|
||||
SwigType_inherit_equiv(f_table);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
Printf(stdout,"---r_mangled---\n");
|
||||
Printf(stdout,"%s\n", r_mangled);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ typedef DOH List;
|
|||
typedef DOH String_or_char;
|
||||
typedef DOH File;
|
||||
|
||||
/* --- Legacy DataType interface. This is being replaced --- */
|
||||
/* --- Legacy DataType interface. These type codes are provided solely
|
||||
for backwards compatibility with older modules --- */
|
||||
|
||||
#define T_INT 1
|
||||
#define T_SHORT 2
|
||||
|
|
@ -338,6 +339,26 @@ extern Wrapper *Swig_cvarget_wrapper(String_or_char *varname,
|
|||
String_or_char *code);
|
||||
|
||||
|
||||
/* --- Legacy Typemap API (somewhat simplified) --- */
|
||||
|
||||
extern void Swig_typemap_init();
|
||||
extern void Swig_typemap_register(char *op, SwigType *type, String_or_char *name, String_or_char *code, ParmList *locals);
|
||||
extern void Swig_typemap_copy(char *op, SwigType *stype, String_or_char *sname,
|
||||
SwigType *ttype, String_or_char *tname);
|
||||
extern void Swig_typemap_clear(char *op, SwigType *type, String_or_char *name);
|
||||
extern void Swig_typemap_apply(SwigType *tm_type, String_or_char *tmname, SwigType *type, String_or_char *pname);
|
||||
extern void Swig_typemap_clear_apply(SwigType *type, String_or_char *pname);
|
||||
extern void Swig_typemap_debug();
|
||||
extern Hash *Swig_typemap_search(char *op, SwigType *type, String_or_char *pname);
|
||||
extern char *Swig_typemap_lookup(char *op, SwigType *type, String_or_char *pname, String_or_char *source, String_or_char *target, Wrapper *f);
|
||||
extern void Swig_typemap_new_scope();
|
||||
extern Hash *Swig_typemap_pop_scope();
|
||||
|
||||
/* --- Legacy %except directive API --- */
|
||||
extern void Swig_except_register(String_or_char *code);
|
||||
extern char *Swig_except_lookup();
|
||||
extern void Swig_except_clear();
|
||||
|
||||
/* --- Attribute access macros --- */
|
||||
|
||||
#define Gettype(x) Getattr(x,"type")
|
||||
|
|
|
|||
478
Source/Swig/typemap.c
Normal file
478
Source/Swig/typemap.c
Normal file
|
|
@ -0,0 +1,478 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* typemap.c
|
||||
*
|
||||
* A somewhat generalized implementation of SWIG1.1 typemaps.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
#define MAX_SCOPE 32
|
||||
|
||||
static Hash *typemaps[MAX_SCOPE];
|
||||
static int tm_scope = 0;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_init()
|
||||
*
|
||||
* Initialize the typemap system
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_typemap_init() {
|
||||
int i;
|
||||
for (i = 0; i < MAX_SCOPE; i++) {
|
||||
typemaps[i] = 0;
|
||||
}
|
||||
typemaps[0] = NewHash();
|
||||
tm_scope = 0;
|
||||
}
|
||||
|
||||
static char *parm_key(String_or_char *pname) {
|
||||
static char temp[512] = "-";
|
||||
strcpy(temp+1,Char(pname));
|
||||
return temp;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_new_scope()
|
||||
*
|
||||
* Create a new typemap scope
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_typemap_new_scope() {
|
||||
tm_scope++;
|
||||
typemaps[tm_scope] = NewHash();
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_pop_scope()
|
||||
*
|
||||
* Pop the last typemap scope off
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
Hash *
|
||||
Swig_typemap_pop_scope() {
|
||||
if (tm_scope > 0) {
|
||||
return Swig_temp_result(typemaps[tm_scope--]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_register()
|
||||
*
|
||||
* Add a new typemap
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_typemap_register(char *op, SwigType *type, String_or_char *pname, String_or_char *code, ParmList *locals) {
|
||||
char *key;
|
||||
Hash *tm;
|
||||
Hash *tm1;
|
||||
Hash *tm2;
|
||||
|
||||
if ((pname) && (Cmp(pname,"SWIG_DEFAULT_TYPE") == 0)) {
|
||||
type = SwigType_default(type);
|
||||
Swig_temp_result(type);
|
||||
}
|
||||
|
||||
/* See if this type has been seen before */
|
||||
tm = Getattr(typemaps[tm_scope],type);
|
||||
if (!tm) {
|
||||
tm = NewHash();
|
||||
Setattr(typemaps[tm_scope],Char(type),tm);
|
||||
Delete(tm);
|
||||
}
|
||||
if ((pname) && Len(pname)) {
|
||||
/* See if parameter has been seen before */
|
||||
key = parm_key(pname);
|
||||
tm1 = Getattr(tm,key);
|
||||
if (!tm1) {
|
||||
tm1 = NewHash();
|
||||
Setattr(tm,key,tm1);
|
||||
Delete(tm1);
|
||||
}
|
||||
tm = tm1;
|
||||
}
|
||||
tm2 = NewHash();
|
||||
Setattr(tm2,"code",NewString(code));
|
||||
Setattr(tm2,"locals", CopyParmList(locals));
|
||||
Setattr(tm,op,tm2);
|
||||
Delete(tm2);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_get()
|
||||
*
|
||||
* Retrieve typemap information from current scope.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static Hash *
|
||||
Swig_typemap_get(SwigType *type, String_or_char *name, int scope) {
|
||||
Hash *tm, *tm1;
|
||||
/* See if this type has been seen before */
|
||||
if ((scope < 0) || (scope > tm_scope)) return 0;
|
||||
tm = Getattr(typemaps[scope],type);
|
||||
if (!tm) {
|
||||
return 0;
|
||||
}
|
||||
if ((name) && Len(name)) {
|
||||
tm1 = Getattr(tm, parm_key(name));
|
||||
return tm1;
|
||||
}
|
||||
return tm;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_copy()
|
||||
*
|
||||
* Copy a typemap
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_typemap_copy(char *op, SwigType *stype, String_or_char *sname,
|
||||
SwigType *ttype, String_or_char *tname) {
|
||||
|
||||
Hash *tm=0, *tm1;
|
||||
int ts = tm_scope;
|
||||
while (ts >= 0) {
|
||||
tm = Swig_typemap_get(stype,sname,ts);
|
||||
if (tm) break;
|
||||
tm = Swig_typemap_get(stype,0,ts);
|
||||
if (tm) break;
|
||||
ts--;
|
||||
}
|
||||
if (!tm) return;
|
||||
tm1 = Getattr(tm,op);
|
||||
if (!tm1) return;
|
||||
Swig_typemap_register(op,ttype,tname, Getattr(tm1,"code"), Getattr(tm1,"locals"));
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_clear()
|
||||
*
|
||||
* Delete a typemap
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_typemap_clear(char *op, SwigType *type, String_or_char *name) {
|
||||
Hash *tm;
|
||||
|
||||
tm = Swig_typemap_get(type,name,tm_scope);
|
||||
if (tm)
|
||||
Delattr(tm,op);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_apply()
|
||||
*
|
||||
* %apply directive. This function is nothing more than a glorified typemap
|
||||
* copy. Note: this is *very* different than SWIG1.1 although the end result
|
||||
* is very "similar."
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void merge_attributes(Hash *target, Hash *source) {
|
||||
String *key;
|
||||
for (key = Firstkey(source); key; key = Nextkey(source)) {
|
||||
if (Getattr(target,key)) continue;
|
||||
Setattr(target,key,Getattr(source,key));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Swig_typemap_apply(SwigType *tm_type, String_or_char *tmname, SwigType *type, String_or_char *pname) {
|
||||
Hash *tm, *tm1, *am;
|
||||
int ts = tm_scope;
|
||||
char *key;
|
||||
|
||||
tm = Swig_typemap_get(type,pname,tm_scope);
|
||||
if (!tm) {
|
||||
tm = Getattr(typemaps[tm_scope],type);
|
||||
if (!tm) {
|
||||
tm = NewHash();
|
||||
Setattr(typemaps[tm_scope], Char(type), tm);
|
||||
Delete(tm);
|
||||
}
|
||||
if ((pname) && Len(pname)) {
|
||||
key = parm_key(pname);
|
||||
tm1 = NewHash();
|
||||
Setattr(tm,key,tm1);
|
||||
Delete(tm1);
|
||||
tm = tm1;
|
||||
}
|
||||
}
|
||||
/* tm contains the typemap table into which we are going to be copying */
|
||||
while (ts >= 0) {
|
||||
am = Swig_typemap_get(tm_type, tmname,ts);
|
||||
if (am) {
|
||||
merge_attributes(tm,am);
|
||||
}
|
||||
ts--;
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_clear_apply()
|
||||
*
|
||||
* %clear directive. Clears all typemaps for a type.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_typemap_clear_apply(SwigType *type, String_or_char *name) {
|
||||
Hash *tm;
|
||||
|
||||
tm = Getattr(typemaps[tm_scope],type);
|
||||
if (!tm) return;
|
||||
if ((name) && (Len(name))) {
|
||||
Delattr(tm,parm_key(name));
|
||||
} else {
|
||||
Delattr(typemaps[tm_scope],type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Internal function to strip array dimensions. */
|
||||
static SwigType *strip_arrays(SwigType *type) {
|
||||
SwigType *t;
|
||||
int ndim;
|
||||
int i;
|
||||
t = Copy(type);
|
||||
ndim = SwigType_array_ndim(t);
|
||||
for (i = 0; i < ndim; i++) {
|
||||
SwigType_array_setdim(t,i,"ANY");
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_search_op()
|
||||
*
|
||||
* Search for a typemap match.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
Hash *
|
||||
Swig_typemap_search(char *op, SwigType *type, String_or_char *name) {
|
||||
Hash *result = 0, *tm, *tm1, *tma;
|
||||
SwigType *noarrays = 0;
|
||||
SwigType *primitive = 0;
|
||||
int ts;
|
||||
int isarray;
|
||||
char *cname = 0;
|
||||
|
||||
if ((name) && Len(name)) cname = parm_key(name);
|
||||
isarray = SwigType_isarray(type);
|
||||
ts = tm_scope;
|
||||
while (ts >= 0) {
|
||||
/* Try to get an exact type-match */
|
||||
tm = Getattr(typemaps[ts],type);
|
||||
if (tm && cname) {
|
||||
tm1 = Getattr(tm,cname);
|
||||
if (tm1) {
|
||||
result = Getattr(tm1,op); /* See if there is a type-name match */
|
||||
if (result) goto ret_result;
|
||||
}
|
||||
}
|
||||
if (tm) {
|
||||
result = Getattr(tm,op); /* See if there is simply a type match */
|
||||
if (result) goto ret_result;
|
||||
}
|
||||
|
||||
if (isarray) {
|
||||
/* If working with arrays, strip away all of the dimensions and replace with ANY.
|
||||
See if that generates a match */
|
||||
if (!noarrays) noarrays = strip_arrays(type);
|
||||
tma = Getattr(typemaps[ts],noarrays);
|
||||
if (tma && cname) {
|
||||
tm1 = Getattr(tma,cname);
|
||||
if (tm1) {
|
||||
result = Getattr(tm1,op); /* type-name match */
|
||||
if (result) goto ret_result;
|
||||
}
|
||||
}
|
||||
if (tma) {
|
||||
result = Getattr(tma,op); /* type match */
|
||||
if (result) goto ret_result;
|
||||
}
|
||||
}
|
||||
/* Hmmm. Well, no match seems to be found at all. See if there is some kind of default
|
||||
mapping */
|
||||
|
||||
if (!primitive) {
|
||||
primitive = SwigType_default(type);
|
||||
}
|
||||
tm = Getattr(typemaps[ts],primitive);
|
||||
if (tm) {
|
||||
tm1 = Getattr(tm,"-SWIG_DEFAULT_TYPE");
|
||||
if (tm1) {
|
||||
result = Getattr(tm1,op);
|
||||
if (result) goto ret_result;
|
||||
}
|
||||
}
|
||||
ts--;
|
||||
}
|
||||
|
||||
ret_result:
|
||||
if (noarrays) Delete(noarrays);
|
||||
if (primitive) Delete(primitive);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* static typemap_locals()
|
||||
*
|
||||
* Takes a string, a parameter list and a wrapper function argument and
|
||||
* creates the local variables.
|
||||
* ------------------------------------------------------------------------ */
|
||||
|
||||
static void typemap_locals(SwigType *t, String_or_char *pname, DOHString *s, ParmList *l, Wrapper *f) {
|
||||
Parm *p;
|
||||
char *new_name;
|
||||
|
||||
p = l;
|
||||
while (p) {
|
||||
SwigType *pt = Gettype(p);
|
||||
String *pn = Getname(p);
|
||||
if (pn) {
|
||||
if (Len(pn) > 0) {
|
||||
DOHString *str;
|
||||
SwigType *tt;
|
||||
|
||||
str = NewString("");
|
||||
/* If the user gave us $type as the name of the local variable, we'll use
|
||||
the passed datatype instead */
|
||||
|
||||
if (Cmp(SwigType_base(pt),"$type")==0 || Cmp(SwigType_base(pt),"$basetype")==0) {
|
||||
tt = t;
|
||||
} else {
|
||||
tt = pt;
|
||||
}
|
||||
Printf(str,"%s",pn);
|
||||
/* Substitute parameter names */
|
||||
Replace(str,"$arg",pname, DOH_REPLACE_ANY);
|
||||
if (Cmp(SwigType_base(pt),"$basetype")==0) {
|
||||
/* use $basetype */
|
||||
new_name = Wrapper_new_localv(f,str,SwigType_base(tt),str,0);
|
||||
} else {
|
||||
new_name = Wrapper_new_localv(f,str, SwigType_str(tt,str), 0);
|
||||
}
|
||||
/* Substitute */
|
||||
Replace(s,pn,new_name,DOH_REPLACE_ID);
|
||||
}
|
||||
}
|
||||
p = Getnext(l);
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_lookup()
|
||||
*
|
||||
* Perform a typemap lookup (ala SWIG1.1)
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char *Swig_typemap_lookup(char *op, SwigType *type, String_or_char *pname, String_or_char *source,
|
||||
String_or_char *target, Wrapper *f)
|
||||
{
|
||||
Hash *tm;
|
||||
String *s;
|
||||
ParmList *locals;
|
||||
|
||||
tm = Swig_typemap_search(op,type,pname);
|
||||
if (!tm) return 0;
|
||||
|
||||
s = Getattr(tm,"code");
|
||||
if (!s) return 0;
|
||||
s = Copy(s); /* Make a local copy of the typemap code */
|
||||
|
||||
locals = Getattr(tm,"locals");
|
||||
|
||||
/* Replace array dimensions */
|
||||
if (locals && f) {
|
||||
typemap_locals(type,pname,s,locals,f);
|
||||
}
|
||||
|
||||
/* If the original datatype was an array. We're going to go through and substitute
|
||||
it's array dimensions */
|
||||
|
||||
if (SwigType_isarray(type)) {
|
||||
char temp[10];
|
||||
int ndim = SwigType_array_ndim(type);
|
||||
int i;
|
||||
for (i = 0; i < ndim; i++) {
|
||||
DOHString *dim = SwigType_array_getdim(type,i);
|
||||
sprintf(temp,"$dim%d",i);
|
||||
Replace(f->locals,temp,dim, DOH_REPLACE_ANY);
|
||||
Replace(s,temp,dim,DOH_REPLACE_ANY);
|
||||
}
|
||||
}
|
||||
|
||||
/* Now perform character replacements */
|
||||
Replace(s,"$source",source,DOH_REPLACE_ANY);
|
||||
Replace(s,"$target",target,DOH_REPLACE_ANY);
|
||||
Replace(s,"$type",SwigType_str(type,0),DOH_REPLACE_ANY);
|
||||
Replace(s,"$parmname",pname, DOH_REPLACE_ANY);
|
||||
|
||||
/* Print base type (without any pointers) */
|
||||
Replace(s,"$basetype",SwigType_base(type), DOH_REPLACE_ANY);
|
||||
Replace(s,"$basemangle",SwigType_manglestr(SwigType_base(type)), DOH_REPLACE_ANY);
|
||||
Replace(s,"$mangle",SwigType_manglestr(type), DOH_REPLACE_ANY);
|
||||
Swig_temp_result(s);
|
||||
return Char(s);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_typemap_debug()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_typemap_debug() {
|
||||
int ts;
|
||||
Printf(stdout,"---[ typemaps ]--------------------------------------------------------------\n");
|
||||
|
||||
ts = tm_scope;
|
||||
while (ts >= 0) {
|
||||
Printf(stdout,"::: scope %d\n\n",ts);
|
||||
Printf(stdout,"%s\n", typemaps[ts]);
|
||||
ts--;
|
||||
}
|
||||
Printf(stdout,"-----------------------------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* %except directive support.
|
||||
*
|
||||
* These functions technically don't really have anything to do with typemaps
|
||||
* except that they have the same scoping rules. Therefore, it's easy enough to
|
||||
* just use the hash table structure of the typemap code.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_except_register(String_or_char *code) {
|
||||
String *s = NewString(code);
|
||||
Setattr(typemaps[tm_scope],"*except*",s);
|
||||
Delete(s);
|
||||
}
|
||||
|
||||
char *Swig_except_lookup() {
|
||||
String *s;
|
||||
int ts = tm_scope;
|
||||
while (ts >= 0) {
|
||||
s = Getattr(typemaps[tm_scope],"*except*");
|
||||
if (s) {
|
||||
s = Copy(s);
|
||||
Swig_temp_result(s);
|
||||
return Char(s);
|
||||
}
|
||||
ts--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Swig_except_clear() {
|
||||
Delattr(typemaps[tm_scope],"*except*");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue