Skip to content

Commit dc967f1

Browse files
[declaration.d] move getConstInitializer (dlang#21659)
1 parent 665dbe8 commit dc967f1

4 files changed

Lines changed: 36 additions & 34 deletions

File tree

compiler/src/dmd/declaration.d

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import dmd.hdrgen;
3232
import dmd.id;
3333
import dmd.identifier;
3434
import dmd.init;
35-
import dmd.initsem : initializerToExpression, initializerSemantic;
3635
import dmd.intrange;
3736
import dmd.location;
3837
import dmd.mtype;
@@ -41,7 +40,7 @@ import dmd.rootobject;
4140
import dmd.root.filename;
4241
import dmd.target;
4342
import dmd.tokens;
44-
import dmd.typesem : toDsymbol, typeSemantic, size, hasPointers;
43+
import dmd.typesem : toDsymbol, typeSemantic, size;
4544
import dmd.visitor;
4645

4746
version (IN_GCC) {}
@@ -1050,38 +1049,6 @@ extern (C++) class VarDeclaration : Declaration
10501049
return edtor && !(storage_class & STC.nodtor);
10511050
}
10521051

1053-
/*******************************************
1054-
* If variable has a constant expression initializer, get it.
1055-
* Otherwise, return null.
1056-
*/
1057-
extern (D) final Expression getConstInitializer(bool needFullType = true)
1058-
{
1059-
assert(type && _init);
1060-
1061-
// Ungag errors when not speculative
1062-
const oldgag = global.gag;
1063-
if (global.gag)
1064-
{
1065-
Dsymbol sym = isMember();
1066-
if (sym && !sym.isSpeculative())
1067-
global.gag = 0;
1068-
}
1069-
1070-
if (_scope)
1071-
{
1072-
inuse++;
1073-
_init = _init.initializerSemantic(_scope, type, INITinterpret);
1074-
import dmd.semantic2 : lowerStaticAAs;
1075-
lowerStaticAAs(this, _scope);
1076-
_scope = null;
1077-
inuse--;
1078-
}
1079-
1080-
Expression e = _init.initializerToExpression(needFullType ? type : null);
1081-
global.gag = oldgag;
1082-
return e;
1083-
}
1084-
10851052
override final Dsymbol toAlias()
10861053
{
10871054
//printf("VarDeclaration::toAlias('%s', this = %p, aliassym = %p)\n", toChars(), this, aliassym);

compiler/src/dmd/expressionsem.d

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17632,6 +17632,39 @@ bool checkDisabled(Declaration d, Loc loc, Scope* sc, bool isAliasedDeclaration
1763217632
return true;
1763317633
}
1763417634

17635+
17636+
/*******************************************
17637+
* If variable has a constant expression initializer, get it.
17638+
* Otherwise, return null.
17639+
*/
17640+
Expression getConstInitializer(VarDeclaration vd, bool needFullType = true)
17641+
{
17642+
assert(vd.type && vd._init);
17643+
17644+
// Ungag errors when not speculative
17645+
const oldgag = global.gag;
17646+
if (global.gag)
17647+
{
17648+
Dsymbol sym = vd.isMember();
17649+
if (sym && !sym.isSpeculative())
17650+
global.gag = 0;
17651+
}
17652+
17653+
if (vd._scope)
17654+
{
17655+
vd.inuse++;
17656+
vd._init = vd._init.initializerSemantic(vd._scope, vd.type, INITinterpret);
17657+
import dmd.semantic2 : lowerStaticAAs;
17658+
lowerStaticAAs(vd, vd._scope);
17659+
vd._scope = null;
17660+
vd.inuse--;
17661+
}
17662+
17663+
Expression e = vd._init.initializerToExpression(needFullType ? vd.type : null);
17664+
global.gag = oldgag;
17665+
return e;
17666+
}
17667+
1763517668
/*******************************************
1763617669
* Helper function for the expansion of manifest constant.
1763717670
*/

compiler/src/dmd/lambdacomp.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import dmd.dsymbol;
2525
import dmd.dsymbolsem;
2626
import dmd.dtemplate;
2727
import dmd.expression;
28+
import dmd.expressionsem : getConstInitializer;
2829
import dmd.func;
2930
import dmd.hdrgen;
3031
import dmd.mangle;

compiler/src/dmd/mtype.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import dmd.dtemplate;
3030
import dmd.enumsem;
3131
import dmd.errors;
3232
import dmd.expression;
33+
import dmd.expressionsem : getConstInitializer;
3334
import dmd.hdrgen;
3435
import dmd.id;
3536
import dmd.identifier;

0 commit comments

Comments
 (0)