Slightly efficiency improvements for packages/namespaces/

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11933 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-03-10 07:50:32 +00:00
commit 8d227bce62
2 changed files with 45 additions and 43 deletions

View file

@ -181,7 +181,7 @@ public:
String *nspace = Getattr(n, "sym:nspace"); String *nspace = Getattr(n, "sym:nspace");
String *symname = Getattr(n, "sym:name"); String *symname = Getattr(n, "sym:name");
if (nspace) { if (nspace) {
if (Len(namespce) > 0) if (namespce)
proxyname = NewStringf("%s.%s.%s", namespce, nspace, symname); proxyname = NewStringf("%s.%s.%s", namespce, nspace, symname);
else else
proxyname = NewStringf("%s.%s", nspace, symname); proxyname = NewStringf("%s.%s", nspace, symname);
@ -239,6 +239,10 @@ public:
if (argv[i + 1]) { if (argv[i + 1]) {
namespce = NewString(""); namespce = NewString("");
Printf(namespce, argv[i + 1]); Printf(namespce, argv[i + 1]);
if (Len(namespce) == 0) {
Delete(namespce);
namespce = 0;
}
Swig_mark_arg(i); Swig_mark_arg(i);
Swig_mark_arg(i + 1); Swig_mark_arg(i + 1);
i++; i++;
@ -378,8 +382,6 @@ public:
dmethods_table = NewHash(); dmethods_table = NewHash();
n_dmethods = 0; n_dmethods = 0;
n_directors = 0; n_directors = 0;
if (!namespce)
namespce = NewString("");
if (!dllimport) if (!dllimport)
dllimport = Copy(module_class_name); dllimport = Copy(module_class_name);
@ -439,7 +441,7 @@ public:
// Start writing out the intermediary class file // Start writing out the intermediary class file
emitBanner(f_im); emitBanner(f_im);
addOpenNamespace(namespce, 0, f_im); addOpenNamespace(0, f_im);
if (imclass_imports) if (imclass_imports)
Printf(f_im, "%s\n", imclass_imports); Printf(f_im, "%s\n", imclass_imports);
@ -463,7 +465,7 @@ public:
// Finish off the class // Finish off the class
Printf(f_im, "}\n"); Printf(f_im, "}\n");
addCloseNamespace(namespce, 0, f_im); addCloseNamespace(0, f_im);
Close(f_im); Close(f_im);
} }
@ -483,7 +485,7 @@ public:
// Start writing out the module class file // Start writing out the module class file
emitBanner(f_module); emitBanner(f_module);
addOpenNamespace(namespce, 0, f_module); addOpenNamespace(0, f_module);
if (module_imports) if (module_imports)
Printf(f_module, "%s\n", module_imports); Printf(f_module, "%s\n", module_imports);
@ -515,7 +517,7 @@ public:
// Finish off the class // Finish off the class
Printf(f_module, "}\n"); Printf(f_module, "}\n");
addCloseNamespace(namespce, 0, f_module); addCloseNamespace(0, f_module);
Close(f_module); Close(f_module);
} }
@ -1134,7 +1136,7 @@ public:
if (!nspace) { if (!nspace) {
full_imclass_name = NewStringf("%s", imclass_name); full_imclass_name = NewStringf("%s", imclass_name);
} else { } else {
if (Len(namespce) > 0) { if (namespce) {
full_imclass_name = NewStringf("%s.%s", namespce, imclass_name); full_imclass_name = NewStringf("%s.%s", namespce, imclass_name);
} else { } else {
full_imclass_name = NewStringf("%s", imclass_name); full_imclass_name = NewStringf("%s", imclass_name);
@ -1214,12 +1216,12 @@ public:
// Start writing out the enum file // Start writing out the enum file
emitBanner(f_enum); emitBanner(f_enum);
addOpenNamespace(namespce, nspace, f_enum); addOpenNamespace(nspace, f_enum);
Printv(f_enum, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements Printv(f_enum, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements
"\n", enum_code, "\n", NIL); "\n", enum_code, "\n", NIL);
addCloseNamespace(namespce, nspace, f_enum); addCloseNamespace(nspace, f_enum);
Close(f_enum); Close(f_enum);
Delete(output_directory); Delete(output_directory);
} }
@ -1820,7 +1822,7 @@ public:
SWIG_exit(EXIT_FAILURE); SWIG_exit(EXIT_FAILURE);
} }
} else { } else {
if (Len(namespce) > 0) { if (namespce) {
full_proxy_class_name = NewStringf("%s.%s.%s", namespce, nspace, proxy_class_name); full_proxy_class_name = NewStringf("%s.%s.%s", namespce, nspace, proxy_class_name);
full_imclass_name = NewStringf("%s.%s", namespce, imclass_name); full_imclass_name = NewStringf("%s.%s", namespce, imclass_name);
} else { } else {
@ -1846,7 +1848,7 @@ public:
// Start writing out the proxy class file // Start writing out the proxy class file
emitBanner(f_proxy); emitBanner(f_proxy);
addOpenNamespace(namespce, nspace, f_proxy); addOpenNamespace(nspace, f_proxy);
Clear(proxy_class_def); Clear(proxy_class_def);
Clear(proxy_class_code); Clear(proxy_class_code);
@ -1878,7 +1880,7 @@ public:
Printv(f_proxy, proxy_class_constants_code, NIL); Printv(f_proxy, proxy_class_constants_code, NIL);
Printf(f_proxy, "}\n"); Printf(f_proxy, "}\n");
addCloseNamespace(namespce, nspace, f_proxy); addCloseNamespace(nspace, f_proxy);
Close(f_proxy); Close(f_proxy);
f_proxy = NULL; f_proxy = NULL;
@ -2959,7 +2961,7 @@ public:
// global enum or enum in a namespace // global enum or enum in a namespace
String *nspace = Getattr(n, "sym:nspace"); String *nspace = Getattr(n, "sym:nspace");
if (nspace) { if (nspace) {
if (Len(namespce) > 0) if (namespce)
enumname = NewStringf("%s.%s.%s", namespce, nspace, symname); enumname = NewStringf("%s.%s.%s", namespce, nspace, symname);
else else
enumname = NewStringf("%s.%s", nspace, symname); enumname = NewStringf("%s.%s", nspace, symname);
@ -3111,7 +3113,7 @@ public:
// Start writing out the type wrapper class file // Start writing out the type wrapper class file
emitBanner(f_swigtype); emitBanner(f_swigtype);
addOpenNamespace(namespce, 0, f_swigtype); addOpenNamespace(0, f_swigtype);
// Pure C# baseclass and interfaces // Pure C# baseclass and interfaces
const String *pure_baseclass = typemapLookup(n, "csbase", type, WARN_NONE); const String *pure_baseclass = typemapLookup(n, "csbase", type, WARN_NONE);
@ -3140,7 +3142,7 @@ public:
Printv(f_swigtype, swigtype, NIL); Printv(f_swigtype, swigtype, NIL);
addCloseNamespace(namespce, 0, f_swigtype); addCloseNamespace(0, f_swigtype);
Close(f_swigtype); Close(f_swigtype);
Delete(swigtype); Delete(swigtype);
@ -3215,12 +3217,12 @@ public:
* addOpenNamespace() * addOpenNamespace()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void addOpenNamespace(const String *namspace, const String *nspace, File *file) { void addOpenNamespace(const String *nspace, File *file) {
if (namspace) { if (namespce) {
if (Len(namspace) > 0 || nspace) { if (namespce || nspace) {
Printf(file, "namespace "); Printf(file, "namespace ");
if (Len(namspace) > 0) if (namespce)
Printv(file, namspace, nspace ? "." : "", NIL); Printv(file, namespce, nspace ? "." : "", NIL);
if (nspace) if (nspace)
Printv(file, nspace, NIL); Printv(file, nspace, NIL);
Printf(file, " {\n"); Printf(file, " {\n");
@ -3232,9 +3234,9 @@ public:
* addCloseNamespace() * addCloseNamespace()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void addCloseNamespace(const String *namspace, const String *nspace, File *file) { void addCloseNamespace(const String *nspace, File *file) {
if (namspace) if (namespce)
if (Len(namspace) > 0 || nspace) if (namespce || nspace)
Printf(file, "\n}\n"); Printf(file, "\n}\n");
} }
@ -3303,8 +3305,7 @@ public:
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
* emitDirectorExtraMethods() * emitDirectorExtraMethods()
* *
* This is where the director connect method is * This is where the director connect method is generated.
* generated.
*--------------------------------------------------------------------*/ *--------------------------------------------------------------------*/
void emitDirectorExtraMethods(Node *n) { void emitDirectorExtraMethods(Node *n) {
if (!Swig_directorclass(n)) if (!Swig_directorclass(n))

View file

@ -176,7 +176,7 @@ public:
String *nspace = Getattr(n, "sym:nspace"); String *nspace = Getattr(n, "sym:nspace");
String *symname = Getattr(n, "sym:name"); String *symname = Getattr(n, "sym:name");
if (nspace) { if (nspace) {
if (Len(package) > 0) if (package)
proxyname = NewStringf("%s.%s.%s", package, nspace, symname); proxyname = NewStringf("%s.%s.%s", package, nspace, symname);
else else
proxyname = NewStringf("%s.%s", nspace, symname); proxyname = NewStringf("%s.%s", nspace, symname);
@ -234,6 +234,10 @@ public:
if (argv[i + 1]) { if (argv[i + 1]) {
package = NewString(""); package = NewString("");
Printf(package, argv[i + 1]); Printf(package, argv[i + 1]);
if (Len(package) == 0) {
Delete(package);
package = 0;
}
Swig_mark_arg(i); Swig_mark_arg(i);
Swig_mark_arg(i + 1); Swig_mark_arg(i + 1);
i++; i++;
@ -390,8 +394,6 @@ public:
dmethods_table = NewHash(); dmethods_table = NewHash();
n_dmethods = 0; n_dmethods = 0;
n_directors = 0; n_directors = 0;
if (!package)
package = NewString("");
jnipackage = NewString(""); jnipackage = NewString("");
package_path = NewString(""); package_path = NewString("");
@ -420,7 +422,7 @@ public:
String *wrapper_name = NewString(""); String *wrapper_name = NewString("");
if (Len(package)) { if (package) {
String *jniname = makeValidJniName(package); String *jniname = makeValidJniName(package);
Printv(jnipackage, jniname, NIL); Printv(jnipackage, jniname, NIL);
Delete(jniname); Delete(jniname);
@ -467,7 +469,7 @@ public:
// Start writing out the intermediary class file // Start writing out the intermediary class file
emitBanner(f_im); emitBanner(f_im);
if (Len(package) > 0) if (package)
Printf(f_im, "package %s;\n", package); Printf(f_im, "package %s;\n", package);
if (imclass_imports) if (imclass_imports)
@ -518,7 +520,7 @@ public:
// Start writing out the module class file // Start writing out the module class file
emitBanner(f_module); emitBanner(f_module);
if (Len(package) > 0) if (package)
Printf(f_module, "package %s;\n", package); Printf(f_module, "package %s;\n", package);
if (module_imports) if (module_imports)
@ -570,7 +572,7 @@ public:
// Start writing out the Java constants interface file // Start writing out the Java constants interface file
emitBanner(f_module); emitBanner(f_module);
if (Len(package) > 0) if (package)
Printf(f_module, "package %s;\n", package); Printf(f_module, "package %s;\n", package);
if (module_imports) if (module_imports)
@ -1195,7 +1197,7 @@ public:
if (!nspace) { if (!nspace) {
full_imclass_name = NewStringf("%s", imclass_name); full_imclass_name = NewStringf("%s", imclass_name);
} else { } else {
if (Len(package) > 0) { if (package) {
full_imclass_name = NewStringf("%s.%s", package, imclass_name); full_imclass_name = NewStringf("%s.%s", package, imclass_name);
} else { } else {
full_imclass_name = NewStringf("%s", imclass_name); full_imclass_name = NewStringf("%s", imclass_name);
@ -1277,9 +1279,9 @@ public:
// Start writing out the enum file // Start writing out the enum file
emitBanner(f_enum); emitBanner(f_enum);
if (Len(package) > 0 || nspace) { if (package || nspace) {
Printf(f_enum, "package "); Printf(f_enum, "package ");
if (Len(package) > 0) if (package)
Printv(f_enum, package, nspace ? "." : "", NIL); Printv(f_enum, package, nspace ? "." : "", NIL);
if (nspace) if (nspace)
Printv(f_enum, nspace, NIL); Printv(f_enum, nspace, NIL);
@ -1828,7 +1830,7 @@ public:
SWIG_exit(EXIT_FAILURE); SWIG_exit(EXIT_FAILURE);
} }
} else { } else {
if (Len(package) > 0) { if (package) {
full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name);
full_imclass_name = NewStringf("%s.%s", package, imclass_name); full_imclass_name = NewStringf("%s.%s", package, imclass_name);
} else { } else {
@ -1856,9 +1858,9 @@ public:
// Start writing out the proxy class file // Start writing out the proxy class file
emitBanner(f_proxy); emitBanner(f_proxy);
if (Len(package) > 0 || nspace) { if (package || nspace) {
Printf(f_proxy, "package "); Printf(f_proxy, "package ");
if (Len(package) > 0) if (package)
Printv(f_proxy, package, nspace ? "." : "", NIL); Printv(f_proxy, package, nspace ? "." : "", NIL);
if (nspace) if (nspace)
Printv(f_proxy, nspace, NIL); Printv(f_proxy, nspace, NIL);
@ -2807,7 +2809,7 @@ public:
// global enum or enum in a namespace // global enum or enum in a namespace
String *nspace = Getattr(n, "sym:nspace"); String *nspace = Getattr(n, "sym:nspace");
if (nspace) { if (nspace) {
if (Len(package) > 0) if (package)
enumname = NewStringf("%s.%s.%s", package, nspace, symname); enumname = NewStringf("%s.%s.%s", package, nspace, symname);
else else
enumname = NewStringf("%s.%s", nspace, symname); enumname = NewStringf("%s.%s", nspace, symname);
@ -2963,7 +2965,7 @@ public:
// Start writing out the type wrapper class file // Start writing out the type wrapper class file
emitBanner(f_swigtype); emitBanner(f_swigtype);
if (Len(package) > 0) if (package)
Printf(f_swigtype, "package %s;\n", package); Printf(f_swigtype, "package %s;\n", package);
// Pure Java baseclass and interfaces // Pure Java baseclass and interfaces
@ -3274,8 +3276,7 @@ public:
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
* emitDirectorExtraMethods() * emitDirectorExtraMethods()
* *
* This is where the $javaclassname_director_connect is * This is where the director connect method is generated.
* generated.
*--------------------------------------------------------------------*/ *--------------------------------------------------------------------*/
void emitDirectorExtraMethods(Node *n) { void emitDirectorExtraMethods(Node *n) {
if (!Swig_directorclass(n)) if (!Swig_directorclass(n))