From 66d06a1759038ffa2c0e189e00d3f181db87efa5 Mon Sep 17 00:00:00 2001 From: Terraneo Federico <fede.tft@miosix.org> Date: Mon, 29 Jun 2015 17:05:27 +0200 Subject: [PATCH] Added preliminary C++11 support --- miosix/_doc/textdoc/Changelog.txt | 3 +++ miosix/config/Makefile.inc | 2 +- miosix/e20/e20.cpp | 2 ++ miosix/e20/e20.h | 11 +++++++++-- miosix/util/unicode.h | 4 +++- miosix/util/version.cpp | 17 ++++++++++++++--- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/miosix/_doc/textdoc/Changelog.txt b/miosix/_doc/textdoc/Changelog.txt index d8f06f5d..2b71e3f9 100644 --- a/miosix/_doc/textdoc/Changelog.txt +++ b/miosix/_doc/textdoc/Changelog.txt @@ -1,5 +1,8 @@ Changelog for Miosix np embedded OS + +v2.01 +- Added preliminary C++11 support v2.0 - Added support for new board, oledboard2 - Added support for new board, tempsensor diff --git a/miosix/config/Makefile.inc b/miosix/config/Makefile.inc index dfc9f815..06c4a8ad 100644 --- a/miosix/config/Makefile.inc +++ b/miosix/config/Makefile.inc @@ -365,7 +365,7 @@ endif ## CFLAGS_BASE := -D_MIOSIX_BOARDNAME=\"$(OPT_BOARD)\" \ -Wno-unused-but-set-variable -CXXFLAGS_BASE := -D_MIOSIX_BOARDNAME=\"$(OPT_BOARD)\" \ +CXXFLAGS_BASE := -std=gnu++11 -D_MIOSIX_BOARDNAME=\"$(OPT_BOARD)\" \ -Wno-unused-but-set-variable ## diff --git a/miosix/e20/e20.cpp b/miosix/e20/e20.cpp index 973a34e3..558054cf 100644 --- a/miosix/e20/e20.cpp +++ b/miosix/e20/e20.cpp @@ -28,7 +28,9 @@ #include "e20.h" using namespace std; +#if __cplusplus <= 199711L using namespace std::tr1; +#endif //!c++11 namespace miosix { diff --git a/miosix/e20/e20.h b/miosix/e20/e20.h index 7012b306..4f53a416 100644 --- a/miosix/e20/e20.h +++ b/miosix/e20/e20.h @@ -31,7 +31,14 @@ #define E20_H #include <list> +#if __cplusplus > 199711L +#include <functional> +//TODO: remove this once we make the full transition to C++11 +#define FUN_NAMESPACE std +#else //c++11 #include <tr1/functional> +#define FUN_NAMESPACE std::tr1 +#endif //c++11 #include <miosix.h> #include "callback.h" @@ -64,7 +71,7 @@ public: * run() or runOne(). Bind can be used to bind parameters to the function. * \throws std::bad_alloc if there is not enough heap memory */ - void post(std::tr1::function<void ()> event); + void post(FUN_NAMESPACE::function<void ()> event); /** * This function blocks waiting for events being posted, and when available @@ -104,7 +111,7 @@ private: EventQueue(const EventQueue&); EventQueue& operator= (const EventQueue&); - std::list<std::tr1::function<void ()> > events; ///< Event queue + std::list<FUN_NAMESPACE::function<void ()> > events; ///< Event queue mutable FastMutex m; ///< Mutex for synchronisation ConditionVariable cv; ///< Condition variable for synchronisation }; diff --git a/miosix/util/unicode.h b/miosix/util/unicode.h index 00f97bfb..da9a81b0 100644 --- a/miosix/util/unicode.h +++ b/miosix/util/unicode.h @@ -31,9 +31,11 @@ #ifndef UNICODE_H #define UNICODE_H -//TODO: these should be provided by the compiler, byt they're not +#if __cplusplus <= 199711L +//These are builtin types in C++11, add them if compiling in C++03 mode typedef uint16_t char16_t; typedef uint32_t char32_t; +#endif // !c++11 namespace miosix { diff --git a/miosix/util/version.cpp b/miosix/util/version.cpp index e6155bdc..82571357 100644 --- a/miosix/util/version.cpp +++ b/miosix/util/version.cpp @@ -28,6 +28,9 @@ #include "config/miosix_settings.h" #include "board_settings.h" +// These two #if are here because version checking for config files in +// out-of-git-tree projects has to be done somewhere. + #if MIOSIX_SETTINGS_VERSION != 100 #error You need to update miosix_settings.h to match the version in the kernel. #endif @@ -38,17 +41,25 @@ namespace miosix { -#ifdef __GNUC__ #define tts(x) #x #define ts(x) tts(x) -#define CV ", gcc "ts(__GNUC__)"."ts(__GNUC_MINOR__)"."ts(__GNUC_PATCHLEVEL__) + +#ifdef __clang__ //clang also defines GNUC, so it has to go first +#define CV ", clang " \ + ts(__clang_major__) "." ts(__clang_minor__) "." ts(__clang_patchlevel__) \ + "-mp" ts(_MIOSIX_CLANG_PATCH_VERSION) +#define AU __attribute__((used)) +#elif defined(__GNUC__) +#define CV ", gcc " \ + ts(__GNUC__) "." ts(__GNUC_MINOR__) "." ts(__GNUC_PATCHLEVEL__) \ + "-mp" ts(_MIOSIX_GCC_PATCH_VERSION) #define AU __attribute__((used)) #else #define CV #define AU #endif -const char AU ver[]="Miosix v2.0 (" _MIOSIX_BOARDNAME ", " __DATE__ " " __TIME__ CV ")"; +const char AU ver[]="Miosix v2.01 (" _MIOSIX_BOARDNAME ", " __DATE__ " " __TIME__ CV ")"; const char *getMiosixVersion() { -- GitLab