merge revisions 11243-11872 from trunk to gsoc2009-matevz

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12162 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-07-20 21:58:41 +00:00
commit ab1cd03979
387 changed files with 12383 additions and 4412 deletions

View file

@ -57,7 +57,7 @@ extern "C" {
extern void Swig_cparse_replace_descriptor(String *s);
extern void cparse_normalize_void(Node *);
extern Parm *Swig_cparse_parm(String *s);
extern ParmList *Swig_cparse_parms(String *s);
extern ParmList *Swig_cparse_parms(String *s, Node *file_line_node);
/* templ.c */

View file

@ -139,7 +139,7 @@ static void scanner_locator(String *loc) {
break;
Putc(c, fn);
}
/* Printf(stderr,"location: %s:%d\n",cparse_file,cparse_line); */
/* Swig_diagnostic(cparse_file, cparse_line, "Scanner_set_location\n"); */
Scanner_set_location(scan,cparse_file,cparse_line);
Delete(fn);
}
@ -261,7 +261,7 @@ void skip_decl(void) {
* Lexical scanner.
* ------------------------------------------------------------------------- */
int yylook(void) {
static int yylook(void) {
int tok = 0;
@ -416,6 +416,9 @@ int yylook(void) {
case SWIG_TOKEN_FLOAT:
return NUM_FLOAT;
case SWIG_TOKEN_BOOL:
return NUM_BOOL;
case SWIG_TOKEN_POUND:
Scanner_skip_line(scan);
yylval.id = Swig_copy_string(Char(Scanner_text(scan)));
@ -505,7 +508,7 @@ int yylex(void) {
l = yylook();
/* Printf(stdout, "%s:%d:::%d: '%s'\n", cparse_file, cparse_line, l, Scanner_text(scan)); */
/* Swig_diagnostic(cparse_file, cparse_line, ":::%d: '%s'\n", l, Scanner_text(scan)); */
if (l == NONID) {
last_id = 1;
@ -531,6 +534,7 @@ int yylex(void) {
case NUM_UNSIGNED:
case NUM_LONGLONG:
case NUM_ULONGLONG:
case NUM_BOOL:
if (l == NUM_INT)
yylval.dtype.type = T_INT;
if (l == NUM_FLOAT)
@ -545,6 +549,8 @@ int yylex(void) {
yylval.dtype.type = T_LONGLONG;
if (l == NUM_ULONGLONG)
yylval.dtype.type = T_ULONGLONG;
if (l == NUM_BOOL)
yylval.dtype.type = T_BOOL;
yylval.dtype.val = NewString(Scanner_text(scan));
yylval.dtype.bitfield = 0;
yylval.dtype.throws = 0;

File diff suppressed because it is too large Load diff

View file

@ -266,7 +266,7 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab
/* Look for partial specialization matching */
if (Getattr(n, "partialargs")) {
Parm *p, *tp;
ParmList *ptargs = SwigType_function_parms(Getattr(n, "partialargs"));
ParmList *ptargs = SwigType_function_parms(Getattr(n, "partialargs"), n);
p = ptargs;
tp = tparms;
while (p && tp) {
@ -426,6 +426,70 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab
return 0;
}
typedef enum { ExactNoMatch = -2, PartiallySpecializedNoMatch = -1, PartiallySpecializedMatch = 1, ExactMatch = 2 } EMatch;
/* -----------------------------------------------------------------------------
* does_parm_match()
*
* Template argument deduction - check if a template type matches a partially specialized
* template parameter type. Reduce 'partial_parm_type' to see if it matches 'type'.
*
* type - template parameter type to match against
* partial_parm_type - partially specialized template type - a possible match
* partial_parm_type_base - base type of partial_parm_type
* tscope - template scope
* specialization_priority - (output) contains a value indicating how good the match is
* (higher is better) only set if return is set to PartiallySpecializedMatch or ExactMatch.
* ----------------------------------------------------------------------------- */
static EMatch does_parm_match(SwigType *type, SwigType *partial_parm_type, const char *partial_parm_type_base, Symtab *tscope, int *specialization_priority) {
static const int EXACT_MATCH_PRIORITY = 99999; /* a number bigger than the length of any conceivable type */
int matches;
int substitutions;
EMatch match;
SwigType *ty = Swig_symbol_typedef_reduce(type, tscope);
String *base = SwigType_base(ty);
SwigType *t = Copy(partial_parm_type);
substitutions = Replaceid(t, partial_parm_type_base, base); /* eg: Replaceid("p.$1", "$1", "int") returns t="p.int" */
matches = Equal(ty, t);
*specialization_priority = -1;
if (substitutions == 1) {
/* we have a non-explicit specialized parameter (in partial_parm_type) because a substitution for $1, $2... etc has taken place */
SwigType *tt = Copy(partial_parm_type);
int len;
/*
check for match to partial specialization type, for example, all of the following could match the type in the %template:
template <typename T> struct XX {};
template <typename T> struct XX<T &> {}; // r.$1
template <typename T> struct XX<T const&> {}; // r.q(const).$1
template <typename T> struct XX<T *const&> {}; // r.q(const).p.$1
%template(XXX) XX<int *const&>; // r.q(const).p.int
where type="r.q(const).p.int" will match either of tt="r.", tt="r.q(const)" tt="r.q(const).p"
*/
Replaceid(tt, partial_parm_type_base, ""); /* remove the $1, $2 etc, eg tt="p.$1" => "p." */
len = Len(tt);
if (Strncmp(tt, ty, len) == 0) {
match = PartiallySpecializedMatch;
*specialization_priority = len;
} else {
match = PartiallySpecializedNoMatch;
}
Delete(tt);
} else {
match = matches ? ExactMatch : ExactNoMatch;
if (matches)
*specialization_priority = EXACT_MATCH_PRIORITY; /* exact matches always take precedence */
}
/*
Printf(stdout, " does_parm_match %2d %5d [%s] [%s]\n", match, *specialization_priority, type, partial_parm_type);
*/
Delete(t);
Delete(base);
Delete(ty);
return match;
}
/* -----------------------------------------------------------------------------
* template_locate()
*
@ -433,175 +497,294 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab
* ----------------------------------------------------------------------------- */
static Node *template_locate(String *name, Parm *tparms, Symtab *tscope) {
Node *n;
String *tname, *rname = 0;
Node *n = 0;
String *tname = 0;
Node *templ;
List *mpartials = 0;
Symtab *primary_scope = 0;
List *possiblepartials = 0;
Parm *p;
Parm *parms;
Parm *parms = 0;
Parm *targs;
ParmList *expandedparms;
int *priorities_matrix = 0;
int max_possible_partials = 0;
int posslen = 0;
tname = Copy(name);
parms = CopyParmList(tparms);
/* Search for generic template */
/* Search for primary (unspecialized) template */
templ = Swig_symbol_clookup(name, 0);
/* Add default values from generic template */
if (templ) {
Symtab *tsdecl = Getattr(templ, "sym:symtab");
if (template_debug) {
tname = Copy(name);
SwigType_add_template(tname, tparms);
Printf(stdout, "\n");
Swig_diagnostic(cparse_file, cparse_line, "template_debug: Searching for match to: '%s'\n", tname);
Delete(tname);
tname = 0;
}
if (templ) {
tname = Copy(name);
parms = CopyParmList(tparms);
/* All template specializations must be in the primary template's scope, store the symbol table for this scope for specialization lookups */
primary_scope = Getattr(templ, "sym:symtab");
/* Add default values from primary template */
targs = Getattr(templ, "templateparms");
expandedparms = Swig_symbol_template_defargs(parms, targs, tscope, tsdecl);
} else {
expandedparms = parms;
}
expandedparms = Swig_symbol_template_defargs(parms, targs, tscope, primary_scope);
/* reduce the typedef */
p = expandedparms;
while (p) {
SwigType *ty = Getattr(p, "type");
if (ty) {
SwigType *nt = Swig_symbol_type_qualify(ty, tscope);
Setattr(p, "type", nt);
Delete(nt);
}
p = nextSibling(p);
}
SwigType_add_template(tname, expandedparms);
if (template_debug) {
Printf(stdout, "\n%s:%d: template_debug: Searching for %s\n", cparse_file, cparse_line, tname);
}
/* Search for an exact specialization.
Example: template<> class name<int> { ... } */
{
if (template_debug) {
Printf(stdout, " searching: '%s' (exact specialization)\n", tname);
}
n = Swig_symbol_clookup_local(tname, 0);
if (!n) {
SwigType *rname = Swig_symbol_typedef_reduce(tname, tscope);
if (!Equal(rname, tname)) {
if (template_debug) {
Printf(stdout, " searching: '%s' (exact specialization)\n", rname);
}
n = Swig_symbol_clookup_local(rname, 0);
/* reduce the typedef */
p = expandedparms;
while (p) {
SwigType *ty = Getattr(p, "type");
if (ty) {
SwigType *nt = Swig_symbol_type_qualify(ty, tscope);
Setattr(p, "type", nt);
Delete(nt);
}
Delete(rname);
p = nextSibling(p);
}
if (n) {
Node *tn;
String *nodeType = nodeType(n);
if (Equal(nodeType, "template"))
goto success;
tn = Getattr(n, "template");
if (tn) {
n = tn;
goto success; /* Previously wrapped by a template return that */
SwigType_add_template(tname, expandedparms);
/* Search for an explicit (exact) specialization. Example: template<> class name<int> { ... } */
{
if (template_debug) {
Printf(stdout, " searching for : '%s' (explicit specialization)\n", tname);
}
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType(n));
Delete(tname);
Delete(parms);
return 0; /* Found a match, but it's not a template of any kind. */
}
}
/* Search for partial specialization.
Example: template<typename T> class name<T *> { ... } */
/* Generate reduced template name (stripped of extraneous pointers, etc.) */
rname = NewStringf("%s<(", name);
p = parms;
while (p) {
String *t;
t = Getattr(p, "type");
if (!t)
t = Getattr(p, "value");
if (t) {
String *ty = Swig_symbol_typedef_reduce(t, tscope);
String *tb = SwigType_base(ty);
String *td = SwigType_default(ty);
Replaceid(td, "enum SWIGTYPE", tb);
Replaceid(td, "SWIGTYPE", tb);
Append(rname, td);
Delete(tb);
Delete(ty);
Delete(td);
}
p = nextSibling(p);
if (p) {
Append(rname, ",");
}
}
Append(rname, ")>");
mpartials = NewList();
if (templ) {
/* First, we search using an exact type prototype */
Parm *p;
char tmp[32];
int i;
List *partials;
String *ss;
Iterator pi;
partials = Getattr(templ, "partials");
if (partials) {
for (pi = First(partials); pi.item; pi = Next(pi)) {
ss = Copy(pi.item);
p = parms;
i = 1;
while (p) {
String *t, *tn;
sprintf(tmp, "$%d", i);
t = Getattr(p, "type");
if (!t)
t = Getattr(p, "value");
if (t) {
String *ty = Swig_symbol_typedef_reduce(t, tscope);
tn = SwigType_base(ty);
Replaceid(ss, tmp, tn);
Delete(tn);
Delete(ty);
n = Swig_symbol_clookup_local(tname, primary_scope);
if (!n) {
SwigType *rname = Swig_symbol_typedef_reduce(tname, tscope);
if (!Equal(rname, tname)) {
if (template_debug) {
Printf(stdout, " searching for : '%s' (explicit specialization with typedef reduction)\n", rname);
}
i++;
p = nextSibling(p);
n = Swig_symbol_clookup_local(rname, primary_scope);
}
if (template_debug) {
Printf(stdout, " searching: '%s' (partial specialization - %s)\n", ss, pi.item);
}
if ((Equal(ss, tname)) || (Equal(ss, rname))) {
Append(mpartials, pi.item);
}
Delete(ss);
Delete(rname);
}
}
}
if (template_debug) {
Printf(stdout, " Matched partials: %s\n", mpartials);
}
if (Len(mpartials)) {
String *s = Getitem(mpartials, 0);
n = Swig_symbol_clookup_local(s, 0);
if (Len(mpartials) > 1) {
if (n) {
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, cparse_file, cparse_line, "Instantiation of template '%s' is ambiguous,\n", SwigType_namestr(tname));
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, Getfile(n), Getline(n), " instantiation '%s' is used.\n", SwigType_namestr(Getattr(n, "name")));
Node *tn;
String *nodeType = nodeType(n);
if (Equal(nodeType, "template")) {
if (template_debug) {
Printf(stdout, " explicit specialization found: '%s'\n", Getattr(n, "name"));
}
goto success;
}
tn = Getattr(n, "template");
if (tn) {
if (template_debug) {
Printf(stdout, " previous instantiation found: '%s'\n", Getattr(n, "name"));
}
n = tn;
goto success; /* Previously wrapped by a template instantiation */
}
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType(n));
Delete(tname);
Delete(parms);
return 0; /* Found a match, but it's not a template of any kind. */
}
}
/* Search for partial specializations.
* Example: template<typename T> class name<T *> { ... }
* There are 3 types of template arguments:
* (1) Template type arguments
* (2) Template non type arguments
* (3) Template template arguments
* only (1) is really supported for partial specializations
*/
/* Rank each template parameter against the desired template parameters then build a matrix of best matches */
possiblepartials = NewList();
{
char tmp[32];
List *partials;
partials = Getattr(templ, "partials"); /* note that these partial specializations do not include explicit specializations */
if (partials) {
Iterator pi;
int parms_len = ParmList_len(parms);
int *priorities_row;
max_possible_partials = Len(partials);
priorities_matrix = (int *)malloc(sizeof(int) * max_possible_partials * parms_len); /* slightly wasteful allocation for max possible matches */
priorities_row = priorities_matrix;
for (pi = First(partials); pi.item; pi = Next(pi)) {
Parm *p = parms;
int all_parameters_match = 1;
int i = 1;
Parm *partialparms = Getattr(pi.item, "partialparms");
Parm *pp = partialparms;
String *templcsymname = Getattr(pi.item, "templcsymname");
if (template_debug) {
Printf(stdout, " checking match: '%s' (partial specialization)\n", templcsymname);
}
if (ParmList_len(partialparms) == parms_len) {
while (p && pp) {
SwigType *t;
sprintf(tmp, "$%d", i);
t = Getattr(p, "type");
if (!t)
t = Getattr(p, "value");
if (t) {
EMatch match = does_parm_match(t, Getattr(pp, "type"), tmp, tscope, priorities_row + i - 1);
if (match < (int)PartiallySpecializedMatch) {
all_parameters_match = 0;
break;
}
}
i++;
p = nextSibling(p);
pp = nextSibling(pp);
}
if (all_parameters_match) {
Append(possiblepartials, pi.item);
priorities_row += parms_len;
}
}
}
}
}
posslen = Len(possiblepartials);
if (template_debug) {
int i;
if (posslen == 0)
Printf(stdout, " matched partials: NONE\n");
else if (posslen == 1)
Printf(stdout, " chosen partial: '%s'\n", Getattr(Getitem(possiblepartials, 0), "templcsymname"));
else {
Printf(stdout, " possibly matched partials:\n");
for (i = 0; i < posslen; i++) {
Printf(stdout, " '%s'\n", Getattr(Getitem(possiblepartials, i), "templcsymname"));
}
}
}
if (posslen > 1) {
/* Now go through all the possibly matched partial specialization templates and look for a non-ambiguous match.
* Exact matches rank the highest and deduced parameters are ranked by how much they are reduced, eg looking for
* a match to const int *, the following rank (highest to lowest):
* const int * (exact match)
* const T *
* T *
* T
*
* An ambiguous example when attempting to match as either specialization could match: %template() X<int *, double *>;
* template<typename T1, typename T2> X class {}; // primary template
* template<typename T1> X<T1, double *> class {}; // specialization (1)
* template<typename T2> X<int *, T2> class {}; // specialization (2)
*/
if (template_debug) {
int row, col;
int parms_len = ParmList_len(parms);
Printf(stdout, " parameter priorities matrix (%d parms):\n", parms_len);
for (row = 0; row < posslen; row++) {
int *priorities_row = priorities_matrix + row*parms_len;
Printf(stdout, " ");
for (col = 0; col < parms_len; col++) {
Printf(stdout, "%5d ", priorities_row[col]);
}
Printf(stdout, "\n");
}
}
{
int row, col;
int parms_len = ParmList_len(parms);
/* Printf(stdout, " parameter priorities inverse matrix (%d parms):\n", parms_len); */
for (col = 0; col < parms_len; col++) {
int *priorities_col = priorities_matrix + col;
int maxpriority = -1;
/*
Printf(stdout, "max_possible_partials: %d col:%d\n", max_possible_partials, col);
Printf(stdout, " ");
*/
/* determine the highest rank for this nth parameter */
for (row = 0; row < posslen; row++) {
int *element_ptr = priorities_col + row*parms_len;
int priority = *element_ptr;
if (priority > maxpriority)
maxpriority = priority;
/* Printf(stdout, "%5d ", priority); */
}
/* Printf(stdout, "\n"); */
/* flag all the parameters which equal the highest rank */
for (row = 0; row < posslen; row++) {
int *element_ptr = priorities_col + row*parms_len;
int priority = *element_ptr;
*element_ptr = (priority >= maxpriority) ? 1 : 0;
}
}
}
{
int row, col;
int parms_len = ParmList_len(parms);
Iterator pi = First(possiblepartials);
Node *chosenpartials = NewList();
if (template_debug)
Printf(stdout, " priority flags matrix:\n");
for (row = 0; row < posslen; row++) {
int *priorities_row = priorities_matrix + row*parms_len;
int highest_count = 0; /* count of highest priority parameters */
for (col = 0; col < parms_len; col++) {
highest_count += priorities_row[col];
}
if (template_debug) {
Printf(stdout, " ");
for (col = 0; col < parms_len; col++) {
Printf(stdout, "%5d ", priorities_row[col]);
}
Printf(stdout, "\n");
}
if (highest_count == parms_len) {
Append(chosenpartials, pi.item);
}
pi = Next(pi);
}
if (Len(chosenpartials) > 0) {
/* one or more best match found */
Delete(possiblepartials);
possiblepartials = chosenpartials;
posslen = Len(possiblepartials);
} else {
/* no best match found */
Delete(chosenpartials);
}
}
}
if (posslen > 0) {
String *s = Getattr(Getitem(possiblepartials, 0), "templcsymname");
n = Swig_symbol_clookup_local(s, primary_scope);
if (posslen > 1) {
int i;
if (n) {
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, cparse_file, cparse_line, "Instantiation of template '%s' is ambiguous,\n", SwigType_namestr(tname));
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, Getfile(n), Getline(n), " instantiation '%s' used,\n", SwigType_namestr(Getattr(n, "name")));
}
for (i = 1; i < posslen; i++) {
String *templcsymname = Getattr(Getitem(possiblepartials, i), "templcsymname");
Node *ignored_node = Swig_symbol_clookup_local(templcsymname, primary_scope);
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, Getfile(ignored_node), Getline(ignored_node), " instantiation '%s' ignored.\n", SwigType_namestr(Getattr(ignored_node, "name")));
}
}
}
if (!n) {
if (template_debug) {
Printf(stdout, " chosen primary template: '%s'\n", Getattr(templ, "name"));
}
n = templ;
}
} else {
if (template_debug) {
Printf(stdout, " primary template not found\n");
}
/* Give up if primary (unspecialized) template not found as specializations will only exist if there is a primary template */
n = 0;
}
if (!n) {
n = templ;
}
if (!n) {
Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name);
} else if (n) {
@ -613,13 +796,16 @@ static Node *template_locate(String *name, Parm *tparms, Symtab *tscope) {
}
success:
Delete(tname);
Delete(rname);
Delete(mpartials);
Delete(possiblepartials);
if ((template_debug) && (n)) {
/*
Printf(stdout, "Node: %p\n", n);
Swig_print_node(n);
*/
Printf(stdout, " chosen template:'%s'\n", Getattr(n, "name"));
}
Delete(parms);
free(priorities_matrix);
return n;
}

View file

@ -74,7 +74,7 @@
#define WARN_PARSE_PRIVATE_INHERIT 309
#define WARN_PARSE_TEMPLATE_REPEAT 310
#define WARN_PARSE_TEMPLATE_PARTIAL 311
#define WARN_PARSE_NESTED_CLASS 312
#define WARN_PARSE_UNNAMED_NESTED_CLASS 312
#define WARN_PARSE_UNDEFINED_EXTERN 313
#define WARN_PARSE_KEYWORD 314
#define WARN_PARSE_USING_UNDEF 315
@ -86,6 +86,8 @@
#define WARN_PARSE_BUILTIN_NAME 321
#define WARN_PARSE_REDUNDANT 322
#define WARN_PARSE_REC_INHERITANCE 323
#define WARN_PARSE_NESTED_TEMPLATE 324
#define WARN_PARSE_NAMED_NESTED_CLASS 325
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */
@ -251,15 +253,9 @@
/* please leave 850-869 free for Modula 3 */
/* These are needed for backward compatibility, but you don't need to add
* PHP4 versions of new warnings since existing user interface files can't
* be using them.
*/
#define WARN_PHP_MULTIPLE_INHERITANCE 870
#define WARN_PHP_UNKNOWN_PRAGMA 871
#define WARN_PHP_MULTIPLE_INHERITANCE 870
#define WARN_PHP_UNKNOWN_PRAGMA 871
#define WARN_PHP_PUBLIC_BASE 872
/* please leave 870-889 free for PHP */

View file

@ -8,7 +8,7 @@ BUILD_SOURCE_DIR=$(top_builddir)/Source
SWIG_CXX_DEFS = @SWILL@
AM_CFLAGS = -I$(BUILD_SOURCE_DIR)/Include \
AM_CPPFLAGS = -I$(BUILD_SOURCE_DIR)/Include \
-I$(BUILD_SOURCE_DIR)/CParse \
-I$(SOURCE_DIR)/Include \
-I$(SOURCE_DIR)/DOH \
@ -17,8 +17,7 @@ AM_CFLAGS = -I$(BUILD_SOURCE_DIR)/Include \
-I$(SOURCE_DIR)/Swig \
-I$(SOURCE_DIR)/Modules
AM_CXXFLAGS = $(AM_CFLAGS) \
$(SWIG_CXX_DEFS)
AM_CXXFLAGS = $(SWIG_CXX_DEFS)
AM_YFLAGS = -d
@ -87,7 +86,6 @@ eswig_SOURCES = CParse/cscanner.c \
Swig/typeobj.c \
Swig/typemap.c \
Swig/typesys.c \
Swig/warn.c \
Swig/wrapfunc.c
bin_PROGRAMS = eswig

View file

@ -378,9 +378,12 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
// Swig_print_node(n);
}
if (SwigType_istemplate(name)) {
String *temp = strip_namespaces(SwigType_templateprefix(name));
String *tname = SwigType_istemplate_templateprefix(name);
if (tname) {
String *temp = strip_namespaces(tname);
name = NewStringf("%s%s%s", temp, SwigType_templateargs(name), SwigType_templatesuffix(name));
Delete(temp);
Delete(tname);
}
val = lookup_defined_foreign_type(k);
@ -630,7 +633,7 @@ void note_implicit_template_instantiation(SwigType *t) {
add_defined_foreign_type(0, 0, t, t, implicit_ns ? implicit_ns : current_namespace);
}
String *get_ffi_type(SwigType *ty, const_String_or_char_ptr name) {
String *get_ffi_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
/* lookup defined foreign type.
if it exists, it will return a form suitable for placing
into lisp code to generate the def-foreign-type name */
@ -645,18 +648,20 @@ String *get_ffi_type(SwigType *ty, const_String_or_char_ptr name) {
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "found_type '%s'\n", found_type);
#endif
return (Strcmp(found_type, "forward-reference") ? Copy(found_type) :
get_ffi_type(fwdref_ffi_type, ""));
return (Strcmp(found_type, "forward-reference") ? Copy(found_type) : get_ffi_type(n, fwdref_ffi_type, ""));
} else {
Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0);
if (typemap) {
String *typespec = Getattr(typemap, "code");
Node *node = NewHash();
Setattr(node, "type", ty);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("ffitype", node, name, 0);
Delete(node);
if (tm) {
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "g-f-t: found ffitype typemap '%s'\n%s\n", typespec, typemap);
Printf(stderr, "g-f-t: found ffitype typemap '%s'\n", tm);
#endif
return NewString(typespec);
return NewString(tm);
}
if (SwigType_istemplate(ty)) {
@ -677,7 +682,7 @@ String *lookup_defined_foreign_ltype(String *l) {
/* walk type and return string containing lisp version.
recursive. */
String *internal_compose_foreign_type(SwigType *ty) {
String *internal_compose_foreign_type(Node *n, SwigType *ty) {
SwigType *tok;
String *ffiType = NewString("");
@ -695,18 +700,18 @@ String *internal_compose_foreign_type(SwigType *ty) {
Printf(ffiType, "("); // start parm list
for (Iterator i = First(pl); i.item; i = Next(i)) {
SwigType *f_arg = SwigType_strip_qualifiers(i.item);
Printf(ffiType, "%s ", internal_compose_foreign_type(f_arg));
Printf(ffiType, "%s ", internal_compose_foreign_type(n, f_arg));
Delete(f_arg);
}
Printf(ffiType, ")"); // end parm list.
// do function return type.
Printf(ffiType, " %s)", internal_compose_foreign_type(ty));
Printf(ffiType, " %s)", internal_compose_foreign_type(n, ty));
break;
} else if (SwigType_ispointer(tok) || SwigType_isreference(tok)) {
Printf(ffiType, "(* %s)", internal_compose_foreign_type(ty));
Printf(ffiType, "(* %s)", internal_compose_foreign_type(n, ty));
} else if (SwigType_isarray(tok)) {
Printf(ffiType, "(:array %s", internal_compose_foreign_type(ty));
Printf(ffiType, "(:array %s", internal_compose_foreign_type(n, ty));
String *atype = NewString("int");
String *dim = convert_literal(SwigType_array_getdim(tok, 0), atype);
Delete(atype);
@ -717,18 +722,18 @@ String *internal_compose_foreign_type(SwigType *ty) {
}
} else if (SwigType_ismemberpointer(tok)) {
// temp
Printf(ffiType, "(* %s)", internal_compose_foreign_type(ty));
Printf(ffiType, "(* %s)", internal_compose_foreign_type(n, ty));
} else {
String *res = get_ffi_type(tok, "");
String *res = get_ffi_type(n, tok, "");
if (res) {
Printf(ffiType, "%s", res);
} else {
SwigType *resolved_type = SwigType_typedef_resolve(tok);
if (resolved_type) {
res = get_ffi_type(resolved_type, "");
SwigType *resolved_type = SwigType_typedef_resolve_all(tok);
if (Cmp(resolved_type, tok) != 0) {
res = get_ffi_type(n, resolved_type, "");
if (res) {
} else {
res = internal_compose_foreign_type(resolved_type);
res = internal_compose_foreign_type(n, resolved_type);
}
if (res)
Printf(ffiType, "%s", res);
@ -766,7 +771,7 @@ String *internal_compose_foreign_type(SwigType *ty) {
add_forward_referenced_type(nn, 0);
// tok_name is dangling here, unused. ouch. why?
Printf(ffiType, "%s", get_ffi_type(tok, ""), tok_name);
Printf(ffiType, "%s", get_ffi_type(n, tok, ""), tok_name);
}
}
}
@ -774,9 +779,7 @@ String *internal_compose_foreign_type(SwigType *ty) {
return ffiType;
}
String *compose_foreign_type(SwigType *ty, String * /*id*/ = 0) {
/* Hash *lookup_res = Swig_typemap_search("ffitype", ty, id, 0); */
String *compose_foreign_type(Node *n, SwigType *ty, String * /*id*/ = 0) {
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "compose_foreign_type: ENTER (%s)...\n ", ty);
@ -806,7 +809,7 @@ String *compose_foreign_type(SwigType *ty, String * /*id*/ = 0) {
*/
SwigType *temp = SwigType_strip_qualifiers(ty);
String *res = internal_compose_foreign_type(temp);
String *res = internal_compose_foreign_type(n, temp);
Delete(temp);
#ifdef ALLEGROCL_TYPE_DEBUG
@ -1089,11 +1092,12 @@ void emit_stub_class(Node *n) {
if (Getattr(n, "allegrocl:synonym:already-been-stubbed"))
return;
if (SwigType_istemplate(name)) {
String *temp = strip_namespaces(SwigType_templateprefix(name));
String *tname = SwigType_istemplate_templateprefix(name);
if (tname) {
String *temp = strip_namespaces(tname);
name = NewStringf("%s%s%s", temp, SwigType_templateargs(name), SwigType_templatesuffix(name));
Delete(temp);
Delete(tname);
} else {
name = strip_namespaces(name);
}
@ -1243,7 +1247,7 @@ void emit_full_class(Node *n) {
#ifdef ALLEGROCL_WRAP_DEBUG
Printf(stderr, "slot name = '%s' ns = '%s' class-of '%s' and type = '%s'\n", cname, ns, name, childType);
#endif
Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)", cname, ns, name, compose_foreign_type(childType));
Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)", cname, ns, name, compose_foreign_type(n, childType));
Delete(ns);
if (access && Strcmp(access, "public"))
Printf(slotdefs, " ;; %s member", access);
@ -1280,11 +1284,12 @@ void emit_class(Node *n) {
String *ns_list = listify_namespace(Getattr(n, "allegrocl:namespace"));
String *name = Getattr(n, is_tempInst ? "real-name" : "name");
if (SwigType_istemplate(name)) {
String *temp = strip_namespaces(SwigType_templateprefix(name));
String *tname = SwigType_istemplate_templateprefix(name);
if (tname) {
String *temp = strip_namespaces(tname);
name = NewStringf("%s%s%s", temp, SwigType_templateargs(name), SwigType_templatesuffix(name));
Delete(temp);
Delete(tname);
} else {
name = strip_namespaces(name);
}
@ -1326,7 +1331,7 @@ void emit_typedef(Node *n) {
String *name;
String *sym_name = Getattr(n, "sym:name");
String *type = NewStringf("%s%s", Getattr(n, "decl"), Getattr(n, "type"));
String *lisp_type = compose_foreign_type(type);
String *lisp_type = compose_foreign_type(n, type);
Delete(type);
Node *in_class = Getattr(n, "allegrocl:typedef:in-class");
@ -1339,10 +1344,12 @@ void emit_typedef(Node *n) {
if (in_class) {
String *class_name = Getattr(in_class, "name");
if (SwigType_istemplate(class_name)) {
String *temp = strip_namespaces(SwigType_templateprefix(class_name));
String *tname = SwigType_istemplate_templateprefix(class_name);
if (tname) {
String *temp = strip_namespaces(tname);
class_name = NewStringf("%s%s%s", temp, SwigType_templateargs(class_name), SwigType_templatesuffix(class_name));
Delete(temp);
Delete(tname);
}
name = NewStringf("%s__%s", class_name, sym_name);
@ -1375,9 +1382,13 @@ void emit_enum_type_no_wrap(Node *n) {
name = unnamed ? Getattr(n, "allegrocl:name") : Getattr(n, "sym:name");
SwigType *tmp = NewStringf("enum %s", unnamed ? unnamed : name);
Hash *typemap = Swig_typemap_search("ffitype", tmp, 0, 0);
String *enumtype = Getattr(typemap, "code");
// enumtype = compose_foreign_type(tmp);
Node *node = NewHash();
Setattr(node, "type", tmp);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *enumtype = Swig_typemap_lookup("ffitype", node, "", 0);
Delete(node);
Delete(tmp);
if (name) {
@ -1431,12 +1442,14 @@ void emit_enum_type(Node *n) {
name = unnamed ? Getattr(n, "allegrocl:name") : Getattr(n, "sym:name");
SwigType *tmp = NewStringf("enum %s", unnamed ? unnamed : name);
// SwigType *tmp = NewStringf("enum ACL_SWIG_ENUM_NAME");
Hash *typemap = Swig_typemap_search("ffitype", tmp, 0, 0);
String *enumtype = Getattr(typemap, "code");
Node *node = NewHash();
Setattr(node, "type", tmp);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *enumtype = Swig_typemap_lookup("ffitype", node, "", 0);
Delete(node);
// enumtype = compose_foreign_type(tmp);
Delete(tmp);
if (name) {
@ -1801,13 +1814,13 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
String *t2 = Getattr(p2, "tmap:typecheck:precedence");
if ((!t1) && (!nodes[i].error)) {
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n),
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
Getattr(nodes[i].n, "name"), ParmList_str_defaultargs(Getattr(nodes[i].n, "parms")), SwigType_str(Getattr(p1, "type"), 0));
"Overloaded method %s not supported (no type checking rule for '%s').\n",
Swig_name_decl(nodes[i].n), SwigType_str(Getattr(p1, "type"), 0));
nodes[i].error = 1;
} else if ((!t2) && (!nodes[j].error)) {
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
Getattr(nodes[j].n, "name"), ParmList_str_defaultargs(Getattr(nodes[j].n, "parms")), SwigType_str(Getattr(p2, "type"), 0));
"Overloaded method %s not supported (no type checking rule for '%s').\n",
Swig_name_decl(nodes[j].n), SwigType_str(Getattr(p2, "type"), 0));
nodes[j].error = 1;
}
if (t1 && t2) {
@ -1898,14 +1911,15 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (!nodes[j].error) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n),
"using non-const method %s instead.\n", Swig_name_decl(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
"using %s instead.\n", Swig_name_decl(nodes[i].n));
}
}
nodes[j].error = 1;
@ -1914,14 +1928,15 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (!nodes[j].error) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n),
"using non-const method %s instead.\n", Swig_name_decl(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
"using %s instead.\n", Swig_name_decl(nodes[i].n));
}
}
nodes[j].error = 1;
@ -1935,19 +1950,15 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (!nodes[j].error) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n",
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "",
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms),
SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s effectively ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[i].n), Getline(nodes[i].n),
"as it is shadowed by %s.\n", Swig_name_decl(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "",
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms),
SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
"using %s instead.\n", Swig_name_decl(nodes[i].n));
}
nodes[j].error = 1;
}
@ -1983,14 +1994,16 @@ int any_varargs(ParmList *pl) {
return 0;
}
String *get_lisp_type(SwigType *ty, const_String_or_char_ptr name) {
Hash *typemap = Swig_typemap_search("lisptype", ty, name, 0);
if (typemap) {
String *typespec = Getattr(typemap, "code");
return NewString(typespec);
} else {
return NewString("");
}
String *get_lisp_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
Node *node = NewHash();
Setattr(node, "type", ty);
Setattr(node, "name", name);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("lisptype", node, "", 0);
Delete(node);
return tm ? NewString(tm) : NewString("");
}
Node *parent_node_skipping_extends(Node *n) {
@ -2006,7 +2019,7 @@ Node *parent_node_skipping_extends(Node *n) {
* emit_num_lin_arguments()
*
* Calculate the total number of arguments. This function is safe for use
* with multi-valued typemaps which may change the number of arguments in
* with multi-argument typemaps which may change the number of arguments in
* strange ways.
* ----------------------------------------------------------------------------- */
@ -2278,18 +2291,21 @@ int ALLEGROCL::emit_buffered_defuns(Node *n) {
return SWIG_OK;
}
String *dispatching_type(Parm *p) {
String *dispatching_type(Node *n, Parm *p) {
String *result = 0;
String *parsed = Getattr(p, "type"); //Swig_cparse_type(Getattr(p,"tmap:ctype"));
String *cl_t = SwigType_typedef_resolve_all(parsed);
Hash *typemap = Swig_typemap_search("lispclass", parsed, Getattr(p, "name"), 0);
// Printf(stderr,"inspecting type '%s' for class\n", parsed);
// Printf(stderr," cfcocr = '%s' res_all = '%s'\n",
// class_from_class_or_class_ref(parsed), cl_t);
if (typemap) {
result = Copy(Getattr(typemap, "code"));
Node *node = NewHash();
Setattr(node, "type", parsed);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("lispclass", node, Getattr(p, "name"), 0);
Delete(node);
if (tm) {
result = Copy(tm);
} else {
String *lookup_type = class_from_class_or_class_ref(parsed);
if (lookup_type)
@ -2309,24 +2325,6 @@ String *dispatching_type(Parm *p) {
return result;
}
String *defmethod_lambda_list(Node *overload) {
String *result = NewString("");
ParmList *parms = Getattr(overload, "wrap:parms");
Parm *p;
int a;
for (a = 0, p = parms; p; p = nextSibling(p), ++a) {
if (a != 0)
Printf(result, " ");
Printf(result, "(arg%d ", a);
Printf(result, "%s", dispatching_type(p));
Printf(result, ")");
}
return result;
}
int ALLEGROCL::emit_dispatch_defun(Node *n) {
#ifdef ALLEGROCL_WRAP_DEBUG
Printf(stderr, "emit_dispatch_defun: ENTER... ");
@ -2433,9 +2431,9 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
String *argname = NewStringf("PARM%d_%s", largnum, Getattr(p, "name"));
// Printf(stderr,"%s\n", Getattr(p,"tmap:lin"));
String *ffitype = compose_foreign_type(argtype, Getattr(p,"name"));
String *ffitype = compose_foreign_type(n, argtype, Getattr(p,"name"));
String *deref_ffitype = dereference_ffitype(ffitype);
String *lisptype = get_lisp_type(parmtype, Getattr(p, "name"));
String *lisptype = get_lisp_type(n, parmtype, Getattr(p, "name"));
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "lisptype of '%s' '%s' = '%s'\n", parmtype,
@ -2458,7 +2456,7 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
Replaceall(wrap->code, "$body", parm_code);
}
String *dispatchtype = Getattr(n, "sym:overloaded") ? dispatching_type(p) : NewString("");
String *dispatchtype = Getattr(n, "sym:overloaded") ? dispatching_type(n, p) : NewString("");
// if this parameter has been removed from the C/++ wrapper
// it shouldn't be in the lisp wrapper either.
@ -2489,13 +2487,13 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
SwigType *parsed = Swig_cparse_type(Getattr(n, "tmap:ctype"));
// SwigType *cl_t = SwigType_typedef_resolve_all(parsed);
SwigType *cl_t = class_from_class_or_class_ref(parsed);
String *out_ffitype = compose_foreign_type(parsed);
String *out_ffitype = compose_foreign_type(n, parsed);
String *deref_out_ffitype;
String *out_temp = Copy(parsed);
if (SwigType_ispointer(out_temp)) {
SwigType_pop(out_temp);
deref_out_ffitype = compose_foreign_type(out_temp);
deref_out_ffitype = compose_foreign_type(n, out_temp);
} else {
deref_out_ffitype = Copy(out_ffitype);
}
@ -2551,7 +2549,7 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
/////////////////////////////////////////////////////
// Lisp foreign call return type and optimizations //
/////////////////////////////////////////////////////
Printf(fcl, " (:returning (%s %s)", compose_foreign_type(result_type), get_lisp_type(Getattr(n, "type"), "result"));
Printf(fcl, " (:returning (%s %s)", compose_foreign_type(n, result_type), get_lisp_type(n, Getattr(n, "type"), "result"));
for (Iterator option = First(n); option.item; option = Next(option)) {
if (Strncmp("feature:ffargs:", option.key, 15))
@ -2930,10 +2928,6 @@ int ALLEGROCL::variableWrapper(Node *n) {
Printf(f_runtime, "EXPORT %s %s;\n%s %s = %s%s;\n", ctype, mangled_name, ctype, mangled_name, (pointer_added ? "&" : ""), name);
Printf(f_cl, "(swig-defvar \"%s\" :type %s)\n", mangled_name, ((SwigType_isconst(type)) ? ":constant" : ":variable"));
/*
Printf(f_runtime, "// swigtype: %s\n", SwigType_typedef_resolve_all(Getattr(n,"type")));
Printf(f_runtime, "// vwrap: %s\n", compose_foreign_type(SwigType_strip_qualifiers(Copy(rtype))));
*/
Printf(stderr,"***\n");
Delete(mangled_name);
@ -2975,7 +2969,7 @@ int ALLEGROCL::typedefHandler(Node *n) {
SwigType *typedef_type = Getattr(n,"type");
// has the side-effect of noting any implicit
// template instantiations in type.
String *ff_type = compose_foreign_type(typedef_type);
String *ff_type = compose_foreign_type(n, typedef_type);
String *sym_name = Getattr(n, "sym:name");
@ -3136,7 +3130,7 @@ int ALLEGROCL::cppClassHandler(Node *n) {
Printf(stderr, "looking at child '%x' of type '%s'\n", c, childType);
#endif
if (!SwigType_isfunction(childType))
Delete(compose_foreign_type(childType));
Delete(compose_foreign_type(n, childType));
Delete(childType);
}

View file

@ -522,7 +522,7 @@ class Allocate:public Dispatcher {
*/
String *scatchlist = Getattr(n, "feature:catches");
if (scatchlist) {
catchlist = Swig_cparse_parms(scatchlist);
catchlist = Swig_cparse_parms(scatchlist, n);
if (catchlist) {
Setattr(n, "catchlist", catchlist);
mark_exception_classes(catchlist);
@ -531,8 +531,7 @@ class Allocate:public Dispatcher {
}
ParmList *throws = Getattr(n, "throws");
if (throws) {
/* if there is no an explicit catchlist,
we catch everything in the throwlist */
/* if there is no explicit catchlist, we catch everything in the throws list */
if (!catchlist) {
Setattr(n, "catchlist", throws);
}

View file

@ -622,12 +622,12 @@ int CFFI::enumDeclaration(Node *n) {
slot_name_keywords = true;
//Registering the enum name to the cin and cout typemaps
Parm *pattern = NewParm(name, NULL);
Parm *pattern = NewParm(name, NULL, n);
Swig_typemap_register("cin", pattern, lisp_name, NULL, NULL);
Swig_typemap_register("cout", pattern, lisp_name, NULL, NULL);
Delete(pattern);
//Registering with the kind, i.e., enum
pattern = NewParm(NewStringf("enum %s", name), NULL);
pattern = NewParm(NewStringf("enum %s", name), NULL, n);
Swig_typemap_register("cin", pattern, lisp_name, NULL, NULL);
Swig_typemap_register("cout", pattern, lisp_name, NULL, NULL);
Delete(pattern);
@ -692,7 +692,7 @@ void CFFI::emit_class(Node *n) {
Printf(f_clos, "\n(cl:defclass %s%s", lisp_name, supers);
Printf(f_clos, "\n ((ff-pointer :reader ff-pointer)))\n\n");
Parm *pattern = NewParm(Getattr(n, "name"), NULL);
Parm *pattern = NewParm(Getattr(n, "name"), NULL, n);
Swig_typemap_register("lispclass", pattern, lisp_name, NULL, NULL);
SwigType_add_pointer(Getattr(pattern, "type"));
@ -762,7 +762,7 @@ void CFFI::emit_class(Node *n) {
Delete(supers);
// Delete(ns_list);
// Parm *pattern = NewParm(name,NULL);
// Parm *pattern = NewParm(name, NULL, n);
// Swig_typemap_register("cin",pattern,lisp_name,NULL,NULL);
//Swig_typemap_register("cout",pattern,lisp_name,NULL,NULL);
//Delete(pattern);
@ -791,12 +791,12 @@ void CFFI::emit_struct_union(Node *n, bool un = false) {
//Register the struct/union name to the cin and cout typemaps
Parm *pattern = NewParm(name, NULL);
Parm *pattern = NewParm(name, NULL, n);
Swig_typemap_register("cin", pattern, lisp_name, NULL, NULL);
Swig_typemap_register("cout", pattern, lisp_name, NULL, NULL);
Delete(pattern);
//Registering with the kind, i.e., struct or union
pattern = NewParm(NewStringf("%s %s", kind, name), NULL);
pattern = NewParm(NewStringf("%s %s", kind, name), NULL, n);
Swig_typemap_register("cin", pattern, lisp_name, NULL, NULL);
Swig_typemap_register("cout", pattern, lisp_name, NULL, NULL);
Delete(pattern);
@ -823,21 +823,24 @@ void CFFI::emit_struct_union(Node *n, bool un = false) {
// Getattr(c, "type"));
// SWIG_exit(EXIT_FAILURE);
} else {
SwigType *childType = NewStringf("%s%s", Getattr(c, "decl"),
Getattr(c, "type"));
SwigType *childType = NewStringf("%s%s", Getattr(c, "decl"), Getattr(c, "type"));
Hash *typemap = Swig_typemap_search("cin", childType, "", 0);
String *typespec = NewString("");
if (typemap) {
typespec = NewString(Getattr(typemap, "code"));
}
Node *node = NewHash();
Setattr(node, "type", childType);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("cin", node, "", 0);
String *typespec = tm ? NewString(tm) : NewString("");
String *slot_name = lispify_name(c, Getattr(c, "sym:name"), "'slotname");
if (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0)
slot_name = NewStringf("t_var");
slot_name = NewStringf("t_var");
Printf(f_cl, "\n\t(%s %s)", slot_name, typespec);
Delete(node);
Delete(childType);
Delete(typespec);
}
}

View file

@ -29,7 +29,7 @@ public:
virtual int typedefHandler(Node *n);
List *entries;
private:
String *get_ffi_type(SwigType *ty);
String *get_ffi_type(Node *n, SwigType *ty);
String *convert_literal(String *num_param, String *type);
String *strip_parens(String *string);
int extern_all_flag;
@ -171,7 +171,7 @@ int CLISP::functionWrapper(Node *n) {
String *argname = Getattr(p, "name");
// SwigType *argtype;
String *ffitype = get_ffi_type(Getattr(p, "type"));
String *ffitype = get_ffi_type(n, Getattr(p, "type"));
int tempargname = 0;
@ -194,7 +194,7 @@ int CLISP::functionWrapper(Node *n) {
if (ParmList_len(pl) != 0) {
Printf(f_cl, ")\n"); /* finish arg list */
}
String *ffitype = get_ffi_type(Getattr(n, "type"));
String *ffitype = get_ffi_type(n, Getattr(n, "type"));
if (Strcmp(ffitype, "NIL")) { //when return type is not nil
Printf(f_cl, "\t(:return-type %s)\n", ffitype);
}
@ -226,7 +226,7 @@ int CLISP::variableWrapper(Node *n) {
return SWIG_OK;
String *var_name = Getattr(n, "sym:name");
String *lisp_type = get_ffi_type(Getattr(n, "type"));
String *lisp_type = get_ffi_type(n, Getattr(n, "type"));
Printf(f_cl, "\n(ffi:def-c-var %s\n (:name \"%s\")\n (:type %s)\n", var_name, var_name, lisp_type);
Printf(f_cl, "\t(:library +library-name+))\n");
Append(entries, var_name);
@ -238,7 +238,7 @@ int CLISP::variableWrapper(Node *n) {
int CLISP::typedefHandler(Node *n) {
if (generate_typedef_flag) {
is_function = 0;
Printf(f_cl, "\n(ffi:def-c-type %s %s)\n", Getattr(n, "name"), get_ffi_type(Getattr(n, "type")));
Printf(f_cl, "\n(ffi:def-c-type %s %s)\n", Getattr(n, "name"), get_ffi_type(n, Getattr(n, "type")));
}
return Language::typedefHandler(n);
@ -294,7 +294,7 @@ int CLISP::classDeclaration(Node *n) {
String *temp = Copy(Getattr(c, "decl"));
Append(temp, Getattr(c, "type")); //appending type to the end, otherwise wrong type
String *lisp_type = get_ffi_type(temp);
String *lisp_type = get_ffi_type(n, temp);
Delete(temp);
String *slot_name = Getattr(c, "sym:name");
@ -375,15 +375,20 @@ String *CLISP::convert_literal(String *num_param, String *type) {
return res;
}
String *CLISP::get_ffi_type(SwigType *ty) {
Hash *typemap = Swig_typemap_search("in", ty, "", 0);
if (typemap) {
String *typespec = Getattr(typemap, "code");
return NewString(typespec);
String *CLISP::get_ffi_type(Node *n, SwigType *ty) {
Node *node = NewHash();
Setattr(node, "type", ty);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("in", node, "", 0);
Delete(node);
if (tm) {
return NewString(tm);
} else if (SwigType_ispointer(ty)) {
SwigType *cp = Copy(ty);
SwigType_del_pointer(cp);
String *inner_type = get_ffi_type(cp);
String *inner_type = get_ffi_type(n, cp);
if (SwigType_isfunction(cp)) {
return inner_type;
@ -413,12 +418,12 @@ String *CLISP::get_ffi_type(SwigType *ty) {
Delete(array_dim);
SwigType_del_array(cp);
SwigType_add_pointer(cp);
String *str = get_ffi_type(cp);
String *str = get_ffi_type(n, cp);
Delete(cp);
return str;
} else {
SwigType_pop_arrays(cp);
String *inner_type = get_ffi_type(cp);
String *inner_type = get_ffi_type(n, cp);
Delete(cp);
int ndim = SwigType_array_ndim(ty);
@ -451,7 +456,7 @@ String *CLISP::get_ffi_type(SwigType *ty) {
SwigType *cp = Copy(ty);
SwigType *fn = SwigType_pop_function(cp);
String *args = NewString("");
ParmList *pl = SwigType_function_parms(fn);
ParmList *pl = SwigType_function_parms(fn, n);
if (ParmList_len(pl) != 0) {
Printf(args, "(:arguments ");
}
@ -459,7 +464,7 @@ String *CLISP::get_ffi_type(SwigType *ty) {
for (Parm *p = pl; p; p = nextSibling(p), argnum++) {
String *argname = Getattr(p, "name");
SwigType *argtype = Getattr(p, "type");
String *ffitype = get_ffi_type(argtype);
String *ffitype = get_ffi_type(n, argtype);
int tempargname = 0;
@ -479,7 +484,7 @@ String *CLISP::get_ffi_type(SwigType *ty) {
if (ParmList_len(pl) != 0) {
Printf(args, ")\n"); /* finish arg list */
}
String *ffitype = get_ffi_type(cp);
String *ffitype = get_ffi_type(n, cp);
String *str = NewStringf("(ffi:c-function %s \t\t\t\t(:return-type %s))", args, ffitype);
Delete(fn);
Delete(args);

View file

@ -90,13 +90,6 @@ class CSHARP:public Language {
enum EnumFeature { SimpleEnum, TypeunsafeEnum, TypesafeEnum, ProperEnum };
static Parm *NewParmFromNode(SwigType *type, const_String_or_char_ptr name, Node *n) {
Parm *p = NewParm(type, name);
Setfile(p, Getfile(n));
Setline(p, Getline(n));
return p;
}
public:
/* -----------------------------------------------------------------------------
@ -341,6 +334,10 @@ public:
module_class_name = Copy(Getattr(n, "name"));
}
// module class and intermediary classes are always created
addSymbol(imclass_name, n);
addSymbol(module_class_name, n);
imclass_class_code = NewString("");
proxy_class_def = NewString("");
proxy_class_code = NewString("");
@ -390,10 +387,10 @@ public:
Printf(f_runtime, "\n");
Swig_name_register((char *) "wrapper", (char *) "CSharp_%f");
Swig_name_register("wrapper", "CSharp_%f");
if (old_variable_names) {
Swig_name_register((char *) "set", (char *) "set_%v");
Swig_name_register((char *) "get", (char *) "get_%v");
Swig_name_register("set", "set_%v");
Swig_name_register("get", "get_%v");
}
Printf(f_wrappers, "\n#ifdef __cplusplus\n");
@ -682,7 +679,7 @@ public:
virtual int nativeWrapper(Node *n) {
String *wrapname = Getattr(n, "wrap:name");
if (!addSymbol(wrapname, n))
if (!addSymbol(wrapname, n, imclass_name))
return SWIG_ERROR;
if (Getattr(n, "type")) {
@ -722,7 +719,7 @@ public:
String *overloaded_name = getOverloadedName(n);
if (!Getattr(n, "sym:overloaded")) {
if (!addSymbol(Getattr(n, "sym:name"), n))
if (!addSymbol(Getattr(n, "sym:name"), n, imclass_name))
return SWIG_ERROR;
}
@ -902,9 +899,9 @@ public:
}
}
// Get any C# exception classes in the throws typemap
// Look for usage of throws typemap and the canthrow flag
ParmList *throw_parm_list = NULL;
if ((throw_parm_list = Getattr(n, "throws"))) {
if ((throw_parm_list = Getattr(n, "catchlist"))) {
Swig_typemap_attach_parms("throws", throw_parm_list, f);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
@ -1119,16 +1116,16 @@ public:
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum
// Pure C# baseclass and interfaces
const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE);
const String *pure_interfaces = typemapLookup("csinterfaces", typemap_lookup_type, WARN_NONE);
const String *pure_baseclass = typemapLookup(n, "csbase", typemap_lookup_type, WARN_NONE);
const String *pure_interfaces = typemapLookup(n, "csinterfaces", typemap_lookup_type, WARN_NONE);
// Class attributes
const String *csattributes = typemapLookup("csattributes", typemap_lookup_type, WARN_NONE);
const String *csattributes = typemapLookup(n, "csattributes", typemap_lookup_type, WARN_NONE);
if (csattributes && *Char(csattributes))
Printf(enum_code, "%s\n", csattributes);
// Emit the enum
Printv(enum_code, typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really)
Printv(enum_code, typemapLookup(n, "csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really)
" ", symname, (*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces
", " : "", pure_interfaces, " {\n", NIL);
} else {
@ -1144,8 +1141,8 @@ public:
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum
// Finish the enum declaration
// Typemaps are used to generate the enum definition in a similar manner to proxy classes.
Printv(enum_code, (enum_feature == ProperEnum) ? "\n" : typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code
Printv(enum_code, (enum_feature == ProperEnum) ? "\n" : typemapLookup(n, "csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
typemapLookup(n, "cscode", typemap_lookup_type, WARN_NONE), // extra C# code
"}", NIL);
Replaceall(enum_code, "$csclassname", symname);
@ -1181,7 +1178,7 @@ public:
addOpenNamespace(namespce, f_enum);
Printv(f_enum, typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements
Printv(f_enum, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements
"\n", enum_code, "\n", NIL);
addCloseNamespace(namespce, f_enum);
@ -1215,6 +1212,9 @@ public:
String *symname = Getattr(n, "sym:name");
String *value = Getattr(n, "value");
String *name = Getattr(n, "name");
Node *parent = parentNode(n);
int unnamedinstance = GetFlag(parent, "unnamedinstance");
String *parent_name = Getattr(parent, "name");
String *tmpValue;
// Strange hack from parent method
@ -1226,13 +1226,18 @@ public:
Setattr(n, "value", tmpValue);
{
EnumFeature enum_feature = decodeEnumFeature(parentNode(n));
EnumFeature enum_feature = decodeEnumFeature(parent);
const String *csattributes = Getattr(n, "feature:cs:attributes");
if ((enum_feature == ProperEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) {
if ((enum_feature == ProperEnum) && parent_name && !unnamedinstance) {
// Wrap (non-anonymous) C/C++ enum with a proper C# enum
// Emit the enum item.
if (!Getattr(n, "_last")) // Only the first enum item has this attribute set
if (!GetFlag(n, "firstenumitem"))
Printf(enum_code, ",\n");
if (csattributes)
Printf(enum_code, " %s\n", csattributes);
Printf(enum_code, " %s", symname);
// Check for the %csconstvalue feature
@ -1245,21 +1250,19 @@ public:
}
} else {
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern
const String *parent_name = Getattr(parentNode(n), "name");
String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int");
const String *tm = typemapLookup("cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF);
String *type = Getattr(n, "type"); /* should be int unless explicitly specified in a C++0x enum class */
SwigType *typemap_lookup_type = parent_name ? parent_name : type;
const String *tm = typemapLookup(n, "cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF);
String *return_type = Copy(tm);
Delete(typemap_lookup_type);
typemap_lookup_type = NULL;
// The %csconst feature determines how the constant value is obtained
int const_feature_flag = GetFlag(n, "feature:cs:const");
const String *methodmods = Getattr(n, "feature:cs:methodmodifiers");
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
if ((enum_feature == TypesafeEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) {
// Wrap (non-anonymouse) enum using the typesafe enum pattern
if (csattributes)
Printf(enum_code, " %s\n", csattributes);
if ((enum_feature == TypesafeEnum) && parent_name && !unnamedinstance) {
// Wrap (non-anonymous) enum using the typesafe enum pattern
if (Getattr(n, "enumvalue")) {
String *value = enumValue(n);
Printf(enum_code, " %s static readonly %s %s = new %s(\"%s\", %s);\n", methodmods, return_type, symname, return_type, symname, value);
@ -1271,6 +1274,10 @@ public:
// Simple integer constants
// Note these are always generated for anonymous enums, no matter what enum_feature is specified
// Code generated is the same for SimpleEnum and TypeunsafeEnum -> the class it is generated into is determined later
// The %csconst feature determines how the constant value is obtained
int const_feature_flag = GetFlag(n, "feature:cs:const");
const char *const_readonly = const_feature_flag ? "const" : "static readonly";
String *value = enumValue(n);
Printf(enum_code, " %s %s %s %s = %s;\n", methodmods, const_readonly, return_type, symname, value);
@ -1279,9 +1286,9 @@ public:
}
// Add the enum value to the comma separated list being constructed in the enum declaration.
String *enumvalues = Getattr(parentNode(n), "enumvalues");
String *enumvalues = Getattr(parent, "enumvalues");
if (!enumvalues)
Setattr(parentNode(n), "enumvalues", Copy(symname));
Setattr(parent, "enumvalues", Copy(symname));
else
Printv(enumvalues, ", ", symname, NIL);
}
@ -1310,11 +1317,13 @@ public:
String *return_type = NewString("");
String *constants_code = NewString("");
if (!addSymbol(symname, n))
return SWIG_ERROR;
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
const String *itemname = (proxy_flag && wrapping_member_flag) ? variable_name : symname;
String *scope = proxy_flag && wrapping_member_flag ? proxy_class_name : module_class_name;
if (!addSymbol(itemname, n, scope))
return SWIG_ERROR;
// The %csconst feature determines how the constant value is obtained
int const_feature_flag = GetFlag(n, "feature:cs:const");
@ -1355,7 +1364,6 @@ public:
const String *outattributes = Getattr(n, "tmap:cstype:outattributes");
if (outattributes)
Printf(constants_code, " %s\n", outattributes);
const String *itemname = (proxy_flag && wrapping_member_flag) ? variable_name : symname;
const String *methodmods = Getattr(n, "feature:cs:methodmodifiers");
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
@ -1388,7 +1396,14 @@ public:
enum_constant_flag = false;
} else {
// Alternative constant handling will use the C syntax to make a true C# constant and hope that it compiles as C# code
Printf(constants_code, "%s;\n", Getattr(n, "value"));
if (Getattr(n, "wrappedasconstant")) {
if (SwigType_type(t) == T_CHAR)
Printf(constants_code, "\'%s\';\n", Getattr(n, "staticmembervariableHandler:value"));
else
Printf(constants_code, "%s;\n", Getattr(n, "staticmembervariableHandler:value"));
} else {
Printf(constants_code, "%s;\n", Getattr(n, "value"));
}
}
// Emit the generated code to appropriate place
@ -1494,12 +1509,12 @@ public:
String *c_baseclass = NULL;
String *baseclass = NULL;
String *c_baseclassname = NULL;
String *typemap_lookup_type = Getattr(n, "classtypeobj");
SwigType *typemap_lookup_type = Getattr(n, "classtypeobj");
bool feature_director = Swig_directorclass(n) ? true : false;
// Inheritance from pure C# classes
Node *attributes = NewHash();
const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE, attributes);
const String *pure_baseclass = typemapLookup(n, "csbase", typemap_lookup_type, WARN_NONE, attributes);
bool purebase_replace = GetFlag(attributes, "tmap:csbase:replace") ? true : false;
bool purebase_notderived = GetFlag(attributes, "tmap:csbase:notderived") ? true : false;
Delete(attributes);
@ -1553,21 +1568,21 @@ public:
}
// Pure C# interfaces
const String *pure_interfaces = typemapLookup(derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE);
const String *pure_interfaces = typemapLookup(n, derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE);
// Start writing the proxy class
Printv(proxy_class_def, typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements
Printv(proxy_class_def, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements
"\n", NIL);
// Class attributes
const String *csattributes = typemapLookup("csattributes", typemap_lookup_type, WARN_NONE);
const String *csattributes = typemapLookup(n, "csattributes", typemap_lookup_type, WARN_NONE);
if (csattributes && *Char(csattributes))
Printf(proxy_class_def, "%s\n", csattributes);
Printv(proxy_class_def, typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
Printv(proxy_class_def, typemapLookup(n, "csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" $csclassname", // Class name and base class
(*Char(wanted_base) || *Char(pure_interfaces)) ? " : " : "", wanted_base, (*Char(wanted_base) && *Char(pure_interfaces)) ? // Interfaces
", " : "", pure_interfaces, " {", derived ? typemapLookup("csbody_derived", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF) : // main body of class
typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
", " : "", pure_interfaces, " {", derived ? typemapLookup(n, "csbody_derived", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF) : // main body of class
typemapLookup(n, "csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
NIL);
// C++ destructor is wrapped by the Dispose method
@ -1578,11 +1593,11 @@ public:
String *destruct_methodname = NULL;
String *destruct_methodmodifiers = NULL;
if (derived) {
tm = typemapLookup("csdestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
tm = typemapLookup(n, "csdestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:csdestruct_derived:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct_derived:methodmodifiers");
} else {
tm = typemapLookup("csdestruct", typemap_lookup_type, WARN_NONE, attributes);
tm = typemapLookup(n, "csdestruct", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:csdestruct:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct:methodmodifiers");
}
@ -1599,7 +1614,7 @@ public:
if (tm) {
// Finalize method
if (*Char(destructor_call)) {
Printv(proxy_class_def, typemapLookup("csfinalize", typemap_lookup_type, WARN_NONE), NIL);
Printv(proxy_class_def, typemapLookup(n, "csfinalize", typemap_lookup_type, WARN_NONE), NIL);
}
// Dispose method
Printv(destruct, tm, NIL);
@ -1694,7 +1709,7 @@ public:
Delete(destruct);
// Emit extra user code
Printv(proxy_class_def, typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code
Printv(proxy_class_def, typemapLookup(n, "cscode", typemap_lookup_type, WARN_NONE), // extra C# code
"\n", NIL);
// Substitute various strings into the above template
@ -2359,7 +2374,7 @@ public:
/* Insert the csconstruct typemap, doing the replacement for $directorconnect, as needed */
Hash *attributes = NewHash();
String *construct_tm = Copy(typemapLookup("csconstruct", Getattr(n, "name"),
String *construct_tm = Copy(typemapLookup(n, "csconstruct", Getattr(n, "name"),
WARN_CSHARP_TYPEMAP_CSCONSTRUCT_UNDEF, attributes));
if (construct_tm) {
if (!feature_director) {
@ -2770,6 +2785,16 @@ public:
Delete(func_name);
}
/*----------------------------------------------------------------------
* replaceSpecialVariables()
*--------------------------------------------------------------------*/
virtual void replaceSpecialVariables(String *method, String *tm, Parm *parm) {
(void)method;
SwigType *type = Getattr(parm, "type");
substituteClassname(type, tm);
}
/*----------------------------------------------------------------------
* decodeEnumFeature()
* Decode the possible enum features, which are one of:
@ -2863,15 +2888,15 @@ public:
/* -----------------------------------------------------------------------------
* substituteClassname()
*
* Substitute $csclassname with the proxy class name for classes/structs/unions that SWIG knows about.
* Also substitutes enums with enum name.
* Substitute the special variable $csclassname with the proxy class name for classes/structs/unions
* that SWIG knows about. Also substitutes enums with enum name.
* Otherwise use the $descriptor name for the C# class name. Note that the $&csclassname substitution
* is the same as a $&descriptor substitution, ie one pointer added to descriptor name.
* Inputs:
* pt - parameter type
* tm - cstype typemap
* tm - typemap contents that might contain the special variable to be replaced
* Outputs:
* tm - cstype typemap with $csclassname substitution
* tm - typemap contents complete with the special variable substitution
* Return:
* substitution_performed - flag indicating if a substitution was performed
* ----------------------------------------------------------------------------- */
@ -2976,6 +3001,10 @@ public:
* ----------------------------------------------------------------------------- */
void emitTypeWrapperClass(String *classname, SwigType *type) {
Node *n = NewHash();
Setfile(n, input_file);
Setline(n, line_number);
String *swigtype = NewString("");
String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), classname);
File *f_swigtype = NewFile(filen, "w", SWIG_output_files());
@ -2993,23 +3022,23 @@ public:
addOpenNamespace(namespce, f_swigtype);
// Pure C# baseclass and interfaces
const String *pure_baseclass = typemapLookup("csbase", type, WARN_NONE);
const String *pure_interfaces = typemapLookup("csinterfaces", type, WARN_NONE);
const String *pure_baseclass = typemapLookup(n, "csbase", type, WARN_NONE);
const String *pure_interfaces = typemapLookup(n, "csinterfaces", type, WARN_NONE);
// Emit the class
Printv(swigtype, typemapLookup("csimports", type, WARN_NONE), // Import statements
Printv(swigtype, typemapLookup(n, "csimports", type, WARN_NONE), // Import statements
"\n", NIL);
// Class attributes
const String *csattributes = typemapLookup("csattributes", type, WARN_NONE);
const String *csattributes = typemapLookup(n, "csattributes", type, WARN_NONE);
if (csattributes && *Char(csattributes))
Printf(swigtype, "%s\n", csattributes);
Printv(swigtype, typemapLookup("csclassmodifiers", type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
Printv(swigtype, typemapLookup(n, "csclassmodifiers", type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" $csclassname", // Class name and base class
(*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces
", " : "", pure_interfaces, " {", typemapLookup("csbody", type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
typemapLookup("cscode", type, WARN_NONE), // extra C# code
", " : "", pure_interfaces, " {", typemapLookup(n, "csbody", type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
typemapLookup(n, "cscode", type, WARN_NONE), // extra C# code
"}\n", NIL);
Replaceall(swigtype, "$csclassname", classname);
@ -3023,36 +3052,34 @@ public:
Close(f_swigtype);
Delete(swigtype);
Delete(n);
}
/* -----------------------------------------------------------------------------
* typemapLookup()
* n - for input only and must contain info for Getfile(n) and Getline(n) to work
* tmap_method - typemap method name
* type - typemap type to lookup
* warning - warning number to issue if no typemaps found
* typemap_attributes - the typemap attributes are attached to this node and will
* also be used for temporary storage if non null
* return is never NULL, unlike Swig_typemap_lookup()
* ----------------------------------------------------------------------------- */
const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes = NULL) {
String *tm = NULL;
const String *code = NULL;
if ((tm = Swig_typemap_search(op, type, NULL, NULL))) {
code = Getattr(tm, "code");
if (typemap_attributes)
Swig_typemap_attach_kwargs(tm, op, typemap_attributes);
}
if (!code) {
code = empty_string;
const String *typemapLookup(Node *n, const_String_or_char_ptr tmap_method, SwigType *type, int warning, Node *typemap_attributes = 0) {
Node *node = !typemap_attributes ? NewHash() : typemap_attributes;
Setattr(node, "type", type);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup(tmap_method, node, "", 0);
if (!tm) {
tm = empty_string;
if (warning != WARN_NONE)
Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type);
Swig_warning(warning, Getfile(n), Getline(n), "No %s typemap defined for %s\n", tmap_method, SwigType_str(type, 0));
}
return code ? code : empty_string;
}
/* -----------------------------------------------------------------------------
* addThrows()
// TODO: remove
* ----------------------------------------------------------------------------- */
void addThrows(Node *, const String *, Node *) {
if (!typemap_attributes)
Delete(node);
return tm;
}
/* -----------------------------------------------------------------------------
@ -3306,7 +3333,7 @@ public:
}
/* Create the intermediate class wrapper */
Parm *tp = NewParmFromNode(returntype, empty_str, n);
Parm *tp = NewParm(returntype, empty_str, n);
tm = Swig_typemap_lookup("imtype", tp, "", 0);
if (tm) {
@ -3326,7 +3353,7 @@ public:
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
Parm *retpm = NewParmFromNode(returntype, empty_str, n);
Parm *retpm = NewParm(returntype, empty_str, n);
if ((c_ret_type = Swig_typemap_lookup("ctype", retpm, "", 0))) {
@ -3336,7 +3363,8 @@ public:
Delete(jretval_decl);
}
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(returntype, 0));
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
@ -3401,10 +3429,6 @@ public:
Printf(arg, "j%s", ln);
/* Add various typemap's 'throws' clauses */
addThrows(n, "tmap:directorin", p);
addThrows(n, "tmap:out", p);
/* And add to the upcall args */
if (gencomma > 0)
Printf(jupcall_args, ", ");
@ -3416,7 +3440,7 @@ public:
if (ctypeout)
c_param_type = ctypeout;
Parm *tp = NewParmFromNode(c_param_type, empty_str, n);
Parm *tp = NewParm(c_param_type, empty_str, n);
String *desc_tm = NULL;
/* Add to local variables */
@ -3479,11 +3503,13 @@ public:
Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(pt, 0));
}
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number, "No csdirectorin typemap defined for %s\n", SwigType_str(pt, 0));
Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number, "No csdirectorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(pt, 0));
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
@ -3493,11 +3519,13 @@ public:
} else {
if (!desc_tm) {
Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap defined for %s\n", SwigType_str(c_param_type, 0));
"No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(c_param_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
p = nextSibling(p);
} else if (!tm) {
Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap defined for argument %s\n", SwigType_str(pt, 0));
"No or improper directorin typemap defined for argument %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
p = nextSibling(p);
}
@ -3506,7 +3534,8 @@ public:
Delete(tp);
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(pt, 0));
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
p = nextSibling(p);
}
@ -3528,9 +3557,8 @@ public:
Printf(declaration, " virtual %s", target);
Delete(target);
// Get any Java exception classes in the throws typemap
// Add any exception specifications to the methods in the director class
ParmList *throw_parm_list = NULL;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
int gencomma = 0;
@ -3541,13 +3569,10 @@ public:
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
addThrows(n, "tmap:throws", p);
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
}
Printf(w->def, "%s", SwigType_str(Getattr(p, "type"), 0));
Printf(declaration, "%s", SwigType_str(Getattr(p, "type"), 0));
}
@ -3570,7 +3595,7 @@ public:
String *upcall = NewStringf("%s(%s)", symname, imcall_args);
if (!is_void) {
Parm *tp = NewParmFromNode(returntype, empty_str, n);
Parm *tp = NewParm(returntype, empty_str, n);
if ((tm = Swig_typemap_lookup("csdirectorout", tp, "", 0))) {
substituteClassname(returntype, tm);
@ -3596,18 +3621,17 @@ public:
if (!is_void) {
String *jresult_str = NewString("jresult");
String *result_str = NewString("c_result");
Parm *tp = NewParmFromNode(returntype, result_str, n);
Parm *tp = NewParm(returntype, result_str, n);
/* Copy jresult into c_result... */
if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) {
addThrows(n, "tmap:directorout", tp);
Replaceall(tm, "$input", jresult_str);
Replaceall(tm, "$result", result_str);
Printf(w->code, "%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0),
SwigType_namestr(c_classname), SwigType_namestr(name));
"Unable to use return type %s used in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
@ -3818,7 +3842,7 @@ public:
Node *disconn_attr = NewHash();
String *disconn_methodname = NULL;
disconn_tm = typemapLookup("directordisconnect", full_classname, WARN_NONE, disconn_attr);
disconn_tm = typemapLookup(n, "directordisconnect", full_classname, WARN_NONE, disconn_attr);
disconn_methodname = Getattr(disconn_attr, "tmap:directordisconnect:methodname");
Printv(w->code, "}\n", NIL);

View file

@ -204,7 +204,7 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
* emit_num_arguments()
*
* Calculate the total number of arguments. This function is safe for use
* with multi-valued typemaps which may change the number of arguments in
* with multi-argument typemaps which may change the number of arguments in
* strange ways.
* ----------------------------------------------------------------------------- */
@ -236,7 +236,7 @@ int emit_num_arguments(ParmList *parms) {
* emit_num_required()
*
* Computes the number of required arguments. This function is safe for
* use with multi-valued typemaps and knows how to skip over everything
* use with multi-argument typemaps and knows how to skip over everything
* properly. Note that parameters with default values are counted unless
* the compact default args option is on.
* ----------------------------------------------------------------------------- */

View file

@ -1411,16 +1411,18 @@ public:
}
{
/* Hack alert: will cleanup later -- Dave */
Node *n = NewHash();
Setattr(n, "name", var_name);
Setattr(n, "sym:name", iname);
Setattr(n, "type", nctype);
SetFlag(n, "feature:immutable");
Node *nn = NewHash();
Setfile(nn, Getfile(n));
Setline(nn, Getline(n));
Setattr(nn, "name", var_name);
Setattr(nn, "sym:name", iname);
Setattr(nn, "type", nctype);
SetFlag(nn, "feature:immutable");
if (constasvar) {
SetFlag(n, "feature:constasvar");
SetFlag(nn, "feature:constasvar");
}
variableWrapper(n);
Delete(n);
variableWrapper(nn);
Delete(nn);
}
Delete(var_name);
Delete(nctype);

View file

@ -51,6 +51,7 @@ class JAVA:public Language {
String *imclass_name; // intermediary class name
String *module_class_name; // module class name
String *constants_interface_name; // constants interface name
String *imclass_class_code; // intermediary class code
String *proxy_class_def;
String *proxy_class_code;
@ -87,13 +88,6 @@ class JAVA:public Language {
enum EnumFeature { SimpleEnum, TypeunsafeEnum, TypesafeEnum, ProperEnum };
static Parm *NewParmFromNode(SwigType *type, const_String_or_char_ptr name, Node *n) {
Parm *p = NewParm(type, name);
Setfile(p, Getfile(n));
Setline(p, Getline(n));
return p;
}
public:
/* -----------------------------------------------------------------------------
@ -125,6 +119,7 @@ public:
member_func_flag(false),
imclass_name(NULL),
module_class_name(NULL),
constants_interface_name(NULL),
imclass_class_code(NULL),
proxy_class_def(NULL),
proxy_class_code(NULL),
@ -349,6 +344,11 @@ public:
else
module_class_name = Copy(Getattr(n, "name"));
}
constants_interface_name = NewStringf("%sConstants", module_class_name);
// module class and intermediary classes are always created
addSymbol(imclass_name, n);
addSymbol(module_class_name, n);
imclass_class_code = NewString("");
proxy_class_def = NewString("");
@ -413,10 +413,10 @@ public:
Printf(wrapper_name, "Java_%s%s_%%f", Char(jnipackage), jniname);
Delete(jniname);
Swig_name_register((char *) "wrapper", Char(wrapper_name));
Swig_name_register("wrapper", Char(wrapper_name));
if (old_variable_names) {
Swig_name_register((char *) "set", (char *) "set_%v");
Swig_name_register((char *) "get", (char *) "get_%v");
Swig_name_register("set", "set_%v");
Swig_name_register("get", "get_%v");
}
Delete(wrapper_name);
@ -512,12 +512,12 @@ public:
Printf(f_module, "extends %s ", module_baseclass);
if (Len(module_interfaces) > 0) {
if (Len(module_class_constants_code) != 0)
Printv(f_module, "implements ", Getattr(n, "name"), "Constants, ", module_interfaces, " ", NIL);
Printv(f_module, "implements ", constants_interface_name, ", ", module_interfaces, " ", NIL);
else
Printv(f_module, "implements ", module_interfaces, " ", NIL);
} else {
if (Len(module_class_constants_code) != 0)
Printv(f_module, "implements ", Getattr(n, "name"), "Constants ", NIL);
Printv(f_module, "implements ", constants_interface_name, " ", NIL);
}
Printf(f_module, "{\n");
@ -537,7 +537,7 @@ public:
// Generate the Java constants interface
if (Len(module_class_constants_code) != 0) {
String *filen = NewStringf("%s%sConstants.java", SWIG_output_directory(), module_class_name);
String *filen = NewStringf("%s%s.java", SWIG_output_directory(), constants_interface_name);
File *f_module = NewFile(filen, "w", SWIG_output_files());
if (!f_module) {
FileErrorDisplay(filen);
@ -556,7 +556,7 @@ public:
if (module_imports)
Printf(f_module, "%s\n", module_imports);
Printf(f_module, "public interface %sConstants {\n", module_class_name);
Printf(f_module, "public interface %s {\n", constants_interface_name);
// Write out all the global constants
Printv(f_module, module_class_constants_code, NIL);
@ -621,6 +621,8 @@ public:
imclass_class_modifiers = NULL;
Delete(module_class_name);
module_class_name = NULL;
Delete(constants_interface_name);
constants_interface_name = NULL;
Delete(module_class_code);
module_class_code = NULL;
Delete(module_baseclass);
@ -750,7 +752,7 @@ public:
virtual int nativeWrapper(Node *n) {
String *wrapname = Getattr(n, "wrap:name");
if (!addSymbol(wrapname, n))
if (!addSymbol(wrapname, n, imclass_name))
return SWIG_ERROR;
if (Getattr(n, "type")) {
@ -792,7 +794,7 @@ public:
bool is_destructor = (Cmp(Getattr(n, "nodeType"), "destructor") == 0);
if (!Getattr(n, "sym:overloaded")) {
if (!addSymbol(Getattr(n, "sym:name"), n))
if (!addSymbol(Getattr(n, "sym:name"), n, imclass_name))
return SWIG_ERROR;
}
@ -984,7 +986,7 @@ public:
// Get any Java exception classes in the throws typemap
ParmList *throw_parm_list = NULL;
if ((throw_parm_list = Getattr(n, "throws"))) {
if ((throw_parm_list = Getattr(n, "catchlist"))) {
Swig_typemap_attach_parms("throws", throw_parm_list, f);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
@ -1175,11 +1177,11 @@ public:
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum
// Pure Java baseclass and interfaces
const String *pure_baseclass = typemapLookup("javabase", typemap_lookup_type, WARN_NONE);
const String *pure_interfaces = typemapLookup("javainterfaces", typemap_lookup_type, WARN_NONE);
const String *pure_baseclass = typemapLookup(n, "javabase", typemap_lookup_type, WARN_NONE);
const String *pure_interfaces = typemapLookup(n, "javainterfaces", typemap_lookup_type, WARN_NONE);
// Emit the enum
Printv(enum_code, typemapLookup("javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really)
Printv(enum_code, typemapLookup(n, "javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really)
" ", symname, *Char(pure_baseclass) ? // Bases
" extends " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces
" implements " : "", pure_interfaces, " {\n", NIL);
@ -1200,8 +1202,8 @@ public:
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum
// Finish the enum declaration
// Typemaps are used to generate the enum definition in a similar manner to proxy classes.
Printv(enum_code, (enum_feature == ProperEnum) ? ";\n" : "", typemapLookup("javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class
typemapLookup("javacode", typemap_lookup_type, WARN_NONE), // extra Java code
Printv(enum_code, (enum_feature == ProperEnum) ? ";\n" : "", typemapLookup(n, "javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class
typemapLookup(n, "javacode", typemap_lookup_type, WARN_NONE), // extra Java code
"}", NIL);
Replaceall(enum_code, "$javaclassname", symname);
@ -1238,7 +1240,7 @@ public:
if (Len(package) > 0)
Printf(f_enum, "package %s;\n", package);
Printv(f_enum, typemapLookup("javaimports", typemap_lookup_type, WARN_NONE), // Import statements
Printv(f_enum, typemapLookup(n, "javaimports", typemap_lookup_type, WARN_NONE), // Import statements
"\n", enum_code, "\n", NIL);
Printf(f_enum, "\n");
@ -1271,6 +1273,9 @@ public:
String *symname = Getattr(n, "sym:name");
String *value = Getattr(n, "value");
String *name = Getattr(n, "name");
Node *parent = parentNode(n);
int unnamedinstance = GetFlag(parent, "unnamedinstance");
String *parent_name = Getattr(parent, "name");
String *tmpValue;
// Strange hack from parent method
@ -1282,12 +1287,12 @@ public:
Setattr(n, "value", tmpValue);
{
EnumFeature enum_feature = decodeEnumFeature(parentNode(n));
EnumFeature enum_feature = decodeEnumFeature(parent);
if ((enum_feature == ProperEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) {
if ((enum_feature == ProperEnum) && parent_name && !unnamedinstance) {
// Wrap (non-anonymous) C/C++ enum with a proper Java enum
// Emit the enum item.
if (!Getattr(n, "_last")) // Only the first enum item has this attribute set
if (!GetFlag(n, "firstenumitem"))
Printf(enum_code, ",\n");
Printf(enum_code, " %s", symname);
if (Getattr(n, "enumvalue")) {
@ -1297,18 +1302,16 @@ public:
}
} else {
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern
const String *parent_name = Getattr(parentNode(n), "name");
String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int");
const String *tm = typemapLookup("jstype", typemap_lookup_type, WARN_JAVA_TYPEMAP_JSTYPE_UNDEF);
String *return_type = Copy(tm);
Delete(typemap_lookup_type);
typemap_lookup_type = NULL;
String *type = Getattr(n, "type"); /* should be int unless explicitly specified in a C++0x enum class */
SwigType *typemap_lookup_type = parent_name ? parent_name : type;
const String *tm = typemapLookup(n, "jstype", typemap_lookup_type, WARN_JAVA_TYPEMAP_JSTYPE_UNDEF);
String *return_type = Copy(tm);
const String *methodmods = Getattr(n, "feature:java:methodmodifiers");
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
if ((enum_feature == TypesafeEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) {
// Wrap (non-anonymouse) enum using the typesafe enum pattern
if ((enum_feature == TypesafeEnum) && parent_name && !unnamedinstance) {
// Wrap (non-anonymous) enum using the typesafe enum pattern
if (Getattr(n, "enumvalue")) {
String *value = enumValue(n);
Printf(enum_code, " %s final static %s %s = new %s(\"%s\", %s);\n", methodmods, return_type, symname, return_type, symname, value);
@ -1327,9 +1330,9 @@ public:
}
// Add the enum value to the comma separated list being constructed in the enum declaration.
String *enumvalues = Getattr(parentNode(n), "enumvalues");
String *enumvalues = Getattr(parent, "enumvalues");
if (!enumvalues)
Setattr(parentNode(n), "enumvalues", Copy(symname));
Setattr(parent, "enumvalues", Copy(symname));
else
Printv(enumvalues, ", ", symname, NIL);
}
@ -1358,11 +1361,13 @@ public:
String *return_type = NewString("");
String *constants_code = NewString("");
if (!addSymbol(symname, n))
return SWIG_ERROR;
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
const String *itemname = (proxy_flag && wrapping_member_flag) ? variable_name : symname;
String *scope = proxy_flag && wrapping_member_flag ? proxy_class_name : constants_interface_name;
if (!addSymbol(itemname, n, scope))
return SWIG_ERROR;
// The %javaconst feature determines how the constant value is obtained
int const_feature_flag = GetFlag(n, "feature:java:const");
@ -1397,7 +1402,6 @@ public:
Setattr(n, "value", new_value);
}
const String *itemname = (proxy_flag && wrapping_member_flag) ? variable_name : symname;
const String *methodmods = Getattr(n, "feature:java:methodmodifiers");
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
@ -1429,7 +1433,14 @@ public:
enum_constant_flag = false;
} else {
// Alternative constant handling will use the C syntax to make a true Java constant and hope that it compiles as Java code
Printf(constants_code, "%s;\n", Getattr(n, "value"));
if (Getattr(n, "wrappedasconstant")) {
if (SwigType_type(t) == T_CHAR)
Printf(constants_code, "\'%s\';\n", Getattr(n, "staticmembervariableHandler:value"));
else
Printf(constants_code, "%s;\n", Getattr(n, "staticmembervariableHandler:value"));
} else {
Printf(constants_code, "%s;\n", Getattr(n, "value"));
}
}
// Emit the generated code to appropriate place
@ -1564,12 +1575,12 @@ public:
String *c_baseclass = NULL;
String *baseclass = NULL;
String *c_baseclassname = NULL;
String *typemap_lookup_type = Getattr(n, "classtypeobj");
SwigType *typemap_lookup_type = Getattr(n, "classtypeobj");
bool feature_director = Swig_directorclass(n) ? true : false;
// Inheritance from pure Java classes
Node *attributes = NewHash();
const String *pure_baseclass = typemapLookup("javabase", typemap_lookup_type, WARN_NONE, attributes);
const String *pure_baseclass = typemapLookup(n, "javabase", typemap_lookup_type, WARN_NONE, attributes);
bool purebase_replace = GetFlag(attributes, "tmap:javabase:replace") ? true : false;
bool purebase_notderived = GetFlag(attributes, "tmap:javabase:notderived") ? true : false;
Delete(attributes);
@ -1623,15 +1634,15 @@ public:
}
// Pure Java interfaces
const String *pure_interfaces = typemapLookup("javainterfaces", typemap_lookup_type, WARN_NONE);
const String *pure_interfaces = typemapLookup(n, "javainterfaces", typemap_lookup_type, WARN_NONE);
// Start writing the proxy class
Printv(proxy_class_def, typemapLookup("javaimports", typemap_lookup_type, WARN_NONE), // Import statements
"\n", typemapLookup("javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
Printv(proxy_class_def, typemapLookup(n, "javaimports", typemap_lookup_type, WARN_NONE), // Import statements
"\n", typemapLookup(n, "javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" $javaclassname", // Class name and bases
(*Char(wanted_base)) ? " extends " : "", wanted_base, *Char(pure_interfaces) ? // Pure Java interfaces
" implements " : "", pure_interfaces, " {", derived ? typemapLookup("javabody_derived", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF) : // main body of class
typemapLookup("javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class
" implements " : "", pure_interfaces, " {", derived ? typemapLookup(n, "javabody_derived", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF) : // main body of class
typemapLookup(n, "javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class
NIL);
// C++ destructor is wrapped by the delete method
@ -1642,11 +1653,11 @@ public:
String *destruct_methodname = NULL;
String *destruct_methodmodifiers = NULL;
if (derived) {
tm = typemapLookup("javadestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
tm = typemapLookup(n, "javadestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:javadestruct_derived:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:javadestruct_derived:methodmodifiers");
} else {
tm = typemapLookup("javadestruct", typemap_lookup_type, WARN_NONE, attributes);
tm = typemapLookup(n, "javadestruct", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:javadestruct:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:javadestruct:methodmodifiers");
}
@ -1664,7 +1675,7 @@ public:
if (tm) {
// Finalize method
if (*Char(destructor_call)) {
Printv(proxy_class_def, typemapLookup("javafinalize", typemap_lookup_type, WARN_NONE), NIL);
Printv(proxy_class_def, typemapLookup(n, "javafinalize", typemap_lookup_type, WARN_NONE), NIL);
}
// delete method
Printv(destruct, tm, NIL);
@ -1685,9 +1696,9 @@ public:
release_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, false)", imclass_name, proxy_class_name);
take_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, true)", imclass_name, proxy_class_name);
emitCodeTypemap(false, typemap_lookup_type, "directordisconnect", "methodname", destruct_jnicall);
emitCodeTypemap(false, typemap_lookup_type, "directorowner_release", "methodname", release_jnicall);
emitCodeTypemap(false, typemap_lookup_type, "directorowner_take", "methodname", take_jnicall);
emitCodeTypemap(n, false, typemap_lookup_type, "directordisconnect", "methodname", destruct_jnicall);
emitCodeTypemap(n, false, typemap_lookup_type, "directorowner_release", "methodname", release_jnicall);
emitCodeTypemap(n, false, typemap_lookup_type, "directorowner_take", "methodname", take_jnicall);
Delete(destruct_jnicall);
Delete(release_jnicall);
@ -1698,7 +1709,7 @@ public:
Delete(destruct);
// Emit extra user code
Printv(proxy_class_def, typemapLookup("javacode", typemap_lookup_type, WARN_NONE), // extra Java code
Printv(proxy_class_def, typemapLookup(n, "javacode", typemap_lookup_type, WARN_NONE), // extra Java code
"\n", NIL);
// Substitute various strings into the above template
@ -1977,7 +1988,7 @@ public:
if (qualifier)
SwigType_push(this_type, qualifier);
SwigType_add_pointer(this_type);
Parm *this_parm = NewParm(this_type, name);
Parm *this_parm = NewParm(this_type, name, n);
Swig_typemap_attach_parms("jtype", this_parm, NULL);
Swig_typemap_attach_parms("jstype", this_parm, NULL);
@ -2289,7 +2300,7 @@ public:
/* Insert the javaconstruct typemap, doing the replacement for $directorconnect, as needed */
Hash *attributes = NewHash();
String *construct_tm = Copy(typemapLookup("javaconstruct", Getattr(n, "name"),
String *construct_tm = Copy(typemapLookup(n, "javaconstruct", Getattr(n, "name"),
WARN_JAVA_TYPEMAP_JAVACONSTRUCT_UNDEF, attributes));
if (construct_tm) {
if (!feature_director) {
@ -2607,6 +2618,16 @@ public:
Delete(func_name);
}
/*----------------------------------------------------------------------
* replaceSpecialVariables()
*--------------------------------------------------------------------*/
virtual void replaceSpecialVariables(String *method, String *tm, Parm *parm) {
(void)method;
SwigType *type = Getattr(parm, "type");
substituteClassname(type, tm);
}
/*----------------------------------------------------------------------
* decodeEnumFeature()
* Decode the possible enum features, which are one of:
@ -2704,16 +2725,16 @@ public:
/* -----------------------------------------------------------------------------
* substituteClassname()
*
* Substitute $javaclassname with the proxy class name for classes/structs/unions that SWIG knows about.
* Also substitutes enums with enum name.
* Substitute the special variable $javaclassname with the proxy class name for classes/structs/unions
* that SWIG knows about. Also substitutes enums with enum name.
* Otherwise use the $descriptor name for the Java class name. Note that the $&javaclassname substitution
* is the same as a $&descriptor substitution, ie one pointer added to descriptor name.
* Inputs:
* pt - parameter type
* tm - jstype typemap
* tm - typemap contents that might contain the special variable to be replaced
* jnidescriptor - if set, inner class names are separated with '$' otherwise a '.'
* Outputs:
* tm - jstype typemap with $javaclassname substitution
* tm - typemap contents complete with the special variable substitution
* Return:
* substitution_performed - flag indicating if a substitution was performed
* ----------------------------------------------------------------------------- */
@ -2819,6 +2840,10 @@ public:
* ----------------------------------------------------------------------------- */
void emitTypeWrapperClass(String *classname, SwigType *type) {
Node *n = NewHash();
Setfile(n, input_file);
Setline(n, line_number);
String *swigtype = NewString("");
String *filen = NewStringf("%s%s.java", SWIG_output_directory(), classname);
File *f_swigtype = NewFile(filen, "w", SWIG_output_files());
@ -2837,16 +2862,16 @@ public:
Printf(f_swigtype, "package %s;\n", package);
// Pure Java baseclass and interfaces
const String *pure_baseclass = typemapLookup("javabase", type, WARN_NONE);
const String *pure_interfaces = typemapLookup("javainterfaces", type, WARN_NONE);
const String *pure_baseclass = typemapLookup(n, "javabase", type, WARN_NONE);
const String *pure_interfaces = typemapLookup(n, "javainterfaces", type, WARN_NONE);
// Emit the class
Printv(swigtype, typemapLookup("javaimports", type, WARN_NONE), // Import statements
"\n", typemapLookup("javaclassmodifiers", type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
Printv(swigtype, typemapLookup(n, "javaimports", type, WARN_NONE), // Import statements
"\n", typemapLookup(n, "javaclassmodifiers", type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" $javaclassname", // Class name and bases
*Char(pure_baseclass) ? " extends " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces
" implements " : "", pure_interfaces, " {", typemapLookup("javabody", type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class
typemapLookup("javacode", type, WARN_NONE), // extra Java code
" implements " : "", pure_interfaces, " {", typemapLookup(n, "javabody", type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class
typemapLookup(n, "javacode", type, WARN_NONE), // extra Java code
"}\n", "\n", NIL);
Replaceall(swigtype, "$javaclassname", classname);
@ -2856,29 +2881,34 @@ public:
Close(f_swigtype);
Delete(swigtype);
Delete(n);
}
/* -----------------------------------------------------------------------------
* typemapLookup()
* n - for input only and must contain info for Getfile(n) and Getline(n) to work
* tmap_method - typemap method name
* type - typemap type to lookup
* warning - warning number to issue if no typemaps found
* typemap_attributes - the typemap attributes are attached to this node and will
* also be used for temporary storage if non null
* return is never NULL, unlike Swig_typemap_lookup()
* ----------------------------------------------------------------------------- */
const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes = NULL) {
String *tm = NULL;
const String *code = NULL;
if ((tm = Swig_typemap_search(op, type, NULL, NULL))) {
code = Getattr(tm, "code");
if (typemap_attributes)
Swig_typemap_attach_kwargs(tm, op, typemap_attributes);
}
if (!code) {
code = empty_string;
const String *typemapLookup(Node *n, const_String_or_char_ptr tmap_method, SwigType *type, int warning, Node *typemap_attributes = 0) {
Node *node = !typemap_attributes ? NewHash() : typemap_attributes;
Setattr(node, "type", type);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup(tmap_method, node, "", 0);
if (!tm) {
tm = empty_string;
if (warning != WARN_NONE)
Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type);
Swig_warning(warning, Getfile(n), Getline(n), "No %s typemap defined for %s\n", tmap_method, SwigType_str(type, 0));
}
return code ? code : empty_string;
if (!typemap_attributes)
Delete(node);
return tm;
}
/* -----------------------------------------------------------------------------
@ -3187,8 +3217,7 @@ public:
* typemaps.
*--------------------------------------------------------------------*/
void
emitCodeTypemap(bool derived, String *lookup_type, const String *typemap, const String *methodname, const String *jnicall) {
void emitCodeTypemap(Node *n, bool derived, SwigType *lookup_type, const String *typemap, const String *methodname, const String *jnicall) {
const String *tm = NULL;
Node *tmattrs = NewHash();
String *lookup_tmname = NewString(typemap);
@ -3199,7 +3228,7 @@ public:
Append(lookup_tmname, "_derived");
}
tm = typemapLookup(lookup_tmname, lookup_type, WARN_NONE, tmattrs);
tm = typemapLookup(n, lookup_tmname, lookup_type, WARN_NONE, tmattrs);
method_attr_name = NewStringf("tmap:%s:%s", lookup_tmname, methodname);
method_attr = Getattr(tmattrs, method_attr_name);
@ -3367,7 +3396,7 @@ public:
}
/* Create the intermediate class wrapper */
Parm *tp = NewParmFromNode(returntype, empty_str, n);
Parm *tp = NewParm(returntype, empty_str, n);
tm = Swig_typemap_lookup("jtype", tp, "", 0);
if (tm) {
@ -3379,7 +3408,7 @@ public:
String *cdesc = NULL;
SwigType *covariant = Getattr(n, "covariant");
SwigType *adjustedreturntype = covariant ? covariant : returntype;
Parm *adjustedreturntypeparm = NewParmFromNode(adjustedreturntype, empty_str, n);
Parm *adjustedreturntypeparm = NewParm(adjustedreturntype, empty_str, n);
if ((tm = Swig_typemap_lookup("directorin", adjustedreturntypeparm, "", 0))
&& (cdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor"))) {
@ -3391,17 +3420,18 @@ public:
Append(classret_desc, jnidesc_canon);
Delete(jnidesc_canon);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "No or improper directorin typemap defined for %s\n", SwigType_str(returntype, 0));
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
/* Get the JNI field descriptor for this return type, add the JNI field descriptor
to jniret_desc */
Parm *retpm = NewParmFromNode(returntype, empty_str, n);
Parm *retpm = NewParm(returntype, empty_str, n);
if ((c_ret_type = Swig_typemap_lookup("jni", retpm, "", 0))) {
Parm *tp = NewParmFromNode(c_ret_type, empty_str, n);
Parm *tp = NewParm(c_ret_type, empty_str, n);
if (!is_void && !ignored_method) {
String *jretval_decl = NewStringf("%s jresult", c_ret_type);
@ -3422,13 +3452,15 @@ public:
Delete(jnidesc_canon);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap defined for %s\n", SwigType_str(c_ret_type, 0));
"No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(c_ret_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
Delete(tp);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s\n", SwigType_str(returntype, 0));
Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
@ -3501,7 +3533,7 @@ public:
}
/* Start the Java field descriptor for the intermediate class's upcall (insert self object) */
Parm *tp = NewParmFromNode(c_classname, empty_str, n);
Parm *tp = NewParm(c_classname, empty_str, n);
String *jdesc;
if ((tm = Swig_typemap_lookup("directorin", tp, "", 0))
@ -3512,8 +3544,8 @@ public:
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap for type %s used in director method %s::%s\n", SwigType_str(type, 0), SwigType_namestr(c_classname),
SwigType_namestr(name));
"No or improper directorin typemap for type %s for use in %s::%s (skipping director method)\n",
SwigType_str(type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
@ -3543,7 +3575,7 @@ public:
/* Get parameter's intermediary C type */
if ((c_param_type = Getattr(p, "tmap:jni"))) {
Parm *tp = NewParmFromNode(c_param_type, empty_str, n);
Parm *tp = NewParm(c_param_type, empty_str, n);
String *desc_tm = NULL, *jdesc = NULL, *cdesc = NULL;
/* Add to local variables */
@ -3599,11 +3631,13 @@ public:
Append(classdesc, jni_canon);
Delete(jni_canon);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number, "No javadirectorin typemap defined for %s\n", SwigType_str(pt, 0));
Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number, "No javadirectorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(pt, 0));
Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
@ -3613,19 +3647,23 @@ public:
} else {
if (!desc_tm) {
Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap defined for %s\n", SwigType_str(c_param_type, 0));
"No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(c_param_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
p = nextSibling(p);
} else if (!jdesc) {
Swig_warning(WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC, input_file, line_number,
"Missing JNI descriptor in directorin typemap defined for %s\n", SwigType_str(c_param_type, 0));
"Missing JNI descriptor in directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(c_param_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
p = Getattr(p, "tmap:directorin:next");
} else if (!tm) {
Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap defined for argument %s\n", SwigType_str(pt, 0));
"No or improper directorin typemap defined for argument %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
p = nextSibling(p);
} else if (!cdesc) {
Swig_warning(WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC, input_file, line_number,
"Missing JNI descriptor in directorin typemap defined for %s\n", SwigType_str(pt, 0));
"Missing JNI descriptor in directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
p = Getattr(p, "tmap:directorin:next");
}
@ -3634,7 +3672,8 @@ public:
Delete(tp);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s\n", SwigType_str(pt, 0));
Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
p = nextSibling(p);
}
@ -3655,6 +3694,7 @@ public:
Printf(declaration, " virtual %s", target);
Delete(target);
// Add any exception specifications to the methods in the director class
// Get any Java exception classes in the throws typemap
ParmList *throw_parm_list = NULL;
@ -3691,8 +3731,11 @@ public:
String *upcall = NewStringf("self.%s(%s)", symname, imcall_args);
// Handle exception classes specified in the "except" feature's "throws" attribute
addThrows(n, "feature:except", n);
if (!is_void) {
Parm *tp = NewParmFromNode(returntype, empty_str, n);
Parm *tp = NewParm(returntype, empty_str, n);
if ((tm = Swig_typemap_lookup("javadirectorout", tp, "", 0))) {
addThrows(n, "tmap:javadirectorout", tp);
@ -3736,7 +3779,7 @@ public:
if (!is_void) {
String *jresult_str = NewString("jresult");
String *result_str = NewString("c_result");
Parm *tp = NewParmFromNode(returntype, result_str, n);
Parm *tp = NewParm(returntype, result_str, n);
/* Copy jresult into c_result... */
if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) {
@ -3746,8 +3789,8 @@ public:
Printf(w->code, "%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0),
SwigType_namestr(c_classname), SwigType_namestr(name));
"Unable to use return type %s used in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
@ -3829,7 +3872,7 @@ public:
SwigType_add_pointer(jenv_type);
p = NewParmFromNode(jenv_type, NewString("jenv"), n);
p = NewParm(jenv_type, NewString("jenv"), n);
Setattr(p, "arg:byname", "1");
set_nextSibling(p, NULL);
@ -3866,7 +3909,7 @@ public:
String *jenv_type = NewString("JNIEnv");
SwigType_add_pointer(jenv_type);
p = NewParmFromNode(jenv_type, NewString("jenv"), n);
p = NewParm(jenv_type, NewString("jenv"), n);
set_nextSibling(p, parms);
parms = p;
@ -3973,7 +4016,7 @@ public:
Node *disconn_attr = NewHash();
String *disconn_methodname = NULL;
disconn_tm = typemapLookup("directordisconnect", full_classname, WARN_NONE, disconn_attr);
disconn_tm = typemapLookup(n, "directordisconnect", full_classname, WARN_NONE, disconn_attr);
disconn_methodname = Getattr(disconn_attr, "tmap:directordisconnect:methodname");
Printv(w->code, " swig_disconnect_director_self(\"", disconn_methodname, "\");\n", "}\n", NIL);

View file

@ -22,6 +22,7 @@ static int director_mode = 0;
static int director_protected_mode = 1;
static int all_protected_mode = 0;
static int naturalvar_mode = 0;
Language* Language::this_ = 0;
/* Set director_protected_mode */
void Wrapper_director_mode_set(int flag) {
@ -50,6 +51,9 @@ extern "C" {
int Swig_all_protected_mode() {
return all_protected_mode;
}
void Language_replace_special_variables(String *method, String *tm, Parm *parm) {
Language::instance()->replaceSpecialVariables(method, tm, parm);
}
}
/* Some status variables used during parsing */
@ -175,7 +179,7 @@ int Dispatcher::emit_one(Node *n) {
} else if (strcmp(tag, "types") == 0) {
ret = typesDirective(n);
} else {
Printf(stderr, "%s:%d. Unrecognized parse tree node type '%s'\n", input_file, line_number, tag);
Swig_error(input_file, line_number, "Unrecognized parse tree node type '%s'\n", tag);
ret = SWIG_ERROR;
}
if (wrn) {
@ -307,13 +311,15 @@ Language::Language():
none_comparison(NewString("$arg != 0")),
director_ctor_code(NewString("")),
director_prot_ctor_code(0),
symbols(NewHash()),
symtabs(NewHash()),
classtypes(NewHash()),
enumtypes(NewHash()),
overloading(0),
multiinput(0),
cplus_runtime(0),
directors(0) {
Hash *symbols = NewHash();
Setattr(symtabs, "", symbols); // create top level/global symbol table scope
argc_template_string = NewString("argc");
argv_template_string = NewString("argv[%d]");
@ -327,14 +333,17 @@ directors(0) {
director_prot_ctor_code = 0;
director_multiple_inheritance = 1;
director_language = 0;
assert(!this_);
this_ = this;
}
Language::~Language() {
Delete(symbols);
Delete(symtabs);
Delete(classtypes);
Delete(enumtypes);
Delete(director_ctor_code);
Delete(none_comparison);
this_ = 0;
}
/* ----------------------------------------------------------------------
@ -779,7 +788,7 @@ int Language::typemapcopyDirective(Node *n) {
Swig_error(input_file, line_number, "Can't copy typemap. Number of types differ.\n");
} else {
if (Swig_typemap_copy(method, pattern, npattern) < 0) {
Swig_error(input_file, line_number, "Can't copy typemap.\n");
Swig_error(input_file, line_number, "Can't copy typemap (%s) %s = %s\n", method, ParmList_str(pattern), ParmList_str(npattern));
}
}
items = nextSibling(items);
@ -878,30 +887,8 @@ int Language::cDeclaration(Node *n) {
if (over)
over = first_nontemplate(over);
if (over && (over != n)) {
SwigType *tc = Copy(decl);
SwigType *td = SwigType_pop_function(tc);
String *oname;
String *cname;
if (CurrentClass) {
oname = NewStringf("%s::%s", ClassName, name);
cname = NewStringf("%s::%s", ClassName, Getattr(over, "name"));
} else {
oname = NewString(name);
cname = NewString(Getattr(over, "name"));
}
SwigType *tc2 = Copy(Getattr(over, "decl"));
SwigType *td2 = SwigType_pop_function(tc2);
Swig_warning(WARN_LANG_OVERLOAD_DECL, input_file, line_number, "Overloaded declaration ignored. %s\n", SwigType_str(td, SwigType_namestr(oname)));
Swig_warning(WARN_LANG_OVERLOAD_DECL, Getfile(over), Getline(over), "Previous declaration is %s\n", SwigType_str(td2, SwigType_namestr(cname)));
Delete(tc2);
Delete(td2);
Delete(tc);
Delete(td);
Delete(oname);
Delete(cname);
Swig_warning(WARN_LANG_OVERLOAD_DECL, input_file, line_number, "Overloaded declaration ignored. %s\n", Swig_name_decl(n));
Swig_warning(WARN_LANG_OVERLOAD_DECL, Getfile(over), Getline(over), "Previous declaration is %s\n", Swig_name_decl(over));
return SWIG_NOWRAP;
}
}
@ -919,7 +906,7 @@ int Language::cDeclaration(Node *n) {
Delete(ty);
ty = fullty;
fullty = 0;
ParmList *parms = SwigType_function_parms(ty);
ParmList *parms = SwigType_function_parms(ty, n);
Setattr(n, "parms", parms);
}
/* Transform the node into a 'function' node and emit */
@ -982,7 +969,7 @@ int Language::cDeclaration(Node *n) {
if (Strncmp(symname, "__dummy_", 8) == 0) {
SetFlag(n, "feature:ignore");
Swig_warning(WARN_LANG_TEMPLATE_METHOD_IGNORE, input_file, line_number,
"%%template() contains no name. Template method ignored: %s\n", SwigType_str(decl, SwigType_namestr(Getattr(n,"name"))));
"%%template() contains no name. Template method ignored: %s\n", Swig_name_decl(n));
}
}
if (!GetFlag(n, "feature:ignore"))
@ -1156,7 +1143,7 @@ int Language::callbackfunctionHandler(Node *n) {
Setattr(n, "type", cbty);
Setattr(n, "value", calltype);
Node *ns = Getattr(symbols, cbname);
Node *ns = symbolLookup(cbname);
if (!ns)
constantWrapper(n);
@ -1207,6 +1194,8 @@ int Language::memberfunctionHandler(Node *n) {
Setattr(cbn, "type", cbty);
Setattr(cbn, "value", cbvalue);
Setattr(cbn, "name", name);
Setfile(cbn, Getfile(n));
Setline(cbn, Getline(n));
memberconstantHandler(cbn);
Setattr(n, "feature:callback:name", Swig_name_member(ClassPrefix, cbname));
@ -1426,39 +1415,36 @@ int Language::membervariableHandler(Node *n) {
target = NewStringf("%s->%s", pname, name);
Delete(pname);
}
} else {
target = NewStringf("$extendgetcall"); // member variable access expanded later
tm = Swig_typemap_lookup("memberin", n, target, 0);
}
tm = Swig_typemap_lookup("memberin", n, target, 0);
int flags = Extend | SmartPointer | use_naturalvar_mode(n);
if (is_non_virtual_protected_access(n))
flags = flags | CWRAP_ALL_PROTECTED_ACCESS;
String *call = 0;
Swig_MembersetToFunction(n, ClassType, flags, &call);
Swig_MembersetToFunction(n, ClassType, flags);
Setattr(n, "memberset", "1");
if (!Extend) {
/* Check for a member in typemap here */
if (!tm) {
if (SwigType_isarray(type)) {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(type, 0));
make_set_wrapper = 0;
if (!tm) {
if (SwigType_isarray(type)) {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(type, 0));
make_set_wrapper = 0;
}
} else {
String *pname0 = Swig_cparm_name(0, 0);
String *pname1 = Swig_cparm_name(0, 1);
Replace(tm, "$source", pname1, DOH_REPLACE_ANY);
Replace(tm, "$target", target, DOH_REPLACE_ANY);
Replace(tm, "$input", pname1, DOH_REPLACE_ANY);
Replace(tm, "$self", pname0, DOH_REPLACE_ANY);
Setattr(n, "wrap:action", tm);
Delete(tm);
Delete(pname0);
Delete(pname1);
}
} else {
String *pname0 = Swig_cparm_name(0, 0);
String *pname1 = Swig_cparm_name(0, 1);
Replace(tm, "$source", pname1, DOH_REPLACE_ANY);
Replace(tm, "$target", target, DOH_REPLACE_ANY);
Replace(tm, "$input", pname1, DOH_REPLACE_ANY);
Replace(tm, "$self", pname0, DOH_REPLACE_ANY);
Replace(tm, "$extendgetcall", call, DOH_REPLACE_ANY);
Setattr(n, "wrap:action", tm);
Delete(tm);
Delete(pname0);
Delete(pname1);
Delete(target);
}
Delete(call);
Delete(target);
if (make_set_wrapper) {
Setattr(n, "sym:name", mrename_set);
functionWrapper(n);
@ -1500,7 +1486,7 @@ int Language::membervariableHandler(Node *n) {
Parm *p;
String *gname;
SwigType *vty;
p = NewParm(type, 0);
p = NewParm(type, 0, n);
gname = NewStringf(AttributeFunctionGet, symname);
if (!Extend) {
ActionFunc = Copy(Swig_cmemberget_call(name, type));
@ -1926,12 +1912,14 @@ int Language::classDirectorDisown(Node *n) {
String *type = NewString(ClassType);
String *name = NewString("self");
SwigType_add_pointer(type);
Parm *p = NewParm(type, name);
Parm *p = NewParm(type, name, n);
Delete(name);
Delete(type);
type = NewString("void");
String *action = NewString("");
Printv(action, "{\n", "Swig::Director *director = dynamic_cast<Swig::Director *>(arg1);\n", "if (director) director->swig_disown();\n", "}\n", NULL);
Setfile(disown, Getfile(n));
Setline(disown, Getline(n));
Setattr(disown, "wrap:action", action);
Setattr(disown, "name", mrename);
Setattr(disown, "sym:name", mrename);
@ -2184,7 +2172,7 @@ static void addCopyConstructor(Node *n) {
if (!symname) {
symname = Copy(csymname);
}
Parm *p = NewParm(cc, "other");
Parm *p = NewParm(cc, "other", n);
Setattr(cn, "name", name);
Setattr(cn, "sym:name", symname);
@ -2477,7 +2465,7 @@ int Language::classHandler(Node *n) {
continue;
String *methodname = Getattr(method, "sym:name");
String *wrapname = NewStringf("%s_%s", symname, methodname);
if (!Getattr(symbols, wrapname) && (!is_public(method))) {
if (!symbolLookup(wrapname, "") && (!is_public(method))) {
Node *m = Copy(method);
Setattr(m, "director", "1");
Setattr(m, "parentNode", n);
@ -2930,27 +2918,71 @@ void Language::main(int argc, char *argv[]) {
/* -----------------------------------------------------------------------------
* Language::addSymbol()
*
* Adds a symbol entry. Returns 1 if the symbol is added successfully.
* Adds a symbol entry into the target language symbol tables.
* Returns 1 if the symbol is added successfully.
* Prints an error message and returns 0 if a conflict occurs.
* The scope is optional for target languages and if supplied must be a fully
* resolved scope and the symbol s must not contain any scope qualifiers.
* ----------------------------------------------------------------------------- */
int
Language::addSymbol(const String *s, const Node *n) {
Node *c = Getattr(symbols, s);
if (c && (c != n)) {
Swig_error(input_file, line_number, "'%s' is multiply defined in the generated module.\n", s);
Swig_error(Getfile(c), Getline(c), "Previous declaration of '%s'\n", s);
return 0;
int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) {
Hash *symbols = Getattr(symtabs, scope);
if (!symbols) {
// New scope which has not been added by the target language - lazily created.
symbols = NewHash();
Setattr(symtabs, scope, symbols);
// Add the new scope as a symbol in the top level scope.
// Alternatively the target language must add it in before attempting to add symbols into the scope.
const_String_or_char_ptr top_scope = "";
Hash *topscope_symbols = Getattr(symtabs, top_scope);
Setattr(topscope_symbols, scope, NewHash());
} else {
Node *c = Getattr(symbols, s);
if (c && (c != n)) {
Swig_error(input_file, line_number, "'%s' is multiply defined in the generated target language module.\n", s);
Swig_error(Getfile(c), Getline(c), "Previous declaration of '%s'\n", s);
return 0;
}
}
Setattr(symbols, s, n);
return 1;
}
/* -----------------------------------------------------------------------------
* Language::dumpSymbols()
* ----------------------------------------------------------------------------- */
void Language::dumpSymbols() {
Printf(stdout, "LANGUAGE SYMBOLS start =======================================\n");
Node *table = symtabs;
Iterator ki = First(table);
while (ki.key) {
String *k = ki.key;
Printf(stdout, "===================================================\n");
Printf(stdout, "%s -\n", k);
{
Symtab *symtab = Getattr(table, k);
Iterator it = First(symtab);
while (it.key) {
String *symname = it.key;
Printf(stdout, " %s\n", symname);
it = Next(it);
}
}
ki = Next(ki);
}
Printf(stdout, "LANGUAGE SYMBOLS finish =======================================\n");
}
/* -----------------------------------------------------------------------------
* Language::symbolLookup()
* ----------------------------------------------------------------------------- */
Node *Language::symbolLookup(String *s) {
Node *Language::symbolLookup(String *s, const_String_or_char_ptr scope) {
Hash *symbols = Getattr(symtabs, scope);
return Getattr(symbols, s);
}
@ -3427,6 +3459,24 @@ String *Language::defaultExternalRuntimeFilename() {
return 0;
}
/* -----------------------------------------------------------------------------
* Language::replaceSpecialVariables()
* Language modules should implement this if special variables are to be handled
* correctly in the $typemap(...) special variable macro.
* method - typemap method name
* tm - string containing typemap contents
* parm - a parameter describing the typemap type to be handled
* ----------------------------------------------------------------------------- */
void Language::replaceSpecialVariables(String *method, String *tm, Parm *parm) {
(void)method;
(void)tm;
(void)parm;
}
Language *Language::instance() {
return this_;
}
Hash *Language::getClassHash() const {
return classhash;
}

View file

@ -29,7 +29,7 @@ char cvsroot_main_cxx[] = "$Id$";
// Global variables
Language *lang; // Language method
static Language *lang = 0; // Language method
int CPlusPlus = 0;
int Extend = 0; // Extend flag
int ForceExtern = 0; // Force extern mode
@ -66,11 +66,17 @@ static const char *usage1 = (const char *) "\
-copyright - Display copyright notices\n\
-debug-classes - Display information about the classes found in the interface\n\
-debug-module <n>- Display module parse tree at stages 1-4, <n> is a csv list of stages\n\
-debug-symtabs - Display symbol tables information\n\
-debug-symbols - Display target language symbols in the symbol tables\n\
-debug-csymbols - Display C symbols in the symbol tables\n\
-debug-lsymbols - Display target language layer symbols\n\
-debug-tags - Display information about the tags found in the interface\n\
-debug-template - Display information for debugging templates\n\
-debug-top <n> - Display entire parse tree at stages 1-4, <n> is a csv list of stages\n\
-debug-typedef - Display information about the types and typedefs in the interface\n\
-debug-typemap - Display information for debugging typemaps\n\
-debug-typemap - Display typemap debugging information\n\
-debug-tmsearch - Display typemap search debugging information\n\
-debug-tmused - Display typemaps used debugging information\n\
-directors - Turn on director mode for all the classes, mainly for testing\n\
-dirprot - Turn on wrapping of protected members for director classes (default)\n\
-D<symbol> - Define a symbol <symbol> (for conditional compilation)\n\
@ -163,9 +169,13 @@ static int help = 0;
static int checkout = 0;
static int cpp_only = 0;
static int no_cpp = 0;
static char *outfile_name = 0;
static char *outfile_name_h = 0;
static String *outfile_name = 0;
static String *outfile_name_h = 0;
static int tm_debug = 0;
static int dump_symtabs = 0;
static int dump_symbols = 0;
static int dump_csymbols = 0;
static int dump_lang_symbols = 0;
static int dump_tags = 0;
static int dump_module = 0;
static int dump_top = 0;
@ -178,14 +188,13 @@ static int depend = 0;
static int depend_only = 0;
static int memory_debug = 0;
static int allkw = 0;
static DOH *libfiles = 0;
static DOH *cpps = 0;
static String *dependencies_file = 0;
static File *f_dependencies_file = 0;
static String *dependencies_target = 0;
static int external_runtime = 0;
static String *external_runtime_name = 0;
enum { STAGE1=1, STAGE2=2, STAGE3=4, STAGE4=8, STAGEOVERFLOW=16 };
static List *libfiles = 0;
static List *all_output_files = 0;
// -----------------------------------------------------------------------------
@ -561,22 +570,23 @@ void SWIG_getoptions(int argc, char *argv[]) {
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-swiglib") == 0) {
if (SwigLibWin)
printf("%s\n", Char(SwigLibWin));
printf("%s\n", SwigLib);
Printf(stdout, "%s\n", SwigLibWin);
Printf(stdout, "%s\n", SwigLib);
SWIG_exit(EXIT_SUCCESS);
} else if (strcmp(argv[i], "-o") == 0) {
Swig_mark_arg(i);
if (argv[i + 1]) {
outfile_name = Swig_copy_string(argv[i + 1]);
outfile_name = NewString(argv[i + 1]);
Swig_filename_correct(outfile_name);
if (!outfile_name_h || !dependencies_file) {
char *ext = strrchr(outfile_name, '.');
String *basename = ext ? NewStringWithSize(outfile_name, ext - outfile_name) : NewString(outfile_name);
char *ext = strrchr(Char(outfile_name), '.');
String *basename = ext ? NewStringWithSize(Char(outfile_name), Char(ext) - Char(outfile_name)) : NewString(outfile_name);
if (!dependencies_file) {
dependencies_file = NewStringf("%s.%s", basename, depends_extension);
}
if (!outfile_name_h) {
Printf(basename, ".%s", hpp_extension);
outfile_name_h = Swig_copy_string(Char(basename));
outfile_name_h = NewString(basename);
}
Delete(basename);
}
@ -588,7 +598,8 @@ void SWIG_getoptions(int argc, char *argv[]) {
} else if (strcmp(argv[i], "-oh") == 0) {
Swig_mark_arg(i);
if (argv[i + 1]) {
outfile_name_h = Swig_copy_string(argv[i + 1]);
outfile_name_h = NewString(argv[i + 1]);
Swig_filename_correct(outfile_name_h);
Swig_mark_arg(i + 1);
i++;
} else {
@ -653,6 +664,12 @@ void SWIG_getoptions(int argc, char *argv[]) {
} else if ((strcmp(argv[i], "-debug-typemap") == 0) || (strcmp(argv[i], "-debug_typemap") == 0) || (strcmp(argv[i], "-tm_debug") == 0)) {
tm_debug = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-debug-tmsearch") == 0) {
Swig_typemap_search_debug_set();
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-debug-tmused") == 0) {
Swig_typemap_used_debug_set();
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-module") == 0) {
Swig_mark_arg(i);
if (argv[i + 1]) {
@ -720,6 +737,18 @@ void SWIG_getoptions(int argc, char *argv[]) {
} else if (strncmp(argv[i], "-w", 2) == 0) {
Swig_mark_arg(i);
Swig_warnfilter(argv[i] + 2, 1);
} else if (strcmp(argv[i], "-debug-symtabs") == 0) {
dump_symtabs = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-debug-symbols") == 0) {
dump_symbols = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-debug-csymbols") == 0) {
dump_csymbols = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-debug-lsymbols") == 0) {
dump_lang_symbols = 1;
Swig_mark_arg(i);
} else if ((strcmp(argv[i], "-debug-tags") == 0) || (strcmp(argv[i], "-dump_tags") == 0)) {
dump_tags = 1;
Swig_mark_arg(i);
@ -815,7 +844,6 @@ void SWIG_getoptions(int argc, char *argv[]) {
int SWIG_main(int argc, char *argv[], Language *l) {
char *c;
extern void Swig_print_xml(Node *obj, String *filename);
/* Initialize the SWIG core */
Swig_init();
@ -833,12 +861,6 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Preprocessor_define((DOH *) "SWIG 1", 0);
Preprocessor_define((DOH *) "__STDC__", 0);
#ifdef MACSWIG
Preprocessor_define((DOH *) "SWIGMAC 1", 0);
#endif
#ifdef SWIGWIN32
Preprocessor_define((DOH *) "SWIGWIN32 1", 0);
#endif
// Set the SWIG version value in format 0xAABBCC from package version expected to be in format A.B.C
String *package_version = NewString(PACKAGE_VERSION); /* Note that the fakeversion has not been set at this point */
@ -928,8 +950,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Swig_add_directory((String *) SwigLib);
if (Verbose) {
printf("LangSubDir: %s\n", Char(LangSubDir));
printf("Search paths:\n");
Printf(stdout, "Language subdirectory: %s\n", LangSubDir);
Printf(stdout, "Search paths:\n");
List *sp = Swig_search_path();
Iterator s;
for (s = First(sp); s.item; s = Next(s)) {
@ -948,12 +970,12 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// If the user has requested to check out a file, handle that
if (checkout) {
DOH *s;
char *outfile = Char(input_file);
String *outfile = input_file;
if (outfile_name)
outfile = outfile_name;
if (Verbose)
printf("Handling checkout...\n");
Printf(stdout, "Handling checkout...\n");
s = Swig_include(input_file);
if (!s) {
@ -979,7 +1001,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
} else {
// Run the preprocessor
if (Verbose)
printf("Preprocessing...\n");
Printf(stdout, "Preprocessing...\n");
{
int i;
@ -1009,9 +1031,9 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (lang_config) {
Printf(fs, "\n%%include <%s>\n", lang_config);
}
Printf(fs, "%%include(maininput=\"%s\") \"%s\"\n", Swig_filename_escape(input_file), Swig_last_file());
Printf(fs, "%%include(maininput=\"%s\") \"%s\"\n", Swig_filename_escape(input_file), Swig_filename_escape(Swig_last_file()));
for (i = 0; i < Len(libfiles); i++) {
Printf(fs, "\n%%include \"%s\"\n", Getitem(libfiles, i));
Printf(fs, "\n%%include \"%s\"\n", Swig_filename_escape(Getitem(libfiles, i)));
}
Seek(fs, 0, SEEK_SET);
cpps = Preprocessor_parse(fs);
@ -1030,6 +1052,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (depend) {
if (!no_cpp) {
String *outfile;
File *f_dependencies_file = 0;
char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(input_file): Char(input_file));
if (!outfile_name) {
@ -1063,9 +1086,13 @@ int SWIG_main(int argc, char *argv[], Language *l) {
}
List *files = Preprocessor_depend();
for (int i = 0; i < Len(files); i++) {
if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) != 0))) {
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
}
int use_file = 1;
if (depend == 2) {
if ((Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) == 0) || (SwigLibWin && (Strncmp(Getitem(files, i), SwigLibWin, Len(SwigLibWin)) == 0)))
use_file = 0;
}
if (use_file)
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
}
Printf(f_dependencies_file, "\n");
if (f_dependencies_file != stdout)
@ -1149,6 +1176,19 @@ int SWIG_main(int argc, char *argv[], Language *l) {
SwigType_print_scope(0);
}
if (dump_symtabs) {
Swig_symbol_print_tables(Swig_symbol_global_scope());
Swig_symbol_print_tables_summary();
}
if (dump_symbols) {
Swig_symbol_print_symbols();
}
if (dump_csymbols) {
Swig_symbol_print_csymbols();
}
if (dump_tags) {
Swig_print_tags(top, 0);
}
@ -1196,6 +1236,9 @@ int SWIG_main(int argc, char *argv[], Language *l) {
}
}
}
if (dump_lang_symbols) {
lang->dumpSymbols();
}
if (dump_top & STAGE4) {
Printf(stdout, "debug-top stage 4\n");
Swig_print_tree(top);
@ -1205,6 +1248,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Swig_print_tree(Getattr(top, "module"));
}
if (dump_xml && top) {
delete lang;
lang = 0;
Swig_print_xml(top, xmlout);
}
Delete(top);
@ -1239,6 +1284,9 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if ((werror) && (Swig_warn_count())) {
return Swig_warn_count();
}
delete lang;
return Swig_error_count();
}

View file

@ -85,7 +85,7 @@ char cvsroot_modula3_cxx[] = "$Id$";
that assign special purposes to the array types.
- Can one interpret $n_basetype as the identifier matched with SWIGTYPE ?
Swig's odds:
SWIG's odds:
- arguments of type (Node *) for SWIG functions
should be most often better (const Node *):
Swig_symbol_qualified, Getattr, nodeType, parentNode
@ -970,10 +970,10 @@ MODULA3():
Printf(f_runtime, "#define SWIGMODULA3\n");
Printf(f_runtime, "\n");
Swig_name_register((char *) "wrapper", (char *) "Modula3_%f");
Swig_name_register("wrapper", "Modula3_%f");
if (old_variable_names) {
Swig_name_register((char *) "set", (char *) "set_%v");
Swig_name_register((char *) "get", (char *) "get_%v");
Swig_name_register("set", "set_%v");
Swig_name_register("get", "get_%v");
}
Printf(f_wrappers, "\n#ifdef __cplusplus\n");
@ -1408,7 +1408,7 @@ MODULA3():
// Get any Modula 3 exception classes in the throws typemap
ParmList *throw_parm_list = NULL;
if ((throw_parm_list = Getattr(n, "throws"))) {
if ((throw_parm_list = Getattr(n, "catchlist"))) {
Swig_typemap_attach_parms("throws", throw_parm_list, f);
Parm *p;
for (p = throw_parm_list; p; p = nextSibling(p)) {
@ -2234,23 +2234,23 @@ MODULA3():
baseclass = NewString("");
// Inheritance from pure Modula 3 classes
const String *pure_baseclass = typemapLookup("m3base", classDeclarationName, WARN_NONE);
const String *pure_baseclass = typemapLookup(n, "m3base", classDeclarationName, WARN_NONE);
if (hasContent(pure_baseclass) && hasContent(baseclass)) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file,
line_number,
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", classDeclarationName, pure_baseclass);
}
// Pure Modula 3 interfaces
const String *pure_interfaces = typemapLookup(derived ? "m3interfaces_derived" : "m3interfaces",
const String *pure_interfaces = typemapLookup(n, derived ? "m3interfaces_derived" : "m3interfaces",
classDeclarationName, WARN_NONE);
// Start writing the proxy class
Printv(proxy_class_def, typemapLookup("m3imports", classDeclarationName, WARN_NONE), // Import statements
"\n", typemapLookup("m3classmodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
Printv(proxy_class_def, typemapLookup(n, "m3imports", classDeclarationName, WARN_NONE), // Import statements
"\n", typemapLookup(n, "m3classmodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" class $m3classname", // Class name and bases
(derived || *Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", baseclass, pure_baseclass, ((derived || *Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces
", " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", // Member variables for memory handling
derived ? "" : " protected bool swigCMemOwn;\n", "\n", " ", typemapLookup("m3ptrconstructormodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers
derived ? "" : " protected bool swigCMemOwn;\n", "\n", " ", typemapLookup(n, "m3ptrconstructormodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers
" $m3classname(IntPtr cPtr, bool cMemoryOwn) ", // Constructor used for wrapping pointers
derived ?
": base($imclassname.$m3classnameTo$baseclass(cPtr), cMemoryOwn) {\n"
@ -2266,10 +2266,10 @@ MODULA3():
Node *attributes = NewHash();
String *destruct_methodname = NULL;
if (derived) {
tm = typemapLookup("m3destruct_derived", classDeclarationName, WARN_NONE, attributes);
tm = typemapLookup(n, "m3destruct_derived", classDeclarationName, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:m3destruct_derived:methodname");
} else {
tm = typemapLookup("m3destruct", classDeclarationName, WARN_NONE, attributes);
tm = typemapLookup(n, "m3destruct", classDeclarationName, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:m3destruct:methodname");
}
if (!destruct_methodname) {
@ -2279,7 +2279,7 @@ MODULA3():
if (tm) {
// Finalize method
if (*Char(destructor_call)) {
Printv(proxy_class_def, typemapLookup("m3finalize", classDeclarationName, WARN_NONE), NIL);
Printv(proxy_class_def, typemapLookup(n, "m3finalize", classDeclarationName, WARN_NONE), NIL);
}
// Dispose method
Printv(destruct, tm, NIL);
@ -2294,8 +2294,8 @@ MODULA3():
Delete(destruct);
// Emit various other methods
Printv(proxy_class_def, typemapLookup("m3getcptr", classDeclarationName, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method
typemapLookup("m3code", classDeclarationName, WARN_NONE), // extra Modula 3 code
Printv(proxy_class_def, typemapLookup(n, "m3getcptr", classDeclarationName, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method
typemapLookup(n, "m3code", classDeclarationName, WARN_NONE), // extra Modula 3 code
"\n", NIL);
// Substitute various strings into the above template
@ -3585,17 +3585,28 @@ MODULA3():
Delete(throws_hash);
}
/*----------------------------------------------------------------------
* replaceSpecialVariables()
*--------------------------------------------------------------------*/
virtual void replaceSpecialVariables(String *method, String *tm, Parm *parm) {
(void)method;
SwigType *type = Getattr(parm, "type");
substituteClassname(type, tm);
}
/* -----------------------------------------------------------------------------
* substituteClassname()
*
* Substitute $m3classname with the proxy class name for classes/structs/unions that SWIG knows about.
* Substitute the special variable $m3classname with the proxy class name for classes/structs/unions
* that SWIG knows about.
* Otherwise use the $descriptor name for the Modula 3 class name. Note that the $&m3classname substitution
* is the same as a $&descriptor substitution, ie one pointer added to descriptor name.
* Inputs:
* pt - parameter type
* tm - m3wraptype typemap
* tm - typemap contents that might contain the special variable to be replaced
* Outputs:
* tm - m3wraptype typemap with $m3classname substitution
* tm - typemap contents complete with the special variable substitution
* Return:
* substitution_performed - flag indicating if a substitution was performed
* ----------------------------------------------------------------------------- */
@ -3769,6 +3780,10 @@ MODULA3():
* ----------------------------------------------------------------------------- */
void emitTypeWrapperClass(String *classname, SwigType *type) {
Node *n = NewHash();
Setfile(n, input_file);
Setline(n, line_number);
String *filen = NewStringf("%s%s.m3", Swig_file_dirname(outfile), classname);
File *f_swigtype = NewFile(filen, "w", SWIG_output_files());
if (!f_swigtype) {
@ -3781,19 +3796,19 @@ MODULA3():
emitBanner(f_swigtype);
// Pure Modula 3 baseclass and interfaces
const String *pure_baseclass = typemapLookup("m3base", type, WARN_NONE);
const String *pure_interfaces = typemapLookup("m3interfaces", type, WARN_NONE);
const String *pure_baseclass = typemapLookup(n, "m3base", type, WARN_NONE);
const String *pure_interfaces = typemapLookup(n, "m3interfaces", type, WARN_NONE);
// Emit the class
Printv(swigtype, typemapLookup("m3imports", type, WARN_NONE), // Import statements
"\n", typemapLookup("m3classmodifiers", type, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
Printv(swigtype, typemapLookup(n, "m3imports", type, WARN_NONE), // Import statements
"\n", typemapLookup(n, "m3classmodifiers", type, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" class $m3classname", // Class name and bases
*Char(pure_baseclass) ? " : " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces
" : " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", "\n", " ", typemapLookup("m3ptrconstructormodifiers", type, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers
" : " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", "\n", " ", typemapLookup(n, "m3ptrconstructormodifiers", type, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers
" $m3classname(IntPtr cPtr, bool bFutureUse) {\n", // Constructor used for wrapping pointers
" swigCPtr = cPtr;\n", " }\n", "\n", " protected $m3classname() {\n", // Default constructor
" swigCPtr = IntPtr.Zero;\n", " }\n", typemapLookup("m3getcptr", type, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method
typemapLookup("m3code", type, WARN_NONE), // extra Modula 3 code
" swigCPtr = IntPtr.Zero;\n", " }\n", typemapLookup(n, "m3getcptr", type, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method
typemapLookup(n, "m3code", type, WARN_NONE), // extra Modula 3 code
"}\n", "\n", NIL);
Replaceall(swigtype, "$m3classname", classname);
@ -3806,25 +3821,29 @@ MODULA3():
/* -----------------------------------------------------------------------------
* typemapLookup()
* n - for input only and must contain info for Getfile(n) and Getline(n) to work
* tmap_method - typemap method name
* type - typemap type to lookup
* warning - warning number to issue if no typemaps found
* typemap_attributes - the typemap attributes are attached to this node and will
* also be used for temporary storage if non null
* return is never NULL, unlike Swig_typemap_lookup()
* ----------------------------------------------------------------------------- */
const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes = NULL) {
String *tm = NULL;
const String *code = NULL;
if ((tm = Swig_typemap_search(op, type, NULL, NULL))) {
code = Getattr(tm, "code");
if (typemap_attributes)
Swig_typemap_attach_kwargs(tm, op, typemap_attributes);
}
if (!code) {
code = empty_string;
const String *typemapLookup(Node *n, const_String_or_char_ptr tmap_method, SwigType *type, int warning, Node *typemap_attributes = 0) {
Node *node = !typemap_attributes ? NewHash() : typemap_attributes;
Setattr(node, "type", type);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup(tmap_method, node, "", 0);
if (!tm) {
tm = empty_string;
if (warning != WARN_NONE)
Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type);
Swig_warning(warning, Getfile(n), Getline(n), "No %s typemap defined for %s\n", tmap_method, SwigType_str(type, 0));
}
return code ? code : empty_string;
if (!typemap_attributes)
Delete(node);
return tm;
}
/* -----------------------------------------------------------------------------

View file

@ -651,13 +651,15 @@ public:
{
/* Hack alert: will cleanup later -- Dave */
Node *n = NewHash();
Setattr(n, "name", var_name);
Setattr(n, "sym:name", iname);
Setattr(n, "type", type);
SetFlag(n, "feature:immutable");
variableWrapper(n);
Delete(n);
Node *nn = NewHash();
Setfile(nn, Getfile(n));
Setline(nn, Getline(n));
Setattr(nn, "name", var_name);
Setattr(nn, "sym:name", iname);
Setattr(nn, "type", type);
SetFlag(nn, "feature:immutable");
variableWrapper(nn);
Delete(nn);
}
}
Delete(proc_name);
@ -766,7 +768,7 @@ public:
Printv(access_mem, "(ptr)->", name, NIL);
if ((SwigType_type(type) == T_USER) && (!is_a_pointer(type))) {
Printv(convert_tab, tab4, "fields[i++] = ", NIL);
Printv(convert_tab, "_swig_convert_struct_", swigtype, "((", SwigType_str(ctype_ptr, ""), ")&((ptr)->", name, "));\n", NIL);
Printv(convert_tab, "_swig_convert_struct_", swigtype, "((", SwigType_str(ctype_ptr, 0), ")&((ptr)->", name, "));\n", NIL);
} else if ((tm = Swig_typemap_lookup("varout", n, access_mem, 0))) {
Replaceall(tm, "$result", "fields[i++]");
Printv(convert_tab, tm, "\n", NIL);

View file

@ -1631,11 +1631,6 @@ public:
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, "c_result", w);
Setattr(n, "type", type);
if (tm == 0) {
String *name = NewString("c_result");
tm = Swig_typemap_search("directorout", return_type, name, NULL);
Delete(name);
}
if (tm != 0) {
Replaceall(tm, "$input", "swig_result");
/* TODO check this */
@ -1736,7 +1731,7 @@ public:
ParmList *superparms = Getattr(n, "parms");
ParmList *parms = CopyParmList(superparms);
String *type = NewString("CAML_VALUE");
p = NewParm(type, NewString("self"));
p = NewParm(type, NewString("self"), n);
q = Copy(p);
set_nextSibling(q, superparms);
set_nextSibling(p, parms);
@ -1789,7 +1784,7 @@ public:
ParmList *superparms = Getattr(n, "parms");
ParmList *parms = CopyParmList(superparms);
String *type = NewString("CAML_VALUE");
p = NewParm(type, NewString("self"));
p = NewParm(type, NewString("self"), n);
q = Copy(p);
set_nextSibling(p, parms);
parms = p;

View file

@ -17,7 +17,8 @@ char cvsroot_octave_cxx[] = "$Id$";
static const char *usage = (char *) "\
Octave Options (available with -octave)\n\
(none yet)\n\n";
[no additional options]\n\
\n";
class OCTAVE:public Language {
@ -959,7 +960,7 @@ public:
String *name = NewString("self");
String *type = NewString("void");
SwigType_add_pointer(type);
self = NewParm(type, name);
self = NewParm(type, name, n);
Delete(type);
Delete(name);
Setattr(self, "lname", "self_obj");
@ -1054,7 +1055,7 @@ public:
ParmList *parms = CopyParmList(superparms);
String *type = NewString("void");
SwigType_add_pointer(type);
p = NewParm(type, NewString("self"));
p = NewParm(type, NewString("self"), n);
set_nextSibling(p, parms);
parms = p;
@ -1309,11 +1310,6 @@ public:
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, "result", w);
Setattr(n, "type", type);
if (tm == 0) {
String *name = NewString("result");
tm = Swig_typemap_search("directorout", return_type, name, NULL);
Delete(name);
}
if (tm != 0) {
char temp[24];
sprintf(temp, "out(%d)", idx);

View file

@ -227,13 +227,15 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (!nodes[j].error) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s ignored. Non-const method %s at %s:%d used.\n",
Swig_name_decl(nodes[j].n), Swig_name_decl(nodes[i].n), Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n),
"using non-const method %s instead.\n", Swig_name_decl(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s ignored. Method %s at %s:%d used.\n",
Swig_name_decl(nodes[j].n), Swig_name_decl(nodes[i].n), Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
"using %s instead.\n", Swig_name_decl(nodes[i].n));
}
}
nodes[j].error = 1;
@ -242,13 +244,15 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (!nodes[j].error) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s ignored. Non-const method %s at %s:%d used.\n",
Swig_name_decl(nodes[j].n), Swig_name_decl(nodes[i].n), Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n),
"using non-const method %s instead.\n", Swig_name_decl(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s ignored. Method %s at %s:%d used.\n",
Swig_name_decl(nodes[j].n), Swig_name_decl(nodes[i].n), Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
"using %s instead.\n", Swig_name_decl(nodes[i].n));
}
}
nodes[j].error = 1;
@ -262,15 +266,15 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (!nodes[j].error) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s is shadowed by %s at %s:%d.\n",
Swig_name_decl(nodes[j].n), Swig_name_decl(nodes[i].n),
Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s effectively ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[i].n), Getline(nodes[i].n),
"as it is shadowed by %s.\n", Swig_name_decl(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s ignored. Method %s at %s:%d used.\n",
Swig_name_decl(nodes[j].n), Swig_name_decl(nodes[i].n),
Getfile(nodes[i].n), Getline(nodes[i].n));
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
"using %s instead.\n", Swig_name_decl(nodes[i].n));
}
nodes[j].error = 1;
}
@ -722,6 +726,10 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
Parm *pi = Getattr(ni, "wrap:parms");
int num_required = emit_num_required(pi);
int num_arguments = emit_num_arguments(pi);
if (GetFlag(n, "wrap:this")) {
num_required++;
num_arguments++;
}
if (num_arguments > *maxargs)
*maxargs = num_arguments;
int varargs = emit_isvarargs(pi);
@ -755,7 +763,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
Printf(f, "}\n");
Delete(lfmt);
}
if (print_typecheck(f, j, pj)) {
if (print_typecheck(f, (GetFlag(n, "wrap:this") ? j + 1 : j), pj)) {
Printf(f, "if (_v) {\n");
num_braces++;
}

View file

@ -1511,7 +1511,7 @@ public:
Printf(pcode, "sub new {\n");
} else {
/* Constructor doesn't match classname so we'll just use the normal name */
Printv(pcode, "sub ", Swig_name_construct(symname), " () {\n", NIL);
Printv(pcode, "sub ", Swig_name_construct(symname), " {\n", NIL);
}
Printv(pcode,

File diff suppressed because it is too large Load diff

View file

@ -766,7 +766,7 @@ public:
/* Create a function to set the values of the (mutable) variables */
if (need_setter) {
Wrapper *wrapper = NewWrapper();
String *setter = Swig_name_member(getClassPrefix(), (char *) "`->=");
String *setter = Swig_name_member(getClassPrefix(), "`->=");
String *wname = Swig_name_wrapper(setter);
Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL);
Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n");
@ -805,7 +805,7 @@ public:
/* Create a function to get the values of the (mutable) variables */
Wrapper *wrapper = NewWrapper();
String *getter = Swig_name_member(getClassPrefix(), (char *) "`->");
String *getter = Swig_name_member(getClassPrefix(), "`->");
String *wname = Swig_name_wrapper(getter);
Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL);
Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n");

View file

@ -147,8 +147,8 @@ static const char *usage3 = (char *) "\
-proxydel - Generate a __del__ method even though it is now redundant (default) \n\
-safecstrings - Use safer (but slower) C string mapping, generating copies from Python -> C/C++\n\
-threads - Add thread support for all the interface\n\
-O - Enable all the optimization options: \n\
-modern -fastdispatch -dirvtable -nosafecstrings -fvirtual -noproxydel \n\
-O - Enable the following optimization options: \n\
-modern -fastdispatch -nosafecstrings -fvirtual -noproxydel \n\
-fastproxy -fastinit -fastunpack -fastquery -modernargs -nobuildnone \n\
-py3 - Generate code with Python 3 specific features:\n\
Function annotation \n\
@ -409,7 +409,6 @@ public:
} else if (strcmp(argv[i], "-O") == 0) {
classic = 0;
modern = 1;
dirvtable = 1;
safecstrings = 0;
buildnone = 0;
nobuildnone = 1;
@ -732,7 +731,7 @@ public:
Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
Printv(f_shadow, tab4 tab8, "finally:\n", NULL);
Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL);
Printv(f_shadow, tab8 tab8, "return _mod\n", NULL);
Printv(f_shadow, tab4 tab8, "return _mod\n", NULL);
Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
Printv(f_shadow, "else:\n", NULL);
@ -1917,7 +1916,7 @@ public:
Printv(f->def, "SWIGINTERN PyObject *", wname, "__varargs__", "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *varargs) {", NIL);
}
if (allow_kwargs) {
Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions.\n");
Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions (%s).\n", Swig_name_decl(n));
allow_kwargs = 0;
}
} else {
@ -2629,7 +2628,7 @@ public:
ParmList *parms = CopyParmList(superparms);
String *type = NewString("PyObject");
SwigType_add_pointer(type);
p = NewParm(type, NewString("self"));
p = NewParm(type, NewString("self"), n);
set_nextSibling(p, parms);
parms = p;
@ -2988,7 +2987,7 @@ public:
Delete(realct);
}
if (!have_constructor) {
Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"No constructor defined\")\n", NIL);
Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
} else if (fastinit) {
Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
@ -3209,7 +3208,7 @@ public:
String *name = NewString("self");
String *type = NewString("PyObject");
SwigType_add_pointer(type);
self = NewParm(type, name);
self = NewParm(type, name, n);
Delete(type);
Delete(name);
Setattr(self, "lname", "O");
@ -3953,11 +3952,6 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, "result", w);
Setattr(n, "type", type);
if (tm == 0) {
String *name = NewString("result");
tm = Swig_typemap_search("directorout", return_type, name, NULL);
Delete(name);
}
if (tm != 0) {
if (outputs > 1) {
Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);

View file

@ -70,40 +70,6 @@ static String * getRTypeName(SwigType *t, int *outCount = NULL) {
*/
}
#if 0
static String * getRType(Node *n) {
SwigType *elType = Getattr(n, "type");
SwigType *elDecl = Getattr(n, "decl");
//XXX How can we tell if this is already done.
SwigType_push(elType, elDecl);
String *ans;
String *rtype = Swig_typemap_lookup("rtype", n, "", 0);
String *i = getRTypeName(elType);
if(Len(i) == 0) {
SwigType *td = SwigType_typedef_resolve(elType);
if(td) {
// Printf(stderr, "Resolving typedef %s -> %s\n", elType, td);
i = getRTypeName(td);
}
}
// Printf(stderr, "<getRType> i = %s, rtype = %s (for %s)\n",
// i, rtype, elType);
if(rtype) {
ans = NewString("");
Printf(ans, "%s", rtype);
Replaceall(ans, "$R_class", Char(i));
// Printf(stderr, "Found r type in typemap for %s (for %s) => %s (%s) => %s\n",
// SwigType_str(elType, 0), Getattr(n, "name"), rtype, i, ans);
} else {
ans = i;
}
return(ans);
}
#endif
/*********************
Tries to get the name of the R class corresponding to the given type
e.g. struct A * is ARef, struct A** is ARefRef.
@ -534,12 +500,7 @@ int R::getFunctionPointerNumArgs(Node *n, SwigType *tt) {
n = Getattr(n, "type");
if (debugMode)
Printf(stderr, "type: %s\n", n);
#if 0
SwigType *tmp = SwigType_typedef_resolve(tt);
n = SwigType_typedef_resolve(tt);
#endif
ParmList *parms = Getattr(n, "parms");
if (debugMode)
Printf(stderr, "parms = %p\n", parms);
@ -592,7 +553,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
// ParmList *parms = Getattr(n, "parms");
// memory leak
ParmList *parms = SwigType_function_parms(SwigType_del_pointer(Copy(t)));
ParmList *parms = SwigType_function_parms(SwigType_del_pointer(Copy(t)), n);
// if (debugMode) {
@ -716,10 +677,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
XXX Have to be a little more clever so that we can deal with struct A * - the * is getting lost.
Is this still true? If so, will a SwigType_push() solve things?
*/
Node *bbase = NewHash();
Setattr(bbase, "type", rettype);
Setattr(bbase, "name", NewString("result"));
Parm *bbase = NewParm(rettype, "result", n);
String *returnTM = Swig_typemap_lookup("in", bbase, "result", f);
if(returnTM) {
String *tm = returnTM;
@ -1105,7 +1063,7 @@ int R::OutputMemberReferenceMethod(String *className, int isSet,
Delete(pitem);
}
Delete(itemList);
Printf(f->code, ")\n");
Printf(f->code, ");\n");
if (!isSet && varaccessor > 0) {
Printf(f->code, "%svaccessors = c(", tab8);
@ -1121,7 +1079,7 @@ int R::OutputMemberReferenceMethod(String *className, int isSet,
Printf(f->code, "'%s'%s", item, vcount < varaccessor ? ", " : "");
}
}
Printf(f->code, ")\n");
Printf(f->code, ");\n");
}
@ -1133,24 +1091,24 @@ int R::OutputMemberReferenceMethod(String *className, int isSet,
"stop(\"No ", (isSet ? "modifiable" : "accessible"), " field named \", name, \" in ", className,
": fields are \", paste(names(accessorFuns), sep = \", \")",
")", "\n}\n", NIL); */
Printv(f->code, tab8,
"idx = pmatch(name, names(accessorFuns))\n",
Printv(f->code, ";", tab8,
"idx = pmatch(name, names(accessorFuns));\n",
tab8,
"if(is.na(idx)) \n",
tab8, tab4, NIL);
Printf(f->code, "return(callNextMethod(x, name%s))\n",
Printf(f->code, "return(callNextMethod(x, name%s));\n",
isSet ? ", value" : "");
Printv(f->code, tab8, "f = accessorFuns[[idx]]\n", NIL);
Printv(f->code, tab8, "f = accessorFuns[[idx]];\n", NIL);
if(isSet) {
Printv(f->code, tab8, "f(x, value)\n", NIL);
Printv(f->code, tab8, "x\n", NIL); // make certain to return the S value.
Printv(f->code, tab8, "f(x, value);\n", NIL);
Printv(f->code, tab8, "x;\n", NIL); // make certain to return the S value.
} else {
Printv(f->code, tab8, "formals(f)[[1]] = x\n", NIL);
Printv(f->code, tab8, "formals(f)[[1]] = x;\n", NIL);
if (varaccessor) {
Printv(f->code, tab8,
"if (is.na(match(name, vaccessors))) f else f(x)\n", NIL);
"if (is.na(match(name, vaccessors))) f else f(x);\n", NIL);
} else {
Printv(f->code, tab8, "f\n", NIL);
Printv(f->code, tab8, "f;\n", NIL);
}
}
Printf(f->code, "}\n");
@ -1161,15 +1119,15 @@ int R::OutputMemberReferenceMethod(String *className, int isSet,
isSet ? "<-" : "",
getRClassName(className));
Wrapper_print(f, out);
Printf(out, ")\n");
Printf(out, ");\n");
if(isSet) {
Printf(out, "setMethod('[[<-', c('_p%s', 'character'),",
getRClassName(className));
Insert(f->code, 2, "name = i\n");
Insert(f->code, 2, "name = i;\n");
Printf(attr->code, "%s", f->code);
Wrapper_print(attr, out);
Printf(out, ")\n");
Printf(out, ");\n");
}
DelWrapper(attr);
@ -1422,15 +1380,13 @@ static List * Swig_overload_rank(Node *n,
String *t2 = Getattr(p2,"tmap:typecheck:precedence");
if ((!t1) && (!nodes[i].error)) {
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n),
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
Getattr(nodes[i].n,"name"),ParmList_str_defaultargs(Getattr(nodes[i].n,"parms")),
SwigType_str(Getattr(p1,"type"),0));
"Overloaded method %s not supported (no type checking rule for '%s').\n",
Swig_name_decl(nodes[i].n), SwigType_str(Getattr(p1, "type"), 0));
nodes[i].error = 1;
} else if ((!t2) && (!nodes[j].error)) {
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
Getattr(nodes[j].n,"name"),ParmList_str_defaultargs(Getattr(nodes[j].n,"parms")),
SwigType_str(Getattr(p2,"type"),0));
"xx Overloaded method %s not supported (no type checking rule for '%s').\n",
Swig_name_decl(nodes[j].n), SwigType_str(Getattr(p2, "type"), 0));
nodes[j].error = 1;
}
if (t1 && t2) {
@ -1495,8 +1451,8 @@ static List * Swig_overload_rank(Node *n,
}
if (!differ) {
/* See if declarations differ by const only */
String *d1 = Getattr(nodes[i].n,"decl");
String *d2 = Getattr(nodes[j].n,"decl");
String *d1 = Getattr(nodes[i].n, "decl");
String *d2 = Getattr(nodes[j].n, "decl");
if (d1 && d2) {
String *dq1 = Copy(d1);
String *dq2 = Copy(d2);
@ -1506,49 +1462,47 @@ static List * Swig_overload_rank(Node *n,
if (SwigType_isconst(d2)) {
Delete(SwigType_pop(dq2));
}
if (Strcmp(dq1,dq2) == 0) {
if (Strcmp(dq1, dq2) == 0) {
if (SwigType_isconst(d1) && !SwigType_isconst(d2)) {
if (script_lang_wrapping) {
// Swap nodes so that the const method gets ignored (shadowed by the non-const method)
Overloaded t = nodes[i];
nodes[i] = nodes[j];
nodes[j] = t;
}
if (script_lang_wrapping) {
// Swap nodes so that the const method gets ignored (shadowed by the non-const method)
Overloaded t = nodes[i];
nodes[i] = nodes[j];
nodes[j] = t;
}
differ = 1;
if (!nodes[j].error) {
if (script_lang_wrapping) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
Getfile(nodes[i].n), Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
Getattr(nodes[i].n,"name"), ParmList_errorstr(nodes[i].parms),
Getfile(nodes[i].n), Getline(nodes[i].n));
}
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n),
"using non-const method %s instead.\n", Swig_name_decl(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
"using %s instead.\n", Swig_name_decl(nodes[i].n));
}
}
nodes[j].error = 1;
} else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) {
differ = 1;
if (!nodes[j].error) {
if (script_lang_wrapping) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
Getfile(nodes[i].n), Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
Getattr(nodes[i].n,"name"), ParmList_errorstr(nodes[i].parms),
Getfile(nodes[i].n), Getline(nodes[i].n));
}
}
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n),
"using non-const method %s instead.\n", Swig_name_decl(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
"using %s instead.\n", Swig_name_decl(nodes[i].n));
}
}
nodes[j].error = 1;
}
}
@ -1558,24 +1512,18 @@ static List * Swig_overload_rank(Node *n,
}
if (!differ) {
if (!nodes[j].error) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n",
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "",
Getattr(nodes[i].n,"name"), ParmList_errorstr(nodes[i].parms),
SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "",
Getfile(nodes[i].n),Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "",
Getattr(nodes[i].n,"name"), ParmList_errorstr(nodes[i].parms),
SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "",
Getfile(nodes[i].n),Getline(nodes[i].n));
}
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s effectively ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[i].n), Getline(nodes[i].n),
"as it is shadowed by %s.\n", Swig_name_decl(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n));
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n),
"using %s instead.\n", Swig_name_decl(nodes[i].n));
}
nodes[j].error = 1;
}
}
@ -1613,9 +1561,9 @@ void R::dispatchFunction(Node *n) {
List *dispatch = Swig_overload_rank(n, true);
int nfunc = Len(dispatch);
Printv(f->code,
"argtypes <- mapply(class, list(...))\n",
"argv <- list(...)\n",
"argc <- length(argtypes)\n", NIL );
"argtypes <- mapply(class, list(...));\n",
"argv <- list(...);\n",
"argc <- length(argtypes);\n", NIL );
Printf(f->code, "# dispatch functions %d\n", nfunc);
int cur_args = -1;
@ -1661,16 +1609,16 @@ void R::dispatchFunction(Node *n) {
}
p = Getattr(p, "tmap:in:next");
}
Printf(f->code, ") { f <- %s%s }\n", sfname, overname);
Printf(f->code, ") { f <- %s%s; }\n", sfname, overname);
} else {
Printf(f->code, "f <- %s%s", sfname, overname);
Printf(f->code, "f <- %s%s; ", sfname, overname);
}
}
if (cur_args != -1) {
Printv(f->code, "}", NIL);
}
Printv(f->code, "\nf(...)", NIL);
Printv(f->code, "\n}", NIL);
Printv(f->code, ";\nf(...)", NIL);
Printv(f->code, ";\n}", NIL);
Wrapper_print(f, sfile);
Printv(sfile, "# Dispatch function\n", NIL);
DelWrapper(f);
@ -1898,16 +1846,16 @@ int R::functionWrapper(Node *n) {
String *snargs = NewStringf("%d", nargs);
Printv(sfun->code, "if(is.function(", name, ")) {", "\n",
"assert('...' %in% names(formals(", name,
")) || length(formals(", name, ")) >= ", snargs, ")\n} ", NIL);
")) || length(formals(", name, ")) >= ", snargs, ");\n} ", NIL);
Delete(snargs);
Printv(sfun->code, "else {\n",
"if(is.character(", name, ")) {\n",
name, " = getNativeSymbolInfo(", name, ")",
"\n}\n",
name, " = getNativeSymbolInfo(", name, ");",
"\n};\n",
"if(is(", name, ", \"NativeSymbolInfo\")) {\n",
name, " = ", name, "$address", "\n}\n",
"}\n",
name, " = ", name, "$address", ";\n}\n",
"}; \n",
NIL);
} else {
Printf(sfun->code, "%s\n", tm);
@ -2102,10 +2050,10 @@ int R::functionWrapper(Node *n) {
}
Printv(sfun->code, (Len(tm) ? "ans = " : ""), ".Call('", wname,
"', ", sargs, "PACKAGE='", Rpackage, "')\n", NIL);
Printv(sfun->code, ";", (Len(tm) ? "ans = " : ""), ".Call('", wname,
"', ", sargs, "PACKAGE='", Rpackage, "');\n", NIL);
if(Len(tm))
Printf(sfun->code, "%s\n\nans\n", tm);
Printf(sfun->code, "%s\n\nans;\n", tm);
if (destructor)
Printv(f->code, "R_ClearExternalPtr(self);\n", NIL);
@ -2464,11 +2412,11 @@ int R::generateCopyRoutines(Node *n) {
/* The S functions to get and set the member value. */
String *elNameT = replaceInitialDash(elName);
Printf(copyToR->code, "obj@%s = value$%s\n", elNameT, elNameT);
Printf(copyToC->code, "obj$%s = value@%s\n", elNameT, elNameT);
Printf(copyToR->code, "obj@%s = value$%s;\n", elNameT, elNameT);
Printf(copyToC->code, "obj$%s = value@%s;\n", elNameT, elNameT);
Delete(elNameT);
}
Printf(copyToR->code, "obj\n}\n\n");
Printf(copyToR->code, "obj;\n}\n\n");
String *rclassName = getRClassNameCopyStruct(type, 0); // without the Ref.
Printf(sfile, "# Start definition of copy functions & methods for %s\n", rclassName);
@ -2478,9 +2426,9 @@ int R::generateCopyRoutines(Node *n) {
Printf(sfile, "# Start definition of copy methods for %s\n", rclassName);
Printf(sfile, "setMethod('copyToR', '_p_%s', CopyToR%s)\n", rclassName,
Printf(sfile, "setMethod('copyToR', '_p_%s', CopyToR%s);\n", rclassName,
mangledName);
Printf(sfile, "setMethod('copyToC', '%s', CopyToC%s)\n\n", rclassName,
Printf(sfile, "setMethod('copyToC', '%s', CopyToC%s);\n\n", rclassName,
mangledName);
Printf(sfile, "# End definition of copy methods for %s\n", rclassName);

View file

@ -2578,7 +2578,7 @@ public:
/* First wrap the allocate method */
current = CONSTRUCTOR_ALLOCATE;
Swig_name_register((const_String_or_char_ptr ) "construct", (const_String_or_char_ptr ) "%c_allocate");
Swig_name_register("construct", "%c_allocate");
Language::constructorHandler(n);
@ -2594,7 +2594,7 @@ public:
Parm *self;
String *name = NewString("self");
String *type = NewString("VALUE");
self = NewParm(type, name);
self = NewParm(type, name, n);
Delete(type);
Delete(name);
Setattr(self, "lname", "Qnil");
@ -2613,7 +2613,7 @@ public:
Delete(docs);
current = CONSTRUCTOR_INITIALIZE;
Swig_name_register((const_String_or_char_ptr ) "construct", (const_String_or_char_ptr ) "new_%c");
Swig_name_register("construct", "new_%c");
Language::constructorHandler(n);
/* Restore original parameter list */
@ -2635,7 +2635,7 @@ public:
/* First wrap the allocate method */
current = CONSTRUCTOR_ALLOCATE;
Swig_name_register((const_String_or_char_ptr ) "construct", (const_String_or_char_ptr ) "%c_allocate");
Swig_name_register("construct", "%c_allocate");
return Language::copyconstructorHandler(n);
}
@ -2816,7 +2816,7 @@ public:
ParmList *superparms = Getattr(n, "parms");
ParmList *parms = CopyParmList(superparms);
String *type = NewString("VALUE");
p = NewParm(type, NewString("self"));
p = NewParm(type, NewString("self"), n);
set_nextSibling(p, parms);
parms = p;
@ -3249,11 +3249,6 @@ public:
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, "result", w);
Setattr(n, "type", type);
if (tm == 0) {
String *name = NewString("result");
tm = Swig_typemap_search("directorout", return_type, name, NULL);
Delete(name);
}
if (tm != 0) {
if (outputs > 1 && !asvoid ) {
Printf(w->code, "output = rb_ary_entry(result, %d);\n", idx++);

View file

@ -200,7 +200,8 @@ int main(int margc, char **margv) {
dl = (fac) ();
}
}
int res = SWIG_main(argc, argv, dl);
delete dl;
return res;
}

View file

@ -212,14 +212,16 @@ public:
/* Miscellaneous */
virtual int validIdentifier(String *s); /* valid identifier? */
virtual int addSymbol(const String *s, const Node *n); /* Add symbol */
virtual Node *symbolLookup(String *s); /* Symbol lookup */
virtual int addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope = ""); /* Add symbol */
virtual void dumpSymbols();
virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */
virtual Node *classLookup(SwigType *s); /* Class lookup */
virtual Node *enumLookup(SwigType *s); /* Enum lookup */
virtual int abstractClassTest(Node *n); /* Is class really abstract? */
virtual int is_assignable(Node *n); /* Is variable assignable? */
virtual String *runtimeCode(); /* returns the language specific runtime code */
virtual String *defaultExternalRuntimeFilename(); /* the default filename for the external runtime */
virtual void replaceSpecialVariables(String *method, String *tm, Parm *parm); /* Language specific special variable substitutions for $typemap() */
/* Runtime is C++ based, so extern "C" header section */
void enable_cplus_runtime_mode();
@ -254,6 +256,9 @@ public:
/* Set overload variable templates argc and argv */
void setOverloadResolutionTemplates(String *argc, String *argv);
/* Language instance is a singleton - get instance */
static Language* instance();
protected:
/* Allow multiple-input typemaps */
void allow_multiple_input(int val = 1);
@ -304,13 +309,14 @@ protected:
int director_language;
private:
Hash *symbols;
Hash *symtabs; /* symbol tables */
Hash *classtypes;
Hash *enumtypes;
int overloading;
int multiinput;
int cplus_runtime;
int directors;
static Language *this_;
};
int SWIG_main(int, char **, Language *);
@ -320,6 +326,7 @@ void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */
void SWIG_config_file(const_String_or_char_ptr );
const String *SWIG_output_directory();
void SWIG_config_cppext(const char *ext);
void Swig_print_xml(Node *obj, String *filename);
/* get the list of generated files */
List *SWIG_output_files();
@ -351,7 +358,9 @@ void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f);
extern "C" {
void SWIG_typemap_lang(const char *);
typedef Language *(*ModuleFactory) (void);
} void Swig_register_module(const char *name, ModuleFactory fac);
}
void Swig_register_module(const char *name, ModuleFactory fac);
ModuleFactory Swig_find_module(const char *name);
/* Utilities */

View file

@ -32,7 +32,7 @@ static String *methods_tab = 0; /* Methods table */
static String *attr_tab = 0; /* Attribute table */
static String *prefix = 0;
static String *module = 0;
static int nspace = 0;
static int namespace_option = 0;
static String *init_name = 0;
static String *ns_name = 0;
static int have_constructor;
@ -101,7 +101,7 @@ public:
i++;
}
} else if (strcmp(argv[i], "-namespace") == 0) {
nspace = 1;
namespace_option = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-itcl") == 0) {
itcl = 1;
@ -208,7 +208,7 @@ public:
Printf(f_header, "#define SWIG_init %s\n", init_name);
Printf(f_header, "#define SWIG_name \"%s\"\n", module);
if (nspace) {
if (namespace_option) {
Printf(f_header, "#define SWIG_prefix \"%s::\"\n", ns_name);
Printf(f_header, "#define SWIG_namespace \"%s\"\n\n", ns_name);
} else {
@ -670,7 +670,7 @@ public:
virtual int constantWrapper(Node *n) {
String *name = Getattr(n, "name");
String *iname = Getattr(n, "sym:name");
String *nsname = !nspace ? Copy(iname) : NewStringf("%s::%s", ns_name, iname);
String *nsname = !namespace_option ? Copy(iname) : NewStringf("%s::%s", ns_name, iname);
SwigType *type = Getattr(n, "type");
String *rawval = Getattr(n, "rawval");
String *value = rawval ? rawval : Getattr(n, "value");
@ -678,7 +678,7 @@ public:
if (!addSymbol(iname, n))
return SWIG_ERROR;
if (nspace)
if (namespace_option)
Setattr(n, "sym:name", nsname);
/* Special hook for member pointer */
@ -869,7 +869,7 @@ public:
Printv(ptrclass, attributes, NIL);
// base class swig_getset was being called for complex inheritance trees
if (nspace) {
if (namespace_option) {
Printv(ptrclass, " protected method ", class_name, "_swig_getset {var name1 name2 op} {\n", NIL);
@ -935,13 +935,13 @@ public:
Printv(f_shadow, " constructor { } {\n", NIL);
Printv(f_shadow, " # This constructor will fail if called directly\n", NIL);
Printv(f_shadow, " if { [info class] == \"::", class_name, "\" } {\n", NIL);
Printv(f_shadow, " error \"No constructor for class ", class_name, "\"\n", NIL);
Printv(f_shadow, " error \"No constructor for class ", class_name, (Getattr(n, "abstract") ? " - class is abstract" : ""), "\"\n", NIL);
Printv(f_shadow, " }\n", NIL);
Printv(f_shadow, " }\n", NIL);
}
Printv(f_shadow, "}\n\n", NIL);
};
}
Printv(f_wrappers, "static swig_class *swig_", mangled_classname, "_bases[] = {", base_class, "0};\n", NIL);
Printv(f_wrappers, "static const char * swig_", mangled_classname, "_base_names[] = {", base_class_names, "0};\n", NIL);
@ -1022,7 +1022,7 @@ public:
if (Len(dv) > 0) {
String *defval = NewString(dv);
if (nspace) {
if (namespace_option) {
Insert(defval, 0, "::");
Insert(defval, 0, ns_name);
}
@ -1040,7 +1040,7 @@ public:
}
Printv(imethods, "] ", NIL);
if (nspace) {
if (namespace_option) {
Printv(imethods, "{ ", ns_name, "::", class_name, "_", realname, " $swigobj", NIL);
} else {
Printv(imethods, "{ ", class_name, "_", realname, " $swigobj", NIL);
@ -1168,7 +1168,7 @@ public:
// Call to constructor wrapper and parent Ptr class
// [BRE] add -namespace/-prefix support
if (nspace) {
if (namespace_option) {
Printv(constructor, " ", realname, "Ptr::constructor [", ns_name, "::new_", realname, NIL);
} else {
Printv(constructor, " ", realname, "Ptr::constructor [new_", realname, NIL);
@ -1235,7 +1235,7 @@ public:
if (!temp)
temp = NewString("");
Clear(temp);
if (nspace) {
if (namespace_option) {
Printf(temp, "%s::%s ", ns_name, iname);
} else {
Printf(temp, "%s ", iname);

View file

@ -734,6 +734,49 @@ class TypePass:private Dispatcher {
}
Setattr(n, "enumtype", enumtype);
// This block of code is for dealing with %ignore on an enum item where the target language
// attempts to use the C enum value in the target language itself and expects the previous enum value
// to be one more than the previous value... the previous enum item might not exist if it is ignored!
// - It sets the first non-ignored enum item with the "firstenumitem" attribute.
// - It adds an enumvalue attribute if the previous enum item is ignored
{
Node *c;
int count = 0;
String *previous = 0;
bool previous_ignored = false;
bool firstenumitem = false;
for (c = firstChild(n); c; c = nextSibling(c)) {
assert(strcmp(Char(nodeType(c)), "enumitem") == 0);
bool reset;
String *enumvalue = Getattr(c, "enumvalue");
if (GetFlag(c, "feature:ignore")) {
reset = enumvalue ? true : false;
previous_ignored = true;
} else {
if (!enumvalue && previous_ignored) {
if (previous)
Setattr(c, "enumvalue", NewStringf("(%s) + %d", previous, count+1));
else
Setattr(c, "enumvalue", NewStringf("%d", count));
SetFlag(c, "virtenumvalue"); // identify enumvalue as virtual, ie not from the parsed source
}
if (!firstenumitem) {
SetFlag(c, "firstenumitem");
firstenumitem = true;
}
reset = true;
previous_ignored = false;
}
if (reset) {
previous = enumvalue ? enumvalue : Getattr(c, "name");
count = 0;
} else {
count++;
}
}
}
emit_children(n);
return SWIG_OK;
}
@ -757,13 +800,16 @@ class TypePass:private Dispatcher {
Setattr(n, "value", new_value);
Delete(new_value);
}
// Make up an enumvalue if one was not specified in the parsed code
if (Getattr(n, "_last") && !Getattr(n, "enumvalue")) { // Only the first enum item has _last set
Setattr(n, "enumvalueex", "0");
}
Node *next = nextSibling(n);
if (next && !Getattr(next, "enumvalue")) {
Setattr(next, "enumvalueex", NewStringf("%s + 1", Getattr(n, "sym:name")));
// Make up an enumvalue if one was not specified in the parsed code (not designed to be used on enum items and %ignore - enumvalue will be set instead)
if (!GetFlag(n, "feature:ignore")) {
if (Getattr(n, "_last") && !Getattr(n, "enumvalue")) { // Only the first enum item has _last set (Note: first non-ignored enum item has firstenumitem set)
Setattr(n, "enumvalueex", "0");
}
if (next && !Getattr(next, "enumvalue")) {
Setattr(next, "enumvalueex", NewStringf("%s + 1", Getattr(n, "sym:name")));
}
}
return SWIG_OK;

View file

@ -135,11 +135,17 @@ static void add_defined_foreign_type(String *type) {
}
static String *get_ffi_type(SwigType *ty, const_String_or_char_ptr name) {
Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0);
if (typemap) {
String *typespec = Getattr(typemap, "code");
return NewString(typespec);
static String *get_ffi_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
Node *node = NewHash();
Setattr(node, "type", ty);
Setattr(node, "name", name);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("ffitype", node, "", 0);
Delete(node);
if (tm) {
return NewString(tm);
} else {
SwigType *tr = SwigType_typedef_resolve_all(ty);
char *type_reduced = Char(tr);
@ -171,14 +177,16 @@ static String *get_ffi_type(SwigType *ty, const_String_or_char_ptr name) {
return 0;
}
static String *get_lisp_type(SwigType *ty, const_String_or_char_ptr name) {
Hash *typemap = Swig_typemap_search("lisptype", ty, name, 0);
if (typemap) {
String *typespec = Getattr(typemap, "code");
return NewString(typespec);
} else {
return NewString("");
}
static String *get_lisp_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
Node *node = NewHash();
Setattr(node, "type", ty);
Setattr(node, "name", name);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("lisptype", node, "", 0);
Delete(node);
return tm ? NewString(tm) : NewString("");
}
void UFFI::main(int argc, char *argv[]) {
@ -284,8 +292,8 @@ int UFFI::functionWrapper(Node *n) {
for (p = pl; p; p = nextSibling(p), argnum++) {
String *argname = Getattr(p, "name");
SwigType *argtype = Getattr(p, "type");
String *ffitype = get_ffi_type(argtype, argname);
String *lisptype = get_lisp_type(argtype, argname);
String *ffitype = get_ffi_type(n, argtype, argname);
String *lisptype = get_lisp_type(n, argtype, argname);
int tempargname = 0;
if (!argname) {
@ -311,7 +319,7 @@ int UFFI::functionWrapper(Node *n) {
//" :strings-convert t\n"
//" :call-direct %s\n"
//" :optimize-for-space t"
")\n", get_ffi_type(Getattr(n, "type"), "result")
")\n", get_ffi_type(n, Getattr(n, "type"), "result")
//,varargs ? "nil" : "t"
);
@ -365,7 +373,7 @@ int UFFI::classHandler(Node *n) {
/* Printf(stdout, "Converting %s in %s\n", type, name); */
lisp_type = get_ffi_type(type, Getattr(c, "sym:name"));
lisp_type = get_ffi_type(n, type, Getattr(c, "sym:name"));
Printf(f_cl, " (#.(%s \"%s\" :type :slot) %s)\n", identifier_converter, Getattr(c, "sym:name"), lisp_type);

View file

@ -629,7 +629,7 @@ unterm:
/* -----------------------------------------------------------------------------
* DOH *get_filename(DOH *str)
*
* Read a filename from str. A filename can be enclose in quotes, angle brackets,
* Read a filename from str. A filename can be enclosed in quotes, angle brackets,
* or bare.
* ----------------------------------------------------------------------------- */
@ -656,6 +656,7 @@ static String *get_filename(String *str, int *sysfile) {
if (isspace(c))
Ungetc(c, str);
}
Swig_filename_unescape(fn);
Swig_filename_correct(fn);
Seek(fn, 0, SEEK_SET);
return fn;
@ -1597,9 +1598,9 @@ String *Preprocessor_parse(String *s) {
s1 = cpp_include(fn, sysfile);
if (s1) {
if (include_all)
Printf(ns, "%%includefile \"%s\" [\n", Swig_last_file());
Printf(ns, "%%includefile \"%s\" [\n", Swig_filename_escape(Swig_last_file()));
else if (import_all) {
Printf(ns, "%%importfile \"%s\" [\n", Swig_last_file());
Printf(ns, "%%importfile \"%s\" [\n", Swig_filename_escape(Swig_last_file()));
push_imported();
}
@ -1652,7 +1653,7 @@ String *Preprocessor_parse(String *s) {
state = 0;
break;
/* Swig directives */
/* SWIG directives */
case 100:
/* %{,%} block */
if (c == '{') {
@ -1717,7 +1718,7 @@ String *Preprocessor_parse(String *s) {
case 110:
if (!isidchar(c)) {
Ungetc(c, s);
/* Look for common Swig directives */
/* Look for common SWIG directives */
if (Equal(decl, kpp_dinclude) || Equal(decl, kpp_dimport) || Equal(decl, kpp_dextern)) {
/* Got some kind of file inclusion directive */
if (allow) {
@ -1736,7 +1737,7 @@ String *Preprocessor_parse(String *s) {
char *dirname;
add_chunk(ns, chunk, allow);
copy_location(s, chunk);
Printf(ns, "%sfile%s \"%s\" [\n", decl, opt, Swig_last_file());
Printf(ns, "%sfile%s \"%s\" [\n", decl, opt, Swig_filename_escape(Swig_last_file()));
if (Equal(decl, kpp_dimport)) {
push_imported();
}

View file

@ -212,7 +212,11 @@ int Swig_cargs(Wrapper *w, ParmList *p) {
String *type = Getattr(p, "type");
/* default values only emitted if in compact default args mode */
String *pvalue = (compactdefargs) ? Getattr(p, "value") : 0;
SwigType *altty = SwigType_alttype(type, 0);
/* When using compactdefaultargs, the code generated initialises a variable via a constructor call that accepts the
* default value as a parameter. The default constructor is not called and therefore SwigValueWrapper is not needed. */
SwigType *altty = pvalue ? 0 : SwigType_alttype(type, 0);
int tycode = SwigType_type(type);
if (tycode == T_REFERENCE) {
if (pvalue) {
@ -851,7 +855,7 @@ int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *direc
SwigType_push(type, qualifier);
}
SwigType_add_pointer(type);
p = NewParm(type, "self");
p = NewParm(type, "self", n);
Setattr(p, "self", "1");
Setattr(p, "hidden","1");
/*
@ -1203,7 +1207,7 @@ int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags)
type = NewString(classname);
SwigType_add_pointer(type);
p = NewParm(type, "self");
p = NewParm(type, "self", n);
Setattr(p, "self", "1");
Setattr(p, "hidden", "1");
Setattr(p, "wrap:disown", "1");
@ -1255,7 +1259,7 @@ int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags)
* This function creates a C wrapper for setting a structure member.
* ----------------------------------------------------------------------------- */
int Swig_MembersetToFunction(Node *n, String *classname, int flags, String **call) {
int Swig_MembersetToFunction(Node *n, String *classname, int flags) {
String *name;
ParmList *parms;
Parm *p;
@ -1286,13 +1290,13 @@ int Swig_MembersetToFunction(Node *n, String *classname, int flags, String **cal
t = NewString(classname);
SwigType_add_pointer(t);
parms = NewParm(t, "self");
parms = NewParm(t, "self", n);
Setattr(parms, "self", "1");
Setattr(parms, "hidden","1");
Delete(t);
ty = Swig_wrapped_member_var_type(type, varcref);
p = NewParm(ty, name);
p = NewParm(ty, name, n);
Setattr(parms, "hidden", "1");
set_nextSibling(parms, p);
@ -1303,21 +1307,23 @@ int Swig_MembersetToFunction(Node *n, String *classname, int flags, String **cal
Delete(p);
if (flags & CWRAP_EXTEND) {
String *call;
String *cres;
String *code = Getattr(n, "code");
if (code) {
/* I don't think this ever gets run - WSF */
Swig_add_extension_code(n, mangled, parms, void_type, code, cparse_cplusplus, "self");
}
*call = Swig_cfunction_call(mangled, parms);
cres = NewStringf("%s;", *call);
call = Swig_cfunction_call(mangled, parms);
cres = NewStringf("%s;", call);
Setattr(n, "wrap:action", cres);
Delete(call);
Delete(cres);
} else {
String *cres;
*call = Swig_cmemberset_call(name, type, self, varcref);
cres = NewStringf("%s;", *call);
String *call = Swig_cmemberset_call(name, type, self, varcref);
String *cres = NewStringf("%s;", call);
Setattr(n, "wrap:action", cres);
Delete(call);
Delete(cres);
}
Setattr(n, "type", void_type);
@ -1373,7 +1379,7 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) {
t = NewString(classname);
SwigType_add_pointer(t);
parms = NewParm(t, "self");
parms = NewParm(t, "self", n);
Setattr(parms, "self", "1");
Setattr(parms, "hidden","1");
Delete(t);
@ -1429,7 +1435,7 @@ int Swig_VarsetToFunction(Node *n, int flags) {
type = Getattr(n, "type");
nname = SwigType_namestr(name);
ty = Swig_wrapped_var_type(type, varcref);
parms = NewParm(ty, name);
parms = NewParm(ty, name, n);
if (flags & CWRAP_EXTEND) {
String *sname = Swig_name_set(name);

View file

@ -53,13 +53,15 @@ static char wrn_wnum_fmt[64];
static char wrn_nnum_fmt[64];
static char err_line_fmt[64];
static char err_eof_fmt[64];
static char diag_line_fmt[64];
static char diag_eof_fmt[64];
static String *format_filename(const_String_or_char_ptr filename);
/* -----------------------------------------------------------------------------
* Swig_warning()
*
* Issue a warning message
* Issue a warning message on stderr.
* ----------------------------------------------------------------------------- */
void Swig_warning(int wnum, const_String_or_char_ptr filename, int line, const char *fmt, ...) {
@ -122,7 +124,7 @@ void Swig_warning(int wnum, const_String_or_char_ptr filename, int line, const c
/* -----------------------------------------------------------------------------
* Swig_error()
*
* Issue an error message
* Issue an error message on stderr.
* ----------------------------------------------------------------------------- */
void Swig_error(const_String_or_char_ptr filename, int line, const char *fmt, ...) {
@ -249,8 +251,8 @@ void Swig_error_msg_format(ErrorMessageFormat format) {
by now a switch is used to translated into one. */
switch (format) {
case EMF_MICROSOFT:
fmt_line = "%s(%d)";
fmt_eof = "%s(999999)"; /* Is there a special character for EOF? Just use a large number. */
fmt_line = "%s(%d) ";
fmt_eof = "%s(999999) "; /* Is there a special character for EOF? Just use a large number. */
break;
case EMF_STANDARD:
default:
@ -258,10 +260,12 @@ void Swig_error_msg_format(ErrorMessageFormat format) {
fmt_eof = "%s:EOF";
}
sprintf(wrn_wnum_fmt, "%s: %s(%%d): ", fmt_line, warning);
sprintf(wrn_wnum_fmt, "%s: %s %%d: ", fmt_line, warning);
sprintf(wrn_nnum_fmt, "%s: %s: ", fmt_line, warning);
sprintf(err_line_fmt, "%s: %s: ", fmt_line, error);
sprintf(err_eof_fmt, "%s: %s: ", fmt_eof, error);
sprintf(diag_line_fmt, "%s: ", fmt_line);
sprintf(diag_eof_fmt, "%s: ", fmt_eof);
msg_format = format;
init_fmt = 1;
@ -279,3 +283,29 @@ static String *format_filename(const_String_or_char_ptr filename) {
#endif
return formatted_filename;
}
/* -----------------------------------------------------------------------------
* Swig_diagnostic()
*
* Issue a diagnostic message on stdout.
* ----------------------------------------------------------------------------- */
void Swig_diagnostic(const_String_or_char_ptr filename, int line, const char *fmt, ...) {
va_list ap;
String *formatted_filename = NULL;
if (!init_fmt)
Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT);
va_start(ap, fmt);
formatted_filename = format_filename(filename);
if (line > 0) {
Printf(stdout, diag_line_fmt, formatted_filename, line);
} else {
Printf(stdout, diag_eof_fmt, formatted_filename);
}
vPrintf(stdout, fmt, ap);
va_end(ap);
Delete(formatted_filename);
}

View file

@ -188,9 +188,8 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_
}
if (f) {
Delete(lastpath);
lastpath = Swig_filename_escape(filename);
lastpath = filename;
}
Delete(filename);
return f;
}
@ -248,7 +247,7 @@ static String *Swig_include_any(const_String_or_char_ptr name, int sysfile) {
str = Swig_read_file(f);
fclose(f);
Seek(str, 0, SEEK_SET);
file = Copy(lastpath);
file = Copy(Swig_last_file());
Setfile(str, file);
Delete(file);
Setline(str, 1);

View file

@ -92,8 +92,8 @@ void Swig_banner_target_lang(File *f, const_String_or_char_ptr commentchar) {
/* -----------------------------------------------------------------------------
* Swig_strip_c_comments()
*
* Return a new string with C comments stripped from the input string. Null is
* returned if there aren't any.
* Return a new string with C comments stripped from the input string. NULL is
* returned if there aren't any comments.
* ----------------------------------------------------------------------------- */
String *Swig_strip_c_comments(const String *s) {
@ -111,9 +111,10 @@ String *Swig_strip_c_comments(const String *s) {
comment_begin = c-1;
} else if (comment_begin && !comment_end && *c == '*') {
++c;
if (*c == '/')
if (*c == '/') {
comment_end = c;
break;
break;
}
}
++c;
}
@ -162,12 +163,25 @@ void Swig_filename_correct(String *filename) {
String *Swig_filename_escape(String *filename) {
String *adjusted_filename = Copy(filename);
#if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */
Replaceall(adjusted_filename, "\\\\", "\\"); /* remove double '\' in case any already present */
Replaceall(adjusted_filename, "\\", "\\\\");
Replaceall(adjusted_filename, "\\\\", "\\"); /* remove double '\' in case any already present */
Replaceall(adjusted_filename, "\\", "\\\\");
#endif
return adjusted_filename;
}
/* -----------------------------------------------------------------------------
* Swig_filename_unescape()
*
* Remove double backslash escaping in filename - for Windows
* ----------------------------------------------------------------------------- */
void Swig_filename_unescape(String *filename) {
(void)filename;
#if defined(_WIN32)
Replaceall(filename, "\\\\", "\\");
#endif
}
/* -----------------------------------------------------------------------------
* Swig_string_escape()
*
@ -896,7 +910,11 @@ String *Swig_scopename_suffix(const String *s) {
/* -----------------------------------------------------------------------------
* Swig_scopename_check()
*
* Checks to see if a name is qualified with a scope name
* Checks to see if a name is qualified with a scope name, examples:
* foo -> 0
* ::foo -> 1
* foo::bar -> 1
* foo< ::bar > -> 0
* ----------------------------------------------------------------------------- */
int Swig_scopename_check(const String *s) {

View file

@ -478,25 +478,12 @@ DOH *Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType
Delete(cls);
}
/* A template-based class lookup, check name first */
if (!rn && SwigType_istemplate(name)) {
String *t_name = SwigType_templateprefix(name);
if (!Equal(t_name, name)) {
if (!rn) {
String *t_name = SwigType_istemplate_templateprefix(name);
if (t_name)
rn = Swig_name_object_get(namehash, prefix, t_name, decl);
}
Delete(t_name);
}
/* A template-based class lookup */
/*
if (!rn && SwigType_istemplate(prefix)) {
String *t_prefix = SwigType_templateprefix(prefix);
if (Strcmp(t_prefix, prefix) != 0) {
String *t_name = SwigType_templateprefix(name);
rn = Swig_name_object_get(namehash, t_prefix, t_name, decl);
Delete(t_name);
}
Delete(t_prefix);
}
*/
}
/* A wildcard-based class lookup */
if (!rn) {
@ -667,10 +654,9 @@ void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *d
if (name) {
String *tname = NewStringEmpty();
/* add features for 'root' template */
if (SwigType_istemplate(name)) {
String *dname = SwigType_templateprefix(name);
String *dname = SwigType_istemplate_templateprefix(name);
if (dname) {
features_get(features, dname, decl, ncdecl, node);
Delete(dname);
}
/* Catch-all */
features_get(features, name, decl, ncdecl, node);
@ -688,16 +674,16 @@ void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *d
/* A specific class lookup */
if (Len(prefix)) {
/* A template-based class lookup */
if (SwigType_istemplate(prefix)) {
String *tprefix = SwigType_templateprefix(prefix);
String *tprefix = SwigType_istemplate_templateprefix(prefix);
if (tprefix) {
Clear(tname);
Printf(tname, "%s::%s", tprefix, name);
features_get(features, tname, decl, ncdecl, node);
Delete(tprefix);
}
Clear(tname);
Printf(tname, "%s::%s", prefix, name);
features_get(features, tname, decl, ncdecl, node);
Delete(tprefix);
}
} else {
/* Lookup in the global namespace only */
@ -706,6 +692,7 @@ void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *d
features_get(features, tname, decl, ncdecl, node);
}
Delete(tname);
Delete(dname);
}
if (name && SwigType_istemplate(name)) {
/* add features for complete template type */
@ -1615,7 +1602,7 @@ String *Swig_name_decl(Node *n) {
qname = NewString("");
if (qualifier && Len(qualifier) > 0)
Printf(qname, "%s::", qualifier);
Printf(qname, "%s", name);
Printf(qname, "%s", SwigType_str(name, 0));
decl = NewStringf("%s(%s)%s", qname, ParmList_errorstr(Getattr(n, "parms")), SwigType_isconst(Getattr(n, "decl")) ? " const" : "");

View file

@ -18,10 +18,25 @@ char cvsroot_parms_c[] = "$Id$";
/* ------------------------------------------------------------------------
* NewParm()
*
* Create a new parameter from datatype 'type' and name 'name'.
* Create a new parameter from datatype 'type' and name 'name' copying
* the file and line number from the Node file_line_node.
* ------------------------------------------------------------------------ */
Parm *NewParm(SwigType *type, const_String_or_char_ptr name) {
Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *file_line_node) {
Parm *p = NewParmWithoutFileLineInfo(type, name);
Setfile(p, Getfile(file_line_node));
Setline(p, Getline(file_line_node));
return p;
}
/* ------------------------------------------------------------------------
* NewParmWithoutFileLineInfo()
*
* Create a new parameter from datatype 'type' and name 'name' without any
* file / line numbering information.
* ------------------------------------------------------------------------ */
Parm *NewParmWithoutFileLineInfo(SwigType *type, const_String_or_char_ptr name) {
Parm *p = NewHash();
set_nodeType(p, "parm");
if (type) {
@ -118,6 +133,14 @@ int ParmList_len(ParmList *p) {
return i;
}
/* ---------------------------------------------------------------------
* get_empty_type()
* ---------------------------------------------------------------------- */
static SwigType *get_empty_type() {
return NewStringEmpty();
}
/* ---------------------------------------------------------------------
* ParmList_str()
*
@ -127,7 +150,8 @@ int ParmList_len(ParmList *p) {
String *ParmList_str(ParmList *p) {
String *out = NewStringEmpty();
while (p) {
String *pstr = SwigType_str(Getattr(p, "type"), Getattr(p, "name"));
String *type = Getattr(p, "type");
String *pstr = SwigType_str(type ? type : get_empty_type(), Getattr(p, "name"));
Append(out, pstr);
p = nextSibling(p);
if (p) {
@ -148,7 +172,8 @@ String *ParmList_str_defaultargs(ParmList *p) {
String *out = NewStringEmpty();
while (p) {
String *value = Getattr(p, "value");
String *pstr = SwigType_str(Getattr(p, "type"), Getattr(p, "name"));
String *type = Getattr(p, "type");
String *pstr = SwigType_str(type ? type : get_empty_type(), Getattr(p, "name"));
Append(out, pstr);
if (value) {
Printf(out, "=%s", value);
@ -162,6 +187,24 @@ String *ParmList_str_defaultargs(ParmList *p) {
return out;
}
/* -----------------------------------------------------------------------------
* ParmList_str_multibrackets()
*
* Generates a string of parameters including default arguments adding brackets
* if more than one parameter
* ----------------------------------------------------------------------------- */
String *ParmList_str_multibrackets(ParmList *p) {
String *out;
String *parm_str = ParmList_str_defaultargs(p);
if (ParmList_len(p) > 1)
out = NewStringf("(%s)", parm_str);
else
out = NewStringf("%s", parm_str);
Delete(parm_str);
return out;
}
/* ---------------------------------------------------------------------
* ParmList_protostr()
*
@ -171,7 +214,8 @@ String *ParmList_str_defaultargs(ParmList *p) {
String *ParmList_protostr(ParmList *p) {
String *out = NewStringEmpty();
while (p) {
String *pstr = SwigType_str(Getattr(p, "type"), 0);
String *type = Getattr(p, "type");
String *pstr = SwigType_str(type ? type : get_empty_type(), 0);
Append(out, pstr);
p = nextSibling(p);
if (p) {

View file

@ -20,7 +20,8 @@ char cvsroot_scanner_c[] = "$Id$";
#include <ctype.h>
extern String *cparse_file;
extern int cparse_start_line;
extern int cparse_cplusplus;
extern int cparse_start_line;
struct Scanner {
String *text; /* Current token value */
@ -97,6 +98,7 @@ void Scanner_clear(Scanner * s) {
Clear(s->scanobjs);
Scanner_clear_brackets(s);
Delete(s->error);
s->str = 0;
s->error = 0;
s->line = 1;
s->nexttoken = -1;
@ -864,7 +866,7 @@ static int look(Scanner * s) {
}
break;
case 7: /* Identifier or unicode/custom delimiter string */
case 7: /* Identifier or true/false or unicode/custom delimiter string */
if (c=='R') { /* Possibly CUSTOM DELIMITER string */
state = 72;
break;
@ -875,7 +877,7 @@ static int look(Scanner * s) {
}
if ((c = nextchar(s)) == 0) {
return SWIG_TOKEN_ID;
state = 76;
}
else if (c=='\"') { /* Definitely u, U or L string */
retract(s, 1);
@ -895,20 +897,20 @@ static int look(Scanner * s) {
case 70: /* Identifier */
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_ID;
if (isalnum(c) || (c == '_') || (c == '$')) {
state = 76;
else if (isalnum(c) || (c == '_') || (c == '$')) {
state = 70;
} else {
retract(s, 1);
return SWIG_TOKEN_ID;
state = 76;
}
break;
case 71: /* Possibly u8 string */
if ((c = nextchar(s)) == 0) {
return SWIG_TOKEN_ID;
state = 76;
}
if (c=='\"') {
else if (c=='\"') {
retract(s, 1); /* Definitely u8 string */
state = 1000;
}
@ -926,9 +928,9 @@ static int look(Scanner * s) {
case 73:
case 74:
if ((c = nextchar(s)) == 0) {
return SWIG_TOKEN_ID;
state = 76;
}
if (c=='\"') {
else if (c=='\"') {
retract(s, 1); /* Definitely custom delimiter u, U or L string */
str_delimiter = NewStringEmpty();
state = 1000;
@ -956,10 +958,20 @@ static int look(Scanner * s) {
} else {
retract(s,1);
if (Len(s->text) == 1) return SWIG_TOKEN_DOLLAR;
return SWIG_TOKEN_ID;
state = 76;
}
break;
case 76: /* Identifier or true/false */
if (cparse_cplusplus) {
if (Strcmp(s->text, "true") == 0)
return SWIG_TOKEN_BOOL;
else if (Strcmp(s->text, "false") == 0)
return SWIG_TOKEN_BOOL;
}
return SWIG_TOKEN_ID;
break;
case 8: /* A numerical digit */
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_INT;

View file

@ -543,7 +543,13 @@ String *SwigType_namestr(const SwigType *t) {
Putc(' ', r);
Putc('>', r);
suffix = SwigType_templatesuffix(t);
Append(r, suffix);
if (Len(suffix) > 0) {
String *suffix_namestr = SwigType_namestr(suffix);
Append(r, suffix_namestr);
Delete(suffix_namestr);
} else {
Append(r, suffix);
}
Delete(suffix);
Delete(p);
return r;
@ -562,7 +568,10 @@ String *SwigType_str(SwigType *s, const_String_or_char_ptr id) {
int nelements, i;
if (id) {
result = NewString(id);
/* stringify the id expanding templates, for example when the id is a fully qualified templated class name */
String *id_str = NewString(id); /* unfortunate copy due to current const limitations */
result = SwigType_str(id_str, 0);
Delete(id_str);
} else {
result = NewStringEmpty();
}
@ -1134,6 +1143,25 @@ void SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
Delete(elem);
}
/* -----------------------------------------------------------------------------
* SwigType_remove_global_scope_prefix()
*
* Removes the unary scope operator (::) prefix indicating global scope in all
* components of the type
* ----------------------------------------------------------------------------- */
SwigType *SwigType_remove_global_scope_prefix(const SwigType *t) {
SwigType *result;
const char *type = Char(t);
if (strncmp(type, "::", 2) == 0)
type += 2;
result = NewString(type);
Replaceall(result, ".::", ".");
Replaceall(result, "(::", "(");
Replaceall(result, "enum ::", "enum ");
return result;
}
/* -----------------------------------------------------------------------------
* SwigType_check_decl()
*

View file

@ -131,7 +131,7 @@ extern "C" {
extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms);
extern SwigType *SwigType_add_template(SwigType *t, ParmList *parms);
extern SwigType *SwigType_pop_function(SwigType *t);
extern ParmList *SwigType_function_parms(SwigType *t);
extern ParmList *SwigType_function_parms(SwigType *t, Node *file_line_node);
extern List *SwigType_split(const SwigType *t);
extern String *SwigType_pop(SwigType *t);
extern void SwigType_push(SwigType *t, SwigType *s);
@ -167,6 +167,7 @@ extern "C" {
extern String *SwigType_namestr(const SwigType *t);
extern String *SwigType_templateprefix(const SwigType *t);
extern String *SwigType_templatesuffix(const SwigType *t);
extern String *SwigType_istemplate_templateprefix(const SwigType *t);
extern String *SwigType_templateargs(const SwigType *t);
extern String *SwigType_prefix(const SwigType *t);
extern int SwigType_array_ndim(SwigType *t);
@ -175,6 +176,7 @@ extern "C" {
extern SwigType *SwigType_array_type(SwigType *t);
extern String *SwigType_default(SwigType *t);
extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep);
extern SwigType *SwigType_remove_global_scope_prefix(const SwigType *t);
extern SwigType *SwigType_alttype(SwigType *t, int ltmap);
extern void SwigType_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl);
@ -209,6 +211,10 @@ extern "C" {
/* --- Symbol table module --- */
extern void Swig_symbol_print_tables(Symtab *symtab);
extern void Swig_symbol_print_tables_summary(void);
extern void Swig_symbol_print_symbols(void);
extern void Swig_symbol_print_csymbols(void);
extern void Swig_symbol_init(void);
extern void Swig_symbol_setscopename(const_String_or_char_ptr name);
extern String *Swig_symbol_getscopename(void);
@ -216,6 +222,7 @@ extern "C" {
extern Symtab *Swig_symbol_newscope(void);
extern Symtab *Swig_symbol_setscope(Symtab *);
extern Symtab *Swig_symbol_getscope(const_String_or_char_ptr symname);
extern Symtab *Swig_symbol_global_scope(void);
extern Symtab *Swig_symbol_current(void);
extern Symtab *Swig_symbol_popscope(void);
extern Node *Swig_symbol_add(const_String_or_char_ptr symname, Node *node);
@ -296,8 +303,9 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Swig_banner(File *f);
extern void Swig_banner_target_lang(File *f, const_String_or_char_ptr commentchar);
extern String *Swig_strip_c_comments(const String *s);
extern String *Swig_filename_escape(String *filename);
extern void Swig_filename_correct(String *filename);
extern String *Swig_filename_escape(String *filename);
extern void Swig_filename_unescape(String *filename);
extern String *Swig_string_escape(String *s);
extern String *Swig_string_mangle(const String *s);
extern void Swig_scopename_split(const String *s, String **prefix, String **last);
@ -311,13 +319,8 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern String *Swig_string_title(String *s);
extern void Swig_init(void);
extern void Swig_warn(const char *filename, int line, const char *msg);
extern int Swig_value_wrapper_mode(int mode);
#define WARNING(msg) Swig_warn(__FILE__,__LINE__,msg)
typedef enum { EMF_STANDARD, EMF_MICROSOFT } ErrorMessageFormat;
extern void Swig_warning(int num, const_String_or_char_ptr filename, int line, const char *fmt, ...);
@ -328,6 +331,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Swig_warnall(void);
extern int Swig_warn_count(void);
extern void Swig_error_msg_format(ErrorMessageFormat format);
extern void Swig_diagnostic(const_String_or_char_ptr filename, int line, const char *fmt, ...);
/* --- C Wrappers --- */
extern String *Swig_cparm_name(Parm *p, int i);
@ -352,7 +356,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director);
extern int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags);
extern int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags);
extern int Swig_MembersetToFunction(Node *n, String *classname, int flags, String **call);
extern int Swig_MembersetToFunction(Node *n, String *classname, int flags);
extern int Swig_MembergetToFunction(Node *n, String *classname, int flags);
extern int Swig_VargetToFunction(Node *n, int flags);
extern int Swig_VarsetToFunction(Node *n, int flags);
@ -372,22 +376,21 @@ extern int ParmList_is_compactdefargs(ParmList *p);
/* --- Legacy Typemap API (somewhat simplified, ha!) --- */
extern void Swig_typemap_init(void);
extern void Swig_typemap_register(const_String_or_char_ptr op, ParmList *pattern, const_String_or_char_ptr code, ParmList *locals, ParmList *kwargs);
extern int Swig_typemap_copy(const_String_or_char_ptr op, ParmList *srcpattern, ParmList *pattern);
extern void Swig_typemap_clear(const_String_or_char_ptr op, ParmList *pattern);
extern void Swig_typemap_register(const_String_or_char_ptr tmap_method, ParmList *pattern, const_String_or_char_ptr code, ParmList *locals, ParmList *kwargs);
extern int Swig_typemap_copy(const_String_or_char_ptr tmap_method, ParmList *srcpattern, ParmList *pattern);
extern void Swig_typemap_clear(const_String_or_char_ptr tmap_method, ParmList *pattern);
extern int Swig_typemap_apply(ParmList *srcpat, ParmList *destpat);
extern void Swig_typemap_clear_apply(ParmList *pattern);
extern void Swig_typemap_debug(void);
extern void Swig_typemap_search_debug_set(void);
extern void Swig_typemap_used_debug_set(void);
extern Hash *Swig_typemap_search(const_String_or_char_ptr op, SwigType *type, const_String_or_char_ptr pname, SwigType **matchtype);
extern Hash *Swig_typemap_search_multi(const_String_or_char_ptr op, ParmList *parms, int *nmatch);
extern String *Swig_typemap_lookup(const_String_or_char_ptr op, Node *n, const_String_or_char_ptr lname, Wrapper *f);
extern String *Swig_typemap_lookup_out(const_String_or_char_ptr op, Node *n, const_String_or_char_ptr lname, Wrapper *f, String *actioncode);
extern void Swig_typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr op, Parm *p);
extern String *Swig_typemap_lookup(const_String_or_char_ptr tmap_method, Node *n, const_String_or_char_ptr lname, Wrapper *f);
extern String *Swig_typemap_lookup_out(const_String_or_char_ptr tmap_method, Node *n, const_String_or_char_ptr lname, Wrapper *f, String *actioncode);
extern void Swig_typemap_new_scope(void);
extern Hash *Swig_typemap_pop_scope(void);
extern void Swig_typemap_attach_parms(const_String_or_char_ptr op, ParmList *parms, Wrapper *f);
extern void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *parms, Wrapper *f);
/* --- Code fragment support --- */
@ -402,6 +405,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Wrapper_director_mode_set(int);
extern void Wrapper_director_protected_mode_set(int);
extern void Wrapper_all_protected_mode_set(int);
extern void Language_replace_special_variables(String *method, String *tm, Parm *parm);
/* -- template init -- */

View file

@ -15,7 +15,8 @@
/* $Id: swig.h 9629 2006-12-30 18:27:47Z beazley $ */
/* Individual parameters */
extern Parm *NewParm(SwigType *type, const_String_or_char_ptr name);
extern Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *file_line_node);
extern Parm *NewParmWithoutFileLineInfo(SwigType *type, const_String_or_char_ptr name);
extern Parm *CopyParm(Parm *p);
/* Parameter lists */
@ -28,6 +29,7 @@ extern int ParmList_has_defaultargs(ParmList *p);
/* Output functions */
extern String *ParmList_str(ParmList *);
extern String *ParmList_str_defaultargs(ParmList *);
extern String *ParmList_str_multibrackets(ParmList *);
extern String *ParmList_protostr(ParmList *);

View file

@ -68,6 +68,7 @@ extern void Scanner_freeze_line(Scanner *s, int val);
#define SWIG_TOKEN_ULONGLONG 29 /* 314ULL */
#define SWIG_TOKEN_QUESTION 30 /* ? */
#define SWIG_TOKEN_COMMENT 31 /* C or C++ comment */
#define SWIG_TOKEN_BOOL 32 /* true or false */
#define SWIG_TOKEN_ILLEGAL 99
#define SWIG_TOKEN_ERROR -1

View file

@ -179,20 +179,80 @@ static Hash *global_scope = 0; /* Global scope */
/* common attribute keys, to avoid calling find_key all the times */
/* -----------------------------------------------------------------------------
* Swig_symbol_print_tables()
*
* Debug display of symbol tables
* ----------------------------------------------------------------------------- */
#if 0
void Swig_symbol_dump_symtable() {
Printf(stdout, "DUMPING SYMTABLE start =======================================\n");
{
Hash *cst = Getattr(current_symtab, "csymtab");
Swig_print_tree(cst);
/*
Swig_print_tree(Getattr(cst, "NumSpace"));
*/
}
Printf(stdout, "DUMPING SYMTABLE end =======================================\n");
void Swig_symbol_print_tables(Symtab *symtab) {
if (!symtab)
symtab = current_symtab;
Printf(stdout, "SYMBOL TABLES start =======================================\n");
Swig_print_tree(symtab);
Printf(stdout, "SYMBOL TABLES finish =======================================\n");
}
/* -----------------------------------------------------------------------------
* Swig_symbol_print_tables_summary()
*
* Debug summary display of all symbol tables by fully-qualified name
* ----------------------------------------------------------------------------- */
void Swig_symbol_print_tables_summary(void) {
Printf(stdout, "SYMBOL TABLES SUMMARY start =======================================\n");
Swig_print_node(symtabs);
Printf(stdout, "SYMBOL TABLES SUMMARY finish =======================================\n");
}
/* -----------------------------------------------------------------------------
* symbol_print_symbols()
* ----------------------------------------------------------------------------- */
static void symbol_print_symbols(const char *symboltabletype) {
Node *table = symtabs;
Iterator ki = First(table);
while (ki.key) {
String *k = ki.key;
Printf(stdout, "===================================================\n");
Printf(stdout, "%s -\n", k);
{
Symtab *symtab = Getattr(Getattr(table, k), symboltabletype);
Iterator it = First(symtab);
while (it.key) {
String *symname = it.key;
Printf(stdout, " %s\n", symname);
it = Next(it);
}
}
ki = Next(ki);
}
}
/* -----------------------------------------------------------------------------
* Swig_symbol_print_symbols()
*
* Debug display of all the target language symbols
* ----------------------------------------------------------------------------- */
void Swig_symbol_print_symbols(void) {
Printf(stdout, "SYMBOLS start =======================================\n");
symbol_print_symbols("symtab");
Printf(stdout, "SYMBOLS finish =======================================\n");
}
/* -----------------------------------------------------------------------------
* Swig_symbol_print_csymbols()
*
* Debug display of all the C symbols
* ----------------------------------------------------------------------------- */
void Swig_symbol_print_csymbols(void) {
Printf(stdout, "CSYMBOLS start =======================================\n");
symbol_print_symbols("csymtab");
Printf(stdout, "CSYMBOLS finish =======================================\n");
}
#endif
/* -----------------------------------------------------------------------------
* Swig_symbol_init()
@ -200,7 +260,7 @@ void Swig_symbol_dump_symtable() {
* Create a new symbol table object
* ----------------------------------------------------------------------------- */
void Swig_symbol_init() {
void Swig_symbol_init(void) {
current = NewHash();
current_symtab = NewHash();
@ -244,7 +304,7 @@ void Swig_symbol_setscopename(const_String_or_char_ptr name) {
* Get the C scopename of the current symbol table
* ----------------------------------------------------------------------------- */
String *Swig_symbol_getscopename() {
String *Swig_symbol_getscopename(void) {
return Getattr(current_symtab, "name");
}
@ -299,7 +359,7 @@ String *Swig_symbol_qualifiedscopename(Symtab *symtab) {
* Create a new scope. Returns the newly created scope.
* ----------------------------------------------------------------------------- */
Symtab *Swig_symbol_newscope() {
Symtab *Swig_symbol_newscope(void) {
Hash *n;
Hash *hsyms, *h;
@ -350,7 +410,7 @@ Symtab *Swig_symbol_setscope(Symtab *sym) {
* scope to the parent scope.
* ----------------------------------------------------------------------------- */
Symtab *Swig_symbol_popscope() {
Symtab *Swig_symbol_popscope(void) {
Hash *h = current_symtab;
current_symtab = Getattr(current_symtab, "parentNode");
assert(current_symtab);
@ -361,13 +421,23 @@ Symtab *Swig_symbol_popscope() {
return h;
}
/* -----------------------------------------------------------------------------
* Swig_symbol_global_scope()
*
* Return the symbol table for the global scope.
* ----------------------------------------------------------------------------- */
Symtab *Swig_symbol_global_scope(void) {
return global_scope;
}
/* -----------------------------------------------------------------------------
* Swig_symbol_current()
*
* Return the current symbol table.
* ----------------------------------------------------------------------------- */
Symtab *Swig_symbol_current() {
Symtab *Swig_symbol_current(void) {
return current_symtab;
}
@ -1002,6 +1072,8 @@ Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) {
String *nname = NewString(cname + 2);
if (Swig_scopename_check(nname)) {
s = symbol_lookup_qualified(nname, global_scope, 0, 0, 0);
} else {
s = symbol_lookup(nname, global_scope, 0);
}
Delete(nname);
} else {
@ -1074,6 +1146,8 @@ Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (*
String *nname = NewString(cname + 2);
if (Swig_scopename_check(nname)) {
s = symbol_lookup_qualified(nname, global_scope, 0, 0, checkfunc);
} else {
s = symbol_lookup(nname, global_scope, checkfunc);
}
Delete(nname);
} else {
@ -1138,6 +1212,8 @@ Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) {
String *nname = NewString(cname + 2);
if (Swig_scopename_check(nname)) {
s = symbol_lookup_qualified(nname, global_scope, 0, 0, 0);
} else {
s = symbol_lookup(nname, global_scope, 0);
}
Delete(nname);
} else {
@ -1186,6 +1262,8 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n,
String *nname = NewString(cname + 2);
if (Swig_scopename_check(nname)) {
s = symbol_lookup_qualified(nname, global_scope, 0, 0, checkfunc);
} else {
s = symbol_lookup(nname, global_scope, checkfunc);
}
Delete(nname);
} else {
@ -1257,7 +1335,8 @@ void Swig_symbol_remove(Node *n) {
Setattr(symtab, symname, symnext);
fixovername = symnext; /* fix as symbol to remove is at head of linked list */
} else {
Delattr(symtab, symname);
if (symname)
Delattr(symtab, symname);
}
}
if (symnext) {
@ -1732,7 +1811,7 @@ ParmList *Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope,
ntq = ty;
}
/* Printf(stderr,"value %s %s %s\n",value,ntr,ntq); */
cp = NewParm(ntq, 0);
cp = NewParmWithoutFileLineInfo(ntq, 0);
if (lp)
set_nextSibling(lp, cp);
else
@ -1809,7 +1888,7 @@ SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope) {
String *tprefix = SwigType_templateprefix(base);
String *targs = SwigType_templateargs(base);
String *tsuffix = SwigType_templatesuffix(base);
ParmList *tparms = SwigType_function_parms(targs);
ParmList *tparms = SwigType_function_parms(targs, 0);
Node *tempn = Swig_symbol_clookup_local(tprefix, tscope);
if (!tempn && tsuffix && Len(tsuffix)) {
tempn = Swig_symbol_clookup(tprefix, 0);

View file

@ -34,7 +34,7 @@ void Swig_print_tags(DOH *obj, DOH *root) {
croot = root;
while (obj) {
Printf(stdout, "%s . %s (%s:%d)\n", croot, nodeType(obj), Getfile(obj), Getline(obj));
Swig_diagnostic(Getfile(obj), Getline(obj), "%s . %s\n", croot, nodeType(obj));
cobj = firstChild(obj);
if (cobj) {
newroot = NewStringf("%s . %s", croot, nodeType(obj));
@ -272,7 +272,7 @@ void Swig_require(const char *ns, Node *n, ...) {
}
obj = Getattr(n, name);
if (!opt && !obj) {
Printf(stderr, "%s:%d. Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", Getfile(n), Getline(n), name, nodeType(n));
Swig_error(Getfile(n), Getline(n), "Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", name, nodeType(n));
assert(obj);
}
if (!obj)

File diff suppressed because it is too large Load diff

View file

@ -824,13 +824,15 @@ int SwigType_isfunction(SwigType *t) {
return 0;
}
ParmList *SwigType_function_parms(SwigType *t) {
/* Create a list of parameters from the type t, using the file_line_node Node for
* file and line numbering for the parameters */
ParmList *SwigType_function_parms(SwigType *t, Node *file_line_node) {
List *l = SwigType_parmlist(t);
Hash *p, *pp = 0, *firstp = 0;
Iterator o;
for (o = First(l); o.item; o = Next(o)) {
p = NewParm(o.item, 0);
p = file_line_node ? NewParm(o.item, 0, file_line_node) : NewParmWithoutFileLineInfo(o.item, 0);
if (!firstp)
firstp = p;
if (pp) {
@ -893,11 +895,12 @@ SwigType *SwigType_add_template(SwigType *t, ParmList *parms) {
* SwigType_templateprefix()
*
* Returns the prefix before the first template definition.
* Returns the type unmodified if not a template.
* For example:
*
* Foo<(p.int)>::bar
*
* returns "Foo"
* Foo<(p.int)>::bar => Foo
* r.q(const).Foo<(p.int)>::bar => r.q(const).Foo
* Foo => Foo
* ----------------------------------------------------------------------------- */
String *SwigType_templateprefix(const SwigType *t) {
@ -938,6 +941,25 @@ String *SwigType_templatesuffix(const SwigType *t) {
return NewStringEmpty();
}
/* -----------------------------------------------------------------------------
* SwigType_istemplate_templateprefix()
*
* Combines SwigType_istemplate and SwigType_templateprefix efficiently into one function.
* Returns the prefix before the first template definition.
* Returns NULL if not a template.
* For example:
*
* Foo<(p.int)>::bar => Foo
* r.q(const).Foo<(p.int)>::bar => r.q(const).Foo
* Foo => NULL
* ----------------------------------------------------------------------------- */
String *SwigType_istemplate_templateprefix(const SwigType *t) {
const char *s = Char(t);
const char *c = strstr(s, "<(");
return c ? NewStringWithSize(s, c - s) : 0;
}
/* -----------------------------------------------------------------------------
* SwigType_templateargs()
*

View file

@ -844,7 +844,8 @@ SwigType *SwigType_typedef_resolve_all(SwigType *t) {
*
* Given a type declaration, this function tries to fully qualify it according to
* typedef scope rules.
* Inconsistency to be fixed: ::Foo returns ::Foo, whereas ::Foo * returns Foo *
* If the unary scope operator (::) is used as a prefix to the type to denote global
* scope, it is left in place.
* ----------------------------------------------------------------------------- */
SwigType *SwigType_typedef_qualified(SwigType *t) {
@ -852,10 +853,6 @@ SwigType *SwigType_typedef_qualified(SwigType *t) {
String *result;
int i, len;
if (strncmp(Char(t), "::", 2) == 0) {
return Copy(t);
}
if (!typedef_qualified_cache)
typedef_qualified_cache = NewHash();
result = Getattr(typedef_qualified_cache, t);
@ -1003,10 +1000,6 @@ SwigType *SwigType_typedef_qualified(SwigType *t) {
Delete(qprefix);
Delete(parms);
}
if (strncmp(Char(e), "::", 2) == 0) {
Delitem(e, 0);
Delitem(e, 0);
}
Append(result, e);
Delete(ty);
} else if (SwigType_isfunction(e)) {
@ -1124,11 +1117,13 @@ int SwigType_typedef_using(const_String_or_char_ptr name) {
/* Figure out the scope the using directive refers to */
{
prefix = Swig_scopename_prefix(name);
s = SwigType_find_scope(current_scope, prefix);
if (s) {
Hash *ttab = Getattr(s, "typetab");
if (!Getattr(ttab, base) && defined_name) {
Setattr(ttab, base, defined_name);
if (prefix) {
s = SwigType_find_scope(current_scope, prefix);
if (s) {
Hash *ttab = Getattr(s, "typetab");
if (!Getattr(ttab, base) && defined_name) {
Setattr(ttab, base, defined_name);
}
}
}
}
@ -1170,9 +1165,9 @@ int SwigType_isclass(SwigType *t) {
isclass = 1;
}
/* Hmmm. Not a class. If a template, it might be uninstantiated */
if (!isclass && SwigType_istemplate(qtys)) {
String *tp = SwigType_templateprefix(qtys);
if (Strcmp(tp, t) != 0) {
if (!isclass) {
String *tp = SwigType_istemplate_templateprefix(qtys);
if (tp && Strcmp(tp, t) != 0) {
isclass = SwigType_isclass(tp);
}
Delete(tp);