Cosmetics/code beautification of nested class support

This commit is contained in:
William S Fulton 2013-11-28 21:01:02 +00:00
commit 44a883a057
13 changed files with 249 additions and 241 deletions

View file

@ -118,7 +118,13 @@ void skip_balanced(int startchar, int endchar) {
return; return;
} }
String* get_raw_text_balanced(int startchar, int endchar) { /* -----------------------------------------------------------------------------
* get_raw_text_balanced()
*
* Returns raw text between 2 braces
* ----------------------------------------------------------------------------- */
String *get_raw_text_balanced(int startchar, int endchar) {
return Scanner_get_raw_text_balanced(scan, startchar, endchar); return Scanner_get_raw_text_balanced(scan, startchar, endchar);
} }

View file

@ -51,7 +51,7 @@ static Node *module_node = 0;
static String *Classprefix = 0; static String *Classprefix = 0;
static String *Namespaceprefix = 0; static String *Namespaceprefix = 0;
static int inclass = 0; static int inclass = 0;
static Node *currentOuterClass = 0; /*for nested classes*/ static Node *currentOuterClass = 0; /* for nested classes */
static char *last_cpptype = 0; static char *last_cpptype = 0;
static int inherit_list = 0; static int inherit_list = 0;
static Parm *template_parameters = 0; static Parm *template_parameters = 0;
@ -233,7 +233,7 @@ static String *feature_identifier_fix(String *s) {
} }
} }
static void set_access_mode(Node* n) { static void set_access_mode(Node *n) {
if (cplus_mode == CPLUS_PUBLIC) if (cplus_mode == CPLUS_PUBLIC)
Setattr(n, "access", "public"); Setattr(n, "access", "public");
else if (cplus_mode == CPLUS_PROTECTED) else if (cplus_mode == CPLUS_PROTECTED)
@ -242,7 +242,7 @@ static void set_access_mode(Node* n) {
Setattr(n, "access", "private"); Setattr(n, "access", "private");
} }
static void restore_access_mode(Node* n) { static void restore_access_mode(Node *n) {
char* mode = Char(Getattr(n, "access")); char* mode = Char(Getattr(n, "access"));
if (strcmp(mode, "private") == 0) if (strcmp(mode, "private") == 0)
cplus_mode = CPLUS_PRIVATE; cplus_mode = CPLUS_PRIVATE;
@ -799,26 +799,26 @@ static String *make_class_name(String *name) {
} }
/* Use typedef name as class name */ /* Use typedef name as class name */
void add_typedef_name(Node* n, Node* decl, String* oldName, Symtab *cscope, String* scpname)
{ void add_typedef_name(Node *n, Node *decl, String *oldName, Symtab *cscope, String *scpname) {
String* class_rename = 0; String *class_rename = 0;
SwigType *decltype = Getattr(decl,"decl"); SwigType *decltype = Getattr(decl, "decl");
if (!decltype || !Len(decltype)) { if (!decltype || !Len(decltype)) {
String *cname; String *cname;
String *tdscopename; String *tdscopename;
String *class_scope = Swig_symbol_qualifiedscopename(cscope); String *class_scope = Swig_symbol_qualifiedscopename(cscope);
String *name = Getattr(decl,"name"); String *name = Getattr(decl, "name");
cname = Copy(name); cname = Copy(name);
Setattr(n,"tdname",cname); Setattr(n, "tdname", cname);
tdscopename = class_scope ? NewStringf("%s::%s", class_scope, name) : Copy(name); tdscopename = class_scope ? NewStringf("%s::%s", class_scope, name) : Copy(name);
class_rename = Getattr(n, "class_rename"); class_rename = Getattr(n, "class_rename");
if (class_rename && (Strcmp(class_rename,oldName) == 0)) if (class_rename && (Strcmp(class_rename, oldName) == 0))
Setattr(n, "class_rename", NewString(name)); Setattr(n, "class_rename", NewString(name));
if (!classes_typedefs) classes_typedefs = NewHash(); if (!classes_typedefs) classes_typedefs = NewHash();
if (!Equal(scpname, tdscopename) && !Getattr(classes_typedefs, tdscopename)) { if (!Equal(scpname, tdscopename) && !Getattr(classes_typedefs, tdscopename)) {
Setattr(classes_typedefs, tdscopename, n); Setattr(classes_typedefs, tdscopename, n);
} }
Setattr(n,"decl",decltype); Setattr(n, "decl", decltype);
Delete(class_scope); Delete(class_scope);
Delete(cname); Delete(cname);
Delete(tdscopename); Delete(tdscopename);
@ -1043,10 +1043,10 @@ static String *resolve_create_node_scope(String *cname) {
} }
/* look for simple typedef name in typedef list */ /* look for simple typedef name in typedef list */
String* try_to_find_a_name_for_unnamed_structure(char* storage, Node* decls) { String *try_to_find_a_name_for_unnamed_structure(char *storage, Node *decls) {
String* name = 0; String *name = 0;
Node* n = decls; Node *n = decls;
if (storage && (strcmp(storage,"typedef") == 0)) { if (storage && (strcmp(storage, "typedef") == 0)) {
for (; n; n = nextSibling(n)) { for (; n; n = nextSibling(n)) {
if (!Len(Getattr(n, "decl"))) { if (!Len(Getattr(n, "decl"))) {
name = Copy(Getattr(n, "name")); name = Copy(Getattr(n, "name"));
@ -1058,9 +1058,9 @@ String* try_to_find_a_name_for_unnamed_structure(char* storage, Node* decls) {
} }
/* traverse copied tree segment, and update outer class links*/ /* traverse copied tree segment, and update outer class links*/
void update_nested_classes(Node* n) void update_nested_classes(Node *n)
{ {
Node* c = firstChild(n); Node *c = firstChild(n);
while (c) { while (c) {
if (Getattr(c, "nested:outer")) if (Getattr(c, "nested:outer"))
Setattr(c, "nested:outer", n); Setattr(c, "nested:outer", n);
@ -1432,7 +1432,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) {
%type <node> cpp_declaration cpp_class_decl cpp_forward_class_decl cpp_template_decl cpp_alternate_rettype; %type <node> cpp_declaration cpp_class_decl cpp_forward_class_decl cpp_template_decl cpp_alternate_rettype;
%type <node> cpp_members cpp_member; %type <node> cpp_members cpp_member;
%type <node> cpp_constructor_decl cpp_destructor_decl cpp_protection_decl cpp_conversion_operator cpp_static_assert; %type <node> cpp_constructor_decl cpp_destructor_decl cpp_protection_decl cpp_conversion_operator cpp_static_assert;
%type <node> cpp_swig_directive cpp_temp_possible /*cpp_nested*/ cpp_opt_declarators ; %type <node> cpp_swig_directive cpp_temp_possible cpp_opt_declarators ;
%type <node> cpp_using_decl cpp_namespace_decl cpp_catch_decl cpp_lambda_decl; %type <node> cpp_using_decl cpp_namespace_decl cpp_catch_decl cpp_lambda_decl;
%type <node> kwargs options; %type <node> kwargs options;
@ -3447,7 +3447,8 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
Delete(prefix); Delete(prefix);
inclass = 1; inclass = 1;
currentOuterClass = $<node>$; currentOuterClass = $<node>$;
if (CPlusPlusOut) { /* save the structure declaration to declare it in global scope for C++ to see*/ if (CPlusPlusOut) {
/* save the structure declaration to declare it in global scope for C++ to see */
code = get_raw_text_balanced('{', '}'); code = get_raw_text_balanced('{', '}');
Setattr($<node>$, "code", code); Setattr($<node>$, "code", code);
Delete(code); Delete(code);
@ -3550,7 +3551,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
Delete(Namespaceprefix); Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
if (!cparse_cplusplus && currentOuterClass) { /* nested C structs go into global scope*/ if (!cparse_cplusplus && currentOuterClass) { /* nested C structs go into global scope*/
Node* outer = currentOuterClass; Node *outer = currentOuterClass;
while (Getattr(outer, "nested:outer")) while (Getattr(outer, "nested:outer"))
outer = Getattr(outer, "nested:outer"); outer = Getattr(outer, "nested:outer");
appendSibling(outer, $$); appendSibling(outer, $$);
@ -4286,7 +4287,6 @@ cpp_member : c_declaration { $$ = $1; }
| cpp_conversion_operator { $$ = $1; } | cpp_conversion_operator { $$ = $1; }
| cpp_forward_class_decl { $$ = $1; } | cpp_forward_class_decl { $$ = $1; }
| cpp_class_decl { $$ = $1; } | cpp_class_decl { $$ = $1; }
/* | cpp_nested { $$ = $1; }*/
| storage_class idcolon SEMI { $$ = 0; } | storage_class idcolon SEMI { $$ = 0; }
| cpp_using_decl { $$ = $1; } | cpp_using_decl { $$ = $1; }
| cpp_template_decl { $$ = $1; } | cpp_template_decl { $$ = $1; }

View file

@ -559,7 +559,7 @@ Allocate():
virtual int classDeclaration(Node *n) { virtual int classDeclaration(Node *n) {
Symtab *symtab = Swig_symbol_current(); Symtab *symtab = Swig_symbol_current();
Swig_symbol_setscope(Getattr(n, "symtab")); Swig_symbol_setscope(Getattr(n, "symtab"));
Node* oldInclass = inclass; Node *oldInclass = inclass;
AccessMode oldAcessMode = cplus_mode; AccessMode oldAcessMode = cplus_mode;
if (!CPlusPlus) { if (!CPlusPlus) {

View file

@ -343,7 +343,7 @@ int Contracts::namespaceDeclaration(Node *n) {
int Contracts::classDeclaration(Node *n) { int Contracts::classDeclaration(Node *n) {
int ret = SWIG_OK; int ret = SWIG_OK;
int oldInClass = InClass; int oldInClass = InClass;
Node* oldClass = CurrentClass; Node *oldClass = CurrentClass;
InClass = 1; InClass = 1;
CurrentClass = n; CurrentClass = n;
emit_children(n); emit_children(n);

View file

@ -19,7 +19,7 @@
/* Hash type used for upcalls from C/C++ */ /* Hash type used for upcalls from C/C++ */
typedef DOH UpcallData; typedef DOH UpcallData;
// insert N tabs before each new line in s // insert N tabs before each new line in s
void Swig_offset_string(String* s, int N); void Swig_offset_string(String *s, int N);
class CSHARP:public Language { class CSHARP:public Language {
static const char *usage; static const char *usage;
@ -183,7 +183,7 @@ public:
String *nspace = Getattr(n, "sym:nspace"); String *nspace = Getattr(n, "sym:nspace");
String *symname = Copy(Getattr(n, "sym:name")); String *symname = Copy(Getattr(n, "sym:name"));
if (!GetFlag(n, "feature:flatnested")) { if (!GetFlag(n, "feature:flatnested")) {
for (Node* outer_class = Getattr(n, "nested:outer");outer_class;outer_class = Getattr(outer_class, "nested:outer")) { for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) {
Push(symname, "."); Push(symname, ".");
Push(symname, Getattr(outer_class, "sym:name")); Push(symname, Getattr(outer_class, "sym:name"));
} }
@ -1878,22 +1878,22 @@ public:
String *nspace = getNSpace(); String *nspace = getNSpace();
File *f_proxy = NULL; File *f_proxy = NULL;
// save class local variables // save class local variables
String* old_proxy_class_name = proxy_class_name; String *old_proxy_class_name = proxy_class_name;
String* old_full_imclass_name = full_imclass_name; String *old_full_imclass_name = full_imclass_name;
String* old_destructor_call = destructor_call; String *old_destructor_call = destructor_call;
String* old_proxy_class_constants_code = proxy_class_constants_code; String *old_proxy_class_constants_code = proxy_class_constants_code;
String* old_proxy_class_def = proxy_class_def; String *old_proxy_class_def = proxy_class_def;
String* old_proxy_class_code = proxy_class_code; String *old_proxy_class_code = proxy_class_code;
if (proxy_flag) { if (proxy_flag) {
proxy_class_name = NewString(Getattr(n, "sym:name")); proxy_class_name = NewString(Getattr(n, "sym:name"));
if (Node* outer = Getattr(n, "nested:outer")) { if (Node *outer = Getattr(n, "nested:outer")) {
String* outerClassesPrefix = Copy(Getattr(outer, "sym:name")); String *outerClassesPrefix = Copy(Getattr(outer, "sym:name"));
for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) {
Push(outerClassesPrefix, "::"); Push(outerClassesPrefix, "::");
Push(outerClassesPrefix, Getattr(outer, "sym:name")); Push(outerClassesPrefix, Getattr(outer, "sym:name"));
} }
String* fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix; String *fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix;
if (!addSymbol(proxy_class_name, n, fnspace)) if (!addSymbol(proxy_class_name, n, fnspace))
return SWIG_ERROR; return SWIG_ERROR;
if (nspace) if (nspace)
@ -3458,7 +3458,7 @@ public:
String *dirClassName = directorClassName(n); String *dirClassName = directorClassName(n);
String *smartptr = Getattr(n, "feature:smartptr"); String *smartptr = Getattr(n, "feature:smartptr");
if (!GetFlag(n, "feature:flatnested")) { if (!GetFlag(n, "feature:flatnested")) {
for (Node* outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) {
Push(qualified_classname, "."); Push(qualified_classname, ".");
Push(qualified_classname, Getattr(outer_class, "sym:name")); Push(qualified_classname, Getattr(outer_class, "sym:name"));
@ -4134,7 +4134,9 @@ public:
String *old_director_delegate_instances = director_delegate_instances; String *old_director_delegate_instances = director_delegate_instances;
String *old_director_method_types = director_method_types; String *old_director_method_types = director_method_types;
String *old_director_connect_parms = director_connect_parms; String *old_director_connect_parms = director_connect_parms;
int ret = Language::classDeclaration(n); int ret = Language::classDeclaration(n);
// these variables are deleted in emitProxyClassDefAndCPPCasts, hence no Delete here // these variables are deleted in emitProxyClassDefAndCPPCasts, hence no Delete here
director_callback_typedefs = old_director_callback_typedefs; director_callback_typedefs = old_director_callback_typedefs;
director_callbacks = old_director_callbacks; director_callbacks = old_director_callbacks;
@ -4143,6 +4145,7 @@ public:
director_delegate_instances = old_director_delegate_instances; director_delegate_instances = old_director_delegate_instances;
director_method_types = old_director_method_types; director_method_types = old_director_method_types;
director_connect_parms = old_director_connect_parms; director_connect_parms = old_director_connect_parms;
return ret; return ret;
} }

View file

@ -19,7 +19,7 @@
/* Hash type used for upcalls from C/C++ */ /* Hash type used for upcalls from C/C++ */
typedef DOH UpcallData; typedef DOH UpcallData;
// insert N tabs before each new line in s // insert N tabs before each new line in s
void Swig_offset_string(String* s, int N); void Swig_offset_string(String *s, int N);
class JAVA:public Language { class JAVA:public Language {
static const char *usage; static const char *usage;
@ -210,7 +210,7 @@ public:
String *nspace = Getattr(n, "sym:nspace"); String *nspace = Getattr(n, "sym:nspace");
String *symname = Copy(Getattr(n, "sym:name")); String *symname = Copy(Getattr(n, "sym:name"));
if (!GetFlag(n, "feature:flatnested")) { if (!GetFlag(n, "feature:flatnested")) {
for (Node* outer_class = Getattr(n, "nested:outer");outer_class;outer_class = Getattr(outer_class, "nested:outer")) { for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) {
Push(symname, "."); Push(symname, ".");
Push(symname, Getattr(outer_class, "sym:name")); Push(symname, Getattr(outer_class, "sym:name"));
} }
@ -1923,21 +1923,21 @@ public:
virtual int classHandler(Node *n) { virtual int classHandler(Node *n) {
File *f_proxy = NULL; File *f_proxy = NULL;
String* old_proxy_class_name = proxy_class_name; String *old_proxy_class_name = proxy_class_name;
String* old_full_proxy_class_name = full_proxy_class_name; String *old_full_proxy_class_name = full_proxy_class_name;
String* old_full_imclass_name = full_imclass_name; String *old_full_imclass_name = full_imclass_name;
String* old_destructor_call = destructor_call; String *old_destructor_call = destructor_call;
String* old_destructor_throws_clause = destructor_throws_clause; String *old_destructor_throws_clause = destructor_throws_clause;
String* old_proxy_class_constants_code = proxy_class_constants_code; String *old_proxy_class_constants_code = proxy_class_constants_code;
String* old_proxy_class_def = proxy_class_def; String *old_proxy_class_def = proxy_class_def;
String* old_proxy_class_code = proxy_class_code; String *old_proxy_class_code = proxy_class_code;
if (proxy_flag) { if (proxy_flag) {
proxy_class_name = NewString(Getattr(n, "sym:name")); proxy_class_name = NewString(Getattr(n, "sym:name"));
String *nspace = getNSpace(); String *nspace = getNSpace();
constructIntermediateClassName(n); constructIntermediateClassName(n);
String* outerClassesPrefix = 0; String *outerClassesPrefix = 0;
if (Node* outer = Getattr(n, "nested:outer")) { if (Node *outer = Getattr(n, "nested:outer")) {
outerClassesPrefix = Copy(Getattr(outer, "sym:name")); outerClassesPrefix = Copy(Getattr(outer, "sym:name"));
for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) {
Push(outerClassesPrefix, "."); Push(outerClassesPrefix, ".");
@ -1962,7 +1962,7 @@ public:
full_proxy_class_name = NewStringf("%s.%s.%s.%s", package, nspace, outerClassesPrefix, proxy_class_name); full_proxy_class_name = NewStringf("%s.%s.%s.%s", package, nspace, outerClassesPrefix, proxy_class_name);
else else
full_proxy_class_name = NewStringf("%s.%s.%s", nspace, outerClassesPrefix, proxy_class_name); full_proxy_class_name = NewStringf("%s.%s.%s", nspace, outerClassesPrefix, proxy_class_name);
}else { } else {
if (package) if (package)
full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name);
else else
@ -1972,7 +1972,7 @@ public:
if (outerClassesPrefix) { if (outerClassesPrefix) {
Replaceall(outerClassesPrefix, ".", "::"); Replaceall(outerClassesPrefix, ".", "::");
String* fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix; String *fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix;
if (!addSymbol(proxy_class_name, n, fnspace)) if (!addSymbol(proxy_class_name, n, fnspace))
return SWIG_ERROR; return SWIG_ERROR;
if (nspace) if (nspace)

View file

@ -20,7 +20,7 @@ static int director_mode = 0;
static int director_protected_mode = 1; static int director_protected_mode = 1;
static int all_protected_mode = 0; static int all_protected_mode = 0;
static int naturalvar_mode = 0; static int naturalvar_mode = 0;
Language* Language::this_ = 0; Language *Language::this_ = 0;
/* Set director_protected_mode */ /* Set director_protected_mode */
void Wrapper_director_mode_set(int flag) { void Wrapper_director_mode_set(int flag) {
@ -2367,7 +2367,7 @@ int Language::classDeclaration(Node *n) {
String *oldClassName = ClassName; String *oldClassName = ClassName;
String *oldDirectorClassName = DirectorClassName; String *oldDirectorClassName = DirectorClassName;
String *oldNSpace = NSpace; String *oldNSpace = NSpace;
Node* oldCurrentClass = CurrentClass; Node *oldCurrentClass = CurrentClass;
String *kind = Getattr(n, "kind"); String *kind = Getattr(n, "kind");
String *name = Getattr(n, "name"); String *name = Getattr(n, "name");
@ -2390,7 +2390,7 @@ int Language::classDeclaration(Node *n) {
return SWIG_NOWRAP; return SWIG_NOWRAP;
} }
AccessMode oldAccessMode = cplus_mode; AccessMode oldAccessMode = cplus_mode;
Node* outerClass = Getattr(n, "nested:outer"); Node *outerClass = Getattr(n, "nested:outer");
if (outerClass && oldAccessMode != Dispatcher::PUBLIC) if (outerClass && oldAccessMode != Dispatcher::PUBLIC)
return SWIG_NOWRAP; return SWIG_NOWRAP;
ClassName = Copy(name); ClassName = Copy(name);
@ -3633,12 +3633,12 @@ Hash *Language::getClassHash() const {
} }
// insert N tabs before each new line in s // insert N tabs before each new line in s
void Swig_offset_string(String* s, int N) void Swig_offset_string(String *s, int N)
{ {
// count a number of lines in s // count a number of lines in s
int lines = 1; int lines = 1;
int L = Len(s); int L = Len(s);
char* start = strchr(Char(s), '\n'); char *start = strchr(Char(s), '\n');
while (start) { while (start) {
++lines; ++lines;
start = strchr(start + 1, '\n'); start = strchr(start + 1, '\n');
@ -3647,13 +3647,13 @@ void Swig_offset_string(String* s, int N)
if ((Char(s))[L-1] == '\n') if ((Char(s))[L-1] == '\n')
--lines; --lines;
// allocate a temporary storage for a padded string // allocate a temporary storage for a padded string
char* res = (char*)malloc(L + lines * N * 2 + 1); char *res = (char*)malloc(L + lines * N * 2 + 1);
res[L + lines * N * 2] = 0; res[L + lines * N * 2] = 0;
// copy lines to res, prepending tabs to each line // copy lines to res, prepending tabs to each line
char* p = res; // output pointer char *p = res; // output pointer
start = Char(s); // start of a current line start = Char(s); // start of a current line
char* end = strchr(start, '\n'); // end of a current line char *end = strchr(start, '\n'); // end of a current line
while (end) { while (end) {
memset(p, ' ', N*2); memset(p, ' ', N*2);
p += N*2; p += N*2;

View file

@ -31,8 +31,8 @@ static Language *lang = 0; // Language method
int CPlusPlus = 0; int CPlusPlus = 0;
extern "C" extern "C"
{ {
int CPlusPlusOut = 0; // generate C++ declarations for C code int CPlusPlusOut = 0; // Generate C++ compatible code when wrapping C code
}; }
int Extend = 0; // Extend flag int Extend = 0; // Extend flag
int ForceExtern = 0; // Force extern mode int ForceExtern = 0; // Force extern mode
int GenerateDefault = 1; // Generate default constructors int GenerateDefault = 1; // Generate default constructors
@ -870,18 +870,6 @@ void Swig_flatten_nested() {
Delete(fname); Delete(fname);
Delete(name); Delete(name);
Delete(val); Delete(val);
/*
String* name = NewStringEmpty();
Hash* newname = NewHash();
Setattr(newname, "name", "$ignore");
Hash* match = NewHash();
Setattr(match, "name", "match$nested");
Setattr(match, "value", "1");
set_nextSibling(newname, match);
Swig_name_rename_add(0, name, 0, newname, 0);
Delete(name);
Delete(match);
Delete(newname);*/
} }

View file

@ -476,11 +476,10 @@ class TypePass:private Dispatcher {
if (unnamed && tdname && (Cmp(storage, "typedef") == 0)) { if (unnamed && tdname && (Cmp(storage, "typedef") == 0)) {
SwigType_typedef(unnamed, tdname); SwigType_typedef(unnamed, tdname);
} }
// name of the outer class should already be patched to contain it's outer classes names, but not to contain namespaces // name of the outer class should already be patched to contain it's outer classes names, but not to contain namespaces
// namespace name (if present) is added after processing child nodes // namespace name (if present) is added after processing child nodes
if (Getattr(n, "nested:outer") && name) { if (Getattr(n, "nested:outer") && name) {
String* outerName = Getattr(Getattr(n, "nested:outer"), "name"); String *outerName = Getattr(Getattr(n, "nested:outer"), "name");
name = NewStringf("%s::%s", outerName, name); name = NewStringf("%s::%s", outerName, name);
Setattr(n, "name", name); Setattr(n, "name", name);
if (tdname) { if (tdname) {
@ -679,7 +678,7 @@ class TypePass:private Dispatcher {
if (GetFlag(n, "conversion_operator")) { if (GetFlag(n, "conversion_operator")) {
/* The call to the operator in the generated wrapper must be fully qualified in order to compile */ /* The call to the operator in the generated wrapper must be fully qualified in order to compile */
SwigType *name = Getattr(n, "name"); SwigType *name = Getattr(n, "name");
SwigType *qualifiedname = Swig_symbol_string_qualify(name,0); SwigType *qualifiedname = Swig_symbol_string_qualify(name, 0);
Clear(name); Clear(name);
Append(name, qualifiedname); Append(name, qualifiedname);
Delete(qualifiedname); Delete(qualifiedname);
@ -1116,8 +1115,7 @@ class TypePass:private Dispatcher {
* list of overloaded methods we have just added in as child nodes to the "using" node. * list of overloaded methods we have just added in as child nodes to the "using" node.
* The node will still exist, it is just the symbol table linked list of overloaded methods * The node will still exist, it is just the symbol table linked list of overloaded methods
* which is hacked. */ * which is hacked. */
if (Getattr(n, "sym:overloaded")) if (Getattr(n, "sym:overloaded")) {
{
int cnt = 0; int cnt = 0;
#ifdef DEBUG_OVERLOADED #ifdef DEBUG_OVERLOADED
Node *debugnode = n; Node *debugnode = n;
@ -1180,7 +1178,7 @@ class TypePass:private Dispatcher {
#ifdef DEBUG_OVERLOADED #ifdef DEBUG_OVERLOADED
show_overloaded(debugnode); show_overloaded(debugnode);
#endif #endif
clean_overloaded(n); // Needed? clean_overloaded(n); // Needed?
} }
} }
} }
@ -1286,21 +1284,22 @@ void Swig_process_types(Node *n) {
} }
// Nested classes processing section // Nested classes processing section
static Hash* classhash = 0; static Hash *classhash = 0;
static String *make_name(Node *n, String *name,SwigType *decl) { static String *make_name(Node *n, String *name, SwigType *decl) {
int destructor = name && (*(Char(name)) == '~'); int destructor = name && (*(Char(name)) == '~');
if (String* yyrename = Getattr(n, "class_rename")) { if (String *yyrename = Getattr(n, "class_rename")) {
String *s = NewString(yyrename); String *s = NewString(yyrename);
Delattr(n, "class_rename"); Delattr(n, "class_rename");
if (destructor && (*(Char(s)) != '~')) { if (destructor && (*(Char(s)) != '~')) {
Insert(s,0,"~"); Insert(s, 0, "~");
} }
return s; return s;
} }
if (!name) return 0; if (!name)
return Swig_name_make(n,0,name,decl,0); return 0;
return Swig_name_make(n, 0, name, decl, 0);
} }
// C version of add_symbols() // C version of add_symbols()
@ -1308,73 +1307,74 @@ static void add_symbols_c(Node *n) {
String *decl; String *decl;
String *wrn = 0; String *wrn = 0;
String *symname = 0; String *symname = 0;
int iscdecl = Cmp(nodeType(n),"cdecl") == 0; int iscdecl = Cmp(nodeType(n), "cdecl") == 0;
Setattr(n,"ismember","1"); Setattr(n, "ismember", "1");
Setattr(n,"access", "public"); Setattr(n, "access", "public");
if (Getattr(n,"sym:name")) if (Getattr(n, "sym:name"))
return; return;
decl = Getattr(n,"decl"); decl = Getattr(n, "decl");
if (!SwigType_isfunction(decl)) { if (!SwigType_isfunction(decl)) {
String *name = Getattr(n,"name"); String *name = Getattr(n, "name");
String *makename = Getattr(n,"parser:makename"); String *makename = Getattr(n, "parser:makename");
if (iscdecl) { if (iscdecl) {
String *storage = Getattr(n, "storage"); String *storage = Getattr(n, "storage");
if (Cmp(storage,"typedef") == 0) { if (Cmp(storage, "typedef") == 0) {
Setattr(n,"kind","typedef"); Setattr(n, "kind", "typedef");
} else { } else {
SwigType *type = Getattr(n,"type"); SwigType *type = Getattr(n, "type");
String *value = Getattr(n,"value"); String *value = Getattr(n, "value");
Setattr(n,"kind","variable"); Setattr(n, "kind", "variable");
if (value && Len(value)) { if (value && Len(value)) {
Setattr(n,"hasvalue","1"); Setattr(n, "hasvalue", "1");
} }
if (type) { if (type) {
SwigType *ty; SwigType *ty;
SwigType *tmp = 0; SwigType *tmp = 0;
if (decl) { if (decl) {
ty = tmp = Copy(type); ty = tmp = Copy(type);
SwigType_push(ty,decl); SwigType_push(ty, decl);
} else { } else {
ty = type; ty = type;
} }
if (!SwigType_ismutable(ty)) { if (!SwigType_ismutable(ty)) {
SetFlag(n,"hasconsttype"); SetFlag(n, "hasconsttype");
SetFlag(n,"feature:immutable"); SetFlag(n, "feature:immutable");
} }
if (tmp) Delete(tmp); if (tmp)
Delete(tmp);
} }
if (!type) { if (!type) {
Printf(stderr,"notype name %s\n", name); Printf(stderr, "notype name %s\n", name);
} }
} }
} }
Swig_features_get(Swig_cparse_features(), 0, name, 0, n); Swig_features_get(Swig_cparse_features(), 0, name, 0, n);
if (makename) { if (makename) {
symname = make_name(n, makename, 0); symname = make_name(n, makename, 0);
Delattr(n,"parser:makename"); /* temporary information, don't leave it hanging around */ Delattr(n, "parser:makename"); /* temporary information, don't leave it hanging around */
} else { } else {
makename = name; makename = name;
symname = make_name(n, makename, 0); symname = make_name(n, makename, 0);
} }
if (!symname) { if (!symname) {
symname = Copy(Getattr(n,"unnamed")); symname = Copy(Getattr(n, "unnamed"));
} }
if (symname) { if (symname) {
wrn = Swig_name_warning(n, 0, symname,0); wrn = Swig_name_warning(n, 0, symname, 0);
} }
} else { } else {
String *name = Getattr(n,"name"); String *name = Getattr(n, "name");
SwigType *fdecl = Copy(decl); SwigType *fdecl = Copy(decl);
SwigType *fun = SwigType_pop_function(fdecl); SwigType *fun = SwigType_pop_function(fdecl);
if (iscdecl) { if (iscdecl) {
Setattr(n,"kind","function"); Setattr(n, "kind", "function");
} }
Swig_features_get(Swig_cparse_features(),0,name,fun,n); Swig_features_get(Swig_cparse_features(), 0, name, fun, n);
symname = make_name(n, name, fun); symname = make_name(n, name, fun);
wrn = Swig_name_warning(n, 0, symname,fun); wrn = Swig_name_warning(n, 0, symname, fun);
Delete(fdecl); Delete(fdecl);
Delete(fun); Delete(fun);
@ -1382,15 +1382,15 @@ static void add_symbols_c(Node *n) {
} }
if (!symname) if (!symname)
return; return;
if (GetFlag(n,"feature:ignore")) { if (GetFlag(n, "feature:ignore")) {
/* Only add to C symbol table and continue */ /* Only add to C symbol table and continue */
Swig_symbol_add(0, n); Swig_symbol_add(0, n);
} else if (strncmp(Char(symname),"$ignore",7) == 0) { } else if (strncmp(Char(symname), "$ignore", 7) == 0) {
char *c = Char(symname)+7; char *c = Char(symname) + 7;
SetFlag(n,"feature:ignore"); SetFlag(n, "feature:ignore");
if (strlen(c)) { if (strlen(c)) {
SWIG_WARN_NODE_BEGIN(n); SWIG_WARN_NODE_BEGIN(n);
Swig_warning(0,Getfile(n), Getline(n), "%s\n",c+1); Swig_warning(0, Getfile(n), Getline(n), "%s\n", c + 1);
SWIG_WARN_NODE_END(n); SWIG_WARN_NODE_END(n);
} }
Swig_symbol_add(0, n); Swig_symbol_add(0, n);
@ -1398,51 +1398,50 @@ static void add_symbols_c(Node *n) {
Node *c; Node *c;
if ((wrn) && (Len(wrn))) { if ((wrn) && (Len(wrn))) {
String *metaname = symname; String *metaname = symname;
if (!Getmeta(metaname,"already_warned")) { if (!Getmeta(metaname, "already_warned")) {
SWIG_WARN_NODE_BEGIN(n); SWIG_WARN_NODE_BEGIN(n);
Swig_warning(0,Getfile(n),Getline(n), "%s\n", wrn); Swig_warning(0, Getfile(n), Getline(n), "%s\n", wrn);
SWIG_WARN_NODE_END(n); SWIG_WARN_NODE_END(n);
Setmeta(metaname,"already_warned","1"); Setmeta(metaname, "already_warned", "1");
} }
} }
c = Swig_symbol_add(symname,n); c = Swig_symbol_add(symname, n);
if (c != n) { if (c != n) {
/* symbol conflict attempting to add in the new symbol */ /* symbol conflict attempting to add in the new symbol */
if (Getattr(n,"sym:weak")) { if (Getattr(n, "sym:weak")) {
Setattr(n,"sym:name",symname); Setattr(n, "sym:name", symname);
} else { } else {
String *e = NewStringEmpty(); String *e = NewStringEmpty();
String *en = NewStringEmpty(); String *en = NewStringEmpty();
String *ec = NewStringEmpty(); String *ec = NewStringEmpty();
int redefined = Swig_need_redefined_warn(n,c,true); int redefined = Swig_need_redefined_warn(n, c, true);
if (redefined) { if (redefined) {
Printf(en,"Identifier '%s' redefined (ignored)",symname); Printf(en, "Identifier '%s' redefined (ignored)", symname);
Printf(ec,"previous definition of '%s'",symname); Printf(ec, "previous definition of '%s'", symname);
} else { } else {
Printf(en,"Redundant redeclaration of '%s'",symname); Printf(en, "Redundant redeclaration of '%s'", symname);
Printf(ec,"previous declaration of '%s'",symname); Printf(ec, "previous declaration of '%s'", symname);
} }
if (Cmp(symname,Getattr(n,"name"))) { if (Cmp(symname, Getattr(n, "name"))) {
Printf(en," (Renamed from '%s')", SwigType_namestr(Getattr(n,"name"))); Printf(en, " (Renamed from '%s')", SwigType_namestr(Getattr(n, "name")));
} }
Printf(en,","); Printf(en, ",");
if (Cmp(symname,Getattr(c,"name"))) { if (Cmp(symname, Getattr(c, "name"))) {
Printf(ec," (Renamed from '%s')", SwigType_namestr(Getattr(c,"name"))); Printf(ec, " (Renamed from '%s')", SwigType_namestr(Getattr(c, "name")));
} }
Printf(ec,"."); Printf(ec, ".");
SWIG_WARN_NODE_BEGIN(n); SWIG_WARN_NODE_BEGIN(n);
if (redefined) { if (redefined) {
Swig_warning(WARN_PARSE_REDEFINED,Getfile(n),Getline(n),"%s\n",en); Swig_warning(WARN_PARSE_REDEFINED, Getfile(n), Getline(n), "%s\n", en);
Swig_warning(WARN_PARSE_REDEFINED,Getfile(c),Getline(c),"%s\n",ec); Swig_warning(WARN_PARSE_REDEFINED, Getfile(c), Getline(c), "%s\n", ec);
} else { } else {
Swig_warning(WARN_PARSE_REDUNDANT,Getfile(n),Getline(n),"%s\n",en); Swig_warning(WARN_PARSE_REDUNDANT, Getfile(n), Getline(n), "%s\n", en);
Swig_warning(WARN_PARSE_REDUNDANT,Getfile(c),Getline(c),"%s\n",ec); Swig_warning(WARN_PARSE_REDUNDANT, Getfile(c), Getline(c), "%s\n", ec);
} }
SWIG_WARN_NODE_END(n); SWIG_WARN_NODE_END(n);
Printf(e,"%s:%d:%s\n%s:%d:%s\n",Getfile(n),Getline(n),en, Printf(e, "%s:%d:%s\n%s:%d:%s\n", Getfile(n), Getline(n), en, Getfile(c), Getline(c), ec);
Getfile(c),Getline(c),ec); Setattr(n, "error", e);
Setattr(n,"error",e);
Delete(e); Delete(e);
Delete(en); Delete(en);
Delete(ec); Delete(ec);
@ -1454,58 +1453,59 @@ static void add_symbols_c(Node *n) {
/* Strips C-style and C++-style comments from string in-place. */ /* Strips C-style and C++-style comments from string in-place. */
static void strip_comments(char *string) { static void strip_comments(char *string) {
int state = 0; /* int state = 0;
* 0 - not in comment /*
* 1 - in c-style comment * 0 - not in comment
* 2 - in c++-style comment * 1 - in c-style comment
* 3 - in string * 2 - in c++-style comment
* 4 - after reading / not in comments * 3 - in string
* 5 - after reading * in c-style comments * 4 - after reading / not in comments
* 6 - after reading \ in strings * 5 - after reading * in c-style comments
*/ * 6 - after reading \ in strings
char * c = string; */
char *c = string;
while (*c) { while (*c) {
switch (state) { switch (state) {
case 0: case 0:
if (*c == '\"') if (*c == '\"')
state = 3; state = 3;
else if (*c == '/') else if (*c == '/')
state = 4; state = 4;
break; break;
case 1: case 1:
if (*c == '*') if (*c == '*')
state = 5; state = 5;
*c = ' '; *c = ' ';
break; break;
case 2: case 2:
if (*c == '\n') if (*c == '\n')
state = 0; state = 0;
else else
*c = ' '; *c = ' ';
break; break;
case 3: case 3:
if (*c == '\"') if (*c == '\"')
state = 0; state = 0;
else if (*c == '\\') else if (*c == '\\')
state = 6; state = 6;
break; break;
case 4: case 4:
if (*c == '/') { if (*c == '/') {
*(c-1) = ' '; *(c - 1) = ' ';
*c = ' '; *c = ' ';
state = 2; state = 2;
} else if (*c == '*') { } else if (*c == '*') {
*(c-1) = ' '; *(c - 1) = ' ';
*c = ' '; *c = ' ';
state = 1; state = 1;
} else } else
state = 0; state = 0;
break; break;
case 5: case 5:
if (*c == '/') if (*c == '/')
state = 0; state = 0;
else else
state = 1; state = 1;
*c = ' '; *c = ' ';
break; break;
case 6: case 6:
@ -1516,11 +1516,10 @@ static void strip_comments(char *string) {
} }
} }
// Create an %insert with a typedef to make a new name visible to C // Create a %insert with a typedef to make a new name visible to C
// the code is moved from parser.y, dump_nested() function with minor changes static Node *create_insert(Node *n, bool noTypedef = false) {
static Node* create_insert(Node* n, bool noTypedef = false) {
// format a typedef // format a typedef
String* ccode = Getattr(n, "code"); String *ccode = Getattr(n, "code");
Push(ccode, " "); Push(ccode, " ");
if (noTypedef) { if (noTypedef) {
Push(ccode, Getattr(n, "name")); Push(ccode, Getattr(n, "name"));
@ -1534,19 +1533,18 @@ static Node* create_insert(Node* n, bool noTypedef = false) {
} }
Append(ccode, ";"); Append(ccode, ";");
/* Strip comments - further code may break in presence of comments. */ /* Strip comments - further code may break in presence of comments. */
strip_comments(Char(ccode)); strip_comments(Char(ccode));
/* Make all SWIG created typedef structs/unions/classes unnamed else /* Make all SWIG created typedef structs/unions/classes unnamed else
redefinition errors occur - nasty hack alert.*/ redefinition errors occur - nasty hack alert. */
if (!noTypedef) { if (!noTypedef) {
const char* types_array[3] = {"struct", "union", "class"}; const char *types_array[3] = { "struct", "union", "class" };
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
char* code_ptr = Char(ccode); char *code_ptr = Char(ccode);
while (code_ptr) { while (code_ptr) {
/* Replace struct name (as in 'struct name {...}' ) with whitespace /* Replace struct name (as in 'struct name {...}' ) with whitespace
name will be between struct and opening brace */ name will be between struct and opening brace */
code_ptr = strstr(code_ptr, types_array[i]); code_ptr = strstr(code_ptr, types_array[i]);
if (code_ptr) { if (code_ptr) {
@ -1555,7 +1553,7 @@ static Node* create_insert(Node* n, bool noTypedef = false) {
open_bracket_pos = strchr(code_ptr, '{'); open_bracket_pos = strchr(code_ptr, '{');
if (open_bracket_pos) { if (open_bracket_pos) {
/* Make sure we don't have something like struct A a; */ /* Make sure we don't have something like struct A a; */
char* semi_colon_pos = strchr(code_ptr, ';'); char *semi_colon_pos = strchr(code_ptr, ';');
if (!(semi_colon_pos && (semi_colon_pos < open_bracket_pos))) if (!(semi_colon_pos && (semi_colon_pos < open_bracket_pos)))
while (code_ptr < open_bracket_pos) while (code_ptr < open_bracket_pos)
*code_ptr++ = ' '; *code_ptr++ = ' ';
@ -1566,11 +1564,11 @@ static Node* create_insert(Node* n, bool noTypedef = false) {
} }
{ {
/* Remove SWIG directive %constant which may be left in the SWIG created typedefs */ /* Remove SWIG directive %constant which may be left in the SWIG created typedefs */
char* code_ptr = Char(ccode); char *code_ptr = Char(ccode);
while (code_ptr) { while (code_ptr) {
code_ptr = strstr(code_ptr, "%constant"); code_ptr = strstr(code_ptr, "%constant");
if (code_ptr) { if (code_ptr) {
char* directive_end_pos = strchr(code_ptr, ';'); char *directive_end_pos = strchr(code_ptr, ';');
if (directive_end_pos) { if (directive_end_pos) {
while (code_ptr <= directive_end_pos) while (code_ptr <= directive_end_pos)
*code_ptr++ = ' '; *code_ptr++ = ' ';
@ -1578,10 +1576,10 @@ static Node* create_insert(Node* n, bool noTypedef = false) {
} }
} }
} }
Node *newnode = NewHash(); Node *newnode = NewHash();
set_nodeType(newnode ,"insert"); set_nodeType(newnode, "insert");
Setfile(newnode ,Getfile(n)); Setfile(newnode, Getfile(n));
Setline(newnode ,Getline(n)); Setline(newnode, Getline(n));
String *code = NewStringEmpty(); String *code = NewStringEmpty();
Wrapper_pretty_print(ccode, code); Wrapper_pretty_print(ccode, code);
Setattr(newnode, "code", code); Setattr(newnode, "code", code);
@ -1590,12 +1588,11 @@ static Node* create_insert(Node* n, bool noTypedef = false) {
return newnode; return newnode;
} }
static void insertNodeAfter(Node *n, Node* c) static void insertNodeAfter(Node *n, Node *c) {
{ Node *g = parentNode(n);
Node* g = parentNode(n);
set_parentNode(c, g); set_parentNode(c, g);
Node* ns = nextSibling(n); Node *ns = nextSibling(n);
if (Node* outer = Getattr(c, "nested:outer")) { if (Node *outer = Getattr(c, "nested:outer")) {
while (ns && outer == Getattr(ns, "nested:outer")) { while (ns && outer == Getattr(ns, "nested:outer")) {
n = ns; n = ns;
ns = nextSibling(n); ns = nextSibling(n);
@ -1603,8 +1600,7 @@ static void insertNodeAfter(Node *n, Node* c)
} }
if (!ns) { if (!ns) {
set_lastChild(g, c); set_lastChild(g, c);
} } else {
else {
set_nextSibling(c, ns); set_nextSibling(c, ns);
set_previousSibling(ns, c); set_previousSibling(ns, c);
} }
@ -1615,36 +1611,36 @@ static void insertNodeAfter(Node *n, Node* c)
void Swig_name_unnamed_c_structs(Node *n) { void Swig_name_unnamed_c_structs(Node *n) {
if (!classhash) if (!classhash)
classhash = Getattr(n, "classes"); classhash = Getattr(n, "classes");
Node* c = firstChild(n); Node *c = firstChild(n);
while (c) { while (c) {
Node* next = nextSibling(c); Node *next = nextSibling(c);
if (String* declName = Getattr(c, "nested:unnamed")) { if (String *declName = Getattr(c, "nested:unnamed")) {
if (Node* outer = Getattr(c, "nested:outer")) { if (Node *outer = Getattr(c, "nested:outer")) {
// generate a name // generate a name
String* name = NewStringf("%s_%s", Getattr(outer, "name"), declName); String *name = NewStringf("%s_%s", Getattr(outer, "name"), declName);
Delattr(c, "nested:unnamed"); Delattr(c, "nested:unnamed");
// set the name to the class and symbol table // set the name to the class and symbol table
Setattr(c, "tdname", name); Setattr(c, "tdname", name);
Setattr(c, "name", name); Setattr(c, "name", name);
Swig_symbol_setscope(Getattr(c,"symtab")); Swig_symbol_setscope(Getattr(c, "symtab"));
Swig_symbol_setscopename(name); Swig_symbol_setscopename(name);
// now that we have a name - gather base symbols // now that we have a name - gather base symbols
if (List* publicBases = Getattr(c,"baselist")) { if (List *publicBases = Getattr(c, "baselist")) {
List* bases = Swig_make_inherit_list(name, publicBases, 0); List *bases = Swig_make_inherit_list(name, publicBases, 0);
Swig_inherit_base_symbols(bases); Swig_inherit_base_symbols(bases);
Delete(bases); Delete(bases);
} }
Setattr(classhash,name,c); Setattr(classhash, name, c);
Swig_symbol_popscope(); Swig_symbol_popscope();
// process declarations following this type (assign correct new type) // process declarations following this type (assign correct new type)
SwigType* ty = Copy(name); SwigType *ty = Copy(name);
Node* decl = nextSibling(c); Node *decl = nextSibling(c);
List* declList = NewList(); List *declList = NewList();
while (decl && Getattr(decl, "nested:unnamedtype") == c) { while (decl && Getattr(decl, "nested:unnamedtype") == c) {
Setattr(decl, "type", ty); Setattr(decl, "type", ty);
Append(declList, decl); Append(declList, decl);
Delattr(decl, "nested:unnamedtype"); Delattr(decl, "nested:unnamedtype");
SetFlag(decl, "feature:immutable"); SetFlag(decl, "feature:immutable");
add_symbols_c(decl); add_symbols_c(decl);
decl = nextSibling(decl); decl = nextSibling(decl);
} }
@ -1662,20 +1658,20 @@ void Swig_name_unnamed_c_structs(Node *n) {
Swig_symbol_setscope(Swig_symbol_global_scope()); Swig_symbol_setscope(Swig_symbol_global_scope());
add_symbols_c(c); add_symbols_c(c);
Node* ins = create_insert(c); Node *ins = create_insert(c);
insertNodeAfter(c, ins); insertNodeAfter(c, ins);
removeNode(c); removeNode(c);
insertNodeAfter(n, c); insertNodeAfter(n, c);
Delete(ins); Delete(ins);
Delattr(c, "nested:outer"); Delattr(c, "nested:outer");
}else { } else {
// global unnamed struct - ignore it // global unnamed struct - ignore it
c = next; c = next;
continue; continue;
} }
} else if (CPlusPlusOut) { } else if (CPlusPlusOut) {
if (Getattr(c, "nested:outer")) { if (Getattr(c, "nested:outer")) {
Node* ins = create_insert(c, true); Node *ins = create_insert(c, true);
insertNodeAfter(c, ins); insertNodeAfter(c, ins);
Delete(ins); Delete(ins);
Delattr(c, "nested:outer"); Delattr(c, "nested:outer");
@ -1686,23 +1682,24 @@ void Swig_name_unnamed_c_structs(Node *n) {
c = next; c = next;
} }
} }
static void remove_outer_class_reference(Node *n)
{ static void remove_outer_class_reference(Node *n) {
for (Node* c = firstChild(n); c; c = nextSibling(c)) { for (Node *c = firstChild(n); c; c = nextSibling(c)) {
if (GetFlag(c, "feature:flatnested")) { if (GetFlag(c, "feature:flatnested")) {
Delattr(c, "nested:outer"); Delattr(c, "nested:outer");
remove_outer_class_reference(c); remove_outer_class_reference(c);
} }
} }
} }
void Swig_process_nested_classes(Node *n) { void Swig_process_nested_classes(Node *n) {
Node* c = firstChild(n); Node *c = firstChild(n);
while (c) { while (c) {
Node* next = nextSibling(c); Node *next = nextSibling(c);
if (!Getattr(c,"templatetype")) { if (!Getattr(c, "templatetype")) {
if (GetFlag(c, "nested") && GetFlag(c, "feature:flatnested")) { if (GetFlag(c, "nested") && GetFlag(c, "feature:flatnested")) {
removeNode(c); removeNode(c);
if (!checkAttribute(c, "access", "public")) if (!checkAttribute(c, "access", "public"))
SetFlag(c, "feature:ignore"); SetFlag(c, "feature:ignore");
else else
insertNodeAfter(n, c); insertNodeAfter(n, c);

View file

@ -1648,14 +1648,18 @@ void Swig_name_inherit(String *base, String *derived) {
Swig_name_object_inherit(Swig_cparse_features(), base, derived); Swig_name_object_inherit(Swig_cparse_features(), base, derived);
} }
void Swig_inherit_base_symbols(List* bases) { /* -----------------------------------------------------------------------------
* Swig_inherit_base_symbols()
* ----------------------------------------------------------------------------- */
void Swig_inherit_base_symbols(List *bases) {
if (bases) { if (bases) {
Iterator s; Iterator s;
for (s = First(bases); s.item; s = Next(s)) { for (s = First(bases); s.item; s = Next(s)) {
Symtab *st = Getattr(s.item,"symtab"); Symtab *st = Getattr(s.item, "symtab");
if (st) { if (st) {
Setfile(st,Getfile(s.item)); Setfile(st, Getfile(s.item));
Setline(st,Getline(s.item)); Setline(st, Getline(s.item));
Swig_symbol_inherit(st); Swig_symbol_inherit(st);
} }
} }
@ -1663,40 +1667,46 @@ void Swig_inherit_base_symbols(List* bases) {
} }
} }
List *Swig_make_inherit_list(String *clsname, List *names, String* Namespaceprefix) { /* -----------------------------------------------------------------------------
* Swig_make_inherit_list()
* ----------------------------------------------------------------------------- */
List *Swig_make_inherit_list(String *clsname, List *names, String *Namespaceprefix) {
int i, ilen; int i, ilen;
String *derived; String *derived;
List *bases = NewList(); List *bases = NewList();
if (Namespaceprefix) derived = NewStringf("%s::%s", Namespaceprefix,clsname); if (Namespaceprefix)
else derived = NewString(clsname); derived = NewStringf("%s::%s", Namespaceprefix, clsname);
else
derived = NewString(clsname);
ilen = Len(names); ilen = Len(names);
for (i = 0; i < ilen; i++) { for (i = 0; i < ilen; i++) {
Node *s; Node *s;
String *base; String *base;
String *n = Getitem(names,i); String *n = Getitem(names, i);
/* Try to figure out where this symbol is */ /* Try to figure out where this symbol is */
s = Swig_symbol_clookup(n,0); s = Swig_symbol_clookup(n,0);
if (s) { if (s) {
while (s && (Strcmp(nodeType(s),"class") != 0)) { while (s && (Strcmp(nodeType(s), "class") != 0)) {
/* Not a class. Could be a typedef though. */ /* Not a class. Could be a typedef though. */
String *storage = Getattr(s,"storage"); String *storage = Getattr(s, "storage");
if (storage && (Strcmp(storage,"typedef") == 0)) { if (storage && (Strcmp(storage, "typedef") == 0)) {
String *nn = Getattr(s,"type"); String *nn = Getattr(s, "type");
s = Swig_symbol_clookup(nn,Getattr(s,"sym:symtab")); s = Swig_symbol_clookup(nn, Getattr(s, "sym:symtab"));
} else { } else {
break; break;
} }
} }
if (s && ((Strcmp(nodeType(s),"class") == 0) || (Strcmp(nodeType(s),"template") == 0))) { if (s && ((Strcmp(nodeType(s), "class") == 0) || (Strcmp(nodeType(s), "template") == 0))) {
String *q = Swig_symbol_qualified(s); String *q = Swig_symbol_qualified(s);
Append(bases,s); Append(bases, s);
if (q) { if (q) {
base = NewStringf("%s::%s", q, Getattr(s,"name")); base = NewStringf("%s::%s", q, Getattr(s, "name"));
Delete(q); Delete(q);
} else { } else {
base = NewString(Getattr(s,"name")); base = NewString(Getattr(s, "name"));
} }
} else { } else {
base = NewString(n); base = NewString(n);
@ -1705,7 +1715,7 @@ List *Swig_make_inherit_list(String *clsname, List *names, String* Namespacepref
base = NewString(n); base = NewString(n);
} }
if (base) { if (base) {
Swig_name_inherit(base,derived); Swig_name_inherit(base, derived);
Delete(base); Delete(base);
} }
} }

View file

@ -1545,13 +1545,18 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) {
Delete(locator); Delete(locator);
return 0; return 0;
} }
/* 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) /* -----------------------------------------------------------------------------
{ * Scanner_get_raw_text_balanced()
String* result = 0; *
* 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; char c;
int old_line = s->line; int old_line = s->line;
String* old_text = Copy(s->text); String *old_text = Copy(s->text);
int position = Tell(s->str); int position = Tell(s->str);
int num_levels = 1; int num_levels = 1;

View file

@ -286,8 +286,8 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl); 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_rename_add(String *prefix, String *name, SwigType *decl, Hash *namewrn, ParmList *declaratorparms);
extern void Swig_name_inherit(String *base, String *derived); extern void Swig_name_inherit(String *base, String *derived);
extern List *Swig_make_inherit_list(String *clsname, List *names, String* Namespaceprefix); extern List *Swig_make_inherit_list(String *clsname, List *names, String *Namespaceprefix);
extern void Swig_inherit_base_symbols(List* bases); extern void Swig_inherit_base_symbols(List *bases);
extern int Swig_need_protected(Node *n); extern int Swig_need_protected(Node *n);
extern int Swig_need_name_warning(Node *n); extern int Swig_need_name_warning(Node *n);
extern int Swig_need_redefined_warn(Node *a, Node *b, int InClass); extern int Swig_need_redefined_warn(Node *a, Node *b, int InClass);

View file

@ -171,11 +171,10 @@ void prependChild(Node *node, Node *chd) {
} }
} }
void appendSibling(Node *node, Node *chd) void appendSibling(Node *node, Node *chd) {
{
Node *parent; Node *parent;
Node* lc = node; Node *lc = node;
while(nextSibling(lc)) while (nextSibling(lc))
lc = nextSibling(lc); lc = nextSibling(lc);
set_nextSibling(lc, chd); set_nextSibling(lc, chd);
set_previousSibling(chd, lc); set_previousSibling(chd, lc);