Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ObsoleteAttribute projection. #1712

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11068,4 +11068,15 @@ return true;
//------------------------------------------------------------------------------
)", VERSION_STRING);
}

void write_deprecated_attribute(writer& w, CustomAttribute const& deprecatedAttribute)
{
std::string_view message = std::get<std::string_view>(std::get<ElemSig>(deprecatedAttribute.Value().FixedArgs()[0].value).value);
ElemSig::EnumValue deprecationType = std::get<ElemSig::EnumValue>(std::get<ElemSig>(deprecatedAttribute.Value().FixedArgs()[1].value).value);
bool shouldError = deprecationType.equals_enumerator("Remove");
w.write(R"([System.Obsolete("%", %)])",
message,
shouldError ? "true" : "false");
w.write('\n');
}
}
43 changes: 43 additions & 0 deletions src/cswinrt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ Where <spec> is one or more of:
auto guard1{ helperWriter.push_generic_params(type.GenericParam()) };

bool type_requires_abi = true;

for (auto&& attribute : type.CustomAttribute())
{
auto attribute_name = attribute.TypeNamespaceAndName();
if (attribute_name.first == "Windows.Foundation.Metadata" && attribute_name.second == "DeprecatedAttribute")
{
write_deprecated_attribute(w, attribute);
break;
}
}
switch (get_category(type))
{
case category::class_type:
Expand Down Expand Up @@ -292,35 +302,68 @@ Where <spec> is one or more of:
if (is_attribute_type(type)) { continue; }
auto guard{ w.push_generic_params(type.GenericParam()) };

bool is_deprecated = false;
CustomAttribute deprecatedAttribute;

for (auto&& attribute : type.CustomAttribute())
{
auto attribute_name = attribute.TypeNamespaceAndName();
if (attribute_name.first == "Windows.Foundation.Metadata" && attribute_name.second == "DeprecatedAttribute")
{
is_deprecated = true;
deprecatedAttribute = attribute;
break;
}
}
switch (get_category(type))
{
case category::class_type:
if (is_deprecated)
write_deprecated_attribute(w, deprecatedAttribute);
write_abi_class(w, type);
if (settings.component && componentActivatableClasses.count(type) == 1)
{
if (is_deprecated)
write_deprecated_attribute(w, deprecatedAttribute);
write_winrt_exposed_type_class(w, type, true);
}
if (is_deprecated)
write_deprecated_attribute(w, deprecatedAttribute);
write_winrt_implementation_type_rcw_factory_attribute_type(w, type);
break;
case category::delegate_type:
if (is_deprecated)
write_deprecated_attribute(w, deprecatedAttribute);
write_abi_delegate(w, type);
if (is_deprecated)
write_deprecated_attribute(w, deprecatedAttribute);
write_winrt_exposed_type_class(w, type, false);
break;
case category::interface_type:
if (settings.netstandard_compat)
{
if (is_deprecated)
write_deprecated_attribute(w, deprecatedAttribute);
write_static_abi_classes(w, type);
if (is_deprecated)
write_deprecated_attribute(w, deprecatedAttribute);
write_abi_interface_netstandard(w, type);
}
else
{
if (is_deprecated)
write_deprecated_attribute(w, deprecatedAttribute);
write_static_abi_classes(w, type);
if (is_deprecated)
write_deprecated_attribute(w, deprecatedAttribute);
write_abi_interface(w, type);
}
break;
case category::struct_type:
if (!is_type_blittable(type))
{
if (is_deprecated)
write_deprecated_attribute(w, deprecatedAttribute);
write_abi_struct(w, type);
}
break;
Expand Down