X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fdata.h;h=57bc5c5ac2b8849b4f6b20ada0667b9b3bcc28c7;hp=3c48716cd21820af4b1d4e30f657e8a3479c04e9;hb=53495ef4bd0321f7f92dd05eef8e01b90d7b415a;hpb=9bcb1df0786a8193d65949c857baaba2f4296e84 diff --git a/src/data.h b/src/data.h index 3c48716..57bc5c5 100644 --- a/src/data.h +++ b/src/data.h @@ -36,7 +36,7 @@ #include #define PSI_DEBUG_PRINT(ctx, msg, ...) do { \ - if (PSI_DATA(ctx)->flags & PSI_DEBUG) { \ + if ((ctx) && (PSI_DATA(ctx)->flags & PSI_DEBUG)) { \ fprintf(stderr, msg, __VA_ARGS__); \ } \ } while(0) @@ -70,4 +70,52 @@ bool psi_data_validate(struct psi_data *dst, struct psi_data *src); void psi_data_dtor(struct psi_data *data); void psi_data_dump(int fd, struct psi_data *data); +struct psi_validate_stack { + HashTable types; + HashTable structs; + HashTable unions; +}; + +static inline void psi_validate_stack_ctor(struct psi_validate_stack *stack) +{ + zend_hash_init(&stack->types, 0, NULL, NULL, 0); + zend_hash_init(&stack->structs, 0, NULL, NULL, 0); + zend_hash_init(&stack->unions, 0, NULL, NULL, 0); +} + +static inline void psi_validate_stack_dtor(struct psi_validate_stack *stack) +{ + zend_hash_destroy(&stack->types); + zend_hash_destroy(&stack->structs); + zend_hash_destroy(&stack->unions); +} + +#define psi_validate_stack_has_type(s, t) \ + ((s) ? zend_hash_str_exists(&(s)->types, (t), strlen(t)) : false) +#define psi_validate_stack_has_struct(s, t) \ + ((s) ? zend_hash_str_exists(&(s)->structs, (t), strlen(t)) : false) +#define psi_validate_stack_has_union(s, t) \ + ((s) ? zend_hash_str_exists(&(s)->unions, (t), strlen(t)) : false) + +#define psi_validate_stack_add_type(s, t, p) \ + do { if (s) zend_hash_str_add_ptr(&(s)->types, (t), strlen(t), (p)); } while(0) +#define psi_validate_stack_add_struct(s, t, p) \ + do { if (s) zend_hash_str_add_ptr(&(s)->structs, (t), strlen(t), (p)); } while(0) +#define psi_validate_stack_add_union(s, t, p) \ + do { if (s) zend_hash_str_add_ptr(&(s)->unions, (t), strlen(t), (p)); } while(0) + +#define psi_validate_stack_get_type(s, t) \ + ((s) ? zend_hash_str_find_ptr(&(s)->types, (t), strlen(t)) : NULL) +#define psi_validate_stack_get_struct(s, t) \ + ((s) ? zend_hash_str_find_ptr(&(s)->structs, (t), strlen(t)) : NULL) +#define psi_validate_stack_get_union(s, t) \ + ((s) ? zend_hash_str_find_ptr(&(s)->unions, (t), strlen(t)) : NULL) + +#define psi_validate_stack_del_type(s, t) \ + do { if (s) zend_hash_str_del(&(s)->types, (t), strlen(t)); } while(0) +#define psi_validate_stack_del_struct(s, t) \ + do { if (s) zend_hash_str_del(&(s)->structs, (t), strlen(t)); } while(0) +#define psi_validate_stack_del_union(s, t) \ + do { if (s) zend_hash_str_del(&(s)->unions, (t), strlen(t)); } while(0) + #endif