Commit 28d1bf44 by François Dumont

debug.cc (format_word): Delete.

2016-11-10  François Dumont  <fdumont@gcc.gnu.org>

	* src/c++11/debug.cc (format_word): Delete.
	(print_literal): New. Replace call to print_word for literals.

From-SVN: r242055
parent 456f0dfa
2016-11-10 François Dumont <fdumont@gcc.gnu.org>
* src/c++11/debug.cc (format_word): Delete.
(print_literal): New. Replace call to print_word for literals.
2016-11-09 Tim Shen <timshen@google.com> 2016-11-09 Tim Shen <timshen@google.com>
* libstdc++-v3/include/bits/regex.h (regex_iterator::regex_iterator()): * libstdc++-v3/include/bits/regex.h (regex_iterator::regex_iterator()):
......
...@@ -540,11 +540,6 @@ namespace ...@@ -540,11 +540,6 @@ namespace
using _Error_formatter = __gnu_debug::_Error_formatter; using _Error_formatter = __gnu_debug::_Error_formatter;
using _Parameter = __gnu_debug::_Error_formatter::_Parameter; using _Parameter = __gnu_debug::_Error_formatter::_Parameter;
template<typename _Tp>
int
format_word(char* buf, int n, const char* fmt, _Tp s)
{ return std::min(__builtin_snprintf(buf, n, fmt, s), n - 1); }
void void
get_max_length(std::size_t& max_length) get_max_length(std::size_t& max_length)
{ {
...@@ -571,6 +566,11 @@ namespace ...@@ -571,6 +566,11 @@ namespace
bool _M_wordwrap; bool _M_wordwrap;
}; };
template<size_t Length>
void
print_literal(PrintContext& ctx, const char(&word)[Length])
{ print_word(ctx, word, Length - 1); }
void void
print_word(PrintContext& ctx, const char* word, print_word(PrintContext& ctx, const char* word,
std::ptrdiff_t count = -1) std::ptrdiff_t count = -1)
...@@ -621,27 +621,28 @@ namespace ...@@ -621,27 +621,28 @@ namespace
} }
else else
{ {
print_word(ctx, "\n", 1); print_literal(ctx, "\n");
print_word(ctx, word, count); print_word(ctx, word, count);
} }
} }
void template<size_t Length>
print_type(PrintContext& ctx, void
const type_info* info, print_type(PrintContext& ctx,
const char* unknown_name) const type_info* info,
{ const char(&unknown_name)[Length])
if (!info) {
print_word(ctx, unknown_name); if (!info)
else print_literal(ctx, unknown_name);
{ else
int status; {
char* demangled_name = int status;
__cxxabiv1::__cxa_demangle(info->name(), NULL, NULL, &status); char* demangled_name =
print_word(ctx, status == 0 ? demangled_name : info->name()); __cxxabiv1::__cxa_demangle(info->name(), NULL, NULL, &status);
free(demangled_name); print_word(ctx, status == 0 ? demangled_name : info->name());
} free(demangled_name);
} }
}
bool bool
print_field(PrintContext& ctx, print_field(PrintContext& ctx,
...@@ -778,20 +779,18 @@ namespace ...@@ -778,20 +779,18 @@ namespace
{ {
if (type._M_name) if (type._M_name)
{ {
const int bufsize = 64; print_literal(ctx, "\"");
char buf[bufsize]; print_word(ctx, type._M_name);
int written print_literal(ctx, "\"");
= format_word(buf, bufsize, "\"%s\"", type._M_name);
print_word(ctx, buf, written);
} }
print_word(ctx, " {\n"); print_literal(ctx, " {\n");
if (type._M_type) if (type._M_type)
{ {
print_word(ctx, " type = "); print_literal(ctx, " type = ");
print_type(ctx, type._M_type, "<unknown type>"); print_type(ctx, type._M_type, "<unknown type>");
print_word(ctx, ";\n"); print_literal(ctx, ";\n");
} }
} }
...@@ -803,9 +802,9 @@ namespace ...@@ -803,9 +802,9 @@ namespace
if (inst._M_name) if (inst._M_name)
{ {
int written print_literal(ctx, "\"");
= format_word(buf, bufsize, "\"%s\" ", inst._M_name); print_word(ctx, inst._M_name);
print_word(ctx, buf, written); print_literal(ctx, "\" ");
} }
int written int written
...@@ -814,7 +813,7 @@ namespace ...@@ -814,7 +813,7 @@ namespace
if (inst._M_type) if (inst._M_type)
{ {
print_word(ctx, " type = "); print_literal(ctx, " type = ");
print_type(ctx, inst._M_type, "<unknown type>"); print_type(ctx, inst._M_type, "<unknown type>");
} }
} }
...@@ -832,36 +831,36 @@ namespace ...@@ -832,36 +831,36 @@ namespace
{ {
const auto& ite = variant._M_iterator; const auto& ite = variant._M_iterator;
print_word(ctx, "iterator "); print_literal(ctx, "iterator ");
print_description(ctx, ite); print_description(ctx, ite);
if (ite._M_type) if (ite._M_type)
{ {
if (ite._M_constness != _Error_formatter::__unknown_constness) if (ite._M_constness != _Error_formatter::__unknown_constness)
{ {
print_word(ctx, " ("); print_literal(ctx, " (");
print_field(ctx, param, "constness"); print_field(ctx, param, "constness");
print_word(ctx, " iterator)"); print_literal(ctx, " iterator)");
} }
print_word(ctx, ";\n"); print_literal(ctx, ";\n");
} }
if (ite._M_state != _Error_formatter::__unknown_state) if (ite._M_state != _Error_formatter::__unknown_state)
{ {
print_word(ctx, " state = "); print_literal(ctx, " state = ");
print_field(ctx, param, "state"); print_field(ctx, param, "state");
print_word(ctx, ";\n"); print_literal(ctx, ";\n");
} }
if (ite._M_sequence) if (ite._M_sequence)
{ {
print_word(ctx, " references sequence "); print_literal(ctx, " references sequence ");
if (ite._M_seq_type) if (ite._M_seq_type)
{ {
print_word(ctx, "with type '"); print_literal(ctx, "with type '");
print_field(ctx, param, "seq_type"); print_field(ctx, param, "seq_type");
print_word(ctx, "' "); print_literal(ctx, "' ");
} }
int written int written
...@@ -869,34 +868,34 @@ namespace ...@@ -869,34 +868,34 @@ namespace
print_word(ctx, buf, written); print_word(ctx, buf, written);
} }
print_word(ctx, "}\n", 2); print_literal(ctx, "}\n");
} }
break; break;
case _Parameter::__sequence: case _Parameter::__sequence:
print_word(ctx, "sequence "); print_literal(ctx, "sequence ");
print_description(ctx, variant._M_sequence); print_description(ctx, variant._M_sequence);
if (variant._M_sequence._M_type) if (variant._M_sequence._M_type)
print_word(ctx, ";\n", 2); print_literal(ctx, ";\n");
print_word(ctx, "}\n", 2); print_literal(ctx, "}\n");
break; break;
case _Parameter::__instance: case _Parameter::__instance:
print_word(ctx, "instance "); print_literal(ctx, "instance ");
print_description(ctx, variant._M_instance); print_description(ctx, variant._M_instance);
if (variant._M_instance._M_type) if (variant._M_instance._M_type)
print_word(ctx, ";\n", 2); print_literal(ctx, ";\n");
print_word(ctx, "}\n", 2); print_literal(ctx, "}\n");
break; break;
case _Parameter::__iterator_value_type: case _Parameter::__iterator_value_type:
print_word(ctx, "iterator::value_type "); print_literal(ctx, "iterator::value_type ");
print_description(ctx, variant._M_iterator_value_type); print_description(ctx, variant._M_iterator_value_type);
print_word(ctx, "}\n", 2); print_literal(ctx, "}\n");
break; break;
default: default:
...@@ -1011,38 +1010,36 @@ namespace __gnu_debug ...@@ -1011,38 +1010,36 @@ namespace __gnu_debug
void void
_Error_formatter::_M_error() const _Error_formatter::_M_error() const
{ {
const int bufsize = 128;
char buf[bufsize];
// Emit file & line number information // Emit file & line number information
bool go_to_next_line = false; bool go_to_next_line = false;
PrintContext ctx; PrintContext ctx;
if (_M_file) if (_M_file)
{ {
int written = format_word(buf, bufsize, "%s:", _M_file); print_word(ctx, _M_file);
print_word(ctx, buf, written); print_literal(ctx, ":");
go_to_next_line = true; go_to_next_line = true;
} }
if (_M_line > 0) if (_M_line > 0)
{ {
char buf[64];
int written = __builtin_sprintf(buf, "%u:", _M_line); int written = __builtin_sprintf(buf, "%u:", _M_line);
print_word(ctx, buf, written); print_word(ctx, buf, written);
go_to_next_line = true; go_to_next_line = true;
} }
if (go_to_next_line) if (go_to_next_line)
print_word(ctx, "\n", 1); print_literal(ctx, "\n");
if (ctx._M_max_length) if (ctx._M_max_length)
ctx._M_wordwrap = true; ctx._M_wordwrap = true;
print_word(ctx, "Error: "); print_literal(ctx, "Error: ");
// Print the error message // Print the error message
assert(_M_text); assert(_M_text);
print_string(ctx, _M_text, _M_parameters, _M_num_parameters); print_string(ctx, _M_text, _M_parameters, _M_num_parameters);
print_word(ctx, ".\n", 2); print_literal(ctx, ".\n");
// Emit descriptions of the objects involved in the operation // Emit descriptions of the objects involved in the operation
ctx._M_first_line = true; ctx._M_first_line = true;
...@@ -1058,7 +1055,7 @@ namespace __gnu_debug ...@@ -1058,7 +1055,7 @@ namespace __gnu_debug
case _Parameter::__iterator_value_type: case _Parameter::__iterator_value_type:
if (!has_header) if (!has_header)
{ {
print_word(ctx, "\nObjects involved in the operation:\n"); print_literal(ctx, "\nObjects involved in the operation:\n");
has_header = true; has_header = true;
} }
print_description(ctx, _M_parameters[i]); print_description(ctx, _M_parameters[i]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment