Code beautifier
This commit is contained in:
parent
9bd39fe4fa
commit
1e282e3981
1 changed files with 511 additions and 530 deletions
|
|
@ -170,18 +170,11 @@ public:
|
||||||
f_initbeforefunc(0),
|
f_initbeforefunc(0),
|
||||||
s_luacode(0),
|
s_luacode(0),
|
||||||
module(0),
|
module(0),
|
||||||
have_constructor(0),
|
have_constructor(0), have_destructor(0), destructor_action(0), class_symname(0), class_fq_symname(0), class_static_nspace(0), constructor_name(0) {
|
||||||
have_destructor(0),
|
|
||||||
destructor_action(0),
|
|
||||||
class_symname(0),
|
|
||||||
class_fq_symname(0),
|
|
||||||
class_static_nspace(0),
|
|
||||||
constructor_name(0) {
|
|
||||||
namespaces_hash = NewHash();
|
namespaces_hash = NewHash();
|
||||||
for (int i = 0; i < STATES_COUNT; i++)
|
for (int i = 0; i < STATES_COUNT; i++)
|
||||||
current[i] = false;
|
current[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
~LUA() {
|
~LUA() {
|
||||||
if (namespaces_hash)
|
if (namespaces_hash)
|
||||||
Delete(namespaces_hash);
|
Delete(namespaces_hash);
|
||||||
|
|
@ -339,10 +332,7 @@ public:
|
||||||
emitLuaFlavor(f_runtime);
|
emitLuaFlavor(f_runtime);
|
||||||
|
|
||||||
if (elua_ltr || eluac_ltr)
|
if (elua_ltr || eluac_ltr)
|
||||||
Printf(f_runtime,
|
Printf(f_runtime, "#ifndef MIN_OPT_LEVEL\n" "#define MIN_OPT_LEVEL %d\n" "#endif\n", elua_opt_lvl);
|
||||||
"#ifndef MIN_OPT_LEVEL\n"\
|
|
||||||
"#define MIN_OPT_LEVEL %d\n"\
|
|
||||||
"#endif\n", elua_opt_lvl);
|
|
||||||
|
|
||||||
if (nomoduleglobal) {
|
if (nomoduleglobal) {
|
||||||
Printf(f_runtime, "#define SWIG_LUA_NO_MODULE_GLOBAL\n");
|
Printf(f_runtime, "#define SWIG_LUA_NO_MODULE_GLOBAL\n");
|
||||||
|
|
@ -1284,8 +1274,7 @@ public:
|
||||||
} else if (eluac_ltr) {
|
} else if (eluac_ltr) {
|
||||||
String *ns_methods_tab = Getattr(nspaceHash, "methods");
|
String *ns_methods_tab = Getattr(nspaceHash, "methods");
|
||||||
assert(ns_methods_tab != 0);
|
assert(ns_methods_tab != 0);
|
||||||
Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", \
|
Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", constructor_name, ")", "},\n", NIL);
|
||||||
constructor_name, ")", "},\n", NIL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (have_destructor) {
|
if (have_destructor) {
|
||||||
|
|
@ -1331,7 +1320,6 @@ public:
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, print class static part
|
// First, print class static part
|
||||||
printNamespaceDefinition(class_static_nspace, class_symname, f_wrappers);
|
printNamespaceDefinition(class_static_nspace, class_symname, f_wrappers);
|
||||||
|
|
||||||
|
|
@ -1341,7 +1329,8 @@ public:
|
||||||
Printv(f_wrappers, "static const char *swig_", mangled_class_fq_symname, "_base_names[] = {", base_class_names, "0};\n", NIL);
|
Printv(f_wrappers, "static const char *swig_", mangled_class_fq_symname, "_base_names[] = {", base_class_names, "0};\n", NIL);
|
||||||
Delete(base_class_names);
|
Delete(base_class_names);
|
||||||
|
|
||||||
Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname, " = { \"", class_symname, "\", \"", class_fq_symname,"\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL);
|
Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_class_fq_symname, " = { \"", class_symname, "\", \"", class_fq_symname, "\", &SWIGTYPE",
|
||||||
|
SwigType_manglestr(t), ",", NIL);
|
||||||
|
|
||||||
if (have_constructor) {
|
if (have_constructor) {
|
||||||
Printv(f_wrappers, constructor_name, NIL);
|
Printv(f_wrappers, constructor_name, NIL);
|
||||||
|
|
@ -1357,8 +1346,7 @@ public:
|
||||||
Printf(f_wrappers, ",0");
|
Printf(f_wrappers, ",0");
|
||||||
}
|
}
|
||||||
Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname"));
|
Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname"));
|
||||||
Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n",
|
Printf(f_wrappers, ", swig_%s_bases, swig_%s_base_names };\n\n", mangled_class_fq_symname, mangled_class_fq_symname);
|
||||||
mangled_class_fq_symname, mangled_class_fq_symname);
|
|
||||||
|
|
||||||
current[NO_CPP] = true;
|
current[NO_CPP] = true;
|
||||||
Delete(class_static_nspace);
|
Delete(class_static_nspace);
|
||||||
|
|
@ -1586,8 +1574,7 @@ public:
|
||||||
emitted into the C/C++ code.
|
emitted into the C/C++ code.
|
||||||
Basically is is a lot of search & replacing of odd sequences
|
Basically is is a lot of search & replacing of odd sequences
|
||||||
*/
|
*/
|
||||||
void EscapeCode(String* str)
|
void EscapeCode(String *str) {
|
||||||
{
|
|
||||||
//Printf(f_runtime,"/* original luacode:[[[\n%s\n]]]\n*/\n",str);
|
//Printf(f_runtime,"/* original luacode:[[[\n%s\n]]]\n*/\n",str);
|
||||||
Chop(str); // trim
|
Chop(str); // trim
|
||||||
Replace(str, "\\", "\\\\", DOH_REPLACE_ANY); // \ to \\ (this must be done first)
|
Replace(str, "\\", "\\\\", DOH_REPLACE_ANY); // \ to \\ (this must be done first)
|
||||||
|
|
@ -1608,8 +1595,7 @@ public:
|
||||||
* XXX:name - name of the C array that stores data for component
|
* XXX:name - name of the C array that stores data for component
|
||||||
* XXX:decl - statement with forward declaration of this array;
|
* XXX:decl - statement with forward declaration of this array;
|
||||||
*/
|
*/
|
||||||
Hash* getNamespaceHash(String *nspace, bool reg = true)
|
Hash *getNamespaceHash(String *nspace, bool reg = true) {
|
||||||
{
|
|
||||||
Hash *nspace_hash = Getattr(namespaces_hash, nspace ? nspace : "");
|
Hash *nspace_hash = Getattr(namespaces_hash, nspace ? nspace : "");
|
||||||
if (nspace_hash != 0)
|
if (nspace_hash != 0)
|
||||||
return nspace_hash;
|
return nspace_hash;
|
||||||
|
|
@ -1758,8 +1744,7 @@ public:
|
||||||
* if "lua:no_namespaces" is set, then array for "namespaces" won't be printed
|
* if "lua:no_namespaces" is set, then array for "namespaces" won't be printed
|
||||||
* if "lua:no_classes" is set, then array for "classes" won't be printed
|
* if "lua:no_classes" is set, then array for "classes" won't be printed
|
||||||
* */
|
* */
|
||||||
void closeNamespaceHash(String *nspace, File *output)
|
void closeNamespaceHash(String *nspace, File *output) {
|
||||||
{
|
|
||||||
Hash *nspace_hash = Getattr(namespaces_hash, nspace);
|
Hash *nspace_hash = Getattr(namespaces_hash, nspace);
|
||||||
assert(nspace_hash != 0);
|
assert(nspace_hash != 0);
|
||||||
assert(Getattr(nspace_hash, "lua:closed") == 0);
|
assert(Getattr(nspace_hash, "lua:closed") == 0);
|
||||||
|
|
@ -1846,10 +1831,11 @@ public:
|
||||||
Printv(output, "\n", NIL);
|
Printv(output, "\n", NIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compareByLen( const DOH* f, const DOH* s) { return Len(s) - Len(f); }
|
static int compareByLen(const DOH *f, const DOH *s) {
|
||||||
|
return Len(s) - Len(f);
|
||||||
|
}
|
||||||
// Recursively close all non-closed namespaces. Prints data to dataOutput,
|
// Recursively close all non-closed namespaces. Prints data to dataOutput,
|
||||||
void closeNamespaces(File *dataOutput)
|
void closeNamespaces(File *dataOutput) {
|
||||||
{
|
|
||||||
// Special handling for empty module.
|
// Special handling for empty module.
|
||||||
if (Getattr(namespaces_hash, "") == 0) {
|
if (Getattr(namespaces_hash, "") == 0) {
|
||||||
// Module is empty. Create hash for global scope in order to have swig__Global
|
// Module is empty. Create hash for global scope in order to have swig__Global
|
||||||
|
|
@ -1885,8 +1871,7 @@ public:
|
||||||
// You can call this function as many times as necessary.
|
// You can call this function as many times as necessary.
|
||||||
// 'name' is a user-visible name that this namespace will have in Lua. It shouldn't
|
// 'name' is a user-visible name that this namespace will have in Lua. It shouldn't
|
||||||
// be fully qualified name, just it's own name.
|
// be fully qualified name, just it's own name.
|
||||||
void printNamespaceDefinition(String *nspace, String* name, File *output)
|
void printNamespaceDefinition(String *nspace, String *name, File *output) {
|
||||||
{
|
|
||||||
Hash *nspace_hash = getNamespaceHash(nspace, false);
|
Hash *nspace_hash = getNamespaceHash(nspace, false);
|
||||||
|
|
||||||
String *cname = Getattr(nspace_hash, "cname"); // cname - name of the C structure that describes namespace
|
String *cname = Getattr(nspace_hash, "cname"); // cname - name of the C structure that describes namespace
|
||||||
|
|
@ -1909,9 +1894,7 @@ public:
|
||||||
tab4, attr_tab_name, ",\n",
|
tab4, attr_tab_name, ",\n",
|
||||||
tab4, const_tab_name, ",\n",
|
tab4, const_tab_name, ",\n",
|
||||||
tab4, (has_classes) ? classes_tab_name : null_string, ",\n",
|
tab4, (has_classes) ? classes_tab_name : null_string, ",\n",
|
||||||
tab4, (has_namespaces)?namespaces_tab_name:null_string, "\n};\n",
|
tab4, (has_namespaces) ? namespaces_tab_name : null_string, "\n};\n", NIL);
|
||||||
NIL
|
|
||||||
);
|
|
||||||
Delete(null_string);
|
Delete(null_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1964,8 +1947,7 @@ public:
|
||||||
|
|
||||||
// Function creates fully qualified name of given symbol. Current NSpace and current class
|
// Function creates fully qualified name of given symbol. Current NSpace and current class
|
||||||
// are used
|
// are used
|
||||||
String* fully_qualified_name(const_String_or_char_ptr name)
|
String *fully_qualified_name(const_String_or_char_ptr name) {
|
||||||
{
|
|
||||||
assert(name != 0);
|
assert(name != 0);
|
||||||
String *scope = 0;
|
String *scope = 0;
|
||||||
if (getCurrentClass())
|
if (getCurrentClass())
|
||||||
|
|
@ -1984,8 +1966,7 @@ public:
|
||||||
|
|
||||||
// Input: symname
|
// Input: symname
|
||||||
// Output - wrapper around fully qualified form of symname
|
// Output - wrapper around fully qualified form of symname
|
||||||
String* symname_wrapper( String *symname)
|
String *symname_wrapper(String *symname) {
|
||||||
{
|
|
||||||
String *fqname = fully_qualified_name(symname);
|
String *fqname = fully_qualified_name(symname);
|
||||||
String *wname = Swig_name_wrapper(fqname);
|
String *wname = Swig_name_wrapper(fqname);
|
||||||
Delete(fqname);
|
Delete(fqname);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue