From patchwork Tue Jun 16 21:59:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1310732 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=dm7IiLIB; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49mhwR3b1Rz9sR4 for ; Wed, 17 Jun 2020 08:00:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75641388E83A; Tue, 16 Jun 2020 22:00:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75641388E83A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592344830; bh=eFYXo4zRZIZj+4EKOJuBEogvhl6utbg2QXt3agoOeuQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dm7IiLIB32uiwo6p9vAqVeTpMs4QWPyBLhzOz4Q8lK5yuFeRmi/ONTfnimOY4HKCM fNRnBsDpLHgvJrt+ZhmEJ6kvIg9F0eUcd6c2MGrEgAIm/l4GeQOnZoOB9o0vrbMV91 IAoxOd4aLKLIzrv6rilYw84evLrbW80kAAvlnEfI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050::465:101]) by sourceware.org (Postfix) with ESMTPS id 33DF4388C011 for ; Tue, 16 Jun 2020 22:00:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 33DF4388C011 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 49mhvt37jGzKmn0; Wed, 17 Jun 2020 00:00:26 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id JOcKIoEvMm2g; Wed, 17 Jun 2020 00:00:16 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Use new isXxxxExp helpers where possible Date: Tue, 16 Jun 2020 23:59:31 +0200 Message-Id: <20200616215933.3858164-8-ibuclaw@gdcproject.org> In-Reply-To: <20200616215933.3858164-1-ibuclaw@gdcproject.org> References: <20200616215933.3858164-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 38E531782 X-Rspamd-Score: -2.39 / 15.00 / 15.00 X-Spam-Status: No, score=-16.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_ABUSE_SURBL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch replaces uses of casting to Expression nodes with the newly introduced isXxxxExp functions. Bootstrapped and regression tested on x86_64-linux-gnu, and committed to master. Regards Iain gcc/d/ChangeLog: * d-attribs.cc (build_attributes): Use isXxxxExp helpers instead of explicit casts. * d-codegen.cc (d_build_call): Likewise. * d-compiler.cc (Compiler::paintAsType): Likewise. * decl.cc (ExprVisitor::visit): Likewise. (layout_class_initializer): Likewise. * expr.cc (ExprVisitor::lvalue_p): Likewise (ExprVisitor::visit): Likewise. * types.cc (layout_aggregate_members): Likewise. --- gcc/d/d-attribs.cc | 6 ++--- gcc/d/d-codegen.cc | 2 +- gcc/d/d-compiler.cc | 4 +-- gcc/d/decl.cc | 11 ++++---- gcc/d/expr.cc | 62 +++++++++++++++++++++++++-------------------- gcc/d/types.cc | 2 +- 6 files changed, 46 insertions(+), 41 deletions(-) diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc index b83db95e2a7..7e55b42fd03 100644 --- a/gcc/d/d-attribs.cc +++ b/gcc/d/d-attribs.cc @@ -268,7 +268,7 @@ build_attributes (Expressions *eattrs) /* Should now have a struct `Attribute("attrib", "value", ...)' initializer list. */ gcc_assert (attr->op == TOKstructliteral); - Expressions *elems = ((StructLiteralExp*) attr)->elements; + Expressions *elems = attr->isStructLiteralExp ()->elements; Expression *e0 = (*elems)[0]; if (e0->op != TOKstring) @@ -300,10 +300,10 @@ build_attributes (Expressions *eattrs) for (size_t j = 1; j < elems->length; j++) { Expression *e = (*elems)[j]; + StringExp *s = e->isStringExp (); tree t; - if (e->op == TOKstring && ((StringExp *) e)->sz == 1) + if (s != NULL && s->sz == 1) { - StringExp *s = (StringExp *) e; const char *string = (const char *)(s->len ? s->string : ""); t = build_string (s->len, string); } diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 1bf74e1f223..d31638e2c1d 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -1874,7 +1874,7 @@ d_build_call (TypeFunction *tf, tree callable, tree object, if (arg->op == TOKcomma) { - CommaExp *ce = (CommaExp *) arg; + CommaExp *ce = arg->isCommaExp (); tree tce = build_expr (ce->e1); saved_args = compound_expr (saved_args, tce); (*arguments)[i] = ce->e2; diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc index 75ca15737d9..41b3b53207a 100644 --- a/gcc/d/d-compiler.cc +++ b/gcc/d/d-compiler.cc @@ -88,7 +88,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type *type) else if (expr->op == TOKarrayliteral) { /* Build array as VECTOR_CST, assumes EXPR is constant. */ - Expressions *elements = ((ArrayLiteralExp *) expr)->elements; + Expressions *elements = expr->isArrayLiteralExp ()->elements; vec *elms = NULL; vec_safe_reserve (elms, elements->length); @@ -136,7 +136,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type *type) Expression *e = d_eval_constant_expression (cst); gcc_assert (e != NULL && e->op == TOKvector); - return ((VectorExp *) e)->e1; + return e->isVectorExp ()->e1; } else { diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index a6144f7c269..28d1d6d5f31 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -218,12 +218,11 @@ public: for (size_t i = 0; i < d->objects->length; i++) { RootObject *o = (*d->objects)[i]; - if ((o->dyncast () == DYNCAST_EXPRESSION) - && ((Expression *) o)->op == TOKdsymbol) + if (o->dyncast () == DYNCAST_EXPRESSION) { - Declaration *d = ((DsymbolExp *) o)->s->isDeclaration (); - if (d) - this->build_dsymbol (d); + DsymbolExp *de = ((Expression *) o)->isDsymbolExp (); + if (de != NULL && de->s->isDeclaration ()) + this->build_dsymbol (de->s); } } } @@ -2239,7 +2238,7 @@ layout_class_initializer (ClassDeclaration *cd) Expression *e = ne->ctfeInterpret (); gcc_assert (e->op == TOKclassreference); - return build_class_instance ((ClassReferenceExp *) e); + return build_class_instance (e->isClassReferenceExp ()); } tree diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc index 9c80db15552..06cd83a737d 100644 --- a/gcc/d/expr.cc +++ b/gcc/d/expr.cc @@ -90,9 +90,15 @@ class ExprVisitor : public Visitor bool lvalue_p (Expression *e) { - return ((e->op != TOKslice && e->isLvalue ()) - || (e->op == TOKslice && ((UnaExp *) e)->e1->isLvalue ()) - || (e->op == TOKcast && ((UnaExp *) e)->e1->isLvalue ())); + SliceExp *se = e->isSliceExp (); + if (se != NULL && se->e1->isLvalue ()) + return true; + + CastExp *ce = e->isCastExp (); + if (ce != NULL && ce->e1->isLvalue ()) + return true; + + return (e->op != TOKslice && e->isLvalue ()); } /* Build an expression of code CODE, data type TYPE, and operands ARG0 and @@ -174,7 +180,7 @@ class ExprVisitor : public Visitor Expression *e1b = e1; while (e1b->op == TOKcast) { - CastExp *ce = (CastExp *) e1b; + CastExp *ce = e1b->isCastExp (); gcc_assert (same_type_p (ce->type, ce->to)); e1b = ce->e1; } @@ -679,7 +685,7 @@ public: { if (ex->op == TOKcat) { - ex = ((CatExp *) ex)->e1; + ex = ex->isCatExp ()->e1; ndims++; } } @@ -696,7 +702,7 @@ public: for (Expression *oe = ce->e2; oe != NULL; (ce->e1->op != TOKcat ? (oe = ce->e1) - : (ce = (CatExp *)ce->e1, oe = ce->e2))) + : (ce = ce->e1->isCatExp (), oe = ce->e2))) { tree arg = d_array_convert (etype, oe); tree index = size_int (dim); @@ -790,7 +796,7 @@ public: Strip off casts just incase anyway. */ while (e1b->op == TOKcast) { - CastExp *ce = (CastExp *) e1b; + CastExp *ce = e1b->isCastExp (); gcc_assert (same_type_p (ce->type, ce->to)); e1b = ce->e1; } @@ -883,7 +889,7 @@ public: if (e->e1->op == TOKarraylength) { /* Assignment to an array's length property; resize the array. */ - ArrayLengthExp *ale = (ArrayLengthExp *) e->e1; + ArrayLengthExp *ale = e->e1->isArrayLengthExp (); tree newlength = convert_expr (build_expr (e->e2), e->e2->type, Type::tsize_t); tree ptr = build_address (build_expr (ale->e1)); @@ -904,7 +910,7 @@ public: /* Look for array[] = n; */ if (e->e1->op == TOKslice) { - SliceExp *se = (SliceExp *) e->e1; + SliceExp *se = e->e1->isSliceExp (); Type *stype = se->e1->type->toBasetype (); Type *etype = stype->nextOf ()->toBasetype (); @@ -998,7 +1004,7 @@ public: gcc_assert (e->op == TOKconstruct || e->op == TOKblit); gcc_assert (e->e1->op == TOKvar); - Declaration *decl = ((VarExp *) e->e1)->var; + Declaration *decl = e->e1->isVarExp ()->var; if (decl->storage_class & (STCout | STCref)) { tree t2 = convert_for_assignment (build_expr (e->e2), @@ -1443,7 +1449,7 @@ public: if (e->e1->op == TOKvar) { - VarDeclaration *v = ((VarExp *) e->e1)->var->isVarDeclaration (); + VarDeclaration *v = e->e1->isVarExp ()->var->isVarDeclaration (); if (v && v->onstack) { libcall = tb1->isClassHandle ()->isInterfaceDeclaration () @@ -1588,19 +1594,19 @@ public: if (e->e1->op == TOKadd) { - BinExp *be = (BinExp *) e->e1; - if (be->e1->op == TOKaddress - && be->e2->isConst () && be->e2->type->isintegral ()) + AddExp *ae = e->e1->isAddExp (); + if (ae->e1->op == TOKaddress + && ae->e2->isConst () && ae->e2->type->isintegral ()) { - Expression *ae = ((AddrExp *) be->e1)->e1; - tnext = ae->type->toBasetype (); - result = build_expr (ae); - offset = be->e2->toUInteger (); + Expression *ex = ae->e1->isAddrExp ()->e1; + tnext = ex->type->toBasetype (); + result = build_expr (ex); + offset = ae->e2->toUInteger (); } } else if (e->e1->op == TOKsymoff) { - SymOffExp *se = (SymOffExp *) e->e1; + SymOffExp *se = e->e1->isSymOffExp (); if (!declaration_reference_p (se->var)) { tnext = se->var->type->toBasetype (); @@ -1652,7 +1658,7 @@ public: Taking the address of a struct literal is otherwise illegal. */ if (e->e1->op == TOKstructliteral) { - StructLiteralExp *sle = ((StructLiteralExp *) e->e1)->origin; + StructLiteralExp *sle = e->e1->isStructLiteralExp ()->origin; gcc_assert (sle != NULL); /* Build the reference symbol, the decl is built first as the @@ -1690,21 +1696,21 @@ public: /* Calls to delegates can sometimes look like this. */ if (e1b->op == TOKcomma) { - e1b = ((CommaExp *) e1b)->e2; + e1b = e1b->isCommaExp ()->e2; gcc_assert (e1b->op == TOKvar); - Declaration *var = ((VarExp *) e1b)->var; + Declaration *var = e1b->isVarExp ()->var; gcc_assert (var->isFuncDeclaration () && !var->needThis ()); } if (e1b->op == TOKdotvar && tb->ty != Tdelegate) { - DotVarExp *dve = (DotVarExp *) e1b; + DotVarExp *dve = e1b->isDotVarExp (); /* Don't modify the static initializer for struct literals. */ if (dve->e1->op == TOKstructliteral) { - StructLiteralExp *sle = (StructLiteralExp *) dve->e1; + StructLiteralExp *sle = dve->e1->isStructLiteralExp (); sle->useStaticInit = false; } @@ -1767,7 +1773,7 @@ public: /* This gets the true function type, getting the function type from e1->type can sometimes be incorrect, such as when calling a 'ref' return function. */ - tf = get_function_type (((DotVarExp *) e1b)->var->type); + tf = get_function_type (e1b->isDotVarExp ()->var->type); } else tf = get_function_type (tb); @@ -1784,7 +1790,7 @@ public: } else if (e1b->op == TOKvar) { - FuncDeclaration *fd = ((VarExp *) e1b)->var->isFuncDeclaration (); + FuncDeclaration *fd = e1b->isVarExp ()->var->isFuncDeclaration (); gcc_assert (fd != NULL); tf = get_function_type (fd->type); @@ -2145,7 +2151,7 @@ public: void visit (SymOffExp *e) { /* Build the address and offset of the symbol. */ - size_t soffset = ((SymOffExp *) e)->offset; + size_t soffset = e->isSymOffExp ()->offset; tree result = get_decl_tree (e->var); TREE_USED (result) = 1; @@ -2956,7 +2962,7 @@ public: /* First handle array literal expressions. */ if (e->e1->op == TOKarrayliteral) { - ArrayLiteralExp *ale = ((ArrayLiteralExp *) e->e1); + ArrayLiteralExp *ale = e->e1->isArrayLiteralExp (); vec *elms = NULL; bool constant_p = true; diff --git a/gcc/d/types.cc b/gcc/d/types.cc index cb9a6dec7e5..ba7e29a12e1 100644 --- a/gcc/d/types.cc +++ b/gcc/d/types.cc @@ -292,7 +292,7 @@ layout_aggregate_members (Dsymbols *members, tree context, bool inherited_p) gcc_assert (ro->dyncast () == DYNCAST_EXPRESSION); Expression *e = (Expression *) ro; gcc_assert (e->op == TOKdsymbol); - DsymbolExp *se = (DsymbolExp *) e; + DsymbolExp *se = e->isDsymbolExp (); tmembers.push (se->s); }