Skip to content

Commit 1675e47

Browse files
committed
Move isLvalue to expressionsem.d
1 parent e0dcc96 commit 1675e47

File tree

9 files changed

+110
-213
lines changed

9 files changed

+110
-213
lines changed

compiler/src/dmd/canthrow.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import dmd.dsymbol;
2323
import dmd.dsymbolsem : include;
2424
import dmd.errorsink;
2525
import dmd.expression;
26-
import dmd.expressionsem : errorSupplementalInferredAttr;
26+
import dmd.expressionsem : errorSupplementalInferredAttr, isLvalue;
2727
import dmd.func;
2828
import dmd.globals;
2929
import dmd.init;

compiler/src/dmd/cxxfrontend.d

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ bool fill(StructDeclaration sd, Loc loc,
291291
return dmd.expressionsem.fill(sd, loc, elements, ctorinit);
292292
}
293293

294+
bool isLvalue(Expression e)
295+
{
296+
import dmd.expressionsem;
297+
return dmd.expressionsem.isLvalue(e);
298+
}
299+
294300
/***********************************************************
295301
* func.d
296302
*/

compiler/src/dmd/dtemplate.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import dmd.dsymbolsem : dsymbolSemantic, aliasSemantic, search, oneMembers;
5757
import dmd.errors;
5858
import dmd.errorsink;
5959
import dmd.expression;
60-
import dmd.expressionsem : resolveLoc, expressionSemantic, resolveProperties, checkValue;
60+
import dmd.expressionsem : resolveLoc, expressionSemantic, resolveProperties, checkValue, isLvalue;
6161
import dmd.func;
6262
import dmd.funcsem : functionSemantic, overloadApply;
6363
import dmd.globals;

compiler/src/dmd/e2ir.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import dmd.dsymbol;
4040
import dmd.dsymbolsem : include, _isZeroInit;
4141
import dmd.dtemplate;
4242
import dmd.expression;
43-
import dmd.expressionsem : fill;
43+
import dmd.expressionsem : fill, isLvalue;
4444
import dmd.func;
4545
import dmd.glue;
4646
import dmd.hdrgen;

compiler/src/dmd/expression.d

Lines changed: 2 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import dmd.aggregate;
2121
import dmd.arraytypes;
2222
import dmd.astenums;
2323
import dmd.ast_node;
24-
import dmd.dcast : implicitConvTo;
24+
import dmd.dcast : implicitConvTo /*toStringExp*/;
2525
import dmd.dclass;
2626
import dmd.declaration;
2727
import dmd.dimport;
@@ -49,7 +49,7 @@ import dmd.root.string;
4949
import dmd.root.utf;
5050
import dmd.target;
5151
import dmd.tokens;
52-
import dmd.typesem : toHeadMutable, size, mutableOf, unSharedOf;
52+
import dmd.typesem : toHeadMutable, size /*getFieldIndex*/;
5353
import dmd.visitor;
5454

5555
enum LOGSEMANTIC = false;
@@ -506,14 +506,6 @@ extern (C++) abstract class Expression : ASTNode
506506
return null;
507507
}
508508

