Skip to content

Commit 619498c

Browse files
Move search_toString to semantic3 (#21590)
1 parent c2c8189 commit 619498c

4 files changed

Lines changed: 27 additions & 27 deletions

File tree

compiler/src/dmd/cxxfrontend.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import dmd.init : Initializer, NeedInterpret;
3232
import dmd.location : Loc;
3333
import dmd.mtype /*: Covariant, Type, Parameter, ParameterList*/;
3434
import dmd.rootobject : RootObject;
35+
import dmd.semantic3;
3536
import dmd.statement : Statement, AsmStatement, GccAsmStatement;
3637

3738
// NB: At some point in the future, we can switch to shortened function syntax.
@@ -132,7 +133,7 @@ void gendocfile(Module m, const char* ddoctext_ptr, size_t ddoctext_length,
132133
*/
133134
FuncDeclaration search_toString(StructDeclaration sd)
134135
{
135-
return dmd.dstruct.search_toString(sd);
136+
return dmd.semantic3.search_toString(sd);
136137
}
137138

138139
/***********************************************************

compiler/src/dmd/dstruct.d

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,9 @@ import dmd.mtype;
3737
import dmd.opover;
3838
import dmd.target;
3939
import dmd.tokens;
40-
import dmd.typesem : merge;
4140
import dmd.typinf;
4241
import dmd.visitor;
4342

44-
/***************************************
45-
* Search sd for a member function of the form:
46-
* `extern (D) string toString();`
47-
* Params:
48-
* sd = struct declaration to search
49-
* Returns:
50-
* FuncDeclaration of `toString()` if found, `null` if not
51-
*/
52-
FuncDeclaration search_toString(StructDeclaration sd)
53-
{
54-
Dsymbol s = search_function(sd, Id.tostring);
55-
FuncDeclaration fd = s ? s.isFuncDeclaration() : null;
56-
if (fd)
57-
{
58-
__gshared TypeFunction tftostring;
59-
if (!tftostring)
60-
{
61-
tftostring = new TypeFunction(ParameterList(), Type.tstring, LINK.d);
62-
tftostring = tftostring.merge().toTypeFunction();
63-
}
64-
fd = fd.overloadExactMatch(tftostring);
65-
}
66-
return fd;
67-
}
68-
6943
enum StructFlags : int
7044
{
7145
none = 0x0,

compiler/src/dmd/semantic3.d

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,30 @@ private struct FuncDeclSem3
16651665
}
16661666
}
16671667

1668+
/***************************************
1669+
* Search sd for a member function of the form:
1670+
* `extern (D) string toString();`
1671+
* Params:
1672+
* sd = struct declaration to search
1673+
* Returns:
1674+
* FuncDeclaration of `toString()` if found, `null` if not
1675+
*/
1676+
FuncDeclaration search_toString(StructDeclaration sd)
1677+
{
1678+
Dsymbol s = search_function(sd, Id.tostring);
1679+
FuncDeclaration fd = s ? s.isFuncDeclaration() : null;
1680+
if (!fd)
1681+
return null;
1682+
1683+
__gshared TypeFunction tftostring;
1684+
if (!tftostring)
1685+
{
1686+
tftostring = new TypeFunction(ParameterList(), Type.tstring, LINK.d);
1687+
tftostring = tftostring.merge().toTypeFunction();
1688+
}
1689+
return fd.overloadExactMatch(tftostring);
1690+
}
1691+
16681692
/**
16691693
* Ensures special members of a struct are fully analysed
16701694
* before the backend emits TypeInfo.

compiler/src/dmd/todt.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import dmd.init;
4040
import dmd.location;
4141
import dmd.mtype;
4242
import dmd.optimize;
43+
import dmd.semantic3 : search_toString;
4344
import dmd.target;
4445
import dmd.tokens;
4546
import dmd.tocsym;

0 commit comments

Comments
 (0)