Skip to content

Commit b90baee

Browse files
authored
use default args instead of multiple functions (#21677)
1 parent dc967f1 commit b90baee

1 file changed

Lines changed: 19 additions & 25 deletions

File tree

compiler/src/dmd/expressionsem.d

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/***
22
* Semantic analysis of expressions.
33
*
44
* Specification: ($LINK2 https://dlang.org/spec/expression.html, Expressions)
@@ -11507,7 +11507,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
1150711507
{
1150811508

1150911509
// Ensure e1 is a modifiable lvalue
11510-
auto ale1x = ale.e1.modifiableLvalueImpl(sc, exp.e1);
11510+
auto ale1x = ale.e1.modifiableLvalue(sc, exp.e1);
1151111511
if (ale1x.op == EXP.error)
1151211512
return setResult(ale1x);
1151311513
ale.e1 = ale1x;
@@ -11586,7 +11586,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
1158611586
se = cast(SliceExp)se.e1;
1158711587
if (se.e1.op == EXP.question && se.e1.type.toBasetype().ty == Tsarray)
1158811588
{
11589-
se.e1 = se.e1.modifiableLvalueImpl(sc, exp.e1);
11589+
se.e1 = se.e1.modifiableLvalue(sc, exp.e1);
1159011590
if (se.e1.op == EXP.error)
1159111591
return setResult(se.e1);
1159211592
}
@@ -11610,7 +11610,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
1161011610
// Try to do a decent error message with the expression
1161111611
// before it gets constant folded
1161211612
if (exp.op == EXP.assign)
11613-
e1x = e1x.modifiableLvalueImpl(sc, e1old);
11613+
e1x = e1x.modifiableLvalue(sc, e1old);
1161411614

1161511615
e1x = e1x.optimize(WANTvalue, /*keepLvalue*/ true);
1161611616

@@ -15976,17 +15976,14 @@ Expression addDtorHook(Expression e, Scope* sc)
1597615976
* _this = expression to convert
1597715977
* sc = scope
1597815978
* action = for error messages, what the lvalue is needed for (e.g. take address of for `&x`, modify for `x++`)
15979+
* eorig = original un-lowered expression for error messages, in case of recursive calls; null means use `_this`
1597915980
* Returns: converted expression, or `ErrorExp` on error
1598015981
*/
15981-
Expression toLvalue(Expression _this, Scope* sc, const(char)* action)
15982-
{
15983-
return toLvalueImpl(_this, sc, action, _this);
15984-
}
15985-
15986-
// eorig = original un-lowered expression for error messages, in case of recursive calls
15987-
private Expression toLvalueImpl(Expression _this, Scope* sc, const(char)* action, Expression eorig)
15982+
Expression toLvalue(Expression _this, Scope* sc, const(char)* action, Expression eorig = null)
1598815983
{
15989-
//printf("toLvalueImpl() %s\n", _this.toChars());
15984+
//printf("toLvalue() %s\n", _this.toChars());
15985+
if (!eorig)
15986+
eorig = _this;
1599015987
if (!action)
1599115988
action = "create lvalue of";
1599215989

@@ -16090,7 +16087,7 @@ private Expression toLvalueImpl(Expression _this, Scope* sc, const(char)* action
1609016087
/* C11 6.5.2.3-3: A postfix expression followed by the '.' or '->' operator
1609116088
* is an lvalue if the first expression is an lvalue.
1609216089
*/
16093-
e1 = e1.toLvalueImpl(sc, action, eorig);
16090+
e1 = e1.toLvalue(sc, action, eorig);
1609416091
if (e1.isErrorExp())
1609516092
return e1;
1609616093
}
@@ -16153,7 +16150,7 @@ private Expression toLvalueImpl(Expression _this, Scope* sc, const(char)* action
1615316150

1615416151
Expression visitVectorArray(VectorArrayExp _this)
1615516152
{
16156-
_this.e1 = _this.e1.toLvalueImpl(sc, action, eorig);
16153+
_this.e1 = _this.e1.toLvalue(sc, action, eorig);
1615716154
return _this;
1615816155
}
1615916156

@@ -16178,13 +16175,13 @@ private Expression toLvalueImpl(Expression _this, Scope* sc, const(char)* action
1617816175

1617916176
Expression visitDelegatePointer(DelegatePtrExp _this)
1618016177
{
16181-
_this.e1 = _this.e1.toLvalueImpl(sc, action, eorig);
16178+
_this.e1 = _this.e1.toLvalue(sc, action, eorig);
1618216179
return _this;
1618316180
}
1618416181

1618516182
Expression visitDelegateFuncptr(DelegateFuncptrExp _this)
1618616183
{
16187-
_this.e1 = _this.e1.toLvalueImpl(sc, action, eorig);
16184+
_this.e1 = _this.e1.toLvalue(sc, action, eorig);
1618816185
return _this;
1618916186
}
1619016187

@@ -16415,17 +16412,14 @@ Modifiable checkModifiable(Expression exp, Scope* sc, ModifyFlags flag = ModifyF
1641516412
* Params:
1641616413
* _this = Expression to convert
1641716414
* sc = scope
16415+
* eorig = original / un-lowered expression to print in error messages, if null default to `_this`
1641816416
* Returns: `_this` converted to an lvalue, or an `ErrorExp`
1641916417
*/
16420-
Expression modifiableLvalue(Expression _this, Scope* sc)
16418+
Expression modifiableLvalue(Expression _this, Scope* sc, Expression eorig = null)
1642116419
{
16422-
return modifiableLvalueImpl(_this, sc, _this);
16423-
}
16420+
if (!eorig)
16421+
eorig = _this;
1642416422

16425-
// eorig = original / un-lowered expression to print in error messages
16426-
private Expression modifiableLvalueImpl(Expression _this, Scope* sc, Expression eorig)
16427-
{
16428-
assert(eorig);
1642916423
Expression visit(Expression exp)
1643016424
{
1643116425
//printf("Expression::modifiableLvalue() %s, type = %s\n", exp.toChars(), exp.type.toChars());
@@ -16464,7 +16458,7 @@ private Expression modifiableLvalueImpl(Expression _this, Scope* sc, Expression
1646416458
return ErrorExp.get();
1646516459
}
1646616460
}
16467-
return exp.toLvalueImpl(sc, "modify", eorig);
16461+
return exp.toLvalue(sc, "modify", eorig);
1646816462
}
1646916463

1647016464
Expression visitString(StringExp exp)
@@ -16513,7 +16507,7 @@ private Expression modifiableLvalueImpl(Expression _this, Scope* sc, Expression
1651316507

1651416508
Expression visitComma(CommaExp exp)
1651516509
{
16516-
exp.e2 = exp.e2.modifiableLvalueImpl(sc, eorig);
16510+
exp.e2 = exp.e2.modifiableLvalue(sc, eorig);
1651716511
return exp;
1651816512
}
1651916513

0 commit comments

Comments
 (0)