summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorng420 <nish.gupta01@gmail.com>2016-08-16 00:30:47 +0100
committerng420 <nish.gupta01@gmail.com>2016-08-16 00:30:47 +0100
commitd522d41d73dee4b3fb7de644cbac197492b7767d (patch)
tree9b4e3759aa1232afce3454bf41a90adee5dfcbf8
parentdbe7630278aee8a0075618fbdb95a675d86d894c (diff)
downloadswig-d522d41d73dee4b3fb7de644cbac197492b7767d.tar.gz
Reimplement overloading in the spirit of swig
-rw-r--r--Examples/test-suite/hhvm/Makefile.in2
-rw-r--r--Lib/hhvm/hhvm.swg28
-rw-r--r--Lib/hhvm/std_string.i2
-rw-r--r--Source/Modules/hhvm.cxx62
4 files changed, 53 insertions, 41 deletions
diff --git a/Examples/test-suite/hhvm/Makefile.in b/Examples/test-suite/hhvm/Makefile.in
index bd614f55d..3a3d3f56d 100644
--- a/Examples/test-suite/hhvm/Makefile.in
+++ b/Examples/test-suite/hhvm/Makefile.in
@@ -54,6 +54,7 @@ FAILING_CPP_TESTS = \
li_std_map \
li_std_pair \
li_std_pair_using \
+ li_std_string \
li_std_vector \
li_std_vector_enum \
li_std_vector_member_var \
@@ -75,6 +76,7 @@ FAILING_CPP_TESTS = \
overload_method \
overload_rename \
overload_return_type \
+ overload_simple \
overload_template \
overload_template_fast \
pointer_reference \
diff --git a/Lib/hhvm/hhvm.swg b/Lib/hhvm/hhvm.swg
index d15281c2a..657098b9a 100644
--- a/Lib/hhvm/hhvm.swg
+++ b/Lib/hhvm/hhvm.swg
@@ -320,49 +320,37 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
const long long &, const unsigned long long &,
enum SWIGTYPE
{
- int64_t $result;
_v = $input.isInteger();
- if (_v) $result = $input.toInt64Val();
}
%typecheck(SWIG_TYPECHECK_DOUBLE, noblock = 1)
float, double,
const float &, const double &
{
- double $result;
_v = $input.isDouble();
- if (_v) $result = $input.toDouble();
}
%typecheck(SWIG_TYPECHECK_CHAR, noblock = 1) char
{
- HPHP::String $result;
_v = ($input.isString() && $input.toString().length() == 1);
- if (_v) $result = $input.toString();
}
%typecheck(SWIG_TYPECHECK_STRING, noblock = 1) char *
{
- HPHP::String $result;
_v = $input.isString();
- if (_v) $result = $input.toString();
}
%typecheck(SWIG_TYPECHECK_BOOL, noblock = 1)
bool, const bool &
{
- bool $result;
_v = $input.isBoolean();
- if (_v) $result = $input.toBoolean();
}
%typecheck(SWIG_TYPECHECK_POINTER, noblock = 1)
SWIGTYPE *,
SWIGTYPE []
{
- HPHP::Object $result;
_v = $input.isObject();
- if (_v) $result = $input.toObject();
}
%typemap(variant_out) int,
@@ -376,14 +364,14 @@ bool, const bool &
unsigned char,
signed char,
enum SWIGTYPE
- "toInt64Val";
+ ".toInt64Val()";
%typemap(variant_out) bool
- "toBooleanVal";
+ ".toBooleanVal()";
%typemap(variant_out) float,
double
- "toDoubleVal";
+ ".toDoubleVal()";
%typemap(variant_out) char *,
char,
@@ -391,14 +379,16 @@ bool, const bool &
char [ANY],
char [],
const char []
- "toString";
+ ".toString()";
%typemap(variant_out) SWIGTYPE
- "toObject";
+ ".toObject()";
%typemap(variant_out) SWIGTYPE *,
- SWIGTYPE []
- "toObject";
+ SWIGTYPE [],
+ SWIGTYPE &,
+ SWIGTYPE &&
+ "";
%typemap(hhwrapclass) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] %{
diff --git a/Lib/hhvm/std_string.i b/Lib/hhvm/std_string.i
index 2f0dfc99d..f0be6d29e 100644
--- a/Lib/hhvm/std_string.i
+++ b/Lib/hhvm/std_string.i
@@ -19,7 +19,7 @@ class string;
%typemap(hni_parmtype) string, const string & "const HPHP::String&"
%typemap(hni_rttype) string, const string & "HPHP::String";
%typemap(php_type) string, const string & "string";
-%typemap(variant_out) string "toString"
+%typemap(variant_out) string ".toString()"
%typemap(in) string %{$1 = $input.toCppString();%}
%typemap(out) string %{$result = HPHP::String($1);%}
diff --git a/Source/Modules/hhvm.cxx b/Source/Modules/hhvm.cxx
index 7aa901b2e..c704b2788 100644
--- a/Source/Modules/hhvm.cxx
+++ b/Source/Modules/hhvm.cxx
@@ -407,7 +407,7 @@ public:
Parm *p = parms;
// Skip the class pointer
- if (!is_constructor && !staticmethodwrapper && !is_static && is_member) {
+ if (!is_constructor && !staticmethodwrapper && !is_static && (is_member || is_destructor)) {
p = nextSibling(p);
}
@@ -454,10 +454,14 @@ public:
Printf(f_link, ") {\n");
Printf(f_phpcode, ";\n\n");
- if (is_member && !staticmethodwrapper && !is_static) {
- Printf(f_link, " auto data = Object(this_);\n", classname);
+ if ((is_member || is_destructor) && !staticmethodwrapper && !is_static) {
+ Printf(f_link, " auto data = Object(this_);\n", classname);
if (!is_constructor) {
Replaceall(call_parms, "arg1", "data");
+ if (is_overloaded) {
+ Printf(f_link, " Array args = Array::Create(data) + argv;\n");
+ Replaceall(call_parms, "argv", "args");
+ }
}
}
@@ -625,10 +629,9 @@ public:
void dispatchFunction(Node *n) {
/* Last node in overloaded chain */
- String *tmp = NewStringEmpty();
- Printf(tmp, "result = %%s($commaargs);\n");
- Printf(tmp, "if (result.isInitialized()) {\n return result; \n}");
- String *dispatch = hhvm_overload_dispatch(n);
+ int maxargs;
+ const char* ret = "return %s(argv);\n";
+ String *dispatch = Swig_overload_dispatch(n, ret, &maxargs);
/* Generate a dispatch wrapper for all overloaded functions */
@@ -643,7 +646,6 @@ public:
Printf(wrapper->def, "HPHP::Variant %s(const HPHP::Array& argv) {\n", wname);
Wrapper_add_local(wrapper, "argc", "int argc");
- Wrapper_add_local(wrapper, "result", "HPHP::Variant result");
Printf(wrapper->code, "argc = argv.size();\n");
Printv(wrapper->code, dispatch, "\n", NIL);
@@ -659,7 +661,6 @@ public:
DelWrapper(wrapper);
Delete(dispatch);
- Delete(tmp);
Delete(wname);
}
@@ -705,7 +706,10 @@ public:
Setattr(n, "wrap:parms", parms);
Printf(wrapper->def, "SWIGINTERN\n");
- if ((tm = Swig_typemap_lookup("hni_rttype", n, "", 0))) {
+ if (overloaded) {
+ Printv(wrapper->def, "HPHP::Variant ", NIL);
+ Printf(return_type, "HPHP::Variant");
+ } else if ((tm = Swig_typemap_lookup("hni_rttype", n, "", 0))) {
Printv(wrapper->def, tm, " ", NIL);
Printf(return_type, "%s", tm);
} else {
@@ -720,25 +724,38 @@ public:
/* Attach the standard typemaps */
emit_attach_parmmaps(parms, wrapper);
+ if (overloaded) {
+ Printf(wrapper->def, "const HPHP::Array& argv");
+ Swig_typemap_attach_parms("variant_out", parms, wrapper);
+ }
+
bool prev = false;
- p = parms;
- while (p) {
+ int parm_i = 0;
+ for (p = parms; p; parm_i++) {
String *parm_name = Getattr(p, "lname");
String *parm_type = Getattr(p, "type");
String *arg = NewString("");
Printf(arg, "t%s", parm_name);
- if ((tm = Getattr(p, "tmap:hni_parmtype"))) {
- if (prev) {
- Printf(wrapper->def, ", ");
- Printf(call_parms, ", ");
+ if (!overloaded) {
+ if ((tm = Getattr(p, "tmap:hni_parmtype"))) {
+ if (prev) {
+ Printf(wrapper->def, ", ");
+ Printf(call_parms, ", ");
+ }
+ Printf(wrapper->def, "%s %s", tm, arg);
+ Printf(call_parms, "%s", parm_name);
+ prev = true;
+ } else {
+ Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to define type %s as a function argument.\n", SwigType_str(parm_type, 0));
}
- Printf(wrapper->def, "%s %s", tm, arg);
- Printf(call_parms, "%s", parm_name);
- prev = true;
} else {
- Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to define type %s as a function argument.\n", SwigType_str(parm_type, 0));
+ Printf(wrapper->code, "auto %s = argv[%d]", arg, parm_i);
+ if ((tm = Getattr(p, "tmap:variant_out"))) {
+ Printf(wrapper->code, "%s", tm);
+ }
+ Printf(wrapper->code, ";\n");
}
if ((tm = Getattr(p, "tmap:in"))) {
@@ -799,6 +816,9 @@ public:
if (!is_void_return)
Printv(wrapper->code, "return tresult;\n", NIL);
+ else if (overloaded) {
+ Printv(wrapper->code, "return HPHP::Variant();\n", NIL);
+ }
Printv(wrapper->code, "}\n", NIL);
@@ -952,7 +972,7 @@ public:
Printf(f_link, "static void %s(const Object& this_, HHVM_PROP_CONST Variant& value) {\n", accname);
Printf(f_link, " auto data = Object(this_);\n");
if ((tm = Swig_typemap_lookup("variant_out", n, varname, 0))) {
- Printf(f_link, " %s(data, value.%s());\n", wname, tm);
+ Printf(f_link, " %s(data, value%s);\n", wname, tm);
}
Printf(f_link, "}\n\n");
Printf(out_str, "%s },\n", accname);