Skip to content

Commit

Permalink
Different fixes for d2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyProkhin committed Oct 7, 2010
1 parent df87607 commit 4d7a6ed
Show file tree
Hide file tree
Showing 35 changed files with 445 additions and 243 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -168,6 +168,7 @@ set_source_files_properties(

file(GLOB FE_SRC ${DMDFE_PATH}/*.c)
file(GLOB FE_SRC_ROOT ${DMDFE_PATH}/root/*.c)
file(GLOB_RECURSE GEN_HDR gen/*.h)
file(GLOB_RECURSE GEN_SRC gen/*.cpp)
file(GLOB IR_SRC ir/*.cpp)
# exclude idgen and impcnvgen and generated sources, just in case
Expand All @@ -182,6 +183,7 @@ set(LDC_SOURCE_FILES
${FE_SRC}
${FE_SRC_ROOT}
${GEN_SRC}
${GEN_HDR}
${IR_SRC}
)
set_source_files_properties(
Expand Down
2 changes: 1 addition & 1 deletion dmd2/aggregate.h
Expand Up @@ -41,6 +41,7 @@ struct VarDeclaration;
struct dt_t;

#if IN_LLVM
class ClassInfoDeclaration;
namespace llvm
{
class Type;
Expand Down Expand Up @@ -251,7 +252,6 @@ struct ClassDeclaration : AggregateDeclaration

BaseClasses *vtblInterfaces; // array of base interfaces that have
// their own vtbl[]

TypeInfoClassDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration
int com; // !=0 if this is a COM class (meaning
// it derives from IUnknown)
Expand Down
13 changes: 10 additions & 3 deletions dmd2/cast.c
Expand Up @@ -1171,7 +1171,7 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
{ Dsymbol *s = (Dsymbol *)eo->vars->a.data[i];
FuncDeclaration *f2 = s->isFuncDeclaration();
assert(f2);
if (f2->overloadExactMatch(t->nextOf(), m))
if (f2->overloadExactMatch(t->nextOf(), m))
{ if (f)
/* Error if match in more than one overload set,
* even if one is a 'better' match than the other.
Expand All @@ -1190,7 +1190,6 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
}
}


if (type->ty == Tpointer && type->nextOf()->ty == Tfunction &&
tb->ty == Tpointer && tb->nextOf()->ty == Tfunction &&
e1->op == TOKvar)
Expand All @@ -1199,8 +1198,10 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
FuncDeclaration *f = ve->var->isFuncDeclaration();
if (f)
{
#if !IN_LLVM
assert(0); // should be SymOffExp instead
f = f->overloadExactMatch(tb->nextOf(), m);
#endif
f = f->overloadExactMatch(tb->nextOf(), m);
if (f)
{
e = new VarExp(loc, f);
Expand All @@ -1211,6 +1212,7 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
}
}
}

e = Expression::castTo(sc, t);
}
e->type = t;
Expand Down Expand Up @@ -1474,7 +1476,10 @@ Expression *BinExp::scaleFactor(Scope *sc)
stride = t1b->nextOf()->size(loc);
if (!t->equals(t2b))
e2 = e2->castTo(sc, t);
// LDC: llvm uses typesafe pointer arithmetic
#if !IN_LLVM
e2 = new MulExp(loc, e2, new IntegerExp(0, stride, t));
#endif
e2->type = t;
type = e1->type;
}
Expand All @@ -1489,7 +1494,9 @@ Expression *BinExp::scaleFactor(Scope *sc)
e = e1->castTo(sc, t);
else
e = e1;
#if !IN_LLVM
e = new MulExp(loc, e, new IntegerExp(0, stride, t));
#endif
e->type = t;
type = e2->type;
e1 = e2;
Expand Down
2 changes: 2 additions & 0 deletions dmd2/class.c
Expand Up @@ -190,11 +190,13 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
classinfo = this;
}

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

com = 0;
Expand Down
10 changes: 7 additions & 3 deletions dmd2/declaration.c
Expand Up @@ -614,7 +614,7 @@ void AliasDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (haliassym)
{
buf->writestring(haliassym->toChars());
buf->writestring(haliassym->toChars());
buf->writeByte(' ');
buf->writestring(ident->toChars());
}
Expand All @@ -626,7 +626,11 @@ void AliasDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (aliassym)
{
#if !IN_LLVM
aliassym->toCBuffer(buf, hgs);
#else
buf->writestring(aliassym->toChars());
#endif
buf->writeByte(' ');
buf->writestring(ident->toChars());
}
Expand Down Expand Up @@ -876,15 +880,15 @@ void VarDeclaration::semantic(Scope *sc)
//printf("declaring field %s of type %s\n", v->toChars(), v->type->toChars());
v->semantic(sc);

/*
#if !IN_LLVM
// removed for LDC since TupleDeclaration::toObj already creates the fields;
// adding them to the scope again leads to duplicates
if (sc->scopesym)
{ //printf("adding %s to %s\n", v->toChars(), sc->scopesym->toChars());
if (sc->scopesym->members)
sc->scopesym->members->push(v);
}
*/
#endif
Expression *e = new DsymbolExp(loc, v);
exps->data[i] = e;
}
Expand Down
9 changes: 9 additions & 0 deletions dmd2/declaration.h
Expand Up @@ -450,6 +450,7 @@ struct TypeInfoClassDeclaration : TypeInfoDeclaration
#endif

#if IN_LLVM
void codegen(Ir*);
void llvmDefine();
#endif
};
Expand Down Expand Up @@ -618,6 +619,10 @@ struct TypeInfoSharedDeclaration : TypeInfoDeclaration
#if IN_DMD
void toDt(dt_t **pdt);
#endif

#if IN_LLVM
void llvmDefine();
#endif
};

struct TypeInfoWildDeclaration : TypeInfoDeclaration
Expand All @@ -627,6 +632,10 @@ struct TypeInfoWildDeclaration : TypeInfoDeclaration
#if IN_DMD
void toDt(dt_t **pdt);
#endif

#if IN_LLVM
void llvmDefine();
#endif
};
#endif

Expand Down
22 changes: 19 additions & 3 deletions dmd2/expression.c
Expand Up @@ -834,12 +834,14 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,

void expToCBuffer(OutBuffer *buf, HdrGenState *hgs, Expression *e, enum PREC pr)
{
#if !IN_LLVM
#ifdef DEBUG
if (precedence[e->op] == PREC_zero)
printf("precedence not defined for token '%s'\n",Token::tochars[e->op]);
#endif
assert(precedence[e->op] != PREC_zero);
assert(pr != PREC_zero);
#endif

//if (precedence[e->op] == 0) e->dump(0);
if (precedence[e->op] < pr ||
Expand Down Expand Up @@ -2489,7 +2491,7 @@ Expression *ThisExp::semantic(Scope *sc)
#if LOGSEMANTIC
printf("ThisExp::semantic()\n");
#endif
if (type)
if (type && var)
{ //assert(global.errors || var);
return this;
}
Expand Down Expand Up @@ -2534,7 +2536,8 @@ Expression *ThisExp::semantic(Scope *sc)
assert(fd->vthis);
var = fd->vthis;
assert(var->parent);
type = var->type;
if (!type)
type = var->type;
var->isVarDeclaration()->checkNestedReference(sc, loc);
if (!sc->intypeof)
sc->callSuper |= CSXthis;
Expand Down Expand Up @@ -7402,6 +7405,14 @@ Expression *AddrExp::semantic(Scope *sc)

if (f)
{
#if !IN_LLVM
if (f->isIntrinsic())
{
error("cannot take the address of intrinsic function %s", e1->toChars());
return this;
}
#endif

if (!ve->hasOverloads ||
/* Because nested functions cannot be overloaded,
* mark here that we took its address because castTo()
Expand Down Expand Up @@ -7789,6 +7800,9 @@ CastExp::CastExp(Loc loc, Expression *e, Type *t)
{
to = t;
this->mod = ~0;
#if IN_LLVM
disableOptimization = false;
#endif
}

#if DMDV2
Expand All @@ -7799,6 +7813,9 @@ CastExp::CastExp(Loc loc, Expression *e, unsigned mod)
{
to = NULL;
this->mod = mod;
#if IN_LLVM
disableOptimization = false;
#endif
}
#endif

Expand Down Expand Up @@ -7987,7 +8004,6 @@ void CastExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
expToCBuffer(buf, hgs, e1, precedence[op]);
}


/************************************************************/

SliceExp::SliceExp(Loc loc, Expression *e1, Expression *lwr, Expression *upr)
Expand Down
1 change: 1 addition & 0 deletions dmd2/expression.h
Expand Up @@ -1301,6 +1301,7 @@ struct CastExp : UnaExp
#if IN_LLVM
DValue* toElem(IRState* irs);
llvm::Constant *toConstElem(IRState *irs);
bool disableOptimization;
#endif
};

Expand Down
10 changes: 6 additions & 4 deletions dmd2/func.c
Expand Up @@ -775,7 +775,9 @@ void FuncDeclaration::semantic(Scope *sc)

Ldone:
Module::dprogress++;
semanticRun = PASSsemanticdone;
//LDC relies on semanticRun variable not being reset here
if(semanticRun < PASSsemanticdone)
semanticRun = PASSsemanticdone;

/* Save scope for possible later use (if we need the
* function internals)
Expand Down Expand Up @@ -1235,7 +1237,7 @@ void FuncDeclaration::semantic3(Scope *sc)
else
{ // Call invariant virtually
ThisExp *tv = new ThisExp(0);
tv->type = vthis->type;
tv->type = vthis->type;
tv->var = vthis;
Expression* v = tv;

Expand Down Expand Up @@ -2771,7 +2773,7 @@ FuncDeclaration *FuncDeclaration::genCfunc(Parameters *args, Type *treturn, Iden
}
else
{
tf = new TypeFunction(NULL, treturn, 0, LINKc);
tf = new TypeFunction(args, treturn, 0, LINKc);
fd = new FuncDeclaration(0, 0, id, STCstatic, tf);
fd->protection = PROTpublic;
fd->linkage = LINKc;
Expand Down Expand Up @@ -3011,7 +3013,7 @@ void CtorDeclaration::semantic(Scope *sc)
// to the function body
if (fbody && semanticRun < PASSsemantic)
{
Expression *e = new ThisExp(loc);
ThisExp *e = new ThisExp(loc);
if (parent->isClassDeclaration())
e->type = tret;
Statement *s = new ReturnStatement(loc, e);
Expand Down
2 changes: 2 additions & 0 deletions dmd2/mangle.c
Expand Up @@ -202,7 +202,9 @@ char *ClassDeclaration::mangle()
ident == Id::TypeInfo_Tuple ||
this == object ||
this == classinfo ||
#if !MODULEINFO_IS_STRUCT
this == Module::moduleinfo ||
#endif
memcmp(ident->toChars(), "TypeInfo_", 9) == 0
)
parent = NULL;
Expand Down
2 changes: 1 addition & 1 deletion dmd2/module.c
Expand Up @@ -57,7 +57,7 @@ static llvm::cl::opt<bool> fqnNames("oq",
llvm::cl::ZeroOrMore);
#endif

ClassDeclaration *Module::moduleinfo;
AggregateDeclaration *Module::moduleinfo;

Module *Module::rootModule;
DsymbolTable *Module::modules;
Expand Down
3 changes: 1 addition & 2 deletions dmd2/module.h
Expand Up @@ -65,8 +65,7 @@ struct Module : Package
static unsigned dprogress; // progress resolving the deferred list
static void init();

static ClassDeclaration *moduleinfo;

static AggregateDeclaration *moduleinfo;

const char *arg; // original argument name
ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration
Expand Down

0 comments on commit 4d7a6ed

Please sign in to comment.