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

Generate deprecation attribute for deprecated functions/constants #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion source/gtd/GirConstant.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ final class GirConstant
string cType;
string value;
string doc;
bool isDeprecated;
string docDeprecated;

GirType type;
GirPackage pack;
Expand All @@ -52,6 +54,8 @@ final class GirConstant
cType = reader.front.attributes["c:type"];
else
cType = reader.front.attributes["c:identifier"];
if ( "deprecated" in reader.front.attributes )
isDeprecated = reader.front.attributes["deprecated"] == "1";

reader.popFront();

Expand All @@ -71,7 +75,8 @@ final class GirConstant
break;
case "doc-deprecated":
reader.popFront();
doc ~= "\n\nDeprecated: "~ reader.front.value;
docDeprecated = reader.front.value;
doc ~= "\n\nDeprecated: "~ docDeprecated;
kubo39 marked this conversation as resolved.
Show resolved Hide resolved
reader.popFront();
break;
case "source-position":
Expand Down Expand Up @@ -102,6 +107,14 @@ final class GirConstant
buff ~= " */";
}

if ( isDeprecated )
{
if ( docDeprecated )
buff ~= `deprecated("` ~ docDeprecated ~ `")`;
else
buff ~= `deprecated("` ~ name ~ ` has been deprecated.")`;
}

if ( type.name in pack.collectedAliases && pack.collectedAliases[type.name].baseType.cType.among("gint64", "guint64") )
value ~= "UL";

Expand Down
15 changes: 14 additions & 1 deletion source/gtd/GirFunction.d
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ final class GirFunction
string cType;
string libVersion;
string movedTo;
bool isDeprecated;
string docDeprecated;
bool virtual = false;
bool throws = false;
bool lookupOverride; /// Force marking this function with override.
Expand Down Expand Up @@ -107,6 +109,8 @@ final class GirFunction
throws = reader.front.attributes["throws"] == "1";
if ( "moved-to" in reader.front.attributes )
movedTo = reader.front.attributes["moved-to"];
if ( "deprecated" in reader.front.attributes )
isDeprecated = reader.front.attributes["deprecated"] == "1";

reader.popFront();

Expand All @@ -127,7 +131,8 @@ final class GirFunction
break;
case "doc-deprecated":
reader.popFront();
doc ~= "\n\nDeprecated: "~ reader.front.value;
docDeprecated = reader.front.value;
doc ~= "\n\nDeprecated: " ~ docDeprecated;
reader.popFront();
break;
case "doc-version":
Expand Down Expand Up @@ -361,6 +366,14 @@ final class GirFunction
resolveLength();
writeDocs(buff);

if ( isDeprecated )
{
if ( docDeprecated.length )
buff ~= `deprecated("` ~ docDeprecated ~ `")`;
else
buff ~= `deprecated("` ~ name ~ ` has been deprecated.")`;
}

if ( type == GirFunctionType.Constructor )
{
dec ~= "this(";
Expand Down