Skip to content

Commit

Permalink
[.di generation] Show TypeCtor method attributes after parameters (dl…
Browse files Browse the repository at this point in the history
…ang#16732)

* [.di generation] Show TypeCtor method attributes after parameters

Follow up to dlang#16708.

* Add changelog
  • Loading branch information
ntrel authored and thewilsonator committed Oct 7, 2024
1 parent d6059e1 commit 7f07be7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
13 changes: 13 additions & 0 deletions changelog/dmd.postfix-this-attributes.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Postfix type qualifier method attributes for `-H` and `-D`

`.di` interface file generation and Ddoc output will now have type qualifier
attributes placed after the parameter list for methods (and constructors).
This avoids confusion with the return type.

---
struct S
{
const int f(); // before
int f() const; // now
}
---
6 changes: 3 additions & 3 deletions compiler/src/dmd/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -3927,7 +3927,7 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te

/* Use 'storage class' (prefix) style for attributes
*/
if (t.mod && !hgs.ddoc)
if (t.mod && !(hgs.ddoc || hgs.hdrgen))
{
MODtoBuffer(buf, t.mod);
buf.writeByte(' ');
Expand Down Expand Up @@ -3977,8 +3977,8 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te
buf.writeByte(')');
}
parametersToBuffer(t.parameterList, buf, hgs);
// postfix TypeCtor attributes are more readable
if (t.mod && hgs.ddoc)
// postfix this attributes are more readable
if (t.mod && (hgs.ddoc || hgs.hdrgen))
{
buf.writeByte(' ');
MODtoBuffer(buf, t.mod);
Expand Down
12 changes: 6 additions & 6 deletions compiler/test/compilable/extra-files/header1.di
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ int bar11(T)()
}
struct S6360
{
const pure nothrow @property long weeks1();
const pure nothrow @property long weeks2();
pure nothrow @property long weeks1() const;
pure nothrow @property long weeks2() const;
}
struct S12
{
Expand All @@ -369,10 +369,10 @@ struct S12
}
struct T12
{
immutable this()(int args)
this()(int args) immutable
{
}
immutable this(A...)(A args)
this(A...)(A args) immutable
{
}
}
Expand Down Expand Up @@ -502,7 +502,7 @@ size_t magic();
class Foo2A
{
immutable(FooA) Dummy = new immutable(FooA);
private immutable pure nothrow @nogc @safe this();
private pure nothrow @nogc @safe this() immutable;
}
struct Foo3A(T)
{
Expand Down Expand Up @@ -560,4 +560,4 @@ interface I12344
assert(result > 0);
}
;
}
}
12 changes: 6 additions & 6 deletions compiler/test/compilable/extra-files/header1i.di
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,11 @@ int bar11(T)()
}
struct S6360
{
const pure nothrow @property long weeks1()
pure nothrow @property long weeks1() const
{
return 0;
}
const pure nothrow @property long weeks2()
pure nothrow @property long weeks2() const
{
return 0;
}
Expand All @@ -472,10 +472,10 @@ struct S12
}
struct T12
{
immutable this()(int args)
this()(int args) immutable
{
}
immutable this(A...)(A args)
this(A...)(A args) immutable
{
}
}
Expand Down Expand Up @@ -624,7 +624,7 @@ size_t magic()
class Foo2A
{
immutable(FooA) Dummy = new immutable(FooA);
private immutable pure nothrow @nogc @safe this()
private pure nothrow @nogc @safe this() immutable
{
}
}
Expand Down Expand Up @@ -715,4 +715,4 @@ interface I12344
assert(result > 0);
}
;
}
}
2 changes: 1 addition & 1 deletion compiler/test/compilable/header18365.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct FullCaseEntry
ubyte n;
ubyte size;
ubyte entry_len;
auto const pure nothrow @nogc @property @trusted value() return
auto pure nothrow @nogc @property @trusted value() const return
{
return seq[0..entry_len];
}
Expand Down

0 comments on commit 7f07be7

Please sign in to comment.