Merge branch 'class_p1_fixes' of github.com:v-for-vandal/swig into v-for-vandal-class_p1_fixes

Lua changes tweaks.

* 'class_p1_fixes' of github.com:v-for-vandal/swig:
  Removing all TODO:REMOVE
  Fixing enums
  __Static -> SwigStatig, __Module -> SwigModule
  Setattr -> SetFlag
  Backward compatibility -> Compatibility Note
  Fixing documentation. Adding an example.
This commit is contained in:
William S Fulton 2014-03-03 19:16:18 +00:00
commit 8b75b90b2f
10 changed files with 180 additions and 158 deletions

View file

@ -142,7 +142,7 @@ private:
// then it is basically C++ fully qualified name with colons replaced with dots.
String *full_proxy_class_name;
// All static methods and/or variables are treated as if they were in the
// special C++ namespace $(classname).__Static. This is internal mechanism only
// special C++ namespace $(classname).SwigStatic. This is internal mechanism only
// and is not visible to user in any manner. This variable holds the name
// of such pseudo-namespace a.k.a the result of above expression evaluation
String *class_static_nspace;
@ -486,8 +486,6 @@ public:
}
}
wrapname = Swig_name_wrapper(mrename);
//Printf(stdout, "luaname %s, symname %s mrename %s wrapname %s\n\tscope %s\n",
// Getattr(n, "lua:name"), symname, mrename, wrapname, luaScope ); // TODO: REMOVE
registerMethod(n, wrapname, luaScope);
}
@ -901,10 +899,6 @@ public:
// Remember C name of the wrapping function
Setattr(n, "wrap:name", wname);
/* TODO: REMOVE
if (functionWrapperRegisterNow()) { // emit normal fns & static fns
registerMethod(n);
}*/
if (current[CONSTRUCTOR]) {
if (constructor_name != 0)
Delete(constructor_name);
@ -965,8 +959,6 @@ public:
getName = Swig_name_wrapper(getName);
if (setName)
setName = Swig_name_wrapper(setName);
//Printf(stdout, "luaname %s, symname %s mrename %s getName %s\n\tscope %s\n\tassignable %d\n",
// Getattr(n, "lua:name"), symname, mrename, getName, luaScope, assignable ); // TODO: REMOVE
registerVariable(luaScope, n, getName, setName);
}
@ -1017,8 +1009,6 @@ public:
current[VARIABLE] = true;
// let SWIG generate the wrappers
int result = Language::variableWrapper(n);
// TODO: REMOVE
//registerVariable(luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name");
// It is impossible to use registerVariable, because sym:name of the Node is currently
// in an undefined state - the callees of this function may have modified it.
@ -1087,7 +1077,6 @@ public:
}
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
//Printf(stdout, "tm v1: %s\n", tm); // TODO:REMOVE
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", lua_name);
Replaceall(tm, "$value", value);
@ -1110,47 +1099,41 @@ public:
bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0;
if (make_v2_compatible) {
// Special handling for enums in C mode - they are not prefixed with structure name
if(!CPlusPlus && current[ENUM_CONST]) {
lua_name_v2 = lua_name;
DohIncref(lua_name_v2);
iname_v2 = iname;
DohIncref(iname_v2);
} else {
// Don't do anything for enums in C mode - they are already
// wrapped correctly
if (CPlusPlus || !current[ENUM_CONST]) {
lua_name_v2 = Swig_name_member(0, proxy_class_name, lua_name);
iname_v2 = Swig_name_member(0, proxy_class_name, iname);
}
n_v2 = Copy(n);
//Printf( stdout, "target name v2: %s, symname v2 %s\n", lua_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE
if (!luaAddSymbol(iname_v2, n, getNSpace())) {
Swig_restore(n);
return SWIG_ERROR;
}
n_v2 = Copy(n);
if (!luaAddSymbol(iname_v2, n, getNSpace())) {
Swig_restore(n);
return SWIG_ERROR;
}
Setattr(n_v2, "sym:name", lua_name_v2);
tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0);
if (tm_v2) {
//Printf(stdout, "tm v2: %s\n", tm_v2.ptr()); // TODO:REMOVE
Replaceall(tm_v2, "$source", value);
Replaceall(tm_v2, "$target", lua_name_v2);
Replaceall(tm_v2, "$value", value);
Replaceall(tm_v2, "$nsname", nsname);
registerConstant(getNSpace(), tm_v2);
} else {
tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0);
if (!tm_v2) {
// This can't be.
assert(false);
Swig_restore(n);
return SWIG_ERROR;
}
Replaceall(tm_v2, "$source", value);
Replaceall(tm_v2, "$target", lua_name_v2);
Replaceall(tm_v2, "$value", value);
Replaceall(tm_v2, "$nsname", nsname);
Printf(f_init, "%s\n", tm_v2);
Setattr(n_v2, "sym:name", lua_name_v2);
tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0);
if (tm_v2) {
Replaceall(tm_v2, "$source", value);
Replaceall(tm_v2, "$target", lua_name_v2);
Replaceall(tm_v2, "$value", value);
Replaceall(tm_v2, "$nsname", nsname);
registerConstant(getNSpace(), tm_v2);
} else {
tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0);
if (!tm_v2) {
// This can't be.
assert(false);
Swig_restore(n);
return SWIG_ERROR;
}
Replaceall(tm_v2, "$source", value);
Replaceall(tm_v2, "$target", lua_name_v2);
Replaceall(tm_v2, "$value", value);
Replaceall(tm_v2, "$nsname", nsname);
Printf(f_init, "%s\n", tm_v2);
}
Delete(n_v2);
}
Delete(n_v2);
}
Swig_restore(n);
@ -1301,7 +1284,7 @@ public:
proxy_class_name = 0;
return SWIG_NOWRAP;
}
Setattr(emitted, mangled_fr_t, "1");
SetFlag(emitted, mangled_fr_t);
// We treat class T as both 'class' and 'namespace'. All static members, attributes
// and constants are considered part of namespace T, all members - part of the 'class'
@ -1309,28 +1292,25 @@ public:
// are described with same structures - swig_lua_attribute/swig_lua_method. Instead of calling
// getCArraysHash(class name) to initialize things for static methods/attributes and then
// manually doing same initialization for non-static methods, we call getCArraysHash 2 times:
// 1) With name "class name" + "." + "__Static" to initialize static things
// 1) With name "class name" + "." + "SwigStatic" to initialize static things
// 2) With "class name" to initialize non-static things
// And we can guarantee that there will not be any name collision because names starting with 2 underscores
// and capital letter are forbiden to use in C++. So, under know circumstances could our class contain
// any member or subclass with name "__Static". Thus, never any name clash.
Hash *instance_cls = getCArraysHash(full_proxy_class_name, false);
assert(instance_cls);
String *s_attr_tab_name = Getattr(instance_cls, "attributes:name");
String *s_methods_tab_name = Getattr(instance_cls, "methods:name");
Setattr(instance_cls, "lua:no_namespaces", "1");
Setattr(instance_cls, "lua:no_classes", "1");
Setattr(instance_cls, "lua:class_instance", "1");
SetFlag(instance_cls, "lua:no_namespaces");
SetFlag(instance_cls, "lua:no_classes");
SetFlag(instance_cls, "lua:class_instance");
/* There is no use for "constants", "classes" and "namespaces" arrays.
* All constants are considered part of static part of class.
*/
class_static_nspace = NewStringf("%s%s__Static", full_proxy_class_name, NSPACE_SEPARATOR);
class_static_nspace = NewStringf("%s%sSwigStatic", full_proxy_class_name, NSPACE_SEPARATOR);
Hash *static_cls = getCArraysHash(class_static_nspace, false);
assert(static_cls);
Setattr(static_cls, "lua:no_namespaces", "1");
Setattr(static_cls, "lua:class_static", "1");
SetFlag(static_cls, "lua:no_namespaces");
SetFlag(static_cls, "lua:class_static");
// Notifying instance_cls and static_cls hashes about each other
Setattr(instance_cls, "lua:class_instance:static_hash", static_cls);
@ -1479,7 +1459,6 @@ public:
Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname"));
if (!eluac_ltr) {
assert(Getattr(instance_cls, "metatable:name")); // TODO: REMOVE
Printf(f_wrappers, ", %s", Getattr(instance_cls,"metatable:name"));
}
else
@ -1520,7 +1499,6 @@ public:
current[MEMBER_FUNC] = true;
Language::memberfunctionHandler(n);
//Printf( stdout, "add member function: %s to %s\n", symname, luaCurrentSymbolNSpace());// TODO: REMOVE
registerMethod(n);
current[MEMBER_FUNC] = false;
return SWIG_OK;
@ -1675,7 +1653,6 @@ public:
// not the C++ name. This is because an earlier version used such a scheme for static function
// name generation and we have to maintain backward compatibility.
String *v2_name = Swig_name_member(NIL, proxy_class_name, lua_name);
//Printf( stdout, "Name %s, class %s, compt. name %s\n", lua_name, proxy_class_name, v2_name ); // TODO: REMOVE
if (!GetFlag(n, "wrappedasconstant")) {
Setattr(n, "lua:name", v2_name);
// Registering static var in the class parent nspace
@ -1809,7 +1786,7 @@ public:
carrays_hash = NewHash();
String *mangled_name = 0;
if (nspace == 0 || Len(nspace) == 0)
mangled_name = NewString("__Module"); // C++ names can't start with "__ + capital letter"
mangled_name = NewString("SwigModule");
else
mangled_name = Swig_name_mangle(nspace);
String *cname = NewStringf("swig_%s", mangled_name);
@ -1907,8 +1884,6 @@ public:
Printf(metatable_tab, "const LUA_REG_TYPE ");
else
Printf(metatable_tab, "static swig_lua_method ");
assert(metatable_tab); // TODO: REMOVE
assert(metatable_tab_name); // TODO: REMOVE
Printv(metatable_tab, metatable_tab_name, "[]", NIL);
Printv(metatable_tab_decl, metatable_tab, ";", NIL);
Printv(metatable_tab, " = {\n", NIL);
@ -1932,7 +1907,6 @@ public:
String *item = Getitem(components, i);
Printv(parent_path, item, NIL);
}
//Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); // TODO: REMOVE
Hash *parent = getCArraysHash(parent_path, true);
String *namespaces_tab = Getattr(parent, "namespaces");
Printv(namespaces_tab, "&", cname, ",\n", NIL);
@ -1945,7 +1919,7 @@ public:
Delete(components);
Delete(parent_path);
} else if (!reg) // This namespace shouldn't be registered. Lets remember it.
Setattr(carrays_hash, "lua:no_reg", "1");
SetFlag(carrays_hash, "lua:no_reg");
Delete(mangled_name);
mangled_name = 0;
@ -1969,7 +1943,7 @@ public:
assert(carrays_hash);
assert(Getattr(carrays_hash, "lua:closed") == 0);
Setattr(carrays_hash, "lua:closed", "1");
SetFlag(carrays_hash, "lua:closed");
String *attr_tab = Getattr(carrays_hash, "attributes");
Printf(attr_tab, " {0,0,0}\n};\n");
@ -1989,12 +1963,10 @@ public:
}
String *methods_tab = Getattr(carrays_hash, "methods");
String *metatable_tab_name = Getattr(carrays_hash, "metatable:name");
assert(methods_tab); // TODO: REMOVE
if (elua_ltr || eluac_ltr) {
if (v2_compatibility)
Printv(methods_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(", const_tab_name, ")},\n", NIL);
if (elua_ltr) {
assert(metatable_tab_name); // TODO: REMOVE
Printv(methods_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(", metatable_tab_name, ")},\n", NIL);
}
@ -2086,7 +2058,7 @@ public:
void closeNamespaces(File *dataOutput) {
// Special handling for empty module.
if (symbolScopeLookup("") == 0 || rawGetCArraysHash("") == 0) {
// Module is empty. Create hash for global scope in order to have swig__Module
// Module is empty. Create hash for global scope in order to have swig_SwigModule
// variable in resulting file
getCArraysHash(0);
}
@ -2177,6 +2149,9 @@ public:
// If inside class, but current[NO_CPP], then this is friend function. It belongs to NSpace
if (!getCurrentClass() || current[NO_CPP]) {
scope = getNSpace();
} else if (current[ENUM_CONST] && !CPlusPlus ) {
// Enums in C mode go to NSpace
scope = getNSpace();
} else {
// If inside class, then either class static namespace or class fully qualified name is used
assert(!current[NO_CPP]);