Skip to content

Commit a76a05b

Browse files
committed
feat(deprecations): ARK-341 show deprecation warnings when using '@deprecated' functions/values
1 parent 67cbb00 commit a76a05b

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- `:?s` to format as an escaped quoted string,
1313
- `:s` to format as a quoted string
1414
- `format` can use format specifiers for integers: `b`, `#b`, `B`, `#B`, `c`, `d`, `o`, `x`, `#x`, `X`, and `#X` if the argument is an integer
15+
- display a warning to `stderr` when using a deprecated function/value (checks for `@deprecated` inside the attached comment of functions / values)
1516

1617
### Changed
1718

src/arkreactor/Compiler/AST/Optimizer.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <Ark/Compiler/AST/Optimizer.hpp>
22

3+
#include <Ark/Utils/Utils.hpp>
4+
35
namespace Ark::internal
46
{
57
Optimizer::Optimizer(const unsigned debug) noexcept :
@@ -110,6 +112,30 @@ namespace Ark::internal
110112
// erase the node by turning it to an Unused node
111113
child = Node(NodeType::Unused);
112114
}
115+
else if (child.comment().find("@deprecated") != std::string::npos)
116+
{
117+
std::string advice;
118+
const std::vector<std::string> vec = Utils::splitString(child.comment(), '\n');
119+
if (auto result = std::ranges::find_if(vec, [](const std::string& line) {
120+
return line.find("@deprecated") != std::string::npos;
121+
});
122+
result != vec.end())
123+
{
124+
advice = result->substr(result->find("@deprecated") + 11);
125+
Utils::trimWhitespace(advice);
126+
}
127+
128+
m_logger.warn(
129+
"Using a deprecated {} `{}'.{}",
130+
child.constList()[2].nodeType() == NodeType::List &&
131+
!child.constList()[2].constList().empty() &&
132+
child.constList()[2].constList()[0].nodeType() == NodeType::Keyword &&
133+
child.constList()[2].constList()[0].keyword() == Keyword::Fun
134+
? "function"
135+
: "value",
136+
name,
137+
advice.empty() ? "" : " " + advice);
138+
}
113139
}
114140
}
115141
else if (child.nodeType() == NodeType::Namespace)

0 commit comments

Comments
 (0)