Skip to content

Commit

Permalink
Add #deprecated preprocessor directive for marking macros deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 12, 2018
1 parent 3440546 commit ae50be5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 14 deletions.
37 changes: 27 additions & 10 deletions data/core/macros/deprecated-utils.cfg
Expand Up @@ -5,7 +5,7 @@

#wmllint: markcheck off
#define DEPRECATE MACRO_NAME VERSION_NAME
# Tag ActionWML macros for removal, where VERSION_NAME is the the next development series from the date of deprecation.
#deprecated 3 1.15 Use DEPRECATE_ACTION_MACRO instead.
[deprecated_message]
what={MACRO_NAME}
level=2
Expand All @@ -25,32 +25,42 @@
#wmllint: markcheck on

#define MAGENTA_IS_THE_TEAM_COLOR
# This used to be used to set the default team colour for most unit types
# It's no longer needed, since the default is now set in the game_config.
#deprecated 3 1.15 This used to be used to set the default team colour for most unit types
#deprecated 3 1.15 It's no longer needed, since the default is now set in the game_config.
#enddef

#define ABILITY_LEADERSHIP_LEVEL_1
#deprecated 2 1.15 Leadership is now a single unified macro.
#deprecated 2 1.15 If you gave it to a unit other than its intended level, you'll need a custom macro.
{ABILITY_LEADERSHIP}
#enddef

#define ABILITY_LEADERSHIP_LEVEL_2
#deprecated 2 1.15 Leadership is now a single unified macro.
#deprecated 2 1.15 If you gave it to a unit other than its intended level, you'll need a custom macro.
{ABILITY_LEADERSHIP}
#enddef

#define ABILITY_LEADERSHIP_LEVEL_3
#deprecated 2 1.15 Leadership is now a single unified macro.
#deprecated 2 1.15 If you gave it to a unit other than its intended level, you'll need a custom macro.
{ABILITY_LEADERSHIP}
#enddef

#define ABILITY_LEADERSHIP_LEVEL_4
#deprecated 2 1.15 Leadership is now a single unified macro.
#deprecated 2 1.15 If you gave it to a unit other than its intended level, you'll need a custom macro.
{ABILITY_LEADERSHIP}
#enddef

#define ABILITY_LEADERSHIP_LEVEL_5
#deprecated 2 1.15 Leadership is now a single unified macro.
#deprecated 2 1.15 If you gave it to a unit other than its intended level, you'll need a custom macro.
{ABILITY_LEADERSHIP}
#enddef

#define EARLY_FINISH_BONUS_CAPTION
# Deprecated; use the below EARLY_FINISH_BONUS_FOOTNOTE instead
#deprecated 3 1.15 Use EARLY_FINISH_BONUS_FOOTNOTE instead
_"<small>(early finish bonus)</small>"#enddef

#define EARLY_FINISH_BONUS_NOTE
Expand Down Expand Up @@ -80,6 +90,7 @@ _"No gold carried over to the next scenario."#enddef
#enddef

#define MESSAGE SPEAKER_ID IMAGE CAPTION_TEXT MESSAGE_TEXT
#deprecated 1 It's preferred to simply write out the message tag in full.
# Displays a text message spoken by SPEAKER_ID.
# Speaker can be any of: narrator, unit and second_unit
# For example, let's have the narrator, which looks like a faery
Expand Down Expand Up @@ -119,6 +130,7 @@ _"No gold carried over to the next scenario."#enddef
#enddef

#define ON_SIGHTING ID SIGHTING_SIDE SIGHTED_FILTER ACTION_WML
#deprecated 1 Use an [event]name=sighted instead.
# NOTE: As of version 1.11, this macro is unnecessary, since sighted
# events now work as intended.
#
Expand Down Expand Up @@ -267,6 +279,7 @@ _"No gold carried over to the next scenario."#enddef
#enddef

