From 72c9d90ce174c14f9963ac5d8471d9d3bce53964 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 28 Sep 2008 20:06:07 +0100 Subject: [PATCH] Special unchecked nulls for d A null in D source can be cast to a non-null type without error. This is necessary to be able to compile D code. --- dmd2/cast.c | 13 +++++++++---- dmd2/expression.c | 1 + dmd2/expression.h | 1 + dmd2/parse.c | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dmd2/cast.c b/dmd2/cast.c index 8569419..bb9b3c8 100644 --- a/dmd2/cast.c +++ b/dmd2/cast.c @@ -389,13 +389,18 @@ MATCH NullExp::implicitConvTo(Type *t) t->ty == Taarray || t->ty == Tmaybe || t->ty == Tdelegate) return committed ? MATCHconvert : MATCHexact; + if (dUnchecked && (t->ty == Tpointer || t->ty == Tclass)) + return committed ? MATCHconvert : MATCHexact; } - /* Null can only be implicitly converted to a maybe type */ - if (t->ty != Tmaybe) - return MATCHnomatch; + if (!dUnchecked) + { + /* In Delight, null can only be implicitly converted to a maybe type */ + if (t->ty != Tmaybe) + return MATCHnomatch; - t = t->nextOf(); + t = t->nextOf(); + } return Expression::implicitConvTo(t); } diff --git a/dmd2/expression.c b/dmd2/expression.c index 5cd0d2b..327b0b2 100644 --- a/dmd2/expression.c +++ b/dmd2/expression.c @@ -2311,6 +2311,7 @@ NullExp::NullExp(Loc loc) : Expression(loc, TOKnull, sizeof(NullExp)) { committed = 0; + dUnchecked = false; } Expression *NullExp::semantic(Scope *sc) diff --git a/dmd2/expression.h b/dmd2/expression.h index 6f0143c..c150c50 100644 --- a/dmd2/expression.h +++ b/dmd2/expression.h @@ -301,6 +301,7 @@ struct SuperExp : ThisExp struct NullExp : Expression { unsigned char committed; // !=0 if type is committed + bool dUnchecked; // can be implicitly cast to a non-null type (for D) NullExp(Loc loc); Expression *semantic(Scope *sc); diff --git a/dmd2/parse.c b/dmd2/parse.c index bd6a9a9..e63a597 100644 --- a/dmd2/parse.c +++ b/dmd2/parse.c @@ -4659,6 +4659,7 @@ Expression *Parser::parsePrimaryExp() case TOKnull: e = new NullExp(loc); + ((NullExp *) e)->dUnchecked = !dltSyntax; nextToken(); break; -- 2.11.4.GIT