-
Notifications
You must be signed in to change notification settings - Fork 1
/
method.h
75 lines (60 loc) · 1.06 KB
/
method.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef __METHOD_H
#define __METHOD_H
#include <string.h>
#include <stdbool.h>
#include <sys/types.h>
#include <kernel-types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define method_foreachparam(param, sig) \
for ((param) = (sig); *(param) != '\0'; (param) += 1)
static inline char method_returntype(const char * sig)
{
switch (*sig)
{
case ':':
case '\0':
return T_VOID;
default:
return *sig;
}
}
static inline const char * method_params(const char * sig)
{
const char * ptr;
if ((ptr = strchr(sig, ':')) == NULL)
{
return sig;
}
if (*(ptr+1) == '\0')
{
return "v";
}
return ptr+1;
}
static inline size_t method_numparams(const char * sig)
{
size_t params = 0;
while(*sig != '\0')
{
switch(*sig)
{
case T_VOID:
break;
default:
params += 1;
break;
}
sig += 1;
}
return params;
}
static inline bool method_isequal(const char * sig1, const char * sig2)
{
return strcmp(method_params(sig1), method_params(sig2)) == 0 && method_returntype(sig1) == method_returntype(sig2);
}
#ifdef __cplusplus
}
#endif
#endif