diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2014-03-14 09:01:15 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2014-03-14 09:01:15 +0000 |
commit | bf8eb05dbbcca6f749d5a234f5c53ef4d84f004e (patch) | |
tree | cffd8561d078ca340bbe53550223b4b6db98ae56 | |
parent | 90a9ac99a8d45522c86ccc5f46efcf0c2155c605 (diff) | |
parent | ddbf439db9e65ec4243fa71f1c036bd7d56f1624 (diff) | |
download | swig-bf8eb05dbbcca6f749d5a234f5c53ef4d84f004e.tar.gz |
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
-rw-r--r-- | Examples/test-suite/lua/nspace_runme.lua | 16 | ||||
-rw-r--r-- | Examples/test-suite/nspace.i | 8 | ||||
-rw-r--r-- | Source/Modules/lua.cxx | 55 |
3 files changed, 58 insertions, 21 deletions
diff --git a/Examples/test-suite/lua/nspace_runme.lua b/Examples/test-suite/lua/nspace_runme.lua index 5d55357c0..21f88e2af 100644 --- a/Examples/test-suite/lua/nspace_runme.lua +++ b/Examples/test-suite/lua/nspace_runme.lua @@ -62,6 +62,18 @@ sc = ns.Outer.SomeClass() assert( sc:GetInner1ColorChannel() ~= 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) diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index 58c560412..1520b3652 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -10,6 +10,7 @@ SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) %nspace; %nonspace Outer::Inner2::NoNSpacePlease; +%nonspace Outer::Inner2::NoNSpacePlease::ReallyNoNSpaceEnum; %copyctor; %ignore Outer::Inner2::Color::Color(); @@ -67,7 +68,12 @@ namespace Outer { const Outer::Inner2::Color& col2c) {} }; // Color 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 // Derived class diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 2f06b8668..002c6eb3a 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -103,13 +103,11 @@ static int squash_bases = 0; * This variable is controled by -no-old-metatable-bindings option. * v2_compatibility - * 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 - * 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_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; /* NEW LANGUAGE NOTE:*********************************************** @@ -1096,7 +1094,8 @@ public: 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) { // Don't do anything for enums in C mode - they are already @@ -1166,9 +1165,20 @@ public: virtual int enumDeclaration(Node *n) { current[STATIC_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); current[STATIC_CONST] = false; current[ENUM_CONST] = false; + v2_compat_names_generation = v2_compat_names_generation_old; return result; } @@ -1279,7 +1289,7 @@ public: // * consider effect on template_specialization_defarg static Hash *emitted = NewHash(); - if (Getattr(emitted, mangled_fr_t)) { + if (GetFlag(emitted, mangled_fr_t)) { full_proxy_class_name = 0; proxy_class_name = 0; return SWIG_NOWRAP; @@ -1316,12 +1326,21 @@ public: Setattr(instance_cls, "lua:class_instance:static_hash", static_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 * by SWIG and namespaces couldn't be nested inside classes (C++ Standard) */ // Generate normal wrappers Language::classHandler(n); + v2_compat_names_generation = v2_compat_names_generation_old; + SwigType_add_pointer(t); // 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); 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); String *lua_name = Getattr(n, "lua:name"); // Although this function uses Swig_name_member, it actually generates the Lua name, @@ -1646,7 +1665,7 @@ public: if (result == SWIG_OK) { // 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); String *lua_name = Getattr(n, "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); 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 List *components = Split(nspace, '.', -1); String *parent_path = NewString(""); @@ -1941,7 +1960,7 @@ public: void closeCArraysHash(String *nspace, File *output) { Hash *carrays_hash = rawGetCArraysHash(nspace); assert(carrays_hash); - assert(Getattr(carrays_hash, "lua:closed") == 0); + assert(GetFlag(carrays_hash, "lua:closed") == 0); SetFlag(carrays_hash, "lua:closed"); @@ -1976,13 +1995,13 @@ public: Printf(methods_tab, " {0,0}\n};\n"); 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"); Printf(classes_tab, " 0\n};\n"); 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"); Printf(namespaces_tab, " 0\n};\n"); Printv(output, namespaces_tab, NIL); @@ -2003,7 +2022,7 @@ public: String *get_tab_name = Getattr(carrays_hash, "get: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(\"__newindex\"), LFUNCVAL(SWIG_Lua_class_set)},\n", NIL); } else { @@ -2016,7 +2035,7 @@ public: 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); - 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"); assert(static_cls); // 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); // Put forward declaration of this array 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"); assert(instance_cls); 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 Hash *carrays_hash = rawGetCArraysHash(ki.key); assert(carrays_hash); - if (Getattr(carrays_hash, "lua:closed") == 0) + if (GetFlag(carrays_hash, "lua:closed") == 0) Append(to_close, ki.key); } ki = Next(ki); @@ -2119,8 +2138,8 @@ public: String *const_tab_name = Getattr(carrays_hash, "constants:name"); String *classes_tab_name = Getattr(carrays_hash, "classes:name"); String *namespaces_tab_name = Getattr(carrays_hash, "namespaces:name"); - bool has_classes = Getattr(carrays_hash, "lua:no_classes") == 0; - bool has_namespaces = Getattr(carrays_hash, "lua:no_namespaces") == 0; + bool has_classes = GetFlag(carrays_hash, "lua:no_classes") == 0; + bool has_namespaces = GetFlag(carrays_hash, "lua:no_namespaces") == 0; Printv(output, "{\n", tab4, "\"", name, "\",\n", |