Skip to content

Commit

Permalink
Merge branch 'master' of github.com:D-Programming-Language/dmd
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed May 4, 2013
2 parents 11a2966 + c69a605 commit 757135a
Show file tree
Hide file tree
Showing 59 changed files with 1,083 additions and 392 deletions.
7 changes: 1 addition & 6 deletions src/apply.c
Expand Up @@ -36,12 +36,7 @@ int Expression::apply(fp_t fp, void *param)
/******************************
* Perform apply() on an t if not null
*/
template<typename T>
int condApply(T* t, fp_t fp, void* param)
{
return t ? t->apply(fp, param) : 0;
}

#define condApply(t, fp, param) (t ? t->apply(fp, param) : 0)

int NewExp::apply(int (*fp)(Expression *, void *), void *param)
{
Expand Down
12 changes: 6 additions & 6 deletions src/attrib.c
Expand Up @@ -539,7 +539,7 @@ void StorageClassDeclaration::stcToCBuffer(OutBuffer *buf, StorageClass stc)
const char *p = stcToChars(tmp, stc);
if (!p)
break;
assert(strlen(p) < sizeof(tmp));
assert(strlen(p) < sizeof(tmp) / sizeof(tmp[0]));
buf->writestring(p);
buf->writeByte(' ');
}
Expand Down Expand Up @@ -971,7 +971,7 @@ void PragmaDeclaration::semantic(Scope *sc)
{
Expression *e = (*args)[i];

e = e->semantic(sc);
e = e->ctfeSemantic(sc);
e = resolveProperties(sc, e);
if (e->op != TOKerror && e->op != TOKtype)
e = e->ctfeInterpret();
Expand Down Expand Up @@ -999,7 +999,7 @@ void PragmaDeclaration::semantic(Scope *sc)
{
Expression *e = (*args)[0];

e = e->semantic(sc);
e = e->ctfeSemantic(sc);
e = resolveProperties(sc, e);
e = e->ctfeInterpret();
(*args)[0] = e;
Expand Down Expand Up @@ -1027,7 +1027,7 @@ void PragmaDeclaration::semantic(Scope *sc)
else
{
Expression *e = (*args)[0];
e = e->semantic(sc);
e = e->ctfeSemantic(sc);
e = resolveProperties(sc, e);
e = e->ctfeInterpret();
(*args)[0] = e;
Expand All @@ -1050,7 +1050,7 @@ void PragmaDeclaration::semantic(Scope *sc)
for (size_t i = 0; i < args->dim; i++)
{
Expression *e = (*args)[i];
e = e->semantic(sc);
e = e->ctfeSemantic(sc);
e = resolveProperties(sc, e);
e = e->ctfeInterpret();
if (i == 0)
Expand Down Expand Up @@ -1428,7 +1428,7 @@ int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
void CompileDeclaration::compileIt(Scope *sc)
{
//printf("CompileDeclaration::compileIt(loc = %d) %s\n", loc.linnum, exp->toChars());
exp = exp->semantic(sc);
exp = exp->ctfeSemantic(sc);
exp = resolveProperties(sc, exp);
exp = exp->ctfeInterpret();
StringExp *se = exp->toString();
Expand Down
9 changes: 9 additions & 0 deletions src/backend/cod3.c
Expand Up @@ -1696,6 +1696,15 @@ int jmpopcode(elem *e)
}

jp = jops[i][zero][op - OPle]; /* table starts with OPle */

/* Try to rewrite unsigned comparisons so they rely on just the Carry flag
*/
if (i == 1 && (jp == JA || jp == JBE) &&
(e->E2->Eoper != OPconst && e->E2->Eoper != OPrelconst))
{
jp = (jp == JA) ? JC : JNC;
}

L1:
#if DEBUG
if ((jp & 0xF0) != 0x70)
Expand Down
86 changes: 75 additions & 11 deletions src/backend/cod4.c
Expand Up @@ -783,6 +783,7 @@ code *cdaddass(elem *e,regm_t *pretregs)
regm_t varregm;
unsigned varreg;
unsigned cflags;
unsigned jop;

//printf("cdaddass(e=%p, *pretregs = %s)\n",e,regm_str(*pretregs));
op = e->Eoper;
Expand Down Expand Up @@ -1077,6 +1078,43 @@ code *cdaddass(elem *e,regm_t *pretregs)
c = cat(cr,cl);
retregs = 0; /* to trigger a bug if we attempt to use it */
}
else if ((op == OPaddass || op == OPminass) &&
sz <= REGSIZE &&
!e2->Ecount &&
((jop = jmpopcode(e2)) == JC || jop == JNC ||
(OTconv(e2->Eoper) && !e2->E1->Ecount && ((jop = jmpopcode(e2->E1)) == JC || jop == JNC)))
)
{
/* e1 += (x < y) ADC EA,0
* e1 -= (x < y) SBB EA,0
* e1 += (x >= y) SBB EA,-1
* e1 -= (x >= y) ADC EA,-1
*/
cl = getlvalue(&cs,e1,0); // get lvalue
cl = cat(cl,modEA(&cs));
regm_t keepmsk = idxregm(&cs);
retregs = mPSW;
if (OTconv(e2->Eoper))
{
cr = scodelem(e2->E1,&retregs,keepmsk,TRUE);
freenode(e2);
}
else
cr = scodelem(e2,&retregs,keepmsk,TRUE);
cs.Iop = 0x81 ^ byte; // ADC EA,imm16/32
unsigned reg = 2; // ADC
if ((op == OPaddass) ^ (jop == JC))
reg = 3; // SBB
code_newreg(&cs,reg);
cs.Iflags |= opsize;
if (forccs)
cs.Iflags |= CFpsw;
cs.IFL2 = FLconst;
cs.IEV2.Vsize_t = (jop == JC) ? 0 : ~(targ_size_t)0;
cr = gen(cr,&cs);
c = cat(cl,cr);
retregs = 0; /* to trigger a bug if we attempt to use it */
}
else // evaluate e2 into register
{
retregs = (byte) ? BYTEREGS : ALLREGS; // pick working reg
Expand Down Expand Up @@ -1732,12 +1770,11 @@ code *cdshass(elem *e,regm_t *pretregs)

code *cdcmp(elem *e,regm_t *pretregs)
{ regm_t retregs,rretregs;
unsigned reg,rreg,op,jop,byte;
unsigned reg,rreg,op,byte;
tym_t tym;
code *cl,*cr,*c,cs,*ce,*cg;
elem *e1,*e2;
bool eqorne;
unsigned reverse;
unsigned sz;
int fl;
int flag;
Expand All @@ -1756,9 +1793,10 @@ code *cdcmp(elem *e,regm_t *pretregs)
return cat(cl,cr);
}

jop = jmpopcode(e); // must be computed before
unsigned jop = jmpopcode(e); // must be computed before
// leaves are free'd
reverse = 0;
unsigned reverse = 0;

cl = cr = CNIL;
op = e->Eoper;
assert(OTrel(op));
Expand Down Expand Up @@ -1827,7 +1865,9 @@ code *cdcmp(elem *e,regm_t *pretregs)
(I16 && tym == TYlong && tybasic(e2->Ety) == TYlong ||
I32 && tym == TYllong && tybasic(e2->Ety) == TYllong)
)
{ retregs = mDX | mAX;
{
assert(jop != JC && jop != JNC);
retregs = mDX | mAX;
cl = codelem(e1,&retregs,FALSE);
retregs = mCX | mBX;
cr = scodelem(e2,&retregs,mDX | mAX,FALSE);
Expand Down Expand Up @@ -1868,11 +1908,23 @@ code *cdcmp(elem *e,regm_t *pretregs)
goto L3;
}

/* See if we should reverse the comparison, so a JA => JC, and JBE => JNC
* (This is already reflected in the jop)
*/
if ((jop == JC || jop == JNC) &&
(op == OPgt || op == OPle) &&
(tyuns(tym) || tyuns(e2->Ety))
)
{ // jmpopcode() sez comparison should be reversed
assert(e2->Eoper != OPconst && e2->Eoper != OPrelconst);
reverse ^= 2;
}

/* See if we should swap operands */
if (e1->Eoper == OPvar && e2->Eoper == OPvar && evalinregister(e2))
{ e1 = e->E2;
e2 = e->E1;
reverse = 2;
reverse ^= 2;
}

retregs = allregs;
Expand Down Expand Up @@ -2681,7 +2733,8 @@ code *cdcnvt(elem *e, regm_t *pretregs)

/***************************
* Convert short to long.
* For OPs16_32, OPu16_32, OPnp_fp, OPu32_64, OPs32_64
* For OPs16_32, OPu16_32, OPnp_fp, OPu32_64, OPs32_64,
* OPu64_128, OPs64_128
*/

code *cdshtlng(elem *e,regm_t *pretregs)
Expand All @@ -2703,15 +2756,16 @@ code *cdshtlng(elem *e,regm_t *pretregs)
(I32 && op == OPu32_64)
)
{
regm_t regm;
tym_t tym1;
/* Result goes into a register pair.
* Zero extend by putting a zero into most significant reg.
*/

retregs = *pretregs & mLSW;
assert(retregs);
tym1 = tybasic(e->E1->Ety);
tym_t tym1 = tybasic(e->E1->Ety);
c = codelem(e->E1,&retregs,FALSE);

regm = *pretregs & (mMSW & ALLREGS);
regm_t regm = *pretregs & (mMSW & ALLREGS);
if (regm == 0) /* *pretregs could be mES */
regm = mMSW & ALLREGS;
ce = allocreg(&regm,&reg,TYint);
Expand Down Expand Up @@ -2760,6 +2814,16 @@ code *cdshtlng(elem *e,regm_t *pretregs)
c4 = fixresult(e,retregs,pretregs);
c = cat4(c1,c2,c3,c4);
}
else if (I64 && op == OPs32_64 && OTrel(e->E1->Eoper) && !e->E1->Ecount)
{
/* Due to how e1 is calculated, the high 32 bits of the register
* are already 0.
*/
retregs = *pretregs;
c1 = codelem(e->E1,&retregs,FALSE);
c2 = fixresult(e,retregs,pretregs);
c = cat(c1,c2);
}
else if (!I16 && (op == OPs16_32 || op == OPu16_32) ||
I64 && op == OPs32_64)
{
Expand Down
2 changes: 2 additions & 0 deletions src/cast.c
Expand Up @@ -2744,6 +2744,8 @@ Expression *Expression::integralPromotions(Scope *sc)
case Tdchar:
e = e->castTo(sc, Type::tuns32);
break;
default:
break;
}
return e;
}
Expand Down
7 changes: 7 additions & 0 deletions src/class.c
Expand Up @@ -218,11 +218,18 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
classinfo = this;
}

#if !MODULEINFO_IS_STRUCT
#ifdef DMDV2
if (id == Id::ModuleInfo && !Module::moduleinfo)
Module::moduleinfo = this;
#else
if (id == Id::ModuleInfo)
{ if (Module::moduleinfo)
Module::moduleinfo->error("%s", msg);
Module::moduleinfo = this;
}
#endif
#endif
}

com = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/clone.c
Expand Up @@ -157,7 +157,7 @@ FuncDeclaration *StructDeclaration::buildOpAssign(Scope *sc)
FuncDeclaration *fop = new FuncDeclaration(loc, 0, Id::assign, STCundefined, ftype);

Expression *e = NULL;
if (postblit)
if (dtor || postblit)
{ /* Swap:
* tmp = *this; *this = s; tmp.dtor();
*/
Expand Down
2 changes: 1 addition & 1 deletion src/cond.c
Expand Up @@ -259,7 +259,7 @@ int StaticIfCondition::include(Scope *sc, ScopeDsymbol *s)
sc = sc->push(sc->scopesym);
sc->sd = s; // s gets any addMember()
sc->flags |= SCOPEstaticif;
Expression *e = exp->semantic(sc);
Expression *e = exp->ctfeSemantic(sc);
e = resolveProperties(sc, e);
sc->pop();
if (!e->type->checkBoolean())
Expand Down
2 changes: 1 addition & 1 deletion src/ctfe.h
Expand Up @@ -45,7 +45,7 @@ struct ClassReferenceExp : Expression
StructLiteralExp *value;
ClassReferenceExp(Loc loc, StructLiteralExp *lit, Type *type);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
char *toChars();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
ClassDeclaration *originalClass();
VarDeclaration *getFieldAt(unsigned index);

Expand Down
4 changes: 2 additions & 2 deletions src/ctfeexpr.c
Expand Up @@ -40,9 +40,9 @@ Expression *ClassReferenceExp::interpret(InterState *istate, CtfeGoal goal)
return this;
}