509-
/***************************************
510-
* Return !=0 if expression is an lvalue.
511-
*/
512-
bool isLvalue()
513-
{
514-
return false;
515-
}
516-
517509
/****************************************
518510
* Check that the expression has a valid type.
519511
* If not, generates an error "... has no type".
@@ -1197,11 +1189,6 @@ extern (C++) class IdentifierExp : Expression
11971189
return new IdentifierExp(loc, ident);
11981190
}
11991191

1200-
override final bool isLvalue()
1201-
{
1202-
return !this.rvalue;
1203-
}
1204-
12051192
override void accept(Visitor v)
12061193
{
12071194
v.visit(this);
@@ -1241,11 +1228,6 @@ extern (C++) final class DsymbolExp : Expression
12411228
this.hasOverloads = hasOverloads;
12421229
}
12431230

1244-
override bool isLvalue()
1245-
{
1246-
return !rvalue;
1247-
}
1248-
12491231
override void accept(Visitor v)
12501232
{
12511233
v.visit(this);
@@ -1286,12 +1268,6 @@ extern (C++) class ThisExp : Expression
12861268
return typeof(return)(true);
12871269
}
12881270

1289-
override final bool isLvalue()
1290-
{
1291-
// Class `this` should be an rvalue; struct `this` should be an lvalue.
1292-
return !rvalue && type.toBasetype().ty != Tclass;
1293-
}
1294-
12951271
override void accept(Visitor v)
12961272
{
12971273
v.visit(this);
@@ -1672,14 +1648,6 @@ extern (C++) final class StringExp : Expression
16721648
return typeof(return)(true);
16731649
}
16741650

1675-
override bool isLvalue()
1676-
{
1677-
/* string literal is rvalue in default, but
1678-
* conversion to reference of static array is only allowed.
1679-
*/
1680-
return !rvalue && (type && type.toBasetype().ty == Tsarray);
1681-
}
1682-
16831651
/********************************
16841652
* Convert string contents to a 0 terminated string,
16851653
* allocated by mem.xmalloc().
@@ -2361,11 +2329,6 @@ extern (C++) final class TemplateExp : Expression
23612329
this.fd = fd;
23622330
}
23632331

2364-
override bool isLvalue()
2365-
{
2366-
return fd !is null;
2367-
}
2368-
23692332
override bool checkType()
23702333
{
23712334
error(loc, "%s `%s` has no type", td.kind(), toChars());
@@ -2558,13 +2521,6 @@ extern (C++) final class VarExp : SymbolExp
25582521
return false;
25592522
}
25602523

2561-
override bool isLvalue()
2562-
{
2563-
if (rvalue || var.storage_class & (STC.lazy_ | STC.rvalue | STC.manifest))
2564-
return false;
2565-
return true;
2566-
}
2567-
25682524
override void accept(Visitor v)
25692525
{
25702526
v.visit(this);
@@ -2586,11 +2542,6 @@ extern (C++) final class OverExp : Expression
25862542
type = Type.tvoid;
25872543
}
25882544

2589-
override bool isLvalue()
2590-
{
2591-
return true;
2592-
}
2593-
25942545
override void accept(Visitor v)
25952546
{
25962547
v.visit(this);
@@ -2906,11 +2857,6 @@ extern (C++) class BinAssignExp : BinExp
29062857
super(loc, op, e1, e2);
29072858
}
29082859

2909-
override final bool isLvalue()
2910-
{
2911-
return !rvalue;
2912-
}
2913-
29142860
override void accept(Visitor v)
29152861
{
29162862
v.visit(this);
@@ -3104,16 +3050,6 @@ extern (C++) final class DotVarExp : UnaExp
31043050
this.hasOverloads = hasOverloads;
31053051
}
31063052

3107-
override bool isLvalue()
3108-
{
3109-
if (rvalue)
3110-
return false;
3111-
if (e1.op != EXP.structLiteral)
3112-
return true;
3113-
auto vd = var.isVarDeclaration();
3114-
return !(vd && vd.isField());
3115-
}
3116-
31173053
override void accept(Visitor v)
31183054
{
31193055
v.visit(this);
@@ -3328,24 +3264,6 @@ extern (C++) final class CallExp : UnaExp
33283264
return new CallExp(loc, e1.syntaxCopy(), arraySyntaxCopy(arguments), names ? names.copy() : null);
33293265
}
33303266

3331-
override bool isLvalue()
3332-
{
3333-
if (rvalue)
3334-
return false;
3335-
Type tb = e1.type.toBasetype();
3336-
if (tb.ty == Tdelegate || tb.ty == Tpointer)
3337-
tb = tb.nextOf();
3338-
auto tf = tb.isTypeFunction();
3339-
if (tf && tf.isRef)
3340-
{
3341-
if (auto dve = e1.isDotVarExp())
3342-
if (dve.var.isCtorDeclaration())
3343-
return false;
3344-
return true; // function returns a reference
3345-
}
3346-
return false;
3347-
}
3348-
33493267
override void accept(Visitor v)
33503268
{
33513269
v.visit(this);
@@ -3447,11 +3365,6 @@ extern (C++) final class PtrExp : UnaExp
34473365
type = t;
34483366
}
34493367

3450-
override bool isLvalue()
3451-
{
3452-
return !rvalue;
3453-
}
3454-
34553368
override void accept(Visitor v)
34563369
{
34573370
v.visit(this);
@@ -3576,16 +3489,6 @@ extern (C++) final class CastExp : UnaExp
35763489
return to ? new CastExp(loc, e1.syntaxCopy(), to.syntaxCopy()) : new CastExp(loc, e1.syntaxCopy(), mod);
35773490
}
35783491

3579-
override bool isLvalue()
3580-
{
3581-
//printf("e1.type = %s, to.type = %s\n", e1.type.toChars(), to.toChars());
3582-
if (rvalue || !e1.isLvalue())
3583-
return false;
3584-
return (to.ty == Tsarray && (e1.type.ty == Tvector || e1.type.ty == Tsarray)) ||
3585-
(to.ty == Taarray && e1.type.ty == Taarray) ||
3586-
e1.type.mutableOf.unSharedOf().equals(to.mutableOf().unSharedOf());
3587-
}
3588-
35893492
override void accept(Visitor v)
35903493
{
35913494
v.visit(this);
@@ -3635,11 +3538,6 @@ extern (C++) final class VectorArrayExp : UnaExp
36353538
super(loc, EXP.vectorArray, e1);
36363539
}
36373540

3638-
override bool isLvalue()
3639-
{
3640-
return !rvalue && e1.isLvalue();
3641-
}
3642-
36433541
override void accept(Visitor v)
36443542
{
36453543
v.visit(this);
@@ -3689,14 +3587,6 @@ extern (C++) final class SliceExp : UnaExp
36893587
return se;
36903588
}
36913589

3692-
override bool isLvalue()
3693-
{
3694-
/* slice expression is rvalue in default, but
3695-
* conversion to reference of static array is only allowed.
3696-
*/
3697-
return !rvalue && (type && type.toBasetype().ty == Tsarray);
3698-
}
3699-
37003590
override Optional!bool toBool()
37013591
{
37023592
return e1.toBool();
@@ -3757,15 +3647,6 @@ extern (C++) final class ArrayExp : UnaExp
37573647
return ae;
37583648
}
37593649

