diff options
author | Artem Serebriyskiy <v.for.vandal@gmail.com> | 2014-03-06 15:24:17 +0400 |
---|---|---|
committer | Artem Serebriyskiy <v.for.vandal@gmail.com> | 2014-03-06 15:24:17 +0400 |
commit | 3028b16cee672a796ed0fb4226b127e7a8c493c5 (patch) | |
tree | 53cd7a178ebfec886c56c8eba1a90efad56dd79c | |
parent | 869de3e7614814bcbf827d6796ef44d4c7047855 (diff) | |
download | swig-3028b16cee672a796ed0fb4226b127e7a8c493c5.tar.gz |
Partially disabling old names generation for classes with nspace
-rw-r--r-- | Examples/test-suite/lua/nspace_runme.lua | 12 | ||||
-rw-r--r-- | Examples/test-suite/nspace.i | 6 | ||||
-rw-r--r-- | Source/Modules/lua.cxx | 28 |
3 files changed, 30 insertions, 16 deletions
diff --git a/Examples/test-suite/lua/nspace_runme.lua b/Examples/test-suite/lua/nspace_runme.lua index 5d55357c0..049d4ff00 100644 --- a/Examples/test-suite/lua/nspace_runme.lua +++ b/Examples/test-suite/lua/nspace_runme.lua @@ -62,6 +62,14 @@ 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.NoNSpacePlease_NoNspace1 == 1) +-- assert(ns.NoNSpacePlease.NoNspace2 == 10) diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index 58c560412..c595322a7 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -67,7 +67,11 @@ namespace Outer { const Outer::Inner2::Color& col2c) {} }; // Color int Color::staticMemberVariable = 0; - class NoNSpacePlease {}; + class NoNSpacePlease { + public: + enum NoNSpaceEnum { NoNspace1 = 1, NoNspace2 = 10 }; + static int noNspaceStaticFunc() { return 10; } + }; } // Inner2 // Derived class diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 0a5a00515..e0fb2c2a0 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,15 +1165,9 @@ public: virtual int enumDeclaration(Node *n) { current[STATIC_CONST] = true; current[ENUM_CONST] = true; - // Drop v2_compatibility if NSpace is given - int old_v2_compatibility = v2_compatibility; - if (getNSpace()) { - v2_compatibility = 0; - } int result = Language::enumDeclaration(n); current[STATIC_CONST] = false; current[ENUM_CONST] = false; - v2_compatibility = old_v2_compatibility; return result; } @@ -1322,12 +1315,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' @@ -1607,7 +1609,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, @@ -1652,7 +1654,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, |