From ada7e9ce9b89158431547d10b2659168976ab95c Mon Sep 17 00:00:00 2001 From: k-hara Date: Sat, 23 Aug 2014 03:50:30 +0900 Subject: [PATCH] Add VectorExp handling in CTFE interpreter to fix compilable/test8543.d --- src/constfold.c | 7 +++++++ src/ctfeexpr.c | 3 +++ src/interpret.c | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/constfold.c b/src/constfold.c index f8ffda463dd1..c74ccebdfca0 100644 --- a/src/constfold.c +++ b/src/constfold.c @@ -1175,6 +1175,13 @@ UnionExp Cast(Type *type, Type *to, Expression *e1) return ue; } + if (e1->op == TOKvector && ((TypeVector *)e1->type)->basetype->equals(type) && type->equals(to)) + { + Expression *ex = ((VectorExp *)e1)->e1; + memcpy(&ue, ex, ex->size); + return ue; + } + if (e1->type->implicitConvTo(to) >= MATCHconst || to->implicitConvTo(e1->type) >= MATCHconst) { diff --git a/src/ctfeexpr.c b/src/ctfeexpr.c index 1a1cb90a1ce2..f34e9966f6c3 100644 --- a/src/ctfeexpr.c +++ b/src/ctfeexpr.c @@ -446,6 +446,9 @@ Expression *resolveSlice(Expression *e) */ uinteger_t resolveArrayLength(Expression *e) { + if (e->op == TOKvector) + e = ((VectorExp *)e)->e1; + if (e->op == TOKnull) return 0; if (e->op == TOKslice) diff --git a/src/interpret.c b/src/interpret.c index 3051fb441b0d..11397f1909ab 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -3787,6 +3787,8 @@ class Interpreter : public Visitor /* Assignment to variable of the form: * v = newval */ + if (e1->op == TOKvector) + e1 = ((VectorExp *)e1)->e1; if (e1->op == TOKvar) { VarExp *ve = (VarExp *)e1; @@ -4009,6 +4011,7 @@ class Interpreter : public Visitor return false; } if (oldval->op != TOKarrayliteral && + oldval->op != TOKvector && oldval->op != TOKstring && oldval->op != TOKslice) { @@ -4134,6 +4137,8 @@ class Interpreter : public Visitor } if (aggregate->op == TOKarrayliteral) existingAE = (ArrayLiteralExp *)aggregate; + else if (aggregate->op == TOKvector) + existingAE = (ArrayLiteralExp *)((VectorExp *)aggregate)->e1; else if (aggregate->op == TOKstring) existingSE = (StringExp *)aggregate; else @@ -6172,7 +6177,7 @@ class Interpreter : public Visitor if (result->op == TOKstructliteral) return; if ((e->type->ty == Tsarray || goal == ctfeNeedLvalue) && ( - result->op == TOKarrayliteral || + result->op == TOKarrayliteral || result->op == TOKvector || result->op == TOKassocarrayliteral || result->op == TOKstring || result->op == TOKclassreference || result->op == TOKslice)) {