#define ANIMATED_CAMPFIRE X Y
# deprecated 2 1.15 Use the campfire terrain overlay (^Ecf) instead.
# Embed this at scenario toplevel, not within an event.
# Note that it will freeze while dialogue popups are onscreen.
[terrain_graphics]
Expand All @@ -284,6 +297,7 @@ _"No gold carried over to the next scenario."#enddef
#enddef

#define ANIMATED_BRAZIER X Y
# deprecated 2 1.15 Use the campfire terrain overlay (^Eb) instead.
# Embed this at scenario toplevel, not within an event.
# Note that it will freeze while dialogue popups are onscreen.
[terrain_graphics]
Expand Down Expand Up @@ -319,6 +333,7 @@ _"No gold carried over to the next scenario."#enddef

# wmlindent: start ignoring
#define FOREACH ARRAY_VALUE VAR
#deprecated 1 You should use the [foreach] WML tag instead.
# Macro to begin a WML clause that iterates over an array.
{VARIABLE {VAR} 0}
[while]
Expand All @@ -330,6 +345,7 @@ _"No gold carried over to the next scenario."#enddef
#enddef

#define NEXT VAR
#deprecated 1 You should use the [foreach] WML tag instead of {FOREACH}.
# Macro to end a WML clause that iterates over an array.
[set_variable]
name={VAR}
Expand Down Expand Up @@ -379,15 +395,15 @@ _"No gold carried over to the next scenario."#enddef
#enddef

#define SOUND:SLOW
# This was used to play a sound when slowing a unit, it had to
# be placed inside an attack animation. Now this sound is played
# automatically, there is no other use for this macro.
#deprecated 3 1.15 This was used to play a sound when slowing a unit, it had to
#deprecated 3 1.15 be placed inside an attack animation. Now this sound is played
#deprecated 3 1.15 automatically, there is no other use for this macro.
#enddef

#define SOUND:POISON
# This was used to play a sound when poisoning a unit, it had to
# be placed inside an attack animation. Now this sound is played
# automatically, there is no other use for this macro.
#deprecated 3 1.15 This was used to play a sound when poisoning a unit, it had to
#deprecated 3 1.15 be placed inside an attack animation. Now this sound is played
#deprecated 3 1.15 automatically, there is no other use for this macro.
#enddef

#define NO_INTERRUPT_NO_UNDO
Expand All @@ -398,5 +414,6 @@ _"No gold carried over to the next scenario."#enddef

# TODO: remove for 1.15
#define KHALIFATE_NAMES
#deprecated 3 1.15 Use DUNEFOLK_NAMES instead.
{DUNEFOLK_NAMES}
#enddef
53 changes: 50 additions & 3 deletions src/serialization/preprocessor.cpp
Expand Up @@ -28,6 +28,7 @@
#include "serialization/string_utils.hpp"
#include "version.hpp"
#include "wesconfig.h"
#include "deprecation.hpp"

#include <stdexcept>
#include <deque>
Expand Down Expand Up @@ -1152,8 +1153,10 @@ bool preprocessor_data::get_chunk()

std::string symbol = items.front();
items.erase(items.begin());
int found_arg = 0, found_enddef = 0;
std::string buffer;
int found_arg = 0, found_enddef = 0, found_deprecate = 0;
int deprecation_level = -1;
std::string buffer, deprecation_detail;
version_info deprecation_version = game_config::wesnoth_version;
for(;;) {
if(in_.eof())
break;
Expand All @@ -1164,6 +1167,8 @@ bool preprocessor_data::get_chunk()
if(d == '#') {
if(in_.peek() == 'a') {
found_arg = 1;
} else if(in_.peek() == 'd') {
found_deprecate = 1;
} else {
found_enddef = 1;
}
Expand Down Expand Up @@ -1207,6 +1212,28 @@ bool preprocessor_data::get_chunk()
}
}