char *ClassReferenceExp::toChars()
void ClassReferenceExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
return value->toChars();
buf->writestring(value->toChars());
}

ClassDeclaration *ClassReferenceExp::originalClass()
Expand Down
12 changes: 11 additions & 1 deletion src/declaration.c
Expand Up @@ -851,6 +851,11 @@ void VarDeclaration::semantic(Scope *sc)
if (!type)
{ inuse++;

// Infering the type requires running semantic,
// so mark the scope as ctfe if required
if (storage_class & (STCmanifest | STCstatic))
sc->needctfe++;

//printf("inferring type for %s with init %s\n", toChars(), init->toChars());
ArrayInitializer *ai = init->isArrayInitializer();
if (ai)
Expand All @@ -872,6 +877,8 @@ void VarDeclaration::semantic(Scope *sc)
else
type = init->inferType(sc);

if (storage_class & (STCmanifest | STCstatic))
sc->needctfe--;
// type = type->semantic(loc, sc);

inuse--;
Expand Down Expand Up @@ -1585,7 +1592,10 @@ void VarDeclaration::semantic(Scope *sc)
{
Expression *exp;
exp = ei->exp->syntaxCopy();
exp = exp->semantic(sc);
if (isDataseg() || (storage_class & STCmanifest))
exp = exp->ctfeSemantic(sc);
else
exp = exp->semantic(sc);
exp = resolveProperties(sc, exp);
Type *tb = type->toBasetype();
Type *ti = exp->type->toBasetype();
Expand Down
2 changes: 2 additions & 0 deletions src/declaration.h
Expand Up @@ -108,6 +108,8 @@ int overloadApply(FuncDeclaration *fstart,
int (*fp)(void *, FuncDeclaration *),
void *param);

void ObjectNotFound(Identifier *id);

enum Semantic
{
SemanticStart, // semantic has not been run
Expand Down
6 changes: 3 additions & 3 deletions src/dsymbol.c
Expand Up @@ -420,7 +420,7 @@ Dsymbol *Dsymbol::search_correct(Identifier *ident)
* symbol found, NULL if not
*/

Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id)
Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Object *id)
{
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars());
Dsymbol *s = toAlias();
Expand All @@ -429,15 +429,15 @@ Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id)
switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
sm = s->search(loc, id, 0);
sm = s->search(loc, (Identifier *)id, 0);
break;

case DYNCAST_DSYMBOL:
{ // It's a template instance
//printf("\ttemplate instance id\n");
Dsymbol *st = (Dsymbol *)id;
TemplateInstance *ti = st->isTemplateInstance();
id = ti->name;
Identifier *id = ti->name;
sm = s->search(loc, id, 0);
if (!sm)
{
Expand Down
2 changes: 1 addition & 1 deletion src/dsymbol.h
Expand Up @@ -164,7 +164,7 @@ struct Dsymbol : Object
virtual void inlineScan();
virtual Dsymbol *search(Loc loc, Identifier *ident, int flags);
Dsymbol *search_correct(Identifier *id);
Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id);
Dsymbol *searchX(Loc loc, Scope *sc, Object *id);
virtual int overloadInsert(Dsymbol *s);
virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs);
virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expand Down

0 comments on commit 757135a

Please sign in to comment.