Esempio n. 1
0
/* 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);
}
  static void adjust_region(cv::Rect &region, const int const_width, const int const_height)
  {
	  adjust_line(region.x, region.width, const_width);
	  adjust_line(region.y, region.height, const_height);
  }