@@ -26,7 +26,7 @@ static int _process_unspecified_params(
26
26
if (p_tag != NULL && p_tag -> handler ) {
27
27
metac_value_event_t ev = {
28
28
.type = METAC_RQVST_va_list ,
29
- .va_list_param_id = param_id , /* TODO: to remove?*/
29
+ .va_list_param_id = param_id ,
30
30
.p_return_value = metac_parameter_storage_new_param_value (p_param_storage , param_id ),
31
31
.p_va_list_container = & cntr ,
32
32
};
@@ -50,51 +50,107 @@ static int _process_unspecified_params(
50
50
return failed ;
51
51
}
52
52
53
- #define _APPEND_PARAM_2 (_NEXT_ , _N_ , args ...) if (failure == 0) { \
53
+ #define _process_bt_ (arg , _type_ , _pseudoname_ , _short_type_name_ ) \
54
+ if (strcmp(param_base_type_name, #_pseudoname_) == 0 && param_entry_byte_size == sizeof(_type_)) { \
55
+ metac_value_set_##_short_type_name_(p_param_value, *((_type_*)arg)); \
56
+ } else
57
+
58
+ #define _process_enum_ (arg , _type_ , _short_type_name_ ) \
59
+ if (param_entry_byte_size == sizeof(_type_)) { \
60
+ _type_ v = *((_type_*)arg); \
61
+ memcpy(metac_value_addr(p_param_value), &v, param_entry_byte_size); \
62
+ } else
63
+
64
+ #define _QSTRING (_string_ ...) \
65
+ #_string_
66
+ #define _QSTRING_ARG (_args ) \
67
+ _QSTRING(_args)
68
+
69
+ #define _APPEND_PARAM (_NEXT_ , _N_ , args ...) if (failure == 0) { \
54
70
metac_entry_t *p_param_entry = metac_entry_by_paremeter_id(p_val_entry, param_id); \
55
71
if (metac_entry_is_unspecified_parameter(p_param_entry) == 0 && metac_entry_is_va_list_parameter(p_param_entry) == 0) { \
56
72
/* normal argument */ \
57
- typeof (MR_FIRST (args )) _x_val = MR_FIRST (args ); \
58
73
metac_entry_t * p_param_entry = metac_entry_by_paremeter_id (p_val_entry , param_id ); \
74
+ metac_entry_t * p_param_type_entry = metac_entry_parameter_entry (p_param_entry ); \
75
+ if (p_param_type_entry == NULL ) { \
76
+ failure = 1 ; \
77
+ break ; \
78
+ } \
59
79
metac_size_t param_entry_byte_size = 0 ; \
60
80
if (metac_entry_byte_size (p_param_entry , & param_entry_byte_size ) != 0 ) { \
61
81
printf ("param %d metac_entry_byte_size failed\n" , param_id ); \
62
- failure = 1 ; \
82
+ failure = 2 ; \
63
83
break ; \
64
84
} \
85
+ typeof (MR_FIRST (args )) _x_val = MR_FIRST (args ); \
65
86
if (metac_parameter_storage_append_by_buffer (p_param_storage , p_param_entry , param_entry_byte_size ) == 0 ) { \
66
87
metac_value_t * p_param_value = metac_parameter_storage_new_param_value (p_param_storage , param_id ); \
67
- if (p_param_value != NULL ) { \
68
- if (param_entry_byte_size != sizeof (_x_val )) { \
69
- printf ("param %d got sz %d, expectect sz %d\n" , param_id , (int )sizeof (_x_val ), (int )param_entry_byte_size ); \
70
- /*TODO: - handle that */ \
71
- } \
72
- memcpy (metac_value_addr (p_param_value ), & _x_val , param_entry_byte_size ); \
88
+ \
89
+ if (metac_entry_is_base_type (p_param_type_entry ) != 0 ) { \
90
+ metac_name_t param_base_type_name = metac_entry_base_type_name (p_param_type_entry ); \
91
+ _process_bt_ (& _x_val , char , char , char ) \
92
+ _process_bt_ (& _x_val , unsigned char , unsigned char , uchar ) \
93
+ _process_bt_ (& _x_val , short , short int , short ) \
94
+ _process_bt_ (& _x_val , unsigned short , unsigned short int , ushort ) \
95
+ _process_bt_ (& _x_val , int , int , int ) \
96
+ _process_bt_ (& _x_val , unsigned int , unsigned int , uint ) \
97
+ _process_bt_ (& _x_val , long , long int , long ) \
98
+ _process_bt_ (& _x_val , unsigned long , unsigned long int , ulong ) \
99
+ _process_bt_ (& _x_val , long long , long long int , llong ) \
100
+ _process_bt_ (& _x_val , unsigned long long , unsigned long long int , ullong ) \
101
+ _process_bt_ (& _x_val , bool , _Bool , bool ) \
102
+ _process_bt_ (& _x_val , float , float , float ) \
103
+ _process_bt_ (& _x_val , double , double , double ) \
104
+ _process_bt_ (& _x_val , long double , long double , ldouble ) \
105
+ _process_bt_ (& _x_val , float complex , complex float , float_complex ) \
106
+ _process_bt_ (& _x_val , double complex , complex double , double_complex ) \
107
+ _process_bt_ (& _x_val , long double complex , long complex double , ldouble_complex ); \
108
+ } else if (metac_entry_is_enumeration (p_param_type_entry ) != 0 ) { \
109
+ _process_enum_ (& _x_val , char , char ) \
110
+ _process_enum_ (& _x_val , short , short ) \
111
+ _process_enum_ (& _x_val , int , int ) \
112
+ _process_enum_ (& _x_val , long , long ) \
113
+ _process_enum_ (& _x_val , long long , llong ); \
114
+ } else if (metac_entry_is_pointer (p_param_type_entry ) != 0 ) { \
115
+ /* ensure arg isn't string constant */ \
116
+ char _s_arg [] = _QSTRING_ARG (MR_FIRST (args )); \
117
+ if (_s_arg [0 ] == '\"' ) { \
118
+ /* TODO: can't handle structs, va_list as arguments because of this line */ \
119
+ char * s = ((char * )MR_FIRST (args )); \
120
+ memcpy (metac_value_addr (p_param_value ), & s , param_entry_byte_size ); \
121
+ } else { \
122
+ memcpy (metac_value_addr (p_param_value ), & _x_val , param_entry_byte_size ); \
123
+ } \
124
+ } else { \
125
+ /* not supported */ \
126
+ failure = 3 ; \
73
127
metac_value_delete (p_param_value ); \
128
+ break ; \
74
129
} \
130
+ /*cleanup*/ \
131
+ metac_value_delete (p_param_value ); \
75
132
} \
76
133
} else if (metac_entry_is_va_list_parameter (p_param_entry ) != 0 ) { \
134
+ /* not supported */ \
135
+ failure = 4 ; \
136
+ break ; \
77
137
} else if (metac_entry_is_unspecified_parameter (p_param_entry ) != 0 ) { \
78
138
if (metac_parameter_storage_append_by_parameter_storage (p_param_storage , p_param_entry ) != 0 ) { \
79
139
failure = 5 ; \
80
140
break ; \
81
141
} \
82
142
if (_process_unspecified_params (p_param_storage , p_val , p_param_entry , p_tag_map , param_id , _N_ , args ) != 0 ) { \
83
- failure = 4 ; \
143
+ failure = 6 ; \
84
144
break ; \
85
145
} \
86
146
break ; \
87
- } else { \
88
- failure = 3 ; \
89
- break ; \
90
147
} \
91
148
if (failure == 0 ) { \
92
149
++ param_id ; \
93
150
_NEXT_ \
94
151
} \
95
152
}
96
153
97
-
98
154
// this gets called in the context where p_param_storage is declared
99
155
#define _WRAP (_tag_map_ , _fn_ , _args_ ...) ({ \
100
156
metac_tag_map_t * p_tag_map = _tag_map_; \
@@ -104,11 +160,10 @@ static int _process_unspecified_params(
104
160
metac_num_t param_id = 0; \
105
161
/* append params*/ \
106
162
do { \
107
- MR_FOREACH_EX (_APPEND_PARAM_2 , _args_ ) \
163
+ MR_FOREACH_EX (_APPEND_PARAM , _args_ ) \
108
164
} while (0 ); \
109
165
if (failure != 0 ) { \
110
166
printf ("failure %d\n" , failure ); \
111
- /* TODO: */ \
112
167
} \
113
168
p_val ; \
114
169
})
0 commit comments