if(found_deprecate > 0 && ++found_deprecate == 11) {
if(std::equal(buffer.end() - 10, buffer.end(), "deprecated")) {
buffer.erase(buffer.end() - 11, buffer.end());
skip_spaces();
try {
deprecation_level = std::max(deprecation_level, std::stoi(read_word()));
} catch(std::invalid_argument&) {
deprecation_level = 0;
}
deprecation_version = game_config::wesnoth_version;
if(deprecation_level == 2 || deprecation_level == 3) {
skip_spaces();
deprecation_version = std::max(deprecation_version, version_info(read_word()));
}
skip_spaces();
if(!deprecation_detail.empty()){
deprecation_detail += '\n';
}
deprecation_detail = read_rest_of_line();
}
}

if(found_enddef > 0 && ++found_enddef == 7) {
if(std::equal(buffer.end() - 6, buffer.end(), "enddef")) {
break;
Expand Down Expand Up @@ -1244,7 +1271,8 @@ bool preprocessor_data::get_chunk()

buffer.erase(buffer.end() - 7, buffer.end());
(*parent_.defines_)[symbol]
= preproc_define(buffer, items, optargs, parent_.textdomain_, linenum, parent_.location_);
= preproc_define(buffer, items, optargs, parent_.textdomain_, linenum, parent_.location_,
deprecation_detail, deprecation_level, deprecation_version);

LOG_PREPROC << "defining macro " << symbol << " (location " << get_location(parent_.location_) << ")\n";
}
Expand Down Expand Up @@ -1366,6 +1394,21 @@ bool preprocessor_data::get_chunk()
} else {
DBG_PREPROC << "Skipped a warning\n";
}
} else if(command == "deprecated") {
// The current file is deprecated, so print a message
skip_spaces();
int level = 0;
try {
level = std::stoi(read_word());
} catch(std::invalid_argument&) {}
version_info version = game_config::wesnoth_version;
if(level == 2 || level == 3) {
skip_spaces();
version = version_info(read_word());
}
skip_spaces();
std::string detail = read_rest_of_line();
deprecated_message(get_filename(parent_.location_), level, version, detail);
} else {
comment = token.type != token_desc::MACRO_SPACE;
}
Expand Down Expand Up @@ -1444,6 +1487,10 @@ bool preprocessor_data::get_chunk()
std::unique_ptr<std::map<std::string, std::string>> defines{new std::map<std::string, std::string>};
const std::string& dir = filesystem::directory_name(val.location.substr(0, val.location.find(' ')));

if(val.is_deprecated()) {
deprecated_message(symbol, val.deprecation_level, val.deprecation_version, val.deprecation_message);
}

for(size_t i = 0; i < nb_arg; ++i) {
if(i < val.arguments.size()) {
// Normal mandatory arguments
Expand Down
18 changes: 17 additions & 1 deletion src/serialization/preprocessor.hpp
Expand Up @@ -23,6 +23,7 @@
#include <vector>

#include "exceptions.hpp"
#include "version.hpp"

class config_writer;
class config;
Expand Down Expand Up @@ -56,13 +57,18 @@ struct preproc_define
const std::map<std::string, std::string>& optargs,
const std::string& domain,
int line,
const std::string& loc)
const std::string& loc,
const std::string& dep_msg,
int dep_lvl, const version_info& dep_ver)
: value(val)
, arguments(args)
, optional_arguments(optargs)
, textdomain(domain)
, linenum(line)
, location(loc)
, deprecation_message(dep_msg)
, deprecation_level(dep_lvl)
, deprecation_version(dep_ver)
{
}

Expand All @@ -78,6 +84,16 @@ struct preproc_define

std::string location;

std::string deprecation_message;

int deprecation_level = -1;

This comment has been minimized.

Copy link
@CelticMinstrel

CelticMinstrel Feb 12, 2018

Author Member

I guess I could've made this 0, but whatever. It doesn't really matter as long as it means is_deprecated() returns false.


version_info deprecation_version;

bool is_deprecated() const {
return deprecation_level > 0;
}

void write(config_writer&, const std::string&) const;
void write_argument(config_writer&, const std::string&) const;

Expand Down

0 comments on commit ae50be5

Please sign in to comment.