Minor fixes to %apply.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@652 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
0d5ed7dff5
commit
ccc26cebae
1 changed files with 59 additions and 102 deletions
|
|
@ -64,6 +64,7 @@ extern "C" {
|
||||||
* ------------------------------------------------------------------------ */
|
* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
static ParmList *last_args = 0;
|
static ParmList *last_args = 0;
|
||||||
|
char *typemap_lang = 0; // Typemap language name
|
||||||
|
|
||||||
int type_id = 0;
|
int type_id = 0;
|
||||||
|
|
||||||
|
|
@ -220,17 +221,16 @@ void typemap_clear_apply(SwigType *type, String_or_char *pname) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
* char *typemap_string(char *lang, DataType *type, char *pname, char *suffix)
|
* char *typemap_string()
|
||||||
*
|
*
|
||||||
* Produces a character string corresponding to a lang, datatype, and
|
* Produces a character string corresponding to a lang, datatype, and
|
||||||
* method. This string is used as the key for our typemap hash table.
|
* method. This string is used as the key for our typemap hash table.
|
||||||
* ------------------------------------------------------------------------ */
|
* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
static String *typemap_string(char *op, char *lang, SwigType *type, String_or_char *pname) {
|
static char *typemap_string(char *op, SwigType *type, String_or_char *pname) {
|
||||||
String *str;
|
static char str[1024];
|
||||||
str = NewStringf("%s-%s-%s",op,lang,SwigType_str(type,pname));
|
sprintf(str,"%s-%s-%s",op, Char(type), Char(pname));
|
||||||
/* Printf(stdout,"key: %s\n", str); */
|
return str;
|
||||||
return Swig_temp_result(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
|
|
@ -243,13 +243,13 @@ static String *typemap_string(char *op, char *lang, SwigType *type, String_or_ch
|
||||||
void typemap_register(char *op, char *lang, SwigType *type, String_or_char *pname,
|
void typemap_register(char *op, char *lang, SwigType *type, String_or_char *pname,
|
||||||
String_or_char *getcode, ParmList *args) {
|
String_or_char *getcode, ParmList *args) {
|
||||||
|
|
||||||
String *key;
|
char *key;
|
||||||
TypeMap *tm, *tm_old;
|
TypeMap *tm, *tm_old;
|
||||||
int is_default = 0;
|
int is_default = 0;
|
||||||
|
|
||||||
|
if (!typemap_lang || (strcmp(typemap_lang,lang))) return;
|
||||||
if (!typemap_hash) typemap_hash = NewHash();
|
if (!typemap_hash) typemap_hash = NewHash();
|
||||||
|
|
||||||
|
|
||||||
tm = new TypeMap(lang,type,getcode,args);
|
tm = new TypeMap(lang,type,getcode,args);
|
||||||
/* If this is a default typemap, downgrade the type! */
|
/* If this is a default typemap, downgrade the type! */
|
||||||
|
|
||||||
|
|
@ -258,7 +258,7 @@ void typemap_register(char *op, char *lang, SwigType *type, String_or_char *pnam
|
||||||
is_default = 1;
|
is_default = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
key = typemap_string(op,lang,tm->type,pname);
|
key = typemap_string(op,tm->type,pname);
|
||||||
|
|
||||||
/* Get any previous setting of the typemap */
|
/* Get any previous setting of the typemap */
|
||||||
tm_old = (TypeMap *) GetVoid(typemap_hash, key);
|
tm_old = (TypeMap *) GetVoid(typemap_hash, key);
|
||||||
|
|
@ -327,7 +327,7 @@ typemap_search(String_or_char *key, int id) {
|
||||||
static
|
static
|
||||||
TypeMap *typemap_search_array(char *op, char *lang, SwigType *type, String_or_char *pname, DOHString *str) {
|
TypeMap *typemap_search_array(char *op, char *lang, SwigType *type, String_or_char *pname, DOHString *str) {
|
||||||
SwigType *atype;
|
SwigType *atype;
|
||||||
String *key;
|
char *key;
|
||||||
int ndim,i,j,k,n;
|
int ndim,i,j,k,n;
|
||||||
TypeMap *tm;
|
TypeMap *tm;
|
||||||
char temp[10];
|
char temp[10];
|
||||||
|
|
@ -336,12 +336,12 @@ TypeMap *typemap_search_array(char *op, char *lang, SwigType *type, String_or_ch
|
||||||
|
|
||||||
/* First check to see if exactly this array has been mapped */
|
/* First check to see if exactly this array has been mapped */
|
||||||
|
|
||||||
key = typemap_string(op,lang,type,pname);
|
key = typemap_string(op,type,pname);
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
|
|
||||||
/* Check for unnamed array of specific dimensions */
|
/* Check for unnamed array of specific dimensions */
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
key = typemap_string(op,lang,type,(char*)"");
|
key = typemap_string(op,type,(char*)"");
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -359,10 +359,10 @@ TypeMap *typemap_search_array(char *op, char *lang, SwigType *type, String_or_ch
|
||||||
}
|
}
|
||||||
k = k >> 1;
|
k = k >> 1;
|
||||||
}
|
}
|
||||||
key = typemap_string(op,lang,type,pname);
|
key = typemap_string(op,type,pname);
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
key = typemap_string(op,lang,type,(char*)"");
|
key = typemap_string(op,type,(char*)"");
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
}
|
}
|
||||||
if (tm) {
|
if (tm) {
|
||||||
|
|
@ -370,8 +370,8 @@ TypeMap *typemap_search_array(char *op, char *lang, SwigType *type, String_or_ch
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
j--;
|
j--;
|
||||||
|
Delete(atype);
|
||||||
}
|
}
|
||||||
Delete(atype);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tm) {
|
if (tm) {
|
||||||
|
|
@ -485,7 +485,7 @@ static String *realname = 0; /* Real parameter name */
|
||||||
static char *typemap_lookup_internal(char *op, char *lang, SwigType *type, String_or_char *pname,
|
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_or_char *source, String_or_char *target, Wrapper *f) {
|
||||||
String *str = 0;
|
String *str = 0;
|
||||||
String *key = 0;
|
char *key = 0;
|
||||||
TypeMap *tm = 0;
|
TypeMap *tm = 0;
|
||||||
|
|
||||||
last_args = 0;
|
last_args = 0;
|
||||||
|
|
@ -498,7 +498,7 @@ static char *typemap_lookup_internal(char *op, char *lang, SwigType *type, Strin
|
||||||
|
|
||||||
/* Check for named argument */
|
/* Check for named argument */
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
key = typemap_string(op,lang,type,pname);
|
key = typemap_string(op,type,pname);
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
if (tm)
|
if (tm)
|
||||||
Printf(str,"%s",tm->code);
|
Printf(str,"%s",tm->code);
|
||||||
|
|
@ -506,7 +506,7 @@ static char *typemap_lookup_internal(char *op, char *lang, SwigType *type, Strin
|
||||||
|
|
||||||
/* Check for unnamed type */
|
/* Check for unnamed type */
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
key = typemap_string(op,lang,type,(char*)"");
|
key = typemap_string(op,type,(char*)"");
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
if (tm)
|
if (tm)
|
||||||
Printf(str,"%s", tm->code);
|
Printf(str,"%s", tm->code);
|
||||||
|
|
@ -551,8 +551,6 @@ char *typemap_lookup(char *op, char *lang, SwigType *type, String_or_char *pname
|
||||||
TmMethod *m;
|
TmMethod *m;
|
||||||
char *result;
|
char *result;
|
||||||
String *temp;
|
String *temp;
|
||||||
String_or_char *ppname;
|
|
||||||
char *tstr;
|
|
||||||
|
|
||||||
realtype = type; /* The other half of the gross hack */
|
realtype = type; /* The other half of the gross hack */
|
||||||
realname = pname;
|
realname = pname;
|
||||||
|
|
@ -610,7 +608,7 @@ char *typemap_lookup(char *op, char *lang, SwigType *type, String_or_char *pname
|
||||||
|
|
||||||
char *typemap_check_internal(char *op, char *lang, SwigType *type, String_or_char *pname) {
|
char *typemap_check_internal(char *op, char *lang, SwigType *type, String_or_char *pname) {
|
||||||
DOHString *str = 0;
|
DOHString *str = 0;
|
||||||
String *key = 0;
|
char *key = 0;
|
||||||
TypeMap *tm = 0;
|
TypeMap *tm = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -625,19 +623,19 @@ char *typemap_check_internal(char *op, char *lang, SwigType *type, String_or_cha
|
||||||
|
|
||||||
/* Check for named argument */
|
/* Check for named argument */
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
key = typemap_string(op,lang,type,pname);
|
key = typemap_string(op,type,pname);
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for unnamed array */
|
/* Check for unnamed array */
|
||||||
if ((!tm) && (SwigType_isarray(type))) {
|
if ((!tm) && (SwigType_isarray(type))) {
|
||||||
key = typemap_string(op,lang,type,(char*)"");
|
key = typemap_string(op,type,(char*)"");
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for unnamed type */
|
/* Check for unnamed type */
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
key = typemap_string(op,lang,type,(char*)"");
|
key = typemap_string(op,type,(char*)"");
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
}
|
}
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
|
|
@ -654,82 +652,36 @@ char *typemap_check_internal(char *op, char *lang, SwigType *type, String_or_cha
|
||||||
|
|
||||||
char *typemap_check(char *op, char *lang, SwigType *type, String_or_char *pname) {
|
char *typemap_check(char *op, char *lang, SwigType *type, String_or_char *pname) {
|
||||||
TmMethod *m;
|
TmMethod *m;
|
||||||
char temp[512];
|
String *temp;
|
||||||
char *result;
|
char *result;
|
||||||
char *ppname;
|
|
||||||
char *tstr;
|
|
||||||
/* Try to apply typemap right away */
|
/* Try to apply typemap right away */
|
||||||
|
|
||||||
result = typemap_check_internal(op,lang,type,pname);
|
result = typemap_check_internal(op,lang,type,pname);
|
||||||
|
|
||||||
#ifdef OLD
|
/* If not found, try to pick up anything that might have been
|
||||||
|
specified with %apply */
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
int drop_pointer = 0;
|
temp = NewStringf("%s$%s", SwigType_str(type,0), pname);
|
||||||
ppname = pname;
|
m = (TmMethod *) GetVoid(application_hash,temp);
|
||||||
if (!ppname) ppname = (char*)"";
|
if (!m) {
|
||||||
|
Clear(temp);
|
||||||
/* The idea : We're going to cycle through applications and
|
Printf(temp,"%s$",SwigType_str(type,0));
|
||||||
drop pointers off until we get a match. */
|
|
||||||
|
|
||||||
while (drop_pointer <= (type->_is_pointer - type->_implicit_ptr)) {
|
|
||||||
type->_is_pointer -= drop_pointer;
|
|
||||||
tstr = DataType_str(type,0);
|
|
||||||
sprintf(temp,"%s$%s",tstr,ppname);
|
|
||||||
/* No mapping was found. See if the name has been mapped with %apply */
|
|
||||||
if (!application_hash) application_hash = NewHash();
|
|
||||||
m = (TmMethod *) GetVoid(application_hash,temp);
|
m = (TmMethod *) GetVoid(application_hash,temp);
|
||||||
if (!m) {
|
}
|
||||||
sprintf(temp,"%s$",tstr);
|
Delete(temp);
|
||||||
m = (TmMethod *) GetVoid(application_hash,temp);
|
if (m) {
|
||||||
}
|
m = m->next;
|
||||||
if (m) {
|
while (m) {
|
||||||
m = m->next;
|
result = typemap_check_internal(op,lang,m->type,m->name);
|
||||||
while (m) {
|
if (result) {
|
||||||
char *oldary = 0;
|
return result;
|
||||||
static DOHString *newarray = 0;
|
|
||||||
if (!newarray) newarray = NewString("");
|
|
||||||
if (*(m->name)) ppname = m->name;
|
|
||||||
else ppname = pname;
|
|
||||||
m->type->_is_pointer += drop_pointer;
|
|
||||||
if (DataType_arraystr(m->type))
|
|
||||||
oldary = Swig_copy_string(DataType_arraystr(m->type));
|
|
||||||
else
|
|
||||||
oldary = 0;
|
|
||||||
|
|
||||||
/* If the mapping type is an array and has the 'ANY' keyword, we
|
|
||||||
have to play some magic */
|
|
||||||
|
|
||||||
if ((DataType_arraystr(m->type)) && (DataType_arraystr(type))) {
|
|
||||||
/* Build up the new array string */
|
|
||||||
Clear(newarray);
|
|
||||||
for (int n = 0; n < DataType_array_dimensions(m->type); n++) {
|
|
||||||
char *d = DataType_get_dimension(m->type,n);
|
|
||||||
if (strcmp(d,"ANY") == 0) {
|
|
||||||
Printf(newarray,"[%s]", DataType_get_dimension(type,n));
|
|
||||||
} else {
|
|
||||||
Printf(newarray,"[%s]", d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DataType_set_arraystr(m->type, Char(newarray));
|
|
||||||
} else if (DataType_arraystr(type)) {
|
|
||||||
DataType_set_arraystr(m->type, DataType_arraystr(type));
|
|
||||||
}
|
|
||||||
result = typemap_check_internal(op,lang,m->type,ppname);
|
|
||||||
DataType_set_arraystr(m->type,oldary);
|
|
||||||
if (oldary) free(oldary);
|
|
||||||
m->type->_is_pointer -= drop_pointer;
|
|
||||||
if (result) {
|
|
||||||
type->_is_pointer += drop_pointer;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
m = m->next;
|
|
||||||
}
|
}
|
||||||
|
m = m->next;
|
||||||
}
|
}
|
||||||
type->_is_pointer += drop_pointer;
|
|
||||||
drop_pointer++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* If still no result, might have a default typemap */
|
/* If still no result, might have a default typemap */
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
|
@ -754,10 +706,11 @@ char *typemap_check(char *op, char *lang, SwigType *type, String_or_char *pname)
|
||||||
|
|
||||||
void typemap_clear(char *op, char *lang, SwigType *type, String_or_char *pname) {
|
void typemap_clear(char *op, char *lang, SwigType *type, String_or_char *pname) {
|
||||||
|
|
||||||
String *key;
|
char *key;
|
||||||
TypeMap *tm;
|
TypeMap *tm;
|
||||||
|
|
||||||
key = typemap_string(op,lang,type,pname);
|
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
|
/* Look for any previous version, simply set the last id if
|
||||||
applicable. */
|
applicable. */
|
||||||
|
|
@ -779,12 +732,13 @@ void typemap_clear(char *op, char *lang, SwigType *type, String_or_char *pname)
|
||||||
void typemap_copy(char *op, char *lang, SwigType *stype, String_or_char *sname,
|
void typemap_copy(char *op, char *lang, SwigType *stype, String_or_char *sname,
|
||||||
SwigType *ttype, String_or_char *tname) {
|
SwigType *ttype, String_or_char *tname) {
|
||||||
|
|
||||||
String *key;
|
char *key;
|
||||||
TypeMap *tm, *tk, *tn;
|
TypeMap *tm;
|
||||||
|
|
||||||
/* Try to locate a previous typemap */
|
/* Try to locate a previous typemap */
|
||||||
|
if (!typemap_lang || (strcmp(typemap_lang,lang))) return;
|
||||||
|
|
||||||
key = typemap_string(op,lang,stype,sname);
|
key = typemap_string(op,stype,sname);
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
if (!tm) return;
|
if (!tm) return;
|
||||||
typemap_register(op,lang,ttype,tname,tm->code,tm->args);
|
typemap_register(op,lang,ttype,tname,tm->code,tm->args);
|
||||||
|
|
@ -797,9 +751,9 @@ void typemap_copy(char *op, char *lang, SwigType *stype, String_or_char *sname,
|
||||||
* This string is used as the key for our typemap hash table.
|
* This string is used as the key for our typemap hash table.
|
||||||
* ------------------------------------------------------------------------ */
|
* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
static char *fragment_string(char *op, char *lang) {
|
static char *fragment_string(char *op) {
|
||||||
static char str[512];
|
static char str[512];
|
||||||
sprintf(str,"fragment:%s%s", lang, op);
|
sprintf(str,"fragment:%s", op);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -815,8 +769,10 @@ void fragment_register(char *op, char *lang, String_or_char *code) {
|
||||||
TypeMap *tm,*tm_old;
|
TypeMap *tm,*tm_old;
|
||||||
char temp[256];
|
char temp[256];
|
||||||
|
|
||||||
|
if (!typemap_lang || (strcmp(typemap_lang,lang))) return;
|
||||||
|
|
||||||
tm = new TypeMap(lang,code);
|
tm = new TypeMap(lang,code);
|
||||||
key = fragment_string(op,lang);
|
key = fragment_string(op);
|
||||||
|
|
||||||
/* Get any previous setting of the typemap */
|
/* Get any previous setting of the typemap */
|
||||||
|
|
||||||
|
|
@ -862,11 +818,10 @@ char *fragment_lookup(char *op, char *lang) {
|
||||||
char *key = 0;
|
char *key = 0;
|
||||||
TypeMap *tm = 0;
|
TypeMap *tm = 0;
|
||||||
|
|
||||||
if (!lang) {
|
if (!typemap_lang || (strcmp(typemap_lang,lang))) return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
str = NewString("");
|
str = NewString("");
|
||||||
key = fragment_string(op,lang);
|
key = fragment_string(op);
|
||||||
tm = typemap_search(key,type_id);
|
tm = typemap_search(key,type_id);
|
||||||
|
|
||||||
if (!tm) return 0;
|
if (!tm) return 0;
|
||||||
|
|
@ -888,7 +843,9 @@ void fragment_clear(char *op, char *lang) {
|
||||||
char *key;
|
char *key;
|
||||||
TypeMap *tm;
|
TypeMap *tm;
|
||||||
|
|
||||||
key = fragment_string(op,lang);
|
if (!typemap_lang || (strcmp(typemap_lang,lang))) return;
|
||||||
|
|
||||||
|
key = fragment_string(op);
|
||||||
|
|
||||||
/* Look for any previous version, simply set the last id if
|
/* Look for any previous version, simply set the last id if
|
||||||
applicable. */
|
applicable. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue