inline errcode_t htable_set(htable_t * self, int hash, htable_key_t key, htable_key_t value) { int size = self->size; htable_bucket_t * bucket; int head_index = ((unsigned)hash) % size; int index = self->heads[head_index]; if (index < 0) { // no collision -- this bucket is free PROPAGATE(_htable_add(self, key, value, &index)); self->heads[head_index] = index; } else { // a collision -- find the terminal bucket. if we find that the key // already exists, just replace the value #ifdef HTABLE_COLLECT_STATS int length = 0; #endif while (index >= 0) { bucket = &self->buckets[index]; if (key == bucket->key) { // replace existing key #ifdef HTABLE_COLLECT_STATS self->total_set_replaces += 1; #endif bucket->value = value; RETURN_SUCCESSFUL; } index = bucket->next; #ifdef HTABLE_COLLECT_STATS length += 1; #endif } // we have found the terminal bucket PROPAGATE(_htable_add(self, key, value, &index)); #ifdef HTABLE_COLLECT_STATS self->total_set_collisions += 1; #endif bucket->next = index; #ifdef HTABLE_COLLECT_STATS int histindex = length; if (histindex >= HTABLE_HISTOGRAM_SIZE) { histindex = HTABLE_HISTOGRAM_SIZE - 1; } self->set_histogram[histindex] += 1; #endif } RETURN_SUCCESSFUL; }
void THROW(const char *code, ...) { va_list args; int i; const char *arg[4]; va_start(args, code); for (i = 0; i < 4; i++) arg[i] = va_arg(args, const char *); ERROR_define(code, arg); PROPAGATE(); }
void THROW(int code, ...) { va_list args; int i; char *arg[4]; va_start(args, code); for (i = 0; i < 4; i++) arg[i] = va_arg(args, char *); ERROR_define((char *)(intptr_t)code, arg); va_end(args); PROPAGATE(); }
void TRANS_tree(bool check_statement, TRANS_TREE **result, int *count) { #ifdef DEBUG int i; #endif tree_length = 0; current = JOB->current; level = 0; TRY { analyze_expr(0, RS_NONE); JOB->current = current; } CATCH { JOB->current = current; PROPAGATE(); } END_TRY #ifdef DEBUG printf("\n"); for (i = 0; i < tree_length; i++) { printf("[%d] ", i); READ_dump_pattern(&tree[i]); } #endif if (check_statement && (!is_statement())) THROW("This expression cannot be a statement"); if (result) { ALLOC(result, sizeof(PATTERN) * tree_length); memcpy(*result, tree, sizeof(PATTERN) * tree_length); *count = tree_length; } }