Skip to content

Commit

Permalink
Merge pull request #3886 from 9rnsr/refactor_syntaxCopy
Browse files Browse the repository at this point in the history
[Refactoring] Clean up syntaxCopy functions
  • Loading branch information
yebblies committed Aug 22, 2014
2 parents 7f28fa6 + c9f08d7 commit c6cf84f
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 504 deletions.
51 changes: 14 additions & 37 deletions src/attrib.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 8 additions & 17 deletions src/class.c
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
45 changes: 13 additions & 32 deletions src/declaration.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 2 additions & 12 deletions src/dsymbol.c
Expand Up @@ -766,7 +766,6 @@ PROT Dsymbol::prot()
* Do syntax copy of an array of Dsymbol's.
*/


Dsymbols *Dsymbol::arraySyntaxCopy(Dsymbols *a)
{

Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
51 changes: 8 additions & 43 deletions src/enum.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c6cf84f

Please sign in to comment.