Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/39535 )
Change subject: base: Style fixes in cprintf related files.
......................................................................
base: Style fixes in cprintf related files.
Fix braces, capitalization, missing line breaks, and remove mostly
useless "using namespace std"s.
Change-Id: I1210dd3b918e7cba8e576cbbdf47aa986d9278e6
---
M src/base/cprintf.cc
M src/base/cprintf.hh
M src/base/cprintf_formats.hh
3 files changed, 252 insertions(+), 192 deletions(-)
diff --git a/src/base/cprintf.cc b/src/base/cprintf.cc
index e7336a8..572fc40 100644
--- a/src/base/cprintf.cc
+++ b/src/base/cprintf.cc
@@ -35,26 +35,25 @@
#include "base/compiler.hh"
-using namespace std;
-
-namespace cp {
+namespace cp
+{
Print::Print(std::ostream &stream, const std::string &format)
: stream(stream), format(format.c_str()), ptr(format.c_str()),
cont(false)
{
- saved_flags = stream.flags();
- saved_fill = stream.fill();
- saved_precision = stream.precision();
- saved_width = stream.width();
+ savedFlags = stream.flags();
+ savedFill = stream.fill();
+ savedPrecision = stream.precision();
+ savedWidth = stream.width();
}
Print::Print(std::ostream &stream, const char *format)
: stream(stream), format(format), ptr(format), cont(false)
{
- saved_flags = stream.flags();
- saved_fill = stream.fill();
- saved_precision = stream.precision();
- saved_width = stream.width();
+ savedFlags = stream.flags();
+ savedFill = stream.fill();
+ savedPrecision = stream.precision();
+ savedWidth = stream.width();
}
Print::~Print()
@@ -72,7 +71,7 @@
switch (*ptr) {
case '%':
if (ptr[1] != '%') {
- process_flag();
+ processFlag();
return;
}
stream.put('%');
@@ -99,7 +98,7 @@
}
void
-Print::process_flag()
+Print::processFlag()
{
bool done = false;
bool end_number = false;
@@ -114,17 +113,18 @@
if (*ptr >= '0' && *ptr <= '9') {
if (end_number)
continue;
- } else if (number > 0)
+ } else if (number > 0) {
end_number = true;
+ }
switch (*ptr) {
case 's':
- fmt.format = Format::string;
+ fmt.format = Format::String;
done = true;
break;
case 'c':
- fmt.format = Format::character;
+ fmt.format = Format::Character;
done = true;
break;
@@ -132,8 +132,8 @@
continue;
case 'p':
- fmt.format = Format::integer;
- fmt.base = Format::hex;
+ fmt.format = Format::Integer;
+ fmt.base = Format::Hex;
fmt.alternate_form = true;
done = true;
break;
@@ -142,21 +142,21 @@
fmt.uppercase = true;
M5_FALLTHROUGH;
case 'x':
- fmt.base = Format::hex;
- fmt.format = Format::integer;
+ fmt.base = Format::Hex;
+ fmt.format = Format::Integer;
done = true;
break;
case 'o':
- fmt.base = Format::oct;
- fmt.format = Format::integer;
+ fmt.base = Format::Oct;
+ fmt.format = Format::Integer;
done = true;
break;
case 'd':
case 'i':
case 'u':
- fmt.format = Format::integer;
+ fmt.format = Format::Integer;
done = true;
break;
@@ -164,8 +164,8 @@
fmt.uppercase = true;
M5_FALLTHROUGH;
case 'g':
- fmt.format = Format::floating;
- fmt.float_format = Format::best;
+ fmt.format = Format::Floating;
+ fmt.floatFormat = Format::Best;
done = true;
break;
@@ -173,14 +173,14 @@
fmt.uppercase = true;
M5_FALLTHROUGH;
case 'e':
- fmt.format = Format::floating;
- fmt.float_format = Format::scientific;
+ fmt.format = Format::Floating;
+ fmt.floatFormat = Format::Scientific;
done = true;
break;
case 'f':
- fmt.format = Format::floating;
- fmt.float_format = Format::fixed;
+ fmt.format = Format::Floating;
+ fmt.floatFormat = Format::Fixed;
done = true;
break;
@@ -190,19 +190,19 @@
break;
case '#':
- fmt.alternate_form = true;
+ fmt.alternateForm = true;
break;
case '-':
- fmt.flush_left = true;
+ fmt.flushLeft = true;
break;
case '+':
- fmt.print_sign = true;
+ fmt.printSign = true;
break;
case ' ':
- fmt.blank_space = true;
+ fmt.blankSpace = true;
break;
case '.':
@@ -215,7 +215,7 @@
case '0':
if (number == 0) {
- fmt.fill_zero = true;
+ fmt.fillZero = true;
break;
}
M5_FALLTHROUGH;
@@ -233,13 +233,13 @@
case '*':
if (have_precision)
- fmt.get_precision = true;
+ fmt.getPrecision = true;
else
- fmt.get_width = true;
+ fmt.getWidth = true;
break;
case '%':
- assert(false && "we shouldn't get here");
+ panic("we shouldn't get here");
break;
default:
@@ -258,12 +258,12 @@
}
if (done) {
- if ((fmt.format == Format::integer) && have_precision) {
+ if ((fmt.format == Format::Integer) && have_precision) {
// specified a . but not a float, set width
fmt.width = fmt.precision;
// precision requries digits for width, must fill with 0
fmt.fill_zero = true;
- } else if ((fmt.format == Format::floating) && !have_precision
&&
+ } else if ((fmt.format == Format::Floating) && !have_precision
&&
fmt.fill_zero) {
// ambiguous case, matching printf
fmt.precision = fmt.width;
@@ -275,7 +275,7 @@
}
void
-Print::end_args()
+Print::endArgs()
{
size_t len;
@@ -307,10 +307,10 @@
}
}
- stream.flags(saved_flags);
- stream.fill(saved_fill);
- stream.precision(saved_precision);
- stream.width(saved_width);
+ stream.flags(savedFlags);
+ stream.fill(savedFill);
+ stream.precision(savedPrecision);
+ stream.width(savedWidth);
}
} // namespace cp
diff --git a/src/base/cprintf.hh b/src/base/cprintf.hh
index 06aebd2..51531f4 100644
--- a/src/base/cprintf.hh
+++ b/src/base/cprintf.hh
@@ -37,7 +37,8 @@
#include "base/cprintf_formats.hh"
-namespace cp {
+namespace cp
+{
struct Print
{
@@ -48,13 +49,13 @@
bool cont;
std::ios::fmtflags saved_flags;
- char saved_fill;
- int saved_precision;
- int saved_width;
+ char savedFill;
+ int savedPrecision;
+ int savedWidth;
Format fmt;
void process();
- void process_flag();
+ void processFlag();
public:
Print(std::ostream &stream, const std::string &format);
@@ -62,54 +63,54 @@
~Print();
int
- get_number(int data)
+ getNumber(int data)
{
return data;
}
template <typename T>
int
- get_number(const T& data)
+ getNumber(const T& data)
{
return 0;
}
template <typename T>
void
- add_arg(const T &data)
+ addArg(const T &data)
{
if (!cont)
process();
- if (fmt.get_width) {
- fmt.get_width = false;
+ if (fmt.getWidth) {
+ fmt.getWidth = false;
cont = true;
- fmt.width = get_number(data);
+ fmt.width = getNumber(data);
return;
}
- if (fmt.get_precision) {
- fmt.get_precision = false;
+ if (fmt.getPrecision) {
+ fmt.getPrecision = false;
cont = true;
- fmt.precision = get_number(data);
+ fmt.precision = getNumber(data);
return;
}
switch (fmt.format) {
- case Format::character:
- format_char(stream, data, fmt);
+ case Format::Character:
+ formatChar(stream, data, fmt);
break;
- case Format::integer:
- format_integer(stream, data, fmt);
+ case Format::Integer:
+ formatInteger(stream, data, fmt);
break;
- case Format::floating:
- format_float(stream, data, fmt);
+ case Format::Floating:
+ formatFloat(stream, data, fmt);
break;
- case Format::string:
- format_string(stream, data, fmt);
+ case Format::String:
+ formatString(stream, data, fmt);
break;
default:
@@ -118,7 +119,7 @@
}
}
- void end_args();
+ void endArgs();
};
} // namespace cp
@@ -126,14 +127,14 @@
inline void
ccprintf(cp::Print &print)
{
- print.end_args();
+ print.endArgs();
}
template<typename T, typename ...Args> void
ccprintf(cp::Print &print, const T &value, const Args &...args)
{
- print.add_arg(value);
+ print.addArg(value);
ccprintf(print, args...);
}
diff --git a/src/base/cprintf_formats.hh b/src/base/cprintf_formats.hh
index b12b2d7..a803013 100644
--- a/src/base/cprintf_formats.hh
+++ b/src/base/cprintf_formats.hh
@@ -33,104 +33,119 @@
#include <ostream>
#include <sstream>
-namespace cp {
+namespace cp
+{
struct Format
{
- bool alternate_form;
- bool flush_left;
- bool print_sign;
- bool blank_space;
- bool fill_zero;
+ bool alternateForm;
+ bool flushLeft;
+ bool printSign;
+ bool blankSpace;
+ bool fillZero;
bool uppercase;
- enum { dec, hex, oct } base;
- enum { none, string, integer, character, floating } format;
- enum { best, fixed, scientific } float_format;
+ enum
+ {
+ Dec,
+ Hex,
+ Oct
+ } base;
+ enum
+ {
+ None,
+ String,
+ Integer,
+ Character,
+ Floating
+ } format;
+ enum
+ {
+ Best,
+ Fixed,
+ Scientific
+ } floatFormat;
int precision;
int width;
- bool get_precision;
- bool get_width;
+ bool getPrecision;
+ bool getWidth;
Format() { clear(); }
- void clear()
+ void
+ clear()
{
- alternate_form = false;
- flush_left = false;
- print_sign = false;
- blank_space = false;
- fill_zero = false;
+ alternateForm = false;
+ flushLeft = false;
+ printSign = false;
+ blankSpace = false;
+ fillZero = false;
uppercase = false;
- base = dec;
- format = none;
- float_format = best;
+ base = Dec;
+ format = None;
+ floatFormat = Best;
precision = -1;
width = 0;
- get_precision = false;
- get_width = false;
+ getPrecision = false;
+ getWidth = false;
}
};
template <typename T>
-inline void
-_format_char(std::ostream &out, const T &data, Format &fmt)
+static inline void
+_formatChar(std::ostream &out, const T &data, Format &fmt)
{
- using namespace std;
-
out << data;
}
template <typename T>
-inline void
-_format_integer(std::ostream &out, const T &data, Format &fmt)
+static inline void
+_formatInteger(std::ostream &out, const T &data, Format &fmt)
{
- using namespace std;
-
- ios::fmtflags flags(out.flags());
+ std::ios::fmtflags flags(out.flags());
switch (fmt.base) {
- case Format::hex:
+ case Format::Hex:
out.setf(std::ios::hex, std::ios::basefield);
break;
- case Format::oct:
+ case Format::Oct:
out.setf(std::ios::oct, std::ios::basefield);
break;
- case Format::dec:
+ case Format::Dec:
out.setf(std::ios::dec, std::ios::basefield);
break;
}
- if (fmt.alternate_form) {
- if (!fmt.fill_zero)
+ if (fmt.alternateForm) {
+ if (!fmt.fillZero) {
out.setf(std::ios::showbase);
- else {
+ } else {
switch (fmt.base) {
- case Format::hex:
+ case Format::Hex:
out << "0x";
fmt.width -= 2;
break;
- case Format::oct:
+ case Format::Oct:
out << "0";
fmt.width -= 1;
break;
- case Format::dec:
+ case Format::Dec:
break;
}
}
}
- if (fmt.fill_zero)
+ if (fmt.fillZero)
out.fill('0');
if (fmt.width > 0)
out.width(fmt.width);
- if (fmt.flush_left && !fmt.fill_zero)
+ if (fmt.flushLeft && !fmt.fillZero)
out.setf(std::ios::left);
- if (fmt.print_sign)
+ if (fmt.printSign)
out.setf(std::ios::showpos);
if (fmt.uppercase)
@@ -142,18 +157,16 @@
}
template <typename T>
-inline void
-_format_float(std::ostream &out, const T &data, Format &fmt)
+static inline void
+_formatFloat(std::ostream &out, const T &data, Format &fmt)
{
- using namespace std;
+ std::ios::fmtflags flags(out.flags());
- ios::fmtflags flags(out.flags());
-
- if (fmt.fill_zero)
+ if (fmt.fillZero)
out.fill('0');
- switch (fmt.float_format) {
- case Format::scientific:
+ switch (fmt.floatFormat) {
+ case Format::Scientific:
if (fmt.precision != -1) {
if (fmt.width > 0)
out.width(fmt.width);
@@ -164,24 +177,26 @@
out.setf(std::ios::scientific);
out.precision(fmt.precision);
- } else
+ } else {
if (fmt.width > 0)
out.width(fmt.width);
+ }
if (fmt.uppercase)
out.setf(std::ios::uppercase);
break;
- case Format::fixed:
+ case Format::Fixed:
if (fmt.precision != -1) {
if (fmt.width > 0)
out.width(fmt.width);
out.setf(std::ios::fixed);
out.precision(fmt.precision);
- } else
+ } else {
if (fmt.width > 0)
out.width(fmt.width);
+ }
break;
@@ -201,8 +216,8 @@
}
template <typename T>
-inline void
-_format_string(std::ostream &out, const T &data, Format &fmt)
+static inline void
+_formatString(std::ostream &out, const T &data, Format &fmt)
{
if (fmt.width > 0) {
std::stringstream foo;
@@ -214,7 +229,7 @@
std::memset(spaces, ' ', fmt.width - flen);
spaces[fmt.width - flen] = 0;
- if (fmt.flush_left)
+ if (fmt.flushLeft)
out << foo.str() << spaces;
else
out << spaces << foo.str();
@@ -235,100 +250,144 @@
// character formats
//
template <typename T>
-inline void
-format_char(std::ostream &out, const T &data, Format &fmt)
-{ out << "<bad arg type for char format>"; }
+static inline void
+formatChar(std::ostream &out, const T &data, Format &fmt)
+{
+ out << "<bad arg type for char format>";
+}
-inline void
-format_char(std::ostream &out, char data, Format &fmt)
-{ _format_char(out, data, fmt); }
+static inline void
+formatChar(std::ostream &out, char data, Format &fmt)
+{
+ _formatChar(out, data, fmt);
+}
-inline void
-format_char(std::ostream &out, unsigned char data, Format &fmt)
-{ _format_char(out, data, fmt); }
+static inline void
+formatChar(std::ostream &out, unsigned char data, Format &fmt)
+{
+ _formatChar(out, data, fmt);
+}
-inline void
-format_char(std::ostream &out, signed char data, Format &fmt)
-{ _format_char(out, data, fmt); }
+static inline void
+formatChar(std::ostream &out, signed char data, Format &fmt)
+{
+ _formatChar(out, data, fmt);
+}
-inline void
-format_char(std::ostream &out, short data, Format &fmt)
-{ _format_char(out, (char)data, fmt); }
+static inline void
+formatChar(std::ostream &out, short data, Format &fmt)
+{
+ _formatChar(out, (char)data, fmt);
+}
-inline void
-format_char(std::ostream &out, unsigned short data, Format &fmt)
-{ _format_char(out, (char)data, fmt); }
+static inline void
+formatChar(std::ostream &out, unsigned short data, Format &fmt)
+{
+ _formatChar(out, (char)data, fmt);
+}
-inline void
-format_char(std::ostream &out, int data, Format &fmt)
-{ _format_char(out, (char)data, fmt); }
+static inline void
+formatChar(std::ostream &out, int data, Format &fmt)
+{
+ _formatChar(out, (char)data, fmt);
+}
-inline void
-format_char(std::ostream &out, unsigned int data, Format &fmt)
-{ _format_char(out, (char)data, fmt); }
+static inline void
+formatChar(std::ostream &out, unsigned int data, Format &fmt)
+{
+ _formatChar(out, (char)data, fmt);
+}
-inline void
-format_char(std::ostream &out, long data, Format &fmt)
-{ _format_char(out, (char)data, fmt); }
+static inline void
+formatChar(std::ostream &out, long data, Format &fmt)
+{
+ _formatChar(out, (char)data, fmt);
+}
-inline void
-format_char(std::ostream &out, unsigned long data, Format &fmt)
-{ _format_char(out, (char)data, fmt); }
+static inline void
+formatChar(std::ostream &out, unsigned long data, Format &fmt)
+{
+ _formatChar(out, (char)data, fmt);
+}
-inline void
-format_char(std::ostream &out, long long data, Format &fmt)
-{ _format_char(out, (char)data, fmt); }
+static inline void
+formatChar(std::ostream &out, long long data, Format &fmt)
+{
+ _formatChar(out, (char)data, fmt);
+}
-inline void
-format_char(std::ostream &out, unsigned long long data, Format &fmt)
-{ _format_char(out, (char)data, fmt); }
+static inline void
+formatChar(std::ostream &out, unsigned long long data, Format &fmt)
+{
+ _formatChar(out, (char)data, fmt);
+}
//
// integer formats
//
template <typename T>
-inline void
-format_integer(std::ostream &out, const T &data, Format &fmt)
-{ _format_integer(out, data, fmt); }
-inline void
-format_integer(std::ostream &out, char data, Format &fmt)
-{ _format_integer(out, (int)data, fmt); }
-inline void
-format_integer(std::ostream &out, unsigned char data, Format &fmt)
-{ _format_integer(out, (int)data, fmt); }
-inline void
-format_integer(std::ostream &out, signed char data, Format &fmt)
-{ _format_integer(out, (int)data, fmt); }
-inline void
-format_integer(std::ostream &out, const unsigned char *data, Format &fmt)
-{ _format_integer(out, (uintptr_t)data, fmt); }
-inline void
-format_integer(std::ostream &out, const signed char *data, Format &fmt)
-{ _format_integer(out, (uintptr_t)data, fmt); }
+static inline void
+formatInteger(std::ostream &out, const T &data, Format &fmt)
+{
+ _formatInteger(out, data, fmt);
+}
+static inline void
+formatInteger(std::ostream &out, char data, Format &fmt)
+{
+ _formatInteger(out, (int)data, fmt);
+}
+static inline void
+formatInteger(std::ostream &out, unsigned char data, Format &fmt)
+{
+ _formatInteger(out, (int)data, fmt);
+}
+static inline void
+formatInteger(std::ostream &out, signed char data, Format &fmt)
+{
+ _formatInteger(out, (int)data, fmt);
+}
+static inline void
+formatInteger(std::ostream &out, const unsigned char *data, Format &fmt)
+{
+ _formatInteger(out, (uintptr_t)data, fmt);
+}
+static inline void
+formatInteger(std::ostream &out, const signed char *data, Format &fmt)
+{
+ _formatInteger(out, (uintptr_t)data, fmt);
+}
//
// floating point formats
//
template <typename T>
-inline void
-format_float(std::ostream &out, const T &data, Format &fmt)
-{ out << "<bad arg type for float format>"; }
+static inline void
+formatFloat(std::ostream &out, const T &data, Format &fmt)
+{
+ out << "<bad arg type for float format>";
+}
-inline void
-format_float(std::ostream &out, float data, Format &fmt)
-{ _format_float(out, data, fmt); }
+static inline void
+formatFloat(std::ostream &out, float data, Format &fmt)
+{
+ _formatFloat(out, data, fmt);
+}
-inline void
-format_float(std::ostream &out, double data, Format &fmt)
-{ _format_float(out, data, fmt); }
+static inline void
+formatFloat(std::ostream &out, double data, Format &fmt)
+{
+ _formatFloat(out, data, fmt);
+}
//
// string formats
//
template <typename T>
-inline void
-format_string(std::ostream &out, const T &data, Format &fmt)
-{ _format_string(out, data, fmt); }
+static inline void
+formatString(std::ostream &out, const T &data, Format &fmt)
+{
+ _formatString(out, data, fmt);
+}
} // namespace cp
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/39535
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I1210dd3b918e7cba8e576cbbdf47aa986d9278e6
Gerrit-Change-Number: 39535
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s