Skip to content

Commit 21d2df8

Browse files
Aidan63Aidan Lee
andauthored
Untyped array reflection functions (#1300)
* Remove un-needed include * Dynamic callable for array reflection functions * Silence warning spam about missing override --------- Co-authored-by: Aidan Lee <[email protected]>
1 parent 0e9183d commit 21d2df8

File tree

3 files changed

+101
-31
lines changed

3 files changed

+101
-31
lines changed

include/Array.h

Lines changed: 100 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,40 +1504,110 @@ HX_ARRAY_FUNC(, void, resize, HX_ARRAY_ARG_LIST1(int), HX_ARRAY_FUNC_LIST1(int),
15041504
template<class ELEM_>
15051505
hx::Val Array_obj<ELEM_>::__Field(const String& inString, hx::PropertyAccess inCallProp)
15061506
{
1507+
#define ARRAY_RUN_FUNC(ret,func,dynamic_arg_list,arg_list) \
1508+
Dynamic __run(dynamic_arg_list) \
1509+
{ \
1510+
ret mThis->__##func(arg_list); return Dynamic(); \
1511+
}
1512+
1513+
#define DEFINE_ARRAY_FUNC(ret,func,array_list,run_func,ARG_C) \
1514+
struct Reflective_##func : public hx::Object \
1515+
{ \
1516+
HX_IS_INSTANCE_OF enum { _hx_ClassId = hx::clsIdClosure }; \
1517+
bool __IsFunction() const { return true; } \
1518+
Array_obj<ELEM_> *mThis; \
1519+
Reflective_##func(Array_obj<ELEM_> *inThis) : mThis(inThis) { } \
1520+
String toString() const{ return HX_CSTRING(#func) ; } \
1521+
String __ToString() const{ return HX_CSTRING(#func) ; } \
1522+
int __GetType() const { return vtFunction; } \
1523+
void *__GetHandle() const { return mThis; } \
1524+
int __ArgCount() const { return ARG_C; } \
1525+
void __Mark(hx::MarkContext *__inCtx) { HX_MARK_MEMBER(mThis); } \
1526+
ARRAY_VISIT_FUNC \
1527+
Dynamic __Run(const Array<Dynamic> &inArgs) \
1528+
{ \
1529+
ret mThis->__##func(array_list); return Dynamic(); \
1530+
} \
1531+
run_func \
1532+
int __Compare(const hx::Object *inRHS) const \
1533+
{ \
1534+
if (!dynamic_cast<const Reflective_##func *>(inRHS)) return -1; \
1535+
return (mThis==inRHS->__GetHandle() ? 0 : -1); \
1536+
} \
1537+
};
1538+
1539+
1540+
#define DEFINE_ARRAY_FUNC0(ret,func) DEFINE_ARRAY_FUNC(ret,func,HX_ARR_LIST0,ARRAY_RUN_FUNC(ret,func,HX_DYNAMIC_ARG_LIST0,HX_ARG_LIST0),0)
1541+
#define DEFINE_ARRAY_FUNC1(ret,func) DEFINE_ARRAY_FUNC(ret,func,HX_ARR_LIST1,ARRAY_RUN_FUNC(ret,func,HX_DYNAMIC_ARG_LIST1,HX_ARG_LIST1),1)
1542+
#define DEFINE_ARRAY_FUNC2(ret,func) DEFINE_ARRAY_FUNC(ret,func,HX_ARR_LIST2,ARRAY_RUN_FUNC(ret,func,HX_DYNAMIC_ARG_LIST2,HX_ARG_LIST2),2)
1543+
#define DEFINE_ARRAY_FUNC3(ret,func) DEFINE_ARRAY_FUNC(ret,func,HX_ARR_LIST3,ARRAY_RUN_FUNC(ret,func,HX_DYNAMIC_ARG_LIST3,HX_ARG_LIST3),3)
1544+
#define DEFINE_ARRAY_FUNC4(ret,func) DEFINE_ARRAY_FUNC(ret,func,HX_ARR_LIST4,ARRAY_RUN_FUNC(ret,func,HX_DYNAMIC_ARG_LIST4,HX_ARG_LIST4),4)
1545+
1546+
DEFINE_ARRAY_FUNC1(, __SetSize);
1547+
DEFINE_ARRAY_FUNC1(, __SetSizeExact);
1548+
DEFINE_ARRAY_FUNC2(, insert);
1549+
DEFINE_ARRAY_FUNC0(, reverse);
1550+
DEFINE_ARRAY_FUNC1(, sort);
1551+
DEFINE_ARRAY_FUNC1(, unshift);
1552+
DEFINE_ARRAY_FUNC4(, blit);
1553+
DEFINE_ARRAY_FUNC2(, zero);
1554+
DEFINE_ARRAY_FUNC1(, resize);
1555+
DEFINE_ARRAY_FUNC1(return, concat);
1556+
DEFINE_ARRAY_FUNC0(return, iterator);
1557+
DEFINE_ARRAY_FUNC0(return, keyValueIterator);
1558+
DEFINE_ARRAY_FUNC1(return, join);
1559+
DEFINE_ARRAY_FUNC0(return, pop);
1560+
DEFINE_ARRAY_FUNC0(return, copy);
1561+
DEFINE_ARRAY_FUNC1(return, push);
1562+
DEFINE_ARRAY_FUNC1(return, contains);
1563+
DEFINE_ARRAY_FUNC1(return, remove);
1564+
DEFINE_ARRAY_FUNC1(return, removeAt);
1565+
DEFINE_ARRAY_FUNC2(return, indexOf);
1566+
DEFINE_ARRAY_FUNC2(return, lastIndexOf);
1567+
DEFINE_ARRAY_FUNC0(return, shift);
1568+
DEFINE_ARRAY_FUNC2(return, slice);
1569+
DEFINE_ARRAY_FUNC2(return, splice);
1570+
DEFINE_ARRAY_FUNC0(return, toString);
1571+
DEFINE_ARRAY_FUNC1(return, map);
1572+
DEFINE_ARRAY_FUNC1(return, filter);
1573+
DEFINE_ARRAY_FUNC1(return, __unsafe_get);
1574+
DEFINE_ARRAY_FUNC2(return, __unsafe_set);
1575+
DEFINE_ARRAY_FUNC1(return, memcmp);
1576+
15071577
if (inString == HX_CSTRING("length")) return (int)size();
1508-
if (inString == HX_CSTRING("concat")) return concat_dyn();
1509-
if (inString == HX_CSTRING("insert")) return insert_dyn();
1510-
if (inString == HX_CSTRING("copy")) return copy_dyn();
1511-
if (inString == HX_CSTRING("iterator")) return iterator_dyn();
1512-
if (inString == HX_CSTRING("keyValueIterator")) return keyValueIterator_dyn();
1513-
if (inString == HX_CSTRING("join")) return join_dyn();
1514-
if (inString == HX_CSTRING("pop")) return pop_dyn();
1515-
if (inString == HX_CSTRING("push")) return push_dyn();
1516-
if (inString == HX_CSTRING("contains")) return contains_dyn();
1517-
if (inString == HX_CSTRING("remove")) return remove_dyn();
1518-
if (inString == HX_CSTRING("removeAt")) return removeAt_dyn();
1519-
if (inString == HX_CSTRING("indexOf")) return indexOf_dyn();
1520-
if (inString == HX_CSTRING("lastIndexOf")) return lastIndexOf_dyn();
1521-
if (inString == HX_CSTRING("reverse")) return reverse_dyn();
1522-
if (inString == HX_CSTRING("shift")) return shift_dyn();
1523-
if (inString == HX_CSTRING("splice")) return splice_dyn();
1524-
if (inString == HX_CSTRING("slice")) return slice_dyn();
1525-
if (inString == HX_CSTRING("sort")) return sort_dyn();
1526-
if (inString == HX_CSTRING("toString")) return toString_dyn();
1527-
if (inString == HX_CSTRING("unshift")) return unshift_dyn();
1528-
if (inString == HX_CSTRING("filter")) return filter_dyn();
1529-
if (inString == HX_CSTRING("map")) return map_dyn<::Dynamic>();
1530-
if (inString == HX_CSTRING("__SetSize")) return __SetSize_dyn();
1531-
if (inString == HX_CSTRING("__SetSizeExact")) return __SetSizeExact_dyn();
1532-
if (inString == HX_CSTRING("__unsafe_get")) return __unsafe_get_dyn();
1533-
if (inString == HX_CSTRING("__unsafe_set")) return __unsafe_set_dyn();
1534-
if (inString == HX_CSTRING("blit")) return blit_dyn();
1535-
if (inString == HX_CSTRING("zero")) return zero_dyn();
1536-
if (inString == HX_CSTRING("memcmp")) return memcmp_dyn();
1578+
if (inString == HX_CSTRING("concat")) return new Reflective_concat(this);
1579+
if (inString == HX_CSTRING("insert")) return new Reflective_insert(this);
1580+
if (inString == HX_CSTRING("copy")) return new Reflective_copy(this);
1581+
if (inString == HX_CSTRING("iterator")) return new Reflective_iterator(this);
1582+
if (inString == HX_CSTRING("keyValueIterator")) return new Reflective_keyValueIterator(this);
1583+
if (inString == HX_CSTRING("join")) return new Reflective_join(this);
1584+
if (inString == HX_CSTRING("pop")) return new Reflective_pop(this);
1585+
if (inString == HX_CSTRING("push")) return new Reflective_push(this);
1586+
if (inString == HX_CSTRING("contains")) return new Reflective_contains(this);
1587+
if (inString == HX_CSTRING("remove")) return new Reflective_remove(this);
1588+
if (inString == HX_CSTRING("removeAt")) return new Reflective_removeAt(this);
1589+
if (inString == HX_CSTRING("indexOf")) return new Reflective_indexOf(this);
1590+
if (inString == HX_CSTRING("lastIndexOf")) return new Reflective_lastIndexOf(this);
1591+
if (inString == HX_CSTRING("reverse")) return new Reflective_reverse(this);
1592+
if (inString == HX_CSTRING("shift")) return new Reflective_shift(this);
1593+
if (inString == HX_CSTRING("splice")) return new Reflective_splice(this);
1594+
if (inString == HX_CSTRING("slice")) return new Reflective_slice(this);
1595+
if (inString == HX_CSTRING("sort")) return new Reflective_sort(this);
1596+
if (inString == HX_CSTRING("toString")) return new Reflective_toString(this);
1597+
if (inString == HX_CSTRING("unshift")) return new Reflective_unshift(this);
1598+
if (inString == HX_CSTRING("filter")) return new Reflective_filter(this);
1599+
if (inString == HX_CSTRING("map")) return new Reflective_map(this);
1600+
if (inString == HX_CSTRING("__SetSize")) return new Reflective___SetSize(this);
1601+
if (inString == HX_CSTRING("__SetSizeExact")) return new Reflective___SetSizeExact(this);
1602+
if (inString == HX_CSTRING("__unsafe_get")) return new Reflective___unsafe_get(this);
1603+
if (inString == HX_CSTRING("__unsafe_set")) return new Reflective___unsafe_set(this);
1604+
if (inString == HX_CSTRING("blit")) return new Reflective_blit(this);
1605+
if (inString == HX_CSTRING("zero")) return new Reflective_zero(this);
1606+
if (inString == HX_CSTRING("memcmp")) return new Reflective_memcmp(this);
15371607
if (inString == HX_CSTRING("_hx_storeType")) return (int)getStoreType();
15381608
if (inString == HX_CSTRING("_hx_elementSize")) return (int)GetElementSize();
15391609
if (inString == HX_CSTRING("_hx_pointer")) return __pointerToBase();
1540-
if (inString == HX_CSTRING("resize")) return resize_dyn();
1610+
if (inString == HX_CSTRING("resize")) return new Reflective_resize(this);
15411611
return null();
15421612
}
15431613

include/hx/Functions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#ifndef HX_FUNCTIONS_H
22
#define HX_FUNCTIONS_H
3-
#include <hxcpp.h>
43

54
namespace hx
65
{

toolchain/linux-toolchain.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<flag value="-fpic"/>
4848
<flag value="-fPIC"/>
4949
<flag value="-Wno-overflow" />
50+
<flag value="-Wno-inconsistent-missing-override"/>
5051
<cppflag value="-Wno-invalid-offsetof" />
5152
<flag value="-DHX_LINUX"/>
5253
<flag value="-DRASPBERRYPI=RASPBERRYPI" if="rpi"/>

0 commit comments

Comments
 (0)