Nested classes support
Closes #89 Squash merge branch 'master' of https://github.com/wkalinin/swig into wkalinin-nested By Vladimir Kalinin * 'master' of https://github.com/wkalinin/swig: CPlusPlusOut mode for Octave nested class illustration fixed "Abstract" flag for nested classes added an example enabled anonymous nested structs runtime test porting warnings disabled porting fixes java runtime tests ported nested class closing bracket offset fixed removed double nested template (not supported by %template parsing) template_nested test extended parent field made public property access fixed replaced tabs with spaces warning W-reorder deprecated warnings removed, derived_nested runtime test added optimized string indenting Nested classes indenting nested classes docs fixed the order in which flattened inner classes are added after the outer Private nested classes were getting into the type table. Java getProxyName() fix for nested classes fixes the case when nested classes is forward declared Fix for a case when a nested class inherits from the same base as the outer. (Base class constructor declaration is found first in this case) merge fix nested C struct first immediate declaration incorrectly renamed sample fixed tests updated to reflect nested classes support Java nested classes support (1) flattening should remove the link to the outer class access mode correctly set/restored for nested classes nested templates should be skipped while flattening (template nodes themselves, not expanded versions) also non-public nested classes should be ignored If nested classes are not supported, default behaviour is flattening, not ignoring flag "nested" is preserved, so, the nested classes can be ignored by user nested workaround test updated template instantiated within a class is marked as nested for ignoring purposes %ignore not applied to the nested classed, because "nested" flag is set too late typedef name takes precedence over the real name (reason?) unnamed structs should be processed for all the languages nested C struct instances are wrapped as "immutable" tree building typedef declaration for unnamed C structures fixed nested classes "flattening" fixed %ignoring nested classes renamed "nested" attribute to "nested:outer" added "nested" flag, to be used with $ignore (it is not removed while flattening) added nestedClassesSupported() function to the Language interface renamed "nested" attribute to "nested:outer" added "nested" flag, to be used with $ignore (it is not removed while flattening) added nestedClassesSupported() function to the Language interface tree iteration fix dirclassname variable names unified memory issue fixed merge error ignore unnamed structs for C++ unnamed nested C structs naming & unnesting class added to classes hash under typedef name private nested classes skipped test updated due to nested templates support anonymous structs with inheritance fixed nested_class test to allow anonymous structs w/o declarator tests updated: nested workaround removed from namespace_class.i propagated nested template declaration to the C++ file injected members scope nested tempplates fixes, nested structures in "C" mode parsing added utility function "appendSibling" (like "appendChild") nested unnamed structures parsing fixes, access mode restored on nested class end, tdname is properly patched with outer class name prefix memory management fixes nested templates (1) Nested unnamed structs Nested class support (1) Nested class support (1)
This commit is contained in:
parent
fcd0480364
commit
b63c4839fe
39 changed files with 1449 additions and 1111 deletions
|
|
@ -355,7 +355,7 @@ Language::~Language() {
|
|||
String *dirclassname;
|
||||
String *nspace = NewString(Getattr(n, "sym:nspace"));
|
||||
const char *attrib = "director:classname";
|
||||
String *classname = Getattr(n, "sym:name");
|
||||
String *classname = getClassPrefix();
|
||||
|
||||
Replace(nspace, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
|
||||
if (Len(nspace) > 0)
|
||||
|
|
@ -1015,8 +1015,6 @@ int Language::cDeclaration(Node *n) {
|
|||
/* Some kind of variable declaration */
|
||||
String *declaration = Copy(decl);
|
||||
Delattr(n, "decl");
|
||||
if (Getattr(n, "nested"))
|
||||
SetFlag(n, "feature:immutable");
|
||||
if (!CurrentClass) {
|
||||
if (Swig_storage_isextern(n) || ForceExtern) {
|
||||
if (AddExtern) {
|
||||
|
|
@ -2362,6 +2360,15 @@ int Language::classDeclaration(Node *n) {
|
|||
return SWIG_NOWRAP;
|
||||
}
|
||||
|
||||
// save class local variables for nested classes support
|
||||
int oldInClass = InClass;
|
||||
String *oldClassType = ClassType;
|
||||
String *oldClassPrefix = ClassPrefix;
|
||||
String *oldClassName = ClassName;
|
||||
String *oldDirectorClassName = DirectorClassName;
|
||||
String *oldNSpace = NSpace;
|
||||
Node* oldCurrentClass = CurrentClass;
|
||||
|
||||
String *kind = Getattr(n, "kind");
|
||||
String *name = Getattr(n, "name");
|
||||
String *tdname = Getattr(n, "tdname");
|
||||
|
|
@ -2370,6 +2377,8 @@ int Language::classDeclaration(Node *n) {
|
|||
|
||||
int strip = CPlusPlus ? 1 : unnamed && tdname;
|
||||
|
||||
if (cplus_mode != PUBLIC)
|
||||
return SWIG_NOWRAP;
|
||||
if (!name) {
|
||||
Swig_warning(WARN_LANG_CLASS_UNNAMED, input_file, line_number, "Can't generate wrappers for unnamed struct/class.\n");
|
||||
return SWIG_NOWRAP;
|
||||
|
|
@ -2380,15 +2389,21 @@ int Language::classDeclaration(Node *n) {
|
|||
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap class %s unless renamed to a valid identifier.\n", SwigType_namestr(symname));
|
||||
return SWIG_NOWRAP;
|
||||
}
|
||||
|
||||
AccessMode oldAccessMode = cplus_mode;
|
||||
Node* outerClass = Getattr(n, "nested:outer");
|
||||
if (outerClass && oldAccessMode != Dispatcher::PUBLIC)
|
||||
return SWIG_NOWRAP;
|
||||
ClassName = Copy(name);
|
||||
ClassPrefix = Copy(symname);
|
||||
if (Cmp(kind, "class") == 0) {
|
||||
cplus_mode = PRIVATE;
|
||||
} else {
|
||||
cplus_mode = PUBLIC;
|
||||
}
|
||||
|
||||
ClassName = Copy(name);
|
||||
ClassPrefix = Copy(symname);
|
||||
for (; outerClass; outerClass = Getattr(outerClass, "nested:outer")) {
|
||||
Push(ClassPrefix, "_");
|
||||
Push(ClassPrefix, Getattr(outerClass, "sym:name"));
|
||||
}
|
||||
if (strip) {
|
||||
ClassType = Copy(name);
|
||||
} else {
|
||||
|
|
@ -2399,9 +2414,8 @@ int Language::classDeclaration(Node *n) {
|
|||
|
||||
InClass = 1;
|
||||
CurrentClass = n;
|
||||
|
||||
String *oldNSpace = NSpace;
|
||||
NSpace = Getattr(n, "sym:nspace");
|
||||
int oldAbstract = Abstract;
|
||||
|
||||
/* Call classHandler() here */
|
||||
if (!ImportMode) {
|
||||
|
|
@ -2443,25 +2457,27 @@ int Language::classDeclaration(Node *n) {
|
|||
classDirector(n);
|
||||
}
|
||||
/* check for abstract after resolving directors */
|
||||
Abstract = abstractClassTest(n);
|
||||
|
||||
Abstract = abstractClassTest(n);
|
||||
classHandler(n);
|
||||
} else {
|
||||
Abstract = abstractClassTest(n);
|
||||
Language::classHandler(n);
|
||||
}
|
||||
|
||||
Abstract = oldAbstract;
|
||||
cplus_mode = oldAccessMode;
|
||||
NSpace = oldNSpace;
|
||||
InClass = 0;
|
||||
CurrentClass = 0;
|
||||
InClass = oldInClass;
|
||||
CurrentClass = oldCurrentClass;
|
||||
Delete(ClassType);
|
||||
ClassType = 0;
|
||||
ClassType = oldClassType;
|
||||
Delete(ClassPrefix);
|
||||
ClassPrefix = 0;
|
||||
ClassPrefix = oldClassPrefix;
|
||||
Delete(ClassName);
|
||||
ClassName = 0;
|
||||
ClassName = oldClassName;
|
||||
Delete(DirectorClassName);
|
||||
DirectorClassName = 0;
|
||||
DirectorClassName = oldDirectorClassName;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
|
@ -2640,7 +2656,7 @@ int Language::constructorDeclaration(Node *n) {
|
|||
String *scope = Swig_scopename_check(ClassName) ? Swig_scopename_prefix(ClassName) : 0;
|
||||
String *actual_name = scope ? NewStringf("%s::%s", scope, name) : NewString(name);
|
||||
Delete(scope);
|
||||
if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) {
|
||||
if (!Equal(actual_name, expected_name) && !SwigType_istemplate(expected_name)) {
|
||||
bool illegal_name = true;
|
||||
if (Extend) {
|
||||
// Check for typedef names used as a constructor name in %extend. This is deprecated except for anonymous
|
||||
|
|
@ -3426,6 +3442,9 @@ bool Language::extraDirectorProtectedCPPMethodsRequired() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Language::nestedClassesSupported() const {
|
||||
return false;
|
||||
}
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Language::is_wrapping_class()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -3612,3 +3631,45 @@ Language *Language::instance() {
|
|||
Hash *Language::getClassHash() const {
|
||||
return classhash;
|
||||
}
|
||||
|
||||
// insert N tabs before each new line in s
|
||||
void Swig_offset_string(String* s, int N)
|
||||
{
|
||||
// count a number of lines in s
|
||||
int lines = 1;
|
||||
int L = Len(s);
|
||||
char* start = strchr(Char(s), '\n');
|
||||
while (start) {
|
||||
++lines;
|
||||
start = strchr(start + 1, '\n');
|
||||
}
|
||||
// do not count pending new line
|
||||
if ((Char(s))[L-1] == '\n')
|
||||
--lines;
|
||||
// allocate a temporary storage for a padded string
|
||||
char* res = (char*)malloc(L + lines * N * 2 + 1);
|
||||
res[L + lines * N * 2] = 0;
|
||||
|
||||
// copy lines to res, prepending tabs to each line
|
||||
char* p = res; // output pointer
|
||||
start = Char(s); // start of a current line
|
||||
char* end = strchr(start, '\n'); // end of a current line
|
||||
while (end) {
|
||||
memset(p, ' ', N*2);
|
||||
p += N*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, ' ', N*2);
|
||||
p += N*2;
|
||||
strcpy(p, start);
|
||||
}
|
||||
// replace 's' contents with 'res'
|
||||
Clear(s);
|
||||
Append(s, res);
|
||||
free(res);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue