Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/45086 )

Change subject: base: Add macros to mark things as deprecated.
......................................................................

base: Add macros to mark things as deprecated.

GEM5_DEPRECATED(message) expands to the [[gnu::deprecated(message)]]
attribute on gnu compatible compilers and marks an entity (function,
variable, etc) as deprecated. The msg parameter should be used to tell
the user what they should do to move away from the deprecated entity.

GEM5_DEPRECATED_MACRO(name, definition, message) is used inside an
expression-like macro with definition "definition" to mark that macro as
deprecated with message "message". For instance, if there were macros
like this:

 #define SUM(a, b) ((a) + (b))
 #define ONE 1

We could mark that as deprecated like so:

 #define SUM(a, b) GEM5_DEPRECATED_MACRO(SUM, (a) + (b), \
     "The SUM macro is deprecated, use the + operator instead.")
 #define ONE GEM5_DEPRECATED_MACRO(ONE, 1, "Use the literal 1.")

Note that this macro should not be used for macros which, for instance,
declare variables, since it assumes the body of the macro expands into
an expression and not a statement or statements.

Change-Id: I58f5e834cfeeb23e37a6548433dfe7e4f695a5ec
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/45086
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/base/compiler.hh
1 file changed, 15 insertions(+), 0 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/compiler.hh b/src/base/compiler.hh
index c003bfa..97dec94 100644
--- a/src/base/compiler.hh
+++ b/src/base/compiler.hh
@@ -113,6 +113,21 @@
 #  define M5_LIKELY(cond) __builtin_expect(!!(cond), 1)
 #  define M5_UNLIKELY(cond) __builtin_expect(!!(cond), 0)

+// Mark a c++ declaration as deprecated, with a message explaining what to do
+// to update to a non-deprecated alternative.
+#  define GEM5_DEPRECATED(message) [[gnu::deprecated(message)]]
+// Mark an expression-like macro as deprecated by wrapping it in some code
+// which declares and uses a deprecated variable with the same name as the
+// macro. The wrapping macro evaluates to the same thing as the original macro. +// The definition must be an c++ expression and not a statement because of how
+// the original macro is wrapped.
+#  define GEM5_DEPRECATED_MACRO(name, definition, message) \
+ ([](){GEM5_DEPRECATED(message) int name{}; return name;}, (definition)) +// This version is for macros which are statement-like, which frequently use +// "do {} while (0)" to make their syntax look more like normal c++ statements.
+#  define GEM5_DEPRECATED_MACRO_STMT(name, definition, message) \
+     do {{definition;} GEM5_DEPRECATED_MACRO(name, {}, message);} while (0)
+
 // Evaluate an expanded parameter pack in order. Multiple arguments can be
 // passed in which be evaluated in order relative to each other as a group.
// The argument(s) must include a parameter pack to expand. This works because

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/45086
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: I58f5e834cfeeb23e37a6548433dfe7e4f695a5ec
Gerrit-Change-Number: 45086
Gerrit-PatchSet: 7
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to