[allegrocl] Make type and namespace wrapping more compatible with other modules. cpp test-suite work.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10878 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Mikel Bancroft 2008-09-22 18:41:10 +00:00
commit e88b502bab
5 changed files with 178 additions and 88 deletions

View file

@ -1,6 +1,17 @@
2008-09-22 Mikel Bancroft <mikel@franz.com>
Version 1.3.37 (in progress)
=============================
2008-09-22: mutandiz (Mikel Bancroft)
[allegrocl]
- Support wrapping of types whose definitions are not seen by
SWIG. They are treated as forward-referenced classes and if a
definition is not seen are treated as (* :void).
- Don't wrap the contents of unnamed namespaces.
- More code cleanup. Removed some extraneous warnings.
- start work on having the allegrocl mod pass the cpp test-suite.
2008-09-19: olly
[PHP5] Add typemaps for long long and unsigned long long.

View file

@ -9,21 +9,40 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
# these cpp tests generate warnings/errors when compiling
# the wrapper .cxx file.
CPP_TEST_BROKEN_CXX = \
# might be a problem in our cxx wrapping. not sure. \
class_scope_weird \
# works as expected. must muffle warnings if you want none. \
# 'struct A' is not seen by SWIG, so it's type cannot be \
# derived \
# Look into cxx problems, though.
constant_pointers
# these cpp tests aren't working. Fix 'em
# need to further separate these into tests requiring
# std libraries, or the $ldestructor problem.
CPP_TEST_BROKEN_ACL = \
array_member \
# seems like a problem with the .i file. not enough includes. \
char_strings \
# not sure what this one is supposed to do. needs investigation. \
class_ignore \
constant_pointers \
contract \
# 'throws' typemap entries. \
cplusplus_throw \
# not sure. \
cpp_basic \
# redefinition of enum_members. Looks like a namespace problem. \
cpp_enum \
# works as expected. Bar is not seen by swig. muffle warning. \
cpp_typedef \
default_constructor \
# 'throws' typemap entries. \
default_args \
default_constructor \
dynamic_cast \
enum_thorough \
extend_variable \
@ -91,7 +110,13 @@ CPP_TEST_BROKEN_LONGLONG = \
# These are currently unsupported.
CPP_TEST_CASES_ACL_UNSUPPORTED = \
# contract support \
aggregate \
# directors and allprotected support \
allprotected \
# directors support \
apply_signed_char \
# contract support \
contract \
director_abstract \
director_basic \
@ -130,7 +155,7 @@ SKIP_CPP_STD_CASES = Yes
C_TEST_CASES =
CPP_TEST_CASES =
CPP_TEST_CASES =
include $(srcdir)/../common.mk

View file

