X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gcc%2Fpretty-print.c;h=49e1cb9da8131d397d545bee149028ce4d3f444d;hb=eac97ce657b0b1a3800383f327414771d26227e6;hp=955a4c45f7b52dd90d94fa451ed7693d51faece7;hpb=bdff91a14bf8e5d18b1eb47bb529894482065762;p=platform%2Fupstream%2Flinaro-gcc.git diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c index 955a4c4..49e1cb9 100644 --- a/gcc/pretty-print.c +++ b/gcc/pretty-print.c @@ -1,5 +1,5 @@ /* Various declarations for language-independent pretty-print subroutines. - Copyright (C) 2003-2013 Free Software Foundation, Inc. + Copyright (C) 2003-2016 Free Software Foundation, Inc. Contributed by Gabriel Dos Reis This file is part of GCC. @@ -25,12 +25,31 @@ along with GCC; see the file COPYING3. If not see #include "pretty-print.h" #include "diagnostic-color.h" -#include // For placement-new. - #if HAVE_ICONV #include #endif +/* Overwrite the given location/range within this text_info's rich_location. + For use e.g. when implementing "+" in client format decoders. */ + +void +text_info::set_location (unsigned int idx, location_t loc, bool show_caret_p) +{ + gcc_checking_assert (m_richloc); + m_richloc->set_range (line_table, idx, loc, show_caret_p); +} + +location_t +text_info::get_location (unsigned int index_of_location) const +{ + gcc_checking_assert (m_richloc); + + if (index_of_location == 0) + return m_richloc->get_loc (); + else + return UNKNOWN_LOCATION; +} + // Default construct an output buffer. output_buffer::output_buffer () @@ -40,7 +59,8 @@ output_buffer::output_buffer () cur_chunk_array (), stream (stderr), line_length (), - digit_buffer () + digit_buffer (), + flush_p (true) { obstack_init (&formatted_obstack); obstack_init (&chunk_obstack); @@ -54,9 +74,6 @@ output_buffer::~output_buffer () obstack_free (&formatted_obstack, NULL); } -/* A pointer to the formatted diagnostic message. */ -#define pp_formatted_text_data(PP) \ - ((const char *) obstack_base (pp_buffer (PP)->obstack)) /* Format an integer given by va_arg (ARG, type-specifier T) where type-specifier is a precision modifier as indicated by PREC. F is @@ -224,8 +241,7 @@ pp_maybe_wrap_text (pretty_printer *pp, const char *start, const char *end) static inline void pp_append_r (pretty_printer *pp, const char *start, int length) { - obstack_grow (pp_buffer (pp)->obstack, start, length); - pp_buffer (pp)->line_length += length; + output_buffer_append_r (pp_buffer (pp), start, length); } /* Insert enough spaces into the output area of PRETTY-PRINTER to bring @@ -628,10 +644,9 @@ pp_format (pretty_printer *pp, text_info *text) *formatters[argno] = XOBFINISH (&buffer->chunk_obstack, const char *); } -#ifdef ENABLE_CHECKING - for (; argno < PP_NL_ARGMAX; argno++) - gcc_assert (!formatters[argno]); -#endif + if (CHECKING_P) + for (; argno < PP_NL_ARGMAX; argno++) + gcc_assert (!formatters[argno]); /* Revert to normal obstack and wrapping mode. */ buffer->obstack = &buffer->formatted_obstack; @@ -679,12 +694,25 @@ pp_format_verbatim (pretty_printer *pp, text_info *text) pp_wrapping_mode (pp) = oldmode; } -/* Flush the content of BUFFER onto the attached stream. */ +/* Flush the content of BUFFER onto the attached stream. This + function does nothing unless pp->output_buffer->flush_p. */ void pp_flush (pretty_printer *pp) { + pp_clear_state (pp); + if (!pp->buffer->flush_p) + return; pp_write_text_to_stream (pp); + fflush (pp_buffer (pp)->stream); +} + +/* Flush the content of BUFFER onto the attached stream independently + of the value of pp->output_buffer->flush_p. */ +void +pp_really_flush (pretty_printer *pp) +{ pp_clear_state (pp); + pp_write_text_to_stream (pp); fflush (pp_buffer (pp)->stream); } @@ -812,8 +840,7 @@ pp_append_text (pretty_printer *pp, const char *start, const char *end) const char * pp_formatted_text (pretty_printer *pp) { - obstack_1grow (pp_buffer (pp)->obstack, '\0'); - return pp_formatted_text_data (pp); + return output_buffer_formatted_text (pp_buffer (pp)); } /* Return a pointer to the last character emitted in PRETTY-PRINTER's @@ -821,12 +848,7 @@ pp_formatted_text (pretty_printer *pp) const char * pp_last_position_in_text (const pretty_printer *pp) { - const char *p = NULL; - struct obstack *text = pp_buffer (pp)->obstack; - - if (obstack_base (text) != obstack_next_free (text)) - p = ((const char *) obstack_next_free (text)) - 1; - return p; + return output_buffer_last_position_in_text (pp_buffer (pp)); } /* Return the amount of characters PRETTY-PRINTER can accept to @@ -849,7 +871,6 @@ pp_printf (pretty_printer *pp, const char *msg, ...) text.err_no = errno; text.args_ptr = ≈ text.format_spec = msg; - text.locus = NULL; pp_format (pp, &text); pp_output_formatted_text (pp); va_end (ap); @@ -867,7 +888,6 @@ pp_verbatim (pretty_printer *pp, const char *msg, ...) text.err_no = errno; text.args_ptr = ≈ text.format_spec = msg; - text.locus = NULL; pp_format_verbatim (pp, &text); va_end (ap); } @@ -903,7 +923,8 @@ pp_character (pretty_printer *pp, int c) void pp_string (pretty_printer *pp, const char *str) { - pp_maybe_wrap_text (pp, str, str + (str ? strlen (str) : 0)); + gcc_checking_assert (str); + pp_maybe_wrap_text (pp, str, str + strlen (str)); } /* Maybe print out a whitespace if needed. */