aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/dmd
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2020-06-08 21:57:59 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2020-06-08 22:02:18 +0200
commit49a09af117be32adf230efd2c52a41f810b9ee04 (patch)
treeb80a467ae0cf80347884d81b45332229fe9a236a /gcc/d/dmd
parent8cd239614e43c9dcc0838845aec504e5eb938dbd (diff)
downloadgcc-49a09af117be32adf230efd2c52a41f810b9ee04.zip
gcc-49a09af117be32adf230efd2c52a41f810b9ee04.tar.gz
gcc-49a09af117be32adf230efd2c52a41f810b9ee04.tar.bz2
d: Merge upstream dmd 955b8b36f.
Merges AndAndExp and OrOrExp into a LogicalExp AST node. gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 955b8b36f. * expr.cc (ExprVisitor::visit (AndAndExp *)): Rename type to ... (ExprVisitor::visit (LogicalExp *)): ... this. Handle both 'and if' and 'or if' expression nodes. (ExprVisitor::visit (OrOrExp *)): Remove.
Diffstat (limited to 'gcc/d/dmd')
-rw-r--r--gcc/d/dmd/MERGE2
-rw-r--r--gcc/d/dmd/dinterpret.c63
-rw-r--r--gcc/d/dmd/expression.c28
-rw-r--r--gcc/d/dmd/expression.h12
-rw-r--r--gcc/d/dmd/expressionsem.c85
-rw-r--r--gcc/d/dmd/opover.c4
-rw-r--r--gcc/d/dmd/optimize.c60
-rw-r--r--gcc/d/dmd/parse.c4
-rw-r--r--gcc/d/dmd/sideeffect.c9
-rw-r--r--gcc/d/dmd/staticcond.c28
-rw-r--r--gcc/d/dmd/visitor.h6
11 files changed, 49 insertions, 252 deletions
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index f71d20c..e2ebd27 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-73d8e2fecb9e73422464b4cbf71f2b2967c9a75d
+955b8b36f8bbacc59745b44cdf48ef1ddeb01bcd
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/dinterpret.c b/gcc/d/dmd/dinterpret.c
index 6b4a2b7..ada1d8b 100644
--- a/gcc/d/dmd/dinterpret.c
+++ b/gcc/d/dmd/dinterpret.c
@@ -4465,7 +4465,7 @@ public:
result = pue->exp();
}
- void visit(AndAndExp *e)
+ void visit(LogicalExp *e)
{
// Check for an insidePointer expression, evaluate it if so
interpretFourPointerRelation(pue, e);
@@ -4477,9 +4477,10 @@ public:
return;
int res;
- if (result->isBool(false))
- res = 0;
- else if (isTrueBool(result))
+ const bool andand = e->op == TOKandand;
+ if (andand ? result->isBool(false) : isTrueBool(result))
+ res = !andand;
+ else if (andand ? isTrueBool(result) : result->isBool(false))
{
UnionExp ue2;
result = interpret(&ue2, e->e2, istate);
@@ -4497,64 +4498,14 @@ public:
res = 1;
else
{
- result->error("%s does not evaluate to a boolean", result->toChars());
+ result->error("`%s` does not evaluate to a boolean", result->toChars());
result = CTFEExp::cantexp;
return;
}
}
else
{
- result->error("%s cannot be interpreted as a boolean", result->toChars());
- result = CTFEExp::cantexp;
- return;
- }
- if (goal != ctfeNeedNothing)
- {
- new(pue) IntegerExp(e->loc, res, e->type);
- result = pue->exp();
- }
- }
-
- void visit(OrOrExp *e)
- {
- // Check for an insidePointer expression, evaluate it if so
- interpretFourPointerRelation(pue, e);
- if (result)
- return;
-
- result = interpret(e->e1, istate);
- if (exceptionOrCant(result))
- return;
-
- int res;
- if (isTrueBool(result))
- res = 1;
- else if (result->isBool(false))
- {
- UnionExp ue2;
- result = interpret(&ue2, e->e2, istate);
- if (exceptionOrCant(result))
- return;
- if (result->op == TOKvoidexp)
- {
- assert(e->type->ty == Tvoid);
- result = NULL;
- return;
- }
- if (result->isBool(false))
- res = 0;
- else if (isTrueBool(result))
- res = 1;
- else
- {
- result->error("%s cannot be interpreted as a boolean", result->toChars());
- result = CTFEExp::cantexp;
- return;
- }
- }
- else
- {
- result->error("%s cannot be interpreted as a boolean", result->toChars());
+ result->error("`%s` cannot be interpreted as a boolean", result->toChars());
result = CTFEExp::cantexp;
return;
}
diff --git a/gcc/d/dmd/expression.c b/gcc/d/dmd/expression.c
index d150817..0b21fc9 100644
--- a/gcc/d/dmd/expression.c
+++ b/gcc/d/dmd/expression.c
@@ -1895,7 +1895,7 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
// edtor => (__gate || edtor)
assert(tmp->edtor);
Expression *e = tmp->edtor;
- e = new OrOrExp(e->loc, new VarExp(e->loc, gate), e);
+ e = new LogicalExp(e->loc, TOKoror, new VarExp(e->loc, gate), e);
tmp->edtor = semantic(e, sc);
//printf("edtor: %s\n", tmp->edtor->toChars());
}
@@ -6457,28 +6457,12 @@ XorExp::XorExp(Loc loc, Expression *e1, Expression *e2)
/************************************************************/
-OrOrExp::OrOrExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKoror, sizeof(OrOrExp), e1, e2)
+LogicalExp::LogicalExp(Loc loc, TOK op, Expression *e1, Expression *e2)
+ : BinExp(loc, op, sizeof(LogicalExp), e1, e2)
{
}
-Expression *OrOrExp::toBoolean(Scope *sc)
-{
- Expression *ex2 = e2->toBoolean(sc);
- if (ex2->op == TOKerror)
- return ex2;
- e2 = ex2;
- return this;
-}
-
-/************************************************************/
-
-AndAndExp::AndAndExp(Loc loc, Expression *e1, Expression *e2)
- : BinExp(loc, TOKandand, sizeof(AndAndExp), e1, e2)
-{
-}
-
-Expression *AndAndExp::toBoolean(Scope *sc)
+Expression *LogicalExp::toBoolean(Scope *sc)
{
Expression *ex2 = e2->toBoolean(sc);
if (ex2->op == TOKerror)
@@ -6591,9 +6575,9 @@ void CondExp::hookDtors(Scope *sc)
//printf("\t++v = %s, v->edtor = %s\n", v->toChars(), v->edtor->toChars());
Expression *ve = new VarExp(vcond->loc, vcond);
if (isThen)
- v->edtor = new AndAndExp(v->edtor->loc, ve, v->edtor);
+ v->edtor = new LogicalExp(v->edtor->loc, TOKandand, ve, v->edtor);
else
- v->edtor = new OrOrExp(v->edtor->loc, ve, v->edtor);
+ v->edtor = new LogicalExp(v->edtor->loc, TOKoror, ve, v->edtor);
v->edtor = semantic(v->edtor, sc);
//printf("\t--v = %s, v->edtor = %s\n", v->toChars(), v->edtor->toChars());
}
diff --git a/gcc/d/dmd/expression.h b/gcc/d/dmd/expression.h
index f6ac7c5..e353fdc9 100644
--- a/gcc/d/dmd/expression.h
+++ b/gcc/d/dmd/expression.h
@@ -1350,18 +1350,10 @@ public:
void accept(Visitor *v) { v->visit(this); }
};
-class OrOrExp : public BinExp
+class LogicalExp : public BinExp
{
public:
- OrOrExp(Loc loc, Expression *e1, Expression *e2);
- Expression *toBoolean(Scope *sc);
- void accept(Visitor *v) { v->visit(this); }
-};
-
-class AndAndExp : public BinExp
-{
-public:
- AndAndExp(Loc loc, Expression *e1, Expression *e2);
+ LogicalExp(Loc loc, TOK op, Expression *e1, Expression *e2);
Expression *toBoolean(Scope *sc);
void accept(Visitor *v) { v->visit(this); }
};
diff --git a/gcc/d/dmd/expressionsem.c b/gcc/d/dmd/expressionsem.c
index 412d416..e3a5cb3 100644
--- a/gcc/d/dmd/expressionsem.c
+++ b/gcc/d/dmd/expressionsem.c
@@ -7445,7 +7445,7 @@ public:
result = exp;
}
- void visit(OrOrExp *exp)
+ void visit(LogicalExp *exp)
{
if (exp->type)
{
@@ -7455,7 +7455,6 @@ public:
setNoderefOperands(exp);
- // same as for AndAnd
Expression *e1x = semantic(exp->e1, sc);
// for static alias this: https://issues.dlang.org/show_bug.cgi?id=17684
@@ -7471,87 +7470,9 @@ public:
/* If in static if, don't evaluate e2 if we don't have to.
*/
e1x = e1x->optimize(WANTvalue);
- if (e1x->isBool(true))
+ if (e1x->isBool(exp->op == TOKoror))
{
- result = new IntegerExp(exp->loc, 1, Type::tbool);
- return;
- }
- }
-
- Expression *e2x = semantic(exp->e2, sc);
- sc->mergeCallSuper(exp->loc, cs1);
-
- // for static alias this: https://issues.dlang.org/show_bug.cgi?id=17684
- if (e2x->op == TOKtype)
- e2x = resolveAliasThis(sc, e2x);
-
- e2x = resolveProperties(sc, e2x);
-
- bool f1 = checkNonAssignmentArrayOp(e1x);
- bool f2 = checkNonAssignmentArrayOp(e2x);
- if (f1 || f2)
- return setError();
-
- // Unless the right operand is 'void', the expression is converted to 'bool'.
- if (e2x->type->ty != Tvoid)
- e2x = e2x->toBoolean(sc);
-
- if (e2x->op == TOKtype || e2x->op == TOKscope)
- {
- exp->error("%s is not an expression", exp->e2->toChars());
- return setError();
- }
- if (e1x->op == TOKerror)
- {
- result = e1x;
- return;
- }
- if (e2x->op == TOKerror)
- {
- result = e2x;
- return;
- }
-
- // The result type is 'bool', unless the right operand has type 'void'.
- if (e2x->type->ty == Tvoid)
- exp->type = Type::tvoid;
- else
- exp->type = Type::tbool;
-
- exp->e1 = e1x;
- exp->e2 = e2x;
- result = exp;
- }
-
- void visit(AndAndExp *exp)
- {
- if (exp->type)
- {
- result = exp;
- return;
- }
-
- setNoderefOperands(exp);
-
- // same as for OrOr
- Expression *e1x = semantic(exp->e1, sc);
-
- // for static alias this: https://issues.dlang.org/show_bug.cgi?id=17684
- if (e1x->op == TOKtype)
- e1x = resolveAliasThis(sc, e1x);
-
- e1x = resolveProperties(sc, e1x);
- e1x = e1x->toBoolean(sc);
- unsigned cs1 = sc->callSuper;
-
- if (sc->flags & SCOPEcondition)
- {
- /* If in static if, don't evaluate e2 if we don't have to.
- */
- e1x = e1x->optimize(WANTvalue);
- if (e1x->isBool(false))
- {
- result = new IntegerExp(exp->loc, 0, Type::tbool);
+ result = new IntegerExp(exp->loc, exp->op == TOKoror, Type::tbool);
return;
}
}
diff --git a/gcc/d/dmd/opover.c b/gcc/d/dmd/opover.c
index 847cee9..66a0d23 100644
--- a/gcc/d/dmd/opover.c
+++ b/gcc/d/dmd/opover.c
@@ -1106,9 +1106,9 @@ Expression *op_overload(Expression *e, Scope *sc)
if (!result)
result = eeq;
else if (e->op == TOKequal)
- result = new AndAndExp(e->loc, result, eeq);
+ result = new LogicalExp(e->loc, TOKandand, result, eeq);
else
- result = new OrOrExp(e->loc, result, eeq);
+ result = new LogicalExp(e->loc, TOKoror, result, eeq);
}
assert(result);
}
diff --git a/gcc/d/dmd/optimize.c b/gcc/d/dmd/optimize.c
index 82f3aee..e907229 100644
--- a/gcc/d/dmd/optimize.c
+++ b/gcc/d/dmd/optimize.c
@@ -1095,65 +1095,23 @@ Expression *Expression_optimize(Expression *e, int result, bool keepLvalue)
//printf("-SliceExp::optimize() %s\n", ret->toChars());
}
- void visit(AndAndExp *e)
+ void visit(LogicalExp *e)
{
- //printf("AndAndExp::optimize(%d) %s\n", result, e->toChars());
+ //printf("LogicalExp::optimize(%d) %s\n", result, e->toChars());
if (expOptimize(e->e1, WANTvalue))
return;
-
- if (e->e1->isBool(false))
- {
- // Replace with (e1, false)
- ret = new IntegerExp(e->loc, 0, Type::tbool);
- ret = Expression::combine(e->e1, ret);
- if (e->type->toBasetype()->ty == Tvoid)
- {
- ret = new CastExp(e->loc, ret, Type::tvoid);
- ret->type = e->type;
- }
- return;
- }
-
- if (expOptimize(e->e2, WANTvalue))
- return;
-
- if (e->e1->isConst())
- {
- if (e->e2->isConst())
- {
- bool n1 = e->e1->isBool(true);
- bool n2 = e->e2->isBool(true);
- ret = new IntegerExp(e->loc, n1 && n2, e->type);
- }
- else if (e->e1->isBool(true))
- {
- if (e->type->toBasetype()->ty == Tvoid)
- ret = e->e2;
- else
- {
- ret = new CastExp(e->loc, e->e2, e->type);
- ret->type = e->type;
- }
- }
- }
- }
-
- void visit(OrOrExp *e)
- {
- //printf("OrOrExp::optimize(%d) %s\n", result, e->toChars());
- if (expOptimize(e->e1, WANTvalue))
- return;
-
- if (e->e1->isBool(true))
+ const bool oror = e->op == TOKoror;
+ if (e->e1->isBool(oror))
{
- // Replace with (e1, true)
- ret = new IntegerExp(e->loc, 1, Type::tbool);
+ // Replace with (e1, oror)
+ ret = new IntegerExp(e->loc, oror, Type::tbool);
ret = Expression::combine(e->e1, ret);
if (e->type->toBasetype()->ty == Tvoid)
{
ret = new CastExp(e->loc, ret, Type::tvoid);
ret->type = e->type;
}
+ ret = ret->optimize(result);
return;
}
@@ -1166,9 +1124,9 @@ Expression *Expression_optimize(Expression *e, int result, bool keepLvalue)
{
bool n1 = e->e1->isBool(true);
bool n2 = e->e2->isBool(true);
- ret = new IntegerExp(e->loc, n1 || n2, e->type);
+ ret = new IntegerExp(e->loc, oror ? (n1 || n2) : (n1 && n2), e->type);
}
- else if (e->e1->isBool(false))
+ else if (e->e1->isBool(!oror))
{
if (e->type->toBasetype()->ty == Tvoid)
ret = e->e2;
diff --git a/gcc/d/dmd/parse.c b/gcc/d/dmd/parse.c
index 79acab7..4aec7a4 100644
--- a/gcc/d/dmd/parse.c
+++ b/gcc/d/dmd/parse.c
@@ -7773,7 +7773,7 @@ Expression *Parser::parseAndAndExp()
{
nextToken();
e2 = parseOrExp();
- e = new AndAndExp(loc, e, e2);
+ e = new LogicalExp(loc, TOKandand, e, e2);
}
return e;
}
@@ -7789,7 +7789,7 @@ Expression *Parser::parseOrOrExp()
{
nextToken();
e2 = parseAndAndExp();
- e = new OrOrExp(loc, e, e2);
+ e = new LogicalExp(loc, TOKoror, e, e2);
}
return e;
}
diff --git a/gcc/d/dmd/sideeffect.c b/gcc/d/dmd/sideeffect.c
index c6448ae..efab276 100644
--- a/gcc/d/dmd/sideeffect.c
+++ b/gcc/d/dmd/sideeffect.c
@@ -301,15 +301,10 @@ bool discardValue(Expression *e)
return true;
case TOKandand:
- {
- AndAndExp *aae = (AndAndExp *)e;
- return discardValue(aae->e2);
- }
-
case TOKoror:
{
- OrOrExp *ooe = (OrOrExp *)e;
- return discardValue(ooe->e2);
+ LogicalExp *aae = (LogicalExp *)e;
+ return discardValue(aae->e2);
}
case TOKquestion:
diff --git a/gcc/d/dmd/staticcond.c b/gcc/d/dmd/staticcond.c
index 72c11a9..48a60d3 100644
--- a/gcc/d/dmd/staticcond.c
+++ b/gcc/d/dmd/staticcond.c
@@ -28,25 +28,23 @@ Expression *semantic(Expression *e, Scope *sc);
bool evalStaticCondition(Scope *sc, Expression *exp, Expression *e, bool &errors)
{
- if (e->op == TOKandand)
+ if (e->op == TOKandand || e->op == TOKoror)
{
- AndAndExp *aae = (AndAndExp *)e;
+ LogicalExp *aae = (LogicalExp *)e;
bool result = evalStaticCondition(sc, exp, aae->e1, errors);
- if (errors || !result)
- return false;
- result = evalStaticCondition(sc, exp, aae->e2, errors);
- return !errors && result;
- }
-
- if (e->op == TOKoror)
- {
- OrOrExp *ooe = (OrOrExp *)e;
- bool result = evalStaticCondition(sc, exp, ooe->e1, errors);
if (errors)
return false;
- if (result)
- return true;
- result = evalStaticCondition(sc, exp, ooe->e2, errors);
+ if (e->op == TOKandand)
+ {
+ if (!result)
+ return false;
+ }
+ else
+ {
+ if (result)
+ return true;
+ }
+ result = evalStaticCondition(sc, exp, aae->e2, errors);
return !errors && result;
}
diff --git a/gcc/d/dmd/visitor.h b/gcc/d/dmd/visitor.h
index dafde3bd..8093c94 100644
--- a/gcc/d/dmd/visitor.h
+++ b/gcc/d/dmd/visitor.h
@@ -269,8 +269,7 @@ class UshrExp;
class AndExp;
class OrExp;
class XorExp;
-class OrOrExp;
-class AndAndExp;
+class LogicalExp;
class CmpExp;
class InExp;
class RemoveExp;
@@ -563,8 +562,7 @@ public:
virtual void visit(AndExp *e) { visit((BinExp *)e); }
virtual void visit(OrExp *e) { visit((BinExp *)e); }
virtual void visit(XorExp *e) { visit((BinExp *)e); }
- virtual void visit(OrOrExp *e) { visit((BinExp *)e); }
- virtual void visit(AndAndExp *e) { visit((BinExp *)e); }
+ virtual void visit(LogicalExp *e) { visit((BinExp *)e); }
virtual void visit(CmpExp *e) { visit((BinExp *)e); }
virtual void visit(InExp *e) { visit((BinExp *)e); }
virtual void visit(RemoveExp *e) { visit((BinExp *)e); }