28#define swex_init_val( expr_type, expr ) \
29 expr_type swex_init_imm_tmp_var_##expr_type##_##expr##__ = ( expr ); \
30 expr_type *swex_init_imm_tmp_var_##expr_type##_##expr##_ptr_ = \
31 &( swex_init_imm_tmp_var_##expr_type##_##expr##__ ); \
32 _Switch_expression_push_( sizeof( expr_type ), \
33 &( swex_init_imm_tmp_var_##expr_type##_##expr##_ptr_ ) );
41#define swex_init_ptr( expr, nbytes ) _Switch_expression_push_( nbytes, ( expr ) );
44#define swex_init_str( expr ) \
45 const char *swex_init_imm_tmp_var_char##_##expr##__ = ( expr ); \
46 _Switch_expression_push_( strlen( expr ), \
47 &( swex_init_imm_tmp_var_char##_##expr##__ ) );
50#define as( VAR_NAME ) \
52 void *swex_as_var_addr = &( VAR_NAME ); \
53 _Switch_expression_init_var_( &swex_as_var_addr ); \
57#define as_new( NEW_VAR_TYPE, NEW_VAR_NAME ) \
58 NEW_VAR_TYPE NEW_VAR_NAME = ( NEW_VAR_TYPE ) 0; \
63#define resolve( RESULT_TYPE, RESULT ) \
66 *deref_as( RESULT_TYPE *, _Switch_expression_get_varaddr_() ) = RESULT; \
77#define swex_case_imm( type, expr_case ) \
79 if ( _Swex_aux_variable_ != NULL ) \
81 free_n( _Swex_aux_variable_ ); \
82 _Swex_aux_variable_ = NULL; \
84 _Swex_aux_variable_ = malloc( sizeof( type ) ); \
85 if ( _Swex_aux_variable_ == NULL ) \
86 err( ENOMEM, "swex_case_imm" ); \
87 type swex_case_imm_aux_var_ = expr_case; \
88 memcpy( _Swex_aux_variable_, &swex_case_imm_aux_var_, sizeof( type ) ); \
90 if ( !_Switch_expression_is_assigned_() \
91 && ( _Switch_expression_size_peek_() ) == sizeof( type ) \
92 && memcmp( _Switch_expression_value_peek_(), \
93 _Swex_aux_variable_, \
96 if ( _Switch_expression_assign_() != 1 )
99#define swex_case_ptr( expr_case, nbytes ) \
100 if ( !_Switch_expression_is_assigned_() \
101 && ( _Switch_expression_size_peek_() ) == sizeof( void * ) \
102 && memcmp( _Switch_expression_value_peek_(), expr_case, nbytes ) == 0 ) \
103 if ( _Switch_expression_assign_() != 1 )
106#define swex_case_str( expr_case ) \
107 if ( !_Switch_expression_is_assigned_() \
108 && strcmp( _Switch_expression_value_peek_(), expr_case ) == 0 ) \
109 if ( _Switch_expression_assign_() != 1 )
115#define swex_default() \
116 if ( !_Switch_expression_is_assigned_() && ( _Switch_expression_assign_() != 1 ) )
126#define swex_finish() \
129 _Switch_expression_pop_(); \
130 free_n( _Swex_aux_variable_ ); \
153LibraryDefined int _Switch_expression_push_(
const size_t nbytes,
const void *
const data )
155#define try_push( LIST, EXPRESSION, NBYTES ) \
158 if ( LIST == NULL && ( LIST = list_init_size( NBYTES ) ) == NULL ) \
159 return f_stack_trace( RV_ERROR ); \
160 if ( list_append( LIST, EXPRESSION ) == RV_ERROR ) \
161 return f_stack_trace( RV_ERROR ); \
165 static const bool SWEX_FALSE =
false;
166 static void *
const null = NULL;
168 try_push( _Switch_expr_sizes_stack_, &nbytes,
sizeof(
size_t ) );
169 try_push( _Switch_expr_values_stack_, data,
sizeof(
void * ) );
170 try_push( _Switch_expr_assigned_stack_, &SWEX_FALSE,
sizeof(
bool ) );
172 try_push( _Switch_expr_variables_stack_, &null,
sizeof(
void * ) );
180 return *(
bool * )
list_peek( _Switch_expr_assigned_stack_ );
185 static const bool SWEX_TRUE =
true;
188 list_size( _Switch_expr_assigned_stack_ ) - 1,
194#define try_pop( LIST ) \
197 if ( list_pop( LIST, NULL ) != RV_SUCCESS ) \
198 return f_stack_trace( RV_ERROR ); \
199 if ( list_size( LIST ) == 0 ) \
201 list_destroy( LIST ); \
207 try_pop( _Switch_expr_values_stack_ );
208 try_pop( _Switch_expr_assigned_stack_ );
209 try_pop( _Switch_expr_sizes_stack_ );
210 try_pop( _Switch_expr_variables_stack_ );
216LibraryDefined int _Switch_expression_init_var_(
void *
const var_addr )
219 list_size( _Switch_expr_variables_stack_ ) - 1,
#define LibraryDefined
Definition attributes.h:107
A dynamic array. (also called List, Vector or ArrayList)
struct dynamic_array List
Definition dynarr.h:41
void * list_at_last(struct dynamic_array *)
size_t list_size(const struct dynamic_array *)
Returns number of elements in the list.
const void * list_peek(const struct dynamic_array *ls)
int list_set_at(struct dynamic_array *, size_t index, const void *data)
#define RV_SUCCESS
Definition errors.h:34
#define deref_as(type, var)
Dereferences a pointer as if it was a pointer to type
Definition pointer_utils.h:53