Skip to content

Commit

Permalink
[Refactoring] for StructDeclaration::buildCpCtor
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed May 10, 2013
1 parent cfb631d commit 58e903b
Showing 1 changed file with 38 additions and 44 deletions.
82 changes: 38 additions & 44 deletions src/clone.c
Expand Up @@ -455,61 +455,55 @@ FuncDeclaration *StructDeclaration::buildXopEquals(Scope *sc)

FuncDeclaration *StructDeclaration::buildCpCtor(Scope *sc)
{
//printf("StructDeclaration::buildCpCtor() %s\n", toChars());
FuncDeclaration *fcp = NULL;

/* Copy constructor is only necessary if there is a postblit function,
* otherwise the code generator will just do a bit copy.
*/
if (postblit)
{
//printf("generating cpctor\n");
if (!postblit)
return NULL;

StorageClass stc = postblit->storage_class &
(STCdisable | STCsafe | STCtrusted | STCsystem | STCpure | STCnothrow);
if (stc & (STCsafe | STCtrusted))
stc = stc & ~STCsafe | STCtrusted;
//printf("StructDeclaration::buildCpCtor() %s\n", toChars());
StorageClass stc = postblit->storage_class &
(STCdisable | STCsafe | STCtrusted | STCsystem | STCpure | STCnothrow);
if (stc & (STCsafe | STCtrusted))
stc = stc & ~STCsafe | STCtrusted;

Parameters *fparams = new Parameters;
fparams->push(new Parameter(STCref, type->constOf(), Id::p, NULL));
Type *ftype = new TypeFunction(fparams, Type::tvoid, FALSE, LINKd, stc);
ftype->mod = MODconst;
Parameters *fparams = new Parameters;
fparams->push(new Parameter(STCref, type->constOf(), Id::p, NULL));
Type *ftype = new TypeFunction(fparams, Type::tvoid, 0, LINKd, stc);
ftype->mod = MODconst;

fcp = new FuncDeclaration(loc, 0, Id::cpctor, stc, ftype);
FuncDeclaration *fcp = new FuncDeclaration(loc, 0, Id::cpctor, stc, ftype);

if (!(fcp->storage_class & STCdisable))
{
// Build *this = p;
Expression *e = new ThisExp(0);
AssignExp *ea = new AssignExp(0,
new PtrExp(0, new CastExp(0, new AddrExp(0, e), type->mutableOf()->pointerTo())),
new PtrExp(0, new CastExp(0, new AddrExp(0, new IdentifierExp(0, Id::p)), type->mutableOf()->pointerTo()))
);
ea->op = TOKblit;
Statement *s = new ExpStatement(0, ea);

// Build postBlit();
e = new ThisExp(0);
e = new PtrExp(0, new CastExp(0, new AddrExp(0, e), type->mutableOf()->pointerTo()));
e = new DotVarExp(0, e, postblit, 0);
e = new CallExp(0, e);

s = new CompoundStatement(0, s, new ExpStatement(0, e));
fcp->fbody = s;
}
else
fcp->fbody = new ExpStatement(0, (Expression *)NULL);
if (!(fcp->storage_class & STCdisable))
{
// Build *this = p;
Expression *e = new ThisExp(0);
AssignExp *ea = new AssignExp(0,
new PtrExp(0, new CastExp(0, new AddrExp(0, e), type->mutableOf()->pointerTo())),
new PtrExp(0, new CastExp(0, new AddrExp(0, new IdentifierExp(0, Id::p)), type->mutableOf()->pointerTo()))
);
ea->op = TOKblit;
Statement *s = new ExpStatement(0, ea);

// Build postBlit();
e = new ThisExp(0);
e = new PtrExp(0, new CastExp(0, new AddrExp(0, e), type->mutableOf()->pointerTo()));
e = new DotVarExp(0, e, postblit, 0);
e = new CallExp(0, e);

s = new CompoundStatement(0, s, new ExpStatement(0, e));
fcp->fbody = s;
}

members->push(fcp);
members->push(fcp);

sc = sc->push();
sc->stc = 0;
sc->linkage = LINKd;
sc = sc->push();
sc->stc = 0;
sc->linkage = LINKd;

fcp->semantic(sc);
fcp->semantic(sc);

sc->pop();
}
sc->pop();

return fcp;
}
Expand Down

0 comments on commit 58e903b

Please sign in to comment.