From fcd9f1526c3c7e3099d9c7b70884ec92db4c76ed Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 27 Aug 2017 16:55:33 -0300 Subject: [PATCH] Use different output messages for deprecated methods versus functions. --HG-- branch : minor --- src/common/deprecation.cpp | 24 +++++++++++++++---- src/common/deprecation.h | 15 +++++++++--- src/common/runtime.cpp | 8 +++---- src/common/runtime.h | 4 ++-- src/modules/audio/wrap_Audio.cpp | 2 +- src/modules/audio/wrap_Source.cpp | 2 +- .../physics/box2d/wrap_PrismaticJoint.cpp | 2 +- .../physics/box2d/wrap_RevoluteJoint.cpp | 2 +- src/modules/sound/wrap_Decoder.cpp | 2 +- src/modules/sound/wrap_SoundData.cpp | 2 +- 10 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/common/deprecation.cpp b/src/common/deprecation.cpp index 3f7cbd919..2733972d9 100644 --- a/src/common/deprecation.cpp +++ b/src/common/deprecation.cpp @@ -91,9 +91,22 @@ std::string getDeprecationNotice(const DeprecationInfo &info, bool usewhere) if (usewhere) notice += info.where; - notice += "Using deprecated function " + info.name; + notice += "Using deprecated "; - if (info.type == DEPRECATED_REPLACEMENT && !info.replacement.empty()) + if (info.apiType == API_FUNCTION) + notice += "function "; + else if (info.apiType == API_METHOD) + notice += "method "; + else if (info.apiType == API_FIELD) + notice += "field "; + else if (info.apiType == API_CONSTANT) + notice += "constant "; + else + notice += "API "; + + notice += info.name; + + if (info.type == DEPRECATED_REPLACED && !info.replacement.empty()) notice += " (replaced by " + info.replacement + ")"; else if (info.type == DEPRECATED_RENAMED && !info.replacement.empty()) notice += " (renamed to " + info.replacement + ")"; @@ -114,12 +127,12 @@ GetDeprecated::~GetDeprecated() mutex->unlock(); } -MarkDeprecated::MarkDeprecated(const char *name) - : MarkDeprecated(name, DEPRECATED_NO_REPLACEMENT, nullptr) +MarkDeprecated::MarkDeprecated(const char *name, APIType api) + : MarkDeprecated(name, api, DEPRECATED_NO_REPLACEMENT, nullptr) { } -MarkDeprecated::MarkDeprecated(const char *name, DeprecationType type, const char *replacement) +MarkDeprecated::MarkDeprecated(const char *name, APIType api, DeprecationType type, const char *replacement) : info(nullptr) { if (mutex != nullptr) @@ -137,6 +150,7 @@ MarkDeprecated::MarkDeprecated(const char *name, DeprecationType type, const cha DeprecationInfo newinfo = {}; newinfo.type = type; + newinfo.apiType = api; newinfo.uses = 1; newinfo.name = name; diff --git a/src/common/deprecation.h b/src/common/deprecation.h index 1efad5f41..8cd70e8b4 100644 --- a/src/common/deprecation.h +++ b/src/common/deprecation.h @@ -28,16 +28,25 @@ namespace love { +enum APIType +{ + API_FUNCTION, + API_METHOD, + API_FIELD, + API_CONSTANT, +}; + enum DeprecationType { DEPRECATED_NO_REPLACEMENT, - DEPRECATED_REPLACEMENT, + DEPRECATED_REPLACED, DEPRECATED_RENAMED, }; struct DeprecationInfo { DeprecationType type; + APIType apiType; int64 uses; std::string name; std::string replacement; @@ -62,8 +71,8 @@ struct GetDeprecated struct MarkDeprecated { - MarkDeprecated(const char *name); - MarkDeprecated(const char *name, DeprecationType type, const char *replacement); + MarkDeprecated(const char *name, APIType api); + MarkDeprecated(const char *name, APIType api, DeprecationType type, const char *replacement); ~MarkDeprecated(); DeprecationInfo *info; diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index a9291fed5..a655462db 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -786,14 +786,14 @@ lua_State *luax_getpinnedthread(lua_State *L) return thread; } -void luax_markdeprecated(lua_State *L, const char *name) +void luax_markdeprecated(lua_State *L, const char *name, APIType api) { - luax_markdeprecated(L, name, DEPRECATED_NO_REPLACEMENT, nullptr); + luax_markdeprecated(L, name, api, DEPRECATED_NO_REPLACEMENT, nullptr); } -void luax_markdeprecated(lua_State *L, const char *name, DeprecationType type, const char *replacement) +void luax_markdeprecated(lua_State *L, const char *name, APIType api, DeprecationType type, const char *replacement) { - MarkDeprecated deprecated(name, type, replacement); + MarkDeprecated deprecated(name, api, type, replacement); if (deprecated.info != nullptr && deprecated.info->uses == 1) { diff --git a/src/common/runtime.h b/src/common/runtime.h index fa9ed834b..14c89a5dd 100644 --- a/src/common/runtime.h +++ b/src/common/runtime.h @@ -452,8 +452,8 @@ lua_State *luax_getpinnedthread(lua_State *L); * Mark a function as deprecated. Should only be called inside wrapper function * code. **/ -void luax_markdeprecated(lua_State *L, const char *name); -void luax_markdeprecated(lua_State *L, const char *name, DeprecationType type, const char *replacement); +void luax_markdeprecated(lua_State *L, const char *name, APIType api); +void luax_markdeprecated(lua_State *L, const char *name, APIType api, DeprecationType type, const char *replacement); extern "C" { // Also called from luasocket int luax_typerror(lua_State *L, int narg, const char *tname); diff --git a/src/modules/audio/wrap_Audio.cpp b/src/modules/audio/wrap_Audio.cpp index 48370466f..8d3faa56c 100644 --- a/src/modules/audio/wrap_Audio.cpp +++ b/src/modules/audio/wrap_Audio.cpp @@ -526,7 +526,7 @@ int w_setMixWithSystem(lua_State *L) int w_getSourceCount(lua_State *L) { - luax_markdeprecated(L, "love.audio.getSourceCount", DEPRECATED_RENAMED, "love.audio.getActiveSourceCount"); + luax_markdeprecated(L, "love.audio.getSourceCount", API_FUNCTION, DEPRECATED_RENAMED, "love.audio.getActiveSourceCount"); return w_getActiveSourceCount(L); } diff --git a/src/modules/audio/wrap_Source.cpp b/src/modules/audio/wrap_Source.cpp index 63e9195d7..95f66bdfe 100644 --- a/src/modules/audio/wrap_Source.cpp +++ b/src/modules/audio/wrap_Source.cpp @@ -584,7 +584,7 @@ int w_Source_getType(lua_State *L) int w_Source_getChannels(lua_State *L) { - luax_markdeprecated(L, "Source:getChannels", DEPRECATED_RENAMED, "Source:getChannelCount"); + luax_markdeprecated(L, "Source:getChannels", API_METHOD, DEPRECATED_RENAMED, "Source:getChannelCount"); return w_Source_getChannelCount(L); } diff --git a/src/modules/physics/box2d/wrap_PrismaticJoint.cpp b/src/modules/physics/box2d/wrap_PrismaticJoint.cpp index 977edae1f..61d61fbd0 100644 --- a/src/modules/physics/box2d/wrap_PrismaticJoint.cpp +++ b/src/modules/physics/box2d/wrap_PrismaticJoint.cpp @@ -180,7 +180,7 @@ int w_PrismaticJoint_getReferenceAngle(lua_State *L) int w_PrismaticJoint_hasLimitsEnabled(lua_State *L) { - luax_markdeprecated(L, "PrismaticJoint:hasLimitsEnabled", DEPRECATED_RENAMED, "PrismaticJoint:areLimitsEnabled"); + luax_markdeprecated(L, "PrismaticJoint:hasLimitsEnabled", API_METHOD, DEPRECATED_RENAMED, "PrismaticJoint:areLimitsEnabled"); return w_PrismaticJoint_areLimitsEnabled(L); } diff --git a/src/modules/physics/box2d/wrap_RevoluteJoint.cpp b/src/modules/physics/box2d/wrap_RevoluteJoint.cpp index 4e10de4cf..436a90cfc 100644 --- a/src/modules/physics/box2d/wrap_RevoluteJoint.cpp +++ b/src/modules/physics/box2d/wrap_RevoluteJoint.cpp @@ -173,7 +173,7 @@ int w_RevoluteJoint_getReferenceAngle(lua_State *L) int w_RevoluteJoint_hasLimitsEnabled(lua_State *L) { - luax_markdeprecated(L, "RevoluteJoint:hasLimitsEnabled", DEPRECATED_RENAMED, "RevoluteJoint:areLimitsEnabled"); + luax_markdeprecated(L, "RevoluteJoint:hasLimitsEnabled", API_METHOD, DEPRECATED_RENAMED, "RevoluteJoint:areLimitsEnabled"); return w_RevoluteJoint_areLimitsEnabled(L); } diff --git a/src/modules/sound/wrap_Decoder.cpp b/src/modules/sound/wrap_Decoder.cpp index 764f05655..17bc8bdd8 100644 --- a/src/modules/sound/wrap_Decoder.cpp +++ b/src/modules/sound/wrap_Decoder.cpp @@ -98,7 +98,7 @@ int w_Decoder_seek(lua_State *L) int w_Decoder_getChannels(lua_State *L) { - luax_markdeprecated(L, "Decoder:getChannels", DEPRECATED_RENAMED, "Decoder:getChannelCount"); + luax_markdeprecated(L, "Decoder:getChannels", API_METHOD, DEPRECATED_RENAMED, "Decoder:getChannelCount"); return w_Decoder_getChannelCount(L); } diff --git a/src/modules/sound/wrap_SoundData.cpp b/src/modules/sound/wrap_SoundData.cpp index 26061441b..6985ead9a 100644 --- a/src/modules/sound/wrap_SoundData.cpp +++ b/src/modules/sound/wrap_SoundData.cpp @@ -107,7 +107,7 @@ int w_SoundData_getSample(lua_State *L) int w_SoundData_getChannels(lua_State *L) { - luax_markdeprecated(L, "SoundData:getChannels", DEPRECATED_RENAMED, "SoundData:getChannelCount"); + luax_markdeprecated(L, "SoundData:getChannels", API_METHOD, DEPRECATED_RENAMED, "SoundData:getChannelCount"); return w_SoundData_getChannelCount(L); }