Skip to content

Commit

Permalink
Remove deprecated "inheritance" (#2974)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Oct 28, 2024
1 parent 379e2b1 commit 93ed7f7
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 43 deletions.
26 changes: 3 additions & 23 deletions cpp/src/Slice/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,23 +936,17 @@ Slice::Contained::parseFormatMetadata(const StringList& metadata)
}

bool
Slice::Contained::isDeprecated(bool checkParent) const
Slice::Contained::isDeprecated() const
{
const string prefix1 = "deprecate";
const string prefix2 = "deprecated";
ContainedPtr parent = checkParent ? dynamic_pointer_cast<Contained>(_container) : nullptr;

return (hasMetadata(prefix1) || (parent && parent->hasMetadata(prefix1))) ||
(hasMetadata(prefix2) || (parent && parent->hasMetadata(prefix2)));
return (hasMetadata("deprecate") || hasMetadata("deprecated"));
}

optional<string>
Slice::Contained::getDeprecationReason(bool checkParent) const
Slice::Contained::getDeprecationReason() const
{
const string prefix1 = "deprecate:";
const string prefix2 = "deprecated:";

// First, we check if the element itself is deprecated.
if (auto meta = findMetadata(prefix1))
{
return meta->substr(prefix1.size());
Expand All @@ -962,20 +956,6 @@ Slice::Contained::getDeprecationReason(bool checkParent) const
return meta->substr(prefix2.size());
}

// Then, if necessary, we check if the container it's within is deprecated.
ContainedPtr parent = checkParent ? dynamic_pointer_cast<Contained>(_container) : nullptr;
if (checkParent && parent)
{
if (auto meta = parent->findMetadata(prefix1))
{
return meta->substr(prefix1.size());
}
if (auto meta = parent->findMetadata(prefix2))
{
return meta->substr(prefix2.size());
}
}

return nullopt;
}

Expand Down
13 changes: 5 additions & 8 deletions cpp/src/Slice/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,14 @@ namespace Slice

static std::optional<FormatType> parseFormatMetadata(const StringList& metadata);

/// Returns true if this item is deprecated (due to the presence of 'deprecated' metadata).
/// @param checkParent If true, this item's immediate container will also be checked for 'deprecated' metadata.
/// @return True if this item (or possibly its container) has 'deprecated' metadata on it, false otherwise.
bool isDeprecated(bool checkParent) const;
/// Returns true if this item is deprecated, due to the presence of 'deprecated' metadata.
/// @return True if this item has 'deprecated' metadata on it, false otherwise.
bool isDeprecated() const;

/// If this item is deprecated, return its deprecation message (if present).
/// This is the string argument that can be optionally provided with 'deprecated' metadata.
/// @param checkParent If true, this item's immediate container will also be checked for 'deprecated' messages.
/// @return The message provided to the 'deprecated' metadata, if present. If 'checkParent' is true, and both
/// this item and its parent have 'deprecated' messages, the item's message is returned, not its container's.
std::optional<std::string> getDeprecationReason(bool checkParent) const;
/// @return The message provided to the 'deprecated' metadata, if present.
std::optional<std::string> getDeprecationReason() const;

virtual std::string kindOf() const = 0;

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/slice2cpp/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ namespace
string getDeprecatedSymbol(const ContainedPtr& p1)
{
string deprecatedSymbol;
if (p1->isDeprecated(false)) // 'false' means: don't check the parent type.
if (p1->isDeprecated())
{
if (auto reason = p1->getDeprecationReason(false))
if (auto reason = p1->getDeprecationReason())
{
deprecatedSymbol = "[[deprecated(\"" + *reason + "\")]] ";
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/slice2cs/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ namespace

void emitObsoleteAttribute(const ContainedPtr& p1, Output& out)
{
if (p1->isDeprecated(true))
if (p1->isDeprecated())
{
if (auto reason = p1->getDeprecationReason(true))
if (auto reason = p1->getDeprecationReason())
{
out << nl << "[global::System.Obsolete(\"" << *reason << "\")]";
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/slice2matlab/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,10 @@ namespace
{
DocElements doc;

doc.deprecated = p->isDeprecated(false);
doc.deprecated = p->isDeprecated();

// First check metadata for a deprecated tag.
if (auto reason = p->getDeprecationReason(false))
if (auto reason = p->getDeprecationReason())
{
doc.deprecateReason.push_back(IceInternal::trim(*reason));
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/slice2py/PythonUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,10 +1109,10 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
}
_out << "))";

if (operation->isDeprecated(true))
if (operation->isDeprecated())
{
// Get the deprecation reason if present, or default to an empty string.
string reason = operation->getDeprecationReason(true).value_or("");
string reason = operation->getDeprecationReason().value_or("");
_out << nl << className << "._op_" << operation->name() << ".deprecate(\"" << reason << "\")";
}
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/slice2rb/RubyUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,10 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
}
_out << "])";

if (op->isDeprecated(true))
if (op->isDeprecated())
{
// Get the deprecation reason if present, or default to an empty string.
string reason = op->getDeprecationReason(true).value_or("");
string reason = op->getDeprecationReason().value_or("");
_out << nl << name << "Prx_mixin::OP_" << op->name() << ".deprecate(\"" << reason << "\")";
}
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/slice2swift/SwiftUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ SwiftGenerator::parseComment(const ContainedPtr& p)
{
DocElements doc;

doc.deprecated = p->isDeprecated(false);
doc.deprecated = p->isDeprecated();

// First check metadata for a deprecated tag.
if (auto reason = p->getDeprecationReason(false))
if (auto reason = p->getDeprecationReason())
{
doc.deprecateReason.push_back(IceInternal::trim(*reason));
}
Expand Down

0 comments on commit 93ed7f7

Please sign in to comment.