/* Wrap a text delimited by START and END into PRETTY-PRINTER. */ static void pp_wrap_text (pretty_printer *pp, const char *start, const char *end) { bool wrapping_line = pp_is_wrapping_line (pp); while (start != end) { /* Dump anything bordered by whitespaces. */ { const char *p = start; while (p != end && !ISBLANK (*p) && *p != '\n') ++p; if (wrapping_line && p - start >= pp_remaining_character_count_for_line (pp)) pp_newline (pp); pp_append_text (pp, start, p); start = p; } if (start != end && ISBLANK (*start)) { pp_space (pp); ++start; } if (start != end && *start == '\n') { pp_newline (pp); ++start; } } }
static void test_begin_group_cb (diagnostic_context * context) { pp_string (context->printer, "================================= BEGIN GROUP =============================="); pp_newline (context->printer); }
void test_diagnostic_start_span_fn (diagnostic_context *context, expanded_location exploc) { pp_string (context->printer, "START_SPAN_FN: "); pp_newline (context->printer); }
/* Print the physical source line corresponding to the location of this diagnostics, and a caret indicating the precise column. */ void diagnostic_show_locus (diagnostic_context * context, const diagnostic_info *diagnostic) { const char *line; char *buffer; expanded_location s; int max_width; const char *saved_prefix; const char *caret_cs, *caret_ce; if (!context->show_caret || diagnostic->location <= BUILTINS_LOCATION || diagnostic->location == context->last_location) return; context->last_location = diagnostic->location; s = expand_location_to_spelling_point (diagnostic->location); line = location_get_source_line (s); if (line == NULL) return; max_width = context->caret_max_width; line = adjust_line (line, max_width, &(s.column)); pp_newline (context->printer); saved_prefix = pp_get_prefix (context->printer); pp_set_prefix (context->printer, NULL); pp_character (context->printer, ' '); while (max_width > 0 && *line != '\0') { char c = *line == '\t' ? ' ' : *line; pp_character (context->printer, c); max_width--; line++; } pp_newline (context->printer); caret_cs = colorize_start (pp_show_color (context->printer), "caret"); caret_ce = colorize_stop (pp_show_color (context->printer)); /* pp_printf does not implement %*c. */ size_t len = s.column + 3 + strlen (caret_cs) + strlen (caret_ce); buffer = XALLOCAVEC (char, len); snprintf (buffer, len, "%s %*c%s", caret_cs, s.column, '^', caret_ce); pp_string (context->printer, buffer); pp_set_prefix (context->printer, saved_prefix); }
void diagnostic_report_current_module (diagnostic_context *context, location_t where) { const struct line_map *map = NULL; if (pp_needs_newline (context->printer)) { pp_newline (context->printer); pp_needs_newline (context->printer) = false; } if (where <= BUILTINS_LOCATION) return; linemap_resolve_location (line_table, where, LRK_MACRO_DEFINITION_LOCATION, &map); if (map && diagnostic_last_module_changed (context, map)) { diagnostic_set_last_module (context, map); if (! MAIN_FILE_P (map)) { map = INCLUDED_FROM (line_table, map); if (context->show_column) pp_verbatim (context->printer, "In file included from %s:%d:%d", LINEMAP_FILE (map), LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map)); else pp_verbatim (context->printer, "In file included from %s:%d", LINEMAP_FILE (map), LAST_SOURCE_LINE (map)); while (! MAIN_FILE_P (map)) { map = INCLUDED_FROM (line_table, map); pp_verbatim (context->printer, ",\n from %s:%d", LINEMAP_FILE (map), LAST_SOURCE_LINE (map)); } pp_verbatim (context->printer, ":"); pp_newline (context->printer); } } }
static void print_insn_with_notes (pretty_printer *pp, const_rtx x) { pp_string (pp, print_rtx_head); print_insn (pp, x, 1); pp_newline (pp); if (INSN_P (x) && REG_NOTES (x)) for (rtx note = REG_NOTES (x); note; note = XEXP (note, 1)) { pp_printf (pp, "%s %s ", print_rtx_head, GET_REG_NOTE_NAME (REG_NOTE_KIND (note))); if (GET_CODE (note) == INT_LIST) pp_printf (pp, "%d", XINT (note, 0)); else print_pattern (pp, XEXP (note, 0), 1); pp_newline (pp); } }
void pp_c_function_definition (c_pretty_printer *pp, tree t) { pp_declaration_specifiers (pp, t); pp_declarator (pp, t); pp_needs_newline (pp) = true; pp_statement (pp, DECL_SAVED_TREE (t)); pp_newline (pp); pp_flush (pp); }
/* * Flush the current line then move to the next line * - empty the pending token buffer */ static void print_newline(printer_t *p) { if (p->pending_tokens.size > 0) { print_pending(p); } pp_newline(p); assert(!p->area.truncate || p->margin >= 4); p->no_space = true; // prevent space after the new line p->full_line = false; }
void diagnostic_report_current_module (diagnostic_context *context) { const struct line_map *map; if (pp_needs_newline (context->printer)) { pp_newline (context->printer); pp_needs_newline (context->printer) = false; } if (input_location <= BUILTINS_LOCATION) return; map = linemap_lookup (line_table, input_location); if (map && diagnostic_last_module_changed (context, map)) { diagnostic_set_last_module (context, map); if (! MAIN_FILE_P (map)) { map = INCLUDED_FROM (line_table, map); if (flag_show_column) pp_verbatim (context->printer, "In file included from %s:%d:%d", map->to_file, LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map)); else pp_verbatim (context->printer, "In file included from %s:%d", map->to_file, LAST_SOURCE_LINE (map)); while (! MAIN_FILE_P (map)) { map = INCLUDED_FROM (line_table, map); pp_verbatim (context->printer, ",\n from %s:%d", map->to_file, LAST_SOURCE_LINE (map)); } pp_verbatim (context->printer, ":"); pp_newline (context->printer); } } }
void diagnostic_show_locus (diagnostic_context * context, const diagnostic_info *diagnostic) { pp_newline (context->printer); if (!context->show_caret || diagnostic_location (diagnostic, 0) <= BUILTINS_LOCATION || diagnostic_location (diagnostic, 0) == context->last_location) return; context->last_location = diagnostic_location (diagnostic, 0); const char *saved_prefix = pp_get_prefix (context->printer); pp_set_prefix (context->printer, NULL); layout layout (context, diagnostic); for (int line_span_idx = 0; line_span_idx < layout.get_num_line_spans (); line_span_idx++) { const line_span *line_span = layout.get_line_span (line_span_idx); if (layout.print_heading_for_line_span_index_p (line_span_idx)) { expanded_location exploc = layout.get_expanded_location (line_span); context->start_span (context, exploc); } int last_line = line_span->get_last_line (); for (int row = line_span->get_first_line (); row <= last_line; row++) { /* Print the source line, followed by an annotation line consisting of any caret/underlines, then any fixits. If the source line can't be read, print nothing. */ line_bounds lbounds; if (layout.print_source_line (row, &lbounds)) { layout.print_annotation_line (row, lbounds); layout.print_any_fixits (row, diagnostic->richloc); } } } pp_set_prefix (context->printer, saved_prefix); }
void print_pattern (pretty_printer *pp, const_rtx x, int verbose) { if (! x) { pp_string (pp, "(nil)"); return; } switch (GET_CODE (x)) { case SET: print_value (pp, SET_DEST (x), verbose); pp_equal (pp); print_value (pp, SET_SRC (x), verbose); break; case RETURN: case SIMPLE_RETURN: case EH_RETURN: pp_string (pp, GET_RTX_NAME (GET_CODE (x))); break; case CALL: print_exp (pp, x, verbose); break; case CLOBBER: case USE: pp_printf (pp, "%s ", GET_RTX_NAME (GET_CODE (x))); print_value (pp, XEXP (x, 0), verbose); break; case VAR_LOCATION: pp_string (pp, "loc "); print_value (pp, PAT_VAR_LOCATION_LOC (x), verbose); break; case COND_EXEC: pp_left_paren (pp); if (GET_CODE (COND_EXEC_TEST (x)) == NE && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx) print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose); else if (GET_CODE (COND_EXEC_TEST (x)) == EQ && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx) { pp_exclamation (pp); print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose); } else print_value (pp, COND_EXEC_TEST (x), verbose); pp_string (pp, ") "); print_pattern (pp, COND_EXEC_CODE (x), verbose); break; case PARALLEL: { int i; pp_left_brace (pp); for (i = 0; i < XVECLEN (x, 0); i++) { print_pattern (pp, XVECEXP (x, 0, i), verbose); pp_semicolon (pp); } pp_right_brace (pp); } break; case SEQUENCE: { pp_string (pp, "sequence{"); if (INSN_P (XVECEXP (x, 0, 0))) { /* Print the sequence insns indented. */ const char * save_print_rtx_head = print_rtx_head; char indented_print_rtx_head[32]; pp_newline (pp); gcc_assert (strlen (print_rtx_head) < sizeof (indented_print_rtx_head) - 4); snprintf (indented_print_rtx_head, sizeof (indented_print_rtx_head), "%s ", print_rtx_head); print_rtx_head = indented_print_rtx_head; for (int i = 0; i < XVECLEN (x, 0); i++) print_insn_with_notes (pp, XVECEXP (x, 0, i)); pp_printf (pp, "%s ", save_print_rtx_head); print_rtx_head = save_print_rtx_head; } else { for (int i = 0; i < XVECLEN (x, 0); i++) { print_pattern (pp, XVECEXP (x, 0, i), verbose); pp_semicolon (pp); } } pp_right_brace (pp); } break; case ASM_INPUT: pp_printf (pp, "asm {%s}", XSTR (x, 0)); break; case ADDR_VEC: /* Fall through. */ case ADDR_DIFF_VEC: print_value (pp, XEXP (x, 0), verbose); break; case TRAP_IF: pp_string (pp, "trap_if "); print_value (pp, TRAP_CONDITION (x), verbose); break; case UNSPEC: case UNSPEC_VOLATILE: /* Fallthru -- leave UNSPECs to print_exp. */ default: print_value (pp, x, verbose); } } /* print_pattern */