// define_expression = "<==" expression. bool adam_parser::is_define_expression(line_position_t& position, array_t& expression) { if (!is_token(is_k)) return false; position = next_position(); require_expression(expression); return true; }
void pos_iteration(int *steps) { double dtinc = 0.0004; double dt; next_position(steps); dt = dist - tim; if ((((delta_t - feedrate_end) / dtinc) >= dt) && (delta_t > feedrate_end)) delta_t -= dtinc; else if (delta_t < (feedrate - dtinc)) delta_t += dtinc; }
bool adam_parser::is_conditional(line_position_t& position, array_t& expression) { if (!is_keyword(when_k)) return false; require_token(open_parenthesis_k); position = next_position(); require_expression(expression); require_token(close_parenthesis_k); return true; }
string_iterator_t *new_string_iterator(const char *source, const char *delimiters) { string_iterator_t *self = malloc(sizeof(string_iterator_t)); self->source = calloc(strlen(source) + 1, sizeof(char)); strcpy(self->source, source); self->delimiters = calloc(strlen(delimiters) + 1, sizeof(char)); strcpy(self->delimiters, delimiters); self->next_position = 0; next_position(self); self->current_string = next_string(self); self->good = (self->current_string != NULL); return self; }
// relate_decl = [conditional] "relate" "{" relate_expression relate_expression { relate_expression } "}" [trail_comment] bool adam_parser::is_relate_decl(line_position_t& position, array_t& expression, relation_set_t& relation_set, std::string& brief) { /* REVISIT (sparent) : A relation_set_t needs a position independent of the continitional expression in order to report overconstraints. Here we "fudge" and reuse the conditional expression for this purpose. */ bool conditional(is_conditional(position, expression)); if (!is_keyword(relate_k)) { if (conditional) throw_exception("relate required"); return false; } if (!conditional) position = next_position(); require_token(open_brace_k); relation_t relation_1; relation_t relation_2; if (!is_relate_expression_decl(relation_1) || !is_relate_expression_decl(relation_2)) { throw_exception("minimum two relate_expression required"); } relation_set.push_back(relation_1); relation_set.push_back(relation_2); relation_1.expression_m.clear(); while (is_relate_expression_decl(relation_1)) { relation_set.push_back(relation_1); relation_1.expression_m.clear(); } require_token(close_brace_k); (void)is_trail_comment(brief); return true; }
void binspector_parser_t::parse() { try { if (!is_struct_set()) throw_exception("Format description must not be empty"); require_token(adobe::eof_k); } catch (const adobe::stream_error_t& error) { // Necessary to keep stream_error_t from being caught by the next catch throw error; } catch (const std::exception& error) { putback(); throw adobe::stream_error_t(error, next_position()); } }
char *next_string(string_iterator_t *self) { char *result = NULL; unsigned short done = 0; size_t begin = self->next_position; size_t end = begin; if(self->next_position < strlen(self->source)) { while(end < strlen(self->source) && !done) { size_t i = 0; while(i < strlen(self->delimiters) && !done) { if(self->source[end] == self->delimiters[i]) { --end; --end; done = 1; } ++i; } ++end; } result = calloc(((end + 1) - begin) + 1, sizeof(char)); for(size_t i = 0; i <= end - begin; ++i) { result[i] = self->source[begin + i]; } result[(end + 1) - begin] = '\0'; self->next_position = end + 2; next_position(self); } return result; }
bool binspector_parser_t::is_field() { adobe::name_t named_field_identifier; atom_base_type_t atom_type(atom_unknown_k); adobe::array_t bit_count_expression; adobe::array_t is_big_endian_expression; bool named_field(is_named_field(named_field_identifier)); bool atom_field(!named_field && is_atom_field(atom_type, bit_count_expression, is_big_endian_expression)); if (!named_field && !atom_field) return false; adobe::name_t field_identifier; require_identifier(field_identifier); adobe::array_t field_size_expression; field_size_t field_size_type(field_size_none_k); adobe::array_t offset_expression; adobe::array_t callback_expression; bool shuffleable(false); is_field_size(field_size_type, field_size_expression, shuffleable); // optional is_offset(offset_expression); // optional try { static const adobe::array_t empty_array_k; adobe::dictionary_t parameters; parameters[key_field_name].assign(field_identifier); parameters[key_field_size_type].assign(field_size_type); parameters[key_field_size_expression].assign(field_size_expression); parameters[key_field_offset_expression].assign(offset_expression); parameters[key_field_shuffle].assign(shuffleable); // add the field to the current structure description if (named_field) { parameters[key_field_type].assign(value_field_type_named); parameters[key_named_type_name].assign(named_field_identifier); } else { parameters[key_field_type].assign(value_field_type_atom); parameters[key_atom_base_type].assign(atom_type); parameters[key_atom_bit_count_expression].assign(bit_count_expression); parameters[key_atom_is_big_endian_expression].assign(is_big_endian_expression); } insert_parser_metadata(parameters); add_field_proc_m(field_identifier, parameters); } catch (const std::exception& error) { putback(); throw adobe::stream_error_t(error, next_position()); } return true; }
void expression_parser::throw_exception(const name_t& found, const name_t& expected) { throw_parser_exception(found, expected, next_position()); }
void expression_parser::throw_exception(const char* errorString) { throw_parser_exception(errorString, next_position()); }
const ConstArrayView next_draw() { return array_view().slice(next_position(), -1, -1); }
int SqAttacked(short square, short side, short *blockable) { #ifdef SAVE_NEXTPOS short d; #else unsigned char *ppos, *pdir; #endif short u, ptyp; if (MatchSignature(threats_signature[side])) { *blockable = true; /* don't know */ return Anyattack(side, square); } /* * First check neighbouring squares, * then check Knights. * then check Bishops, * then (last) check Rooks, */ *blockable = false; /* try a capture from direct neighboured squares */ ptyp = ptype[black][king]; #ifdef SAVE_NEXTPOS u = first_direction(ptyp, &d, square); #else pdir = (*nextdir[ptyp])[square]; u = pdir[square]; #endif do { if (color[u] == side) /* can piece reach square in one step ? */ #ifdef CHECK_DISTANCE { if (piece_distance(side, board[u], u, square) == 1) return true; } #else { short v; short ptypv = ptype[side][board[u]]; #ifdef SAVE_NEXTPOS short dv; v = first_direction(ptypv, &dv, u); #else unsigned char *qdir; qdir = (*nextdir[ptypv])[u]; v = qdir[u]; #endif do { if (v == square) return true; #ifdef SAVE_NEXTPOS v = next_direction(ptypv, &dv, u); #else v = qdir[v]; #endif } while (v != u); } #endif #ifdef SAVE_NEXTPOS u = next_direction(ptyp, &d, square); #else u = pdir[u]; #endif } while (u != square); /* try a knight capture (using xside's knight moves) */ ptyp = ptype[side ^ 1][knight]; #ifdef SAVE_NEXTPOS u = first_direction(ptyp, &d, square); #else pdir = (*nextdir[ptyp])[square]; u = pdir[square]; #endif do { if (color[u] == side && board[u] == knight) return true; #ifdef SAVE_NEXTPOS u = next_direction(ptyp, &d, square); #else u = pdir[u]; #endif } while (u != square); *blockable = true; /* try a (promoted) bishop capture */ ptyp = ptype[black][bishop]; #ifdef SAVE_NEXTPOS u = first_direction(ptyp, &d, square); #else ppos = (*nextpos[ptyp])[square]; pdir = (*nextdir[ptyp])[square]; u = ppos[square]; #endif do { if (color[u] == neutral) #ifdef SAVE_NEXTPOS u = next_position(ptyp, &d, square, u); #else u = ppos[u]; #endif else { if (color[u] == side && (unpromoted[board[u]] == bishop)) return true; #ifdef SAVE_NEXTPOS u = next_direction(ptyp, &d, square); #else u = pdir[u]; #endif } }
void GroupedIconView::LayoutItems() { if (!model()) return; const int count = model()->rowCount(); QString last_group; QPoint next_position(0, 0); int max_row_height = 0; visual_rects_.clear(); visual_rects_.reserve(count); headers_.clear(); for (int i=0 ; i<count ; ++i) { const QModelIndex index(model()->index(i, 0)); const QString group = index.data(Role_Group).toString(); const QSize size(rectForIndex(index).size()); // Is this the first item in a new group? if (group != last_group) { // Add the group header. Header header; header.y = next_position.y() + max_row_height + header_indent_; header.first_row = i; header.text = group; if (!last_group.isNull()) { header.y += header_spacing_; } headers_ << header; // Remember this group so we don't add it again. last_group = group; // Move the next item immediately below the header. next_position.setX(0); next_position.setY(header.y + header_height() + header_indent_ + header_spacing_); max_row_height = 0; } // Take into account padding and spacing QPoint this_position(next_position); if (this_position.x() == 0) { this_position.setX(this_position.x() + item_indent_); } else { this_position.setX(this_position.x() + spacing()); } // Should this item wrap? if (next_position.x() != 0 && this_position.x() + size.width() >= viewport()->width()) { next_position.setX(0); next_position.setY(next_position.y() + max_row_height); this_position = next_position; this_position.setX(this_position.x() + item_indent_); max_row_height = 0; } // Set this item's geometry visual_rects_.append(QRect(this_position, size)); // Update next index next_position.setX(this_position.x() + size.width()); max_row_height = qMax(max_row_height, size.height()); } verticalScrollBar()->setRange(0, next_position.y() + max_row_height - viewport()->height()); update(); }