added forward declaration instead of ignored nested class (resurrected old code)
This commit is contained in:
parent
69d849b56c
commit
4744ea8903
2 changed files with 91 additions and 35 deletions
|
|
@ -1069,6 +1069,71 @@ static void update_nested_classes(Node *n)
|
|||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* nested_forward_declaration()
|
||||
*
|
||||
* Nested struct handling for C++ code if the nested classes are diasbled.
|
||||
* Create the nested class/struct/union as a forward declaration.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, String *name, Node *cpp_opt_declarators) {
|
||||
Node *nn = 0;
|
||||
int warned = 0;
|
||||
|
||||
if (sname) {
|
||||
/* Add forward declaration of the nested type */
|
||||
Node *n = new_node("classforward");
|
||||
Setattr(n, "kind", kind);
|
||||
Setattr(n, "name", sname);
|
||||
Setattr(n, "storage", storage);
|
||||
Setattr(n, "sym:weak", "1");
|
||||
add_symbols(n);
|
||||
nn = n;
|
||||
}
|
||||
|
||||
/* Add any variable instances. Also add in any further typedefs of the nested type.
|
||||
Note that anonymous typedefs (eg typedef struct {...} a, b;) are treated as class forward declarations */
|
||||
if (cpp_opt_declarators) {
|
||||
int storage_typedef = (storage && (strcmp(storage, "typedef") == 0));
|
||||
int variable_of_anonymous_type = !sname && !storage_typedef;
|
||||
if (!variable_of_anonymous_type) {
|
||||
int anonymous_typedef = !sname && (storage && (strcmp(storage, "typedef") == 0));
|
||||
Node *n = cpp_opt_declarators;
|
||||
SwigType *type = name;
|
||||
while (n) {
|
||||
Setattr(n, "type", type);
|
||||
Setattr(n, "storage", storage);
|
||||
if (anonymous_typedef) {
|
||||
Setattr(n, "nodeType", "classforward");
|
||||
Setattr(n, "sym:weak", "1");
|
||||
}
|
||||
n = nextSibling(n);
|
||||
}
|
||||
add_symbols(cpp_opt_declarators);
|
||||
|
||||
if (nn) {
|
||||
set_nextSibling(nn, cpp_opt_declarators);
|
||||
} else {
|
||||
nn = cpp_opt_declarators;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nn && Equal(nodeType(nn), "classforward")) {
|
||||
Node *n = nn;
|
||||
SWIG_WARN_NODE_BEGIN(n);
|
||||
Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", kind, sname ? sname : name);
|
||||
SWIG_WARN_NODE_END(n);
|
||||
warned = 1;
|
||||
}
|
||||
|
||||
if (!warned)
|
||||
Swig_warning(WARN_PARSE_UNNAMED_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", kind);
|
||||
|
||||
return nn;
|
||||
}
|
||||
|
||||
|
||||
Node *Swig_cparse(File *f) {
|
||||
scanner_file(f);
|
||||
top = 0;
|
||||
|
|
@ -3553,8 +3618,13 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
|||
Setattr($$, "symtab", Swig_symbol_popscope());
|
||||
Classprefix = Getattr($<node>$, "Classprefix");
|
||||
Delattr($<node>$, "Classprefix");
|
||||
Delete(Namespaceprefix);
|
||||
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||
Swig_features_get(Swig_cparse_features(), Namespaceprefix, Getattr($$, "name"), 0, $$);
|
||||
if (cplus_mode == CPLUS_PRIVATE) {
|
||||
$$ = 0; /* skip private nested classes */
|
||||
} else if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) {
|
||||
$$ = nested_forward_declaration($1, $2, $3, Copy($3), $9);
|
||||
} else if (nscope_inner) {
|
||||
/* this is tricky */
|
||||
/* we add the declaration in the original namespace */
|
||||
|
|
@ -3564,31 +3634,23 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
|||
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||
yyrename = Copy(Getattr($<node>$, "class_rename"));
|
||||
add_symbols($$);
|
||||
if (currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) {
|
||||
SetFlag($$,"feature:ignore");
|
||||
Swig_warning(WARN_PARSE_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", Getattr($$, "name"));
|
||||
$$ = 0;
|
||||
} else {
|
||||
Delattr($$, "class_rename");
|
||||
/* but the variable definition in the current scope */
|
||||
Swig_symbol_setscope(cscope);
|
||||
Delete(Namespaceprefix);
|
||||
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||
add_symbols($9);
|
||||
if (nscope) {
|
||||
$$ = nscope; /* here we return recreated namespace tower instead of the class itself */
|
||||
if ($9) {
|
||||
appendSibling($$, $9);
|
||||
}
|
||||
} else if (!SwigType_istemplate(ty) && template_parameters == 0) { /* for tempalte we need the class itself */
|
||||
$$ = $9;
|
||||
Delattr($$, "class_rename");
|
||||
/* but the variable definition in the current scope */
|
||||
Swig_symbol_setscope(cscope);
|
||||
Delete(Namespaceprefix);
|
||||
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||
add_symbols($9);
|
||||
if (nscope) {
|
||||
$$ = nscope; /* here we return recreated namespace tower instead of the class itself */
|
||||
if ($9) {
|
||||
appendSibling($$, $9);
|
||||
}
|
||||
} else if (!SwigType_istemplate(ty) && template_parameters == 0) { /* for tempalte we need the class itself */
|
||||
$$ = $9;
|
||||
}
|
||||
} else {
|
||||
Delete(yyrename);
|
||||
yyrename = 0;
|
||||
Delete(Namespaceprefix);
|
||||
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||
if (!cparse_cplusplus && currentOuterClass) { /* nested C structs go into global scope*/
|
||||
Node *outer = currentOuterClass;
|
||||
while (Getattr(outer, "nested:outer"))
|
||||
|
|
@ -3607,14 +3669,8 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
|||
} else {
|
||||
yyrename = Copy(Getattr($<node>$, "class_rename"));
|
||||
add_symbols($$);
|
||||
if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) {
|
||||
SetFlag($$,"feature:ignore");
|
||||
Swig_warning(WARN_PARSE_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", Getattr($$, "name"));
|
||||
$$ = 0;
|
||||
} else {
|
||||
add_symbols($9);
|
||||
Delattr($$, "class_rename");
|
||||
}
|
||||
add_symbols($9);
|
||||
Delattr($$, "class_rename");
|
||||
}
|
||||
}
|
||||
Delete(ty);
|
||||
|
|
@ -3678,7 +3734,11 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
|||
/* Check for pure-abstract class */
|
||||
Setattr($$,"abstracts", pure_abstracts($6));
|
||||
n = $8;
|
||||
if (n) {
|
||||
Swig_features_get(Swig_cparse_features(), Namespaceprefix, 0, 0, $$);
|
||||
if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) {
|
||||
String *name = n ? Copy(Getattr(n, "name")) : 0;
|
||||
$$ = nested_forward_declaration($1, $2, 0, name, n);
|
||||
} else if (n) {
|
||||
appendSibling($$,n);
|
||||
/* If a proper typedef name was given, we'll use it to set the scope name */
|
||||
name = try_to_find_a_name_for_unnamed_structure($1, n);
|
||||
|
|
@ -3747,11 +3807,6 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
|||
add_symbols($$);
|
||||
add_symbols(n);
|
||||
Delattr($$, "class_rename");
|
||||
if (cparse_cplusplus && currentOuterClass && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) {
|
||||
SetFlag($$,"feature:ignore");
|
||||
Swig_warning(WARN_PARSE_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", name);
|
||||
$$ = 0;
|
||||
}
|
||||
}else if (cparse_cplusplus)
|
||||
$$ = 0; /* ignore unnamed structs for C++ */
|
||||
Delete(unnamed);
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
#define WARN_PARSE_PRIVATE_INHERIT 309
|
||||
#define WARN_PARSE_TEMPLATE_REPEAT 310
|
||||
#define WARN_PARSE_TEMPLATE_PARTIAL 311
|
||||
#define WARN_PARSE_NESTED_CLASS 312
|
||||
#define WARN_PARSE_UNNAMED_NESTED_CLASS 312
|
||||
#define WARN_PARSE_UNDEFINED_EXTERN 313
|
||||
#define WARN_PARSE_KEYWORD 314
|
||||
#define WARN_PARSE_USING_UNDEF 315
|
||||
|
|
@ -89,6 +89,7 @@
|
|||
#define WARN_PARSE_REDUNDANT 322
|
||||
#define WARN_PARSE_REC_INHERITANCE 323
|
||||
#define WARN_PARSE_NESTED_TEMPLATE 324
|
||||
#define WARN_PARSE_NAMED_NESTED_CLASS 325
|
||||
#define WARN_PARSE_EXTEND_NAME 326
|
||||
|
||||
#define WARN_CPP11_LAMBDA 340
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue