Skip to content

Commit

Permalink
dmd 0.98
Browse files Browse the repository at this point in the history
  • Loading branch information
braddr committed Jul 2, 2009
1 parent 73cc237 commit 15d4546
Show file tree
Hide file tree
Showing 12 changed files with 1,047 additions and 65 deletions.
6 changes: 4 additions & 2 deletions src/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ printf("to:\n");
t->print();
#endif
//*(char*)0=0;
error("cannot implicitly convert %s to %s", type->toChars(), t->toChars());
error("cannot implicitly convert expression %s of type %s to %s", toChars(), type->toChars(), t->toChars());
return castTo(t);
}

Expand All @@ -57,7 +57,9 @@ int Expression::implicitConvTo(Type *t)
toChars(), type->toChars(), t->toChars());
#endif
if (!type)
error("%s is not an expression", toChars());
{ error("%s is not an expression", toChars());
type = Type::terror;
}
if (t->ty == Tbit && isBit())
return MATCHconvert;
return type->implicitConvTo(t);
Expand Down
7 changes: 5 additions & 2 deletions src/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,15 @@ void ClassDeclaration::semantic(Scope *sc)

sc->pop();

#if 0 // Do not call until toObjfile() because of forward references
// Fill in base class vtbl[]s
for (i = 0; i < vtblInterfaces->dim; i++)
{
BaseClass *b = (BaseClass *)vtblInterfaces->data[i];

b->fillVtbl(this, &b->vtbl, 1);
//b->fillVtbl(this, &b->vtbl, 1);
}
#endif
//printf("-ClassDeclaration::semantic(%s), type = %p\n", toChars(), type);
}

Expand Down Expand Up @@ -706,6 +708,7 @@ void InterfaceDeclaration::semantic(Scope *sc)
}
//members->print();
sc->pop();
//printf("-InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type);
}


Expand Down Expand Up @@ -838,7 +841,7 @@ int BaseClass::fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance)
int j;
int result = 0;

//printf("BaseClass::fillVtbl('%s')\n", base->toChars());
//printf("BaseClass::fillVtbl(this='%s', cd='%s')\n", base->toChars(), cd->toChars());
if (vtbl)
vtbl->setDim(base->vtbl.dim);

Expand Down
17 changes: 11 additions & 6 deletions src/declaration.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ void AliasDeclaration::semantic(Scope *sc)
}
if (overnext)
ScopeDsymbol::multiplyDefined(s, overnext);
assert(s != this);
if (s == this)
{
assert(global.errors);
s = NULL;
}
aliassym = s;
this->inSemantic = 0;
}
Expand Down Expand Up @@ -298,12 +302,13 @@ Type *AliasDeclaration::getType()

Dsymbol *AliasDeclaration::toAlias()
{
#ifdef DEBUG
//printf("AliasDeclaration::toAlias('%s', this = %p, aliassym = %p, kind = '%s')\n", toChars(), this, aliassym, aliassym->kind());
assert(this != aliassym);
#endif
//static int count; if (++count == 10) *(char*)0=0;
if (inSemantic)
error("recursive alias declaration");
return aliassym ? aliassym->toAlias() : this;
Dsymbol *s = aliassym ? aliassym->toAlias() : this;
return s;
}

void AliasDeclaration::toCBuffer(OutBuffer *buf)
Expand Down Expand Up @@ -510,11 +515,11 @@ void VarDeclaration::semantic(Scope *sc)
}

// If inside function, there is no semantic3() call
if (fd && init)
if (sc->func && init)
{
// If local variable, use AssignExp to handle all the various
// possibilities.
if (!isStatic() && !isConst())
if (fd && !isStatic() && !isConst())
{
ExpInitializer *ie;
Expression *e1;
Expand Down
116 changes: 92 additions & 24 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void Expression::error(const char *format, ...)
fflush(stdout);

global.errors++;
fatal();
//fatal();
}

void Expression::rvalue()
Expand Down Expand Up @@ -451,8 +451,8 @@ void Expression::checkDeprecated(Scope *sc, Dsymbol *s)
if (!global.params.useDeprecated && s->isDeprecated())
{
// Don't complain if we're inside a deprecated symbol's scope
for (Dsymbol *s = sc->parent; s; s = s->parent)
{ if (s->isDeprecated())
for (Dsymbol *sp = sc->parent; sp; sp = sp->parent)
{ if (sp->isDeprecated())
return;
}

Expand Down Expand Up @@ -923,6 +923,7 @@ Expression *IdentifierExp::semantic(Scope *sc)
return e->semantic(sc);
}
error("undefined identifier %s", ident->toChars());
type = Type::terror;
return this;
}

Expand Down Expand Up @@ -974,8 +975,10 @@ Expression *DsymbolExp::semantic(Scope *sc)
Import *imp;
Type *t;

//printf("'%s' is a symbol\n", toChars());
//printf("DsymbolExp:: '%s' is a symbol\n", toChars());
//printf("s = '%s', s->kind = '%s'\n", s->toChars(), s->kind());
s = s->toAlias();
//printf("s = '%s', s->kind = '%s'\n", s->toChars(), s->kind());
if (!s->isFuncDeclaration())
checkDeprecated(sc, s);

Expand Down Expand Up @@ -1186,6 +1189,7 @@ Expression *SuperExp::semantic(Scope *sc)
{ FuncDeclaration *fd;
FuncDeclaration *fdthis;
ClassDeclaration *cd;
Dsymbol *s;

#if LOGSEMANTIC
printf("SuperExp::semantic('%s')\n", toChars());
Expand All @@ -1200,7 +1204,13 @@ Expression *SuperExp::semantic(Scope *sc)
assert(fd->vthis);
var = fd->vthis;
assert(var->parent);
cd = fd->toParent()->isClassDeclaration();

s = fd->toParent();
while (s && s->isTemplateInstance())
s = s->toParent();
assert(s);
cd = s->isClassDeclaration();
//printf("parent is %s %s\n", fd->toParent()->kind(), fd->toParent()->toChars());
assert(cd);
if (!cd->baseClass)
{
Expand Down Expand Up @@ -1651,6 +1661,10 @@ Expression *NewExp::semantic(Scope *sc)
error("negative array index %s", arg->toChars());
arguments->data[0] = (void *) arg;
}
else if (tb->isscalar())
{
type = type->pointerTo();
}
else
{
error("new can only create structs, dynamic arrays or class objects, not %s's", type->toChars());
Expand Down Expand Up @@ -1748,7 +1762,7 @@ Expression *VarExp::semantic(Scope *sc)
VarDeclaration *v = var->isVarDeclaration();
if (v)
{
if (v->isConst() && type->toBasetype()->ty != Tsarray)
if (v->isConst() && type->toBasetype()->ty != Tsarray && v->init)
{
ExpInitializer *ei = v->init->isExpInitializer();
if (ei)
Expand Down Expand Up @@ -2035,12 +2049,17 @@ Expression *BinExp::semantic(Scope *sc)
#endif
e1 = e1->semantic(sc);
if (!e1->type)
{
error("%s has no value", e1->toChars());
e1->type = Type::terror;
}
e2 = e2->semantic(sc);
if (!e2->type)
{
error("%s has no value", e2->toChars());
e2->type = Type::terror;
}
assert(e1->type);
return this;
}

Expand Down Expand Up @@ -2078,6 +2097,29 @@ Expression *BinExp::commonSemanticAssign(Scope *sc)
return this;
}

Expression *BinExp::commonSemanticAssignIntegral(Scope *sc)
{ Expression *e;

if (!type)
{
BinExp::semantic(sc);
e2 = resolveProperties(sc, e2);

e = op_overload(sc);
if (e)
return e;

e1 = e1->modifiableLvalue(sc, NULL);
e1->checkScalar();
type = e1->type;
typeCombine();
e1->checkIntegral();
e2->checkIntegral();
}
return this;
}


void BinExp::toCBuffer(OutBuffer *buf)
{
e1->toCBuffer(buf);
Expand Down Expand Up @@ -2180,18 +2222,27 @@ Expression *DotIdExp::semantic(Scope *sc)
type = v->type;
if (v->isConst())
{
ExpInitializer *ei = v->init->isExpInitializer();
if (ei)
if (v->init)
{
//printf("\tei: %p (%s)\n", ei->exp, ei->exp->toChars());
//ei->exp = ei->exp->semantic(sc);
if (ei->exp->type == type)
ExpInitializer *ei = v->init->isExpInitializer();
if (ei)
{
e = ei->exp->copy(); // make copy so we can change loc
e->loc = loc;
return e;
//printf("\tei: %p (%s)\n", ei->exp, ei->exp->toChars());
//ei->exp = ei->exp->semantic(sc);
if (ei->exp->type == type)
{
e = ei->exp->copy(); // make copy so we can change loc
e->loc = loc;
return e;
}
}
}
else if (type->isscalar())
{
e = type->defaultInit();
e->loc = loc;
return e;
}
}
if (v->needThis())
{
Expand Down Expand Up @@ -2313,7 +2364,8 @@ Expression *DotVarExp::semantic(Scope *sc)
type = var->type;
assert(type);

accessCheck(loc, sc, e1, var);
if (!var->isFuncDeclaration()) // do access check after overload resolution
accessCheck(loc, sc, e1, var);
}
return this;
}
Expand Down Expand Up @@ -2690,8 +2742,18 @@ if (arguments && arguments->dim)
assert(f);
f = f->overloadResolve(loc, arguments);
checkDeprecated(sc, f);
dve->var = f;
e1->type = f->type;
accessCheck(loc, sc, dve->e1, f);
if (!f->needThis())
{
VarExp *ve = new VarExp(loc, f);
e1 = new CommaExp(loc, dve->e1, ve);
e1->type = f->type;
}
else
{
dve->var = f;
e1->type = f->type;
}
t1 = e1->type;
}
else if (e1->op == TOKsuper)
Expand Down Expand Up @@ -2767,6 +2829,7 @@ if (arguments && arguments->dim)
else if (!t1)
{
error("function expected before (), not '%s'", e1->toChars());
type = Type::terror;
return this;
}
else if (t1->ty != Tfunction)
Expand All @@ -2787,6 +2850,7 @@ if (arguments && arguments->dim)
}
else
{ error("function expected before (), not '%s'", e1->type->toChars());
type = Type::terror;
return this;
}
}
Expand Down Expand Up @@ -3215,6 +3279,8 @@ Expression *SliceExp::semantic(Scope *sc)
Type *t = e1->type->toBasetype();
if (t->ty == Tpointer)
{
if (!lwr || !upr)
error("need upper and lower bound to slice pointer");
}
else if (t->ty == Tarray)
{
Expand Down Expand Up @@ -3690,6 +3756,7 @@ Expression *AssignExp::semantic(Scope *sc)
BinExp::semantic(sc);
e2 = resolveProperties(sc, e2);

assert(e1->type);
t1 = e1->type->toBasetype();
if (t1->ty == Tfunction)
{ // Rewrite f=value to f(value)
Expand All @@ -3713,11 +3780,12 @@ Expression *AssignExp::semantic(Scope *sc)
e1 = e1->modifiableLvalue(sc, e1old);

if (e1->op == TOKrange &&
!(e1->type->next->equals(e2->type->next) /*||
(e1->type->next->ty == Tchar && e2->op == TOKstring)*/)
t1->next &&
!(t1->next->equals(e2->type->next) /*||
(t1->next->ty == Tchar && e2->op == TOKstring)*/)
)
{ // memset
e2 = e2->implicitCastTo(e1->type->next);
e2 = e2->implicitCastTo(t1->next);
}
#if 0
else if (e1->op == TOKrange &&
Expand All @@ -3727,7 +3795,7 @@ Expression *AssignExp::semantic(Scope *sc)
e2 = e2->implicitCastTo(e1->type->next);
}
#endif
else if (e1->type->toBasetype()->ty == Tsarray)
else if (t1->ty == Tsarray)
{
error("cannot assign to static array %s", e1->toChars());
}
Expand Down Expand Up @@ -4107,7 +4175,7 @@ AndAssignExp::AndAssignExp(Loc loc, Expression *e1, Expression *e2)

Expression *AndAssignExp::semantic(Scope *sc)
{
return commonSemanticAssign(sc);
return commonSemanticAssignIntegral(sc);
}

/************************************************************/
Expand All @@ -4119,7 +4187,7 @@ OrAssignExp::OrAssignExp(Loc loc, Expression *e1, Expression *e2)

Expression *OrAssignExp::semantic(Scope *sc)
{
return commonSemanticAssign(sc);
return commonSemanticAssignIntegral(sc);
}

/************************************************************/
Expand All @@ -4131,7 +4199,7 @@ XorAssignExp::XorAssignExp(Loc loc, Expression *e1, Expression *e2)

Expression *XorAssignExp::semantic(Scope *sc)
{
return commonSemanticAssign(sc);
return commonSemanticAssignIntegral(sc);
}

/************************* AddExp *****************************/
Expand Down
1 change: 1 addition & 0 deletions src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ struct BinExp : Expression
Expression *semantic(Scope *sc);
Expression *semanticp(Scope *sc);
Expression *commonSemanticAssign(Scope *sc);
Expression *commonSemanticAssignIntegral(Scope *sc);
void toCBuffer(OutBuffer *buf);
Expression *scaleFactor();
Expression *typeCombine();
Expand Down
Loading

0 comments on commit 15d4546

Please sign in to comment.