1 //===-- jitcs_fnctypeinfo.h - -----------------------------------*- C++ -*-===//
3 //===----------------------------------------------------------------------===//
5 #ifndef _JITCS_FNCTYPEINFO_H_
6 #define _JITCS_FNCTYPEINFO_H_
8 #include "jitcs_base.h"
23 template <typename T
> struct GetFTSubType
{};
24 template <typename R
, typename
...Args
>
25 struct GetFTSubType
<R (__cdecl
*)(Args
...)> {
26 static const FTSubType Value
= FTS_CDecl
;
27 typedef R (*FType
)(Args
...);
29 template <typename R
, typename
...Args
>
30 struct GetFTSubType
<R (__fastcall
*)(Args
...)> {
31 static const FTSubType Value
= FTS_FastCall
;
32 typedef R (*FType
)(Args
...);
34 template <typename R
, typename
...Args
>
35 struct GetFTSubType
<R (__stdcall
*)(Args
...)> {
36 static const FTSubType Value
= FTS_StdCall
;
37 typedef R (*FType
)(Args
...);
42 static const bool OK
= false;
43 static const FTTypeId Value
= FTT_Void
;
46 struct GetFTTypeId
<void> {
47 static const bool OK
= true;
48 static const FTTypeId Value
= FTT_Void
;
51 struct GetFTTypeId
<i32
> {
52 static const bool OK
= true;
53 static const FTTypeId Value
= FTT_Int
;
56 struct GetFTTypeId
<u32
> {
57 static const bool OK
= true;
58 static const FTTypeId Value
= FTT_Int
;
61 struct GetFTTypeId
<i64
> {
62 static const bool OK
= sizeof(i64
) <= sizeof(void*);
63 static const FTTypeId Value
= sizeof(i64
) == sizeof(void*) ? FTT_PtrInt
: FTT_Int
;
66 struct GetFTTypeId
<u64
> {
67 static const bool OK
= sizeof(i64
) <= sizeof(void*);
68 static const FTTypeId Value
= sizeof(u64
) == sizeof(void*) ? FTT_PtrInt
: FTT_Int
;
71 struct GetFTTypeId
<T
*> {
72 static const bool OK
= true;
73 static const FTTypeId Value
= FTT_Ptr
;
76 struct GetFTTypeId
<T
const*> {
77 static const bool OK
= true;
78 static const FTTypeId Value
= FTT_Ptr
;
81 struct GetFTTypeId
<T
&> {
82 static const bool OK
= true;
83 static const FTTypeId Value
= FTT_Ptr
;
86 struct GetFTTypeId
<T
const&> {
87 static const bool OK
= true;
88 static const FTTypeId Value
= FTT_Ptr
;
92 template <typename T
> struct _GetFTResultId
{};
93 template <typename R
, typename
...Args
>
94 struct _GetFTResultId
<R (*)(Args
...)> {
95 static const bool OK
= GetFTTypeId
<R
>::OK
;
96 static const FTTypeId Value
= GetFTTypeId
<R
>::Value
;
98 template <typename T
> struct GetFTResultId
: _GetFTResultId
<typename GetFTSubType
<T
>::FType
> {};
99 template <typename T
> struct _GetFTParamCount
{};
100 template <typename R
>
101 struct _GetFTParamCount
<R (*)()> {
102 static const uint Value
= 0;
104 template <typename R
, typename Arg
, typename
...Args
>
105 struct _GetFTParamCount
<R (*)(Arg
, Args
...)> {
106 static const uint Value
= _GetFTParamCount
<R (*)(Args
...)>::Value
+ 1;
108 template <typename T
> struct GetFTParamCount
: _GetFTParamCount
<typename GetFTSubType
<T
>::FType
> {};
109 template <typename T
, uint N
> struct _GetFTParamId
{};
110 template <typename R
, typename Arg
, typename
...Args
>
111 struct _GetFTParamId
<R (*)(Arg
, Args
...), 0> {
112 static const bool OK
= GetFTTypeId
<Arg
>::OK
;
113 static const FTTypeId Value
= GetFTTypeId
<Arg
>::Value
;
115 template <typename R
, uint N
>
116 struct _GetFTParamId
<R (*)(), N
> {
117 static const bool OK
= false;
118 static const FTTypeId Value
= FTT_Void
;
120 template <uint N
, typename R
, typename Arg
, typename
...Args
>
121 struct _GetFTParamId
<R (*)(Arg
, Args
...), N
> {
122 static const bool OK
= _GetFTParamId
<R (*)(Args
...), N
- 1>::OK
;
123 static const FTTypeId Value
= _GetFTParamId
<R (*)(Args
...), N
- 1>::Value
;
125 template <typename T
, uint N
> struct GetFTParamId
: _GetFTParamId
<typename GetFTSubType
<T
>::FType
, N
> {};
126 } // end of namespace jitcs
129 // _JITCS_FNCTYPEINFO_H_