Comments added to interface feature implementation and cosmetic code changes
This commit is contained in:
parent
d0fb0ae801
commit
645147a5b2
3 changed files with 52 additions and 37 deletions
|
|
@ -1651,14 +1651,14 @@ public:
|
|||
String *ret = Getattr(n, "interface:qname");
|
||||
if (!ret) {
|
||||
String *nspace = Getattr(n, "sym:nspace");
|
||||
String *iname = Getattr(n, "feature:interface:name");
|
||||
String *interface_name = Getattr(n, "feature:interface:name");
|
||||
if (nspace) {
|
||||
if (namespce)
|
||||
ret = NewStringf("%s.%s.%s", namespce, nspace, iname);
|
||||
ret = NewStringf("%s.%s.%s", namespce, nspace, interface_name);
|
||||
else
|
||||
ret = NewStringf("%s.%s", nspace, iname);
|
||||
ret = NewStringf("%s.%s", nspace, interface_name);
|
||||
} else {
|
||||
ret = Copy(iname);
|
||||
ret = Copy(interface_name);
|
||||
}
|
||||
Setattr(n, "interface:qname", ret);
|
||||
}
|
||||
|
|
@ -1670,23 +1670,23 @@ public:
|
|||
for (Iterator it = First(keys); it.item; it = Next(it)) {
|
||||
Node *base = Getattr(base_list, it.item);
|
||||
String *c_baseclass = SwigType_namestr(Getattr(base, "name"));
|
||||
String *iname = getQualifiedInterfaceName(base);
|
||||
String *interface_name = getQualifiedInterfaceName(base);
|
||||
if (Len(interface_list))
|
||||
Append(interface_list, ", ");
|
||||
Append(interface_list, iname);
|
||||
Append(interface_list, interface_name);
|
||||
|
||||
Printf(interface_upcasts, "\n");
|
||||
Printf(interface_upcasts, " [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]\n");
|
||||
String *upcast_name = 0;
|
||||
if (String *cptr_func = Getattr(base, "feature:interface:cptr"))
|
||||
upcast_name = NewStringf("%s.%s", iname, cptr_func);
|
||||
upcast_name = NewStringf("%s.%s", interface_name, cptr_func);
|
||||
else
|
||||
upcast_name = NewStringf("%s.SWIGInterfaceUpcast", iname);
|
||||
upcast_name = NewStringf("%s.SWIGInterfaceUpcast", interface_name);
|
||||
Printf(interface_upcasts, " global::System.Runtime.InteropServices.HandleRef %s() {\n", upcast_name);
|
||||
Replaceall(upcast_name, ".", "_");
|
||||
String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, upcast_name);
|
||||
String *wname = Swig_name_wrapper(upcast_method);
|
||||
Printf(interface_upcasts, " return new global::System.Runtime.InteropServices.HandleRef((%s)this, %s.%s(swigCPtr.Handle));\n", iname, imclass_name, upcast_method);
|
||||
Printf(interface_upcasts, " return new global::System.Runtime.InteropServices.HandleRef((%s)this, %s.%s(swigCPtr.Handle));\n", interface_name, imclass_name, upcast_method);
|
||||
Printf(interface_upcasts, " }\n");
|
||||
Printv(imclass_cppcasts_code, "\n [global::System.Runtime.InteropServices.DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL);
|
||||
Printf(imclass_cppcasts_code, " public static extern global::System.IntPtr %s(global::System.IntPtr jarg1);\n", upcast_method);
|
||||
|
|
@ -1966,9 +1966,9 @@ public:
|
|||
Delete(baseclass);
|
||||
}
|
||||
|
||||
void emitInterfaceDeclaration(Node *n, String *iname, File *f_interface) {
|
||||
void emitInterfaceDeclaration(Node *n, String *interface_name, File *f_interface) {
|
||||
Printv(f_interface, typemapLookup(n, "csimports", Getattr(n, "classtypeobj"), WARN_NONE), "\n", NIL);
|
||||
Printf(f_interface, "public interface %s", iname);
|
||||
Printf(f_interface, "public interface %s", interface_name);
|
||||
if (List *baselist = Getattr(n, "bases")) {
|
||||
String *bases = 0;
|
||||
for (Iterator base = First(baselist); base.item; base = Next(base)) {
|
||||
|
|
@ -2070,15 +2070,15 @@ public:
|
|||
|
||||
if (Getattr(n, "feature:interface")) {
|
||||
interface_class_code = NewStringEmpty();
|
||||
String *iname = Getattr(n, "feature:interface:name");
|
||||
if (!iname) {
|
||||
String *interface_name = Getattr(n, "feature:interface:name");
|
||||
if (!interface_name) {
|
||||
Swig_error(Getfile(n), Getline(n), "Interface %s has no name attribute", proxy_class_name);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
String *output_directory = outputDirectory(nspace);
|
||||
f_interface = getOutputFile(output_directory, iname);
|
||||
f_interface = getOutputFile(output_directory, interface_name);
|
||||
addOpenNamespace(nspace, f_interface);
|
||||
emitInterfaceDeclaration(n, iname, f_interface);
|
||||
emitInterfaceDeclaration(n, interface_name, f_interface);
|
||||
Delete(output_directory);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1756,16 +1756,16 @@ public:
|
|||
for (Iterator it = First(keys); it.item; it = Next(it)) {
|
||||
Node *base = Getattr(base_list, it.item);
|
||||
String *c_baseclass = SwigType_namestr(Getattr(base, "name"));
|
||||
String *iname = Getattr(base, "feature:interface:name");
|
||||
String *interface_name = Getattr(base, "feature:interface:name");
|
||||
if (Len(interface_list))
|
||||
Append(interface_list, ", ");
|
||||
Append(interface_list, iname);
|
||||
Append(interface_list, interface_name);
|
||||
|
||||
String *upcast_name = 0;
|
||||
if (String *cptr_func = Getattr(base, "feature:interface:cptr"))
|
||||
upcast_name = NewStringf("%s", cptr_func);
|
||||
else
|
||||
upcast_name = NewStringf("%s_SWIGInterfaceUpcast", iname);
|
||||
upcast_name = NewStringf("%s_SWIGInterfaceUpcast", interface_name);
|
||||
Printf(interface_upcasts, "\n");
|
||||
Printf(interface_upcasts, " public long %s() {\n", upcast_name);
|
||||
Replaceall(upcast_name, ".", "_");
|
||||
|
|
@ -1998,7 +1998,7 @@ public:
|
|||
Delete(baseclass);
|
||||
}
|
||||
|
||||
void emitInterfaceDeclaration(Node *n, String *iname, File *f_interface, String *nspace) {
|
||||
void emitInterfaceDeclaration(Node *n, String *interface_name, File *f_interface, String *nspace) {
|
||||
if (package || nspace) {
|
||||
Printf(f_interface, "package ");
|
||||
if (package)
|
||||
|
|
@ -2009,7 +2009,7 @@ public:
|
|||
}
|
||||
|
||||
Printv(f_interface, typemapLookup(n, "javaimports", Getattr(n, "classtypeobj"), WARN_NONE), "\n", NIL);
|
||||
Printf(f_interface, "public interface %s", iname);
|
||||
Printf(f_interface, "public interface %s", interface_name);
|
||||
if (List *baselist = Getattr(n, "bases")) {
|
||||
String *bases = 0;
|
||||
for (Iterator base = First(baselist); base.item; base = Next(base)) {
|
||||
|
|
@ -2032,7 +2032,7 @@ public:
|
|||
if (String *cptr_func = Getattr(n, "feature:interface:cptr"))
|
||||
Printf(f_interface, " long %s();\n", cptr_func);
|
||||
else
|
||||
Printf(f_interface, " long %s_SWIGInterfaceUpcast();\n", iname);
|
||||
Printf(f_interface, " long %s_SWIGInterfaceUpcast();\n", interface_name);
|
||||
}
|
||||
|
||||
int classDeclaration(Node *n) {
|
||||
|
|
@ -2147,13 +2147,13 @@ public:
|
|||
|
||||
if (Getattr(n, "feature:interface")) {
|
||||
interface_class_code = NewStringEmpty();
|
||||
String *iname = Getattr(n, "feature:interface:name");
|
||||
if (!iname) {
|
||||
String *interface_name = Getattr(n, "feature:interface:name");
|
||||
if (!interface_name) {
|
||||
Swig_error(Getfile(n), Getline(n), "Interface %s has no name attribute", proxy_class_name);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
String *output_directory = outputDirectory(nspace);
|
||||
String *filen = NewStringf("%s%s.java", output_directory, iname);
|
||||
String *filen = NewStringf("%s%s.java", output_directory, interface_name);
|
||||
f_interface = NewFile(filen, "w", SWIG_output_files());
|
||||
if (!f_interface) {
|
||||
FileErrorDisplay(filen);
|
||||
|
|
@ -2161,7 +2161,7 @@ public:
|
|||
}
|
||||
Append(filenames_list, filen); // file name ownership goes to the list
|
||||
emitBanner(f_interface);
|
||||
emitInterfaceDeclaration(n, iname, f_interface, nspace);
|
||||
emitInterfaceDeclaration(n, interface_name, f_interface, nspace);
|
||||
Delete(filen);
|
||||
Delete(output_directory);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3797,6 +3797,7 @@ String *Language::defaultExternalRuntimeFilename() {
|
|||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Language::replaceSpecialVariables()
|
||||
*
|
||||
* Language modules should implement this if special variables are to be handled
|
||||
* correctly in the $typemap(...) special variable macro.
|
||||
* method - typemap method name
|
||||
|
|
@ -3817,18 +3818,24 @@ Hash *Language::getClassHash() const {
|
|||
return classhash;
|
||||
}
|
||||
|
||||
// 4 methods below are used in C# && Java module "feature:interface" implementation
|
||||
//
|
||||
// Collect all not abstract methods from the bases marked as "interface"
|
||||
static void collect_interface_methods(Node *n, List *methods) {
|
||||
if (Hash *bases = Getattr(n, "interface:bases")){
|
||||
/* -----------------------------------------------------------------------------
|
||||
* collect_interface_methods()
|
||||
*
|
||||
* Create a list of all the methods from the base classes of class n that are
|
||||
* marked as an interface. The resulting list is thus the list of methods that
|
||||
* need to be implemented in order for n to be non-abstract.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static List *collect_interface_methods(Node *n) {
|
||||
List *methods = NewList();
|
||||
if (Hash *bases = Getattr(n, "interface:bases")) {
|
||||
List *keys = Keys(bases);
|
||||
for (Iterator base = First(keys); base.item; base = Next(base)) {
|
||||
Node *cls = Getattr(bases, base.item);
|
||||
if (cls == n)
|
||||
continue;
|
||||
for (Node *child = firstChild(cls); child; child = nextSibling(child)) {
|
||||
if (strcmp(Char(nodeType(child)), "cdecl") == 0) {
|
||||
if (Cmp(nodeType(child), "cdecl") == 0) {
|
||||
if (GetFlag(child, "feature:ignore") || Getattr(child, "interface:owner"))
|
||||
continue; // skip methods propagated to bases
|
||||
Node *m = Copy(child);
|
||||
|
|
@ -3841,6 +3848,7 @@ static void collect_interface_methods(Node *n, List *methods) {
|
|||
}
|
||||
Delete(keys);
|
||||
}
|
||||
return methods;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -3865,7 +3873,7 @@ static void collect_interface_bases(Hash *bases, Node *n) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* collect_and_set_interface_bases()
|
||||
* collect_interface_base_classes()
|
||||
*
|
||||
* Create a hash containing all the classes up the inheritance hierarchy
|
||||
* marked with feature:interface (including this class n).
|
||||
|
|
@ -3874,7 +3882,7 @@ static void collect_interface_bases(Hash *bases, Node *n) {
|
|||
* The idea is to find all the base interfaces that a class must implement.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void collect_and_set_interface_bases(Node *n) {
|
||||
static void collect_interface_base_classes(Node *n) {
|
||||
Hash *interface_bases = NewHash();
|
||||
collect_interface_bases(interface_bases, n);
|
||||
if (Len(interface_bases) == 0)
|
||||
|
|
@ -3883,11 +3891,18 @@ static void collect_and_set_interface_bases(Node *n) {
|
|||
Setattr(n, "interface:bases", interface_bases);
|
||||
}
|
||||
|
||||
// Append all the interface methods not implemented in the current class, so that it would not be abstract
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_propagate_interface_methods()
|
||||
*
|
||||
* Find all the base classes marked as an interface (with feature:interface) for
|
||||
* class node n. For each of these, add all of its methods as methods of n so that
|
||||
* n is not abstract. If class n is also marked as an interface, it will remain
|
||||
* abstract and not have any methods added.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_propagate_interface_methods(Node *n) {
|
||||
collect_and_set_interface_bases(n);
|
||||
List *methods = NewList();
|
||||
collect_interface_methods(n, methods);
|
||||
collect_interface_base_classes(n);
|
||||
List *methods = collect_interface_methods(n);
|
||||
bool is_interface = Getattr(n, "feature:interface") != 0;
|
||||
for (Iterator mi = First(methods); mi.item; mi = Next(mi)) {
|
||||
if (!is_interface && GetFlag(mi.item, "abstract"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue