Use *swig-identifier-converter*.
Derive proper foreign types for all pointer types rather than using (* :void). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7332 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
9148f0cb38
commit
81486b9fe0
1 changed files with 55 additions and 37 deletions
|
|
@ -128,45 +128,64 @@ static void add_defined_foreign_type(String *type) {
|
||||||
static String *get_ffi_type(SwigType *ty, const String_or_char *name) {
|
static String *get_ffi_type(SwigType *ty, const String_or_char *name) {
|
||||||
Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0);
|
Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0);
|
||||||
if (typemap) {
|
if (typemap) {
|
||||||
String *typespec = Getattr(typemap, "code");
|
String *typespec = Getattr(typemap, "code");
|
||||||
return NewString(typespec);
|
return NewString(typespec);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SwigType *tr=SwigType_typedef_resolve_all(ty);
|
List *elements;
|
||||||
char *type_reduced=Char(tr);
|
int nelements, i;
|
||||||
int i;
|
String *head = NewString("");
|
||||||
|
String *tail = NewString("");
|
||||||
//Printf(stdout,"convert_type %s\n", ty);
|
String *base_type;
|
||||||
if (SwigType_isconst(tr)) {
|
do {
|
||||||
SwigType_pop(tr);
|
elements = SwigType_split(ty);
|
||||||
type_reduced=Char(tr);
|
nelements = Len(elements);
|
||||||
}
|
for (i = 0; i<nelements - 1; i++) {
|
||||||
|
String *element = Getitem(elements, i);
|
||||||
if (SwigType_ispointer(type_reduced) || SwigType_isarray(ty) ||
|
if (SwigType_isqualifier(element)) {
|
||||||
!strncmp(type_reduced, "p.f", 3)) {
|
/* discard qualifiers */
|
||||||
#if 1
|
}
|
||||||
return NewString("(* :void)");
|
else if (SwigType_ispointer(element)
|
||||||
#else
|
|| SwigType_isarray(element)) {
|
||||||
return NewString(":foreign-address");
|
Append(head, "(* ");
|
||||||
|
Insert(tail, 0, ")");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* unknown complicated type, so use void * */
|
||||||
|
return NewString("(* :void)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base_type = Getitem(elements, nelements - 1);
|
||||||
|
ty = SwigType_typedef_resolve_all(base_type);
|
||||||
|
} while (Cmp(ty, base_type) != 0);
|
||||||
|
#if 0
|
||||||
|
Printf(stdout, "Basetype: %s\n", base_type);
|
||||||
#endif
|
#endif
|
||||||
}
|
Hash *typemap = Swig_typemap_search("ffitype", base_type, NIL, 0);
|
||||||
|
if (typemap) {
|
||||||
for(i=0; i<defined_foreign_types.count; i++) {
|
String *typespec = Getattr(typemap, "code");
|
||||||
if (!Strcmp(ty, defined_foreign_types.entries[i])) {
|
return NewStringf("%s%s%s", head, typespec, tail);
|
||||||
return NewStringf("#.(%s \"%s\" :type :type)",
|
}
|
||||||
identifier_converter,
|
else {
|
||||||
ty);
|
int i;
|
||||||
}
|
char *bt = Char(base_type);
|
||||||
}
|
if ((strncmp(bt,"struct ", 7) == 0) ||
|
||||||
|
((strncmp(bt,"class ", 6) == 0)) ||
|
||||||
if (!Strncmp(type_reduced, "enum ", 5)) {
|
((strncmp(bt,"union ", 6) == 0))) {
|
||||||
return NewString(":int");
|
bt = strchr(bt, ' ')+1;
|
||||||
}
|
}
|
||||||
|
for (i=0; i<defined_foreign_types.count; i++) {
|
||||||
Printf(stderr, "Unsupported data type: %s (was: %s)\n", type_reduced, ty);
|
if (!Strcmp(bt, defined_foreign_types.entries[i])) {
|
||||||
SWIG_exit(EXIT_FAILURE);
|
return NewStringf("%s#.(funcall *swig-identifier-converter* \"%s\" :type :type)%s",
|
||||||
|
head,
|
||||||
|
bt,
|
||||||
|
tail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Unknown */
|
||||||
|
return NewString("(* :void)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static String *get_lisp_type(SwigType *ty, const String_or_char *name)
|
static String *get_lisp_type(SwigType *ty, const String_or_char *name)
|
||||||
|
|
@ -376,8 +395,7 @@ int ALLEGROCL :: classDeclaration(Node *n) {
|
||||||
lisp_type=get_ffi_type(type, Getattr(c, "sym:name"));
|
lisp_type=get_ffi_type(type, Getattr(c, "sym:name"));
|
||||||
|
|
||||||
Printf(f_cl,
|
Printf(f_cl,
|
||||||
" (#.(%s \"%s\" :type :slot) %s)\n",
|
" (#.(funcall *swig-identifier-converter* \"%s\" :type :slot) %s)\n",
|
||||||
identifier_converter,
|
|
||||||
Getattr(c, "sym:name"),
|
Getattr(c, "sym:name"),
|
||||||
lisp_type);
|
lisp_type);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue