/* * Print all the pending tokens. * Free all pending tokens and empty the pending_vector. * - p->pending_col = column where printing should start */ static void print_pending(printer_t *p) { pvector_t *v; void *tk; bool space; uint32_t i, n; // restore p->col p->col = p->pending_col; v = &p->pending_tokens; n = v->size; assert(n > 0); // no space before the first token space = false; for (i=0; i<n; i++) { tk = v->data[i]; switch (ptr_tag(tk)) { case PP_TOKEN_OPEN_TAG: if (space) pp_space(p); print_label(p, untag_open(tk)); space = tk_sep_allowed(untag_open(tk)); break; case PP_TOKEN_ATOMIC_TAG: if (space) pp_space(p); print_atomic(p, untag_atomic(tk)); space = true; break; case PP_TOKEN_CLOSE_TAG: print_close(p, untag_close(tk)); space = true; break; case PP_TOKEN_SEPARATOR_TAG: // no space before or after that token print_atomic(p, untag_separator(tk)); space = false; break; } } pvector_reset(v); }
int print_single_node(FILE* dest, struct ast_node_t* node, int padding, int wrap) { TOKEN_TYPE_T type = node->type; if (is_meta(type)) { //ignore } else if (is_atomic(type)) { print_atomic(dest, node, padding, wrap); } else { return print_compozite(dest, node, padding, wrap); } return 0; }
/* * Print atomic token tk then free it. * - it's always freed */ static void print_atomic_token(printer_t *p, pp_atomic_token_t *tk) { uint32_t new_col; if (p->area.truncate) { if (p->col + 4 <= p->margin) { /* * truncate mode, line not full, nothing pending */ assert(!p->full_line && p->pending_tokens.size == 0); print_blank(p); new_col = p->col + tk->size; if (new_col + 4 <= p->margin) { // tk fits and there's room for ' ...' after it print_atomic(p, tk); } else if (new_col <= p->margin) { // we can't tell whether tk fits fully yet // because we may need ellipsis after tk. p->pending_col = p->col; p->col = new_col; pvector_push(&p->pending_tokens, tag_atomic(tk)); } else { // tk does not fit: print it truncated followed by ellipsis print_atomic_truncated(p, tk); p->full_line = true; } } else if (!p->full_line) { /* * truncate mode, line not full, tokens pending */ assert(p->col <= p->margin && p->pending_tokens.size > 0); // add tk to the pending tokens if it fits new_col = p->col + tk->size + (! p->no_space); if (new_col <= p->margin) { p->col = new_col; pvector_push(&p->pending_tokens, tag_atomic(tk)); } else { // the pending tokens don't fit // print what we can + ellipsis print_pending_truncated(p); free_atomic_token(p, tk); p->full_line = true; } } else { /* * truncate mode, line full, nothing pending */ assert(p->pending_tokens.size == 0); free_atomic_token(p, tk); } } else { /* * don't truncate */ print_blank(p); print_atomic(p, tk); } }