Merge pull request #146 from v-for-vandal/class_p1_fixes2
Class p1 fixes2 - Lua enums and NSpace Disable old-names generation for enums in class in namespace Getattribute->GetFlag Partially disabling old names generation for classes with nspace Working around some of the SWIG internal issues with enums
This commit is contained in:
commit
bf8eb05dbb
3 changed files with 57 additions and 20 deletions
|
|
@ -62,6 +62,18 @@ sc = ns.Outer.SomeClass()
|
||||||
assert( sc:GetInner1ColorChannel() ~= sc:GetInner2Channel() )
|
assert( sc:GetInner1ColorChannel() ~= sc:GetInner2Channel() )
|
||||||
assert( sc:GetInner1Channel() ~= sc:GetInner2Channel() )
|
assert( sc:GetInner1Channel() ~= sc:GetInner2Channel() )
|
||||||
|
|
||||||
|
-- Backward compatibility
|
||||||
|
assert(ns.Outer.Inner1.Diffuse ~= nil)
|
||||||
|
-- Enums within class within namespace shouldn't have backward compatible name. Same for static methods
|
||||||
|
assert(ns.Outer.Inner1.Color_Diffuse == nil)
|
||||||
|
assert(ns.Outer.Inner1.Color_colorStaticMethod == nil)
|
||||||
|
|
||||||
|
-- Enums and static methods of class marked as %nonspace should have backward compatible name
|
||||||
|
assert(ns.NoNSpacePlease_noNspaceStaticFunc() == 10)
|
||||||
|
assert(ns.Outer.Inner2.NoNSpacePlease_NoNspace == nil)
|
||||||
|
-- ReallyNoNSpaceEnum is wrapped into %nonspace and thus handled correctly.
|
||||||
|
-- NoNSpaceEnum is not (although both of them are in %nonspace-wrapped class) and thus
|
||||||
|
-- handled rather unexpectedly
|
||||||
|
assert(ns.NoNSpacePlease_ReallyNoNspace1 == 1)
|
||||||
|
assert(ns.NoNSpacePlease.ReallyNoNspace2 == 10)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
||||||
|
|
||||||
%nspace;
|
%nspace;
|
||||||
%nonspace Outer::Inner2::NoNSpacePlease;
|
%nonspace Outer::Inner2::NoNSpacePlease;
|
||||||
|
%nonspace Outer::Inner2::NoNSpacePlease::ReallyNoNSpaceEnum;
|
||||||
|
|
||||||
%copyctor;
|
%copyctor;
|
||||||
%ignore Outer::Inner2::Color::Color();
|
%ignore Outer::Inner2::Color::Color();
|
||||||
|
|
@ -67,7 +68,12 @@ namespace Outer {
|
||||||
const Outer::Inner2::Color& col2c) {}
|
const Outer::Inner2::Color& col2c) {}
|
||||||
}; // Color
|
}; // Color
|
||||||
int Color::staticMemberVariable = 0;
|
int Color::staticMemberVariable = 0;
|
||||||
class NoNSpacePlease {};
|
class NoNSpacePlease {
|
||||||
|
public:
|
||||||
|
enum NoNSpaceEnum { NoNspace1 = 1, NoNspace2 = 10 };
|
||||||
|
enum ReallyNoNSpaceEnum { ReallyNoNspace1 = 1, ReallyNoNspace2 = 10 };
|
||||||
|
static int noNspaceStaticFunc() { return 10; }
|
||||||
|
};
|
||||||
} // Inner2
|
} // Inner2
|
||||||
|
|
||||||
// Derived class
|
// Derived class
|
||||||
|
|
|
||||||
|
|
@ -103,13 +103,11 @@ static int squash_bases = 0;
|
||||||
* This variable is controled by -no-old-metatable-bindings option.
|
* This variable is controled by -no-old-metatable-bindings option.
|
||||||
* v2_compatibility -
|
* v2_compatibility -
|
||||||
* 1. static methods will be put into the scope their respective class
|
* 1. static methods will be put into the scope their respective class
|
||||||
* belongs to as well as into the class scope itself.
|
* belongs to as well as into the class scope itself. (only for classes without %nspace given)
|
||||||
* 2. The layout in elua mode is somewhat different
|
* 2. The layout in elua mode is somewhat different
|
||||||
* 3. C enums defined inside struct will oblige to C Standard and
|
|
||||||
* will be defined in the scope surrounding the struct, not scope
|
|
||||||
* associated with it/
|
|
||||||
*/
|
*/
|
||||||
static int v2_compatibility = 0;
|
static int v2_compatibility = 0;
|
||||||
|
static int v2_compat_names_generation = 1; // This flag can temporaraly disable backward compatible names generation if v2_compatibiliti is enabled
|
||||||
static const int default_api_level = 2;
|
static const int default_api_level = 2;
|
||||||
|
|
||||||
/* NEW LANGUAGE NOTE:***********************************************
|
/* NEW LANGUAGE NOTE:***********************************************
|
||||||
|
|
@ -1096,7 +1094,8 @@ public:
|
||||||
return SWIG_NOWRAP;
|
return SWIG_NOWRAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0;
|
bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0
|
||||||
|
&& v2_compat_names_generation;
|
||||||
|
|
||||||
if (make_v2_compatible) {
|
if (make_v2_compatible) {
|
||||||
// Don't do anything for enums in C mode - they are already
|
// Don't do anything for enums in C mode - they are already
|
||||||
|
|
@ -1166,9 +1165,20 @@ public:
|
||||||
virtual int enumDeclaration(Node *n) {
|
virtual int enumDeclaration(Node *n) {
|
||||||
current[STATIC_CONST] = true;
|
current[STATIC_CONST] = true;
|
||||||
current[ENUM_CONST] = true;
|
current[ENUM_CONST] = true;
|
||||||
|
// There is some slightly specific behaviour with enums. Basically,
|
||||||
|
// their NSpace may be tracked separately. The code below tries to work around
|
||||||
|
// this issue to some degree.
|
||||||
|
// The idea is the same as in classHandler - to drop old names generation if
|
||||||
|
// enum is in class in namespace.
|
||||||
|
const int v2_compat_names_generation_old = v2_compat_names_generation;
|
||||||
|
if (getNSpace() ||
|
||||||
|
( Getattr(n, "sym:nspace") != 0 && Len(Getattr(n, "sym:nspace")) > 0 ) ) {
|
||||||
|
v2_compat_names_generation = 0;
|
||||||
|
}
|
||||||
int result = Language::enumDeclaration(n);
|
int result = Language::enumDeclaration(n);
|
||||||
current[STATIC_CONST] = false;
|
current[STATIC_CONST] = false;
|
||||||
current[ENUM_CONST] = false;
|
current[ENUM_CONST] = false;
|
||||||
|
v2_compat_names_generation = v2_compat_names_generation_old;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1279,7 +1289,7 @@ public:
|
||||||
// * consider effect on template_specialization_defarg
|
// * consider effect on template_specialization_defarg
|
||||||
|
|
||||||
static Hash *emitted = NewHash();
|
static Hash *emitted = NewHash();
|
||||||
if (Getattr(emitted, mangled_fr_t)) {
|
if (GetFlag(emitted, mangled_fr_t)) {
|
||||||
full_proxy_class_name = 0;
|
full_proxy_class_name = 0;
|
||||||
proxy_class_name = 0;
|
proxy_class_name = 0;
|
||||||
return SWIG_NOWRAP;
|
return SWIG_NOWRAP;
|
||||||
|
|
@ -1316,12 +1326,21 @@ public:
|
||||||
Setattr(instance_cls, "lua:class_instance:static_hash", static_cls);
|
Setattr(instance_cls, "lua:class_instance:static_hash", static_cls);
|
||||||
Setattr(static_cls, "lua:class_static:instance_hash", instance_cls);
|
Setattr(static_cls, "lua:class_static:instance_hash", instance_cls);
|
||||||
|
|
||||||
|
const int v2_compat_names_generation_old = v2_compat_names_generation;
|
||||||
|
// If class has %nspace enabled, then generation of backward compatible names
|
||||||
|
// should be disabled
|
||||||
|
if (getNSpace()) {
|
||||||
|
v2_compat_names_generation = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* There is no use for "classes" and "namespaces" arrays. Subclasses are not supported
|
/* There is no use for "classes" and "namespaces" arrays. Subclasses are not supported
|
||||||
* by SWIG and namespaces couldn't be nested inside classes (C++ Standard)
|
* by SWIG and namespaces couldn't be nested inside classes (C++ Standard)
|
||||||
*/
|
*/
|
||||||
// Generate normal wrappers
|
// Generate normal wrappers
|
||||||
Language::classHandler(n);
|
Language::classHandler(n);
|
||||||
|
|
||||||
|
v2_compat_names_generation = v2_compat_names_generation_old;
|
||||||
|
|
||||||
SwigType_add_pointer(t);
|
SwigType_add_pointer(t);
|
||||||
|
|
||||||
// Catch all: eg. a class with only static functions and/or variables will not have 'remembered'
|
// Catch all: eg. a class with only static functions and/or variables will not have 'remembered'
|
||||||
|
|
@ -1601,7 +1620,7 @@ public:
|
||||||
const int result = Language::staticmemberfunctionHandler(n);
|
const int result = Language::staticmemberfunctionHandler(n);
|
||||||
registerMethod(n);
|
registerMethod(n);
|
||||||
|
|
||||||
if (v2_compatibility && result == SWIG_OK) {
|
if (v2_compatibility && result == SWIG_OK && v2_compat_names_generation) {
|
||||||
Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL);
|
Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL);
|
||||||
String *lua_name = Getattr(n, "lua:name");
|
String *lua_name = Getattr(n, "lua:name");
|
||||||
// Although this function uses Swig_name_member, it actually generates the Lua name,
|
// Although this function uses Swig_name_member, it actually generates the Lua name,
|
||||||
|
|
@ -1646,7 +1665,7 @@ public:
|
||||||
|
|
||||||
if (result == SWIG_OK) {
|
if (result == SWIG_OK) {
|
||||||
// This will add static member variable to the class namespace with name ClassName_VarName
|
// This will add static member variable to the class namespace with name ClassName_VarName
|
||||||
if (v2_compatibility) {
|
if (v2_compatibility && v2_compat_names_generation) {
|
||||||
Swig_save("lua_staticmembervariableHandler", n, "lua:name", NIL);
|
Swig_save("lua_staticmembervariableHandler", n, "lua:name", NIL);
|
||||||
String *lua_name = Getattr(n, "lua:name");
|
String *lua_name = Getattr(n, "lua:name");
|
||||||
// Although this function uses Swig_name_member, it actually generates the Lua name,
|
// Although this function uses Swig_name_member, it actually generates the Lua name,
|
||||||
|
|
@ -1895,7 +1914,7 @@ public:
|
||||||
Setattr(scope, "lua:cdata", carrays_hash);
|
Setattr(scope, "lua:cdata", carrays_hash);
|
||||||
assert(rawGetCArraysHash(nspace));
|
assert(rawGetCArraysHash(nspace));
|
||||||
|
|
||||||
if (reg && nspace != 0 && Len(nspace) != 0 && Getattr(carrays_hash, "lua:no_reg") == 0) {
|
if (reg && nspace != 0 && Len(nspace) != 0 && GetFlag(carrays_hash, "lua:no_reg") == 0) {
|
||||||
// Split names into components
|
// Split names into components
|
||||||
List *components = Split(nspace, '.', -1);
|
List *components = Split(nspace, '.', -1);
|
||||||
String *parent_path = NewString("");
|
String *parent_path = NewString("");
|
||||||
|
|
@ -1941,7 +1960,7 @@ public:
|
||||||
void closeCArraysHash(String *nspace, File *output) {
|
void closeCArraysHash(String *nspace, File *output) {
|
||||||
Hash *carrays_hash = rawGetCArraysHash(nspace);
|
Hash *carrays_hash = rawGetCArraysHash(nspace);
|
||||||
assert(carrays_hash);
|
assert(carrays_hash);
|
||||||
assert(Getattr(carrays_hash, "lua:closed") == 0);
|
assert(GetFlag(carrays_hash, "lua:closed") == 0);
|
||||||
|
|
||||||
SetFlag(carrays_hash, "lua:closed");
|
SetFlag(carrays_hash, "lua:closed");
|
||||||
|
|
||||||
|
|
@ -1976,13 +1995,13 @@ public:
|
||||||
Printf(methods_tab, " {0,0}\n};\n");
|
Printf(methods_tab, " {0,0}\n};\n");
|
||||||
Printv(output, methods_tab, NIL);
|
Printv(output, methods_tab, NIL);
|
||||||
|
|
||||||
if (!Getattr(carrays_hash, "lua:no_classes")) {
|
if (!GetFlag(carrays_hash, "lua:no_classes")) {
|
||||||
String *classes_tab = Getattr(carrays_hash, "classes");
|
String *classes_tab = Getattr(carrays_hash, "classes");
|
||||||
Printf(classes_tab, " 0\n};\n");
|
Printf(classes_tab, " 0\n};\n");
|
||||||
Printv(output, classes_tab, NIL);
|
Printv(output, classes_tab, NIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Getattr(carrays_hash, "lua:no_namespaces")) {
|
if (!GetFlag(carrays_hash, "lua:no_namespaces")) {
|
||||||
String *namespaces_tab = Getattr(carrays_hash, "namespaces");
|
String *namespaces_tab = Getattr(carrays_hash, "namespaces");
|
||||||
Printf(namespaces_tab, " 0\n};\n");
|
Printf(namespaces_tab, " 0\n};\n");
|
||||||
Printv(output, namespaces_tab, NIL);
|
Printv(output, namespaces_tab, NIL);
|
||||||
|
|
@ -2003,7 +2022,7 @@ public:
|
||||||
String *get_tab_name = Getattr(carrays_hash, "get:name");
|
String *get_tab_name = Getattr(carrays_hash, "get:name");
|
||||||
String *set_tab_name = Getattr(carrays_hash, "set:name");
|
String *set_tab_name = Getattr(carrays_hash, "set:name");
|
||||||
|
|
||||||
if (Getattr(carrays_hash, "lua:class_instance")) {
|
if (GetFlag(carrays_hash, "lua:class_instance")) {
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_class_get)},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_class_get)},\n", NIL);
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_class_set)},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_class_set)},\n", NIL);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2016,7 +2035,7 @@ public:
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL);
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\".fn\"), LROVAL(", Getattr(carrays_hash, "methods:name"), ")},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\".fn\"), LROVAL(", Getattr(carrays_hash, "methods:name"), ")},\n", NIL);
|
||||||
|
|
||||||
if (Getattr(carrays_hash, "lua:class_instance")) {
|
if (GetFlag(carrays_hash, "lua:class_instance")) {
|
||||||
String *static_cls = Getattr(carrays_hash, "lua:class_instance:static_hash");
|
String *static_cls = Getattr(carrays_hash, "lua:class_instance:static_hash");
|
||||||
assert(static_cls);
|
assert(static_cls);
|
||||||
// static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR)
|
// static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR)
|
||||||
|
|
@ -2026,7 +2045,7 @@ public:
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL);
|
||||||
// Put forward declaration of this array
|
// Put forward declaration of this array
|
||||||
Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL);
|
Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL);
|
||||||
} else if (Getattr(carrays_hash, "lua:class_static")) {
|
} else if (GetFlag(carrays_hash, "lua:class_static")) {
|
||||||
Hash *instance_cls = Getattr(carrays_hash, "lua:class_static:instance_hash");
|
Hash *instance_cls = Getattr(carrays_hash, "lua:class_static:instance_hash");
|
||||||
assert(instance_cls);
|
assert(instance_cls);
|
||||||
String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name");
|
String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name");
|
||||||
|
|
@ -2074,7 +2093,7 @@ public:
|
||||||
// We have a pseudo symbol. Lets get actual scope for this pseudo symbol
|
// We have a pseudo symbol. Lets get actual scope for this pseudo symbol
|
||||||
Hash *carrays_hash = rawGetCArraysHash(ki.key);
|
Hash *carrays_hash = rawGetCArraysHash(ki.key);
|
||||||
assert(carrays_hash);
|
assert(carrays_hash);
|
||||||
if (Getattr(carrays_hash, "lua:closed") == 0)
|
if (GetFlag(carrays_hash, "lua:closed") == 0)
|
||||||
Append(to_close, ki.key);
|
Append(to_close, ki.key);
|
||||||
}
|
}
|
||||||
ki = Next(ki);
|
ki = Next(ki);
|
||||||
|
|
@ -2119,8 +2138,8 @@ public:
|
||||||
String *const_tab_name = Getattr(carrays_hash, "constants:name");
|
String *const_tab_name = Getattr(carrays_hash, "constants:name");
|
||||||
String *classes_tab_name = Getattr(carrays_hash, "classes:name");
|
String *classes_tab_name = Getattr(carrays_hash, "classes:name");
|
||||||
String *namespaces_tab_name = Getattr(carrays_hash, "namespaces:name");
|
String *namespaces_tab_name = Getattr(carrays_hash, "namespaces:name");
|
||||||
bool has_classes = Getattr(carrays_hash, "lua:no_classes") == 0;
|
bool has_classes = GetFlag(carrays_hash, "lua:no_classes") == 0;
|
||||||
bool has_namespaces = Getattr(carrays_hash, "lua:no_namespaces") == 0;
|
bool has_namespaces = GetFlag(carrays_hash, "lua:no_namespaces") == 0;
|
||||||
|
|
||||||
Printv(output, "{\n",
|
Printv(output, "{\n",
|
||||||
tab4, "\"", name, "\",\n",
|
tab4, "\"", name, "\",\n",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue