Merge branch 'master' into doxygen

Merge with ~3.0.1 sources from master.
This commit is contained in:
Vadim Zeitlin 2014-04-30 18:37:57 +02:00
commit 1ebd2334b8
1593 changed files with 51732 additions and 28076 deletions

View file

@ -12,11 +12,9 @@
* the naming of local variables, calling conventions, and so forth.
* ----------------------------------------------------------------------------- */
char cvsroot_cwrap_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
extern int cparse_cplusplus;
static const char *cresult_variable_name = "result";
static Parm *nonvoid_parms(Parm *p) {
@ -90,6 +88,19 @@ static String *Swig_clocal(SwigType *t, const_String_or_char_ptr name, const_Str
Delete(lstrname);
}
break;
case T_RVALUE_REFERENCE:
if (value) {
String *lstrname = SwigType_lstr(t, name);
String *lstr = SwigType_lstr(t, 0);
Printf(decl, "%s = (%s) &%s_defrvalue", lstrname, lstr, name);
Delete(lstrname);
Delete(lstr);
} else {
String *lstrname = SwigType_lstr(t, name);
Printf(decl, "%s = 0", lstrname);
Delete(lstrname);
}
break;
case T_VOID:
break;
case T_VARARGS:
@ -255,7 +266,35 @@ int Swig_cargs(Wrapper *w, ParmList *p) {
Delete(defname);
Delete(defvalue);
}
} else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING))) {
} else if (tycode == T_RVALUE_REFERENCE) {
if (pvalue) {
SwigType *tvalue;
String *defname, *defvalue, *rvalue, *qvalue;
rvalue = SwigType_typedef_resolve_all(pvalue);
qvalue = SwigType_typedef_qualified(rvalue);
defname = NewStringf("%s_defrvalue", lname);
tvalue = Copy(type);
SwigType_del_rvalue_reference(tvalue);
tycode = SwigType_type(tvalue);
if (tycode != T_USER) {
/* plain primitive type, we copy the the def value */
String *lstr = SwigType_lstr(tvalue, defname);
defvalue = NewStringf("%s = %s", lstr, qvalue);
Delete(lstr);
} else {
/* user type, we copy the reference value */
String *str = SwigType_str(type, defname);
defvalue = NewStringf("%s = %s", str, qvalue);
Delete(str);
}
Wrapper_add_localv(w, defname, defvalue, NIL);
Delete(tvalue);
Delete(rvalue);
Delete(qvalue);
Delete(defname);
Delete(defvalue);
}
} else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING) || (tycode == T_WSTRING))) {
pvalue = (String *) "0";
}
if (!altty) {
@ -295,6 +334,23 @@ String *Swig_cresult(SwigType *t, const_String_or_char_ptr name, const_String_or
Delete(lstr);
}
break;
case T_RVALUE_REFERENCE:
{
String *const_lvalue_str;
String *lstr = SwigType_lstr(t, 0);
SwigType *tt = Copy(t);
SwigType_del_rvalue_reference(tt);
SwigType_add_qualifier(tt, "const");
SwigType_add_reference(tt);
const_lvalue_str = SwigType_rcaststr(tt, 0);
Printf(fcall, "%s = (%s) &%s", name, lstr, const_lvalue_str);
Delete(const_lvalue_str);
Delete(tt);
Delete(lstr);
}
break;
case T_USER:
Printf(fcall, "%s = ", name);
break;
@ -411,7 +467,7 @@ static String *Swig_cmethod_call(const_String_or_char_ptr name, ParmList *parms,
return func;
if (!self)
self = (char *) "(this)->";
self = "(this)->";
Append(func, self);
if (SwigType_istemplate(name) && (strncmp(Char(name), "operator ", 9) == 0)) {
@ -719,7 +775,25 @@ String *Swig_cmemberset_call(const_String_or_char_ptr name, SwigType *type, Stri
if (SwigType_type(type) != T_ARRAY) {
if (!Strstr(type, "enum $unnamed")) {
String *dref = Swig_wrapped_var_deref(type, pname1, varcref);
Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref);
int extra_cast = 0;
if (cparse_cplusplusout) {
/* Required for C nested structs compiled as C++ as a duplicate of the nested struct is put into the global namespace.
* We could improve this by adding the extra casts just for nested structs rather than all structs. */
String *base = SwigType_base(type);
extra_cast = SwigType_isclass(base);
Delete(base);
}
if (extra_cast) {
String *lstr;
SwigType *ptype = Copy(type);
SwigType_add_pointer(ptype);
lstr = SwigType_lstr(ptype, 0);
Printf(func, "if (%s) *(%s)&%s%s = %s", pname0, lstr, self, name, dref);
Delete(lstr);
Delete(ptype);
} else {
Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref);
}
Delete(dref);
} else {
Printf(func, "if (%s && sizeof(int) == sizeof(%s%s)) *(int*)(void*)&(%s%s) = %s", pname0, self, name, self, name, pname1);
@ -759,6 +833,46 @@ String *Swig_cmemberget_call(const_String_or_char_ptr name, SwigType *t, String
return func;
}
/* -----------------------------------------------------------------------------
* Swig_replace_special_variables()
*
* Replaces special variables with a value from the supplied node
* ----------------------------------------------------------------------------- */
void Swig_replace_special_variables(Node *n, Node *parentnode, String *code) {
Node *parentclass = parentnode;
String *overloaded = Getattr(n, "sym:overloaded");
Replaceall(code, "$name", Getattr(n, "name"));
Replaceall(code, "$symname", Getattr(n, "sym:name"));
Replaceall(code, "$wrapname", Getattr(n, "wrap:name"));
Replaceall(code, "$overname", overloaded ? Char(Getattr(n, "sym:overname")) : "");
if (Strstr(code, "$decl")) {
String *decl = Swig_name_decl(n);
Replaceall(code, "$decl", decl);
Delete(decl);
}
if (Strstr(code, "$fulldecl")) {
String *fulldecl = Swig_name_fulldecl(n);
Replaceall(code, "$fulldecl", fulldecl);
Delete(fulldecl);
}
if (parentclass && !Equal(nodeType(parentclass), "class"))
parentclass = 0;
if (Strstr(code, "$parentclasssymname")) {
String *parentclasssymname = 0;
if (parentclass)
parentclasssymname = Getattr(parentclass, "sym:name");
Replaceall(code, "$parentclasssymname", parentclasssymname ? parentclasssymname : "");
}
if (Strstr(code, "$parentclassname")) {
String *parentclassname = 0;
if (parentclass)
parentclassname = Getattr(parentclass, "name");
Replaceall(code, "$parentclassname", parentclassname ? parentclassname : "");
}
}
/* -----------------------------------------------------------------------------
* extension_code()
*
@ -767,14 +881,17 @@ String *Swig_cmemberget_call(const_String_or_char_ptr name, SwigType *t, String
* return_type function_name(parms) code
*
* ----------------------------------------------------------------------------- */
static String *extension_code(const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) {
static String *extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) {
String *parms_str = cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms);
String *sig = NewStringf("%s(%s)", function_name, parms_str);
String *sig = NewStringf("%s(%s)", function_name, (cplusplus || Len(parms_str)) ? parms_str : "void");
String *rt_sig = SwigType_str(return_type, sig);
String *body = NewStringf("SWIGINTERN %s", rt_sig);
Printv(body, code, "\n", NIL);
if (self)
Replaceall(body, "$self", self);
if (Strstr(body, "$")) {
Swig_replace_special_variables(n, parentNode(parentNode(n)), body);
if (self)
Replaceall(body, "$self", self);
}
Delete(parms_str);
Delete(sig);
Delete(rt_sig);
@ -791,7 +908,7 @@ static String *extension_code(const String *function_name, ParmList *parms, Swig
*
* ----------------------------------------------------------------------------- */
int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) {
String *body = extension_code(function_name, parms, return_type, code, cplusplus, self);
String *body = extension_code(n, function_name, parms, return_type, code, cplusplus, self);
Setattr(n, "wrap:code", body);
Delete(body);
return SWIG_OK;
@ -812,6 +929,9 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
String *self = 0;
int is_smart_pointer_overload = 0;
String *qualifier = Getattr(n, "qualifier");
String *directorScope = NewString(nspace);
Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
/* If smart pointer without const overload or mutable method, change self dereferencing */
if (flags & CWRAP_SMART_POINTER) {
@ -820,8 +940,8 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
self = NewString("(*(this))->");
is_smart_pointer_overload = 1;
}
else if (Cmp(Getattr(n, "storage"), "static") == 0) {
String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname;
else if (Swig_storage_isstatic(n)) {
String *cname = Getattr(n, "extendsmartclassname") ? Getattr(n, "extendsmartclassname") : classname;
String *ctname = SwigType_namestr(cname);
self = NewStringf("(*(%s const *)this)->", ctname);
is_smart_pointer_overload = 1;
@ -894,7 +1014,10 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
/* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */
String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname"));
explicitcall_name = NewStringf("%sSwigPublic", name);
explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp);
if (Len(directorScope) > 0)
explicit_qualifier = NewStringf("SwigDirector_%s_%s", directorScope, explicit_qualifier_tmp);
else
explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp);
Delete(explicit_qualifier_tmp);
} else {
explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname"));
@ -935,7 +1058,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
String *defaultargs = Getattr(n, "defaultargs");
String *code = Getattr(n, "code");
String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname;
String *cname = Getattr(n, "extendsmartclassname") ? Getattr(n, "extendsmartclassname") : classname;
String *membername = Swig_name_member(nspace, cname, name);
String *mangled = Swig_name_mangle(membername);
int is_smart_pointer = flags & CWRAP_SMART_POINTER;
@ -959,7 +1082,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
String *func = NewStringf("%s(", mangled);
String *cres;
if (Cmp(Getattr(n, "storage"), "static") != 0) {
if (!Swig_storage_isstatic(n)) {
String *pname = Swig_cparm_name(pp, i);
String *ctname = SwigType_namestr(cname);
String *fadd = 0;
@ -1014,6 +1137,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
Delete(p);
Delete(self);
Delete(parms);
Delete(directorScope);
return SWIG_OK;
}
@ -1057,20 +1181,14 @@ Node *Swig_directormap(Node *module, String *type) {
* This function creates a C wrapper for a C constructor function.
* ----------------------------------------------------------------------------- */
int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) {
ParmList *parms;
Parm *prefix_args;
int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags, String *directorname) {
Parm *p;
ParmList *directorparms;
SwigType *type;
int use_director;
use_director = Swig_directorclass(n);
parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
int use_director = Swig_directorclass(n);
ParmList *parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
/* Prepend the list of prefix_args (if any) */
prefix_args = Getattr(n, "director:prefix_args");
Parm *prefix_args = Getattr(n, "director:prefix_args");
if (prefix_args != NIL) {
Parm *p2, *p3;
@ -1122,9 +1240,7 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
/* if a C++ director class exists, create it rather than the original class */
if (use_director) {
Node *parent = Swig_methodclass(n);
int abstract = Getattr(parent, "abstract") != 0;
String *name = Getattr(parent, "sym:name");
String *directorname = NewStringf("SwigDirector_%s", name);
int abstract = Getattr(parent, "abstracts") != 0;
String *action = NewStringEmpty();
String *tmp_none_comparison = Copy(none_comparison);
String *director_call;
@ -1168,7 +1284,6 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
Setattr(n, "wrap:action", action);
Delete(tmp_none_comparison);
Delete(action);
Delete(directorname);
} else {
String *call = Swig_cppconstructor_call(classname, parms);
String *cres = Swig_cresult(type, Swig_cresult_name(), call);
@ -1352,7 +1467,7 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) {
int varcref = flags & CWRAP_NATURAL_VAR;
if (flags & CWRAP_SMART_POINTER) {
if (checkAttribute(n, "storage", "static")) {
if (Swig_storage_isstatic(n)) {
Node *sn = Getattr(n, "cplus:staticbase");
String *base = Getattr(sn, "name");
self = NewStringf("%s::", base);

View file

@ -13,8 +13,6 @@
* that the function and/or API needs to be changed in some future release.
* ----------------------------------------------------------------------------- */
char cvsroot_deprecate_c[] = "$Id: parms.c 9630 2007-01-02 21:17:19Z beazley $";
#include "swig.h"
/* ---------------------------------------------------------------------

View file

@ -12,8 +12,6 @@
* error messages.
* ----------------------------------------------------------------------------- */
char cvsroot_error_c[] = "$Id$";
#include "swig.h"
#include <stdarg.h>
#include <ctype.h>

View file

@ -16,10 +16,9 @@
* wrapper code and to generate cleaner wrapper files.
* ----------------------------------------------------------------------------- */
char cvsroot_fragment_c[] = "$Id$";
#include "swig.h"
#include "swigwarn.h"
#include "cparse.h"
static Hash *fragments = 0;
static Hash *looking_fragments = 0;
@ -62,6 +61,8 @@ void Swig_fragment_register(Node *fragment) {
}
Setfile(ccode, Getfile(fragment));
Setline(ccode, Getline(fragment));
/* Replace $descriptor() macros */
Swig_cparse_replace_descriptor(ccode);
Setattr(fragments, name, ccode);
if (debug)
Printf(stdout, "registering fragment %s %s\n", name, section);
@ -93,16 +94,16 @@ void Swig_fragment_emit(Node *n) {
String *name = 0;
String *type = 0;
name = Getattr(n, "value");
if (!name) {
name = n;
}
if (!fragments) {
Swig_warning(WARN_FRAGMENT_NOT_FOUND, Getfile(n), Getline(n), "Fragment '%s' not found.\n", name);
return;
}
name = Getattr(n, "value");
if (!name) {
name = n;
}
type = Getattr(n, "type");
if (type) {
mangle = Swig_string_mangle(type);

View file

@ -20,8 +20,6 @@
* Should have cleaner error handling in general.
* ----------------------------------------------------------------------------- */
char cvsroot_getopt_c[] = "$Id$";
#include "swig.h"
static char **args;

View file

@ -13,8 +13,6 @@
* are provided.
* ----------------------------------------------------------------------------- */
char cvsroot_include_c[] = "$Id$";
#include "swig.h"
static List *directories = 0; /* List of include directories */
@ -165,7 +163,8 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_
String *filename;
List *spath = 0;
char *cname;
int i, ilen;
int i, ilen, nbytes;
char bom[3];
if (!directories)
directories = NewList();
@ -193,6 +192,14 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_
if (f) {
Delete(lastpath);
lastpath = filename;
/* Skip the UTF-8 BOM if it's present */
nbytes = fread(bom, 1, 3, f);
if (nbytes == 3 && bom[0] == (char)0xEF && bom[1] == (char)0xBB && bom[2] == (char)0xBF) {
/* skip */
} else {
fseek(f, 0, SEEK_SET);
}
}
return f;
}
@ -317,58 +324,41 @@ File *Swig_filebyname(const_String_or_char_ptr filename) {
}
/* -----------------------------------------------------------------------------
* Swig_file_suffix()
* Swig_file_extension()
*
* Returns the suffix of a file
* Returns the extension of a file
* ----------------------------------------------------------------------------- */
char *Swig_file_suffix(const_String_or_char_ptr filename) {
char *d;
char *c = Char(filename);
int len = Len(filename);
if (strlen(c)) {
d = c + len - 1;
while (d != c) {
if (*d == '.')
return d;
d--;
}
return c + len;
}
return c;
String *Swig_file_extension(const_String_or_char_ptr filename) {
String *name = Swig_file_filename(filename);
const char *c = strrchr(Char(name), '.');
String *extension = c ? NewString(c) : NewString("");
Delete(name);
return extension;
}
/* -----------------------------------------------------------------------------
* Swig_file_basename()
*
* Returns the filename with no suffix attached.
* Returns the filename with the extension removed.
* ----------------------------------------------------------------------------- */
char *Swig_file_basename(const_String_or_char_ptr filename) {
static char tmp[1024];
char *c;
strcpy(tmp, Char(filename));
c = Swig_file_suffix(tmp);
*c = 0;
return tmp;
String *Swig_file_basename(const_String_or_char_ptr filename) {
String *extension = Swig_file_extension(filename);
String *basename = NewStringWithSize(filename, Len(filename) - Len(extension));
Delete(extension);
return basename;
}
/* -----------------------------------------------------------------------------
* Swig_file_filename()
*
* Return the file with any leading path stripped off
* Return the file name with any leading path stripped off
* ----------------------------------------------------------------------------- */
char *Swig_file_filename(const_String_or_char_ptr filename) {
static char tmp[1024];
String *Swig_file_filename(const_String_or_char_ptr filename) {
const char *delim = SWIG_FILE_DELIMITER;
char *c;
strcpy(tmp, Char(filename));
c = strrchr(tmp, *delim);
if (c)
return c + 1;
else
return tmp;
const char *c = strrchr(Char(filename), *delim);
return c ? NewString(c + 1) : NewString(filename);
}
/* -----------------------------------------------------------------------------
@ -376,19 +366,10 @@ char *Swig_file_filename(const_String_or_char_ptr filename) {
*
* Return the name of the directory associated with a file
* ----------------------------------------------------------------------------- */
char *Swig_file_dirname(const_String_or_char_ptr filename) {
static char tmp[1024];
String *Swig_file_dirname(const_String_or_char_ptr filename) {
const char *delim = SWIG_FILE_DELIMITER;
char *c;
strcpy(tmp, Char(filename));
if (!strstr(tmp, delim)) {
return "";
}
c = tmp + strlen(tmp) - 1;
while (*c != *delim)
c--;
*(++c) = 0;
return tmp;
const char *c = strrchr(Char(filename), *delim);
return c ? NewStringWithSize(filename, c - Char(filename) + 1) : NewString("");
}
/*

View file

@ -11,8 +11,6 @@
* Miscellaneous functions that don't really fit anywhere else.
* ----------------------------------------------------------------------------- */
char cvsroot_misc_c[] = "$Id$";
#include "swig.h"
#include <errno.h>
#include <ctype.h>
@ -74,11 +72,11 @@ void Swig_banner(File *f) {
Printf(f, "/* ----------------------------------------------------------------------------\n\
* This file was automatically generated by SWIG (http://www.swig.org).\n\
* Version %s\n\
* \n\
* This file is not intended to be easily readable and contains a number of \n\
*\n\
* This file is not intended to be easily readable and contains a number of\n\
* coding conventions designed to improve portability and efficiency. Do not make\n\
* changes to this file unless you know what you are doing--modify the SWIG \n\
* interface file instead. \n", Swig_package_version());
* changes to this file unless you know what you are doing--modify the SWIG\n\
* interface file instead.\n", Swig_package_version());
/* String too long for ISO compliance */
Printf(f, " * ----------------------------------------------------------------------------- */\n");
@ -167,44 +165,36 @@ static int is_directory(String *directory) {
* Swig_new_subdirectory()
*
* Create the subdirectory only if the basedirectory already exists as a directory.
* basedirectory can be NULL or empty to indicate current directory.
* basedirectory can be empty to indicate current directory but not NULL.
* ----------------------------------------------------------------------------- */
String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) {
String *error = 0;
struct stat st;
int current_directory = basedirectory ? (Len(basedirectory) == 0 ? 1 : 0) : 0;
int current_directory = Len(basedirectory) == 0;
if (current_directory || is_directory(basedirectory)) {
Iterator it;
String *dir = basedirectory ? NewString(basedirectory) : NewString("");
String *dir = NewString(basedirectory);
List *subdirs = Split(subdirectory, SWIG_FILE_DELIMITER[0], INT_MAX);
for (it = First(subdirs); it.item; it = Next(it)) {
int statdir;
int result;
String *subdirectory = it.item;
Printf(dir, "%s", subdirectory);
statdir = stat(Char(dir), &st);
if (statdir == 0) {
Printf(dir, SWIG_FILE_DELIMITER);
if (S_ISDIR(st.st_mode)) {
continue;
} else {
error = NewStringf("Cannot create directory %s", dir);
break;
}
} else {
#ifdef _WIN32
int result = _mkdir(Char(dir));
result = _mkdir(Char(dir));
#else
int result = mkdir(Char(dir), 0777);
result = mkdir(Char(dir), 0777);
#endif
Printf(dir, SWIG_FILE_DELIMITER);
if (result != 0 && errno != EEXIST) {
error = NewStringf("Cannot create directory %s", dir);
break;
}
if (result != 0 && errno != EEXIST) {
error = NewStringf("Cannot create directory %s: %s", dir, strerror(errno));
break;
}
if (!is_directory(dir)) {
error = NewStringf("Cannot create directory %s: it may already exist but not be a directory", dir);
break;
}
Printf(dir, SWIG_FILE_DELIMITER);
}
} else {
error = NewStringf("Cannot create subdirectory %s under the base directory %s. Either the base does not exist as a directory or it is not readable.", subdirectory, basedirectory);
@ -215,8 +205,8 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) {
/* -----------------------------------------------------------------------------
* Swig_filename_correct()
*
* Corrects filename paths by removing duplicate delimeters and on non-unix
* systems use the correct delimeter across the whole name.
* Corrects filename paths by removing duplicate delimiters and on non-unix
* systems use the correct delimiter across the whole name.
* ----------------------------------------------------------------------------- */
void Swig_filename_correct(String *filename) {
@ -272,6 +262,49 @@ void Swig_filename_unescape(String *filename) {
#endif
}
/* -----------------------------------------------------------------------------
* Swig_storage_isextern()
*
* Determine if the storage class specifier is extern (but not externc)
* ----------------------------------------------------------------------------- */
int Swig_storage_isextern(Node *n) {
const String *storage = Getattr(n, "storage");
return storage ? Strcmp(storage, "extern") == 0 || Strncmp(storage, "extern ", 7) == 0 : 0;
}
/* -----------------------------------------------------------------------------
* Swig_storage_isexternc()
*
* Determine if the storage class specifier is externc (but not plain extern)
* ----------------------------------------------------------------------------- */
int Swig_storage_isexternc(Node *n) {
const String *storage = Getattr(n, "storage");
return storage ? Strcmp(storage, "externc") == 0 || Strncmp(storage, "externc ", 8) == 0 : 0;
}
/* -----------------------------------------------------------------------------
* Swig_storage_isstatic_custom()
*
* Determine if the storage class specifier is static
* ----------------------------------------------------------------------------- */
int Swig_storage_isstatic_custom(Node *n, const_String_or_char_ptr storage_name) {
const String *storage = Getattr(n, storage_name);
return storage ? Strncmp(storage, "static", 6) == 0 : 0;
}
/* -----------------------------------------------------------------------------
* Swig_storage_isstatic()
*
* Determine if the storage class specifier is static
* ----------------------------------------------------------------------------- */
int Swig_storage_isstatic(Node *n) {
return Swig_storage_isstatic_custom(n, "storage");
}
/* -----------------------------------------------------------------------------
* Swig_string_escape()
*
@ -880,8 +913,8 @@ String *Swig_scopename_last(const String *s) {
while (*c) {
if ((*c == ':') && (*(c + 1) == ':')) {
cc = c;
c += 2;
cc = c;
} else {
if (*c == '<') {
int level = 1;
@ -898,7 +931,7 @@ String *Swig_scopename_last(const String *s) {
}
}
}
return NewString(cc + 2);
return NewString(cc);
}
/* -----------------------------------------------------------------------------
@ -1114,6 +1147,55 @@ String *Swig_string_strip(String *s) {
return ns;
}
/* -----------------------------------------------------------------------------
* Swig_offset_string()
*
* Insert number tabs before each new line in s
* ----------------------------------------------------------------------------- */
void Swig_offset_string(String *s, int number) {
char *res, *p, *end, *start;
/* count a number of lines in s */
int lines = 1;
int len = Len(s);
if (len == 0)
return;
start = strchr(Char(s), '\n');
while (start) {
++lines;
start = strchr(start + 1, '\n');
}
/* do not count pending new line */
if ((Char(s))[len-1] == '\n')
--lines;
/* allocate a temporary storage for a padded string */
res = (char*)malloc(len + lines * number * 2 + 1);
res[len + lines * number * 2] = 0;
/* copy lines to res, prepending tabs to each line */
p = res; /* output pointer */
start = Char(s); /* start of a current line */
end = strchr(start, '\n'); /* end of a current line */
while (end) {
memset(p, ' ', number*2);
p += number*2;
memcpy(p, start, end - start + 1);
p += end - start + 1;
start = end + 1;
end = strchr(start, '\n');
}
/* process the last line */
if (*start) {
memset(p, ' ', number*2);
p += number*2;
strcpy(p, start);
}
/* replace 's' contents with 'res' */
Clear(s);
Append(s, res);
free(res);
}
#ifdef HAVE_PCRE
#include <pcre.h>
@ -1147,8 +1229,40 @@ err_out:
exit(1);
}
/* This function copies len characters from src to dst, possibly applying case conversions to them: if convertCase is 1, to upper case and if it is -1, to lower
* case. If convertNextOnly is 1, only a single character is converted (and convertCase is reset), otherwise all of them are. */
static void copy_with_maybe_case_conversion(String *dst, const char *src, int len, int *convertCase, int convertNextOnly)
{
/* Deal with the trivial cases first. */
if (!len)
return;
if (!*convertCase) {
Write(dst, src, len);
return;
}
/* If we must convert only the first character, do it and write the rest at once. */
if (convertNextOnly) {
int src_char = *src;
Putc(*convertCase == 1 ? toupper(src_char) : tolower(src_char), dst);
*convertCase = 0;
if (len > 1) {
Write(dst, src + 1, len - 1);
}
} else {
/* We need to convert all characters. */
int i;
for (i = 0; i < len; i++, src++) {
int src_char = *src;
Putc(*convertCase == 1 ? toupper(src_char) : tolower(src_char), dst);
}
}
}
String *replace_captures(int num_captures, const char *input, String *subst, int captures[], String *pattern, String *s)
{
int convertCase = 0, convertNextOnly = 0;
String *result = NewStringEmpty();
const char *p = Char(subst);
@ -1156,10 +1270,10 @@ String *replace_captures(int num_captures, const char *input, String *subst, int
/* Copy part without substitutions */
const char *q = strchr(p, '\\');
if (!q) {
Write(result, p, strlen(p));
copy_with_maybe_case_conversion(result, p, strlen(p), &convertCase, convertNextOnly);
break;
}
Write(result, p, q - p);
copy_with_maybe_case_conversion(result, p, q - p, &convertCase, convertNextOnly);
p = q + 1;
/* Handle substitution */
@ -1170,12 +1284,39 @@ String *replace_captures(int num_captures, const char *input, String *subst, int
if (group < num_captures) {
int l = captures[group*2], r = captures[group*2 + 1];
if (l != -1) {
Write(result, input + l, r - l);
copy_with_maybe_case_conversion(result, input + l, r - l, &convertCase, convertNextOnly);
}
} else {
Swig_error("SWIG", Getline(s), "PCRE capture replacement failed while matching \"%s\" using \"%s\" - request for group %d is greater than the number of captures %d.\n",
Char(pattern), input, group, num_captures-1);
}
} else {
/* Handle Perl-like case conversion escapes. */
switch (*p) {
case 'u':
convertCase = 1;
convertNextOnly = 1;
break;
case 'U':
convertCase = 1;
convertNextOnly = 0;
break;
case 'l':
convertCase = -1;
convertNextOnly = 1;
break;
case 'L':
convertCase = -1;
convertNextOnly = 0;
break;
case 'E':
convertCase = 0;
break;
default:
Swig_error("SWIG", Getline(s), "Unrecognized escape character '%c' in the replacement string \"%s\".\n",
*p, Char(subst));
}
p++;
}
}

View file

@ -20,8 +20,6 @@
* %v - variable name is substituted
* ----------------------------------------------------------------------------- */
char cvsroot_naming_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
#include <ctype.h>
@ -776,7 +774,7 @@ void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *d
* concatenating the feature name plus ':' plus the attribute name.
* ----------------------------------------------------------------------------- */
void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, String *value, Hash *featureattribs) {
void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, const_String_or_char_ptr value, Hash *featureattribs) {
Hash *n;
Hash *fhash;
@ -883,13 +881,16 @@ List *Swig_name_rename_list() {
int Swig_need_name_warning(Node *n) {
int need = 1;
/*
we don't use name warnings for:
We don't use name warnings for:
- class forwards, no symbol is generated at the target language.
- template declarations, only for real instances using %template(name).
- typedefs, they have no effect at the target language.
- typedefs, have no effect at the target language.
- using declarations and using directives, have no effect at the target language.
*/
if (checkAttribute(n, "nodeType", "classforward")) {
need = 0;
} else if (checkAttribute(n, "nodeType", "using")) {
need = 0;
} else if (checkAttribute(n, "storage", "typedef")) {
need = 0;
} else if (Getattr(n, "hidden")) {
@ -937,8 +938,7 @@ static int nodes_are_equivalent(Node *a, Node *b, int a_inclass) {
}
/* static functions */
if ((Cmp(a_storage, "static") == 0)
|| (Cmp(b_storage, "static") == 0)) {
if (Swig_storage_isstatic(a) || Swig_storage_isstatic(b)) {
if (Cmp(a_storage, b_storage) != 0)
return 0;
}
@ -1648,6 +1648,80 @@ void Swig_name_inherit(String *base, String *derived) {
Swig_name_object_inherit(Swig_cparse_features(), base, derived);
}
/* -----------------------------------------------------------------------------
* Swig_inherit_base_symbols()
* ----------------------------------------------------------------------------- */
void Swig_inherit_base_symbols(List *bases) {
if (bases) {
Iterator s;
for (s = First(bases); s.item; s = Next(s)) {
Symtab *st = Getattr(s.item, "symtab");
if (st) {
Setfile(st, Getfile(s.item));
Setline(st, Getline(s.item));
Swig_symbol_inherit(st);
}
}
Delete(bases);
}
}
/* -----------------------------------------------------------------------------
* Swig_make_inherit_list()
* ----------------------------------------------------------------------------- */
List *Swig_make_inherit_list(String *clsname, List *names, String *Namespaceprefix) {
int i, ilen;
String *derived;
List *bases = NewList();
if (Namespaceprefix)
derived = NewStringf("%s::%s", Namespaceprefix, clsname);
else
derived = NewString(clsname);
ilen = Len(names);
for (i = 0; i < ilen; i++) {
String *base;
String *n = Getitem(names, i);
/* Try to figure out where this symbol is */
Node *s = Swig_symbol_clookup(n, 0);
if (s) {
while (s && (Strcmp(nodeType(s), "class") != 0)) {
/* Not a class. Could be a typedef though. */
String *storage = Getattr(s, "storage");
if (storage && (Strcmp(storage, "typedef") == 0)) {
String *nn = Getattr(s, "type");
s = Swig_symbol_clookup(nn, Getattr(s, "sym:symtab"));
} else {
break;
}
}
if (s && ((Strcmp(nodeType(s), "class") == 0) || (Strcmp(nodeType(s), "template") == 0))) {
String *q = Swig_symbol_qualified(s);
Append(bases, s);
if (q) {
base = NewStringf("%s::%s", q, Getattr(s, "name"));
Delete(q);
} else {
base = NewString(Getattr(s, "name"));
}
} else {
base = NewString(n);
}
} else {
base = NewString(n);
}
if (base) {
Swig_name_inherit(base, derived);
Delete(base);
}
}
return bases;
}
/* -----------------------------------------------------------------------------
* void Swig_name_str()
*

View file

@ -11,21 +11,19 @@
* Parameter list class.
* ----------------------------------------------------------------------------- */
char cvsroot_parms_c[] = "$Id$";
#include "swig.h"
/* ------------------------------------------------------------------------
* NewParm()
*
* Create a new parameter from datatype 'type' and name 'name' copying
* the file and line number from the Node file_line_node.
* the file and line number from the Node from_node.
* ------------------------------------------------------------------------ */
Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *file_line_node) {
Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *from_node) {
Parm *p = NewParmWithoutFileLineInfo(type, name);
Setfile(p, Getfile(file_line_node));
Setline(p, Getline(file_line_node));
Setfile(p, Getfile(from_node));
Setline(p, Getline(from_node));
return p;
}
@ -48,6 +46,20 @@ Parm *NewParmWithoutFileLineInfo(SwigType *type, const_String_or_char_ptr name)
return p;
}
/* ------------------------------------------------------------------------
* NewParmNode()
*
* Create a new parameter from datatype 'type' and name and symbol table as
* well as file and line number from the 'from_node'.
* The resulting Parm will be similar to a Node used for typemap lookups.
* ------------------------------------------------------------------------ */
Parm *NewParmNode(SwigType *type, Node *from_node) {
Parm *p = NewParm(type, Getattr(from_node, "name"), from_node);
Setattr(p, "sym:symtab", Getattr(from_node, "sym:symtab"));
return p;
}
/* ------------------------------------------------------------------------
* CopyParm()
* ------------------------------------------------------------------------ */

View file

@ -14,8 +14,6 @@
* to easily construct yacc-compatible scanners.
* ----------------------------------------------------------------------------- */
char cvsroot_scanner_c[] = "$Id$";
#include "swig.h"
#include <ctype.h>
@ -37,6 +35,7 @@ struct Scanner {
String *error; /* Last error message (if any) */
int error_line; /* Error line number */
int freeze_line; /* Suspend line number updates */
List *brackets; /* Current level of < > brackets on each level */
};
typedef struct Locator {
@ -46,6 +45,9 @@ typedef struct Locator {
} Locator;
static int follow_locators = 0;
static void brackets_push(Scanner *);
static void brackets_clear(Scanner *);
/* -----------------------------------------------------------------------------
* NewScanner()
*
@ -65,7 +67,10 @@ Scanner *NewScanner(void) {
s->text = NewStringEmpty();
s->str = 0;
s->error = 0;
s->error_line = 0;
s->freeze_line = 0;
s->brackets = NewList();
brackets_push(s);
return s;
}
@ -75,15 +80,16 @@ Scanner *NewScanner(void) {
* Delete a scanner object.
* ----------------------------------------------------------------------------- */
void DelScanner(Scanner * s) {
void DelScanner(Scanner *s) {
assert(s);
Delete(s->scanobjs);
Delete(s->brackets);
Delete(s->text);
Delete(s->file);
Delete(s->error);
Delete(s->str);
free(s->idstart);
free(s);
free(s);
}
/* -----------------------------------------------------------------------------
@ -92,11 +98,12 @@ void DelScanner(Scanner * s) {
* Clear the contents of a scanner object.
* ----------------------------------------------------------------------------- */
void Scanner_clear(Scanner * s) {
void Scanner_clear(Scanner *s) {
assert(s);
Delete(s->str);
Clear(s->text);
Clear(s->scanobjs);
brackets_clear(s);
Delete(s->error);
s->str = 0;
s->error = 0;
@ -104,6 +111,12 @@ void Scanner_clear(Scanner * s) {
s->nexttoken = -1;
s->start_line = 0;
s->yylen = 0;
/* Should these be cleared too?
s->idstart;
s->file;
s->error_line;
s->freeze_line;
*/
}
/* -----------------------------------------------------------------------------
@ -113,7 +126,7 @@ void Scanner_clear(Scanner * s) {
* immediately before returning to the old text.
* ----------------------------------------------------------------------------- */
void Scanner_push(Scanner * s, String *txt) {
void Scanner_push(Scanner *s, String *txt) {
assert(s && txt);
Push(s->scanobjs, txt);
if (s->str) {
@ -132,7 +145,7 @@ void Scanner_push(Scanner * s, String *txt) {
* call to Scanner_token().
* ----------------------------------------------------------------------------- */
void Scanner_pushtoken(Scanner * s, int nt, const_String_or_char_ptr val) {
void Scanner_pushtoken(Scanner *s, int nt, const_String_or_char_ptr val) {
assert(s);
assert((nt >= 0) && (nt < SWIG_MAXTOKENS));
s->nexttoken = nt;
@ -148,7 +161,7 @@ void Scanner_pushtoken(Scanner * s, int nt, const_String_or_char_ptr val) {
* Set the file and line number location of the scanner.
* ----------------------------------------------------------------------------- */
void Scanner_set_location(Scanner * s, String *file, int line) {
void Scanner_set_location(Scanner *s, String *file, int line) {
Setline(s->str, line);
Setfile(s->str, file);
s->line = line;
@ -160,7 +173,7 @@ void Scanner_set_location(Scanner * s, String *file, int line) {
* Get the current file.
* ----------------------------------------------------------------------------- */
String *Scanner_file(Scanner * s) {
String *Scanner_file(Scanner *s) {
return Getfile(s->str);
}
@ -169,7 +182,7 @@ String *Scanner_file(Scanner * s) {
*
* Get the current line number
* ----------------------------------------------------------------------------- */
int Scanner_line(Scanner * s) {
int Scanner_line(Scanner *s) {
return s->line;
}
@ -178,7 +191,7 @@ int Scanner_line(Scanner * s) {
*
* Get the line number on which the current token starts
* ----------------------------------------------------------------------------- */
int Scanner_start_line(Scanner * s) {
int Scanner_start_line(Scanner *s) {
return s->start_line;
}
@ -188,7 +201,7 @@ int Scanner_start_line(Scanner * s) {
* Change the set of additional characters that can be used to start an identifier.
* ----------------------------------------------------------------------------- */
void Scanner_idstart(Scanner * s, const char *id) {
void Scanner_idstart(Scanner *s, const char *id) {
free(s->idstart);
s->idstart = Swig_copy_string(id);
}
@ -198,7 +211,7 @@ void Scanner_idstart(Scanner * s, const char *id) {
*
* Returns the next character from the scanner or 0 if end of the string.
* ----------------------------------------------------------------------------- */
static char nextchar(Scanner * s) {
static char nextchar(Scanner *s) {
int nc;
if (!s->str)
return 0;
@ -209,10 +222,8 @@ static char nextchar(Scanner * s) {
if (Len(s->scanobjs) == 0)
return 0;
s->str = Getitem(s->scanobjs, 0);
if (s->str) {
s->line = Getline(s->str);
DohIncref(s->str);
}
s->line = Getline(s->str);
DohIncref(s->str);
}
if ((nc == '\n') && (!s->freeze_line))
s->line++;
@ -242,8 +253,7 @@ String *Scanner_errmsg(Scanner *s) {
return s->error;
}
int
Scanner_errline(Scanner *s) {
int Scanner_errline(Scanner *s) {
return s->error_line;
}
@ -257,12 +267,108 @@ static void freeze_line(Scanner *s, int val) {
s->freeze_line = val;
}
/* -----------------------------------------------------------------------------
* brackets_count()
*
* Returns the number of brackets at the current depth.
* A syntax error with unbalanced ) brackets will result in a NULL pointer return.
* ----------------------------------------------------------------------------- */
static int *brackets_count(Scanner *s) {
int *count;
if (Len(s->brackets) > 0)
count = (int *)Data(Getitem(s->brackets, 0));
else
count = 0;
return count;
}
/* -----------------------------------------------------------------------------
* brackets_clear()
*
* Resets the current depth and clears all brackets.
* Usually called at the end of statements;
* ----------------------------------------------------------------------------- */
static void brackets_clear(Scanner *s) {
Clear(s->brackets);
brackets_push(s); /* base bracket count should always be created */
}
/* -----------------------------------------------------------------------------
* brackets_increment()
*
* Increases the number of brackets at the current depth.
* Usually called when a single '<' is found.
* ----------------------------------------------------------------------------- */
static void brackets_increment(Scanner *s) {
int *count = brackets_count(s);
if (count)
(*count)++;
}
/* -----------------------------------------------------------------------------
* brackets_decrement()
*
* Decreases the number of brackets at the current depth.
* Usually called when a single '>' is found.
* ----------------------------------------------------------------------------- */
static void brackets_decrement(Scanner *s) {
int *count = brackets_count(s);
if (count)
(*count)--;
}
/* -----------------------------------------------------------------------------
* brackets_reset()
*
* Sets the number of '<' brackets back to zero. Called at the point where
* it is no longer possible to have a matching closing >> pair for a template.
* ----------------------------------------------------------------------------- */
static void brackets_reset(Scanner *s) {
int *count = brackets_count(s);
if (count)
*count = 0;
}
/* -----------------------------------------------------------------------------
* brackets_push()
*
* Increases the depth of brackets.
* Usually called when '(' is found.
* ----------------------------------------------------------------------------- */
static void brackets_push(Scanner *s) {
int *newInt = malloc(sizeof(int));
*newInt = 0;
Push(s->brackets, NewVoid(newInt, free));
}
/* -----------------------------------------------------------------------------
* brackets_pop()
*
* Decreases the depth of brackets.
* Usually called when ')' is found.
* ----------------------------------------------------------------------------- */
static void brackets_pop(Scanner *s) {
if (Len(s->brackets) > 0) /* protect against unbalanced ')' brackets */
Delitem(s->brackets, 0);
}
/* -----------------------------------------------------------------------------
* brackets_allow_shift()
*
* Return 1 to allow shift (>>), or 0 if (>>) should be split into (> >).
* This is for C++11 template syntax for closing templates.
* ----------------------------------------------------------------------------- */
static int brackets_allow_shift(Scanner *s) {
int *count = brackets_count(s);
return !count || (*count <= 0);
}
/* -----------------------------------------------------------------------------
* retract()
*
* Retract n characters
* ----------------------------------------------------------------------------- */
static void retract(Scanner * s, int n) {
static void retract(Scanner *s, int n) {
int i, l;
char *str;
@ -273,7 +379,7 @@ static void retract(Scanner * s, int n) {
if (str[l - 1] == '\n') {
if (!s->freeze_line) s->line--;
}
Seek(s->str, -1, SEEK_CUR);
(void)Seek(s->str, -1, SEEK_CUR);
Delitem(s->text, DOH_END);
}
}
@ -403,14 +509,16 @@ static void get_escape(Scanner *s) {
* Return the raw value of the next token.
* ----------------------------------------------------------------------------- */
static int look(Scanner * s) {
int state;
static int look(Scanner *s) {
int state = 0;
int c = 0;
String *str_delimiter = 0;
state = 0;
Clear(s->text);
s->start_line = s->line;
Setfile(s->text, Getfile(s->str));
while (1) {
switch (state) {
case 0:
@ -432,32 +540,40 @@ static int look(Scanner * s) {
case 1000:
if ((c = nextchar(s)) == 0)
return (0);
return (0);
if (c == '%')
state = 4; /* Possibly a SWIG directive */
/* Look for possible identifiers */
/* Look for possible identifiers or unicode/delimiter strings */
else if ((isalpha(c)) || (c == '_') ||
(s->idstart && strchr(s->idstart, c)))
(s->idstart && strchr(s->idstart, c))) {
state = 7;
}
/* Look for single character symbols */
else if (c == '(')
else if (c == '(') {
brackets_push(s);
return SWIG_TOKEN_LPAREN;
else if (c == ')')
}
else if (c == ')') {
brackets_pop(s);
return SWIG_TOKEN_RPAREN;
else if (c == ';')
}
else if (c == ';') {
brackets_clear(s);
return SWIG_TOKEN_SEMI;
}
else if (c == ',')
return SWIG_TOKEN_COMMA;
else if (c == '*')
state = 220;
else if (c == '}')
return SWIG_TOKEN_RBRACE;
else if (c == '{')
else if (c == '{') {
brackets_reset(s);
return SWIG_TOKEN_LBRACE;
}
else if (c == '=')
state = 33;
else if (c == '+')
@ -499,16 +615,16 @@ static int look(Scanner * s) {
state = 1; /* Comment (maybe) */
s->start_line = s->line;
}
else if (c == '\"') {
state = 2; /* Possibly a string */
s->start_line = s->line;
Clear(s->text);
}
else if (c == ':')
state = 5; /* maybe double colon */
else if (c == '0')
state = 83; /* An octal or hex value */
else if (c == '\"') {
state = 2; /* A string constant */
s->start_line = s->line;
Clear(s->text);
}
else if (c == '\'') {
s->start_line = s->line;
Clear(s->text);
@ -587,18 +703,63 @@ static int look(Scanner * s) {
break;
case 2: /* Processing a string */
if (!str_delimiter) {
state=20;
break;
}
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated string\n");
return SWIG_TOKEN_ERROR;
}
if (c == '\"') {
Delitem(s->text, DOH_END);
return SWIG_TOKEN_STRING;
} else if (c == '\\') {
Delitem(s->text, DOH_END);
get_escape(s);
} else
state = 2;
else if (c == '(') {
state = 20;
}
else {
char temp[2] = { 0, 0 };
temp[0] = c;
Append( str_delimiter, temp );
}
break;
case 20: /* Inside the string */
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated string\n");
return SWIG_TOKEN_ERROR;
}
if (!str_delimiter) { /* Ordinary string: "value" */
if (c == '\"') {
Delitem(s->text, DOH_END);
return SWIG_TOKEN_STRING;
} else if (c == '\\') {
Delitem(s->text, DOH_END);
get_escape(s);
}
} else { /* Custom delimiter string: R"XXXX(value)XXXX" */
if (c==')') {
int i=0;
String *end_delimiter = NewStringEmpty();
while ((c = nextchar(s)) != 0 && c!='\"') {
char temp[2] = { 0, 0 };
temp[0] = c;
Append( end_delimiter, temp );
i++;
}
if (Strcmp( str_delimiter, end_delimiter )==0) {
Delete( end_delimiter ); /* Correct end delimiter )XXXX" occured */
Delete( str_delimiter );
str_delimiter = 0;
return SWIG_TOKEN_STRING;
} else { /* Incorrect end delimiter occured */
retract( s, i );
Delete( end_delimiter );
}
}
}
break;
case 3: /* Maybe a not equals */
@ -716,41 +877,137 @@ static int look(Scanner * s) {
break;
case 60: /* shift operators */
if ((c = nextchar(s)) == 0)
if ((c = nextchar(s)) == 0) {
brackets_increment(s);
return SWIG_TOKEN_LESSTHAN;
}
if (c == '<')
state = 240;
else if (c == '=')
return SWIG_TOKEN_LTEQUAL;
else {
retract(s, 1);
brackets_increment(s);
return SWIG_TOKEN_LESSTHAN;
}
break;
case 61:
if ((c = nextchar(s)) == 0)
if ((c = nextchar(s)) == 0) {
brackets_decrement(s);
return SWIG_TOKEN_GREATERTHAN;
if (c == '>')
}
if (c == '>' && brackets_allow_shift(s))
state = 250;
else if (c == '=')
return SWIG_TOKEN_GTEQUAL;
else {
retract(s, 1);
brackets_decrement(s);
return SWIG_TOKEN_GREATERTHAN;
}
break;
case 7: /* Identifier */
if ((c = nextchar(s)) == 0)
state = 71;
else if (isalnum(c) || (c == '_') || (c == '$')) {
state = 7;
} else {
case 7: /* Identifier or true/false or unicode/custom delimiter string */
if (c == 'R') { /* Possibly CUSTOM DELIMITER string */
state = 72;
break;
}
else if (c == 'L') { /* Probably identifier but may be a wide string literal */
state = 77;
break;
}
else if (c != 'u' && c != 'U') { /* Definitely an identifier */
state = 70;
break;
}
if ((c = nextchar(s)) == 0) {
state = 76;
}
else if (c == '\"') { /* Definitely u, U or L string */
retract(s, 1);
state = 1000;
}
else if (c == 'R') { /* Possibly CUSTOM DELIMITER u, U, L string */
state = 73;
}
else if (c == '8') { /* Possibly u8 string */
state = 71;
}
else {
retract(s, 1); /* Definitely an identifier */
state = 70;
}
break;
case 71: /* Identifier or true/false */
case 70: /* Identifier */
if ((c = nextchar(s)) == 0)
state = 76;
else if (isalnum(c) || (c == '_') || (c == '$')) {
state = 70;
} else {
retract(s, 1);
state = 76;
}
break;
case 71: /* Possibly u8 string */
if ((c = nextchar(s)) == 0) {
state = 76;
}
else if (c=='\"') {
retract(s, 1); /* Definitely u8 string */
state = 1000;
}
else if (c=='R') {
state = 74; /* Possibly CUSTOM DELIMITER u8 string */
}
else {
retract(s, 2); /* Definitely an identifier. Retract 8" */
state = 70;
}
break;
case 72: /* Possibly CUSTOM DELIMITER string */
case 73:
case 74:
if ((c = nextchar(s)) == 0) {
state = 76;
}
else if (c=='\"') {
retract(s, 1); /* Definitely custom delimiter u, U or L string */
str_delimiter = NewStringEmpty();
state = 1000;
}
else {
if (state==72) {
retract(s, 1); /* Definitely an identifier. Retract ? */
}
else if (state==73) {
retract(s, 2); /* Definitely an identifier. Retract R? */
}
else if (state==74) {
retract(s, 3); /* Definitely an identifier. Retract 8R? */
}
state = 70;
}
break;
case 75: /* Special identifier $ */
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_DOLLAR;
if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) {
state = 70;
} else {
retract(s,1);
if (Len(s->text) == 1) return SWIG_TOKEN_DOLLAR;
state = 76;
}
break;
case 76: /* Identifier or true/false */
if (cparse_cplusplus) {
if (Strcmp(s->text, "true") == 0)
return SWIG_TOKEN_BOOL;
@ -760,15 +1017,56 @@ static int look(Scanner * s) {
return SWIG_TOKEN_ID;
break;
case 75: /* Special identifier $ */
case 77: /*identifier or wide string literal*/
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_DOLLAR;
if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) {
return SWIG_TOKEN_ID;
else if (c == '\"') {
s->start_line = s->line;
Clear(s->text);
state = 78;
}
else if (c == '\'') {
s->start_line = s->line;
Clear(s->text);
state = 79;
}
else if (isalnum(c) || (c == '_') || (c == '$'))
state = 7;
} else {
retract(s,1);
if (Len(s->text) == 1) return SWIG_TOKEN_DOLLAR;
state = 71;
else {
retract(s, 1);
return SWIG_TOKEN_ID;
}
break;
case 78: /* Processing a wide string literal*/
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n");
return SWIG_TOKEN_ERROR;
}
if (c == '\"') {
Delitem(s->text, DOH_END);
return SWIG_TOKEN_WSTRING;
} else if (c == '\\') {
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n");
return SWIG_TOKEN_ERROR;
}
}
break;
case 79: /* Processing a wide char literal */
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide character constant\n");
return SWIG_TOKEN_ERROR;
}
if (c == '\'') {
Delitem(s->text, DOH_END);
return (SWIG_TOKEN_WCHAR);
} else if (c == '\\') {
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide character literal\n");
return SWIG_TOKEN_ERROR;
}
}
break;
@ -1094,7 +1392,7 @@ static int look(Scanner * s) {
* Real entry point to return the next token. Returns 0 if at end of input.
* ----------------------------------------------------------------------------- */
int Scanner_token(Scanner * s) {
int Scanner_token(Scanner *s) {
int t;
Delete(s->error);
if (s->nexttoken >= 0) {
@ -1118,7 +1416,7 @@ int Scanner_token(Scanner * s) {
* Return the lexene associated with the last returned token.
* ----------------------------------------------------------------------------- */
String *Scanner_text(Scanner * s) {
String *Scanner_text(Scanner *s) {
return s->text;
}
@ -1128,7 +1426,7 @@ String *Scanner_text(Scanner * s) {
* Skips to the end of a line
* ----------------------------------------------------------------------------- */
void Scanner_skip_line(Scanner * s) {
void Scanner_skip_line(Scanner *s) {
char c;
int done = 0;
Clear(s->text);
@ -1138,7 +1436,7 @@ void Scanner_skip_line(Scanner * s) {
if ((c = nextchar(s)) == 0)
return;
if (c == '\\') {
c = nextchar(s);
nextchar(s);
} else if (c == '\n') {
done = 1;
}
@ -1153,7 +1451,7 @@ void Scanner_skip_line(Scanner * s) {
* (...). Ignores symbols inside comments or strings.
* ----------------------------------------------------------------------------- */
int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) {
int Scanner_skip_balanced(Scanner *s, int startchar, int endchar) {
char c;
int num_levels = 1;
int state = 0;
@ -1279,6 +1577,114 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) {
return 0;
}
/* -----------------------------------------------------------------------------
* Scanner_get_raw_text_balanced()
*
* Returns raw text between 2 braces, does not change scanner state in any way
* ----------------------------------------------------------------------------- */
String *Scanner_get_raw_text_balanced(Scanner *s, int startchar, int endchar) {
String *result = 0;
char c;
int old_line = s->line;
String *old_text = Copy(s->text);
long position = Tell(s->str);
int num_levels = 1;
int state = 0;
char temp[2] = { 0, 0 };
temp[0] = (char) startchar;
Clear(s->text);
Setfile(s->text, Getfile(s->str));
Setline(s->text, s->line);
Append(s->text, temp);
while (num_levels > 0) {
if ((c = nextchar(s)) == 0) {
Clear(s->text);
Append(s->text, old_text);
Delete(old_text);
s->line = old_line;
return 0;
}
switch (state) {
case 0:
if (c == startchar)
num_levels++;
else if (c == endchar)
num_levels--;
else if (c == '/')
state = 10;
else if (c == '\"')
state = 20;
else if (c == '\'')
state = 30;
break;
case 10:
if (c == '/')
state = 11;
else if (c == '*')
state = 12;
else if (c == startchar) {
state = 0;
num_levels++;
}
else
state = 0;
break;
case 11:
if (c == '\n')
state = 0;
else
state = 11;
break;
case 12: /* first character inside C comment */
if (c == '*')
state = 14;
else
state = 13;
break;
case 13:
if (c == '*')
state = 14;
break;
case 14: /* possible end of C comment */
if (c == '*')
state = 14;
else if (c == '/')
state = 0;
else
state = 13;
break;
case 20:
if (c == '\"')
state = 0;
else if (c == '\\')
state = 21;
break;
case 21:
state = 20;
break;
case 30:
if (c == '\'')
state = 0;
else if (c == '\\')
state = 31;
break;
case 31:
state = 30;
break;
default:
break;
}
}
Seek(s->str, position, SEEK_SET);
result = Copy(s->text);
Clear(s->text);
Append(s->text, old_text);
Delete(old_text);
s->line = old_line;
return result;
}
/* -----------------------------------------------------------------------------
* Scanner_isoperator()
*
@ -1319,7 +1725,7 @@ void Scanner_locator(Scanner *s, String *loc) {
} else {
int c;
Locator *l;
Seek(loc, 7, SEEK_SET);
(void)Seek(loc, 7, SEEK_SET);
c = Getc(loc);
if (c == '@') {
/* Empty locator. We pop the last location off */

View file

@ -12,8 +12,6 @@
* the form of simple strings.
* ----------------------------------------------------------------------------- */
char cvsroot_stype_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
#include <ctype.h>
@ -43,6 +41,7 @@ char cvsroot_stype_c[] = "$Id$";
*
* 'p.' = Pointer (*)
* 'r.' = Reference (&)
* 'z.' = Rvalue reference (&&)
* 'a(n).' = Array of size n [n]
* 'f(..,..).' = Function with arguments (args)
* 'q(str).' = Qualifier (such as const or volatile) (const, volatile)
@ -130,12 +129,22 @@ SwigType *NewSwigType(int t) {
case T_UCHAR:
return NewString("unsigned char");
break;
case T_STRING:{
case T_STRING: {
SwigType *t = NewString("char");
SwigType_add_qualifier(t, "const");
SwigType_add_pointer(t);
return t;
break;
}
case T_WCHAR:
return NewString("wchar_t");
break;
case T_WSTRING: {
SwigType *t = NewString("wchar_t");
SwigType_add_pointer(t);
return t;
break;
}
case T_LONGLONG:
return NewString("long long");
break;
@ -145,6 +154,9 @@ SwigType *NewSwigType(int t) {
case T_VOID:
return NewString("void");
break;
case T_AUTO:
return NewString("auto");
break;
default:
break;
}
@ -232,7 +244,7 @@ int SwigType_isconst(const SwigType *t) {
int SwigType_ismutable(const SwigType *t) {
int r;
SwigType *qt = SwigType_typedef_resolve_all(t);
if (SwigType_isreference(qt) || SwigType_isarray(qt)) {
if (SwigType_isreference(qt) || SwigType_isrvalue_reference(qt) || SwigType_isarray(qt)) {
Delete(SwigType_pop(qt));
}
r = SwigType_isconst(qt);
@ -575,6 +587,12 @@ String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
Insert(result, 0, "(");
Append(result, ")");
}
} else if (SwigType_isrvalue_reference(element)) {
Insert(result, 0, "&&");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result, 0, "(");
Append(result, ")");
}
} else if (SwigType_isarray(element)) {
DOH *size;
Append(result, "[");
@ -639,10 +657,9 @@ SwigType *SwigType_ltype(const SwigType *s) {
SwigType *tt = Copy(tc);
td = 0;
while ((td = SwigType_typedef_resolve(tt))) {
if (td && (SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) {
if (td && (SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td) || SwigType_isrvalue_reference(td))) {
/* We need to use the typedef type */
Delete(tt);
tt = td;
break;
} else if (td) {
Delete(tt);
@ -679,6 +696,13 @@ SwigType *SwigType_ltype(const SwigType *s) {
Append(result, "p.");
}
firstarray = 0;
} else if (SwigType_isrvalue_reference(element)) {
if (notypeconv) {
Append(result, element);
} else {
Append(result, "p.");
}
firstarray = 0;
} else if (SwigType_isarray(element) && firstarray) {
if (notypeconv) {
Append(result, element);
@ -758,14 +782,14 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
rs = s;
}
if ((SwigType_isconst(rs) || SwigType_isarray(rs) || SwigType_isreference(rs))) {
if ((SwigType_isconst(rs) || SwigType_isarray(rs) || SwigType_isreference(rs) || SwigType_isrvalue_reference(rs))) {
td = 0;
} else {
td = SwigType_typedef_resolve(rs);
}
if (td) {
if ((SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) {
if ((SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td) || SwigType_isrvalue_reference(td))) {
elements = SwigType_split(td);
} else {
elements = SwigType_split(rs);
@ -824,6 +848,15 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
}
if (!isfunction)
isreference = 1;
} else if (SwigType_isrvalue_reference(element)) {
Insert(result, 0, "&&");
if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "(");
Append(result, ")");
}
if (!isfunction)
isreference = 1;
clear = 0;
} else if (SwigType_isarray(element)) {
DOH *size;
if (firstarray && !isreference) {
@ -900,6 +933,12 @@ String *SwigType_lcaststr(const SwigType *s, const_String_or_char_ptr name) {
Delete(str);
if (name)
Append(result, name);
} else if (SwigType_isrvalue_reference(s)) {
String *str = SwigType_str(s, 0);
Printf(result, "(%s)", str);
Delete(str);
if (name)
Append(result, name);
} else if (SwigType_isqualifier(s)) {
String *lstr = SwigType_lstr(s, 0);
Printf(result, "(%s)%s", lstr, name);

View file

@ -79,6 +79,7 @@ extern "C" {
#define T_FLTCPLX 23
#define T_DBLCPLX 24
#define T_NUMERIC 25
#define T_AUTO 26
#define T_COMPLEX T_DBLCPLX
@ -95,10 +96,14 @@ extern "C" {
#define T_FUNCTION 37
#define T_MPOINTER 38
#define T_VARARGS 39
#define T_RVALUE_REFERENCE 40
#define T_WSTRING 41
#define T_SYMBOL 98
#define T_ERROR 99
/* --- File interface --- */
#include "swigfile.h"
@ -124,6 +129,8 @@ extern "C" {
extern SwigType *SwigType_pop_arrays(SwigType *t);
extern SwigType *SwigType_add_reference(SwigType *t);
extern SwigType *SwigType_del_reference(SwigType *t);
extern SwigType *SwigType_add_rvalue_reference(SwigType *t);
extern SwigType *SwigType_del_rvalue_reference(SwigType *t);
extern SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual);
extern SwigType *SwigType_del_qualifier(SwigType *t);
extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms);
@ -147,6 +154,7 @@ extern "C" {
extern int SwigType_ismemberpointer(const SwigType *t);
extern int SwigType_isreference(const SwigType *t);
extern int SwigType_isreference_return(const SwigType *t);
extern int SwigType_isrvalue_reference(const SwigType *t);
extern int SwigType_isarray(const SwigType *t);
extern int SwigType_prefix_is_simple_1D_array(const SwigType *t);
extern int SwigType_isfunction(const SwigType *t);
@ -227,6 +235,7 @@ extern "C" {
extern void Swig_symbol_cadd(const_String_or_char_ptr symname, Node *node);
extern Node *Swig_symbol_clookup(const_String_or_char_ptr symname, Symtab *tab);
extern Node *Swig_symbol_clookup_check(const_String_or_char_ptr symname, Symtab *tab, int (*check) (Node *));
extern Node *Swig_symbol_clookup_no_inherit(const_String_or_char_ptr name, Symtab *n);
extern Symtab *Swig_symbol_cscope(const_String_or_char_ptr symname, Symtab *tab);
extern Node *Swig_symbol_clookup_local(const_String_or_char_ptr symname, Symtab *tab);
extern Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr symname, Symtab *tab, int (*check) (Node *));
@ -277,6 +286,8 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl);
extern void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *namewrn, ParmList *declaratorparms);
extern void Swig_name_inherit(String *base, String *derived);
extern List *Swig_make_inherit_list(String *clsname, List *names, String *Namespaceprefix);
extern void Swig_inherit_base_symbols(List *bases);
extern int Swig_need_protected(Node *n);
extern int Swig_need_name_warning(Node *n);
extern int Swig_need_redefined_warn(Node *a, Node *b, int InClass);
@ -293,7 +304,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern DOH *Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *decl);
extern void Swig_name_object_inherit(Hash *namehash, String *base, String *derived);
extern void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, Node *n);
extern void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, String *value, Hash *featureattribs);
extern void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, const_String_or_char_ptr value, Hash *featureattribs);
/* --- Misc --- */
extern char *Swig_copy_string(const char *c);
@ -306,6 +317,10 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Swig_filename_correct(String *filename);
extern String *Swig_filename_escape(String *filename);
extern void Swig_filename_unescape(String *filename);
extern int Swig_storage_isextern(Node *n);
extern int Swig_storage_isexternc(Node *n);
extern int Swig_storage_isstatic_custom(Node *n, const_String_or_char_ptr storage);
extern int Swig_storage_isstatic(Node *n);
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);
@ -317,6 +332,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern String *Swig_string_lower(String *s);
extern String *Swig_string_upper(String *s);
extern String *Swig_string_title(String *s);
extern void Swig_offset_string(String *s, int number);
extern String *Swig_pcre_version(void);
extern void Swig_init(void);
extern void Swig_warn(const char *filename, int line, const char *msg);
@ -356,11 +372,12 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern String *Swig_cmemberget_call(const_String_or_char_ptr name, SwigType *t, String *self, int varcref);
extern int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self);
extern void Swig_replace_special_variables(Node *n, Node *parentnode, String *code);
/* --- Transformations --- */
extern int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int flags, SwigType *director_type, int is_director);
extern int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags);
extern int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags, String *directorname);
extern int Swig_DestructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int cplus, int flags);
extern int Swig_MembersetToFunction(Node *n, String *classname, int flags);
extern int Swig_MembergetToFunction(Node *n, String *classname, int flags);

View file

@ -26,10 +26,10 @@ extern void Swig_set_push_dir(int dopush);
extern int Swig_get_push_dir(void);
extern void Swig_register_filebyname(const_String_or_char_ptr filename, File *outfile);
extern File *Swig_filebyname(const_String_or_char_ptr filename);
extern char *Swig_file_suffix(const_String_or_char_ptr filename);
extern char *Swig_file_basename(const_String_or_char_ptr filename);
extern char *Swig_file_filename(const_String_or_char_ptr filename);
extern char *Swig_file_dirname(const_String_or_char_ptr filename);
extern String *Swig_file_extension(const_String_or_char_ptr filename);
extern String *Swig_file_basename(const_String_or_char_ptr filename);
extern String *Swig_file_filename(const_String_or_char_ptr filename);
extern String *Swig_file_dirname(const_String_or_char_ptr filename);
extern void Swig_file_debug_set();
/* Delimiter used in accessing files and directories */

View file

@ -13,8 +13,9 @@
* ----------------------------------------------------------------------------- */
/* Individual parameters */
extern Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *file_line_node);
extern Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *from_node);
extern Parm *NewParmWithoutFileLineInfo(SwigType *type, const_String_or_char_ptr name);
extern Parm *NewParmNode(SwigType *type, Node *from_node);
extern Parm *CopyParm(Parm *p);
/* Parameter lists */

View file

@ -22,6 +22,7 @@ extern int Scanner_token(Scanner *);
extern String *Scanner_text(Scanner *);
extern void Scanner_skip_line(Scanner *);
extern int Scanner_skip_balanced(Scanner *, int startchar, int endchar);
extern String *Scanner_get_raw_text_balanced(Scanner *, int startchar, int endchar);
extern void Scanner_set_location(Scanner *, String *file, int line);
extern String *Scanner_file(Scanner *);
extern int Scanner_line(Scanner *);
@ -67,6 +68,9 @@ extern void Scanner_locator(Scanner *, String *loc);
#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_WSTRING 33 /* L"str" */
#define SWIG_TOKEN_WCHAR 34 /* L'c' */
#define SWIG_TOKEN_ILLEGAL 99
#define SWIG_TOKEN_ERROR -1

View file

@ -38,6 +38,7 @@ extern void appendChild(Node *node, Node *child);
extern void prependChild(Node *node, Node *child);
extern void removeNode(Node *node);
extern Node *copyNode(Node *node);
extern void appendSibling(Node *node, Node *child);
/* Node restoration/restore functions */

View file

@ -11,8 +11,6 @@
* This file implements the SWIG symbol table. See details below.
* ----------------------------------------------------------------------------- */
char cvsroot_symbol_c[] = "$Id$";
#include "swig.h"
#include "swigwarn.h"
#include <ctype.h>
@ -176,6 +174,8 @@ static Hash *current_symtab = 0; /* Current symbol table node */
static Hash *symtabs = 0; /* Hash of all symbol tables by fully-qualified name */
static Hash *global_scope = 0; /* Global scope */
static int use_inherit = 1;
/* common attribute keys, to avoid calling find_key all the times */
@ -222,7 +222,7 @@ static void symbol_print_symbols(const char *symboltabletype) {
Iterator it = First(symtab);
while (it.key) {
String *symname = it.key;
Printf(stdout, " %s\n", symname);
Printf(stdout, " %s (%s)\n", symname, nodeType(it.item));
/*
Printf(stdout, " %s - %p (%s)\n", symname, it.item, Getattr(it.item, "name"));
*/
@ -463,6 +463,7 @@ Symtab *Swig_symbol_current(void) {
* Swig_symbol_alias()
*
* Makes an alias for a symbol in the global symbol table.
* Primarily for namespace aliases such as 'namespace X = Y;'.
* ----------------------------------------------------------------------------- */
void Swig_symbol_alias(const_String_or_char_ptr aliasname, Symtab *s) {
@ -481,7 +482,9 @@ void Swig_symbol_alias(const_String_or_char_ptr aliasname, Symtab *s) {
/* -----------------------------------------------------------------------------
* Swig_symbol_inherit()
*
* Inherit symbols from another scope.
* Inherit symbols from another scope. Primarily for C++ inheritance and
* for using directives, such as 'using namespace X;'
* but not for using declarations, such as 'using A;'.
* ----------------------------------------------------------------------------- */
void Swig_symbol_inherit(Symtab *s) {
@ -535,6 +538,7 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
if (!name)
return;
if (SwigType_istemplate(name)) {
String *cname = NewString(name);
String *dname = Swig_symbol_template_deftype(cname, 0);
@ -545,7 +549,7 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
Delete(cname);
}
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_cadd %s %x\n", name, n);
Printf(stderr, "symbol_cadd %s %p\n", name, n);
#endif
cn = Getattr(ccurrent, name);
@ -880,7 +884,7 @@ Node *Swig_symbol_add(const_String_or_char_ptr symname, Node *n) {
/* Well, we made it this far. Guess we can drop the symbol in place */
Setattr(n, "sym:symtab", current_symtab);
Setattr(n, "sym:name", symname);
/* Printf(stdout,"%s %x\n", Getattr(n,"sym:overname"), current_symtab); */
/* Printf(stdout,"%s %p\n", Getattr(n,"sym:overname"), current_symtab); */
assert(!Getattr(n, "sym:overname"));
overname = NewStringf("__SWIG_%d", pn);
Setattr(n, "sym:overname", overname);
@ -927,11 +931,10 @@ static Node *_symbol_lookup(const String *name, Symtab *symtab, int (*check) (No
return 0;
Setmark(symtab, 1);
n = Getattr(sym, name);
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_look %s %x %x %s\n", name, n, symtab, Getattr(symtab, "name"));
Printf(stderr, "symbol_look %s %p %p %s\n", name, n, symtab, Getattr(symtab, "name"));
#endif
if (n) {
@ -967,7 +970,7 @@ static Node *_symbol_lookup(const String *name, Symtab *symtab, int (*check) (No
}
inherit = Getattr(symtab, "inherit");
if (inherit) {
if (inherit && use_inherit) {
int i, len;
len = Len(inherit);
for (i = 0; i < len; i++) {
@ -1053,6 +1056,25 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt
Node *pn = Getattr(symtab, "parentNode");
if (pn)
n = symbol_lookup_qualified(name, pn, prefix, local, checkfunc);
/* Check inherited scopes */
if (!n) {
List *inherit = Getattr(symtab, "inherit");
if (inherit && use_inherit) {
int i, len;
len = Len(inherit);
for (i = 0; i < len; i++) {
Node *prefix_node = symbol_lookup(prefix, Getitem(inherit, i), checkfunc);
if (prefix_node) {
Node *prefix_symtab = Getattr(prefix_node, "symtab");
if (prefix_symtab) {
n = symbol_lookup(name, prefix_symtab, checkfunc);
break;
}
}
}
}
}
} else {
n = 0;
}
@ -1065,8 +1087,9 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt
* Swig_symbol_clookup()
*
* Look up a symbol in the symbol table. This uses the C name, not scripting
* names. Note: If we come across a using a directive, we follow it to
* to get the real node.
* names. Note: If we come across a using declaration, we follow it to
* to get the real node. Any using directives are also followed (but this is
* implemented in symbol_lookup()).
* ----------------------------------------------------------------------------- */
Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) {
@ -1207,6 +1230,9 @@ Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (*
/* -----------------------------------------------------------------------------
* Swig_symbol_clookup_local()
*
* Same as Swig_symbol_clookup but parent nodes are not searched, that is, just
* this symbol table is searched.
* ----------------------------------------------------------------------------- */
Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) {
@ -1301,6 +1327,20 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n,
return s;
}
/* -----------------------------------------------------------------------------
* Swig_symbol_clookup_no_inherit()
*
* Symbol lookup like Swig_symbol_clookup but does not follow using declarations.
* ----------------------------------------------------------------------------- */
Node *Swig_symbol_clookup_no_inherit(const_String_or_char_ptr name, Symtab *n) {
Node *s = 0;
assert(use_inherit==1);
use_inherit = 0;
s = Swig_symbol_clookup(name, n);
use_inherit = 1;
return s;
}
/* -----------------------------------------------------------------------------
* Swig_symbol_cscope()
@ -1411,7 +1451,7 @@ String *Swig_symbol_qualified(Node *n) {
if (!symtab)
return NewStringEmpty();
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_qscope %s %x %s\n", Getattr(n, "name"), symtab, Getattr(symtab, "name"));
Printf(stderr, "symbol_qscope %s %p %s\n", Getattr(n, "name"), symtab, Getattr(symtab, "name"));
#endif
return Swig_symbol_qualifiedscopename(symtab);
}
@ -1427,14 +1467,14 @@ Node *Swig_symbol_isoverloaded(Node *n) {
}
/* -----------------------------------------------------------------------------
* Swig_symbol_type_qualify()
* symbol_template_qualify()
*
* Create a fully qualified type name
* Internal function to create a fully qualified type name for templates
* ----------------------------------------------------------------------------- */
/* This cache produces problems with OSS, don't active it */
/* #define SWIG_TEMPLATE_QUALIFY_CACHE */
static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) {
static SwigType *symbol_template_qualify(const SwigType *e, Symtab *st) {
String *tprefix, *tsuffix;
SwigType *qprefix;
List *targs;
@ -1499,10 +1539,17 @@ static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) {
}
static int no_constructor(Node *n) {
static int symbol_no_constructor(Node *n) {
return !Checkattr(n, "nodeType", "constructor");
}
/* -----------------------------------------------------------------------------
* Swig_symbol_type_qualify()
*
* Create a fully qualified type name
* Note: Does not resolve a constructor if passed in as the 'type'.
* ----------------------------------------------------------------------------- */
SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
List *elements;
String *result = NewStringEmpty();
@ -1519,13 +1566,14 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
for (i = 0; i < len; i++) {
String *e = Getitem(elements, i);
if (SwigType_issimple(e)) {
Node *n = Swig_symbol_clookup_check(e, st, no_constructor);
/* Note: the unary scope operator (::) is being removed from the template parameters here. */
Node *n = Swig_symbol_clookup_check(e, st, symbol_no_constructor);
if (n) {
String *name = Getattr(n, "name");
Clear(e);
Append(e, name);
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_qual_ei %d %s %s %x\n", i, name, e, st);
Printf(stderr, "symbol_qual_ei %d %s %s %p\n", i, name, e, st);
#endif
if (!Swig_scopename_check(name)) {
String *qname = Swig_symbol_qualified(n);
@ -1534,12 +1582,12 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
Insert(e, 0, qname);
}
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_qual_sc %d %s %s %x\n", i, qname, e, st);
Printf(stderr, "symbol_qual_sc %d %s %s %p\n", i, qname, e, st);
#endif
Delete(qname);
}
} else if (SwigType_istemplate(e)) {
SwigType *ty = Swig_symbol_template_qualify(e, st);
SwigType *ty = symbol_template_qualify(e, st);
Clear(e);
Append(e, ty);
Delete(ty);
@ -1572,7 +1620,7 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
}
Delete(elements);
#ifdef SWIG_DEBUG
Printf(stderr, "symbol_qualify %s %s %x %s\n", t, result, st, st ? Getattr(st, "name") : 0);
Printf(stderr, "symbol_qualify %s %s %p %s\n", t, result, st, st ? Getattr(st, "name") : 0);
#endif
return result;
@ -1751,7 +1799,7 @@ String *Swig_symbol_string_qualify(String *s, Symtab *st) {
char *c = Char(s);
int first_char = 1;
while (*c) {
if (isalpha((int) *c) || (*c == '_') || (*c == ':') || (isdigit((int) *c) && !first_char)) {
if (isalpha((int) *c) || (*c == '_') || (*c == ':') || (*c == '~' && first_char) || (isdigit((int) *c) && !first_char)) {
Putc(*c, id);
have_id = 1;
} else {

View file

@ -12,8 +12,6 @@
* parse trees.
* ----------------------------------------------------------------------------- */
char cvsroot_tree_c[] = "$Id$";
#include "swig.h"
#include <stdarg.h>
#include <assert.h>
@ -77,12 +75,12 @@ void Swig_print_node(Node *obj) {
if ((Cmp(k, "nodeType") == 0) || (Cmp(k, "firstChild") == 0) || (Cmp(k, "lastChild") == 0) ||
(Cmp(k, "parentNode") == 0) || (Cmp(k, "nextSibling") == 0) || (Cmp(k, "previousSibling") == 0) || (*(Char(k)) == '$')) {
/* Do nothing */
} else if (Cmp(k, "parms") == 0) {
} else if (Cmp(k, "parms") == 0 || Cmp(k, "wrap:parms") == 0) {
print_indent(2);
Printf(stdout, "%-12s - %s\n", k, ParmList_protostr(Getattr(obj, k)));
Printf(stdout, "%-12s - %s\n", k, ParmList_str_defaultargs(Getattr(obj, k)));
} else {
DOH *o;
char *trunc = "";
const char *trunc = "";
print_indent(2);
if (DohIsString(Getattr(obj, k))) {
o = Str(Getattr(obj, k));
@ -92,7 +90,7 @@ void Swig_print_node(Node *obj) {
Printf(stdout, "%-12s - \"%(escape)-0.80s%s\"\n", k, o, trunc);
Delete(o);
} else {
Printf(stdout, "%-12s - 0x%x\n", k, Getattr(obj, k));
Printf(stdout, "%-12s - %p\n", k, Getattr(obj, k));
}
}
ki = Next(ki);
@ -173,6 +171,24 @@ void prependChild(Node *node, Node *chd) {
}
}
void appendSibling(Node *node, Node *chd) {
Node *parent;
Node *lc = node;
while (nextSibling(lc))
lc = nextSibling(lc);
set_nextSibling(lc, chd);
set_previousSibling(chd, lc);
parent = parentNode(node);
if (parent) {
while (chd) {
lc = chd;
set_parentNode(chd, parent);
chd = nextSibling(chd);
}
set_lastChild(parent, lc);
}
}
/* -----------------------------------------------------------------------------
* removeNode()
*

View file

@ -11,8 +11,6 @@
* A somewhat generalized implementation of SWIG1.1 typemaps.
* ----------------------------------------------------------------------------- */
char cvsroot_typemap_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
#include <ctype.h>
@ -89,13 +87,16 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) {
return tm;
}
static void set_typemap(int tm_scope, const SwigType *type, Hash *tm) {
static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) {
SwigType *hashtype = 0;
Hash *new_tm = 0;
assert(*tmhash == 0);
if (SwigType_istemplate(type)) {
SwigType *rty = SwigType_typedef_resolve_all(type);
String *ty = Swig_symbol_template_deftype(rty, 0);
String *tyq = Swig_symbol_type_qualify(ty, 0);
hashtype = SwigType_remove_global_scope_prefix(tyq);
*tmhash = Getattr(typemaps[tm_scope], hashtype);
Delete(rty);
Delete(tyq);
Delete(ty);
@ -103,10 +104,17 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash *tm) {
hashtype = SwigType_remove_global_scope_prefix(type);
}
if (!*tmhash) {
/* this type has not been seen before even after resolving template parameter types */
new_tm = NewHash();
*tmhash = new_tm;
}
/* note that the unary scope operator (::) prefix indicating global scope has been removed from the type */
Setattr(typemaps[tm_scope], hashtype, tm);
Setattr(typemaps[tm_scope], hashtype, *tmhash);
Delete(hashtype);
Delete(new_tm);
}
@ -210,9 +218,7 @@ static void typemap_register(const_String_or_char_ptr tmap_method, ParmList *par
/* See if this type has been seen before */
tm = get_typemap(tm_scope, type);
if (!tm) {
tm = NewHash();
set_typemap(tm_scope, type, tm);
Delete(tm);
set_typemap(tm_scope, type, &tm);
}
if (pname) {
/* See if parameter has been seen before */
@ -476,9 +482,7 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
type = Getattr(lastdp, "type");
tm = get_typemap(tm_scope, type);
if (!tm) {
tm = NewHash();
set_typemap(tm_scope, type, tm);
Delete(tm);
set_typemap(tm_scope, type, &tm);
}
name = Getattr(lastdp, "name");
if (name) {
@ -1035,13 +1039,13 @@ static int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, Swi
$*n_ltype
*/
if (SwigType_ispointer(ftype) || (SwigType_isarray(ftype)) || (SwigType_isreference(ftype))) {
if (!(SwigType_isarray(type) || SwigType_ispointer(type) || SwigType_isreference(type))) {
if (SwigType_ispointer(ftype) || (SwigType_isarray(ftype)) || (SwigType_isreference(ftype)) || (SwigType_isrvalue_reference(ftype))) {
if (!(SwigType_isarray(type) || SwigType_ispointer(type) || SwigType_isreference(type) || SwigType_isrvalue_reference(type))) {
star_type = Copy(ftype);
} else {
star_type = Copy(type);
}
if (!SwigType_isreference(star_type)) {
if (!(SwigType_isreference(star_type) || SwigType_isrvalue_reference(star_type))) {
if (SwigType_isarray(star_type)) {
SwigType_del_element(star_type);
} else {
@ -1196,7 +1200,7 @@ static int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, Swi
* creates the local variables.
* ------------------------------------------------------------------------ */
static void typemap_locals(DOHString * s, ParmList *l, Wrapper *f, int argnum) {
static void typemap_locals(String *s, ParmList *l, Wrapper *f, int argnum) {
Parm *p;
char *new_name;
@ -1300,6 +1304,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
SwigType *mtype = 0;
String *pname;
String *qpname = 0;
String *noscope_pname = 0;
Hash *tm = 0;
String *s = 0;
String *sdef = 0;
@ -1323,7 +1328,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
/* Special hook (hack!). Check for the 'ref' feature and add code it contains to any 'newfree' typemap code.
* We could choose to put this hook into a number of different typemaps, not necessarily 'newfree'...
* Rather confusingly 'newfree' is used to release memory and the 'ref' feature is used to add in memory references - yuck! */
if (node && Cmp(tmap_method, "newfree") == 0) {
if (Cmp(tmap_method, "newfree") == 0) {
String *base = SwigType_base(type);
Node *typenode = Swig_symbol_clookup(base, 0);
if (typenode)
@ -1332,21 +1337,32 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
}
pname = Getattr(node, "name");
noscope_pname = Copy(pname);
if (pname && node && checkAttribute(node, "kind", "function")) {
/*
For functions, add on a qualified name search, for example
struct Foo {
int *foo(int bar) -> Foo::foo
};
if (pname && Getattr(node, "sym:symtab")) {
/* Add on a qualified name search for any symbol in the symbol table, for example:
* struct Foo {
* int *foo(int bar) -> Foo::foo
* };
* Note that if node is a parameter (Parm *) then there will be no symbol table attached to the Parm *.
*/
Symtab *st = Getattr(node, "sym:symtab");
String *qsn = st ? Swig_symbol_string_qualify(pname, st) : 0;
if (qsn && Len(qsn) && !Equal(qsn, pname))
qpname = qsn;
String *qsn;
if (Swig_scopename_check(pname)) {
/* sometimes pname is qualified, so we remove all the scope for the lookup */
Delete(noscope_pname);
noscope_pname = Swig_scopename_last(pname);
/*
Printf(stdout, "Removed scope: %s => %s\n", pname, noscope_pname);
*/
}
qsn = Swig_symbol_qualified(node);
if (qsn && Len(qsn)) {
qpname = NewStringf("%s::%s", qsn, noscope_pname);
Delete(qsn);
}
}
tm = typemap_search(tmap_method, type, pname, qpname, &mtype, node);
tm = typemap_search(tmap_method, type, noscope_pname, qpname, &mtype, node);
if (typemap_search_debug)
debug_search_result_display(tm);
if (typemaps_used_debug && tm) {
@ -1359,6 +1375,8 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
Delete(qpname);
qpname = 0;
Delete(noscope_pname);
noscope_pname = 0;
if (!tm)
return sdef;

View file

@ -14,10 +14,9 @@
* like typedef, namespaces, etc.
* ----------------------------------------------------------------------------- */
char cvsroot_typeobj_c[] = "$Id$";
#include "swig.h"
#include <ctype.h>
#include <limits.h>
/* -----------------------------------------------------------------------------
* Synopsis
@ -45,6 +44,7 @@ char cvsroot_typeobj_c[] = "$Id$";
*
* 'p.' = Pointer (*)
* 'r.' = Reference (&)
* 'z.' = Rvalue reference (&&)
* 'a(n).' = Array of size n [n]
* 'f(..,..).' = Function with arguments (args)
* 'q(str).' = Qualifier (such as const or volatile) (const, volatile)
@ -78,6 +78,7 @@ char cvsroot_typeobj_c[] = "$Id$";
*
* SwigType_add_pointer()
* SwigType_add_reference()
* SwigType_add_rvalue_reference()
* SwigType_add_array()
*
* These are used to build new types. There are also functions to undo these
@ -85,12 +86,14 @@ char cvsroot_typeobj_c[] = "$Id$";
*
* SwigType_del_pointer()
* SwigType_del_reference()
* SwigType_del_rvalue_reference()
* SwigType_del_array()
*
* In addition, there are query functions
*
* SwigType_ispointer()
* SwigType_isreference()
* SwigType_isrvalue_reference()
* SwigType_isarray()
*
* Finally, there are some data extraction functions that can be used to
@ -237,7 +240,7 @@ String *SwigType_parm(const SwigType *t) {
/* -----------------------------------------------------------------------------
* SwigType_split()
*
* Splits a type into it's component parts and returns a list of string.
* Splits a type into its component parts and returns a list of string.
* ----------------------------------------------------------------------------- */
List *SwigType_split(const SwigType *t) {
@ -415,6 +418,41 @@ int SwigType_isreference(const SwigType *t) {
return 0;
}
/* -----------------------------------------------------------------------------
* Rvalue References
*
* SwigType_add_rvalue_reference()
* SwigType_del_rvalue_reference()
* SwigType_isrvalue_reference()
*
* Add, remove, and test if a type is a rvalue reference. The deletion and query
* functions take into account qualifiers (if any).
* ----------------------------------------------------------------------------- */
SwigType *SwigType_add_rvalue_reference(SwigType *t) {
Insert(t, 0, "z.");
return t;
}
SwigType *SwigType_del_rvalue_reference(SwigType *t) {
char *c = Char(t);
int check = strncmp(c, "z.", 2);
assert(check == 0);
Delslice(t, 0, 2);
return t;
}
int SwigType_isrvalue_reference(const SwigType *t) {
char *c;
if (!t)
return 0;
c = Char(t);
if (strncmp(c, "z.", 2) == 0) {
return 1;
}
return 0;
}
/* -----------------------------------------------------------------------------
* Qualifiers
*
@ -427,62 +465,62 @@ int SwigType_isreference(const SwigType *t) {
* Repeated qualifications have no effect. Moreover, the order of qualifications
* is alphabetical---meaning that "const volatile" and "volatile const" are
* stored in exactly the same way as "q(const volatile)".
* 'qual' can be a list of multiple qualifiers in any order, separated by spaces.
* ----------------------------------------------------------------------------- */
SwigType *SwigType_add_qualifier(SwigType *t, const_String_or_char_ptr qual) {
char temp[256], newq[256];
int sz, added = 0;
char *q, *cqual;
List *qlist;
String *allq, *newq;
int i, sz;
const char *cqprev = 0;
const char *c = Char(t);
const char *cqual = Char(qual);
char *c = Char(t);
cqual = Char(qual);
if (!(strncmp(c, "q(", 2) == 0)) {
sprintf(temp, "q(%s).", cqual);
/* if 't' has no qualifiers and 'qual' is a single qualifier, simply add it */
if ((strncmp(c, "q(", 2) != 0) && (strstr(cqual, " ") == 0)) {
String *temp = NewStringf("q(%s).", cqual);
Insert(t, 0, temp);
Delete(temp);
return t;
}
/* The type already has a qualifier on it. In this case, we first check to
see if the qualifier is already specified. In that case do nothing.
If it is a new qualifier, we add it to the qualifier list in alphabetical
order */
sz = element_size(c);
strncpy(temp, c, (sz < 256) ? sz : 256);
if (strstr(temp, cqual)) {
/* Qualifier already added */
return t;
/* create string of all qualifiers */
if (strncmp(c, "q(", 2) == 0) {
allq = SwigType_parm(t);
Append(allq, " ");
SwigType_del_element(t); /* delete old qualifier list from 't' */
} else {
allq = NewStringEmpty();
}
Append(allq, qual);
/* Add the qualifier to the existing list. */
/* create list of all qualifiers from string */
qlist = Split(allq, ' ', INT_MAX);
Delete(allq);
strcpy(newq, "q(");
q = temp + 2;
q = strtok(q, " ).");
while (q) {
if (strcmp(cqual, q) < 0) {
/* New qualifier is less that current qualifier. We need to insert it */
strcat(newq, cqual);
strcat(newq, " ");
strcat(newq, q);
added = 1;
} else {
strcat(newq, q);
}
q = strtok(NULL, " ).");
if (q) {
strcat(newq, " ");
/* sort in alphabetical order */
SortList(qlist, Strcmp);
/* create new qualifier string from unique elements of list */
sz = Len(qlist);
newq = NewString("q(");
for (i = 0; i < sz; ++i) {
String *q = Getitem(qlist, i);
const char *cq = Char(q);
if (cqprev == 0 || strcmp(cqprev, cq) != 0) {
if (i > 0) {
Append(newq, " ");
}
Append(newq, q);
cqprev = cq;
}
}
if (!added) {
strcat(newq, " ");
strcat(newq, cqual);
}
strcat(newq, ").");
Delslice(t, 0, sz);
Append(newq, ").");
Delete(qlist);
/* replace qualifier string with new one */
Insert(t, 0, newq);
Delete(newq);
return t;
}
@ -590,11 +628,11 @@ int SwigType_ismemberpointer(const SwigType *t) {
* ----------------------------------------------------------------------------- */
SwigType *SwigType_add_array(SwigType *t, const_String_or_char_ptr size) {
char temp[512];
strcpy(temp, "a(");
strcat(temp, Char(size));
strcat(temp, ").");
String *temp = NewString("a(");
Append(temp, size);
Append(temp, ").");
Insert(t, 0, temp);
Delete(temp);
return t;
}
@ -627,8 +665,8 @@ int SwigType_prefix_is_simple_1D_array(const SwigType *t) {
if (c && (strncmp(c, "a(", 2) == 0)) {
c = strchr(c, '.');
c++;
return (*c == 0);
if (c)
return (*(++c) == 0);
}
return 0;
}
@ -654,8 +692,10 @@ int SwigType_array_ndim(const SwigType *t) {
while (c && (strncmp(c, "a(", 2) == 0)) {
c = strchr(c, '.');
c++;
ndim++;
if (c) {
c++;
ndim++;
}
}
return ndim;
}
@ -665,8 +705,10 @@ String *SwigType_array_getdim(const SwigType *t, int n) {
char *c = Char(t);
while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) {
c = strchr(c, '.');
c++;
n--;
if (c) {
c++;
n--;
}
}
if (n == 0) {
String *dim = SwigType_parm(c);
@ -695,8 +737,10 @@ void SwigType_array_setdim(SwigType *t, int n, const_String_or_char_ptr rep) {
while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) {
c = strchr(c, '.');
c++;
n--;
if (c) {
c++;
n--;
}
}
if (n == 0) {
temp = *c;
@ -741,7 +785,6 @@ SwigType *SwigType_add_function(SwigType *t, ParmList *parms) {
Insert(t, 0, ").");
pstr = NewString("f(");
p = parms;
for (p = parms; p; p = nextSibling(p)) {
if (p != parms)
Putc(',', pstr);
@ -839,7 +882,6 @@ SwigType *SwigType_add_template(SwigType *t, ParmList *parms) {
Parm *p;
Append(t, "<(");
p = parms;
for (p = parms; p; p = nextSibling(p)) {
String *v;
if (Getattr(p, "default"))

View file

@ -14,8 +14,6 @@
* run-time type checker is also handled here.
* ----------------------------------------------------------------------------- */
char cvsroot_typesys_c[] = "$Id$";
#include "swig.h"
#include "cparse.h"
@ -297,7 +295,7 @@ void SwigType_inherit_scope(Typetab *scope) {
void SwigType_scope_alias(String *aliasname, Typetab *ttab) {
String *q;
/* Printf(stdout,"alias: '%s' '%x'\n", aliasname, ttab); */
/* Printf(stdout,"alias: '%s' '%p'\n", aliasname, ttab); */
q = SwigType_scope_name(current_scope);
if (Len(q)) {
Append(q, "::");
@ -398,13 +396,13 @@ void SwigType_print_scope(void) {
Printf(stdout, "-------------------------------------------------------------\n");
ttab = Getattr(i.item, "typetab");
Printf(stdout, "Type scope '%s' (%x)\n", i.key, i.item);
Printf(stdout, "Type scope '%s' (%p)\n", i.key, i.item);
{
List *inherit = Getattr(i.item, "inherit");
if (inherit) {
Iterator j;
for (j = First(inherit); j.item; j = Next(j)) {
Printf(stdout, " Inherits from '%s' (%x)\n", Getattr(j.item, "qname"), j.item);
Printf(stdout, " Inherits from '%s' (%p)\n", Getattr(j.item, "qname"), j.item);
}
}
}
@ -604,7 +602,7 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
Typetab *s;
Hash *ttab;
String *namebase = 0;
String *nameprefix = 0;
String *nameprefix = 0, *rnameprefix = 0;
int newtype = 0;
resolved_scope = 0;
@ -649,51 +647,66 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
Printf(stdout, "nameprefix = '%s'\n", nameprefix);
#endif
if (nameprefix) {
/* Name had a prefix on it. See if we can locate the proper scope for it */
String *rnameprefix = template_parameters_resolve(nameprefix);
nameprefix = rnameprefix ? Copy(rnameprefix) : nameprefix;
Delete(rnameprefix);
s = SwigType_find_scope(s, nameprefix);
/* Couldn't locate a scope for the type. */
if (!s) {
Delete(base);
Delete(namebase);
Delete(nameprefix);
r = 0;
goto return_result;
}
/* Try to locate the name starting in the scope */
rnameprefix = SwigType_typedef_resolve(nameprefix);
if(rnameprefix != NULL) {
#ifdef SWIG_DEBUG
Printf(stdout, "namebase = '%s'\n", namebase);
Printf(stdout, "nameprefix '%s' is a typedef to '%s'\n", nameprefix, rnameprefix);
#endif
type = typedef_resolve(s, namebase);
if (type) {
/* we need to look for the resolved type, this will also
fix the resolved_scope if 'type' and 'namebase' are
declared in different scopes */
String *rtype = 0;
rtype = typedef_resolve(resolved_scope, type);
if (rtype)
type = rtype;
}
#ifdef SWIG_DEBUG
Printf(stdout, "%s type = '%s'\n", Getattr(s, "name"), type);
#endif
if ((type) && (!Swig_scopename_check(type)) && resolved_scope) {
Typetab *rtab = resolved_scope;
String *qname = Getattr(resolved_scope, "qname");
/* If qualified *and* the typename is defined from the resolved scope, we qualify */
if ((qname) && typedef_resolve(resolved_scope, type)) {
type = Copy(type);
Insert(type, 0, "::");
Insert(type, 0, qname);
#ifdef SWIG_DEBUG
Printf(stdout, "qual %s \n", type);
#endif
newtype = 1;
type = Copy(namebase);
Insert(type, 0, "::");
Insert(type, 0, rnameprefix);
if (strncmp(Char(type), "::", 2) == 0) {
Delitem(type, 0);
Delitem(type, 0);
}
newtype = 1;
} else {
/* Name had a prefix on it. See if we can locate the proper scope for it */
String *rnameprefix = template_parameters_resolve(nameprefix);
nameprefix = rnameprefix ? Copy(rnameprefix) : nameprefix;
Delete(rnameprefix);
s = SwigType_find_scope(s, nameprefix);
/* Couldn't locate a scope for the type. */
if (!s) {
Delete(base);
Delete(namebase);
Delete(nameprefix);
r = 0;
goto return_result;
}
/* Try to locate the name starting in the scope */
#ifdef SWIG_DEBUG
Printf(stdout, "namebase = '%s'\n", namebase);
#endif
type = typedef_resolve(s, namebase);
if (type && resolved_scope) {
/* we need to look for the resolved type, this will also
fix the resolved_scope if 'type' and 'namebase' are
declared in different scopes */
String *rtype = 0;
rtype = typedef_resolve(resolved_scope, type);
if (rtype)
type = rtype;
}
#ifdef SWIG_DEBUG
Printf(stdout, "%s type = '%s'\n", Getattr(s, "name"), type);
#endif
if ((type) && (!Swig_scopename_check(type)) && resolved_scope) {
Typetab *rtab = resolved_scope;
String *qname = Getattr(resolved_scope, "qname");
/* If qualified *and* the typename is defined from the resolved scope, we qualify */
if ((qname) && typedef_resolve(resolved_scope, type)) {
type = Copy(type);
Insert(type, 0, "::");
Insert(type, 0, qname);
#ifdef SWIG_DEBUG
Printf(stdout, "qual %s \n", type);
#endif
newtype = 1;
}
resolved_scope = rtab;
}
resolved_scope = rtab;
}
} else {
/* Name is unqualified. */
@ -794,6 +807,67 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
goto return_result;
}
Delete(base);
/* If 'type' is an array, then the right-most qualifier in 'r' should
be added to 'type' after the array qualifier, so that given
a(7).q(volatile).double myarray // typedef volatile double[7] myarray;
the type
q(const).myarray // const myarray
becomes
a(7).q(const volatile).double // const volatile double[7]
and NOT
q(const).a(7).q(volatile).double // non-sensical type
*/
if (r && Len(r) && SwigType_isarray(type)) {
List *r_elem;
String *r_qual;
int r_sz;
r_elem = SwigType_split(r);
r_sz = Len(r_elem);
r_qual = Getitem(r_elem, r_sz-1);
if (SwigType_isqualifier(r_qual)) {
String *new_r;
String *new_type;
List *type_elem;
String *type_qual;
String *r_qual_arg;
int i, type_sz;
type_elem = SwigType_split(type);
type_sz = Len(type_elem);
for (i = 0; i < type_sz; ++i) {
String *e = Getitem(type_elem, i);
if (!SwigType_isarray(e))
break;
}
type_qual = Copy(Getitem(type_elem, i));
r_qual_arg = SwigType_parm(r_qual);
SwigType_add_qualifier(type_qual, r_qual_arg);
Delete(r_qual_arg);
Setitem(type_elem, i, type_qual);
new_r = NewStringEmpty();
for (i = 0; i < r_sz-1; ++i) {
Append(new_r, Getitem(r_elem, i));
}
new_type = NewStringEmpty();
for (i = 0; i < type_sz; ++i) {
Append(new_type, Getitem(type_elem, i));
}
#ifdef SWIG_DEBUG
Printf(stdout, "r+type='%s%s' new_r+new_type='%s%s'\n", r, type, new_r, new_type);
#endif
Delete(r);
r = new_r;
newtype = 1;
type = new_type;
Delete(type_elem);
}
Delete(r_elem);
}
Append(r, type);
if (newtype) {
Delete(type);
@ -898,7 +972,7 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) {
e = ty;
}
resolved_scope = 0;
if (typedef_resolve(current_scope, e)) {
if (typedef_resolve(current_scope, e) && resolved_scope) {
/* resolved_scope contains the scope that actually resolved the symbol */
String *qname = Getattr(resolved_scope, "qname");
if (qname) {
@ -955,6 +1029,10 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) {
Parm *p;
List *parms;
ty = Swig_symbol_template_deftype(e, current_symtab);
/*
String *dt = Swig_symbol_template_deftype(e, current_symtab);
ty = Swig_symbol_type_qualify(dt, 0);
*/
e = ty;
parms = SwigType_parmlist(e);
tprefix = SwigType_templateprefix(e);
@ -1021,6 +1099,9 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) {
Delete(tprefix);
Delete(qprefix);
Delete(parms);
/*
Delete(dt);
*/
}
Append(result, e);
Delete(ty);
@ -1114,14 +1195,14 @@ int SwigType_typedef_using(const_String_or_char_ptr name) {
/* See if the using name is a scope */
/* tt = SwigType_find_scope(current_scope,name);
Printf(stdout,"tt = %x, name = '%s'\n", tt, name); */
Printf(stdout,"tt = %p, name = '%s'\n", tt, name); */
/* We set up a typedef B --> A::B */
Setattr(current_typetab, base, name);
/* Find the scope name where the symbol is defined */
td = SwigType_typedef_resolve(name);
/* Printf(stdout,"td = '%s' %x\n", td, resolved_scope); */
/* Printf(stdout,"td = '%s' %p\n", td, resolved_scope); */
if (resolved_scope) {
defined_name = Getattr(resolved_scope, "qname");
if (defined_name) {
@ -1216,6 +1297,8 @@ int SwigType_type(const SwigType *t) {
if (strncmp(c, "p.", 2) == 0) {
if (SwigType_type(c + 2) == T_CHAR)
return T_STRING;
else if (SwigType_type(c + 2) == T_WCHAR)
return T_WSTRING;
else
return T_POINTER;
}
@ -1223,6 +1306,8 @@ int SwigType_type(const SwigType *t) {
return T_ARRAY;
if (strncmp(c, "r.", 2) == 0)
return T_REFERENCE;
if (strncmp(c, "z.", 2) == 0)
return T_RVALUE_REFERENCE;
if (strncmp(c, "m(", 2) == 0)
return T_MPOINTER;
if (strncmp(c, "q(", 2) == 0) {
@ -1256,6 +1341,8 @@ int SwigType_type(const SwigType *t) {
return T_SCHAR;
if (strcmp(c, "unsigned char") == 0)
return T_UCHAR;
if (strcmp(c, "wchar_t") == 0)
return T_WCHAR;
if (strcmp(c, "float") == 0)
return T_FLOAT;
if (strcmp(c, "double") == 0)
@ -1278,6 +1365,8 @@ int SwigType_type(const SwigType *t) {
return T_ULONGLONG;
if (strncmp(c, "enum ", 5) == 0)
return T_INT;
if (strcmp(c, "auto") == 0)
return T_AUTO;
if (strcmp(c, "v(...)") == 0)
return T_VARARGS;
@ -1307,13 +1396,13 @@ int SwigType_type(const SwigType *t) {
*
* 2.- swig doesn't mark 'type' as non-assignable.
*
* 3.- the user specify that the value wrapper is not needed by using
* the %feature("novaluewrapper"), in that case the user need to type
* 3.- the user specifies that the value wrapper is not needed by using
* %feature("novaluewrapper") like so:
*
* %feature("novaluewrapper") MyOpaqueClass;
* class MyOpaqueClass;
*
* Users can also force the use of the value wrapper by using the
* The user can also force the use of the value wrapper with
* %feature("valuewrapper").
* ----------------------------------------------------------------------------- */
@ -1555,6 +1644,11 @@ void SwigType_remember_clientdata(const SwigType *t, const_String_or_char_ptr cl
SwigType_del_reference(tt);
SwigType_add_pointer(tt);
SwigType_remember_clientdata(tt, clientdata);
} else if (SwigType_isrvalue_reference(t)) {
SwigType *tt = Copy(t);
SwigType_del_rvalue_reference(tt);
SwigType_add_pointer(tt);
SwigType_remember_clientdata(tt, clientdata);
}
}
@ -1803,13 +1897,13 @@ void SwigType_inherit_equiv(File *out) {
Append(rlist, ck.key);
}
/* Printf(stdout,"rk.key = '%s'\n", rk.key);
Printf(stdout,"rh = %x '%s'\n", rh,rh); */
Printf(stdout,"rh = %p '%s'\n", rh,rh); */
bk = First(sub);
while (bk.key) {
prefix = SwigType_prefix(rk.key);
Append(prefix, bk.key);
/* Printf(stdout,"set %x = '%s' : '%s'\n", rh, SwigType_manglestr(prefix),prefix); */
/* Printf(stdout,"set %p = '%s' : '%s'\n", rh, SwigType_manglestr(prefix),prefix); */
mprefix = SwigType_manglestr(prefix);
Setattr(rh, mprefix, prefix);
mkey = SwigType_manglestr(rk.key);

View file

@ -13,8 +13,6 @@
* to be created in a piecemeal manner.
* ----------------------------------------------------------------------------- */
char cvsroot_wrapfunc_c[] = "$Id$";
#include "swig.h"
#include <ctype.h>