From c9f08d766dc996dc7660db6efc2539c735d237e8 Mon Sep 17 00:00:00 2001 From: k-hara Date: Fri, 8 Aug 2014 16:34:17 +0900 Subject: [PATCH] [Refactoring] Clean up syntaxCopy functions Dsymbol, Statement, Expression, Type, and Initializer. --- src/attrib.c | 51 +++-------- src/class.c | 25 ++---- src/declaration.c | 45 +++------- src/dsymbol.c | 14 +-- src/enum.c | 51 ++--------- src/expression.c | 55 +++--------- src/expression.h | 1 - src/func.c | 86 +++++++----------- src/init.c | 24 +----- src/mtype.c | 50 +++++------ src/nspace.c | 3 +- src/statement.c | 211 +++++++++++++++++---------------------------- src/staticassert.c | 5 +- src/struct.c | 24 ++---- src/template.c | 85 ++++++------------ 15 files changed, 226 insertions(+), 504 deletions(-) diff --git a/src/attrib.c b/src/attrib.c index 622147d4074c..1259caad5cf8 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -339,11 +339,8 @@ StorageClassDeclaration::StorageClassDeclaration(StorageClass stc, Dsymbols *dec Dsymbol *StorageClassDeclaration::syntaxCopy(Dsymbol *s) { - StorageClassDeclaration *scd; - assert(!s); - scd = new StorageClassDeclaration(stc, Dsymbol::arraySyntaxCopy(decl)); - return scd; + return new StorageClassDeclaration(stc, Dsymbol::arraySyntaxCopy(decl)); } bool StorageClassDeclaration::oneMember(Dsymbol **ps, Identifier *ident) @@ -527,11 +524,8 @@ LinkDeclaration::LinkDeclaration(LINK p, Dsymbols *decl) Dsymbol *LinkDeclaration::syntaxCopy(Dsymbol *s) { - LinkDeclaration *ld; - assert(!s); - ld = new LinkDeclaration(linkage, Dsymbol::arraySyntaxCopy(decl)); - return ld; + return new LinkDeclaration(linkage, Dsymbol::arraySyntaxCopy(decl)); } Scope *LinkDeclaration::newScope(Scope *sc) @@ -555,11 +549,8 @@ ProtDeclaration::ProtDeclaration(PROT p, Dsymbols *decl) Dsymbol *ProtDeclaration::syntaxCopy(Dsymbol *s) { - ProtDeclaration *pd; - assert(!s); - pd = new ProtDeclaration(protection, Dsymbol::arraySyntaxCopy(decl)); - return pd; + return new ProtDeclaration(protection, Dsymbol::arraySyntaxCopy(decl)); } Scope *ProtDeclaration::newScope(Scope *sc) @@ -577,11 +568,8 @@ AlignDeclaration::AlignDeclaration(unsigned sa, Dsymbols *decl) Dsymbol *AlignDeclaration::syntaxCopy(Dsymbol *s) { - AlignDeclaration *ad; - assert(!s); - ad = new AlignDeclaration(salign, Dsymbol::arraySyntaxCopy(decl)); - return ad; + return new AlignDeclaration(salign, Dsymbol::arraySyntaxCopy(decl)); } Scope *AlignDeclaration::newScope(Scope *sc) @@ -602,11 +590,8 @@ AnonDeclaration::AnonDeclaration(Loc loc, bool isunion, Dsymbols *decl) Dsymbol *AnonDeclaration::syntaxCopy(Dsymbol *s) { - AnonDeclaration *ad; - assert(!s); - ad = new AnonDeclaration(loc, isunion, Dsymbol::arraySyntaxCopy(decl)); - return ad; + return new AnonDeclaration(loc, isunion, Dsymbol::arraySyntaxCopy(decl)); } void AnonDeclaration::semantic(Scope *sc) @@ -722,12 +707,10 @@ PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Expressions *ar Dsymbol *PragmaDeclaration::syntaxCopy(Dsymbol *s) { //printf("PragmaDeclaration::syntaxCopy(%s)\n", toChars()); - PragmaDeclaration *pd; - assert(!s); - pd = new PragmaDeclaration(loc, ident, - Expression::arraySyntaxCopy(args), Dsymbol::arraySyntaxCopy(decl)); - return pd; + return new PragmaDeclaration(loc, ident, + Expression::arraySyntaxCopy(args), + Dsymbol::arraySyntaxCopy(decl)); } void PragmaDeclaration::setScope(Scope *sc) @@ -1019,13 +1002,10 @@ ConditionalDeclaration::ConditionalDeclaration(Condition *condition, Dsymbols *d Dsymbol *ConditionalDeclaration::syntaxCopy(Dsymbol *s) { - ConditionalDeclaration *dd; - assert(!s); - dd = new ConditionalDeclaration(condition->syntaxCopy(), + return new ConditionalDeclaration(condition->syntaxCopy(), Dsymbol::arraySyntaxCopy(decl), Dsymbol::arraySyntaxCopy(elsedecl)); - return dd; } bool ConditionalDeclaration::oneMember(Dsymbol **ps, Identifier *ident) @@ -1110,13 +1090,10 @@ StaticIfDeclaration::StaticIfDeclaration(Condition *condition, Dsymbol *StaticIfDeclaration::syntaxCopy(Dsymbol *s) { - StaticIfDeclaration *dd; - assert(!s); - dd = new StaticIfDeclaration(condition->syntaxCopy(), + return new StaticIfDeclaration(condition->syntaxCopy(), Dsymbol::arraySyntaxCopy(decl), Dsymbol::arraySyntaxCopy(elsedecl)); - return dd; } Dsymbols *StaticIfDeclaration::include(Scope *sc, ScopeDsymbol *sds) @@ -1232,8 +1209,7 @@ CompileDeclaration::CompileDeclaration(Loc loc, Expression *exp) Dsymbol *CompileDeclaration::syntaxCopy(Dsymbol *s) { //printf("CompileDeclaration::syntaxCopy('%s')\n", toChars()); - CompileDeclaration *sc = new CompileDeclaration(loc, exp->syntaxCopy()); - return sc; + return new CompileDeclaration(loc, exp->syntaxCopy()); } int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sds, int memnum) @@ -1329,8 +1305,9 @@ Dsymbol *UserAttributeDeclaration::syntaxCopy(Dsymbol *s) { //printf("UserAttributeDeclaration::syntaxCopy('%s')\n", toChars()); assert(!s); - Expressions *atts = Expression::arraySyntaxCopy(this->atts); - return new UserAttributeDeclaration(atts, Dsymbol::arraySyntaxCopy(decl)); + return new UserAttributeDeclaration( + Expression::arraySyntaxCopy(this->atts), + Dsymbol::arraySyntaxCopy(decl)); } Scope *UserAttributeDeclaration::newScope(Scope *sc) diff --git a/src/class.c b/src/class.c index 703d2b46fafa..b09b574e986f 100644 --- a/src/class.c +++ b/src/class.c @@ -244,13 +244,10 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla Dsymbol *ClassDeclaration::syntaxCopy(Dsymbol *s) { - ClassDeclaration *cd; - //printf("ClassDeclaration::syntaxCopy('%s')\n", toChars()); - if (s) - cd = (ClassDeclaration *)s; - else - cd = new ClassDeclaration(loc, ident, NULL); + ClassDeclaration *cd = + s ? (ClassDeclaration *)s + : new ClassDeclaration(loc, ident, NULL); cd->storage_class |= storage_class; @@ -262,8 +259,7 @@ Dsymbol *ClassDeclaration::syntaxCopy(Dsymbol *s) (*cd->baseclasses)[i] = b2; } - ScopeDsymbol::syntaxCopy(cd); - return cd; + return ScopeDsymbol::syntaxCopy(cd); } void ClassDeclaration::semantic(Scope *sc) @@ -1222,15 +1218,10 @@ InterfaceDeclaration::InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses Dsymbol *InterfaceDeclaration::syntaxCopy(Dsymbol *s) { - InterfaceDeclaration *id; - - if (s) - id = (InterfaceDeclaration *)s; - else - id = new InterfaceDeclaration(loc, ident, NULL); - - ClassDeclaration::syntaxCopy(id); - return id; + InterfaceDeclaration *id = + s ? (InterfaceDeclaration *)s + : new InterfaceDeclaration(loc, ident, NULL); + return ClassDeclaration::syntaxCopy(id); } void InterfaceDeclaration::semantic(Scope *sc) diff --git a/src/declaration.c b/src/declaration.c index a9e5a282089f..44abc992ed7b 100644 --- a/src/declaration.c +++ b/src/declaration.c @@ -290,16 +290,10 @@ TypedefDeclaration::TypedefDeclaration(Loc loc, Identifier *id, Type *basetype, Dsymbol *TypedefDeclaration::syntaxCopy(Dsymbol *s) { - Type *basetype = this->basetype->syntaxCopy(); - - Initializer *init = NULL; - if (this->init) - init = this->init->syntaxCopy(); - assert(!s); - TypedefDeclaration *st; - st = new TypedefDeclaration(loc, ident, basetype, init); - return st; + return new TypedefDeclaration(loc, ident, + basetype->syntaxCopy(), + init ? init->syntaxCopy() : NULL); } void TypedefDeclaration::semantic(Scope *sc) @@ -414,11 +408,9 @@ Dsymbol *AliasDeclaration::syntaxCopy(Dsymbol *s) { //printf("AliasDeclaration::syntaxCopy()\n"); assert(!s); - AliasDeclaration *sa; - if (type) - sa = new AliasDeclaration(loc, ident, type->syntaxCopy()); - else - sa = new AliasDeclaration(loc, ident, aliassym->syntaxCopy(NULL)); + AliasDeclaration *sa = + type ? new AliasDeclaration(loc, ident, type->syntaxCopy()) + : new AliasDeclaration(loc, ident, aliassym->syntaxCopy(NULL)); sa->storage_class = storage_class; return sa; } @@ -850,24 +842,13 @@ VarDeclaration::VarDeclaration(Loc loc, Type *type, Identifier *id, Initializer Dsymbol *VarDeclaration::syntaxCopy(Dsymbol *s) { //printf("VarDeclaration::syntaxCopy(%s)\n", toChars()); - - VarDeclaration *sv; - if (s) - { sv = (VarDeclaration *)s; - } - else - { - Initializer *init = NULL; - if (this->init) - { init = this->init->syntaxCopy(); - //init->isExpInitializer()->exp->print(); - } - - sv = new VarDeclaration(loc, type ? type->syntaxCopy() : NULL, ident, init); - sv->storage_class = storage_class; - } - - return sv; + assert(!s); + VarDeclaration *v = new VarDeclaration(loc, + type ? type->syntaxCopy() : NULL, + ident, + init ? init->syntaxCopy() : NULL); + v->storage_class = storage_class; + return v; } void VarDeclaration::semantic(Scope *sc) diff --git a/src/dsymbol.c b/src/dsymbol.c index 9f8075d3bac4..06f95b56399b 100644 --- a/src/dsymbol.c +++ b/src/dsymbol.c @@ -766,7 +766,6 @@ PROT Dsymbol::prot() * Do syntax copy of an array of Dsymbol's. */ - Dsymbols *Dsymbol::arraySyntaxCopy(Dsymbols *a) { @@ -776,16 +775,12 @@ Dsymbols *Dsymbol::arraySyntaxCopy(Dsymbols *a) b = a->copy(); for (size_t i = 0; i < b->dim; i++) { - Dsymbol *s = (*b)[i]; - - s = s->syntaxCopy(NULL); - (*b)[i] = s; + (*b)[i] = (*b)[i]->syntaxCopy(NULL); } } return b; } - /**************************************** * Add documentation comment to Dsymbol. * Ignore NULL comments. @@ -872,12 +867,7 @@ ScopeDsymbol::ScopeDsymbol(Identifier *id) Dsymbol *ScopeDsymbol::syntaxCopy(Dsymbol *s) { //printf("ScopeDsymbol::syntaxCopy('%s')\n", toChars()); - - ScopeDsymbol *sds; - if (s) - sds = (ScopeDsymbol *)s; - else - sds = new ScopeDsymbol(ident); + ScopeDsymbol *sds = s ? (ScopeDsymbol *)s : new ScopeDsymbol(ident); sds->members = arraySyntaxCopy(members); return sds; } diff --git a/src/enum.c b/src/enum.c index 86db7b18d484..bee9de833bed 100644 --- a/src/enum.c +++ b/src/enum.c @@ -44,27 +44,10 @@ EnumDeclaration::EnumDeclaration(Loc loc, Identifier *id, Type *memtype) Dsymbol *EnumDeclaration::syntaxCopy(Dsymbol *s) { - Type *t = NULL; - if (memtype) - t = memtype->syntaxCopy(); - - EnumDeclaration *ed; - if (s) - { ed = (EnumDeclaration *)s; - ed->memtype = t; - } - else - ed = new EnumDeclaration(loc, ident, t); - ScopeDsymbol::syntaxCopy(ed); - if (isAnonymous()) - { - for (size_t i = 0; i < members->dim; i++) - { - EnumMember *em = (*members)[i]->isEnumMember(); - em->ed = ed; - } - } - return ed; + assert(!s); + EnumDeclaration *ed = new EnumDeclaration(loc, ident, + memtype ? memtype->syntaxCopy() : NULL); + return ScopeDsymbol::syntaxCopy(ed); } void EnumDeclaration::setScope(Scope *sc) @@ -496,28 +479,10 @@ EnumMember::EnumMember(Loc loc, Identifier *id, Expression *value, Type *type) Dsymbol *EnumMember::syntaxCopy(Dsymbol *s) { - Expression *e = NULL; - if (value) - e = value->syntaxCopy(); - - Type *t = NULL; - if (type) - t = type->syntaxCopy(); - - EnumMember *em; - if (s) - { em = (EnumMember *)s; - em->loc = loc; - em->value = e; - em->type = t; - em->origValue = origValue ? origValue->syntaxCopy() : NULL; - } - else - { - em = new EnumMember(loc, ident, e, t); - em->origValue = origValue ? origValue->syntaxCopy() : NULL; - } - return em; + assert(!s); + return new EnumMember(loc, ident, + value ? value->syntaxCopy() : NULL, + type ? type->syntaxCopy() : NULL); } const char *EnumMember::kind() diff --git a/src/expression.c b/src/expression.c index 5812cf6c160f..4bb77288fb36 100644 --- a/src/expression.c +++ b/src/expression.c @@ -2554,18 +2554,16 @@ Expression *Expression::resolveLoc(Loc loc, Scope *sc) } Expressions *Expression::arraySyntaxCopy(Expressions *exps) -{ Expressions *a = NULL; - +{ + Expressions *a = NULL; if (exps) { a = new Expressions(); a->setDim(exps->dim); for (size_t i = 0; i < a->dim; i++) - { Expression *e = (*exps)[i]; - - if (e) - e = e->syntaxCopy(); - (*a)[i] = e; + { + Expression *e = (*exps)[i]; + (*a)[i] = e ? e->syntaxCopy() : NULL; } } return a; @@ -3578,14 +3576,6 @@ StringExp *StringExp::create(Loc loc, char *s) return new StringExp(loc, s); } -#if 0 -Expression *StringExp::syntaxCopy() -{ - printf("StringExp::syntaxCopy() %s\n", toChars()); - return copy(); -} -#endif - bool StringExp::equals(RootObject *o) { //printf("StringExp::equals('%s') %s\n", o->toChars(), toChars()); @@ -4413,7 +4403,6 @@ TypeExp::TypeExp(Loc loc, Type *type) Expression *TypeExp::syntaxCopy() { - //printf("TypeExp::syntaxCopy()\n"); return new TypeExp(loc, type->syntaxCopy()); } @@ -4468,8 +4457,7 @@ ScopeExp::ScopeExp(Loc loc, ScopeDsymbol *pkg) Expression *ScopeExp::syntaxCopy() { - ScopeExp *se = new ScopeExp(loc, (ScopeDsymbol *)sds->syntaxCopy(NULL)); - return se; + return new ScopeExp(loc, (ScopeDsymbol *)sds->syntaxCopy(NULL)); } Expression *ScopeExp::semantic(Scope *sc) @@ -4628,7 +4616,6 @@ Expression *NewExp::syntaxCopy() newtype->syntaxCopy(), arraySyntaxCopy(arguments)); } - Expression *NewExp::semantic(Scope *sc) { #if LOGSEMANTIC @@ -5029,7 +5016,6 @@ Expression *NewAnonClassExp::syntaxCopy() arraySyntaxCopy(arguments)); } - Expression *NewAnonClassExp::semantic(Scope *sc) { #if LOGSEMANTIC @@ -5946,13 +5932,11 @@ TypeidExp::TypeidExp(Loc loc, RootObject *o) this->obj = o; } - Expression *TypeidExp::syntaxCopy() { return new TypeidExp(loc, objectSyntaxCopy(obj)); } - Expression *TypeidExp::semantic(Scope *sc) { #if LOGSEMANTIC @@ -6028,7 +6012,6 @@ TraitsExp::TraitsExp(Loc loc, Identifier *ident, Objects *args) this->args = args; } - Expression *TraitsExp::syntaxCopy() { return new TraitsExp(loc, ident, TemplateInstance::arraySyntaxCopy(args)); @@ -6078,11 +6061,8 @@ Expression *IsExp::syntaxCopy() p = new TemplateParameters(); p->setDim(parameters->dim); for (size_t i = 0; i < p->dim; i++) - { TemplateParameter *tp = (*parameters)[i]; - (*p)[i] = tp->syntaxCopy(); - } + (*p)[i] = (*parameters)[i]->syntaxCopy(); } - return new IsExp(loc, targ->syntaxCopy(), id, @@ -6923,9 +6903,7 @@ AssertExp::AssertExp(Loc loc, Expression *e, Expression *msg) Expression *AssertExp::syntaxCopy() { - AssertExp *ae = new AssertExp(loc, e1->syntaxCopy(), - msg ? msg->syntaxCopy() : NULL); - return ae; + return new AssertExp(loc, e1->syntaxCopy(), msg ? msg->syntaxCopy() : NULL); } Expression *AssertExp::semantic(Scope *sc) @@ -7659,11 +7637,10 @@ DotTemplateInstanceExp::DotTemplateInstanceExp(Loc loc, Expression *e, TemplateI Expression *DotTemplateInstanceExp::syntaxCopy() { - DotTemplateInstanceExp *de = new DotTemplateInstanceExp(loc, + return new DotTemplateInstanceExp(loc, e1->syntaxCopy(), ti->name, TemplateInstance::arraySyntaxCopy(ti->tiargs)); - return de; } bool DotTemplateInstanceExp::findTempDecl(Scope *sc) @@ -9553,7 +9530,6 @@ Expression *CastExp::syntaxCopy() : new CastExp(loc, e1->syntaxCopy(), mod); } - Expression *CastExp::semantic(Scope *sc) { #if LOGSEMANTIC @@ -9818,15 +9794,9 @@ SliceExp::SliceExp(Loc loc, Expression *e1, Expression *lwr, Expression *upr) Expression *SliceExp::syntaxCopy() { - Expression *lwr = NULL; - if (this->lwr) - lwr = this->lwr->syntaxCopy(); - - Expression *upr = NULL; - if (this->upr) - upr = this->upr->syntaxCopy(); - - SliceExp *se = new SliceExp(loc, e1->syntaxCopy(), lwr, upr); + SliceExp *se = new SliceExp(loc, e1->syntaxCopy(), + lwr ? lwr->syntaxCopy() : NULL, + upr ? upr->syntaxCopy() : NULL); se->lengthVar = this->lengthVar; // bug7871 return se; } @@ -13530,7 +13500,6 @@ Expression *CondExp::syntaxCopy() return new CondExp(loc, econd->syntaxCopy(), e1->syntaxCopy(), e2->syntaxCopy()); } - Expression *CondExp::semantic(Scope *sc) { #if LOGSEMANTIC diff --git a/src/expression.h b/src/expression.h index f7bb950f220f..cfee285f20fa 100644 --- a/src/expression.h +++ b/src/expression.h @@ -395,7 +395,6 @@ class StringExp : public Expression StringExp(Loc loc, void *s, size_t len); StringExp(Loc loc, void *s, size_t len, utf8_t postfix); static StringExp *create(Loc loc, char *s); - //Expression *syntaxCopy(); bool equals(RootObject *o); Expression *semantic(Scope *sc); size_t length(); diff --git a/src/func.c b/src/func.c index 91c9bbce622c..fed77b8cf6b9 100644 --- a/src/func.c +++ b/src/func.c @@ -342,13 +342,10 @@ FuncDeclaration::FuncDeclaration(Loc loc, Loc endloc, Identifier *id, StorageCla Dsymbol *FuncDeclaration::syntaxCopy(Dsymbol *s) { - FuncDeclaration *f; - //printf("FuncDeclaration::syntaxCopy('%s')\n", toChars()); - if (s) - f = (FuncDeclaration *)s; - else - f = new FuncDeclaration(loc, endloc, ident, storage_class, type->syntaxCopy()); + FuncDeclaration *f = + s ? (FuncDeclaration *)s + : new FuncDeclaration(loc, endloc, ident, storage_class, type->syntaxCopy()); f->outId = outId; f->frequire = frequire ? frequire->syntaxCopy() : NULL; f->fensure = fensure ? fensure->syntaxCopy() : NULL; @@ -4208,16 +4205,12 @@ FuncLiteralDeclaration::FuncLiteralDeclaration(Loc loc, Loc endloc, Type *type, Dsymbol *FuncLiteralDeclaration::syntaxCopy(Dsymbol *s) { - FuncLiteralDeclaration *f; - //printf("FuncLiteralDeclaration::syntaxCopy('%s')\n", toChars()); - if (s) - f = (FuncLiteralDeclaration *)s; - else - f = new FuncLiteralDeclaration(loc, endloc, type->syntaxCopy(), tok, fes, ident); + assert(!s); + FuncLiteralDeclaration *f = new FuncLiteralDeclaration(loc, endloc, + type->syntaxCopy(), tok, fes, ident); f->treq = treq; // don't need to copy - FuncDeclaration::syntaxCopy(f); - return f; + return FuncDeclaration::syntaxCopy(f); } bool FuncLiteralDeclaration::isNested() @@ -4309,17 +4302,14 @@ CtorDeclaration::CtorDeclaration(Loc loc, Loc endloc, StorageClass stc, Type *ty Dsymbol *CtorDeclaration::syntaxCopy(Dsymbol *s) { CtorDeclaration *f = new CtorDeclaration(loc, endloc, storage_class, type->syntaxCopy()); - f->outId = outId; f->frequire = frequire ? frequire->syntaxCopy() : NULL; f->fensure = fensure ? fensure->syntaxCopy() : NULL; f->fbody = fbody ? fbody->syntaxCopy() : NULL; assert(!fthrows); // deprecated - return f; } - void CtorDeclaration::semantic(Scope *sc) { //printf("CtorDeclaration::semantic() %s\n", toChars()); @@ -4327,7 +4317,8 @@ void CtorDeclaration::semantic(Scope *sc) assert(tf && tf->ty == Tfunction); if (scope) - { sc = scope; + { + sc = scope; scope = NULL; } @@ -4405,14 +4396,14 @@ Dsymbol *PostBlitDeclaration::syntaxCopy(Dsymbol *s) return FuncDeclaration::syntaxCopy(dd); } - void PostBlitDeclaration::semantic(Scope *sc) { //printf("PostBlitDeclaration::semantic() %s\n", toChars()); //printf("ident: %s, %s, %p, %p\n", ident->toChars(), Id::dtor->toChars(), ident, Id::dtor); //printf("stc = x%llx\n", sc->stc); if (scope) - { sc = scope; + { + sc = scope; scope = NULL; } parent = sc->parent; @@ -4476,13 +4467,13 @@ Dsymbol *DtorDeclaration::syntaxCopy(Dsymbol *s) return FuncDeclaration::syntaxCopy(dd); } - void DtorDeclaration::semantic(Scope *sc) { //printf("DtorDeclaration::semantic() %s\n", toChars()); //printf("ident: %s, %s, %p, %p\n", ident->toChars(), Id::dtor->toChars(), ident, Id::dtor); if (scope) - { sc = scope; + { + sc = scope; scope = NULL; } parent = sc->parent; @@ -4559,7 +4550,6 @@ Dsymbol *StaticCtorDeclaration::syntaxCopy(Dsymbol *s) return FuncDeclaration::syntaxCopy(scd); } - void StaticCtorDeclaration::semantic(Scope *sc) { //printf("StaticCtorDeclaration::semantic()\n"); @@ -4689,11 +4679,11 @@ Dsymbol *StaticDtorDeclaration::syntaxCopy(Dsymbol *s) return FuncDeclaration::syntaxCopy(sdd); } - void StaticDtorDeclaration::semantic(Scope *sc) { if (scope) - { sc = scope; + { + sc = scope; scope = NULL; } @@ -4791,19 +4781,16 @@ InvariantDeclaration::InvariantDeclaration(Loc loc, Loc endloc, StorageClass stc Dsymbol *InvariantDeclaration::syntaxCopy(Dsymbol *s) { - InvariantDeclaration *id; - assert(!s); - id = new InvariantDeclaration(loc, endloc, storage_class); - FuncDeclaration::syntaxCopy(id); - return id; + InvariantDeclaration *id = new InvariantDeclaration(loc, endloc, storage_class); + return FuncDeclaration::syntaxCopy(id); } - void InvariantDeclaration::semantic(Scope *sc) { if (scope) - { sc = scope; + { + sc = scope; scope = NULL; } parent = sc->parent; @@ -4869,14 +4856,11 @@ UnitTestDeclaration::UnitTestDeclaration(Loc loc, Loc endloc, char *codedoc) Dsymbol *UnitTestDeclaration::syntaxCopy(Dsymbol *s) { - UnitTestDeclaration *utd; - assert(!s); - utd = new UnitTestDeclaration(loc, endloc, codedoc); + UnitTestDeclaration *utd = new UnitTestDeclaration(loc, endloc, codedoc); return FuncDeclaration::syntaxCopy(utd); } - void UnitTestDeclaration::semantic(Scope *sc) { protection = sc->protection; @@ -4947,24 +4931,19 @@ NewDeclaration::NewDeclaration(Loc loc, Loc endloc, Parameters *arguments, int v Dsymbol *NewDeclaration::syntaxCopy(Dsymbol *s) { - NewDeclaration *f; - - f = new NewDeclaration(loc, endloc, NULL, varargs); - - FuncDeclaration::syntaxCopy(f); - + assert(!s); + NewDeclaration *f = new NewDeclaration(loc, endloc, NULL, varargs); f->arguments = Parameter::arraySyntaxCopy(arguments); - - return f; + return FuncDeclaration::syntaxCopy(f); } - void NewDeclaration::semantic(Scope *sc) { //printf("NewDeclaration::semantic()\n"); if (scope) - { sc = scope; + { + sc = scope; scope = NULL; } @@ -5028,24 +5007,19 @@ DeleteDeclaration::DeleteDeclaration(Loc loc, Loc endloc, Parameters *arguments) Dsymbol *DeleteDeclaration::syntaxCopy(Dsymbol *s) { - DeleteDeclaration *f; - - f = new DeleteDeclaration(loc, endloc, NULL); - - FuncDeclaration::syntaxCopy(f); - + assert(!s); + DeleteDeclaration *f = new DeleteDeclaration(loc, endloc, NULL); f->arguments = Parameter::arraySyntaxCopy(arguments); - - return f; + return FuncDeclaration::syntaxCopy(f); } - void DeleteDeclaration::semantic(Scope *sc) { //printf("DeleteDeclaration::semantic()\n"); if (scope) - { sc = scope; + { + sc = scope; scope = NULL; } diff --git a/src/init.c b/src/init.c index 1f3380a511e0..89ad35c496a3 100644 --- a/src/init.c +++ b/src/init.c @@ -40,11 +40,7 @@ Initializers *Initializer::arraySyntaxCopy(Initializers *ai) a = new Initializers(); a->setDim(ai->dim); for (size_t i = 0; i < a->dim; i++) - { - Initializer *e = (*ai)[i]; - e = e->syntaxCopy(); - (*a)[i] = e; - } + (*a)[i] = (*ai)[i]->syntaxCopy(); } return a; } @@ -126,17 +122,13 @@ StructInitializer::StructInitializer(Loc loc) Initializer *StructInitializer::syntaxCopy() { StructInitializer *ai = new StructInitializer(loc); - assert(field.dim == value.dim); ai->field.setDim(field.dim); ai->value.setDim(value.dim); for (size_t i = 0; i < field.dim; i++) { ai->field[i] = field[i]; - - Initializer *iz = value[i]; - iz = iz->syntaxCopy(); - ai->value[i] = iz; + ai->value[i] = value[i]->syntaxCopy(); } return ai; } @@ -308,22 +300,14 @@ ArrayInitializer::ArrayInitializer(Loc loc) Initializer *ArrayInitializer::syntaxCopy() { //printf("ArrayInitializer::syntaxCopy()\n"); - ArrayInitializer *ai = new ArrayInitializer(loc); - assert(index.dim == value.dim); ai->index.setDim(index.dim); ai->value.setDim(value.dim); for (size_t i = 0; i < ai->value.dim; i++) { - Expression *e = index[i]; - if (e) - e = e->syntaxCopy(); - ai->index[i] = e; - - Initializer *iz = value[i]; - iz = iz->syntaxCopy(); - ai->value[i] = iz; + ai->index[i] = index[i] ? index[i]->syntaxCopy() : NULL; + ai->value[i] = value[i]->syntaxCopy(); } return ai; } diff --git a/src/mtype.c b/src/mtype.c index cea114f1b363..beba206bfbfd 100644 --- a/src/mtype.c +++ b/src/mtype.c @@ -3004,7 +3004,6 @@ Type *TypeBasic::syntaxCopy() return this; } - char *TypeBasic::toChars() { return Type::toChars(); @@ -4416,7 +4415,8 @@ Type *TypeDArray::syntaxCopy() if (t == next) t = this; else - { t = new TypeDArray(t); + { + t = new TypeDArray(t); t->mod = mod; } return t; @@ -4635,7 +4635,8 @@ Type *TypeAArray::syntaxCopy() if (t == next && ti == index) t = this; else - { t = new TypeAArray(t, ti); + { + t = new TypeAArray(t, ti); t->mod = mod; } return t; @@ -4646,7 +4647,6 @@ d_uns64 TypeAArray::size(Loc loc) return Target::ptrsize; } - Type *TypeAArray::semantic(Loc loc, Scope *sc) { //printf("TypeAArray::semantic() %s index->ty = %d\n", toChars(), index->ty); @@ -4998,7 +4998,8 @@ Type *TypePointer::syntaxCopy() if (t == next) t = this; else - { t = new TypePointer(t); + { + t = new TypePointer(t); t->mod = mod; } return t; @@ -5169,7 +5170,8 @@ Type *TypeReference::syntaxCopy() if (t == next) t = this; else - { t = new TypeReference(t); + { + t = new TypeReference(t); t->mod = mod; } return t; @@ -6335,7 +6337,8 @@ Type *TypeDelegate::syntaxCopy() if (t == next) t = this; else - { t = new TypeDelegate(t); + { + t = new TypeDelegate(t); t->mod = mod; } return t; @@ -6481,7 +6484,6 @@ void TypeQualified::syntaxCopyHelper(TypeQualified *t) } } - void TypeQualified::addIdent(Identifier *ident) { idents.push(ident); @@ -6742,12 +6744,9 @@ const char *TypeIdentifier::kind() return "identifier"; } - Type *TypeIdentifier::syntaxCopy() { - TypeIdentifier *t; - - t = new TypeIdentifier(loc, ident); + TypeIdentifier *t = new TypeIdentifier(loc, ident); t->syntaxCopyHelper(this); t->mod = mod; return t; @@ -6920,9 +6919,7 @@ const char *TypeInstance::kind() Type *TypeInstance::syntaxCopy() { //printf("TypeInstance::syntaxCopy() %s, %d\n", toChars(), idents.dim); - TypeInstance *t; - - t = new TypeInstance(loc, (TemplateInstance *)tempinst->syntaxCopy(NULL)); + TypeInstance *t = new TypeInstance(loc, (TemplateInstance *)tempinst->syntaxCopy(NULL)); t->syntaxCopyHelper(this); t->mod = mod; return t; @@ -7042,9 +7039,7 @@ const char *TypeTypeof::kind() Type *TypeTypeof::syntaxCopy() { //printf("TypeTypeof::syntaxCopy() %s\n", toChars()); - TypeTypeof *t; - - t = new TypeTypeof(loc, exp->syntaxCopy()); + TypeTypeof *t = new TypeTypeof(loc, exp->syntaxCopy()); t->syntaxCopyHelper(this); t->mod = mod; return t; @@ -9351,26 +9346,21 @@ Parameter *Parameter::create(StorageClass storageClass, Type *type, Identifier * Parameter *Parameter::syntaxCopy() { - Parameter *a = new Parameter(storageClass, - type ? type->syntaxCopy() : NULL, - ident, - defaultArg ? defaultArg->syntaxCopy() : NULL); - return a; + return new Parameter(storageClass, + type ? type->syntaxCopy() : NULL, + ident, + defaultArg ? defaultArg->syntaxCopy() : NULL); } Parameters *Parameter::arraySyntaxCopy(Parameters *args) -{ Parameters *a = NULL; - +{ + Parameters *a = NULL; if (args) { a = new Parameters(); a->setDim(args->dim); for (size_t i = 0; i < a->dim; i++) - { Parameter *arg = (*args)[i]; - - arg = arg->syntaxCopy(); - (*a)[i] = arg; - } + (*a)[i] = (*args)[i]->syntaxCopy(); } return a; } diff --git a/src/nspace.c b/src/nspace.c index 299851788a09..699354f17355 100644 --- a/src/nspace.c +++ b/src/nspace.c @@ -30,8 +30,7 @@ Nspace::Nspace(Loc loc, Identifier *ident, Dsymbols *members) Dsymbol *Nspace::syntaxCopy(Dsymbol *s) { Nspace *ns = new Nspace(loc, ident, NULL); - ScopeDsymbol::syntaxCopy(ns); - return ns; + return ScopeDsymbol::syntaxCopy(ns); } void Nspace::semantic(Scope *sc) diff --git a/src/statement.c b/src/statement.c index e322cee3b874..a49bf78cb849 100644 --- a/src/statement.c +++ b/src/statement.c @@ -801,9 +801,7 @@ ExpStatement *ExpStatement::create(Loc loc, Expression *exp) Statement *ExpStatement::syntaxCopy() { - Expression *e = exp ? exp->syntaxCopy() : NULL; - ExpStatement *es = new ExpStatement(loc, e); - return es; + return new ExpStatement(loc, exp ? exp->syntaxCopy() : NULL); } Statement *ExpStatement::semantic(Scope *sc) @@ -900,9 +898,7 @@ DtorExpStatement::DtorExpStatement(Loc loc, Expression *exp, VarDeclaration *v) Statement *DtorExpStatement::syntaxCopy() { - Expression *e = exp ? exp->syntaxCopy() : NULL; - DtorExpStatement *es = new DtorExpStatement(loc, e, var); - return es; + return new DtorExpStatement(loc, exp ? exp->syntaxCopy() : NULL, var); } /******************************** CompileStatement ***************************/ @@ -915,9 +911,7 @@ CompileStatement::CompileStatement(Loc loc, Expression *exp) Statement *CompileStatement::syntaxCopy() { - Expression *e = exp->syntaxCopy(); - CompileStatement *es = new CompileStatement(loc, e); - return es; + return new CompileStatement(loc, exp->syntaxCopy()); } Statements *CompileStatement::flatten(Scope *sc) @@ -1001,16 +995,13 @@ Statement *CompoundStatement::syntaxCopy() Statements *a = new Statements(); a->setDim(statements->dim); for (size_t i = 0; i < statements->dim; i++) - { Statement *s = (*statements)[i]; - if (s) - s = s->syntaxCopy(); - (*a)[i] = s; + { + Statement *s = (*statements)[i]; + (*a)[i] = s ? s->syntaxCopy() : NULL; } - CompoundStatement *cs = new CompoundStatement(loc, a); - return cs; + return new CompoundStatement(loc, a); } - Statement *CompoundStatement::semantic(Scope *sc) { //printf("CompoundStatement::semantic(this = %p, sc = %p)\n", this, sc); @@ -1220,13 +1211,11 @@ Statement *CompoundDeclarationStatement::syntaxCopy() Statements *a = new Statements(); a->setDim(statements->dim); for (size_t i = 0; i < statements->dim; i++) - { Statement *s = (*statements)[i]; - if (s) - s = s->syntaxCopy(); - (*a)[i] = s; + { + Statement *s = (*statements)[i]; + (*a)[i] = s ? s->syntaxCopy() : NULL; } - CompoundDeclarationStatement *cs = new CompoundDeclarationStatement(loc, a); - return cs; + return new CompoundDeclarationStatement(loc, a); } /**************************** UnrolledLoopStatement ***************************/ @@ -1242,16 +1231,13 @@ Statement *UnrolledLoopStatement::syntaxCopy() Statements *a = new Statements(); a->setDim(statements->dim); for (size_t i = 0; i < statements->dim; i++) - { Statement *s = (*statements)[i]; - if (s) - s = s->syntaxCopy(); - (*a)[i] = s; + { + Statement *s = (*statements)[i]; + (*a)[i] = s ? s->syntaxCopy() : NULL; } - UnrolledLoopStatement *cs = new UnrolledLoopStatement(loc, a); - return cs; + return new UnrolledLoopStatement(loc, a); } - Statement *UnrolledLoopStatement::semantic(Scope *sc) { //printf("UnrolledLoopStatement::semantic(this = %p, sc = %p)\n", this, sc); @@ -1298,11 +1284,7 @@ ScopeStatement::ScopeStatement(Loc loc, Statement *s) Statement *ScopeStatement::syntaxCopy() { - Statement *s; - - s = statement ? statement->syntaxCopy() : NULL; - s = new ScopeStatement(loc, s); - return s; + return new ScopeStatement(loc, statement ? statement->syntaxCopy() : NULL); } ReturnStatement *ScopeStatement::isReturnStatement() @@ -1379,11 +1361,11 @@ WhileStatement::WhileStatement(Loc loc, Expression *c, Statement *b) Statement *WhileStatement::syntaxCopy() { - WhileStatement *s = new WhileStatement(loc, condition->syntaxCopy(), body ? body->syntaxCopy() : NULL); - return s; + return new WhileStatement(loc, + condition->syntaxCopy(), + body ? body->syntaxCopy() : NULL); } - Statement *WhileStatement::semantic(Scope *sc) { /* Rewrite as a for(;condition;) loop @@ -1415,11 +1397,11 @@ DoStatement::DoStatement(Loc loc, Statement *b, Expression *c) Statement *DoStatement::syntaxCopy() { - DoStatement *s = new DoStatement(loc, body ? body->syntaxCopy() : NULL, condition->syntaxCopy()); - return s; + return new DoStatement(loc, + body ? body->syntaxCopy() : NULL, + condition->syntaxCopy()); } - Statement *DoStatement::semantic(Scope *sc) { sc->noctor++; @@ -1466,17 +1448,11 @@ ForStatement::ForStatement(Loc loc, Statement *init, Expression *condition, Expr Statement *ForStatement::syntaxCopy() { - Statement *i = NULL; - if (init) - i = init->syntaxCopy(); - Expression *c = NULL; - if (condition) - c = condition->syntaxCopy(); - Expression *inc = NULL; - if (increment) - inc = increment->syntaxCopy(); - ForStatement *s = new ForStatement(loc, i, c, inc, body->syntaxCopy()); - return s; + return new ForStatement(loc, + init ? init->syntaxCopy() : NULL, + condition ? condition->syntaxCopy() : NULL, + increment ? increment->syntaxCopy() : NULL, + body->syntaxCopy()); } Statement *ForStatement::semantic(Scope *sc) @@ -1591,11 +1567,10 @@ ForeachStatement::ForeachStatement(Loc loc, TOK op, Parameters *arguments, Statement *ForeachStatement::syntaxCopy() { - Parameters *args = Parameter::arraySyntaxCopy(arguments); - Expression *exp = aggr->syntaxCopy(); - ForeachStatement *s = new ForeachStatement(loc, op, args, exp, + return new ForeachStatement(loc, op, + Parameter::arraySyntaxCopy(arguments), + aggr->syntaxCopy(), body ? body->syntaxCopy() : NULL); - return s; } Statement *ForeachStatement::semantic(Scope *sc) @@ -2588,12 +2563,11 @@ ForeachRangeStatement::ForeachRangeStatement(Loc loc, TOK op, Parameter *arg, Statement *ForeachRangeStatement::syntaxCopy() { - ForeachRangeStatement *s = new ForeachRangeStatement(loc, op, + return new ForeachRangeStatement(loc, op, arg->syntaxCopy(), lwr->syntaxCopy(), upr->syntaxCopy(), body ? body->syntaxCopy() : NULL); - return s; } Statement *ForeachRangeStatement::semantic(Scope *sc) @@ -2803,17 +2777,11 @@ IfStatement::IfStatement(Loc loc, Parameter *arg, Expression *condition, Stateme Statement *IfStatement::syntaxCopy() { - Statement *i = NULL; - if (ifbody) - i = ifbody->syntaxCopy(); - - Statement *e = NULL; - if (elsebody) - e = elsebody->syntaxCopy(); - - Parameter *a = arg ? arg->syntaxCopy() : NULL; - IfStatement *s = new IfStatement(loc, a, condition->syntaxCopy(), i, e); - return s; + return new IfStatement(loc, + arg ? arg->syntaxCopy() : NULL, + condition->syntaxCopy(), + ifbody ? ifbody->syntaxCopy() : NULL, + elsebody ? elsebody->syntaxCopy() : NULL); } Statement *IfStatement::semantic(Scope *sc) @@ -2900,12 +2868,10 @@ ConditionalStatement::ConditionalStatement(Loc loc, Condition *condition, Statem Statement *ConditionalStatement::syntaxCopy() { - Statement *e = NULL; - if (elsebody) - e = elsebody->syntaxCopy(); - ConditionalStatement *s = new ConditionalStatement(loc, - condition->syntaxCopy(), ifbody->syntaxCopy(), e); - return s; + return new ConditionalStatement(loc, + condition->syntaxCopy(), + ifbody->syntaxCopy(), + elsebody ? elsebody->syntaxCopy() : NULL); } Statement *ConditionalStatement::semantic(Scope *sc) @@ -2970,16 +2936,14 @@ PragmaStatement::PragmaStatement(Loc loc, Identifier *ident, Expressions *args, Statement *PragmaStatement::syntaxCopy() { - Statement *b = NULL; - if (body) - b = body->syntaxCopy(); - PragmaStatement *s = new PragmaStatement(loc, - ident, Expression::arraySyntaxCopy(args), b); - return s; + return new PragmaStatement(loc, ident, + Expression::arraySyntaxCopy(args), + body ? body->syntaxCopy() : NULL); } Statement *PragmaStatement::semantic(Scope *sc) -{ // Should be merged with PragmaDeclaration +{ + // Should be merged with PragmaDeclaration //printf("PragmaStatement::semantic() %s\n", toChars()); //printf("body = %p\n", body); if (ident == Id::msg) @@ -3091,8 +3055,7 @@ StaticAssertStatement::StaticAssertStatement(StaticAssert *sa) Statement *StaticAssertStatement::syntaxCopy() { - StaticAssertStatement *s = new StaticAssertStatement((StaticAssert *)sa->syntaxCopy(NULL)); - return s; + return new StaticAssertStatement((StaticAssert *)sa->syntaxCopy(NULL)); } Statement *StaticAssertStatement::semantic(Scope *sc) @@ -3118,10 +3081,10 @@ SwitchStatement::SwitchStatement(Loc loc, Expression *c, Statement *b, bool isFi Statement *SwitchStatement::syntaxCopy() { - //printf("SwitchStatement::syntaxCopy(%p)\n", this); - SwitchStatement *s = new SwitchStatement(loc, - condition->syntaxCopy(), body->syntaxCopy(), isFinal); - return s; + return new SwitchStatement(loc, + condition->syntaxCopy(), + body->syntaxCopy(), + isFinal); } Statement *SwitchStatement::semantic(Scope *sc) @@ -3284,8 +3247,9 @@ CaseStatement::CaseStatement(Loc loc, Expression *exp, Statement *s) Statement *CaseStatement::syntaxCopy() { - CaseStatement *s = new CaseStatement(loc, exp->syntaxCopy(), statement->syntaxCopy()); - return s; + return new CaseStatement(loc, + exp->syntaxCopy(), + statement->syntaxCopy()); } Statement *CaseStatement::semantic(Scope *sc) @@ -3386,9 +3350,10 @@ CaseRangeStatement::CaseRangeStatement(Loc loc, Expression *first, Statement *CaseRangeStatement::syntaxCopy() { - CaseRangeStatement *s = new CaseRangeStatement(loc, - first->syntaxCopy(), last->syntaxCopy(), statement->syntaxCopy()); - return s; + return new CaseRangeStatement(loc, + first->syntaxCopy(), + last->syntaxCopy(), + statement->syntaxCopy()); } Statement *CaseRangeStatement::semantic(Scope *sc) @@ -3476,8 +3441,7 @@ DefaultStatement::DefaultStatement(Loc loc, Statement *s) Statement *DefaultStatement::syntaxCopy() { - DefaultStatement *s = new DefaultStatement(loc, statement->syntaxCopy()); - return s; + return new DefaultStatement(loc, statement->syntaxCopy()); } Statement *DefaultStatement::semantic(Scope *sc) @@ -3513,8 +3477,7 @@ GotoDefaultStatement::GotoDefaultStatement(Loc loc) Statement *GotoDefaultStatement::syntaxCopy() { - GotoDefaultStatement *s = new GotoDefaultStatement(loc); - return s; + return new GotoDefaultStatement(loc); } Statement *GotoDefaultStatement::semantic(Scope *sc) @@ -3536,9 +3499,7 @@ GotoCaseStatement::GotoCaseStatement(Loc loc, Expression *exp) Statement *GotoCaseStatement::syntaxCopy() { - Expression *e = exp ? exp->syntaxCopy() : NULL; - GotoCaseStatement *s = new GotoCaseStatement(loc, e); - return s; + return new GotoCaseStatement(loc, exp ? exp->syntaxCopy() : NULL); } Statement *GotoCaseStatement::semantic(Scope *sc) @@ -3578,11 +3539,7 @@ ReturnStatement::ReturnStatement(Loc loc, Expression *exp) Statement *ReturnStatement::syntaxCopy() { - Expression *e = NULL; - if (exp) - e = exp->syntaxCopy(); - ReturnStatement *s = new ReturnStatement(loc, e); - return s; + return new ReturnStatement(loc, exp ? exp->syntaxCopy() : NULL); } Statement *ReturnStatement::semantic(Scope *sc) @@ -3963,8 +3920,7 @@ BreakStatement::BreakStatement(Loc loc, Identifier *ident) Statement *BreakStatement::syntaxCopy() { - BreakStatement *s = new BreakStatement(loc, ident); - return s; + return new BreakStatement(loc, ident); } Statement *BreakStatement::semantic(Scope *sc) @@ -4044,8 +4000,7 @@ ContinueStatement::ContinueStatement(Loc loc, Identifier *ident) Statement *ContinueStatement::syntaxCopy() { - ContinueStatement *s = new ContinueStatement(loc, ident); - return s; + return new ContinueStatement(loc, ident); } Statement *ContinueStatement::semantic(Scope *sc) @@ -4137,9 +4092,9 @@ SynchronizedStatement::SynchronizedStatement(Loc loc, Expression *exp, Statement Statement *SynchronizedStatement::syntaxCopy() { - Expression *e = exp ? exp->syntaxCopy() : NULL; - SynchronizedStatement *s = new SynchronizedStatement(loc, e, body ? body->syntaxCopy() : NULL); - return s; + return new SynchronizedStatement(loc, + exp ? exp->syntaxCopy() : NULL, + body ? body->syntaxCopy() : NULL); } Statement *SynchronizedStatement::semantic(Scope *sc) @@ -4283,12 +4238,14 @@ WithStatement::WithStatement(Loc loc, Expression *exp, Statement *body) Statement *WithStatement::syntaxCopy() { - WithStatement *s = new WithStatement(loc, exp->syntaxCopy(), body ? body->syntaxCopy() : NULL); - return s; + return new WithStatement(loc, + exp->syntaxCopy(), + body ? body->syntaxCopy() : NULL); } Statement *WithStatement::semantic(Scope *sc) -{ ScopeDsymbol *sym; +{ + ScopeDsymbol *sym; Initializer *init; //printf("WithStatement::semantic()\n"); @@ -4404,11 +4361,9 @@ Statement *TryCatchStatement::syntaxCopy() for (size_t i = 0; i < a->dim; i++) { Catch *c = (*catches)[i]; - c = c->syntaxCopy(); - (*a)[i] = c; + (*a)[i] = c->syntaxCopy(); } - TryCatchStatement *s = new TryCatchStatement(loc, body->syntaxCopy(), a); - return s; + return new TryCatchStatement(loc, body->syntaxCopy(), a); } Statement *TryCatchStatement::semantic(Scope *sc) @@ -4493,7 +4448,7 @@ Catch::Catch(Loc loc, Type *t, Identifier *id, Statement *handler) Catch *Catch::syntaxCopy() { Catch *c = new Catch(loc, - (type ? type->syntaxCopy() : NULL), + type ? type->syntaxCopy() : NULL, ident, (handler ? handler->syntaxCopy() : NULL)); c->internalCatch = internalCatch; @@ -4581,9 +4536,8 @@ TryFinallyStatement *TryFinallyStatement::create(Loc loc, Statement *body, State Statement *TryFinallyStatement::syntaxCopy() { - TryFinallyStatement *s = new TryFinallyStatement(loc, + return new TryFinallyStatement(loc, body->syntaxCopy(), finalbody->syntaxCopy()); - return s; } Statement *TryFinallyStatement::semantic(Scope *sc) @@ -4629,9 +4583,7 @@ OnScopeStatement::OnScopeStatement(Loc loc, TOK tok, Statement *statement) Statement *OnScopeStatement::syntaxCopy() { - OnScopeStatement *s = new OnScopeStatement(loc, - tok, statement->syntaxCopy()); - return s; + return new OnScopeStatement(loc, tok, statement->syntaxCopy()); } Statement *OnScopeStatement::semantic(Scope *sc) @@ -4772,9 +4724,8 @@ DebugStatement::DebugStatement(Loc loc, Statement *statement) Statement *DebugStatement::syntaxCopy() { - DebugStatement *s = new DebugStatement(loc, - statement ? statement->syntaxCopy() : NULL); - return s; + return new DebugStatement(loc, + statement ? statement->syntaxCopy() : NULL); } Statement *DebugStatement::semantic(Scope *sc) @@ -4820,8 +4771,7 @@ GotoStatement::GotoStatement(Loc loc, Identifier *ident) Statement *GotoStatement::syntaxCopy() { - GotoStatement *s = new GotoStatement(loc, ident); - return s; + return new GotoStatement(loc, ident); } Statement *GotoStatement::semantic(Scope *sc) @@ -4933,8 +4883,7 @@ LabelStatement::LabelStatement(Loc loc, Identifier *ident, Statement *statement) Statement *LabelStatement::syntaxCopy() { - LabelStatement *s = new LabelStatement(loc, ident, statement ? statement->syntaxCopy() : NULL); - return s; + return new LabelStatement(loc, ident, statement ? statement->syntaxCopy() : NULL); } Statement *LabelStatement::semantic(Scope *sc) diff --git a/src/staticassert.c b/src/staticassert.c index 4d6365cb4adb..6c46ab05aae7 100644 --- a/src/staticassert.c +++ b/src/staticassert.c @@ -34,11 +34,8 @@ StaticAssert::StaticAssert(Loc loc, Expression *exp, Expression *msg) Dsymbol *StaticAssert::syntaxCopy(Dsymbol *s) { - StaticAssert *sa; - assert(!s); - sa = new StaticAssert(loc, exp->syntaxCopy(), msg ? msg->syntaxCopy() : NULL); - return sa; + return new StaticAssert(loc, exp->syntaxCopy(), msg ? msg->syntaxCopy() : NULL); } int StaticAssert::addMember(Scope *sc, ScopeDsymbol *sds, int memnum) diff --git a/src/struct.c b/src/struct.c index 5de15f03d427..0768ddb82702 100644 --- a/src/struct.c +++ b/src/struct.c @@ -640,14 +640,10 @@ StructDeclaration::StructDeclaration(Loc loc, Identifier *id) Dsymbol *StructDeclaration::syntaxCopy(Dsymbol *s) { - StructDeclaration *sd; - - if (s) - sd = (StructDeclaration *)s; - else - sd = new StructDeclaration(loc, ident); - ScopeDsymbol::syntaxCopy(sd); - return sd; + StructDeclaration *sd = + s ? (StructDeclaration *)s + : new StructDeclaration(loc, ident); + return ScopeDsymbol::syntaxCopy(sd); } void StructDeclaration::semantic(Scope *sc) @@ -1234,17 +1230,11 @@ UnionDeclaration::UnionDeclaration(Loc loc, Identifier *id) Dsymbol *UnionDeclaration::syntaxCopy(Dsymbol *s) { - UnionDeclaration *ud; - - if (s) - ud = (UnionDeclaration *)s; - else - ud = new UnionDeclaration(loc, ident); - StructDeclaration::syntaxCopy(ud); - return ud; + assert(!s); + UnionDeclaration *ud = new UnionDeclaration(loc, ident); + return StructDeclaration::syntaxCopy(ud); } - const char *UnionDeclaration::kind() { return "union"; diff --git a/src/template.c b/src/template.c index 7d29a35075cb..e87200e757ce 100644 --- a/src/template.c +++ b/src/template.c @@ -406,11 +406,9 @@ RootObject *objectSyntaxCopy(RootObject *o) { if (!o) return NULL; - Type *t = isType(o); - if (t) + if (Type *t = isType(o)) return t->syntaxCopy(); - Expression *e = isExpression(o); - if (e) + if (Expression *e = isExpression(o)) return e->syntaxCopy(); return o; } @@ -471,26 +469,17 @@ TemplateDeclaration::TemplateDeclaration(Loc loc, Identifier *id, Dsymbol *TemplateDeclaration::syntaxCopy(Dsymbol *) { //printf("TemplateDeclaration::syntaxCopy()\n"); - TemplateDeclaration *td; - TemplateParameters *p; - - p = NULL; + TemplateParameters *p = NULL; if (parameters) { p = new TemplateParameters(); p->setDim(parameters->dim); for (size_t i = 0; i < p->dim; i++) - { - TemplateParameter *tp = (*parameters)[i]; - (*p)[i] = tp->syntaxCopy(); - } + (*p)[i] = (*parameters)[i]->syntaxCopy(); } - Expression *e = NULL; - if (constraint) - e = constraint->syntaxCopy(); - Dsymbols *d = Dsymbol::arraySyntaxCopy(members); - td = new TemplateDeclaration(loc, ident, p, e, d, ismixin, literal); - return td; + return new TemplateDeclaration(loc, ident, p, + constraint ? constraint->syntaxCopy() : NULL, + Dsymbol::arraySyntaxCopy(members), ismixin, literal); } void TemplateDeclaration::semantic(Scope *sc) @@ -4682,12 +4671,9 @@ TemplateTypeParameter *TemplateTypeParameter::isTemplateTypeParameter() TemplateParameter *TemplateTypeParameter::syntaxCopy() { - TemplateTypeParameter *tp = new TemplateTypeParameter(loc, ident, specType, defaultType); - if (tp->specType) - tp->specType = specType->syntaxCopy(); - if (defaultType) - tp->defaultType = defaultType->syntaxCopy(); - return tp; + return new TemplateTypeParameter(loc, ident, + specType ? specType->syntaxCopy() : NULL, + defaultType ? defaultType->syntaxCopy() : NULL); } void TemplateTypeParameter::declareParameter(Scope *sc) @@ -4878,12 +4864,9 @@ TemplateThisParameter *TemplateThisParameter::isTemplateThisParameter() TemplateParameter *TemplateThisParameter::syntaxCopy() { - TemplateThisParameter *tp = new TemplateThisParameter(loc, ident, specType, defaultType); - if (tp->specType) - tp->specType = specType->syntaxCopy(); - if (defaultType) - tp->defaultType = defaultType->syntaxCopy(); - return tp; + return new TemplateThisParameter(loc, ident, + specType ? specType->syntaxCopy() : NULL, + defaultType ? defaultType->syntaxCopy() : NULL); } /* ======================== TemplateAliasParameter ========================== */ @@ -4909,12 +4892,10 @@ TemplateAliasParameter *TemplateAliasParameter::isTemplateAliasParameter() TemplateParameter *TemplateAliasParameter::syntaxCopy() { - TemplateAliasParameter *tp = new TemplateAliasParameter(loc, ident, specType, specAlias, defaultAlias); - if (tp->specType) - tp->specType = specType->syntaxCopy(); - tp->specAlias = objectSyntaxCopy(specAlias); - tp->defaultAlias = objectSyntaxCopy(defaultAlias); - return tp; + return new TemplateAliasParameter(loc, ident, + specType ? specType->syntaxCopy() : NULL, + objectSyntaxCopy(specAlias), + objectSyntaxCopy(defaultAlias)); } void TemplateAliasParameter::declareParameter(Scope *sc) @@ -5182,14 +5163,10 @@ TemplateValueParameter *TemplateValueParameter::isTemplateValueParameter() TemplateParameter *TemplateValueParameter::syntaxCopy() { - TemplateValueParameter *tp = - new TemplateValueParameter(loc, ident, valType, specValue, defaultValue); - tp->valType = valType->syntaxCopy(); - if (specValue) - tp->specValue = specValue->syntaxCopy(); - if (defaultValue) - tp->defaultValue = defaultValue->syntaxCopy(); - return tp; + return new TemplateValueParameter(loc, ident, + valType->syntaxCopy(), + specValue ? specValue->syntaxCopy() : NULL, + defaultValue ? defaultValue->syntaxCopy() : NULL); } void TemplateValueParameter::declareParameter(Scope *sc) @@ -5444,8 +5421,7 @@ TemplateTupleParameter *TemplateTupleParameter::isTemplateTupleParameter() TemplateParameter *TemplateTupleParameter::syntaxCopy() { - TemplateTupleParameter *tp = new TemplateTupleParameter(loc, ident); - return tp; + return new TemplateTupleParameter(loc, ident); } void TemplateTupleParameter::declareParameter(Scope *sc) @@ -5652,24 +5628,17 @@ Objects *TemplateInstance::arraySyntaxCopy(Objects *objs) a = new Objects(); a->setDim(objs->dim); for (size_t i = 0; i < objs->dim; i++) - { (*a)[i] = objectSyntaxCopy((*objs)[i]); - } } return a; } Dsymbol *TemplateInstance::syntaxCopy(Dsymbol *s) { - TemplateInstance *ti; - - if (s) - ti = (TemplateInstance *)s; - else - ti = new TemplateInstance(loc, name); - + TemplateInstance *ti = + s ? (TemplateInstance *)s + : new TemplateInstance(loc, name); ti->tiargs = arraySyntaxCopy(tiargs); - TemplateDeclaration *td; if (inst && tempdecl && (td = tempdecl->isTemplateDeclaration()) != NULL) td->ScopeDsymbol::syntaxCopy(ti); @@ -5678,7 +5647,6 @@ Dsymbol *TemplateInstance::syntaxCopy(Dsymbol *s) return ti; } - void TemplateInstance::semantic(Scope *sc) { semantic(sc, NULL); @@ -7794,8 +7762,7 @@ Dsymbol *TemplateMixin::syntaxCopy(Dsymbol *s) { TemplateMixin *tm = new TemplateMixin(loc, ident, (TypeQualified *)tqual->syntaxCopy(), tiargs); - TemplateInstance::syntaxCopy(tm); - return tm; + return TemplateInstance::syntaxCopy(tm); } bool TemplateMixin::findTempDecl(Scope *sc)