@ -9,6 +9,12 @@ below.
%warnfilter(SWIGWARN_TYPEMAP_VARIN_UNDEF) global_char_array1; // Unable to set variable of type char[]
%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) global_const_char; // Setting a const char * variable may leak memory.
#ifdef SWIG_ALLEGRO_CL
%{
#include <stdio.h>
%}
#endif
%{
#define OTHERLAND_MSG "Little message from the safe world."
#define CPLUSPLUS_MSG "A message from the deep dark world of C++, where anything is possible."

View file

@ -55,7 +55,7 @@
int, signed int, unsigned int,
long, signed long, unsigned long,
float, double, long double, char *, void *, void,
enum SWIGTYPE, SWIGTYPE *,
enum SWIGTYPE, SWIGTYPE *, SWIGTYPE[],
SWIGTYPE[ANY], SWIGTYPE & "$1_ltype";
%typemap(ctype) SWIGTYPE "$&1_type";
@ -65,7 +65,7 @@
int, signed int, unsigned int,
long, signed long, unsigned long,
float, double, long double, char *, void *, void,
enum SWIGTYPE, SWIGTYPE *,
enum SWIGTYPE, SWIGTYPE *, SWIGTYPE[],
SWIGTYPE[ANY], SWIGTYPE & "$1 = $input;";
%typemap(in) SWIGTYPE "$1 = *$input;";

View file

@ -170,6 +170,7 @@ static String *namespace_of(String *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);
Swig_print_node(n);
#endif
if (!first_linked_type) {
first_linked_type = n;
@ -299,7 +300,8 @@ void add_forward_referenced_type(Node *n, int overwrite = 0) {
}
}
void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, String *name = 0, String *ns = current_namespace) {
void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
String *name = 0, String *ns = current_namespace) {
String *val;
String *ns_list = listify_namespace(ns);
@ -323,22 +325,34 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, String
/*
For typedefs of the form:
typedef __xxx { ... } xxx;
typedef struct __xxx { ... } xxx;
behavior differs between C mode and C++ mode.
C Mode:
add_defined_foreign_type will be called once via classHandler
to define the type for 'struct __xxx', and once via typedefHandler
to associate xxx with 'struct __xxx'.
to define the type for 'struct __xxx' and add the mapping from
'struct __xxx' -> 'xxx'
We create the following type to identifier mappings:
It will also be called once via typedefHandler to add the
mapping 'xxx' -> 'xxx'
struct __xxx -> (swig-insert-id "xxx") via classHand
xxx -> (swig-insert-id "xxx") via typedefHand
C++ Mode:
add_defined_foreign_type will be called once via classHandler
to define the type for 'xxx'. it also adds the mapping from
'xxx' -> 'xxx' and also for 'struct xxx' -> 'xxx'
and all references to this typedef'd struct will appear in
generated code as 'xxx'. For non-typedef'd structs, the
classHand mapping will be
In typedefHandler, we again try to add the mapping from
'xxx' -> 'xxx', which already exists. This second mapping
is ignored.
struct __xxx -> (swig-insert-id "__xxx")
Both modes:
All references to this typedef'd struct will appear in
generated lisp code as an objectd of type 'xxx'. For
non-typedef'd structs, the classHand mapping will be
struct __xxx -> (swig-insert-id "__xxx")
*/
// Swig_print_node(n);
String *unnamed = Getattr(n, "unnamed");
@ -587,7 +601,11 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, String
Delete(mangled_name_gen);
Delete(mangled_lname_gen);
} else {
Swig_warning(WARN_TYPE_REDEFINED, Getfile(n), Getline(n), "Attempting to store a foreign type that exists: %s (%s)\n", k, val);
if (!CPlusPlus || Strcmp(Getattr(n,"kind"),"typedef")) {
Swig_warning(WARN_TYPE_REDEFINED, Getfile(n), Getline(n),
"Attempting to store a foreign type that exists: %s (%s)\n",
k, val);
}
}
Delete(ns_list);
@ -622,7 +640,8 @@ String *get_ffi_type(SwigType *ty, const String_or_char *name) {
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "found_type '%s'\n", found_type);
#endif
return (Strcmp(found_type, "forward-reference") ? Copy(found_type) : NewString(":void"));
return (Strcmp(found_type, "forward-reference") ? Copy(found_type) :
get_ffi_type(fwdref_ffi_type, ""));
} else {
Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0);
@ -709,25 +728,39 @@ String *internal_compose_foreign_type(SwigType *ty) {
if (res)
Printf(ffiType, "%s", res);
}
// while(resolved_type) {
// // the resolved_type may expand into something like p.NS1::NS2::SomeType
// // for which get_ffi_type will not find any match (due to the p.).
// // Printf(stderr, "\n in resolved type loop on '%s'\n", resolved_type);
// res = get_ffi_type(resolved_type, "");
// if (res) {
// Printf(ffiType, "%s", res);
// break;
// } else {
// resolved_type = SwigType_typedef_resolve(resolved_type);
// }
// }
if (!res) {
if (Strstr(tok, "struct ")) {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(tok), Getline(tok), "Unable to find definition of '%s', assuming forward reference.\n", tok);
} else {
Printf(stderr, "Unable to compose foreign type of: '%s'\n", tok);
String *is_struct = 0;
String *tok_remove_text = 0;
String *tok_name = Copy(tok);
String *tok_key = SwigType_str(tok,0);
if ((is_struct = Strstr(tok_key, "struct ")) || Strstr(tok_key, "union ")) {
tok_remove_text = NewString(is_struct ? "struct " : "union ");
}
Printf(ffiType, "%s", get_ffi_type(fwdref_ffi_type, ""));
/* be more permissive of opaque types. This is the swig way.
compiles will notice if these types are ultimately not
present. */
if(tok_remove_text) {
Replaceall(tok_name,tok_remove_text,"");
}
tok_name = strip_namespaces(tok_name);
Delete(tok_remove_text);
// Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(tok), Getline(tok), "Unable to find definition of '%s', assuming forward reference.\n", tok);
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "i-c-f-t: adding forward reference for unknown type '%s'. mapping: %s -> %s\n", tok, tok_key, tok_name);
#endif
Node *nn = NewHash();
Setattr(nn,"nodeType","classforward");
Setattr(nn,"kind","class");
Setattr(nn,"sym:name",tok_name);
Setattr(nn,"name",tok_key);
Setattr(nn,"allegrocl:package","current_namespace");
add_forward_referenced_type(nn, 0);
Printf(ffiType, "%s", get_ffi_type(tok, ""), tok_name);
}
}
}
@ -841,6 +874,10 @@ String *strip_parens(String *string) {
}
int ALLEGROCL::validIdentifier(String *s) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "validIdentifier %s\n", s);
#endif
char *c = Char(s);
bool got_dot = false;
@ -967,6 +1004,7 @@ String *convert_literal(String *literal, String *type, bool try_to_split) {
Delete(num);
num = 0;
}
Delete(lisp_exp);
} else {
String *id = NewStringf("#.(swig-insert-id \"%s\" %s :type :constant)",
num, ns);
@ -2354,41 +2392,24 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
for (p = pl; p; p = nextSibling(p), argnum++, largnum++) {
// SwigType *argtype=Getattr(p, "type");
SwigType *argtype = Swig_cparse_type(Getattr(p, "tmap:ctype"));
SwigType *parmtype = Getattr(p,"type");
if (!first) {
Printf(fcl, "\n ");
}
if (SwigType_isvarargs(argtype)) {
Printf(stderr, "Function %s (line %d) contains varargs, which is not directly supported. Use %%varargs instead.\n", Getattr(n, "name"), Getline(n));
} else {
/* by default, skip varargs */
if (!SwigType_isvarargs(parmtype)) {
String *argname = NewStringf("PARM%d_%s", largnum, Getattr(p, "name"));
// Swig_print_node(p);
// Printf(stderr,"%s\n", Getattr(p,"tmap:lin"));
String *ffitype = compose_foreign_type(argtype, Getattr(p,"name"));
String *deref_ffitype;
deref_ffitype = dereference_ffitype(ffitype);
/*
String *temp = Copy(argtype);
if (SwigType_ispointer(temp)) {
SwigType_pop(temp);
deref_ffitype = compose_foreign_type(temp);
} else {
deref_ffitype = Copy(ffitype);
}
Delete(temp);
*/
// String *lisptype=get_lisp_type(argtype, argname);
String *lisptype = get_lisp_type(Getattr(p, "type"), Getattr(p, "name"));
String *deref_ffitype = dereference_ffitype(ffitype);
String *lisptype = get_lisp_type(parmtype, Getattr(p, "name"));
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "lisptype of '%s' '%s' = '%s'\n",
Getattr(p, "type"), Getattr(p, "name"), lisptype);
Printf(stderr, "lisptype of '%s' '%s' = '%s'\n", parmtype,
Getattr(p, "name"), lisptype);
#endif
// while we're walking the parameters, generating LIN
@ -2419,7 +2440,9 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
first = 0;
}
Delete(argname);
Delete(ffitype);
Delete(deref_ffitype);
Delete(lisptype);
}
}
@ -2457,11 +2480,6 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
lclass = lookup_defined_foreign_ltype(cl_t);
isPtrReturn = 1;
}
// if (SwigType_ispointer(cl_t)) {
// isPtrReturn = 1;
// SwigType_pop(cl_t);
// lclass = lookup_defined_foreign_ltype(cl_t);
// }
int ff_foreign_ptr = 0;
if (!lclass) {
@ -2534,6 +2552,10 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
}
int ALLEGROCL::functionWrapper(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "functionWrapper %s\n", Getattr(n,"name"));
#endif
ParmList *parms = CopyParmList(Getattr(n, "parms"));
Wrapper *f = NewWrapper();
@ -2694,13 +2716,15 @@ int ALLEGROCL::functionWrapper(Node *n) {
}
int ALLEGROCL::namespaceDeclaration(Node *n) {
// Empty namespaces are not worth DEFPACKAGEing.
// Swig_print_node(n);
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "namespaceDecl: '%s'(0x%x) (fc=0x%x)\n", Getattr(n, "sym:name"), n, firstChild(n));
#endif
if (!firstChild(n))
/* don't wrap a namespace with no contents. package bloat.
also, test-suite/namespace_class.i claims an unnamed namespace
is 'private' and should not be wrapped. Complying...
*/
if (Getattr(n,"unnamed") || !firstChild(n))
return SWIG_OK;
String *name = Getattr(n, "sym:name");
@ -2727,7 +2751,7 @@ int ALLEGROCL::namespaceDeclaration(Node *n) {
int ALLEGROCL::constructorHandler(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "constructor %s\n", Getattr(n, "name"));
Printf(stderr, "constructorHandler %s\n", Getattr(n, "name"));
#endif
// Swig_print_node(n);
Setattr(n, "allegrocl:kind", "constructor");
@ -2739,7 +2763,7 @@ int ALLEGROCL::constructorHandler(Node *n) {
int ALLEGROCL::destructorHandler(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "destructor %s\n", Getattr(n, "name"));
Printf(stderr, "destructorHandler %s\n", Getattr(n, "name"));
#endif
Setattr(n, "allegrocl:kind", "destructor");
@ -2750,9 +2774,8 @@ int ALLEGROCL::destructorHandler(Node *n) {
}
int ALLEGROCL::constantWrapper(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "constant %s\n", Getattr(n, "name"));
Printf(stderr, "constantWrapper %s\n", Getattr(n, "name"));
#endif
if (Generate_Wrapper) {
@ -2808,6 +2831,10 @@ int ALLEGROCL::constantWrapper(Node *n) {
}
int ALLEGROCL::globalvariableHandler(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "globalvariableHandler %s\n", Getattr(n, "name"));
#endif
if (Generate_Wrapper)
return Language::globalvariableHandler(n);
@ -2838,7 +2865,7 @@ int ALLEGROCL::globalvariableHandler(Node *n) {
int ALLEGROCL::variableWrapper(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "variable %s\n", Getattr(n, "name"));
Printf(stderr, "variableWrapper %s\n", Getattr(n, "name"));
#endif
Setattr(n, "allegrocl:kind", "variable");
Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name"));
@ -2863,6 +2890,7 @@ int ALLEGROCL::variableWrapper(Node *n) {
}
ctype = SwigType_str(type, 0);
// EXPORT <SwigType_str> <mangled_name>;
// <SwigType_str> <mangled_name> = <name>;
Printf(f_cxx, "EXPORT %s %s;\n%s %s = %s%s;\n", ctype, mangled_name, ctype, mangled_name, (pointer_added ? "&" : ""), name);
@ -2873,14 +2901,19 @@ int ALLEGROCL::variableWrapper(Node *n) {
Printf(f_cxx, "// vwrap: %s\n", compose_foreign_type(SwigType_strip_qualifiers(Copy(rtype))));
*/
Printf(stderr,"***\n");
Delete(mangled_name);
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "DONE variable %s\n", Getattr(n, "name"));
#endif
return SWIG_OK;
}
int ALLEGROCL::memberfunctionHandler(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "member function %s::%s\n", Getattr(parent_node_skipping_extends(n), "name"), Getattr(n, "name"));
Printf(stderr, "memberfunctionHandler %s::%s\n", Getattr(parent_node_skipping_extends(n), "name"), Getattr(n, "name"));
#endif
Setattr(n, "allegrocl:kind", "member function");
Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name"));
@ -2891,7 +2924,7 @@ int ALLEGROCL::memberfunctionHandler(Node *n) {
int ALLEGROCL::membervariableHandler(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "member variable %s::%s\n", Getattr(parent_node_skipping_extends(n), "name"), Getattr(n, "name"));
Printf(stderr, "membervariableHandler %s::%s\n", Getattr(parent_node_skipping_extends(n), "name"), Getattr(n, "name"));
#endif
Setattr(n, "allegrocl:kind", "member variable");
Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name"));
@ -2901,9 +2934,8 @@ int ALLEGROCL::membervariableHandler(Node *n) {
}
int ALLEGROCL::typedefHandler(Node *n) {
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "In typedefHAND\n");
Printf(stderr, "In typedefHandler\n");
// Swig_print_node(n);
#endif
@ -2945,7 +2977,7 @@ int ALLEGROCL::typedefHandler(Node *n) {
else add_forward_referenced_type(n);
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "Out typedefHAND\n");
Printf(stderr, "Out typedefHandler\n");
#endif
Delete(ff_type);
@ -2955,13 +2987,17 @@ int ALLEGROCL::typedefHandler(Node *n) {
// forward referenced classes are added specially to defined_foreign_types
int ALLEGROCL::classforwardDeclaration(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "classforwardDeclaration %s\n", Getattr(n, "name"));
#endif
add_forward_referenced_type(n);
return SWIG_OK;
}
int ALLEGROCL::classHandler(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "class %s::%s\n", current_namespace, Getattr(n, "sym:name"));
Printf(stderr, "classHandler %s::%s\n", current_namespace, Getattr(n, "sym:name"));
#endif
if (Generate_Wrapper)
@ -2971,6 +3007,9 @@ int ALLEGROCL::classHandler(Node *n) {
}
int ALLEGROCL::cClassHandler(Node *n) {
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "In cClassHandler\n");
#endif
// String *cDeclName = Getattr(n,"classDeclaration:name");
// String *name= Getattr(n, "sym:name");
// String *kind = Getattr(n,"kind");
@ -2980,22 +3019,21 @@ int ALLEGROCL::cClassHandler(Node *n) {
// Printf(stderr, "Adding %s foreign type\n", name);
String *ns = listify_namespace(current_namespace);
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "In cClassHAND\n");
#endif
add_defined_foreign_type(n);
Delete(ns);
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "Out cClassHAND\n");
Printf(stderr, "Out cClassHandler\n");
#endif
return SWIG_OK;
}
int ALLEGROCL::cppClassHandler(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "cppClassHandler %s\n", Getattr(n, "name"));
#endif
// String *name=Getattr(n, "sym:name");
// String *kind = Getattr(n,"kind");
@ -3054,6 +3092,10 @@ int ALLEGROCL::cppClassHandler(Node *n) {
// so their types can be added to the linked_type_list.
SwigType *childType = NewStringf("%s%s", Getattr(c, "decl"),
Getattr(c, "type"));
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "looking at child '%x' of type '%s'\n", c, childType);
Swig_print_node(c);
#endif
if (!SwigType_isfunction(childType))
Delete(compose_foreign_type(childType));
@ -3094,6 +3136,9 @@ int ALLEGROCL::emit_one(Node *n) {
}
int ALLEGROCL::enumDeclaration(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "enumDeclaration %s\n", Getattr(n, "name"));
#endif
if (Getattr(n, "sym:name")) {
add_defined_foreign_type(n);
@ -3110,21 +3155,24 @@ int ALLEGROCL::enumDeclaration(Node *n) {
int ALLEGROCL::enumvalueDeclaration(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "enumvalueDeclaration %s\n", Getattr(n, "name"));
#endif
/* print this when in C mode? make this a command-line arg? */
if (Generate_Wrapper) {
String *mangled_name = mangle_name(n, "ACL_ENUM");
Printf(f_cxx, "EXPORT const %s %s = %s;\n", Getattr(n, "type"), mangled_name, Getattr(n, "value"));
Printf(f_cxx, "EXPORT const %s %s = %s;\n", Getattr(n, "type"),
mangled_name, Getattr(n, "value"));
Delete(mangled_name);
}
return SWIG_OK;
}
int ALLEGROCL::templateDeclaration(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "templateDeclaration %s\n", Getattr(n, "name"));
#endif
String *type = Getattr(n, "templatetype");