From 72538294fb1eb2e4dcd5d818c78bcdf78b0de491 Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Mon, 19 Mar 2012 06:36:09 -0400 Subject: gcc: Clean-up of non-C++0x compliant code, first steps This patch cleans up a number of minor issues aiming to get closer to compliance with the C++0x standard as interpreted by gcc and clang (compile with std=c++0x and -pedantic-errors). In particular, the patch cleans up enums where the last item was succeded by a comma, namespaces closed by a curcly brace followed by a semi-colon, and the use of the GNU-extension typeof (replaced by templated functions). It does not address variable-length arrays, zero-size arrays, anonymous structs, range expressions in switch statements, and the use of long long. The generated CPU code also has a large number of issues that remain to be fixed, mainly related to overflows in implicit constant conversion (due to shifts). --- src/sim/byteswap.hh | 8 ++++---- src/sim/eventq.hh | 2 +- src/sim/serialize.hh | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src/sim') diff --git a/src/sim/byteswap.hh b/src/sim/byteswap.hh index 3a0f7ce8a..db630bd22 100644 --- a/src/sim/byteswap.hh +++ b/src/sim/byteswap.hh @@ -42,7 +42,7 @@ #include "base/types.hh" // This lets us figure out what the byte order of the host system is -#if defined(linux) +#if defined(__linux__) #include // If this is a linux system, lets used the optimized definitions if they exist. // If one doesn't exist, we pretty much get what is listed below, so it all @@ -65,7 +65,7 @@ enum ByteOrder {BigEndianByteOrder, LittleEndianByteOrder}; inline uint64_t swap_byte64(uint64_t x) { -#if defined(linux) +#if defined(__linux__) return bswap_64(x); #elif defined(__APPLE__) return OSSwapInt64(x); @@ -84,7 +84,7 @@ swap_byte64(uint64_t x) inline uint32_t swap_byte32(uint32_t x) { -#if defined(linux) +#if defined(__linux__) return bswap_32(x); #elif defined(__APPLE__) return OSSwapInt32(x); @@ -98,7 +98,7 @@ swap_byte32(uint32_t x) inline uint16_t swap_byte16(uint16_t x) { -#if defined(linux) +#if defined(__linux__) return bswap_16(x); #elif defined(__APPLE__) return OSSwapInt16(x); diff --git a/src/sim/eventq.hh b/src/sim/eventq.hh index 6dc25e760..c859823c8 100644 --- a/src/sim/eventq.hh +++ b/src/sim/eventq.hh @@ -66,7 +66,7 @@ class Event : public Serializable, public FastAlloc friend class EventQueue; protected: - typedef short FlagsType; + typedef unsigned short FlagsType; typedef ::Flags Flags; static const FlagsType PublicRead = 0x003f; // public readable flags diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh index 12b787a5e..bc64e74f8 100644 --- a/src/sim/serialize.hh +++ b/src/sim/serialize.hh @@ -89,6 +89,17 @@ void objParamIn(Checkpoint *cp, const std::string §ion, const std::string &name, SimObject * ¶m); +template +void fromInt(T &t, int i) +{ + t = (T)i; +} + +template +void fromSimObject(T &t, SimObject *s) +{ + t = dynamic_cast(s); +} // // These macros are streamlined to use in serialize/unserialize @@ -106,7 +117,7 @@ objParamIn(Checkpoint *cp, const std::string §ion, do { \ int tmp; \ paramIn(cp, section, #scalar, tmp); \ - scalar = (typeof(scalar))tmp; \ + fromInt(scalar, tmp); \ } while (0) #define SERIALIZE_ARRAY(member, size) \ @@ -121,7 +132,7 @@ objParamIn(Checkpoint *cp, const std::string §ion, do { \ SimObject *sptr; \ objParamIn(cp, section, #objptr, sptr); \ - objptr = dynamic_cast(sptr); \ + fromSimObject(objptr, sptr); \ } while (0) /* -- cgit v1.2.3