3760-
override bool isLvalue()
3761-
{
3762-
if (rvalue)
3763-
return false;
3764-
if (type && type.toBasetype().ty == Tvoid)
3765-
return false;
3766-
return true;
3767-
}
3768-
37693650
override void accept(Visitor v)
37703651
{
37713652
v.visit(this);
@@ -3817,11 +3698,6 @@ extern (C++) final class CommaExp : BinExp
38173698
originalExp = oe;
38183699
}
38193700

3820-
override bool isLvalue()
3821-
{
3822-
return !rvalue && e2.isLvalue();
3823-
}
3824-
38253701
override Optional!bool toBool()
38263702
{
38273703
return e2.toBool();
@@ -3892,11 +3768,6 @@ extern (C++) final class DelegatePtrExp : UnaExp
38923768
super(loc, EXP.delegatePointer, e1);
38933769
}
38943770

3895-
override bool isLvalue()
3896-
{
3897-
return !rvalue && e1.isLvalue();
3898-
}
3899-
39003771
override void accept(Visitor v)
39013772
{
39023773
v.visit(this);
@@ -3915,11 +3786,6 @@ extern (C++) final class DelegateFuncptrExp : UnaExp
39153786
super(loc, EXP.delegateFunctionPointer, e1);
39163787
}
39173788

3918-
override bool isLvalue()
3919-
{
3920-
return !rvalue && e1.isLvalue();
3921-
}
3922-
39233789
override void accept(Visitor v)
39243790
{
39253791
v.visit(this);
@@ -3955,19 +3821,6 @@ extern (C++) final class IndexExp : BinExp
39553821
return ie;
39563822
}
39573823

3958-
override bool isLvalue()
3959-
{
3960-
if (rvalue)
3961-
return false;
3962-
auto t1b = e1.type.toBasetype();
3963-
if (t1b.isTypeAArray() || t1b.isTypeSArray() ||
3964-
(e1.isIndexExp() && t1b != t1b.isTypeDArray()))
3965-
{
3966-
return e1.isLvalue();
3967-
}
3968-
return true;
3969-
}
3970-
39713824
override void accept(Visitor v)
39723825
{
39733826
v.visit(this);
@@ -4036,17 +3889,6 @@ extern (C++) class AssignExp : BinExp
40363889
super(loc, tok, e1, e2);
40373890
}
40383891

4039-
override final bool isLvalue()
4040-
{
4041-
// Array-op 'x[] = y[]' should make an rvalue.
4042-
// Setting array length 'x.length = v' should make an rvalue.
4043-
if (e1.op == EXP.slice || e1.op == EXP.arrayLength)
4044-
{
4045-
return false;
4046-
}
4047-
return !rvalue;
4048-
}
4049-
40503892
override void accept(Visitor v)
40513893
{
40523894
v.visit(this);
@@ -4770,11 +4612,6 @@ extern (C++) final class CondExp : BinExp
47704612
return new CondExp(loc, econd.syntaxCopy(), e1.syntaxCopy(), e2.syntaxCopy());
47714613
}
47724614

4773-
override bool isLvalue()
4774-
{
4775-
return !rvalue && e1.isLvalue() && e2.isLvalue();
4776-
}
4777-
47784615
override void accept(Visitor v)
47794616
{
47804617
v.visit(this);

0 commit comments

Comments
 (0)