Skip to content

Commit 1fd3680

Browse files
authored
Fully qualify base types in macros (#1310)
* Fully qualify base types in macros * Make GenMacro.hx more editor friendly Using \r instead of a literal carriage return character prevents editors from trying to normalise the newlines. * Use replace instead of split + join in GenMacro * Regenerate macro header files * [ci] Run check for macros with unqualified globals * Work around parsing issues :: causes issues if it comes in between the return type of a function and the function name, so we have to dodge those cases
1 parent 8600e4d commit 1fd3680

23 files changed

+566
-547
lines changed

.github/workflows/main.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@ name: main
22
on: [push, pull_request]
33

44
jobs:
5+
check-headers:
6+
name: Check headers
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: checkout
10+
uses: actions/checkout@v4
11+
12+
- name: Install pcre2grep
13+
run: sudo apt-get update && sudo apt-get install -y pcre2-utils
14+
15+
- run: |
16+
# macros in public headers must use the global namespace to qualify types
17+
! pcre2grep --buffer-size=1M --recursive --multiline --line-number --include='.*\.h$' \
18+
'#define\s+(?:.*\\\r?\n)*.*?\K(?<!:)\b(Enum|String|StringOffset|Array|ArrayClassID|Math|Math_obj|Void|null|Dynamic|hx::|cpp::)\b' \
19+
include
20+
name: Check public headers
21+
522
Windows32:
623
strategy:
724
fail-fast: false

include/Array.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ cpp::VirtualArray Array_obj<ELEM_>::map(MappingFunc inFunc)
13781378

13791379
#ifdef HXCPP_VISIT_ALLOCS
13801380
#define ARRAY_VISIT_FUNC \
1381-
void __Visit(hx::VisitContext *__inCtx) { HX_VISIT_MEMBER(mThis); }
1381+
void __Visit(::hx::VisitContext *__inCtx) { HX_VISIT_MEMBER(mThis); }
13821382
#else
13831383
#define ARRAY_VISIT_FUNC
13841384
#endif
@@ -1413,8 +1413,8 @@ namespace hx
14131413
{ \
14141414
struct _hx_array_##name final : public ::hx::AutoCallable_obj<value(args_list)> \
14151415
{ \
1416-
Array<ELEM_> mThis; \
1417-
_hx_array_##name(Array<ELEM_> inThis) : mThis(inThis) \
1416+
::Array<ELEM_> mThis; \
1417+
_hx_array_##name(::Array<ELEM_> inThis) : mThis(inThis) \
14181418
{ \
14191419
HX_OBJ_WB_NEW_MARKED_OBJECT(this); \
14201420
} \
@@ -1423,13 +1423,13 @@ namespace hx
14231423
ret mThis->name(args_call); \
14241424
} \
14251425
void *__GetHandle() const override { return mThis.GetPtr(); } \
1426-
void __Mark(hx::MarkContext *__inCtx) { HX_MARK_MEMBER(mThis); } \
1426+
void __Mark(::hx::MarkContext *__inCtx) { HX_MARK_MEMBER(mThis); } \
14271427
ARRAY_VISIT_FUNC \
14281428
int __Compare(const ::hx::Object* inRhs) const override \
14291429
{ \
14301430
auto casted = dynamic_cast<const _hx_array_##name *>(inRhs); \
14311431
if (!casted) return 1; \
1432-
if (!hx::IsPointerEq(mThis, casted->mThis)) return -1; \
1432+
if (!::hx::IsPointerEq(mThis, casted->mThis)) return -1; \
14331433
return 0; \
14341434
} \
14351435
}; \
@@ -1505,31 +1505,31 @@ template<class ELEM_>
15051505
hx::Val Array_obj<ELEM_>::__Field(const String& inString, hx::PropertyAccess inCallProp)
15061506
{
15071507
#define ARRAY_RUN_FUNC(ret,func,dynamic_arg_list,arg_list) \
1508-
Dynamic __run(dynamic_arg_list) \
1508+
::Dynamic __run(dynamic_arg_list) \
15091509
{ \
1510-
ret mThis->__##func(arg_list); return Dynamic(); \
1510+
ret mThis->__##func(arg_list); return ::Dynamic(); \
15111511
}
15121512

15131513
#define DEFINE_ARRAY_FUNC(ret,func,array_list,run_func,ARG_C) \
1514-
struct Reflective_##func : public hx::Object \
1514+
struct Reflective_##func : public ::hx::Object \
15151515
{ \
1516-
HX_IS_INSTANCE_OF enum { _hx_ClassId = hx::clsIdClosure }; \
1516+
HX_IS_INSTANCE_OF enum { _hx_ClassId = ::hx::clsIdClosure }; \
15171517
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) ; } \
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) ; } \
15221522
int __GetType() const { return vtFunction; } \
15231523
void *__GetHandle() const { return mThis; } \
15241524
int __ArgCount() const { return ARG_C; } \
1525-
void __Mark(hx::MarkContext *__inCtx) { HX_MARK_MEMBER(mThis); } \
1525+
void __Mark(::hx::MarkContext *__inCtx) { HX_MARK_MEMBER(mThis); } \
15261526
ARRAY_VISIT_FUNC \
1527-
Dynamic __Run(const Array<Dynamic> &inArgs) \
1527+
::Dynamic __Run(const ::Array<::Dynamic> &inArgs) \
15281528
{ \
1529-
ret mThis->__##func(array_list); return Dynamic(); \
1529+
ret mThis->__##func(array_list); return ::Dynamic(); \
15301530
} \
15311531
run_func \
1532-
int __Compare(const hx::Object *inRHS) const \
1532+
int __Compare(const ::hx::Object *inRHS) const \
15331533
{ \
15341534
if (!dynamic_cast<const Reflective_##func *>(inRHS)) return -1; \
15351535
return (mThis==inRHS->__GetHandle() ? 0 : -1); \

include/Dynamic.h

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
165165

166166

167167
#define DYNAMIC_COMPARE_OP( op ) \
168-
bool operator op (const String &inRHS) const { return mPtr && ((String)(*this) op inRHS); } \
168+
bool operator op (const ::String &inRHS) const { return mPtr && ((::String)(*this) op inRHS); } \
169169
bool operator op (double inRHS) const { return IsNumeric() && ((double)(*this) op inRHS); } \
170-
bool operator op (cpp::Int64 inRHS) const { return IsNumeric() && ((cpp::Int64)(*this) op inRHS); } \
171-
bool operator op (cpp::UInt64 inRHS) const { return IsNumeric() && ((cpp::Int64)(*this) op inRHS); } \
170+
bool operator op (::cpp::Int64 inRHS) const { return IsNumeric() && ((::cpp::Int64)(*this) op inRHS); } \
171+
bool operator op (::cpp::UInt64 inRHS) const { return IsNumeric() && ((::cpp::Int64)(*this) op inRHS); } \
172172
bool operator op (float inRHS) const { return IsNumeric() && ((double)(*this) op inRHS); } \
173173
bool operator op (int inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
174174
bool operator op (unsigned int inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
@@ -198,8 +198,8 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
198198

199199

200200
#define DYNAMIC_COMPARE_OP_ALL( op ) \
201-
bool operator op (const Dynamic &inRHS) const { return mPtr && (Compare(inRHS) op 0); } \
202-
bool operator op (const cpp::Variant &inRHS) const { return *this op Dynamic(inRHS); } \
201+
bool operator op (const ::Dynamic &inRHS) const { return mPtr && (Compare(inRHS) op 0); } \
202+
bool operator op (const ::cpp::Variant &inRHS) const { return *this op ::Dynamic(inRHS); } \
203203
DYNAMIC_COMPARE_OP(op)
204204

205205

@@ -259,36 +259,36 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
259259
double operator / (const int &inRHS) const { return (double)(*this) / (double)inRHS; }
260260

261261
#define DYNAMIC_ARITH( op ) \
262-
Dynamic operator op (const cpp::Variant &inRHS) const \
262+
::Dynamic operator op (const ::cpp::Variant &inRHS) const \
263263
{ return mPtr->__GetType()==vtInt && inRHS.isInt() ? \
264-
Dynamic((int)(*this) op (int)inRHS) : \
265-
Dynamic( (double)(*this) op (double)inRHS); } \
266-
Dynamic operator op (const Dynamic &inRHS) const \
264+
::Dynamic((int)(*this) op (int)inRHS) : \
265+
::Dynamic( (double)(*this) op (double)inRHS); } \
266+
::Dynamic operator op (const ::Dynamic &inRHS) const \
267267
{ return mPtr->__GetType()==vtInt && inRHS.mPtr->__GetType()==vtInt ? \
268-
Dynamic((int)(*this) op (int)inRHS) : \
269-
Dynamic( (double)(*this) op (double)inRHS); } \
268+
::Dynamic((int)(*this) op (int)inRHS) : \
269+
::Dynamic( (double)(*this) op (double)inRHS); } \
270270
double operator op (const double &inRHS) const { return (double)(*this) op (double)inRHS; } \
271271
double operator op (const float &inRHS) const { return (double)(*this) op (double)inRHS; } \
272-
Dynamic operator op (const int &inRHS) const \
273-
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
274-
Dynamic operator op (const unsigned int &inRHS) const \
275-
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
276-
Dynamic operator op (const short &inRHS) const \
277-
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
278-
Dynamic operator op (const unsigned short &inRHS) const \
279-
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
280-
Dynamic operator op (const signed char &inRHS) const \
281-
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
282-
Dynamic operator op (const unsigned char &inRHS) const \
283-
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
284-
Dynamic operator op (const char16_t &inRHS) const \
285-
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
286-
Dynamic operator op (const char32_t &inRHS) const \
287-
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
288-
Dynamic operator op (const cpp::Int64 &inRHS) const \
289-
{ return Dynamic((double)(*this) op inRHS); } \
290-
Dynamic operator op (const cpp::UInt64 &inRHS) const \
291-
{ return Dynamic((double)(*this) op inRHS); } \
272+
::Dynamic operator op (const int &inRHS) const \
273+
{ return mPtr->__GetType()==vtInt ? ::Dynamic((int)(*this) op inRHS) : ::Dynamic((double)(*this) op inRHS); } \
274+
::Dynamic operator op (const unsigned int &inRHS) const \
275+
{ return mPtr->__GetType()==vtInt ? ::Dynamic((int)(*this) op inRHS) : ::Dynamic((double)(*this) op inRHS); } \
276+
::Dynamic operator op (const short &inRHS) const \
277+
{ return mPtr->__GetType()==vtInt ? ::Dynamic((int)(*this) op inRHS) : ::Dynamic((double)(*this) op inRHS); } \
278+
::Dynamic operator op (const unsigned short &inRHS) const \
279+
{ return mPtr->__GetType()==vtInt ? ::Dynamic((int)(*this) op inRHS) : ::Dynamic((double)(*this) op inRHS); } \
280+
::Dynamic operator op (const signed char &inRHS) const \
281+
{ return mPtr->__GetType()==vtInt ? ::Dynamic((int)(*this) op inRHS) : ::Dynamic((double)(*this) op inRHS); } \
282+
::Dynamic operator op (const unsigned char &inRHS) const \
283+
{ return mPtr->__GetType()==vtInt ? ::Dynamic((int)(*this) op inRHS) : ::Dynamic((double)(*this) op inRHS); } \
284+
::Dynamic operator op (const char16_t &inRHS) const \
285+
{ return mPtr->__GetType()==vtInt ? ::Dynamic((int)(*this) op inRHS) : ::Dynamic((double)(*this) op inRHS); } \
286+
::Dynamic operator op (const char32_t &inRHS) const \
287+
{ return mPtr->__GetType()==vtInt ? ::Dynamic((int)(*this) op inRHS) : ::Dynamic((double)(*this) op inRHS); } \
288+
::Dynamic operator op (const ::cpp::Int64 &inRHS) const \
289+
{ return ::Dynamic((double)(*this) op inRHS); } \
290+
::Dynamic operator op (const ::cpp::UInt64 &inRHS) const \
291+
{ return ::Dynamic((double)(*this) op inRHS); } \
292292

293293
DYNAMIC_ARITH( - )
294294
DYNAMIC_ARITH( * )
@@ -425,8 +425,8 @@ inline bool Dynamic::IsClass< ::cpp::Int64>() { return mPtr && mPtr->__GetClass(
425425
inline String Dynamic::operator+(const String &s) const { return Cast<String>() + s; }
426426

427427
#define HX_DYNAMIC_OP_ISEQ(T) \
428-
inline bool operator == (const T &inLHS,const Dynamic &inRHS) { return inRHS==inLHS; } \
429-
inline bool operator != (const T &inLHS,const Dynamic &inRHS) { return inRHS!=inLHS; }
428+
inline bool operator == (const T &inLHS,const ::Dynamic &inRHS) { return inRHS==inLHS; } \
429+
inline bool operator != (const T &inLHS,const ::Dynamic &inRHS) { return inRHS!=inLHS; }
430430

431431
HX_DYNAMIC_OP_ISEQ(String)
432432
HX_DYNAMIC_OP_ISEQ(double)
@@ -466,18 +466,18 @@ COMPARE_DYNAMIC_OP( > )
466466

467467

468468
#define ARITH_DYNAMIC( op ) \
469-
inline double operator op (const cpp::Int64 &inLHS,const Dynamic &inRHS) { return inLHS op (cpp::Int64)inRHS;} \
470-
inline double operator op (const cpp::UInt64 &inLHS,const Dynamic &inRHS) { return inLHS op (cpp::UInt64)inRHS;} \
471-
inline double operator op (const double &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS;} \
472-
inline double operator op (const float &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS;} \
473-
inline double operator op (const int &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
474-
inline double operator op (const unsigned int &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
475-
inline double operator op (const short &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
476-
inline double operator op (const unsigned short &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
477-
inline double operator op (const signed char &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
478-
inline double operator op (const unsigned char &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
479-
inline double operator op (const char16_t &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
480-
inline double operator op (const char32_t &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
469+
inline double operator op (const ::cpp::Int64 &inLHS,const ::Dynamic &inRHS) { return inLHS op (::cpp::Int64)inRHS;} \
470+
inline double operator op (const ::cpp::UInt64 &inLHS,const ::Dynamic &inRHS) { return inLHS op (::cpp::UInt64)inRHS;} \
471+
inline double operator op (const double &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS;} \
472+
inline double operator op (const float &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS;} \
473+
inline double operator op (const int &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS; } \
474+
inline double operator op (const unsigned int &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS; } \
475+
inline double operator op (const short &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS; } \
476+
inline double operator op (const unsigned short &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS; } \
477+
inline double operator op (const signed char &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS; } \
478+
inline double operator op (const unsigned char &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS; } \
479+
inline double operator op (const char16_t &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS; } \
480+
inline double operator op (const char32_t &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS; } \
481481

482482
ARITH_DYNAMIC( - )
483483
ARITH_DYNAMIC( + )

include/cpp/CppInt32__.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ namespace cpp
77
{
88

99
#define HX_I32_DEF_FUNC1(Name) \
10-
static inline Dynamic __##Name(const Dynamic &a) { return Name(a); } \
11-
static inline Dynamic Name##_dyn() { return hx::CreateStaticFunction1(#Name,&CppInt32__::__##Name); }
10+
static inline ::Dynamic __##Name(const ::Dynamic &a) { return Name(a); } \
11+
static inline ::Dynamic Name##_dyn() { return ::hx::CreateStaticFunction1(#Name,&CppInt32__::__##Name); }
1212

1313
#define HX_I32_DEF_FUNC2(Name) \
14-
static inline Dynamic __##Name(const Dynamic &a, const Dynamic &b) { return Name(a,b); } \
15-
static inline Dynamic Name##_dyn() { return hx::CreateStaticFunction2(#Name,&CppInt32__::__##Name); }
14+
static inline ::Dynamic __##Name(const ::Dynamic &a, const ::Dynamic &b) { return Name(a,b); } \
15+
static inline ::Dynamic Name##_dyn() { return ::hx::CreateStaticFunction2(#Name,&CppInt32__::__##Name); }
1616

1717
class CppInt32__
1818
{

0 commit comments

Comments
 (0)