diff -uNr dmd-0.141/dmd/src/dmd/aggregate.h dmd-0.142/dmd/src/dmd/aggregate.h --- dmd-0.141/dmd/src/dmd/aggregate.h 2005-11-26 22:12:22.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/aggregate.h 2005-12-23 01:11:52.000000000 +0100 @@ -103,10 +103,7 @@ StructDeclaration(Loc loc, Identifier *id); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); char *mangle(); char *kind(); @@ -183,10 +180,7 @@ ClassDeclaration(Loc loc, Identifier *id, Array *baseclasses); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); int isBaseOf2(ClassDeclaration *cd); #define OFFSET_RUNTIME 0x76543210 diff -uNr dmd-0.141/dmd/src/dmd/attrib.c dmd-0.142/dmd/src/dmd/attrib.c --- dmd-0.141/dmd/src/dmd/attrib.c 2005-11-16 15:11:30.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/attrib.c 2005-12-12 19:57:10.000000000 +0100 @@ -257,7 +257,7 @@ } -void AttribDeclaration::toCBuffer(OutBuffer *buf) +void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { if (decl) { @@ -269,7 +269,7 @@ Dsymbol *s = (Dsymbol *)decl->data[i]; buf->writestring(" "); - s->toCBuffer(buf); + s->toCBuffer(buf, hgs); } buf->writeByte('}'); } @@ -315,10 +315,40 @@ sc->stc = stc; } -void StorageClassDeclaration::toCBuffer(OutBuffer *buf) +void StorageClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - buf->writestring("BUG: storage class goes here"); // BUG - AttribDeclaration::toCBuffer(buf); + struct SCstring + { + int stc; + enum TOK tok; + }; + + static SCstring table[] = + { + { STCauto, TOKauto }, + { STCstatic, TOKstatic }, + { STCextern, TOKextern }, + { STCconst, TOKconst }, + { STCfinal, TOKfinal }, + { STCabstract, TOKabstract }, + { STCsynchronized, TOKsynchronized }, + { STCdeprecated, TOKdeprecated }, + { STCoverride, TOKoverride }, + }; + + int written = 0; + for (int i = 0; i < sizeof(table)/sizeof(table[0]); i++) + { + if (stc & table[i].stc) + { + if (written) + buf->writeByte(' '); + written = 1; + buf->writestring(Token::toChars(table[i].tok)); + } + } + + AttribDeclaration::toCBuffer(buf, hgs); } /********************************* LinkDeclaration ****************************/ @@ -381,7 +411,7 @@ } } -void LinkDeclaration::toCBuffer(OutBuffer *buf) +void LinkDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { char *p; switch (linkage) @@ -397,7 +427,7 @@ } buf->writestring("extern "); buf->writestring(p); - AttribDeclaration::toCBuffer(buf); + AttribDeclaration::toCBuffer(buf, hgs); } char *LinkDeclaration::toChars() @@ -441,7 +471,7 @@ sc->protection = protection; } -void ProtDeclaration::toCBuffer(OutBuffer *buf) +void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { char *p; switch (protection) @@ -456,7 +486,7 @@ break; } buf->writestring(p); - AttribDeclaration::toCBuffer(buf); + AttribDeclaration::toCBuffer(buf, hgs); } /********************************* AlignDeclaration ****************************/ @@ -496,10 +526,10 @@ } -void AlignDeclaration::toCBuffer(OutBuffer *buf) +void AlignDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->printf("align %d", salign); - AttribDeclaration::toCBuffer(buf); + AttribDeclaration::toCBuffer(buf, hgs); } /********************************* AnonDeclaration ****************************/ @@ -605,10 +635,21 @@ } -void AnonDeclaration::toCBuffer(OutBuffer *buf) +void AnonDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->printf(isunion ? "union" : "struct"); - AttribDeclaration::toCBuffer(buf); + buf->writestring("\n{\n"); + if (decl) + { + for (unsigned i = 0; i < decl->dim; i++) + { + Dsymbol *s = (Dsymbol *)decl->data[i]; + + //buf->writestring(" "); + s->toCBuffer(buf, hgs); + } + } + buf->writestring("}\n"); } char *AnonDeclaration::kind() @@ -711,7 +752,7 @@ } } -void PragmaDeclaration::toCBuffer(OutBuffer *buf) +void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->printf("pragma(%s", ident->toChars()); if (args) @@ -720,11 +761,12 @@ { Expression *e = (Expression *)args->data[i]; - buf->printf(", %s", e->toChars()); + buf->writestring(", "); + e->toCBuffer(buf, hgs); } } buf->writestring(")"); - AttribDeclaration::toCBuffer(buf); + AttribDeclaration::toCBuffer(buf, hgs); } @@ -801,9 +843,9 @@ } } -void ConditionalDeclaration::toCBuffer(OutBuffer *buf) +void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - condition->toCBuffer(buf); + condition->toCBuffer(buf, hgs); if (decl || elsedecl) { buf->writenl(); @@ -816,7 +858,7 @@ Dsymbol *s = (Dsymbol *)decl->data[i]; buf->writestring(" "); - s->toCBuffer(buf); + s->toCBuffer(buf, hgs); } } buf->writeByte('}'); @@ -832,7 +874,7 @@ Dsymbol *s = (Dsymbol *)elsedecl->data[i]; buf->writestring(" "); - s->toCBuffer(buf); + s->toCBuffer(buf, hgs); } buf->writeByte('}'); } diff -uNr dmd-0.141/dmd/src/dmd/attrib.h dmd-0.142/dmd/src/dmd/attrib.h --- dmd-0.141/dmd/src/dmd/attrib.h 2005-11-26 22:22:32.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/attrib.h 2005-12-23 00:47:10.000000000 +0100 @@ -45,10 +45,7 @@ Dsymbol *oneMember(); void checkCtorConstInit(); void addLocalClass(Array *); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); AttribDeclaration *isAttribDeclaration() { return this; } void toObjFile(); // compile to .obj file @@ -62,10 +59,7 @@ StorageClassDeclaration(unsigned stc, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct LinkDeclaration : AttribDeclaration @@ -76,10 +70,7 @@ Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void semantic3(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); char *toChars(); }; @@ -90,10 +81,7 @@ ProtDeclaration(enum PROT p, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct AlignDeclaration : AttribDeclaration @@ -103,10 +91,7 @@ AlignDeclaration(unsigned sa, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct AnonDeclaration : AttribDeclaration @@ -116,10 +101,7 @@ AnonDeclaration(Loc loc, int isunion, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); char *kind(); }; @@ -130,10 +112,7 @@ PragmaDeclaration(Loc loc, Identifier *ident, Array *args, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); char *kind(); void toObjFile(); // compile to .obj file }; @@ -148,10 +127,7 @@ Dsymbol *oneMember(); Array *include(Scope *sc, ScopeDsymbol *s); void addComment(unsigned char *comment); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; #endif /* DMD_ATTRIB_H */ diff -uNr dmd-0.141/dmd/src/dmd/cast.c dmd-0.142/dmd/src/dmd/cast.c --- dmd-0.141/dmd/src/dmd/cast.c 2005-12-04 13:28:54.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/cast.c 2005-12-09 21:30:20.000000000 +0100 @@ -1008,9 +1008,7 @@ else { Lincompatible: - error("incompatible types for ((%s) %s (%s)): '%s' and '%s'", - e1->toChars(), Token::toChars(op), e2->toChars(), - t1->toChars(), t2->toChars()); + incompatibleTypes(); } Lret: if (!type) diff -uNr dmd-0.141/dmd/src/dmd/class.c dmd-0.142/dmd/src/dmd/class.c --- dmd-0.141/dmd/src/dmd/class.c 2005-12-04 11:31:48.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/class.c 2005-12-23 01:03:58.000000000 +0100 @@ -503,34 +503,30 @@ //printf("-ClassDeclaration::semantic(%s), type = %p\n", toChars(), type); } -void ClassDeclaration::toCBuffer(OutBuffer *buf) -{ int i; - int needcomma; - - buf->printf("%s %s", kind(), toChars()); - needcomma = 0; - if (baseClass) - { buf->printf(" : %s", baseClass->toChars()); - needcomma = 1; - } - for (i = 0; i < baseclasses.dim; i++) +void ClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->printf("%s ", kind()); + if (!isAnonymous()) + buf->writestring(toChars()); + if (baseclasses.dim) + buf->writestring(" : "); + for (int i = 0; i < baseclasses.dim; i++) { BaseClass *b = (BaseClass *)baseclasses.data[i]; - if (needcomma) + if (i) buf->writeByte(','); - needcomma = 1; buf->writestring(b->base->ident->toChars()); } buf->writenl(); buf->writeByte('{'); buf->writenl(); - for (i = 0; i < members->dim; i++) + for (int i = 0; i < members->dim; i++) { Dsymbol *s = (Dsymbol *)members->data[i]; buf->writestring(" "); - s->toCBuffer(buf); + s->toCBuffer(buf, hgs); } buf->writestring("}"); buf->writenl(); diff -uNr dmd-0.141/dmd/src/dmd/complex_t.h dmd-0.142/dmd/src/dmd/complex_t.h --- dmd-0.141/dmd/src/dmd/complex_t.h 2003-02-27 15:11:38.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/complex_t.h 2005-12-28 20:56:52.000000000 +0100 @@ -46,6 +46,9 @@ } operator bool () { return re || im; } + + int operator == (complex_t y) { return re == y.re && im == y.im; } + int operator != (complex_t y) { return re != y.re || im != y.im; } }; inline complex_t operator * (long double x, complex_t y) { return complex_t(x) * y; } diff -uNr dmd-0.141/dmd/src/dmd/cond.c dmd-0.142/dmd/src/dmd/cond.c --- dmd-0.141/dmd/src/dmd/cond.c 2005-11-26 22:07:56.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/cond.c 2005-12-12 00:03:22.000000000 +0100 @@ -107,7 +107,7 @@ return (inc == 1); } -void DebugCondition::toCBuffer(OutBuffer *buf) +void DebugCondition::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { if (ident) buf->printf("debug (%s)", ident->toChars()); @@ -194,7 +194,7 @@ return (inc == 1); } -void VersionCondition::toCBuffer(OutBuffer *buf) +void VersionCondition::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { if (ident) buf->printf("version (%s)", ident->toChars()); @@ -247,10 +247,10 @@ return (inc == 1); } -void StaticIfCondition::toCBuffer(OutBuffer *buf) +void StaticIfCondition::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("static if("); - exp->toCBuffer(buf); + exp->toCBuffer(buf, hgs); buf->writeByte(')'); } @@ -365,17 +365,17 @@ return (inc == 1); } -void IftypeCondition::toCBuffer(OutBuffer *buf) +void IftypeCondition::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("iftype("); - targ->toCBuffer(buf, id); + targ->toCBuffer(buf, id, hgs); if (tspec) { if (tok == TOKcolon) buf->writestring(" : "); else buf->writestring(" == "); - tspec->toCBuffer(buf, NULL); + tspec->toCBuffer(buf, NULL, hgs); } buf->writeByte(')'); } diff -uNr dmd-0.141/dmd/src/dmd/cond.h dmd-0.142/dmd/src/dmd/cond.h --- dmd-0.141/dmd/src/dmd/cond.h 2005-12-02 00:02:50.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/cond.h 2005-12-12 15:04:48.000000000 +0100 @@ -37,10 +37,7 @@ virtual Condition *syntaxCopy() = 0; virtual int include(Scope *sc, ScopeDsymbol *s) = 0; - virtual void toCBuffer(OutBuffer *buf) = 0; -#ifdef _DH - virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs) = 0; }; struct DVCondition : Condition @@ -63,7 +60,7 @@ DebugCondition(Module *mod, unsigned level, Identifier *ident); int include(Scope *sc, ScopeDsymbol *s); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct VersionCondition : DVCondition @@ -76,7 +73,7 @@ VersionCondition(Module *mod, unsigned level, Identifier *ident); int include(Scope *sc, ScopeDsymbol *s); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct StaticIfCondition : Condition @@ -86,10 +83,7 @@ StaticIfCondition(Loc loc, Expression *exp); Condition *syntaxCopy(); int include(Scope *sc, ScopeDsymbol *s); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct IftypeCondition : Condition @@ -104,10 +98,7 @@ IftypeCondition(Loc loc, Type *targ, Identifier *id, enum TOK tok, Type *tspec); Condition *syntaxCopy(); int include(Scope *sc, ScopeDsymbol *s); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; diff -uNr dmd-0.141/dmd/src/dmd/constfold.c dmd-0.142/dmd/src/dmd/constfold.c --- dmd-0.141/dmd/src/dmd/constfold.c 2005-12-04 12:48:14.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/constfold.c 2005-12-28 20:56:52.000000000 +0100 @@ -117,6 +117,29 @@ return new IntegerExp(loc, e1->toInteger() != 0, type); if (type->isintegral()) { + if (e1->type->isfloating()) + { integer_t result; + real_t r = e1->toReal(); + + switch (type->toBasetype()->ty) + { + case Tint8: result = (d_int8)r; break; + case Tchar: + case Tuns8: result = (d_uns8)r; break; + case Tint16: result = (d_int16)r; break; + case Twchar: + case Tuns16: result = (d_uns16)r; break; + case Tint32: result = (d_int32)r; break; + case Tdchar: + case Tuns32: result = (d_uns32)r; break; + case Tint64: result = (d_int64)r; break; + case Tuns64: result = (d_uns64)r; break; + default: + assert(0); + } + + return new IntegerExp(loc, result, type); + } if (type->isunsigned()) return new IntegerExp(loc, e1->toUInteger(), type); else @@ -427,8 +450,8 @@ e = new RealExp(loc, creall(c), type); else if (type->isimaginary()) e = new RealExp(loc, cimagl(c), type); - else if (type->iscomplex()) - e = new ComplexExp(loc, c, type); + //else if (type->iscomplex()) + //e = new ComplexExp(loc, c, type); else assert(0); } @@ -511,6 +534,7 @@ Expression *UshrExp::constFold() { + //printf("UshrExp::constFold() %s\n", toChars()); unsigned count; integer_t value; @@ -522,11 +546,13 @@ { case Tint8: case Tuns8: + assert(0); // no way to trigger this value = (value & 0xFF) >> count; break; case Tint16: case Tuns16: + assert(0); // no way to trigger this value = (value & 0xFFFF) >> count; break; @@ -568,27 +594,35 @@ } Expression *AndAndExp::constFold() -{ integer_t n; +{ int n1, n2; e1 = e1->constFold(); e2 = e2->constFold(); - if (e1->type->isfloating()) - n = e1->toComplex() && e2->toComplex(); + + n1 = e1->isBool(1); + if (n1) + { n2 = e2->isBool(1); + assert(n2 || e2->isBool(0)); + } else - n = e1->toInteger() && e2->toInteger(); - return new IntegerExp(loc, n, type); + assert(e1->isBool(0)); + return new IntegerExp(loc, n1 && n2, type); } Expression *OrOrExp::constFold() -{ integer_t n; +{ int n1, n2; e1 = e1->constFold(); e2 = e2->constFold(); - if (e1->type->isfloating()) - n = e1->toComplex() || e2->toComplex(); - else - n = e1->toInteger() || e2->toInteger(); - return new IntegerExp(loc, n, type); + + n1 = e1->isBool(1); + if (!n1) + { + assert(e1->isBool(0)); + n2 = e2->isBool(1); + assert(n2 || e2->isBool(0)); + } + return new IntegerExp(loc, n1 || n2, type); } Expression *CmpExp::constFold() @@ -596,7 +630,7 @@ real_t r1; real_t r2; - //printf("CmpExp::constFold()\n"); + //printf("CmpExp::constFold() %s\n", toChars()); e1 = e1->constFold(); e2 = e2->constFold(); if (e1->type->isreal()) @@ -786,6 +820,7 @@ Expression *IdentityExp::constFold() { int cmp; + //printf("IdentityExp::constFold() %s\n", toChars()); e1 = e1->constFold(); e2 = e2->constFold(); if (e1->type->isfloating()) @@ -818,10 +853,8 @@ int n; econd = econd->constFold(); - if (econd->type->isfloating()) - n = econd->toComplex() != 0; - else - n = econd->toInteger() != 0; + n = econd->isBool(1); + assert(n || econd->isBool(0)); return n ? e1->constFold() : e2->constFold(); } diff -uNr dmd-0.141/dmd/src/dmd/declaration.c dmd-0.142/dmd/src/dmd/declaration.c --- dmd-0.141/dmd/src/dmd/declaration.c 2005-12-01 11:26:36.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/declaration.c 2005-12-23 00:58:34.000000000 +0100 @@ -20,6 +20,7 @@ #include "module.h" #include "id.h" #include "expression.h" +#include "hdrgen.h" /********************************* Declaration ****************************/ @@ -171,10 +172,15 @@ return type; } -void TypedefDeclaration::toCBuffer(OutBuffer *buf) +void TypedefDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("typedef "); - basetype->toCBuffer(buf, ident); + basetype->toCBuffer(buf, ident, hgs); + if (init) + { + buf->writestring(" = "); + init->toCBuffer(buf, hgs); + } buf->writeByte(';'); buf->writenl(); } @@ -386,17 +392,33 @@ return s; } -void AliasDeclaration::toCBuffer(OutBuffer *buf) +void AliasDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("alias "); - if (aliassym) +#if _DH + if (hgs->hdrgen) { - aliassym->toCBuffer(buf); - buf->writeByte(' '); - buf->writestring(ident->toChars()); + if (haliassym) + { + haliassym->toCBuffer(buf, hgs); + buf->writeByte(' '); + buf->writestring(ident->toChars()); + } + else + htype->toCBuffer(buf, ident, hgs); } else - type->toCBuffer(buf, ident); +#endif + { + if (aliassym) + { + aliassym->toCBuffer(buf, hgs); + buf->writeByte(' '); + buf->writestring(ident->toChars()); + } + else + type->toCBuffer(buf, ident, hgs); + } buf->writeByte(';'); buf->writenl(); } @@ -700,12 +722,12 @@ return "variable"; } -void VarDeclaration::toCBuffer(OutBuffer *buf) +void VarDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - type->toCBuffer(buf, ident); + type->toCBuffer(buf, ident, hgs); if (init) { buf->writestring(" = "); - init->toCBuffer(buf); + init->toCBuffer(buf, hgs); } buf->writeByte(';'); buf->writenl(); @@ -780,6 +802,7 @@ return e; } + /********************************* ClassInfoDeclaration ****************************/ ClassInfoDeclaration::ClassInfoDeclaration(ClassDeclaration *cd) diff -uNr dmd-0.141/dmd/src/dmd/declaration.h dmd-0.142/dmd/src/dmd/declaration.h --- dmd-0.141/dmd/src/dmd/declaration.h 2005-12-01 00:41:08.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/declaration.h 2005-12-23 01:05:26.000000000 +0100 @@ -126,11 +126,10 @@ char *mangle(); char *kind(); Type *getType(); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); #ifdef _DH Type *htype; Type *hbasetype; - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); #endif void toDocBuffer(OutBuffer *buf); @@ -156,9 +155,8 @@ char *kind(); Type *getType(); Dsymbol *toAlias(); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); #ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); Type *htype; Dsymbol *haliassym; #endif @@ -182,9 +180,8 @@ void semantic(Scope *sc); void semantic2(Scope *sc); char *kind(); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); #ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); Type *htype; Initializer *hinit; #endif @@ -344,21 +341,14 @@ struct FuncDeclaration : Declaration { - Array *fthrows; // Array of Type's of exceptions + Array *fthrows; // Array of Type's of exceptions (not used) Statement *frequire; + Statement *fensure; + Statement *fbody; + Identifier *outId; // identifier for out statement VarDeclaration *vresult; // variable corresponding to outId LabelDsymbol *returnLabel; // where the return goes - Statement *fensure; - Statement *fbody; -#ifdef _DH - void hdrSyntaxCopy(FuncDeclaration* f); - FuncDeclaration *hcopyof; // keep track of original - Statement *hbody; // "header body" - syntaxCopy of fbody before semantic is run on contents - Statement *hrequire; // "in{}" - Statement *hensure; // "out{}" - Type *htype; // syntax type -#endif DsymbolTable *localsymtab; // used to prevent symbols in different // scopes from having the same name @@ -385,10 +375,7 @@ Dsymbol *syntaxCopy(Dsymbol *); void semantic(Scope *sc); void semantic3(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); int overrides(FuncDeclaration *fd); int overloadInsert(Dsymbol *s); FuncDeclaration *overloadExactMatch(Type *t); @@ -413,11 +400,7 @@ virtual int addPreInvariant(); virtual int addPostInvariant(); void inlineScan(); -#ifdef _DH int canInline(int hasthis, int hdrscan = 0); -#else - int canInline(int hasthis); -#endif Expression *doInline(InlineScanState *iss, Expression *ethis, Array *arguments); char *kind(); @@ -523,6 +506,7 @@ int addPreInvariant(); int addPostInvariant(); void emitComment(Scope *sc); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); InvariantDeclaration *isInvariantDeclaration() { return this; } }; @@ -537,6 +521,7 @@ int isVirtual(); int addPreInvariant(); int addPostInvariant(); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); UnitTestDeclaration *isUnitTestDeclaration() { return this; } }; diff -uNr dmd-0.141/dmd/src/dmd/doc.c dmd-0.142/dmd/src/dmd/doc.c --- dmd-0.141/dmd/src/dmd/doc.c 2005-11-26 22:33:18.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/doc.c 2005-12-12 00:07:30.000000000 +0100 @@ -34,6 +34,7 @@ #include "id.h" #include "module.h" #include "scope.h" +#include "hdrgen.h" #include "doc.h" struct Section @@ -586,7 +587,9 @@ void Dsymbol::toDocBuffer(OutBuffer *buf) { - toCBuffer(buf); + HdrGenState hgs; + + toCBuffer(buf, &hgs); } void Declaration::toDocBuffer(OutBuffer *buf) @@ -606,7 +609,9 @@ if (isSynchronized()) buf->writestring("synchronized "); if (type) - type->toCBuffer(buf, ident); + { HdrGenState hgs; + type->toCBuffer(buf, ident, &hgs); + } buf->writestring(";\n"); } } @@ -651,7 +656,8 @@ { // Need to create one tf = new TypeFunction(arguments, Type::tvoid, varargs, LINKd); } - tf->argsToCBuffer(buf); + HdrGenState hgs; + tf->argsToCBuffer(buf, &hgs); buf->writestring(";\n"); } @@ -708,7 +714,8 @@ } else { - bc->type->toCBuffer(buf, NULL); + HdrGenState hgs; + bc->type->toCBuffer(buf, NULL, &hgs); } } buf->writestring(";\n"); @@ -1018,13 +1025,13 @@ L1: //printf("param '%.*s' = '%.*s'\n", namelen, namestart, textlen, textstart); - + HdrGenState hgs; buf->writestring("$(DDOC_PARAM_ROW "); buf->writestring("$(DDOC_PARAM_ID "); o = buf->offset; arg = isFunctionParameter(s, namestart, namelen); if (arg && arg->type && arg->ident) - arg->type->toCBuffer(buf, arg->ident); + arg->type->toCBuffer(buf, arg->ident, &hgs); else buf->write(namestart, namelen); highlightCode(sc, s, buf, o); diff -uNr dmd-0.141/dmd/src/dmd/dsymbol.c dmd-0.142/dmd/src/dmd/dsymbol.c --- dmd-0.141/dmd/src/dmd/dsymbol.c 2005-12-04 11:32:08.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/dsymbol.c 2005-12-11 23:24:30.000000000 +0100 @@ -191,7 +191,7 @@ return FALSE; } -void Dsymbol::toCBuffer(OutBuffer *buf) +void Dsymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring(toChars()); } diff -uNr dmd-0.141/dmd/src/dmd/dsymbol.h dmd-0.142/dmd/src/dmd/dsymbol.h --- dmd-0.141/dmd/src/dmd/dsymbol.h 2005-12-01 00:42:40.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/dsymbol.h 2005-12-11 23:23:24.000000000 +0100 @@ -60,10 +60,8 @@ struct ArrayScopeSymbol; struct SymbolDeclaration; struct Expression; -#ifdef _DH struct DeleteDeclaration; struct HdrGenState; -#endif struct TYPE; @@ -120,7 +118,7 @@ char *toHChars(); virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); #endif - virtual void toCBuffer(OutBuffer *buf); + virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); virtual void toDocBuffer(OutBuffer *buf); virtual unsigned size(Loc loc); virtual int isforwardRef(); diff -uNr dmd-0.141/dmd/src/dmd/enum.c dmd-0.142/dmd/src/dmd/enum.c --- dmd-0.141/dmd/src/dmd/enum.c 2005-07-24 00:26:56.000000000 +0200 +++ dmd-0.142/dmd/src/dmd/enum.c 2005-12-12 01:58:34.000000000 +0100 @@ -168,7 +168,7 @@ return this; } -void EnumDeclaration::toCBuffer(OutBuffer *buf) +void EnumDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { int i; buf->writestring("enum "); @@ -179,7 +179,7 @@ if (memtype) { buf->writestring(": "); - memtype->toCBuffer(buf, NULL); + memtype->toCBuffer(buf, NULL, hgs); } if (!members) { @@ -195,8 +195,8 @@ EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember(); if (!em) continue; - buf->writestring(" "); - em->toCBuffer(buf); + //buf->writestring(" "); + em->toCBuffer(buf, hgs); buf->writeByte(','); buf->writenl(); } @@ -240,13 +240,13 @@ return em; } -void EnumMember::toCBuffer(OutBuffer *buf) +void EnumMember::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring(ident->toChars()); if (value) { buf->writestring(" = "); - value->toCBuffer(buf); + value->toCBuffer(buf, hgs); } } diff -uNr dmd-0.141/dmd/src/dmd/enum.h dmd-0.142/dmd/src/dmd/enum.h --- dmd-0.141/dmd/src/dmd/enum.h 2005-11-26 22:13:44.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/enum.h 2005-12-12 15:05:34.000000000 +0100 @@ -36,10 +36,7 @@ Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); Dsymbol *oneMember(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Type *getType(); char *kind(); @@ -60,10 +57,7 @@ EnumMember(Loc loc, Identifier *id, Expression *value); Dsymbol *syntaxCopy(Dsymbol *s); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); char *kind(); void emitComment(Scope *sc); diff -uNr dmd-0.141/dmd/src/dmd/expression.c dmd-0.142/dmd/src/dmd/expression.c --- dmd-0.141/dmd/src/dmd/expression.c 2005-12-04 17:07:36.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/expression.c 2005-12-29 09:52:12.000000000 +0100 @@ -43,11 +43,137 @@ #include "dsymbol.h" #include "module.h" #include "attrib.h" +#include "hdrgen.h" Expression *createTypeInfoArray(Scope *sc, Expression *args[], int dim); #define LOGSEMANTIC 0 +/********************************** + * Set operator precedence for each operator. + */ + +// Operator precedence - greater values are higher precedence + +enum PREC +{ + PREC_zero, + PREC_expr, + PREC_assign, + PREC_cond, + PREC_oror, + PREC_andand, + PREC_or, + PREC_xor, + PREC_and, + PREC_equal, + PREC_rel, + PREC_shift, + PREC_add, + PREC_mul, + PREC_unary, + PREC_primary, +}; + +enum PREC precedence[TOKMAX]; + +void initPrecedence() +{ + precedence[TOKimport] = PREC_primary; + precedence[TOKidentifier] = PREC_primary; + precedence[TOKthis] = PREC_primary; + precedence[TOKsuper] = PREC_primary; + precedence[TOKint64] = PREC_primary; + precedence[TOKfloat64] = PREC_primary; + precedence[TOKnull] = PREC_primary; + precedence[TOKstring] = PREC_primary; + precedence[TOKtypedot] = PREC_primary; + precedence[TOKtypeid] = PREC_primary; + precedence[TOKis] = PREC_primary; + precedence[TOKassert] = PREC_primary; + precedence[TOKfunction] = PREC_primary; + + // post + precedence[TOKdotti] = PREC_primary; + precedence[TOKdot] = PREC_primary; +// precedence[TOKarrow] = PREC_primary; + precedence[TOKplusplus] = PREC_primary; + precedence[TOKminusminus] = PREC_primary; + precedence[TOKcall] = PREC_primary; + precedence[TOKslice] = PREC_primary; + precedence[TOKarray] = PREC_primary; + + precedence[TOKaddress] = PREC_unary; + precedence[TOKstar] = PREC_unary; + precedence[TOKneg] = PREC_unary; + precedence[TOKuadd] = PREC_unary; + precedence[TOKnot] = PREC_unary; + precedence[TOKbool] = PREC_add; + precedence[TOKtilde] = PREC_unary; + precedence[TOKdelete] = PREC_unary; + precedence[TOKnew] = PREC_unary; + precedence[TOKcast] = PREC_unary; + + precedence[TOKmul] = PREC_mul; + precedence[TOKdiv] = PREC_mul; + precedence[TOKmod] = PREC_mul; + + precedence[TOKadd] = PREC_add; + precedence[TOKmin] = PREC_add; + precedence[TOKcat] = PREC_add; + + precedence[TOKshl] = PREC_shift; + precedence[TOKshr] = PREC_shift; + precedence[TOKushr] = PREC_shift; + + precedence[TOKlt] = PREC_rel; + precedence[TOKle] = PREC_rel; + precedence[TOKgt] = PREC_rel; + precedence[TOKge] = PREC_rel; + precedence[TOKunord] = PREC_rel; + precedence[TOKlg] = PREC_rel; + precedence[TOKleg] = PREC_rel; + precedence[TOKule] = PREC_rel; + precedence[TOKul] = PREC_rel; + precedence[TOKuge] = PREC_rel; + precedence[TOKug] = PREC_rel; + precedence[TOKue] = PREC_rel; + precedence[TOKin] = PREC_rel; + + precedence[TOKequal] = PREC_equal; + precedence[TOKnotequal] = PREC_equal; + precedence[TOKidentity] = PREC_equal; + precedence[TOKnotidentity] = PREC_equal; + + precedence[TOKand] = PREC_and; + + precedence[TOKxor] = PREC_xor; + + precedence[TOKor] = PREC_or; + + precedence[TOKandand] = PREC_andand; + + precedence[TOKoror] = PREC_oror; + + precedence[TOKquestion] = PREC_cond; + + precedence[TOKassign] = PREC_assign; + precedence[TOKaddass] = PREC_assign; + precedence[TOKminass] = PREC_assign; + precedence[TOKcatass] = PREC_assign; + precedence[TOKmulass] = PREC_assign; + precedence[TOKdivass] = PREC_assign; + precedence[TOKmodass] = PREC_assign; + precedence[TOKshlass] = PREC_assign; + precedence[TOKshrass] = PREC_assign; + precedence[TOKushrass] = PREC_assign; + precedence[TOKandass] = PREC_assign; + precedence[TOKorass] = PREC_assign; + precedence[TOKxorass] = PREC_assign; + + precedence[TOKcomma] = PREC_expr; +} + /***************************************** * Determine if 'this' is available. * If it is, return the FuncDeclaration that has it. @@ -362,7 +488,28 @@ } } -void argsToCBuffer(OutBuffer *buf, Array *arguments) +/************************************************** + * Write expression out to buf, but wrap it + * in ( ) if its precedence is less than pr. + */ + +void expToCBuffer(OutBuffer *buf, HdrGenState *hgs, Expression *e, enum PREC pr) +{ + if (precedence[e->op] < pr) + { + buf->writeByte('('); + e->toCBuffer(buf, hgs); + buf->writeByte(')'); + } + else + e->toCBuffer(buf, hgs); +} + +/************************************************** + * Write out argument list to buf. + */ + +void argsToCBuffer(OutBuffer *buf, Array *arguments, HdrGenState *hgs) { int i; if (arguments) @@ -372,7 +519,7 @@ if (i) buf->writeByte(','); - arg->toCBuffer(buf); + expToCBuffer(buf, hgs, arg, PREC_assign); } } } @@ -433,9 +580,11 @@ char *Expression::toChars() { OutBuffer *buf; + HdrGenState hgs; + memset(&hgs, 0, sizeof(hgs)); buf = new OutBuffer(); - toCBuffer(buf); + toCBuffer(buf, &hgs); return buf->toChars(); } @@ -514,7 +663,7 @@ return 0; } -void Expression::toCBuffer(OutBuffer *buf) +void Expression::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring(Token::toChars(op)); } @@ -832,7 +981,7 @@ return this; } -void IntegerExp::toCBuffer(OutBuffer *buf) +void IntegerExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { integer_t v = toInteger(); @@ -1048,7 +1197,7 @@ } } -void RealExp::toCBuffer(OutBuffer *buf) +void RealExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { floatToBuffer(buf, type, value); } @@ -1128,11 +1277,13 @@ int ComplexExp::isBool(int result) { - return result ? (value != 0) - : (value == 0); + if (result) + return (bool)(value); + else + return !value; } -void ComplexExp::toCBuffer(OutBuffer *buf) +void ComplexExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { /* Print as: * (re+imi) @@ -1207,9 +1358,12 @@ return ident->toChars(); } -void IdentifierExp::toCBuffer(OutBuffer *buf) +void IdentifierExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - buf->writestring(ident->toChars()); + if (hgs->hdrgen) + buf->writestring(ident->toHChars2()); + else + buf->writestring(ident->toChars()); } Expression *IdentifierExp::toLvalue(Expression *e) @@ -1407,7 +1561,7 @@ return s->toChars(); } -void DsymbolExp::toCBuffer(OutBuffer *buf) +void DsymbolExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring(s->toChars()); } @@ -1475,7 +1629,7 @@ return result ? TRUE : FALSE; } -void ThisExp::toCBuffer(OutBuffer *buf) +void ThisExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("this"); } @@ -1548,7 +1702,7 @@ return this; } -void SuperExp::toCBuffer(OutBuffer *buf) +void SuperExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("super"); } @@ -1577,7 +1731,7 @@ return result ? FALSE : TRUE; } -void NullExp::toCBuffer(OutBuffer *buf) +void NullExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("null"); } @@ -1626,9 +1780,11 @@ char *StringExp::toChars() { OutBuffer buf; + HdrGenState hgs; char *p; - toCBuffer(&buf); + memset(&hgs, 0, sizeof(hgs)); + toCBuffer(&buf, &hgs); p = (char *)buf.data; buf.data = NULL; return p; @@ -1760,7 +1916,7 @@ return result ? TRUE : FALSE; } -void StringExp::toCBuffer(OutBuffer *buf) +void StringExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { unsigned i; buf->writeByte('"'); @@ -1900,10 +2056,10 @@ return e; } -void TypeDotIdExp::toCBuffer(OutBuffer *buf) +void TypeDotIdExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writeByte('('); - type->toCBuffer(buf, NULL); + type->toCBuffer(buf, NULL, hgs); buf->writeByte(')'); buf->writeByte('.'); buf->writestring(ident->toChars()); @@ -1920,9 +2076,9 @@ this->type = type; } -void TypeExp::toCBuffer(OutBuffer *buf) +void TypeExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - type->toCBuffer(buf, NULL); + type->toCBuffer(buf, NULL, hgs); } /************************************************************/ @@ -1987,11 +2143,18 @@ return this; } -void ScopeExp::toCBuffer(OutBuffer *buf) +void ScopeExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - buf->writestring(sds->kind()); - buf->writestring(" "); - buf->writestring(sds->toChars()); + if (sds->isTemplateInstance()) + { + sds->toCBuffer(buf, hgs); + } + else + { + buf->writestring(sds->kind()); + buf->writestring(" "); + buf->writestring(sds->toChars()); + } } /********************** NewExp **************************************/ @@ -2172,21 +2335,21 @@ return this; } -void NewExp::toCBuffer(OutBuffer *buf) +void NewExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { int i; buf->writestring("new "); if (newargs && newargs->dim) { buf->writeByte('('); - argsToCBuffer(buf, newargs); + argsToCBuffer(buf, newargs, hgs); buf->writeByte(')'); } - newtype->toCBuffer(buf, NULL); + newtype->toCBuffer(buf, NULL, hgs); if (arguments && arguments->dim) { buf->writeByte('('); - argsToCBuffer(buf, arguments); + argsToCBuffer(buf, arguments, hgs); buf->writeByte(')'); } } @@ -2226,24 +2389,28 @@ return c->semantic(sc); } -void NewAnonClassExp::toCBuffer(OutBuffer *buf) +void NewAnonClassExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { int i; buf->writestring("new"); if (newargs && newargs->dim) { buf->writeByte('('); - argsToCBuffer(buf, newargs); + argsToCBuffer(buf, newargs, hgs); buf->writeByte(')'); } buf->writestring(" class"); if (arguments && arguments->dim) { buf->writeByte('('); - argsToCBuffer(buf, arguments); + argsToCBuffer(buf, arguments, hgs); buf->writeByte(')'); } - buf->writestring(" { }"); + //buf->writestring(" { }"); + if (cd) + { + cd->toCBuffer(buf, hgs); + } } /********************** SymOffExp **************************************/ @@ -2281,7 +2448,7 @@ } } -void SymOffExp::toCBuffer(OutBuffer *buf) +void SymOffExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { if (offset) buf->printf("(&%s+%u)", var->toChars(), offset); @@ -2360,7 +2527,7 @@ return var->toChars(); } -void VarExp::toCBuffer(OutBuffer *buf) +void VarExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring(var->toChars()); } @@ -2477,7 +2644,7 @@ return fd->toChars(); } -void FuncExp::toCBuffer(OutBuffer *buf) +void FuncExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring(fd->toChars()); } @@ -2556,9 +2723,9 @@ return this; } -void DeclarationExp::toCBuffer(OutBuffer *buf) +void DeclarationExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - declaration->toCBuffer(buf); + declaration->toCBuffer(buf, hgs); } @@ -2592,10 +2759,10 @@ return e; } -void TypeidExp::toCBuffer(OutBuffer *buf) +void TypeidExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("typeid("); - typeidType->toCBuffer(buf, NULL); + typeidType->toCBuffer(buf, NULL, hgs); buf->writeByte(')'); } @@ -2615,7 +2782,7 @@ return this; } -void HaltExp::toCBuffer(OutBuffer *buf) +void HaltExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("halt"); } @@ -2796,17 +2963,17 @@ return new IntegerExp(0); } -void IftypeExp::toCBuffer(OutBuffer *buf) +void IftypeExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("is("); - targ->toCBuffer(buf, id); + targ->toCBuffer(buf, id, hgs); if (tspec) { if (tok == TOKcolon) buf->writestring(" : "); else buf->writestring(" == "); - tspec->toCBuffer(buf, NULL); + tspec->toCBuffer(buf, NULL, hgs); } buf->writeByte(')'); } @@ -2839,10 +3006,10 @@ return this; } -void UnaExp::toCBuffer(OutBuffer *buf) +void UnaExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring(Token::toChars(op)); - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, precedence[op]); } /************************************************************/ @@ -2916,7 +3083,9 @@ e2->checkArithmetic(); if (op == TOKmodass && e2->type->iscomplex()) - error("cannot perform modulo complex arithmetic"); + { error("cannot perform modulo complex arithmetic"); + return new IntegerExp(0); + } } return this; } @@ -2944,13 +3113,13 @@ } -void BinExp::toCBuffer(OutBuffer *buf) +void BinExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, precedence[op]); buf->writeByte(' '); buf->writestring(Token::toChars(op)); buf->writeByte(' '); - e2->toCBuffer(buf); + expToCBuffer(buf, hgs, e2, (enum PREC)(precedence[op] + 1)); } int BinExp::isunsigned() @@ -2958,6 +3127,13 @@ return e1->type->isunsigned() || e2->type->isunsigned(); } +void BinExp::incompatibleTypes() +{ + error("incompatible types for ((%s) %s (%s)): '%s' and '%s'", + e1->toChars(), Token::toChars(op), e2->toChars(), + e1->type->toChars(), e2->type->toChars()); +} + /************************************************************/ AssertExp::AssertExp(Loc loc, Expression *e) @@ -2983,10 +3159,10 @@ return this; } -void AssertExp::toCBuffer(OutBuffer *buf) +void AssertExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("assert("); - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, PREC_assign); buf->writeByte(')'); } @@ -3207,10 +3383,10 @@ } } -void DotIdExp::toCBuffer(OutBuffer *buf) +void DotIdExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { //printf("DotIdExp::toCBuffer()\n"); - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, PREC_primary); buf->writeByte('.'); buf->writestring(ident->toChars()); } @@ -3313,9 +3489,9 @@ return this; } -void DotVarExp::toCBuffer(OutBuffer *buf) +void DotVarExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, PREC_primary); buf->writeByte('.'); buf->writestring(var->toChars()); } @@ -3433,11 +3609,11 @@ return new IntegerExp(0); } -void DotTemplateInstanceExp::toCBuffer(OutBuffer *buf) +void DotTemplateInstanceExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, PREC_primary); buf->writeByte('.'); - ti->toCBuffer(buf); + ti->toCBuffer(buf, hgs); } /************************************************************/ @@ -3462,11 +3638,12 @@ return this; } -void DelegateExp::toCBuffer(OutBuffer *buf) +void DelegateExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writeByte('&'); if (!func->isNested()) - { e1->toCBuffer(buf); + { + expToCBuffer(buf, hgs, e1, PREC_primary); buf->writeByte('.'); } buf->writestring(func->toChars()); @@ -3490,47 +3667,15 @@ return this; } -void DotTypeExp::toCBuffer(OutBuffer *buf) +void DotTypeExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, PREC_primary); buf->writeByte('.'); buf->writestring(sym->toChars()); } /************************************************************/ -ArrowExp::ArrowExp(Loc loc, Expression *e, Identifier *ident) - : UnaExp(loc, TOKarrow, sizeof(ArrowExp), e) -{ - this->ident = ident; -} - -Expression *ArrowExp::semantic(Scope *sc) -{ Expression *e; - -#if LOGSEMANTIC - printf("ArrowExp::semantic('%s')\n", toChars()); -#endif - UnaExp::semantic(sc); - e1 = resolveProperties(sc, e1); - e1 = e1->checkToPointer(); - if (e1->type->ty != Tpointer) - error("pointer expected before ->, not '%s'", e1->type->toChars()); - e = new PtrExp(loc, e1); - e = new DotIdExp(loc, e, ident); - e = e->semantic(sc); - return e; -} - -void ArrowExp::toCBuffer(OutBuffer *buf) -{ - e1->toCBuffer(buf); - buf->writestring("->"); - buf->writestring(ident->toChars()); -} - -/************************************************************/ - CallExp::CallExp(Loc loc, Expression *e, Array *arguments) : UnaExp(loc, TOKcall, sizeof(CallExp), e) { @@ -3905,12 +4050,12 @@ return this; } -void CallExp::toCBuffer(OutBuffer *buf) +void CallExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { int i; - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, precedence[op]); buf->writeByte('('); - argsToCBuffer(buf, arguments); + argsToCBuffer(buf, arguments, hgs); buf->writeByte(')'); } @@ -4043,12 +4188,10 @@ return this; } -void PtrExp::toCBuffer(OutBuffer *buf) +void PtrExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writeByte('*'); - buf->writeByte('('); - e1->toCBuffer(buf); - buf->writeByte(')'); + expToCBuffer(buf, hgs, e1, precedence[op]); } /************************************************************/ @@ -4151,7 +4294,7 @@ /************************************************************/ BoolExp::BoolExp(Loc loc, Expression *e, Type *t) - : UnaExp(loc, TOKnot, sizeof(BoolExp), e) + : UnaExp(loc, TOKbool, sizeof(BoolExp), e) { type = t; } @@ -4293,13 +4436,12 @@ return e1->castTo(to); } -void CastExp::toCBuffer(OutBuffer *buf) +void CastExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("cast("); - to->toCBuffer(buf, NULL); - buf->writestring(")("); - e1->toCBuffer(buf); + to->toCBuffer(buf, NULL, hgs); buf->writeByte(')'); + expToCBuffer(buf, hgs, e1, precedence[op]); } @@ -4439,19 +4581,19 @@ return this; } -void SliceExp::toCBuffer(OutBuffer *buf) +void SliceExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, precedence[op]); buf->writeByte('['); if (upr || lwr) { if (lwr) - lwr->toCBuffer(buf); + expToCBuffer(buf, hgs, lwr, PREC_assign); else buf->writeByte('0'); buf->writestring(".."); if (upr) - upr->toCBuffer(buf); + expToCBuffer(buf, hgs, upr, PREC_assign); else buf->writestring("length"); // BUG: should be array.length } @@ -4481,9 +4623,9 @@ return this; } -void ArrayLengthExp::toCBuffer(OutBuffer *buf) +void ArrayLengthExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, PREC_primary); buf->writestring(".length"); } @@ -4549,12 +4691,12 @@ } -void ArrayExp::toCBuffer(OutBuffer *buf) +void ArrayExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { int i; - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, PREC_primary); buf->writeByte('['); - argsToCBuffer(buf, arguments); + argsToCBuffer(buf, arguments, hgs); buf->writeByte(']'); } @@ -4728,11 +4870,11 @@ return toLvalue(e); } -void IndexExp::toCBuffer(OutBuffer *buf) +void IndexExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, PREC_primary); buf->writeByte('['); - e2->toCBuffer(buf); + expToCBuffer(buf, hgs, e2, PREC_assign); buf->writeByte(']'); } @@ -4767,9 +4909,9 @@ return e; } -void PostIncExp::toCBuffer(OutBuffer *buf) +void PostIncExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, precedence[op]); buf->writestring("++"); } @@ -4803,9 +4945,9 @@ return e; } -void PostDecExp::toCBuffer(OutBuffer *buf) +void PostDecExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, precedence[op]); buf->writestring("--"); } @@ -5417,6 +5559,12 @@ else if (tb1->ty == Tpointer && e2->type->isintegral() || tb2->ty == Tpointer && e1->type->isintegral()) e = scaleFactor(); + else if (tb1->ty == Tpointer && tb2->ty == Tpointer) + { + incompatibleTypes(); + type = e1->type; + e = this; + } else { typeCombine(); @@ -5767,7 +5915,9 @@ if (type->isfloating()) { type = e1->type; if (e2->type->iscomplex()) - error("cannot perform modulo complex arithmetic"); + { error("cannot perform modulo complex arithmetic"); + return new IntegerExp(0); + } } return this; } @@ -6316,13 +6466,13 @@ return this; } -void CondExp::toCBuffer(OutBuffer *buf) +void CondExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - econd->toCBuffer(buf); + expToCBuffer(buf, hgs, econd, PREC_oror); buf->writestring(" ? "); - e1->toCBuffer(buf); + expToCBuffer(buf, hgs, e1, PREC_expr); buf->writestring(" : "); - e2->toCBuffer(buf); + expToCBuffer(buf, hgs, e2, PREC_cond); } diff -uNr dmd-0.141/dmd/src/dmd/expression.h dmd-0.142/dmd/src/dmd/expression.h --- dmd-0.141/dmd/src/dmd/expression.h 2005-12-04 17:07:36.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/expression.h 2005-12-28 01:54:14.000000000 +0100 @@ -34,16 +34,16 @@ struct AggregateDeclaration; struct TemplateInstance; struct ClassDeclaration; -#ifdef _DH struct HdrGenState; struct BinExp; -#endif // Back end struct IRState; struct elem; struct dt_t; +void initPrecedence(); + Expression *resolveProperties(Scope *sc, Expression *e); void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d); FuncDeclaration *search_function(AggregateDeclaration *ad, Identifier *funcid); @@ -76,12 +76,7 @@ virtual real_t toReal(); virtual real_t toImaginary(); virtual complex_t toComplex(); - virtual void toCBuffer(OutBuffer *buf); -#ifdef _DH - virtual BinExp *isBinExp() { return NULL; } - virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); - char *toHChars(HdrGenState *hgs); -#endif + virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); virtual void toMangleBuffer(OutBuffer *buf); virtual Expression *toLvalue(Expression *e); virtual Expression *modifiableLvalue(Scope *sc, Expression *e); @@ -139,10 +134,7 @@ int isConst(); int isBool(int result); int implicitConvTo(Type *t); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toMangleBuffer(OutBuffer *buf); Expression *toLvalue(Expression *e); elem *toElem(IRState *irs); @@ -164,11 +156,8 @@ complex_t toComplex(); int isConst(); int isBool(int result); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toMangleBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif elem *toElem(IRState *irs); dt_t **toDt(dt_t **pdt); }; @@ -188,11 +177,10 @@ complex_t toComplex(); int isConst(); int isBool(int result); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toMangleBuffer(OutBuffer *buf); #ifdef _DH OutBuffer hexp; - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); #endif elem *toElem(IRState *irs); dt_t **toDt(dt_t **pdt); @@ -208,10 +196,7 @@ Expression *semantic(Scope *sc); char *toChars(); void dump(int indent); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Expression *toLvalue(Expression *e); }; @@ -228,10 +213,7 @@ Expression *semantic(Scope *sc); char *toChars(); void dump(int indent); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Expression *toLvalue(Expression *e); }; @@ -242,10 +224,7 @@ ThisExp(Loc loc); Expression *semantic(Scope *sc); int isBool(int result); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Expression *toLvalue(Expression *e); int inlineCost(InlineCostState *ics); @@ -259,10 +238,7 @@ { SuperExp(Loc loc); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); int inlineCost(InlineCostState *ics); Expression *doInline(InlineDoState *ids); @@ -274,10 +250,7 @@ NullExp(Loc loc); Expression *semantic(Scope *sc); int isBool(int result); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toMangleBuffer(OutBuffer *buf); int implicitConvTo(Type *t); Expression *castTo(Type *t); @@ -302,11 +275,8 @@ Expression *castTo(Type *t); int compare(Object *obj); int isBool(int result); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toMangleBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif elem *toElem(IRState *irs); dt_t **toDt(dt_t **pdt); }; @@ -318,20 +288,14 @@ TypeDotIdExp(Loc loc, Type *type, Identifier *ident); Expression *syntaxCopy(); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); elem *toElem(IRState *irs); }; struct TypeExp : Expression { TypeExp(Loc loc, Type *type); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); elem *toElem(IRState *irs); }; @@ -343,10 +307,7 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); elem *toElem(IRState *irs); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct NewExp : Expression @@ -361,10 +322,7 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); elem *toElem(IRState *irs); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); //int inlineCost(InlineCostState *ics); Expression *doInline(InlineDoState *ids); @@ -380,10 +338,7 @@ NewAnonClassExp(Loc loc, Array *newargs, ClassDeclaration *cd, Array *arguments); Expression *syntaxCopy(); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; // Offset from symbol @@ -396,10 +351,7 @@ SymOffExp(Loc loc, Declaration *var, unsigned offset); Expression *semantic(Scope *sc); void checkEscape(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); int isConst(); int isBool(int result); Expression *doInline(InlineDoState *ids); @@ -419,10 +371,7 @@ Expression *semantic(Scope *sc); void dump(int indent); char *toChars(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void checkEscape(); Expression *toLvalue(Expression *e); Expression *modifiableLvalue(Scope *sc, Expression *e); @@ -444,10 +393,7 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); char *toChars(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); elem *toElem(IRState *irs); int inlineCost(InlineCostState *ics); @@ -464,10 +410,7 @@ DeclarationExp(Loc loc, Dsymbol *declaration); Expression *syntaxCopy(); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); elem *toElem(IRState *irs); int inlineCost(InlineCostState *ics); @@ -482,20 +425,14 @@ TypeidExp(Loc loc, Type *typeidType); Expression *syntaxCopy(); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct HaltExp : Expression { HaltExp(Loc loc); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); elem *toElem(IRState *irs); }; @@ -514,10 +451,7 @@ IftypeExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, Type *tspec, enum TOK tok2); Expression *syntaxCopy(); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; /****************************************************************/ @@ -529,10 +463,7 @@ UnaExp(Loc loc, enum TOK op, int size, Expression *e1); Expression *syntaxCopy(); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Expression *optimize(int result); void dump(int indent); @@ -554,15 +485,12 @@ Expression *semanticp(Scope *sc); Expression *commonSemanticAssign(Scope *sc); Expression *commonSemanticAssignIntegral(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); - BinExp *isBinExp() { return this; } -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Expression *scaleFactor(); Expression *typeCombine(); Expression *optimize(int result); int isunsigned(); + void incompatibleTypes(); void dump(int indent); int inlineCost(InlineCostState *ics); @@ -580,10 +508,7 @@ { AssertExp(Loc loc, Expression *e); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); elem *toElem(IRState *irs); }; @@ -593,10 +518,7 @@ DotIdExp(Loc loc, Expression *e, Identifier *ident); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void dump(int i); }; @@ -608,10 +530,7 @@ Expression *semantic(Scope *sc); Expression *toLvalue(Expression *e); Expression *modifiableLvalue(Scope *sc, Expression *e); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void dump(int indent); elem *toElem(IRState *irs); }; @@ -623,10 +542,7 @@ DotTemplateInstanceExp(Loc loc, Expression *e, TemplateInstance *ti); Expression *syntaxCopy(); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void dump(int indent); }; @@ -638,10 +554,7 @@ Expression *semantic(Scope *sc); int implicitConvTo(Type *t); Expression *castTo(Type *t); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void dump(int indent); int inlineCost(InlineCostState *ics); @@ -654,25 +567,10 @@ DotTypeExp(Loc loc, Expression *e, Dsymbol *sym); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); elem *toElem(IRState *irs); }; -struct ArrowExp : UnaExp -{ - Identifier *ident; - - ArrowExp(Loc loc, Expression *e, Identifier *ident); - Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif -}; - struct CallExp : UnaExp { Array *arguments; // Array of Expression's @@ -684,10 +582,7 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); elem *toElem(IRState *irs); int inlineCost(InlineCostState *ics); @@ -711,10 +606,7 @@ PtrExp(Loc loc, Expression *e, Type *t); Expression *semantic(Scope *sc); Expression *toLvalue(Expression *e); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); elem *toElem(IRState *irs); Expression *optimize(int result); }; @@ -787,10 +679,7 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); Expression *optimize(int result); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Expression *constFold(); elem *toElem(IRState *irs); @@ -811,10 +700,7 @@ void checkEscape(); Expression *toLvalue(Expression *e); Expression *modifiableLvalue(Scope *sc, Expression *e); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Expression *optimize(int result); void dump(int indent); elem *toElem(IRState *irs); @@ -828,10 +714,7 @@ { ArrayLengthExp(Loc loc, Expression *e1); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); elem *toElem(IRState *irs); }; @@ -845,10 +728,7 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); Expression *toLvalue(Expression *e); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); // For operator overloading Identifier *opId(); @@ -887,10 +767,7 @@ Expression *semantic(Scope *sc); Expression *toLvalue(Expression *e); Expression *modifiableLvalue(Scope *sc, Expression *e); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Expression *optimize(int result); Expression *doInline(InlineDoState *ids); @@ -901,10 +778,7 @@ { PostIncExp(Loc loc, Expression *e); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Identifier *opId(); // For operator overloading elem *toElem(IRState *irs); }; @@ -913,10 +787,7 @@ { PostDecExp(Loc loc, Expression *e); Expression *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Identifier *opId(); // For operator overloading elem *toElem(IRState *irs); }; @@ -1315,10 +1186,7 @@ Expression *toLvalue(Expression *e); Expression *modifiableLvalue(Scope *sc, Expression *e); Expression *checkToBoolean(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); int implicitConvTo(Type *t); Expression *castTo(Type *t); diff -uNr dmd-0.141/dmd/src/dmd/func.c dmd-0.142/dmd/src/dmd/func.c --- dmd-0.141/dmd/src/dmd/func.c 2005-12-01 01:45:54.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/func.c 2005-12-28 01:08:34.000000000 +0100 @@ -23,7 +23,7 @@ #include "module.h" #include "statement.h" #include "template.h" - +#include "hdrgen.h" /********************************* FuncDeclaration ****************************/ @@ -41,13 +41,6 @@ returnLabel = NULL; fensure = NULL; fbody = NULL; -#ifdef _DH - hcopyof = NULL; - hbody = NULL; - hensure = NULL; - hrequire = NULL; - htype = NULL; -#endif localsymtab = NULL; vthis = NULL; v_arguments = NULL; @@ -80,9 +73,6 @@ f->fensure = fensure ? fensure->syntaxCopy() : NULL; f->fbody = fbody ? fbody->syntaxCopy() : NULL; assert(!fthrows); // deprecated -#ifdef _DH - hdrSyntaxCopy(f); -#endif return f; } @@ -831,12 +821,45 @@ } } -void FuncDeclaration::toCBuffer(OutBuffer *buf) +void FuncDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - type->toCBuffer(buf, ident); - if (fbody) + //printf("FuncDeclaration::toCBuffer() '%s'\n", toChars()); + + type->toCBuffer(buf, ident, hgs); + if (fbody && + (!hgs->hdrgen || hgs->tpltMember || canInline(1,1)) + ) { buf->writenl(); - fbody->toCBuffer(buf); + + // in{} + if (frequire) + { buf->writestring("in"); + buf->writenl(); + frequire->toCBuffer(buf, hgs); + } + + // out{} + if (fensure) + { buf->writestring("out"); + if (outId) + { buf->writebyte('('); + buf->writestring(outId->toChars()); + buf->writebyte(')'); + } + buf->writenl(); + fensure->toCBuffer(buf, hgs); + } + + if (frequire || fensure) + { buf->writestring("body"); + buf->writenl(); + } + + buf->writebyte('{'); + buf->writenl(); + fbody->toCBuffer(buf, hgs); + buf->writebyte('}'); + buf->writenl(); } else { buf->writeByte(';'); @@ -1075,6 +1098,7 @@ if (arguments) { int i; OutBuffer argbuf; + HdrGenState hgs; for (i = 0; i < arguments->dim; i++) { Expression *arg; @@ -1082,7 +1106,7 @@ arg = (Expression *)arguments->data[i]; argbuf.reset(); assert(arg->type); - arg->type->toCBuffer2(&argbuf, NULL); + arg->type->toCBuffer2(&argbuf, NULL, &hgs); if (i) buf.writeByte(','); buf.write(&argbuf); @@ -1469,11 +1493,6 @@ assert(!fthrows); // deprecated f->arguments = Argument::arraySyntaxCopy(arguments); - -#ifdef _DH - FuncDeclaration::hdrSyntaxCopy(f); -#endif - return f; } @@ -1780,6 +1799,13 @@ return FALSE; } +void InvariantDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + if (hgs->hdrgen) + return; + FuncDeclaration::toCBuffer(buf, hgs); +} + /********************************* UnitTestDeclaration ****************************/ @@ -1853,6 +1879,12 @@ return FALSE; } +void UnitTestDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + if (hgs->hdrgen) + return; + FuncDeclaration::toCBuffer(buf, hgs); +} /********************************* NewDeclaration ****************************/ diff -uNr dmd-0.141/dmd/src/dmd/hdrgen.c dmd-0.142/dmd/src/dmd/hdrgen.c --- dmd-0.141/dmd/src/dmd/hdrgen.c 2005-12-02 21:19:22.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/hdrgen.c 2005-12-28 01:54:54.000000000 +0100 @@ -1,7 +1,7 @@ // Copyright (c) 1999-2005 by Digital Mars // All Rights Reserved -// initial header generation implementation by Dave Fladebo +// Initial header generation implementation by Dave Fladebo // www.digitalmars.com // License for redistribution is by either the Artistic License // in artistic.txt, or the GNU General Public License in gnu.txt. @@ -12,7 +12,7 @@ #ifdef _DH #define PRETTY_PRINT -//#define TEST_EMIT_ALL // For Testing +#define TEST_EMIT_ALL 0 // For Testing #define LOG 0 @@ -43,2424 +43,54 @@ #include "expression.h" #include "statement.h" #include "mtype.h" +#include "hdrgen.h" -struct HdrGenState -{ - int tpltMember; - int inCallExp; - int inPtrExp; - int inSlcExp; - int inDotExp; - int inBinExp; - int inArrExp; - int emitInst; - struct - { - int init; - int decl; - } FLinit; -}; - -void Module::genhdrbufr() -{ - HdrGenState hgs; - int i; - - hdrbufr.printf("// D header file generated from '%s'", srcfile->toChars()); - hdrbufr.writenl(); - - if (md) - { - hdrbufr.writestring("module "); - if (md->packages) - { for (i = 0; i < md->packages->dim; i++) - { Identifier *pid = (Identifier *)md->packages->data[i]; - - hdrbufr.writestring(pid->toChars()); - hdrbufr.writebyte('.'); - } - } - memset(&hgs, 0, sizeof(hgs)); - toHBuffer(&hdrbufr, &hgs); - hdrbufr.writebyte(';'); - hdrbufr.writenl(); - } - - for (i = 0; i < members->dim; i++) - { Dsymbol *s = (Dsymbol *)members->data[i]; - - memset(&hgs, 0, sizeof(hgs)); - s->toHBuffer(&hdrbufr, &hgs); - } -} +void argsToCBuffer(OutBuffer *buf, Array *arguments, HdrGenState *hgs); void Module::genhdrfile() { -#ifdef PRETTY_PRINT - // Pretty print a little to make the code more readable for easier debugging. - int i, j, indent = 0; - const int indentStep = 4; - OutBuffer tbuf, line, cs, de; - char prev = NULL, curc = NULL, next = NULL; - - for (j = 0; j < indentStep; j++) - { cs.writebyte(' '); - de.writebyte(' '); - } + OutBuffer hdrbufr; - cs.writestring("case "); - de.writestring("default:"); - cs.fill0(1); - de.fill0(1); + hdrbufr.printf("// D import file generated from '%s'", srcfile->toChars()); + hdrbufr.writenl(); - if (hdrbufr.offset && (hdrbufr.data[hdrbufr.offset - 1] != '\n')) - hdrbufr.writenl(); + HdrGenState hgs; + memset(&hgs, 0, sizeof(hgs)); + hgs.hdrgen = 1; - for (i = 0; i < hdrbufr.offset; i++) //HACK - { - prev = curc; - curc = hdrbufr.data[i]; - next = (i < hdrbufr.offset - 1) ? hdrbufr.data[i+1] : NULL; - switch (curc) - { - case '\r': - break; - case '\n': - if (strstr((const char *)line.data,(const char *)cs.data) || - strstr((const char *)line.data,(const char *)de.data)) - { OutBuffer tline; - for (j = indentStep; j < line.offset; j++) - tline.writebyte(line.data[j]); - tbuf.write(&tline); - } - else - tbuf.write(&line); - tbuf.writenl(); - line.reset(); - for (j = 0; j < indent; j++) - line.writebyte(' '); - break; - case '{': - indent += indentStep; - line.writebyte(curc); - break; - case '}': - if (indent) - { if (next == '\r' || next == '\n') - line.offset -= indentStep; - indent -= indentStep; - } - line.writebyte(curc); - break; - default: - line.writebyte(curc); - break; - } - } - // Transfer image to file - hdrfile->setbuffer(tbuf.data, tbuf.offset); - tbuf.data = hdrbufr.data = line.data = NULL; + toCBuffer(&hdrbufr, &hgs); -#else // Transfer image to file hdrfile->setbuffer(hdrbufr.data, hdrbufr.offset); hdrbufr.data = NULL; -#endif hdrfile->writev(); } -/** Duplicated from template.c for now **/ -static Expression *isExpression(Object *o) -{ - //return dynamic_cast(o); - if (!o || o->dyncast() != DYNCAST_EXPRESSION) - return NULL; - return (Expression *)o; -} - -/** Duplicated from template.c for now **/ -static Dsymbol *isDsymbol(Object *o) -{ - //return dynamic_cast(o); - if (!o || o->dyncast() != DYNCAST_DSYMBOL) - return NULL; - return (Dsymbol *)o; -} - -/** Duplicated from template.c for now **/ -static Type *isType(Object *o) -{ - //return dynamic_cast(o); - if (!o || o->dyncast() != DYNCAST_TYPE) - return NULL; - return (Type *)o; -} -//Moved from func.c -void FuncDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) +void Module::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - // Don't emit this stuff - if (isUnitTestDeclaration() || isInvariantDeclaration()) - { - return; - } - - if (!parent) // not a member of a StorageClassDeclaration - { - if (isConst()) - buf->writestring("const "); - if (isStatic() && - !isStaticCtorDeclaration() && - !isStaticDtorDeclaration() && - !isNewDeclaration() && - !isDeleteDeclaration()) - buf->writestring("static "); - } - - Type *t = htype ? htype : type; - t->toHBuffer(buf,ident, hgs); - -#ifdef TEST_EMIT_ALL - if (hbody) -#else - // hcopyof points to the FuncDeclaration that has been through semantic analysis - // (the syntaxCopy has not). - if (hbody && (hgs->tpltMember || (hcopyof && hcopyof->canInline(1,1)))) -#endif - { - if (hrequire || hensure) - buf->writenl(); - - // in{} - if (hrequire) - { buf->writestring("in"); - buf->writenl(); - hrequire->toHBuffer(buf, hgs); - } - - // out{} - if (hensure) - { buf->writestring("out"); - if (outId) - { buf->writebyte('('); - buf->writestring(outId->toChars()); - buf->writebyte(')'); - } - buf->writenl(); - hensure->toHBuffer(buf, hgs); - } - - if (hrequire || hensure) - buf->writestring("body"); - - buf->writenl(); - buf->writebyte('{'); - buf->writenl(); - hbody->toHBuffer(buf, hgs); - buf->writebyte('}'); - buf->writenl(); - } - else + if (md) { - buf->writeByte(';'); - buf->writenl(); - } -} - -void AttribDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ unsigned dd = 0; - OutBuffer tbuf; - - if (decl) - { dd = decl->dim; - for (unsigned i = 0; i < dd; i++) - { - Dsymbol *s = (Dsymbol *)decl->data[i]; - - //if (dd > 1) - // buf->writestring(" "); - s->toHBuffer(&tbuf, hgs); - } - if (tbuf.offset) - { if (dd > 1) - { buf->writenl(); - buf->writeByte('{'); - buf->writenl(); - } - else - buf->writebyte(' '); - - buf->write(&tbuf); - - if (dd > 1) - buf->writeByte('}'); - } - } - else - buf->writeByte(':'); - - if (!decl || (tbuf.offset && dd != 1)) + buf->writestring("module "); + buf->writestring(md->toChars()); + buf->writebyte(';'); buf->writenl(); -} - -void StorageClassDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - // See declaration.h storage class code (isFinal, isConst, isStatic, etc...) - // to determine storage class for aggragate data members - // this->stc stores the storage class - - struct SCstring - { - int stc; - enum TOK tok; - }; - - static SCstring table[] = - { - { STCauto, TOKauto }, - { STCstatic, TOKstatic }, - { STCextern, TOKextern }, - { STCconst, TOKconst }, - { STCfinal, TOKfinal }, - { STCabstract, TOKabstract }, - { STCsynchronized, TOKsynchronized }, - { STCdeprecated, TOKdeprecated }, - { STCoverride, TOKoverride }, - }; - - OutBuffer tbuf; - - for (int i = 0; i < sizeof(table)/sizeof(table[0]); i++) - { - if (stc & table[i].stc) - { - if (tbuf.offset) - tbuf.writebyte(' '); - tbuf.writestring(Token::toChars(table[i].tok)); - } - } - - buf->write(&tbuf); - AttribDeclaration::toHBuffer(buf, hgs); -} - -void LinkDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ char *p; - - switch (linkage) - { - case LINKd: p = "D"; break; - case LINKc: p = "C"; break; - case LINKcpp: p = "C++"; break; - case LINKwindows: p = "Windows"; break; - case LINKpascal: p = "Pascal"; break; - default: - assert(0); - break; - } - buf->writestring("extern ("); - buf->writestring(p); - buf->writebyte(')'); - AttribDeclaration::toHBuffer(buf, hgs); -} - -void ProtDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ char *p; - OutBuffer tbuf; - int i; - int emit = 0; - char c; - - AttribDeclaration::toHBuffer(&tbuf, hgs); - for (int i = 0; i < tbuf.offset; i++) - { c = tbuf.data[i]; - // identifiers must have at least one of either '_' or alpha, - // or begin a new attribute scope with ':' or '{' - if (c >= 'a' && c <= 'z' || - c >= 'A' && c <= 'Z' || - c == '_' || c == ':' || c == '{') - { emit = 1; - break; - } - } - if (emit) - { - switch (protection) - { - case PROTprivate: p = "private"; break; - case PROTpackage: p = "package"; break; - case PROTprotected: p = "protected"; break; - case PROTpublic: p = "public"; break; - case PROTexport: p = "export"; break; - default: - assert(0); - break; - } - - buf->writestring(p); - buf->write(&tbuf); - } -} - -void AlignDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->printf("align(%d)", salign); - AttribDeclaration::toHBuffer(buf, hgs); -} - -void AnonDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->printf(isunion ? "union" : "struct"); - //AttribDeclaration::toHBuffer(buf); - if (decl) - { - buf->writenl(); - buf->writeByte('{'); - buf->writenl(); - for (unsigned i = 0; i < decl->dim; i++) - { - Dsymbol *s = (Dsymbol *)decl->data[i]; - - //buf->writestring(" "); - s->toHBuffer(buf, hgs); - } - buf->writeByte('}'); - } - buf->writenl(); -} - -void PragmaDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->printf("pragma(%s", ident->toChars()); - if (args) - { - for (size_t i = 0; i < args->dim; i++) - { - Expression *e = (Expression *)args->data[i]; - - buf->writestring(", "); - e->toHBuffer(buf, hgs); - } - } - buf->writestring(")"); - AttribDeclaration::toHBuffer(buf, hgs); -} - -void ConditionalDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - if (decl || elsedecl) - { - int error = 0; - int inc = condition->inc; - if (!inc) - { - unsigned errors = global.errors; - global.gag++; - inc = condition->include(NULL,NULL); - if (errors != global.errors) - { error = 1; - inc = 0; - } - global.gag--; - global.errors = errors; - } - - if (!error || inc) - { - if (decl && condition->inc == 1) - { - for (unsigned i = 0; i < decl->dim; i++) - { - Dsymbol *s = (Dsymbol *)decl->data[i]; - - s->toHBuffer(buf, hgs); - } - } - if (elsedecl && condition->inc == 2) - { - for (unsigned i = 0; i < elsedecl->dim; i++) - { - Dsymbol *s = (Dsymbol *)elsedecl->data[i]; - - s->toHBuffer(buf, hgs); - } - } - } - else - { - OutBuffer ibuf, ebuf; - if (decl) - { - for (unsigned i = 0; i < decl->dim; i++) - { - Dsymbol *s = (Dsymbol *)decl->data[i]; - - s->toHBuffer(&ibuf, hgs); - } - } - if (elsedecl) - { - OutBuffer tbuf; - for (unsigned i = 0; i < elsedecl->dim; i++) - { - Dsymbol *s = (Dsymbol *)elsedecl->data[i]; - - s->toHBuffer(&tbuf, hgs); - } - if (tbuf.offset) - { ebuf.writestring("}\nelse\n{\n"); - ebuf.write(&tbuf); - } - } - if (ibuf.offset || ebuf.offset) - { - condition->toHBuffer(buf, hgs); - buf->writenl(); - buf->writebyte('{'); - buf->writenl(); - if (ibuf.offset) - buf->write(&ibuf); - if (ebuf.offset) - buf->write(&ebuf); - buf->writebyte('}'); - buf->writenl(); - } - } } -} -void ClassDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ int i; - int needcomma; - int needcolon; - int isAnon; - - needcomma = 0; - needcolon = 1; - isAnon = isAnonymous(); - - if (!isAnon) - buf->printf("%s %s", kind(), toChars()); - else - buf->writebyte(' '); - for (i = 0; i < baseclasses.dim; i++) - { BaseClass *b = (BaseClass *)baseclasses.data[i]; - ClassDeclaration *cd = b->base; - - if (!isAnon && cd && !strcmp(cd->ident->toChars(),"Object")) - continue; - if (!isAnon && needcolon) - buf->writestring(" : "); - needcolon = 0; - if (needcomma) - buf->writeByte(','); - needcomma = 1; - - if (cd) - { TemplateInstance *ti = cd->parent ? - cd->parent->isTemplateInstance() : NULL; - if (ti) - { hgs->emitInst++; - ti->toHBuffer(buf,hgs); - hgs->emitInst--; - } - else - buf->writestring(cd->ident->toChars()); - } - else - { - b->type->toHBuffer(buf, NULL, hgs); - } - } - buf->writenl(); - buf->writeByte('{'); - buf->writenl(); - for (i = 0; i < members->dim; i++) - { Dsymbol *s = (Dsymbol *)members->data[i]; + for (int i = 0; i < members->dim; i++) + { Dsymbol *s = (Dsymbol *)members->data[i]; s->toHBuffer(buf, hgs); } - buf->writestring("}"); - if (!isAnon) - buf->writenl(); -} - -void Condition::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void StaticIfCondition::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("static if("); - exp->toHBuffer(buf, hgs); - buf->writeByte(')'); -} - -void IftypeCondition::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("iftype("); - targ->toHBuffer(buf, id, hgs); - if (tspec) - { - if (tok == TOKcolon) - buf->writestring(" : "); - else - buf->writestring(" == "); - tspec->toHBuffer(buf, NULL, hgs); - } - buf->writeByte(')'); -} - -void TypedefDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("typedef "); - hbasetype->toHBuffer(buf, ident, hgs); - TypeTypedef *td = (TypeTypedef *)this->htype; - if (td) - { - if (td->sym->init) - { - Expression *e = td->defaultInit(); - if (e) - { buf->writestring(" = "); - buf->writestring(e->toHChars(hgs)); - } - } - } - buf->writeByte(';'); - buf->writenl(); -} - -void AliasDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("alias "); - if (haliassym) - { - haliassym->toHBuffer(buf, hgs); - buf->writeByte(' '); - buf->writestring(ident->toChars()); - } - else - htype->toHBuffer(buf, ident, hgs); - buf->writeByte(';'); - buf->writenl(); } -void VarDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - OutBuffer tbuf, tbuf2; - - if (!parent) // not a member of a StorageClassDeclaration - { - if (isAuto()) - tbuf.writestring("auto "); - if (isConst()) - tbuf.writestring("const "); - if (isStatic()) - tbuf.writestring("static "); - } - - if (hgs->FLinit.init && hgs->FLinit.decl > 0) - { - tbuf.writebyte(','); - } - - Type *t = htype ? htype : type; - if (t && (!hgs->FLinit.init || !hgs->FLinit.decl)) - { - t->toHBuffer(&tbuf, ident, hgs); - } - else - { - tbuf.writestring(ident->toHChars2()); - } - - // skip initializers for non-const globals -#ifdef TEST_EMIT_ALL - if (1) -#else - if (isConst() || !(parent && parent->isModule() && protection == PROTpublic)) -#endif - { - Initializer *i = hinit ? hinit : init; - if (i) - { - i->toHBuffer(&tbuf2, hgs); - if (tbuf2.offset) - { tbuf.writestring(" = "); - tbuf.write(&tbuf2); - if (!t) // implicit type - { - ExpInitializer *ei = i->isExpInitializer(); - if (ei && ei->exp && ei->exp->type) - { - switch(ei->exp->type->ty) - { - case Tint64: - tbuf.writebyte('l'); - break; - case Tuns32: - tbuf.writebyte('u'); - break; - case Tuns64: - tbuf.writestring("lu"); - break; - case Tfloat32: - tbuf.writebyte('F'); - break; - case Tfloat80: - tbuf.writebyte('L'); - break; - default: - break; - } - } - } - } - } - } - - if (tbuf.offset) - { buf->write(&tbuf); - if (!hgs->FLinit.init) - { buf->writeByte(';'); - buf->writenl(); - } - else - { - hgs->FLinit.decl++; - } - } -} void Dsymbol::toHBuffer(OutBuffer *buf, HdrGenState *hgs) { - buf->writestring(toChars()); -} - -void EnumDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ int i; - - buf->writestring("enum "); - if (ident) - { buf->writestring(ident->toChars()); - buf->writeByte(' '); - } - if (memtype) - { buf->writestring(": "); - memtype->toHBuffer(buf, NULL, hgs); - } - if (!members) - { buf->writeByte(';'); - buf->writenl(); - return; - } - buf->writenl(); - buf->writeByte('{'); - buf->writenl(); - for (i = 0; i < members->dim; i++) - { EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember(); - if (!em) - continue; - //buf->writestring(" "); - em->toHBuffer(buf, hgs); - if (i < members->dim - 1) - buf->writeByte(','); - buf->writenl(); - } - buf->writeByte('}'); - buf->writenl(); -} - -void EnumMember::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring(ident->toChars()); - if (value) - { - buf->writestring(" = "); - value->toHBuffer(buf, hgs); - } -} - -void argsToHBuffer(OutBuffer *buf, Array *arguments, HdrGenState *hgs) -{ - if (arguments) - { - for (int i = 0; i < arguments->dim; i++) - { Expression *arg = (Expression *)arguments->data[i]; - if (arg) - { - if (i) - buf->writeByte(','); - arg->toHBuffer(buf, hgs); - } - } - } -} - -char *Expression::toHChars(HdrGenState *hgs) -{ OutBuffer *buf; - - buf = new OutBuffer(); - toHBuffer(buf, hgs); - return buf->toChars(); -} - -void Expression::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void IntegerExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void RealExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void ComplexExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void IdentifierExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring(ident->toHChars2()); -} - -void DsymbolExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void ThisExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void SuperExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void NullExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void StringExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void TypeDotIdExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - if (type->ty == Tpointer || type->ty == Tarray) - buf->writeByte('('); - type->toHBuffer(buf, NULL, hgs); - if (type->ty == Tpointer || type->ty == Tarray) - buf->writeByte(')'); - buf->writeByte('.'); - buf->writestring(ident->toChars()); -} - -void TypeExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - type->toHBuffer(buf, NULL, hgs); -} - -void ScopeExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - if (sds->isTemplateInstance()) - { - sds->toHBuffer(buf, hgs); - } - else - { - buf->writestring(sds->kind()); - buf->writestring(" "); - buf->writestring(sds->toChars()); - } -} - -void NewExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ int i; - - buf->writestring("new"); - if (newargs && newargs->dim) - { - buf->writeByte('('); - argsToHBuffer(buf, newargs, hgs); - buf->writeByte(')'); - } - buf->writebyte(' '); - type->toHBuffer(buf, NULL, hgs); - if (arguments && arguments->dim) - { - buf->writeByte('('); - argsToHBuffer(buf, arguments, hgs); - buf->writeByte(')'); - } -} - -void NewAnonClassExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ int i; - - buf->writestring("new"); - if (newargs && newargs->dim) - { - buf->writeByte('('); - argsToHBuffer(buf, newargs, hgs); - buf->writeByte(')'); - } - buf->writestring(" class"); - if (arguments && arguments->dim) - { - buf->writeByte('('); - argsToHBuffer(buf, arguments, hgs); - buf->writeByte(')'); - } - //buf->writestring(" { }"); - if (cd) - { - cd->toHBuffer(buf, hgs); - } -} - -void SymOffExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void VarExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void FuncExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - if (fd->tok != TOKfunction && fd->tok != TOKdelegate) - { - buf->writestring(fd->toChars()); - } - else - { - if (fd->tok == TOKfunction) - buf->writestring("function "); - else - buf->writestring("delegate "); - fd->type->toHBuffer(buf,NULL, hgs); - if (fd->fbody && fd->hbody) - { - buf->writenl(); - buf->writebyte('{'); - buf->writenl(); - fd->hbody->toHBuffer(buf, hgs); - buf->writebyte('}'); - buf->writenl(); - } - else - { - buf->writeByte(';'); - buf->writenl(); - } - } -} - -void DeclarationExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - declaration->toHBuffer(buf, hgs); -} - -void TypeidExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("typeid("); - typeidType->toHBuffer(buf, NULL, hgs); - buf->writeByte(')'); -} - -void HaltExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void IftypeExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("is("); - targ->toHBuffer(buf, id, hgs); - if (tspec) - { - if (tok == TOKcolon) - buf->writestring(" : "); - else - buf->writestring(" == "); - tspec->toHBuffer(buf, NULL, hgs); - } - buf->writeByte(')'); -} - -void UnaExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - int bracket = (op == TOKaddress && (hgs->inSlcExp || hgs->inArrExp)); - - if (bracket) - buf->writebyte('('); - - if (op == TOKaddress) - { - buf->writebyte('&'); - } - else - { buf->writestring(Token::toChars(op)); - buf->writebyte(' '); - } - - if (e1->isBinExp()) - buf->writebyte('('); - e1->toHBuffer(buf, hgs); - if (e1->isBinExp()) - buf->writebyte(')'); - - if (bracket) - buf->writebyte(')'); - + toCBuffer(buf, hgs); } -void BinExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - hgs->inBinExp++; - - //e1->toHBuffer(buf, hgs); - //buf->writeByte(' '); - //buf->writestring(Token::toChars(op)); - //buf->writeByte(' '); - //e2->toHBuffer(buf, hgs); - - BinExp *be1 = e1->isBinExp(); - BinExp *be2 = e2->isBinExp(); - int opassign = (op == TOKassign || - op == TOKaddass || - op == TOKminass || - op == TOKmulass || - op == TOKdivass || - op == TOKmodass || - op == TOKshlass || - op == TOKshrass || - op == TOKcatass || - op == TOKandass || - op == TOKorass || - op == TOKxorass || - op == TOKushrass); - - int bracket1 = (be1 && !opassign); - int bracket2 = (be2 && !opassign); - - if (hgs->inPtrExp) - buf->writebyte('('); - - if (bracket1) - buf->writebyte('('); - e1->toHBuffer(buf, hgs); - if (bracket1) - buf->writebyte(')'); - buf->writeByte(' '); - buf->writestring(Token::toChars(op)); - buf->writeByte(' '); - if (bracket2) - buf->writebyte('('); - e2->toHBuffer(buf, hgs); - if (bracket2) - buf->writebyte(')'); - - if (hgs->inPtrExp) - buf->writebyte(')'); - - hgs->inBinExp--; -} - -void AssertExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("assert("); - e1->toHBuffer(buf, hgs); - buf->writeByte(')'); -} - -void DotIdExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - hgs->inDotExp++; - - int hasNew = (e1->op == TOKnew); - if (!hasNew) - { - BinExp *be = e1->isBinExp(); - while (be) - { - if (be->e2 && be->e2->op == TOKnew) - { hasNew = 1; - break; - } - be = be->e2->isBinExp(); - } - } - if (hasNew) - buf->writebyte('('); - e1->toHBuffer(buf, hgs); - if (hasNew) - buf->writebyte(')'); - buf->writeByte('.'); - buf->writestring(ident->toChars()); - - hgs->inDotExp--; -} - -void DotVarExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - e1->toHBuffer(buf, hgs); - buf->writeByte('.'); - buf->writestring(var->toChars()); -} - -void DotTemplateInstanceExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - e1->toHBuffer(buf, hgs); - buf->writeByte('.'); - ti->toHBuffer(buf, hgs); -} - -void DelegateExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writeByte('&'); - if (!func->isNested()) - { e1->toHBuffer(buf, hgs); - buf->writeByte('.'); - } - buf->writestring(func->toChars()); -} - -void DotTypeExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - e1->toHBuffer(buf, hgs); - buf->writeByte('.'); - buf->writestring(sym->toChars()); -} - -void ArrowExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - e1->toHBuffer(buf, hgs); - buf->writestring("->"); - buf->writestring(ident->toChars()); -} - -void CallExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ int i; - - hgs->inCallExp++; - e1->toHBuffer(buf, hgs); - hgs->inCallExp--; - - buf->writeByte('('); - argsToHBuffer(buf, arguments, hgs); - buf->writeByte(')'); -} - -void PtrExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - int bracket = hgs->inDotExp || hgs->inCallExp; - - hgs->inPtrExp++; - - if (bracket) - buf->writeByte('('); - - buf->writeByte('*'); - e1->toHBuffer(buf, hgs); - - if (bracket) - buf->writeByte(')'); - - hgs->inPtrExp--; -} - -void CastExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - int brackets = (hgs->inBinExp || hgs->inDotExp || hgs->inArrExp || hgs->inSlcExp); - - if (brackets) - buf->writebyte('('); - - buf->writestring("cast("); - if (type && type->ty == Ttypedef) - type->toHBuffer(buf, NULL, hgs); - else - to->toHBuffer(buf, NULL, hgs); - buf->writestring(")("); - e1->toHBuffer(buf, hgs); - buf->writebyte(')'); - - if (brackets) - buf->writebyte(')'); -} - -void SliceExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - hgs->inSlcExp++; - - e1->toHBuffer(buf, hgs); - buf->writeByte('['); - if (upr || lwr) - { - if (lwr) - lwr->toHBuffer(buf, hgs); - else - buf->writeByte('0'); - buf->writestring(".."); - if (upr) - upr->toHBuffer(buf, hgs); - else - buf->writestring("length"); // BUG: should be array.length - } - buf->writeByte(']'); - - hgs->inSlcExp--; -} - -void ArrayLengthExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - e1->toHBuffer(buf, hgs); - buf->writestring(".length"); -} - -void ArrayExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - hgs->inArrExp++; - - e1->toHBuffer(buf, hgs); - buf->writeByte('['); - argsToHBuffer(buf, arguments, hgs); - buf->writeByte(']'); - - hgs->inArrExp--; -} - -void IndexExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - e1->toHBuffer(buf, hgs); - buf->writeByte('['); - e2->toHBuffer(buf, hgs); - buf->writeByte(']'); -} - -void PostIncExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - e1->toHBuffer(buf, hgs); - buf->writestring("++"); -} - -void PostDecExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - e1->toHBuffer(buf, hgs); - buf->writestring("--"); -} - -void CondExp::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - econd->toHBuffer(buf, hgs); - buf->writestring(" ? "); - e1->toHBuffer(buf, hgs); - buf->writestring(" : "); - e2->toHBuffer(buf, hgs); -} - -char *Identifier::toHChars2() -{ - char *p = NULL; - - if (this == Id::ctor) p = "this"; - else if (this == Id::dtor) p = "~this"; - else if (this == Id::classInvariant) p = "invariant"; - else if (this == Id::unitTest) p = "unittest"; - else if (this == Id::staticCtor) p = "static this"; - else if (this == Id::staticDtor) p = "static ~this"; - else if (this == Id::dollar) p = "$"; - else if (this == Id::withSym) p = "with"; - else if (this == Id::result) p = "result"; - else if (this == Id::returnLabel) p = "return"; - else - p = toChars(); - - return p; -} - -void Import::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - //object is imported by default - if (strcmp(id->toChars(),"object")) - { - toCBuffer(buf); - } -} - -void VoidInitializer::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void StructInitializer::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writebyte('{'); - for (int i = 0; i < field.dim; i++) - { - if (i > 0) buf->writebyte(','); - //VarDeclaration *v = (VarDeclaration *)field.data[i]; - //buf->writestring(v->ident->toChars()); - Identifier *id = (Identifier *)field.data[i]; - if (id) - { - buf->writestring(id->toChars()); - buf->writebyte(':'); - } - Initializer *iz = (Initializer *)value.data[i]; - if (iz) - iz->toHBuffer(buf, hgs); - } - buf->writebyte('}'); -} - -void ArrayInitializer::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writebyte('['); - for (int i = 0; i < index.dim; i++) - { - if (i > 0) buf->writebyte(','); - Expression *ex = (Expression *)index.data[i]; - if (ex) - { - ex->toHBuffer(buf, hgs); - buf->writebyte(':'); - } - Initializer *iz = (Initializer *)value.data[i]; - if (iz) - iz->toHBuffer(buf, hgs); - } - buf->writebyte(']'); -} - -void ExpInitializer::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - exp->toHBuffer(buf, hgs); -} - -void AsmStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - Token *t = tokens; - while (t) - { - if (t->value == TOKstring) - buf->writebyte('"'); - buf->writestring(t->toChars()); - if (t->value == TOKstring) - buf->writebyte('"'); - if (t->next && - t->value != TOKmin && - t->value != TOKcomma && - t->next->value != TOKcomma && - t->value != TOKlbracket && - t->next->value != TOKlbracket && - t->next->value != TOKrbracket && - t->value != TOKlparen && - t->next->value != TOKlparen && - t->next->value != TOKrparen && - t->value != TOKdot && - t->next->value != TOKdot) - { - buf->writebyte(' '); - } - t = t->next; - } - buf->writebyte(';'); - buf->writenl(); -} - -void Type::toHBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - OutBuffer tbuf; - - toHBuffer2(&tbuf, ident, hgs); - buf->write(&tbuf); -} - -void Type::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - OutBuffer tbuf; - toHBuffer2(&tbuf, NULL, hgs); - buf->prependstring(tbuf.toChars()); - if (ident) - { buf->writeByte(' '); - buf->writestring(ident->toChars()); - } -} - -void TypeBasic::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - toCBuffer2(buf, ident); -} - -void TypeArray::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ -#if 1 - OutBuffer buf2; - toPrettyBracket(&buf2); - buf->prependstring(buf2.toChars()); - if (ident) - { buf->writebyte(' '); - buf->writestring(ident->toChars()); - } - next->toHBuffer2(buf, NULL, hgs); -#elif 1 - // The D way - Type *t; - OutBuffer buf2; - for (t = this; 1; t = t->next) - { TypeArray *ta; - - ta = dynamic_cast(t); - if (!ta) - break; - ta->toPrettyBracket(&buf2); - } - buf->prependstring(buf2.toChars()); - if (ident) - { - buf2.writestring(ident->toChars()); - } - t->toHBuffer2(buf, NULL); -#else - // The C way - if (buf->offset) - { buf->bracket('(', ')'); - assert(!ident); - } - else if (ident) - buf->writestring(ident->toChars()); - Type *t = this; - do - { Expression *dim; - buf->writeByte('['); - dim = ((TypeSArray *)t)->dim; - if (dim) - buf->printf("%d", dim->toInteger()); - buf->writeByte(']'); - t = t->next; - } while (t->ty == Tsarray); - t->toHBuffer2(buf, NULL); -#endif -} - -void TypePointer::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - //printf("TypePointer::toCBuffer2() next = %d\n", next->ty); - buf->prependstring("*"); - if (ident) - { buf->writebyte(' '); - buf->writestring(ident->toChars()); - } - next->toHBuffer2(buf, NULL, hgs); -} - -void TypeReference::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - buf->prependstring("&"); - if (ident) - { - buf->writestring(ident->toChars()); - } - next->toHBuffer2(buf, NULL, hgs); -} - -void TypeFunction::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - if (buf->offset) - { - buf->bracket('(', ')'); - assert(!ident); - } - else - { - if (ident) - { - buf->writestring(ident->toHChars2()); - buf->prependbyte(' '); - } - } - argsToHBuffer(buf, hgs); - if (ident->toHChars2() == ident->toChars()) - next->toHBuffer2(buf, NULL, hgs); -} - -void TypeFunction::argsToHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writeByte('('); - if (arguments) - { int i; - OutBuffer argbuf; - - for (i = 0; i < arguments->dim; i++) - { Argument *arg; - - if (i) - buf->writeByte(','); - arg = (Argument *)arguments->data[i]; - if (arg->inout == Out) - buf->writestring("out "); - else if (arg->inout == InOut) - buf->writestring("inout "); - argbuf.reset(); - arg->type->toHBuffer2(&argbuf, arg->ident, hgs); - if (arg->defaultArg) - { - argbuf.writestring(" = "); - arg->defaultArg->toHBuffer(&argbuf, hgs); - } - buf->write(&argbuf); - } - if (varargs) - { - if (i && varargs == 1) - buf->writeByte(','); - buf->writestring("..."); - } - } - buf->writeByte(')'); -} - -void TypeDelegate::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ -#if 1 - OutBuffer args; - TypeFunction *tf = (TypeFunction *)next; - - tf->argsToHBuffer(&args, hgs); - buf->prependstring(args.toChars()); - buf->prependstring(" delegate"); - if (ident) - { buf->writebyte(' '); - buf->writestring(ident->toChars()); - } - next->next->toHBuffer2(buf, NULL, hgs); -#else - next->toHBuffer2(buf, Id::delegate, hgs); - if (ident) - buf->writestring(ident->toChars()); -#endif -} - -void TypeQualified::toHBuffer2Helper(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - int i; - - for (i = 0; i < idents.dim; i++) - { Identifier *id = (Identifier *)idents.data[i]; - - buf->writeByte('.'); - - if (id->dyncast() != DYNCAST_IDENTIFIER) - { - TemplateInstance *ti = (TemplateInstance *)id; - ti->toHBuffer(buf, hgs); - } - else - buf->writestring(id->toChars()); - } -} - -void TypeIdentifier::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - OutBuffer tbuf; - - tbuf.writestring(this->ident->toChars()); - toHBuffer2Helper(&tbuf, NULL, hgs); - buf->prependstring(tbuf.toChars()); - if (ident) - { buf->writeByte(' '); - buf->writestring(ident->toChars()); - } -} - -void TypeInstance::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - OutBuffer tbuf; - - tempinst->toHBuffer(&tbuf, hgs); - toHBuffer2Helper(&tbuf, NULL, hgs); - buf->prependstring(tbuf.toChars()); - if (ident) - { buf->writeByte(' '); - buf->writestring(ident->toChars()); - } -} - -void TypeTypeof::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - OutBuffer tbuf; - - tbuf.writestring("typeof("); - exp->toHBuffer(&tbuf, hgs); - tbuf.writeByte(')'); - toHBuffer2Helper(&tbuf, NULL, hgs); - buf->prependstring(tbuf.toChars()); - if (ident) - { buf->writeByte(' '); - buf->writestring(ident->toChars()); - } -} - -void TypeEnum::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - buf->prependstring(sym->toChars()); - if (ident) - { buf->writeByte(' '); - buf->writestring(ident->toChars()); - } -} - -void TypeTypedef::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - buf->prependstring(sym->toChars()); - if (ident) - { buf->writeByte(' '); - buf->writestring(ident->toChars()); - } -} - -void TypeStruct::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - buf->prependbyte(' '); - buf->prependstring(sym->toChars()); - if (ident) - buf->writestring(ident->toChars()); -} - -void TypeClass::toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) -{ - if (ident == Id::This) - return; - - buf->prependbyte(' '); - buf->prependstring(sym->toChars()); - if (ident) - buf->writestring(ident->toChars()); -} - -void Statement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toHBuffer(buf, hgs); - buf->writenl(); -} - -void ExpStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - if (exp) - exp->toHBuffer(buf, hgs); - buf->writeByte(';'); - if (!hgs->FLinit.init) - buf->writenl(); -} - -void DeclarationStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - exp->toHBuffer(buf, hgs); -} - -void CompoundStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ int i; - static int asmBlock = 0; - - for (i = 0; i < statements->dim; i++) - { Statement *s; - - s = (Statement *) statements->data[i]; - if (s) - { if (!asmBlock && s->isAsmStatement()) - { asmBlock = 1; - buf->writestring("asm"); - buf->writenl(); - buf->writebyte('{'); - buf->writenl(); - } - s->toHBuffer(buf, hgs); - } - } - - if (asmBlock) - { buf->writebyte('}'); - buf->writenl(); - asmBlock = 0; - } -} - -void ScopeStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writeByte('{'); - buf->writenl(); - - if (statement) - statement->toHBuffer(buf, hgs); - - buf->writeByte('}'); - buf->writenl(); -} - -void ScopeStatement::toHBuffer2(OutBuffer *buf, HdrGenState *hgs) -{ - if (statement) - statement->toHBuffer(buf, hgs); -} - -void WhileStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("while("); - condition->toHBuffer(buf, hgs); - buf->writebyte(')'); - buf->writenl(); - body->toHBuffer(buf, hgs); -} - -void DoStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("do"); - buf->writenl(); - body->toHBuffer(buf, hgs); - buf->writestring("while("); - condition->toHBuffer(buf, hgs); - buf->writebyte(')'); -} - -void ForStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("for("); - if (init) - { - hgs->FLinit.init++; - hgs->FLinit.decl = 0; - init->toHBuffer(buf, hgs); - if (hgs->FLinit.decl > 0) - buf->writebyte(';'); - hgs->FLinit.decl = 0; - hgs->FLinit.init--; - } - else - buf->writebyte(';'); - if (condition) - { buf->writebyte(' '); - condition->toHBuffer(buf, hgs); - } - buf->writebyte(';'); - if (increment) - { buf->writebyte(' '); - increment->toHBuffer(buf, hgs); - } - buf->writebyte(')'); - buf->writenl(); - buf->writebyte('{'); - buf->writenl(); - body->toHBuffer(buf, hgs); - buf->writebyte('}'); - buf->writenl(); -} - -void ForeachStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("foreach("); - int i; - for (int i = 0; i < arguments->dim; i++) - { - Argument *a = (Argument *)arguments->data[i]; - if (i) - buf->writestring(", "); - if (a->inout == InOut) - buf->writestring("inout "); - a->type->toHBuffer(buf, a->ident, hgs); - } - buf->writestring("; "); - aggr->toHBuffer(buf, hgs); - buf->writebyte(')'); - buf->writenl(); - buf->writebyte('{'); - buf->writenl(); - if (body) - { body->toHBuffer(buf, hgs); - } - buf->writebyte('}'); - buf->writenl(); -} - -void IfStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("if("); - condition->toHBuffer(buf, hgs); - buf->writebyte(')'); - buf->writenl(); - ifbody->toHBuffer(buf, hgs); - if (elsebody) - { buf->writestring("else"); - buf->writenl(); - elsebody->toHBuffer(buf, hgs); - } -} - -void ConditionalStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - int error = 0; - int inc = condition->inc; - if (!inc) - { - unsigned errors = global.errors; - global.gag++; - inc = condition->include(NULL,NULL); - if (errors != global.errors) - { error = 1; - inc = 0; - } - global.gag--; - global.errors = errors; - } - - if (!error || inc) - { - // Emit just conditional code (version and debug) - if (inc == 1) - { - ifbody->toHBuffer(buf, hgs); - } - else - { - if (elsebody) - elsebody->toHBuffer(buf, hgs); - } - } - else - { - // Emit everything (iftype and static if). - // These can always be resolved by the symbol file end-user compiler - OutBuffer ibuf, ebuf; - ifbody->toHBuffer(&ibuf, hgs); - if (elsebody) - { - OutBuffer tbuf; - elsebody->toHBuffer(&tbuf, hgs); - if (tbuf.offset) - { ebuf.writebyte('}'); - ebuf.writenl(); - ebuf.writestring("else"); - ebuf.writenl(); - ebuf.writebyte('{'); - ebuf.writenl(); - ebuf.write(&tbuf); - } - } - if (ibuf.offset || ebuf.offset) - { - condition->toHBuffer(buf, hgs); - buf->writenl(); - buf->writebyte('{'); - buf->writenl(); - if (ibuf.offset) - buf->write(&ibuf); - if (ebuf.offset) - buf->write(&ebuf); - buf->writebyte('}'); - buf->writenl(); - } - } -} - -void PragmaStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->printf("PragmaStatement::toHBuffer()"); - buf->writenl(); -} - -void StaticAssertStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - sa->toHBuffer(buf, hgs); -} - -void SwitchStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("switch("); - condition->toHBuffer(buf, hgs); - buf->writebyte(')'); - buf->writenl(); - if (body) - { if (!body->isScopeStatement()) - { buf->writebyte('{'); - buf->writenl(); - buf->writebyte('}'); - buf->writenl(); - } - else - { - body->toHBuffer(buf, hgs); - } - } -} - -void CaseStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("case "); - exp->toHBuffer(buf, hgs); - buf->writebyte(':'); - buf->writenl(); - ScopeStatement *ss = statement->isScopeStatement(); - if (ss) - statement->toHBuffer2(buf, hgs); - else - statement->toHBuffer(buf, hgs); -} - -void DefaultStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - OutBuffer tbuf; - ScopeStatement *ss = statement->isScopeStatement(); - if (ss) - statement->toHBuffer2(&tbuf, hgs); - else - statement->toHBuffer(&tbuf, hgs); - - if (tbuf.offset) - { buf->writestring("default:"); - buf->writenl(); - buf->write(&tbuf); - } -} - -void GotoDefaultStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("goto default;"); - buf->writenl(); -} - -void GotoCaseStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("goto case"); - if (exp) - { buf->writebyte(' '); - exp->toHBuffer(buf, hgs); - } - buf->writebyte(';'); - buf->writenl(); -} - -void SwitchErrorStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("SwitchErrorStatement::toHBuffer()"); - buf->writenl(); -} - -void ReturnStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->printf("return "); - if (exp) - exp->toHBuffer(buf, hgs); - buf->writeByte(';'); - buf->writenl(); -} - -void BreakStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("break;"); - buf->writenl(); -} - -void ContinueStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("continue"); - if (ident) - { buf->writebyte(' '); - buf->writestring(ident->toChars()); - } - buf->writebyte(';'); - buf->writenl(); -} - -void SynchronizedStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("synchronized"); - if (exp) - { buf->writebyte('('); - exp->toHBuffer(buf, hgs); - buf->writebyte(')'); - } - if (body) - { - buf->writebyte(' '); - body->toHBuffer(buf, hgs); - } -} - -void WithStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("with("); - exp->toHBuffer(buf, hgs); - buf->writebyte(')'); - buf->writenl(); - body->toHBuffer(buf, hgs); -} - -void TryCatchStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("try"); - buf->writenl(); - if (body) - body->toHBuffer(buf, hgs); - int i; - for (i = 0; i < catches->dim; i++) - { - Catch *c = (Catch *)catches->data[i]; - c->toHBuffer(buf, hgs); - } -} - -void Catch::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("catch"); - if (type) - { buf->writebyte('('); - type->toHBuffer(buf, ident, hgs); - buf->writebyte(')'); - } - buf->writenl(); - buf->writebyte('{'); - buf->writenl(); - handler->toHBuffer(buf, hgs); - buf->writebyte('}'); - buf->writenl(); -} - -void TryFinallyStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - if (!body->isTryCatchStatement()) - { buf->printf("try"); - buf->writenl(); - } - //buf->writebyte('{'); - //buf->writenl(); - body->toHBuffer(buf, hgs); - //buf->writebyte('}'); - //buf->writenl(); - buf->writestring("finally"); - buf->writenl(); - buf->writebyte('{'); - buf->writenl(); - finalbody->toHBuffer(buf, hgs); - buf->writeByte('}'); - buf->writenl(); -} - -void ThrowStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->printf("throw "); - exp->toHBuffer(buf, hgs); - buf->writeByte(';'); - buf->writenl(); -} - -void VolatileStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("volatile"); - if (statement) - { if (statement->isScopeStatement()) - buf->writenl(); - else - buf->writebyte(' '); - statement->toHBuffer(buf, hgs); - } -} - -void GotoStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("goto "); - //label->toHBuffer(buf, hgs); - buf->writestring(ident->toChars()); - buf->writebyte(';'); - buf->writenl(); -} - -void LabelStatement::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring(ident->toChars()); - buf->writebyte(':'); - buf->writenl(); - if (statement) - statement->toHBuffer(buf, hgs); -} - -void StaticAssert::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring(kind()); - buf->writeByte('('); - exp->toHBuffer(buf, hgs); - buf->writestring(");"); - buf->writenl(); -} - -void StructDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ int i; - - buf->printf("%s %s", kind(), toChars()); - if (!members) - { - buf->writeByte(';'); - buf->writenl(); - return; - } - buf->writenl(); - buf->writeByte('{'); - buf->writenl(); - for (i = 0; i < members->dim; i++) - { - Dsymbol *s = (Dsymbol *)members->data[i]; - - //buf->writestring(" "); - s->toHBuffer(buf, hgs); - } - buf->writeByte('}'); - buf->writenl(); -} - -char *TemplateDeclaration::toHChars(HdrGenState *hgs) -{ - OutBuffer buf; - char *s; - - toHBuffer(&buf, hgs); - s = buf.toChars(); - buf.data = NULL; - return s; -} - -void TemplateDeclaration::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - int i; - - hgs->tpltMember++; - - buf->writestring("template "); - buf->writestring(ident->toChars()); - buf->writeByte('('); - for (i = 0; i < parameters->dim; i++) - { - TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; - if (i) - buf->writeByte(','); - tp->toHBuffer(buf, hgs); - } - buf->writeByte(')'); - buf->writenl(); - buf->writebyte('{'); - buf->writenl(); - for (i = 0; i < members->dim; i++) - { - Dsymbol *s = (Dsymbol *)members->data[i]; - s->toHBuffer(buf, hgs); // need to check ident here to replace built-in identifiers (i.e.: '_ctor') - } - buf->writebyte('}'); - buf->writenl(); - - hgs->tpltMember--; -} - -void TemplateTypeParameter::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring(ident->toChars()); - if (specType) - { - buf->writestring(" : "); - specType->toHBuffer(buf, NULL, hgs); - } - if (defaultType) - { - buf->writestring(" = "); - defaultType->toHBuffer(buf, NULL, hgs); - } -} - -void TemplateAliasParameter::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("alias "); - buf->writestring(ident->toChars()); - if (specAliasT) - { - buf->writestring(" : "); - specAliasT->toHBuffer(buf, NULL, hgs); - } - if (defaultAlias) - { - buf->writestring(" = "); - defaultAlias->toHBuffer(buf, NULL, hgs); - } -} - -void TemplateValueParameter::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - valType->toHBuffer(buf, ident, hgs); - if (specValue) - { - buf->writestring(" : "); - specValue->toHBuffer(buf, hgs); - } - if (defaultValue) - { - buf->writestring(" = "); - defaultValue->toHBuffer(buf, hgs); - } -} - -char *TemplateInstance::toHChars(HdrGenState *hgs) -{ - OutBuffer buf; - char *s; - - toHBuffer(&buf, hgs); - s = buf.toChars(); - buf.data = NULL; - return s; -} - -void TemplateInstance::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - // Don't emit instances - if (!hgs->emitInst && this->inst) - return; - - int i; - - for (i = 0; i < idents.dim; i++) - { Identifier *id = (Identifier *)idents.data[i]; - - if (i) - buf->writeByte('.'); - buf->writestring(id->toChars()); - } - buf->writestring("!("); - - for (i = 0; i < tiargs->dim; i++) - { - if (i) - buf->writeByte(','); - Object *oarg = (Object *)tiargs->data[i]; - Type *t = isType(oarg); - Expression *e = isExpression(oarg); - Dsymbol *s = isDsymbol(oarg); - if (t) - t->toHBuffer(buf, NULL, hgs); - else if (e) - e->toHBuffer(buf, hgs); - else if (s) - { - char *p = s->ident ? s->ident->toChars() : s->toChars(); - buf->writestring(p); - } - else if (!oarg) - { - buf->writestring("NULL"); - } - else - { - assert(0); - } - } - buf->writeByte(')'); -} - -void TemplateMixin::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writestring("mixin "); - int i; - for (i = 0; i < idents->dim; i++) - { Identifier *id = (Identifier *)idents->data[i]; - - if (i) - buf->writeByte('.'); - buf->writestring(id->toChars()); - } - if (tiargs && tiargs->dim) - { - buf->writestring("!("); - for (i = 0; i < tiargs->dim; i++) - { if (i) - buf->writebyte(','); - Object *oarg = (Object *)tiargs->data[i]; - Type *t = isType(oarg); - Expression *e = isExpression(oarg); - Dsymbol *s = isDsymbol(oarg); - if (t) - t->toHBuffer(buf, NULL, hgs); - else if (e) - e->toHBuffer(buf, hgs); - else if (s) - { - char *p = s->ident ? s->ident->toChars() : s->toChars(); - buf->writestring(p); - } - else if (!oarg) - { - buf->writestring("NULL"); - } - else - { - assert(0); - } - } - buf->writebyte(')'); - } - else if (tdtypes.dim) - { - buf->writestring("!("); - for (i = 0; i < tdtypes.dim; i++) - { if (i) - buf->writebyte(','); - Object *oarg = (Object *)tdtypes.data[i]; - Type *t = isType(oarg); - Expression *e = isExpression(oarg); - Dsymbol *s = isDsymbol(oarg); - if (t) - t->toHBuffer(buf, NULL, hgs); - else if (e) - e->toHBuffer(buf, hgs); - else if (s) - { - char *p = s->ident ? s->ident->toChars() : s->toChars(); - buf->writestring(p); - } - else if (!oarg) - { - buf->writestring("NULL"); - } - else - { - assert(0); - } - } - buf->writebyte(')'); - } - if (tempdecl) - { - Identifier *tid = genIdent(); - int res = strcmp(ident->toChars(),tid->toChars()); - if (res) - { buf->writebyte(' '); - buf->writestring(ident->toChars()); - } - } - buf->writebyte(';'); - buf->writenl(); -} - -void DebugSymbol::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -void VersionSymbol::toHBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - toCBuffer(buf); -} - -/*************************************/ - -Type *TypeFunction::hdrSyntaxCopy() -{ - Type *treturn = NULL; - if (next) - treturn = next->syntaxCopy(); - Array *args = Argument::arraySyntaxCopy(arguments); - Type *t = new TypeFunction(args, treturn, varargs, linkage); - return t; -} - -void FuncDeclaration::hdrSyntaxCopy(FuncDeclaration *f) -{ - // Initialize pointer back to original FuncDeclaration - if (!hcopyof) - hcopyof = this; - - // New copy points back to original - f->hcopyof = hcopyof; - - // Syntax copy for header file - if (!hbody) // Don't overwrite original - { if (fbody) // Make copy for both old and new instances - { hbody = fbody->syntaxCopy(); - f->hbody = fbody->syntaxCopy(); - } - } - else // Make copy of original for new instance - { - f->hbody = hbody->syntaxCopy(); - } - - if (!htype) - { TypeFunction *tf = (TypeFunction *)type; - - if (!tf) - { CtorDeclaration *cd = NULL; - DtorDeclaration *dd = NULL; - StaticCtorDeclaration *scd = NULL; - StaticDtorDeclaration *sdd = NULL; - NewDeclaration *nd = NULL; - DeleteDeclaration *ld = NULL; - if ((cd = isCtorDeclaration())) - tf = new TypeFunction(cd->arguments,cd->type,cd->varargs,LINKd); - else if ((dd = isDtorDeclaration())) - tf = new TypeFunction(NULL,dd->type,NULL,LINKd); - else if ((scd = isStaticCtorDeclaration())) - tf = new TypeFunction(NULL,scd->type,NULL,LINKd); - else if ((sdd = isStaticDtorDeclaration())) - tf = new TypeFunction(NULL,sdd->type,NULL,LINKd); - else if ((nd = isNewDeclaration())) - tf = new TypeFunction(nd->arguments,nd->type,nd->varargs,LINKd); - else if ((ld = isDeleteDeclaration())) - tf = new TypeFunction(ld->arguments,ld->type,NULL,LINKd); - } - - if (tf) - { htype = tf->hdrSyntaxCopy(); - f->htype = tf->hdrSyntaxCopy(); - } - } - else - { - f->htype = ((TypeFunction *)htype)->hdrSyntaxCopy(); - } - - if (!hrequire) - { if (frequire) - { hrequire = frequire->syntaxCopy(); - f->hrequire = frequire->syntaxCopy(); - } - } - else - { - f->hrequire = hrequire->syntaxCopy(); - } - - if (!hensure) - { if (fensure) - { hensure = fensure->syntaxCopy(); - f->hensure = fensure->syntaxCopy(); - } - } - else - { - f->hensure = hensure->syntaxCopy(); - } -} /*************************************/ diff -uNr dmd-0.141/dmd/src/dmd/hdrgen.h dmd-0.142/dmd/src/dmd/hdrgen.h --- dmd-0.141/dmd/src/dmd/hdrgen.h 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/hdrgen.h 2005-12-12 00:32:14.000000000 +0100 @@ -0,0 +1,31 @@ + +// Copyright (c) 1999-2005 by Digital Mars +// All Rights Reserved +// initial header generation implementation by Dave Fladebo +// www.digitalmars.com +// License for redistribution is by either the Artistic License +// in artistic.txt, or the GNU General Public License in gnu.txt. +// See the included readme.txt for details. + + +struct HdrGenState +{ + int hdrgen; // 1 if generating header file + int tpltMember; + int inCallExp; + int inPtrExp; + int inSlcExp; + int inDotExp; + int inBinExp; + int inArrExp; + int emitInst; + struct + { + int init; + int decl; + } FLinit; + + HdrGenState() { memset(this, 0, sizeof(HdrGenState)); } +}; + + diff -uNr dmd-0.141/dmd/src/dmd/identifier.c dmd-0.142/dmd/src/dmd/identifier.c --- dmd-0.141/dmd/src/dmd/identifier.c 2005-04-01 15:11:12.000000000 +0200 +++ dmd-0.142/dmd/src/dmd/identifier.c 2005-12-12 00:53:16.000000000 +0100 @@ -1,5 +1,5 @@ -// Copyright (c) 1999-2004 by Digital Mars +// Copyright (c) 1999-2005 by Digital Mars // All Rights Reserved // written by Walter Bright // www.digitalmars.com @@ -43,6 +43,26 @@ return (char *)string; } +char *Identifier::toHChars2() +{ + char *p = NULL; + + if (this == Id::ctor) p = "this"; + else if (this == Id::dtor) p = "~this"; + else if (this == Id::classInvariant) p = "invariant"; + else if (this == Id::unitTest) p = "unittest"; + else if (this == Id::staticCtor) p = "static this"; + else if (this == Id::staticDtor) p = "static ~this"; + else if (this == Id::dollar) p = "$"; + else if (this == Id::withSym) p = "with"; + else if (this == Id::result) p = "result"; + else if (this == Id::returnLabel) p = "return"; + else + p = toChars(); + + return p; +} + void Identifier::print() { printf("%s",string); diff -uNr dmd-0.141/dmd/src/dmd/identifier.h dmd-0.142/dmd/src/dmd/identifier.h --- dmd-0.141/dmd/src/dmd/identifier.h 2005-12-01 00:35:58.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/identifier.h 2005-12-12 00:53:34.000000000 +0100 @@ -1,5 +1,5 @@ -// Copyright (c) 1999-2004 by Digital Mars +// Copyright (c) 1999-2005 by Digital Mars // All Rights Reserved // written by Walter Bright // www.digitalmars.com @@ -30,8 +30,8 @@ char *toChars(); #ifdef _DH char *toHChars(); - char *toHChars2(); //New #endif + char *toHChars2(); int dyncast(); static Identifier *generateId(char *prefix); diff -uNr dmd-0.141/dmd/src/dmd/import.c dmd-0.142/dmd/src/dmd/import.c --- dmd-0.141/dmd/src/dmd/import.c 2005-06-12 00:50:46.000000000 +0200 +++ dmd-0.142/dmd/src/dmd/import.c 2005-12-12 19:53:22.000000000 +0100 @@ -1,5 +1,5 @@ -// Copyright (c) 1999-2002 by Digital Mars +// Copyright (c) 1999-2005 by Digital Mars // All Rights Reserved // written by Walter Bright // www.digitalmars.com @@ -16,6 +16,7 @@ #include "identifier.h" #include "module.h" #include "scope.h" +#include "hdrgen.h" /********************************* Import ****************************/ @@ -132,8 +133,11 @@ return s->isImport() != NULL; } -void Import::toCBuffer(OutBuffer *buf) +void Import::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { + if (hgs->hdrgen && id == Id::object) + return; // object is imported by default + buf->writestring("import "); if (packages && packages->dim) { int i; diff -uNr dmd-0.141/dmd/src/dmd/import.h dmd-0.142/dmd/src/dmd/import.h --- dmd-0.141/dmd/src/dmd/import.h 2005-11-26 22:16:02.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/import.h 2005-12-12 15:13:24.000000000 +0100 @@ -1,5 +1,5 @@ -// Copyright (c) 1999-2002 by Digital Mars +// Copyright (c) 1999-2005 by Digital Mars // All Rights Reserved // written by Walter Bright // www.digitalmars.com @@ -41,10 +41,7 @@ void semantic2(Scope *sc); Dsymbol *search(Identifier *ident, int flags); int overloadInsert(Dsymbol *s); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Import *isImport() { return this; } }; diff -uNr dmd-0.141/dmd/src/dmd/init.c dmd-0.142/dmd/src/dmd/init.c --- dmd-0.141/dmd/src/dmd/init.c 2005-10-19 23:48:56.000000000 +0200 +++ dmd-0.142/dmd/src/dmd/init.c 2005-12-12 14:27:20.000000000 +0100 @@ -89,7 +89,7 @@ } -void VoidInitializer::toCBuffer(OutBuffer *buf) +void VoidInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("void"); } @@ -214,8 +214,24 @@ } -void StructInitializer::toCBuffer(OutBuffer *buf) +void StructInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { + buf->writebyte('{'); + for (int i = 0; i < field.dim; i++) + { + if (i > 0) + buf->writebyte(','); + Identifier *id = (Identifier *)field.data[i]; + if (id) + { + buf->writestring(id->toChars()); + buf->writebyte(':'); + } + Initializer *iz = (Initializer *)value.data[i]; + if (iz) + iz->toCBuffer(buf, hgs); + } + buf->writebyte('}'); } /********************************** ArrayInitializer ************************************/ @@ -316,8 +332,24 @@ } -void ArrayInitializer::toCBuffer(OutBuffer *buf) +void ArrayInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { + buf->writebyte('['); + for (int i = 0; i < index.dim; i++) + { + if (i > 0) + buf->writebyte(','); + Expression *ex = (Expression *)index.data[i]; + if (ex) + { + ex->toCBuffer(buf, hgs); + buf->writebyte(':'); + } + Initializer *iz = (Initializer *)value.data[i]; + if (iz) + iz->toCBuffer(buf, hgs); + } + buf->writebyte(']'); } @@ -387,9 +419,9 @@ } -void ExpInitializer::toCBuffer(OutBuffer *buf) +void ExpInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - exp->toCBuffer(buf); + exp->toCBuffer(buf, hgs); } diff -uNr dmd-0.141/dmd/src/dmd/init.h dmd-0.142/dmd/src/dmd/init.h --- dmd-0.141/dmd/src/dmd/init.h 2005-12-01 00:35:12.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/init.h 2005-12-12 15:14:10.000000000 +0100 @@ -35,10 +35,7 @@ virtual Initializer *semantic(Scope *sc, Type *t); virtual Type *inferType(Scope *sc); virtual Expression *toExpression() = 0; - virtual void toCBuffer(OutBuffer *buf) = 0; -#ifdef _DH - virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs) = 0; -#endif + virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs) = 0; static Array *arraySyntaxCopy(Array *ai); @@ -56,10 +53,7 @@ Initializer *syntaxCopy(); Initializer *semantic(Scope *sc, Type *t); Expression *toExpression(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); dt_t *toDt(); @@ -77,10 +71,7 @@ void addInit(Identifier *field, Initializer *value); Initializer *semantic(Scope *sc, Type *t); Expression *toExpression(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); dt_t *toDt(); }; @@ -98,10 +89,7 @@ void addInit(Expression *index, Initializer *value); Initializer *semantic(Scope *sc, Type *t); Expression *toExpression(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); dt_t *toDt(); dt_t *toDtBit(); // for bit arrays @@ -116,10 +104,7 @@ Initializer *semantic(Scope *sc, Type *t); Type *inferType(Scope *sc); Expression *toExpression(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); dt_t *toDt(); diff -uNr dmd-0.141/dmd/src/dmd/inline.c dmd-0.142/dmd/src/dmd/inline.c --- dmd-0.141/dmd/src/dmd/inline.c 2005-12-01 02:53:28.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/inline.c 2005-12-22 20:46:28.000000000 +0100 @@ -33,9 +33,7 @@ { int nested; int hasthis; -#ifdef _DH - int hdrscan; // Is this an inline scan for 'header' content? -#endif + int hdrscan; // !=0 if inline scan for 'header' content FuncDeclaration *fd; }; @@ -60,19 +58,6 @@ s = (Statement *) statements->data[i]; if (s) { -#ifdef _DH - if (ics->hdrscan) - { if (s->incontract) - continue; // bypass in contract - - GotoStatement *gs = s->isGotoStatement(); - if (gs && gs->label->statement->isReturnLabel) - ics->hdrscan++; // skip out contract - - if (ics->hdrscan > 1) - break; - } -#endif cost += s->inlineCost(ics); if (cost >= COST_MAX) break; @@ -133,10 +118,8 @@ for (int i = 0; i < arguments->dim; i++) { Expression *e = (Expression *)arguments->data[i]; -#ifdef _DH - if (e) // To avoid crash with DMDFE for some expressions -#endif - cost += e->inlineCost(ics); + if (e) + cost += e->inlineCost(ics); } } return cost; @@ -150,16 +133,18 @@ int ThisExp::inlineCost(InlineCostState *ics) { FuncDeclaration *fd = ics->fd; - if (fd->isNested() || !ics->hasthis) - return COST_MAX; + if (!ics->hdrscan) + if (fd->isNested() || !ics->hasthis) + return COST_MAX; return 1; } int SuperExp::inlineCost(InlineCostState *ics) { FuncDeclaration *fd = ics->fd; - if (fd->isNested() || !ics->hasthis) - return COST_MAX; + if (!ics->hdrscan) + if (fd->isNested() || !ics->hasthis) + return COST_MAX; return 1; } @@ -181,7 +166,7 @@ vd = declaration->isVarDeclaration(); if (vd) { - if (vd->isDataseg()) + if (!ics->hdrscan && vd->isDataseg()) return COST_MAX; cost += 1; @@ -362,9 +347,7 @@ for (int i = 0; i < a->dim; i++) { Expression *e = (Expression *)a->data[i]; -#ifdef _DH - if (e) // To avoid crash with DMDFE for some expressions -#endif + if (e) { e = e->doInline(ids); newa->data[i] = (void *)e; @@ -834,9 +817,7 @@ for (int i = 0; i < arguments->dim; i++) { Expression *e = (Expression *)arguments->data[i]; -#ifdef _DH - if (e) // to avoid a crash with DMDFE when scanning arguments with variadic parameters -#endif + if (e) { e = e->inlineScan(iss); arguments->data[i] = (void *)e; @@ -962,11 +943,7 @@ } } -#ifdef _DH int FuncDeclaration::canInline(int hasthis, int hdrscan) -#else -int FuncDeclaration::canInline(int hasthis) -#endif { InlineCostState ics; int cost; @@ -977,7 +954,7 @@ printf("FuncDeclaration::canInline('%s')\n", toChars()); #endif - if (inlineNest || !semanticRun) + if (inlineNest || (!semanticRun && !hdrscan)) { #if CANINLINE_LOG printf("\t1: no, inlineNest = %d, semanticRun = %d\n", inlineNest, semanticRun); @@ -1010,6 +987,10 @@ TypeFunction *tf = (TypeFunction *)(type); if ( + !fbody || + tf->varargs == 1 || // no variadic parameter lists + !hdrscan && + ( #if 0 isCtorDeclaration() || // cannot because need to convert: // return; @@ -1018,11 +999,9 @@ #endif isSynchronized() || isImportedSymbol() || - !fbody || - tf->varargs == 1 || // no variadic parameter lists nestedFrameRef || // no nested references to this frame (isVirtual() && !isFinal()) - ) + )) { goto Lno; } @@ -1043,9 +1022,7 @@ memset(&ics, 0, sizeof(ics)); ics.hasthis = hasthis; ics.fd = this; -#ifdef _DH - ics.hdrscan = hdrscan ? 1 : 0; -#endif + ics.hdrscan = hdrscan; cost = fbody->inlineCost(&ics); #if CANINLINE_LOG printf("cost = %d\n", cost); @@ -1053,26 +1030,20 @@ if (cost >= COST_MAX) goto Lno; -#ifdef _DH if (!hdrscan) // Don't scan recursively for header content scan -#endif - inlineScan(); + inlineScan(); Lyes: -#ifdef _DH if (!hdrscan) // Don't modify inlineStatus for header content scan -#endif - inlineStatus = ILSyes; + inlineStatus = ILSyes; #if CANINLINE_LOG printf("\tyes\n"); #endif return 1; Lno: -#ifdef _DH if (!hdrscan) // Don't modify inlineStatus for header content scan -#endif - inlineStatus = ILSno; + inlineStatus = ILSno; #if CANINLINE_LOG printf("\tno\n"); #endif diff -uNr dmd-0.141/dmd/src/dmd/lexer.c dmd-0.142/dmd/src/dmd/lexer.c --- dmd-0.141/dmd/src/dmd/lexer.c 2005-12-01 23:38:38.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/lexer.c 2005-12-28 20:52:12.000000000 +0100 @@ -96,10 +96,12 @@ return ::operator new(size); } +#ifdef DEBUG void Token::print() { printf("%s\n", toChars()); } +#endif char *Token::toChars() { char *p; @@ -156,7 +158,40 @@ #if CSTRINGS p = string; #else - p = (char *)ustring; + { OutBuffer buf; + + buf.writeByte('"'); + for (unsigned i = 0; i < len; ) + { unsigned c; + + utf_decodeChar((unsigned char *)ustring, len, &i, &c); + switch (c) + { + case 0: + break; + + case '"': + case '\\': + buf.writeByte('\\'); + default: + if (isprint(c)) + buf.writeByte(c); + else if (c <= 0x7F) + buf.printf("\\x%02x", c); + else if (c <= 0xFFFF) + buf.printf("\\u%04x", c); + else + buf.printf("\\U%08x", c); + continue; + } + break; + } + buf.writeByte('"'); + if (postfix) + buf.writeByte('"'); + buf.writeByte(0); + p = (char *)buf.extractData(); + } #endif break; @@ -1396,6 +1431,7 @@ * u 'u' or 'U' */ +#if 0 unsigned Lexer::wchar(unsigned u) { unsigned value; @@ -1426,6 +1462,7 @@ } return value; } +#endif /************************************** * Read in a number. @@ -1670,7 +1707,7 @@ uinteger_t n; // unsigned >=64 bit integer type - if (stringbuffer.offset == 1 && (state == STATE_decimal || state == STATE_0)) + if (stringbuffer.offset == 2 && (state == STATE_decimal || state == STATE_0)) n = stringbuffer.data[0] - '0'; else { @@ -2102,8 +2139,7 @@ char *msg; c = *s; - if (!(c & 0x80)) - return c; + assert(c & 0x80); // Check length of remaining string up to 6 UTF-8 characters for (len = 1; len < 6 && s[len]; len++) @@ -2460,6 +2496,7 @@ Token::tochars[TOKug] = "!<="; Token::tochars[TOKnot] = "!"; + Token::tochars[TOKbool] = "!!"; Token::tochars[TOKshl] = "<<"; Token::tochars[TOKshr] = ">>"; Token::tochars[TOKushr] = ">>>"; @@ -2501,6 +2538,8 @@ Token::tochars[TOKcatass] = "~="; Token::tochars[TOKcat] = "~"; Token::tochars[TOKcall] = "call"; + Token::tochars[TOKidentity] = "is"; + Token::tochars[TOKnotidentity] = "!is"; Token::tochars[TOKorass] = "|="; diff -uNr dmd-0.141/dmd/src/dmd/lexer.h dmd-0.142/dmd/src/dmd/lexer.h --- dmd-0.141/dmd/src/dmd/lexer.h 2005-09-29 19:25:16.000000000 +0200 +++ dmd-0.142/dmd/src/dmd/lexer.h 2005-12-27 00:18:46.000000000 +0100 @@ -73,6 +73,7 @@ TOKequal, TOKnotequal, TOKidentity, TOKnotidentity, TOKindex, TOKis, + TOKbool, // NCEG floating point compares // !<>= <> <>= !> !>= !< !<= !<> diff -uNr dmd-0.141/dmd/src/dmd/mars.c dmd-0.142/dmd/src/dmd/mars.c --- dmd-0.141/dmd/src/dmd/mars.c 2005-12-01 11:42:02.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/mars.c 2005-12-27 00:20:56.000000000 +0100 @@ -29,6 +29,7 @@ #include "mtype.h" #include "id.h" #include "cond.h" +#include "expression.h" void getenv_setargv(const char *envvar, int *pargc, char** *pargv); @@ -38,9 +39,7 @@ { mars_ext = "d"; sym_ext = "d"; -#ifdef _DH - hdr_ext = "d"; -#endif + hdr_ext = "di"; doc_ext = "html"; ddoc_ext = "ddoc"; @@ -54,7 +53,7 @@ copyright = "Copyright (c) 1999-2005 by Digital Mars"; written = "written by Walter Bright"; - version = "v0.141"; + version = "v0.142"; global.structalign = 8; memset(¶ms, 0, sizeof(Param)); @@ -134,6 +133,7 @@ \n\ files.d D source files\n\ -c do not link\n\ + -cov do code coverage analysis\n\ -D generate documentation\n\ -Dddocdir write documentation file to docdir directory\n\ -Dffilename write documentation file to filename\n\ @@ -142,6 +142,7 @@ -debug=level compile in debug code <= level\n\ -debug=ident compile in debug code identified by ident\n\ -g add symbolic debug info\n\ + -H generate 'header' file\n\ -Hdhdrdir write 'header' file to hdrdir directory\n\ -Hffilename write 'header' file to filename\n\ --help print help\n\ @@ -176,6 +177,7 @@ Type::init(); Id::initialize(); Module::init(); + initPrecedence(); backend_init(); @@ -603,11 +605,7 @@ } id = new Identifier(name, 0); -#ifdef _DH m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration); -#else - m = new Module((char *) files.data[i], id, global.params.doDocComments); -#endif modules.push(m); global.params.objfiles->push(m->objfile->name->str); @@ -644,21 +642,27 @@ global.params.link = 0; } } + if (global.errors) + fatal(); #ifdef _DH if (global.params.doHdrGeneration) { - /* Make syntax copies for header file generation after parsing but - * prior to semantic analysis. + /* Generate 'header' import files. + * Since 'header' import files must be independent of command + * line switches and what else is imported, they are generated + * before any semantic analysis. */ for (i = 0; i < modules.dim; i++) { m = (Module *)modules.data[i]; - m->syntaxCopy(NULL); // The original data is *not* overwritten + if (global.params.verbose) + printf("import %s\n", m->toChars()); + m->genhdrfile(); } } -#endif if (global.errors) fatal(); +#endif // Do semantic analysis for (i = 0; i < modules.dim; i++) @@ -693,22 +697,6 @@ if (global.errors) fatal(); -#ifdef _DH - if (global.params.doHdrGeneration) - { - /* Generate header files after semantic analysis but before the - * semantics of function bodies can be changed by function inlining. - */ - for (i = 0; i < modules.dim; i++) - { - m = (Module *)modules.data[i]; - m->genhdrbufr(); - } - if (global.errors) - fatal(); - } -#endif - // Scan for functions to inline if (global.params.useInline) { @@ -735,10 +723,6 @@ m->deleteObjFile(); else { -#ifdef _DH - if (global.params.doHdrGeneration) - m->genhdrfile(); // format and output header content -#endif if (global.params.doDocComments) m->gendocfile(); } diff -uNr dmd-0.141/dmd/src/dmd/mars.h dmd-0.142/dmd/src/dmd/mars.h --- dmd-0.141/dmd/src/dmd/mars.h 2005-11-28 16:44:08.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/mars.h 2005-12-12 23:41:18.000000000 +0100 @@ -55,11 +55,9 @@ char *docname; // write documentation file to docname Array *ddocfiles; // macro include files for Ddoc -#ifdef _DH char doHdrGeneration; // process embedded documentation comments char *hdrdir; // write 'header' file to docdir directory char *hdrname; // write 'header' file to docname -#endif unsigned debuglevel; // debug level Array *debugids; // debug identifiers @@ -93,9 +91,7 @@ char *obj_ext; char *doc_ext; // for Ddoc generated files char *ddoc_ext; // for Ddoc macro include files -#ifdef _DH - char *hdr_ext; -#endif + char *hdr_ext; // for D 'header' import files char *copyright; char *written; Array *path; // Array of char*'s which form the import lookup path diff -uNr dmd-0.141/dmd/src/dmd/module.c dmd-0.142/dmd/src/dmd/module.c --- dmd-0.141/dmd/src/dmd/module.c 2005-12-01 01:53:38.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/module.c 2005-12-21 13:17:22.000000000 +0100 @@ -15,6 +15,8 @@ #include #endif +#include "mem.h" + #include "mars.h" #include "module.h" #include "parse.h" @@ -23,6 +25,7 @@ #include "id.h" #include "import.h" #include "dsymbol.h" +#include "hdrgen.h" #define MARS 1 #include "html.h" @@ -38,11 +41,7 @@ modules = new DsymbolTable(); } -#ifdef _DH Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen) -#else -Module::Module(char *filename, Identifier *ident, int doDocComment) -#endif : Package(ident) { FileName *srcfilename; @@ -122,12 +121,10 @@ setDocfile(); } -#ifdef _DH if (doHdrGen) { setHdrfile(); } -#endif objfile = new File(objfilename); symfile = new File(symfilename); @@ -159,7 +156,6 @@ docfile = new File(docfilename); } -#ifdef _DH void Module::setHdrfile() { FileName *hdrfilename; @@ -185,7 +181,6 @@ hdrfile = new File(hdrfilename); } -#endif void Module::deleteObjFile() { @@ -235,22 +230,47 @@ filename = (char *)buf.extractData(); } -#ifdef _DH m = new Module(filename, ident, 0, 0); -#else - m = new Module(filename, ident, 0); -#endif m->loc = loc; - // Find the sym file - char *s; - s = FileName::searchPath(global.path, m->symfile->toChars(), 1); - if (s) - m->symfile = new File(s); - - // BUG: the sym file is actually a source file that is - // parsed. Someday make it a real symbol table - m->srcfile = m->symfile; + /* Search along global.path for .di file, then .d file. + */ + char *result = NULL; + FileName *fdi = FileName::forceExt(filename, global.hdr_ext); + FileName *fd = FileName::forceExt(filename, global.mars_ext); + char *sdi = fdi->toChars(); + char *sd = fd->toChars(); + + if (FileName::exists(sdi)) + result = sdi; + else if (FileName::exists(sd)) + result =sd; + else if (FileName::absolute(filename)) + ; + else if (!global.path) + ; + else + { + for (size_t i = 0; i < global.path->dim; i++) + { + char *p = (char *)global.path->data[i]; + char *n = FileName::combine(p, sdi); + if (FileName::exists(n)) + { result = n; + break; + } + mem.free(n); + n = FileName::combine(p, sd); + if (FileName::exists(n)) + { result = n; + break; + } + mem.free(n); + } + } + if (result) + m->srcfile = new File(result); + m->read(loc); m->parse(); @@ -667,6 +687,7 @@ void Module::gensymfile() { OutBuffer buf; + HdrGenState hgs; int i; //printf("Module::gensymfile()\n"); @@ -679,7 +700,7 @@ Dsymbol *s; s = (Dsymbol *)members->data[i]; - s->toCBuffer(&buf); + s->toCBuffer(&buf, &hgs); } // Transfer image to file diff -uNr dmd-0.141/dmd/src/dmd/module.h dmd-0.142/dmd/src/dmd/module.h --- dmd-0.141/dmd/src/dmd/module.h 2005-11-29 14:13:00.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/module.h 2005-12-22 20:18:44.000000000 +0100 @@ -51,9 +51,7 @@ ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration File *srcfile; // input source file File *objfile; // output .obj file -#ifdef _DH File *hdrfile; // 'header' file -#endif File *symfile; // output symbol file File *docfile; // output documentation file unsigned errors; // if any errors in file @@ -88,15 +86,12 @@ Macro *macrotable; // document comment macros -#ifdef _DH Module(char *arg, Identifier *ident, int doDocComment, int doHdrGen); -#else - Module(char *arg, Identifier *ident, int doDocComment); -#endif ~Module(); static Module *load(Loc loc, Array *packages, Identifier *ident); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); char *kind(); void setDocfile(); // set docfile member void read(Loc loc); // read file @@ -105,11 +100,9 @@ void semantic2(); // pass 2 semantic analysis void semantic3(); // pass 3 semantic analysis void inlineScan(); // scan for functions to inline -#ifdef _DH - OutBuffer hdrbufr; // Header file contents void setHdrfile(); // set hdrfile member - void genhdrbufr(); // generate header file contents - void genhdrfile(); // format and write buffer to disk +#ifdef _DH + void genhdrfile(); // generate D import file #endif void genobjfile(); void gensymfile(); diff -uNr dmd-0.141/dmd/src/dmd/mtype.c dmd-0.142/dmd/src/dmd/mtype.c --- dmd-0.141/dmd/src/dmd/mtype.c 2005-12-04 13:26:52.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/mtype.c 2005-12-20 17:37:22.000000000 +0100 @@ -47,6 +47,7 @@ #include "enum.h" #include "import.h" #include "aggregate.h" +#include "hdrgen.h" FuncDeclaration *hasThis(Scope *sc); @@ -318,21 +319,22 @@ char *Type::toChars() { OutBuffer *buf; + HdrGenState hgs; buf = new OutBuffer(); - toCBuffer2(buf, NULL); + toCBuffer2(buf, NULL, &hgs); return buf->toChars(); } -void Type::toCBuffer(OutBuffer *buf, Identifier *ident) +void Type::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { OutBuffer tbuf; - toCBuffer2(&tbuf, ident); + toCBuffer2(&tbuf, ident, hgs); buf->write(&tbuf); } -void Type::toCBuffer2(OutBuffer *buf, Identifier *ident) +void Type::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { buf->prependstring(toChars()); if (ident) @@ -523,6 +525,8 @@ else if (ident == Id::mangleof) { assert(deco); e = new StringExp(loc, deco, strlen(deco), 'c'); + Scope sc; + e = e->semantic(&sc); } else { @@ -794,7 +798,7 @@ return dstring; } -void TypeBasic::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeBasic::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { buf->prependstring(cstring); if (ident) @@ -1110,11 +1114,16 @@ complex_t cvalue; #if __DMC__ + //((real_t *)&cvalue)[0] = fvalue; + //((real_t *)&cvalue)[1] = fvalue; cvalue = fvalue + fvalue * I; #else cvalue.re = fvalue; cvalue.im = fvalue; #endif + //for (int i = 0; i < 20; i++) + // printf("%02x ", ((unsigned char *)&cvalue)[i]); + //printf("\n"); e = new ComplexExp(0, cvalue, this); } return e; @@ -1416,18 +1425,18 @@ return e; } -void TypeArray::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeArray::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { #if 1 OutBuffer buf2; - toPrettyBracket(&buf2); + toPrettyBracket(&buf2, hgs); buf->prependstring(buf2.toChars()); if (ident) { buf->writeByte(' '); buf->writestring(ident->toChars()); } - next->toCBuffer2(buf, NULL); + next->toCBuffer2(buf, NULL, hgs); #elif 1 // The D way Type *t; @@ -1438,14 +1447,14 @@ ta = dynamic_cast(t); if (!ta) break; - ta->toPrettyBracket(&buf2); + ta->toPrettyBracket(&buf2, hgs); } buf->prependstring(buf2.toChars()); if (ident) { buf2.writestring(ident->toChars()); } - t->toCBuffer2(buf, NULL); + t->toCBuffer2(buf, NULL, hgs); #else // The C way if (buf->offset) @@ -1464,7 +1473,7 @@ buf->writeByte(']'); t = t->next; } while (t->ty == Tsarray); - t->toCBuffer2(buf, NULL); + t->toCBuffer2(buf, NULL, hgs); #endif } @@ -1591,7 +1600,7 @@ next->toTypeInfoBuffer(buf); } -void TypeSArray::toPrettyBracket(OutBuffer *buf) +void TypeSArray::toPrettyBracket(OutBuffer *buf, HdrGenState *hgs) { buf->printf("[%s]", dim->toChars()); } @@ -1724,7 +1733,7 @@ next->toTypeInfoBuffer(buf); } -void TypeDArray::toPrettyBracket(OutBuffer *buf) +void TypeDArray::toPrettyBracket(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("[]"); } @@ -1981,12 +1990,12 @@ next->toDecoBuffer(buf); } -void TypeAArray::toPrettyBracket(OutBuffer *buf) +void TypeAArray::toPrettyBracket(OutBuffer *buf, HdrGenState *hgs) { buf->writeByte('['); { OutBuffer ibuf; - index->toCBuffer2(&ibuf, NULL); + index->toCBuffer2(&ibuf, NULL, hgs); buf->write(&ibuf); } buf->writeByte(']'); @@ -2041,7 +2050,7 @@ return PTRSIZE; } -void TypePointer::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypePointer::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { //printf("TypePointer::toCBuffer2() next = %d\n", next->ty); buf->prependstring("*"); @@ -2050,7 +2059,7 @@ buf->writeByte(' '); buf->writestring(ident->toChars()); } - next->toCBuffer2(buf, NULL); + next->toCBuffer2(buf, NULL, hgs); } int TypePointer::implicitConvTo(Type *to) @@ -2130,14 +2139,14 @@ return PTRSIZE; } -void TypeReference::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeReference::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { buf->prependstring("&"); if (ident) { buf->writestring(ident->toChars()); } - next->toCBuffer2(buf, NULL); + next->toCBuffer2(buf, NULL, hgs); } Expression *TypeReference::dotExp(Scope *sc, Expression *e, Identifier *ident) @@ -2172,6 +2181,8 @@ TypeFunction::TypeFunction(Array *arguments, Type *treturn, int varargs, enum LINK linkage) : Type(Tfunction, treturn) { +if (!treturn) *(char*)0=0; + assert(treturn); this->arguments = arguments; this->varargs = varargs; this->linkage = linkage; @@ -2179,6 +2190,7 @@ Type *TypeFunction::syntaxCopy() { + assert(next); Type *treturn = next->syntaxCopy(); Array *args = Argument::arraySyntaxCopy(arguments); Type *t = new TypeFunction(args, treturn, varargs, linkage); @@ -2296,7 +2308,7 @@ next->toDecoBuffer(buf); } -void TypeFunction::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeFunction::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { char *p; @@ -2313,25 +2325,26 @@ if (buf->offset) { - if (p) + if (!hgs->hdrgen && p) buf->prependstring(p); buf->bracket('(', ')'); assert(!ident); } else { - if (p) + if (!hgs->hdrgen && p) buf->writestring(p); if (ident) { buf->writeByte(' '); - buf->writestring(ident->toChars()); + buf->writestring(ident->toHChars2()); } } - argsToCBuffer(buf); - next->toCBuffer2(buf, NULL); + argsToCBuffer(buf, hgs); + if (!ident || ident->toHChars2() == ident->toChars()) + next->toCBuffer2(buf, NULL, hgs); } -void TypeFunction::argsToCBuffer(OutBuffer *buf) +void TypeFunction::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writeByte('('); if (arguments) @@ -2349,11 +2362,11 @@ else if (arg->inout == InOut) buf->writestring("inout "); argbuf.reset(); - arg->type->toCBuffer2(&argbuf, arg->ident); + arg->type->toCBuffer2(&argbuf, arg->ident, hgs); if (arg->defaultArg) { argbuf.writestring(" = "); - arg->defaultArg->toCBuffer(&argbuf); + arg->defaultArg->toCBuffer(&argbuf, hgs); } buf->write(&argbuf); } @@ -2556,13 +2569,13 @@ return PTRSIZE * 2; } -void TypeDelegate::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeDelegate::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { #if 1 OutBuffer args; TypeFunction *tf = (TypeFunction *)next; - tf->argsToCBuffer(&args); + tf->argsToCBuffer(&args, hgs); buf->prependstring(args.toChars()); buf->prependstring(" delegate"); if (ident) @@ -2570,9 +2583,9 @@ buf->writeByte(' '); buf->writestring(ident->toChars()); } - next->next->toCBuffer2(buf, NULL); + next->next->toCBuffer2(buf, NULL, hgs); #else - next->toCBuffer2(buf, Id::delegate); + next->toCBuffer2(buf, Id::delegate, hgs); if (ident) { buf->writestring(ident->toChars()); @@ -2634,7 +2647,7 @@ idents.push(ident); } -void TypeQualified::toCBuffer2Helper(OutBuffer *buf, Identifier *ident) +void TypeQualified::toCBuffer2Helper(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { int i; @@ -2646,7 +2659,7 @@ if (id->dyncast() != DYNCAST_IDENTIFIER) { TemplateInstance *ti = (TemplateInstance *)id; - ti->toCBuffer(buf); + ti->toCBuffer(buf, hgs); } else buf->writestring(id->toChars()); @@ -2755,6 +2768,7 @@ for (; i < idents.dim; i++) { id = (Identifier *)idents.data[i]; + //printf("e: '%s', id: '%s', type = %p\n", e->toChars(), id->toChars(), e->type); e = e->type->dotExp(sc, e, id); } *pe = e; @@ -2872,12 +2886,12 @@ buf->printf("%c%s", mangleChar[ty], name); } -void TypeIdentifier::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeIdentifier::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { OutBuffer tmp; tmp.writestring(this->ident->toChars()); - toCBuffer2Helper(&tmp, NULL); + toCBuffer2Helper(&tmp, NULL, hgs); buf->prependstring(tmp.toChars()); if (ident) { buf->writeByte(' '); @@ -3013,12 +3027,12 @@ } -void TypeInstance::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeInstance::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { OutBuffer tmp; - tempinst->toCBuffer(&tmp); - toCBuffer2Helper(&tmp, NULL); + tempinst->toCBuffer(&tmp, hgs); + toCBuffer2Helper(&tmp, NULL, hgs); buf->prependstring(tmp.toChars()); if (ident) { buf->writeByte(' '); @@ -3097,14 +3111,14 @@ return t->toDsymbol(sc); } -void TypeTypeof::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeTypeof::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { OutBuffer tmp; tmp.writestring("typeof("); - exp->toCBuffer(&tmp); + exp->toCBuffer(&tmp, hgs); tmp.writeByte(')'); - toCBuffer2Helper(&tmp, NULL); + toCBuffer2Helper(&tmp, NULL, hgs); buf->prependstring(tmp.toChars()); if (ident) { buf->writeByte(' '); @@ -3260,7 +3274,7 @@ toBasetype()->toTypeInfoBuffer(buf); } -void TypeEnum::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeEnum::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { buf->prependstring(sym->toChars()); if (ident) @@ -3417,7 +3431,7 @@ sym->basetype->toTypeInfoBuffer(buf); } -void TypeTypedef::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeTypedef::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { //printf("TypeTypedef::toCBuffer2() '%s'\n", sym->toChars()); buf->prependstring(sym->toChars()); @@ -3611,14 +3625,12 @@ } -void TypeStruct::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeStruct::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { buf->prependbyte(' '); buf->prependstring(sym->toChars()); if (ident) - { buf->writeByte(' '); buf->writestring(ident->toChars()); - } } Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident) @@ -3820,7 +3832,7 @@ buf->printf("%c%s", mangleChar[ty], name); } -void TypeClass::toCBuffer2(OutBuffer *buf, Identifier *ident) +void TypeClass::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) { buf->prependstring(sym->toChars()); if (ident) @@ -4123,6 +4135,7 @@ if (args) { int i; OutBuffer argbuf; + HdrGenState hgs; for (i = 0; i < args->dim; i++) { Argument *arg; @@ -4131,7 +4144,7 @@ buf->writeByte(','); arg = (Argument *)args->data[i]; argbuf.reset(); - arg->type->toCBuffer2(&argbuf, NULL); + arg->type->toCBuffer2(&argbuf, NULL, &hgs); buf->write(&argbuf); } if (varargs) diff -uNr dmd-0.141/dmd/src/dmd/mtype.h dmd-0.142/dmd/src/dmd/mtype.h --- dmd-0.141/dmd/src/dmd/mtype.h 2005-12-04 13:25:40.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/mtype.h 2005-12-26 15:24:44.000000000 +0100 @@ -33,9 +33,7 @@ enum LINK; struct TypeBasic; -#ifdef _DH struct HdrGenState; -#endif // Back end typedef struct TYPE type; @@ -189,12 +187,8 @@ virtual void toDecoBuffer(OutBuffer *buf); virtual void toTypeInfoBuffer(OutBuffer *buf); Type *merge(); - void toCBuffer(OutBuffer *buf, Identifier *ident); - virtual void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); - virtual void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); + virtual void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); virtual int isbit(); virtual int isintegral(); virtual int isfloating(); // real, imaginary, or complex @@ -254,10 +248,7 @@ Expression *getProperty(Loc loc, Identifier *ident); Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); char *toChars(); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); int isintegral(); int isbit(); int isfloating(); @@ -278,11 +269,8 @@ struct TypeArray : Type { TypeArray(TY ty, Type *next); - virtual void toPrettyBracket(OutBuffer *buf) = 0; - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + virtual void toPrettyBracket(OutBuffer *buf, HdrGenState *hgs) = 0; + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); }; @@ -298,7 +286,7 @@ Type *semantic(Loc loc, Scope *sc); void toDecoBuffer(OutBuffer *buf); void toTypeInfoBuffer(OutBuffer *buf); - void toPrettyBracket(OutBuffer *buf); + void toPrettyBracket(OutBuffer *buf, HdrGenState *hgs); Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); int isString(); unsigned memalign(unsigned salign); @@ -322,7 +310,7 @@ Type *semantic(Loc loc, Scope *sc); void toDecoBuffer(OutBuffer *buf); void toTypeInfoBuffer(OutBuffer *buf); - void toPrettyBracket(OutBuffer *buf); + void toPrettyBracket(OutBuffer *buf, HdrGenState *hgs); Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); int isString(); int checkBoolean(); @@ -344,7 +332,7 @@ d_uns64 size(Loc loc); Type *semantic(Loc loc, Scope *sc); void toDecoBuffer(OutBuffer *buf); - void toPrettyBracket(OutBuffer *buf); + void toPrettyBracket(OutBuffer *buf, HdrGenState *hgs); Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); Expression *defaultInit(); MATCH deduceType(Type *tparam, Array *parameters, Array *atypes); @@ -363,10 +351,7 @@ Type *syntaxCopy(); Type *semantic(Loc loc, Scope *sc); d_uns64 size(Loc loc); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); int implicitConvTo(Type *to); int isscalar(); Expression *defaultInit(); @@ -381,10 +366,7 @@ TypeReference(Type *t); Type *syntaxCopy(); d_uns64 size(Loc loc); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); Expression *defaultInit(); int isZeroInit(); @@ -407,13 +389,8 @@ Type *syntaxCopy(); Type *semantic(Loc loc, Scope *sc); void toDecoBuffer(OutBuffer *buf); - void toCBuffer2(OutBuffer *buf, Identifier *ident); - void argsToCBuffer(OutBuffer *buf); -#ifdef _DH - Type *hdrSyntaxCopy(); - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); - void argsToHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); + void argsToCBuffer(OutBuffer *buf, HdrGenState *hgs); MATCH deduceType(Type *tparam, Array *parameters, Array *atypes); TypeInfoDeclaration *getTypeInfoDeclaration(); @@ -430,10 +407,7 @@ Type *syntaxCopy(); Type *semantic(Loc loc, Scope *sc); d_uns64 size(Loc loc); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); Expression *defaultInit(); int isZeroInit(); int checkBoolean(); @@ -450,10 +424,7 @@ TypeQualified(TY ty, Loc loc); void syntaxCopyHelper(TypeQualified *t); void addIdent(Identifier *ident); - void toCBuffer2Helper(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2Helper(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2Helper(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); d_uns64 size(Loc loc); void resolveHelper(Loc loc, Scope *sc, Dsymbol *s, Dsymbol *scopesym, Expression **pe, Type **pt, Dsymbol **ps); @@ -467,10 +438,7 @@ Type *syntaxCopy(); //char *toChars(); void toDecoBuffer(OutBuffer *buf); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps); Dsymbol *toDsymbol(Scope *sc); Type *semantic(Loc loc, Scope *sc); @@ -487,10 +455,7 @@ Type *syntaxCopy(); //char *toChars(); //void toDecoBuffer(OutBuffer *buf); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps); Type *semantic(Loc loc, Scope *sc); MATCH deduceType(Type *tparam, Array *parameters, Array *atypes); @@ -503,10 +468,7 @@ TypeTypeof(Loc loc, Expression *exp); Type *syntaxCopy(); Dsymbol *toDsymbol(Scope *sc); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); Type *semantic(Loc loc, Scope *sc); d_uns64 size(Loc loc); }; @@ -524,10 +486,7 @@ Dsymbol *toDsymbol(Scope *sc); void toDecoBuffer(OutBuffer *buf); void toTypeInfoBuffer(OutBuffer *buf); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); unsigned memalign(unsigned salign); Expression *defaultInit(); @@ -551,10 +510,7 @@ Dsymbol *toDsymbol(Scope *sc); void toDecoBuffer(OutBuffer *buf); void toTypeInfoBuffer(OutBuffer *buf); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); Expression *getProperty(Loc loc, Identifier *ident); int isintegral(); @@ -584,10 +540,7 @@ Dsymbol *toDsymbol(Scope *sc); void toDecoBuffer(OutBuffer *buf); void toTypeInfoBuffer(OutBuffer *buf); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); int isbit(); int isintegral(); @@ -621,10 +574,7 @@ Type *semantic(Loc loc, Scope *sc); Dsymbol *toDsymbol(Scope *sc); void toDecoBuffer(OutBuffer *buf); - void toCBuffer2(OutBuffer *buf, Identifier *ident); -#ifdef _DH - void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); -#endif + void toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); ClassDeclaration *isClassHandle(); int isBaseOf(Type *t); diff -uNr dmd-0.141/dmd/src/dmd/parse.c dmd-0.142/dmd/src/dmd/parse.c --- dmd-0.141/dmd/src/dmd/parse.c 2005-12-04 11:59:18.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/parse.c 2005-12-28 01:55:10.000000000 +0100 @@ -3960,15 +3960,6 @@ else error("identifier expected following '.', not '%s'", token.toChars()); break; -#if 0 - case TOKarrow: - nextToken(); - if (token.value == TOKidentifier) - e = new ArrowExp(loc, e, token.ident); - else - error("identifier expected following '->', not '%s'", token.toChars()); - break; -#endif case TOKplusplus: e = new PostIncExp(loc, e); diff -uNr dmd-0.141/dmd/src/dmd/statement.c dmd-0.142/dmd/src/dmd/statement.c --- dmd-0.141/dmd/src/dmd/statement.c 2005-12-04 11:50:14.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/statement.c 2005-12-28 01:25:00.000000000 +0100 @@ -23,7 +23,7 @@ #include "declaration.h" #include "aggregate.h" #include "id.h" - +#include "hdrgen.h" /******************************** Statement ***************************/ @@ -51,13 +51,14 @@ char *Statement::toChars() { OutBuffer *buf; + HdrGenState hgs; buf = new OutBuffer(); - toCBuffer(buf); + toCBuffer(buf, &hgs); return buf->toChars(); } -void Statement::toCBuffer(OutBuffer *buf) +void Statement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->printf("Statement::toCBuffer()"); buf->writenl(); @@ -174,12 +175,13 @@ return es; } -void ExpStatement::toCBuffer(OutBuffer *buf) +void ExpStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { if (exp) - exp->toCBuffer(buf); + exp->toCBuffer(buf, hgs); buf->writeByte(';'); - buf->writenl(); + if (!hgs->FLinit.init) + buf->writenl(); } Statement *ExpStatement::semantic(Scope *sc) @@ -244,10 +246,9 @@ return NULL; } -void DeclarationStatement::toCBuffer(OutBuffer *buf) +void DeclarationStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - buf->printf("DeclarationStatement::toCBuffer()"); - buf->writenl(); + exp->toCBuffer(buf, hgs); } @@ -365,7 +366,7 @@ return rs; } -void CompoundStatement::toCBuffer(OutBuffer *buf) +void CompoundStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { int i; for (i = 0; i < statements->dim; i++) @@ -373,7 +374,7 @@ s = (Statement *) statements->data[i]; if (s) - s->toCBuffer(buf); + s->toCBuffer(buf, hgs); } } @@ -467,13 +468,13 @@ return statement ? statement->fallOffEnd() : TRUE; } -void ScopeStatement::toCBuffer(OutBuffer *buf) +void ScopeStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writeByte('{'); buf->writenl(); if (statement) - statement->toCBuffer(buf); + statement->toCBuffer(buf, hgs); buf->writeByte('}'); buf->writenl(); @@ -529,6 +530,15 @@ return TRUE; } +void WhileStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("while ("); + condition->toCBuffer(buf, hgs); + buf->writebyte(')'); + buf->writenl(); + body->toCBuffer(buf, hgs); +} + /******************************** DoStatement ***************************/ DoStatement::DoStatement(Loc loc, Statement *b, Expression *c) @@ -577,6 +587,16 @@ return TRUE; } +void DoStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("do"); + buf->writenl(); + body->toCBuffer(buf, hgs); + buf->writestring("while ("); + condition->toCBuffer(buf, hgs); + buf->writebyte(')'); +} + /******************************** ForStatement ***************************/ ForStatement::ForStatement(Loc loc, Statement *init, Expression *condition, Expression *increment, Statement *body) @@ -652,6 +672,39 @@ return TRUE; } +void ForStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("for ("); + if (init) + { + hgs->FLinit.init++; + hgs->FLinit.decl = 0; + init->toCBuffer(buf, hgs); + if (hgs->FLinit.decl > 0) + buf->writebyte(';'); + hgs->FLinit.decl = 0; + hgs->FLinit.init--; + } + else + buf->writebyte(';'); + if (condition) + { buf->writebyte(' '); + condition->toCBuffer(buf, hgs); + } + buf->writebyte(';'); + if (increment) + { buf->writebyte(' '); + increment->toCBuffer(buf, hgs); + } + buf->writebyte(')'); + buf->writenl(); + buf->writebyte('{'); + buf->writenl(); + body->toCBuffer(buf, hgs); + buf->writebyte('}'); + buf->writenl(); +} + /******************************** ForeachStatement ***************************/ ForeachStatement::ForeachStatement(Loc loc, Array *arguments, @@ -1000,6 +1053,31 @@ return TRUE; } +void ForeachStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("foreach ("); + int i; + for (int i = 0; i < arguments->dim; i++) + { + Argument *a = (Argument *)arguments->data[i]; + if (i) + buf->writestring(", "); + if (a->inout == InOut) + buf->writestring("inout "); + a->type->toCBuffer(buf, a->ident, hgs); + } + buf->writestring("; "); + aggr->toCBuffer(buf, hgs); + buf->writebyte(')'); + buf->writenl(); + buf->writebyte('{'); + buf->writenl(); + if (body) + body->toCBuffer(buf, hgs); + buf->writebyte('}'); + buf->writenl(); +} + /******************************** IfStatement ***************************/ IfStatement::IfStatement(Loc loc, Expression *condition, Statement *ifbody, Statement *elsebody) @@ -1063,10 +1141,18 @@ } -void IfStatement::toCBuffer(OutBuffer *buf) +void IfStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - buf->printf("IfStatement::toCBuffer()"); + buf->writestring("if ("); + condition->toCBuffer(buf, hgs); + buf->writebyte(')'); buf->writenl(); + ifbody->toCBuffer(buf, hgs); + if (elsebody) + { buf->writestring("else"); + buf->writenl(); + elsebody->toCBuffer(buf, hgs); + } } /******************************** ConditionalStatement ***************************/ @@ -1114,11 +1200,18 @@ return (ifbody && ifbody->usesEH()) || (elsebody && elsebody->usesEH()); } -void ConditionalStatement::toCBuffer(OutBuffer *buf) +void ConditionalStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - condition->toCBuffer(buf); + condition->toCBuffer(buf, hgs); buf->writenl(); - buf->printf("ConditionalStatement::toCBuffer()"); + if (ifbody) + ifbody->toCBuffer(buf, hgs); + if (elsebody) + { + buf->writestring("else"); + buf->writenl(); + elsebody->toCBuffer(buf, hgs); + } buf->writenl(); } @@ -1201,7 +1294,7 @@ return TRUE; } -void PragmaStatement::toCBuffer(OutBuffer *buf) +void PragmaStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->printf("PragmaStatement::toCBuffer()"); buf->writenl(); @@ -1228,9 +1321,9 @@ return NULL; } -void StaticAssertStatement::toCBuffer(OutBuffer *buf) +void StaticAssertStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - sa->toCBuffer(buf); + sa->toCBuffer(buf, hgs); } @@ -1360,6 +1453,28 @@ return TRUE; } +void SwitchStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("switch ("); + condition->toCBuffer(buf, hgs); + buf->writebyte(')'); + buf->writenl(); + if (body) + { + if (!body->isScopeStatement()) + { buf->writebyte('{'); + buf->writenl(); + body->toCBuffer(buf, hgs); + buf->writebyte('}'); + buf->writenl(); + } + else + { + body->toCBuffer(buf, hgs); + } + } +} + /******************************** CaseStatement ***************************/ CaseStatement::CaseStatement(Loc loc, Expression *exp, Statement *s) @@ -1445,6 +1560,15 @@ return TRUE; } +void CaseStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("case "); + exp->toCBuffer(buf, hgs); + buf->writebyte(':'); + buf->writenl(); + statement->toCBuffer(buf, hgs); +} + /******************************** DefaultStatement ***************************/ DefaultStatement::DefaultStatement(Loc loc, Statement *s) @@ -1490,6 +1614,12 @@ return TRUE; } +void DefaultStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("default:\n"); + statement->toCBuffer(buf, hgs); +} + /******************************** GotoDefaultStatement ***************************/ GotoDefaultStatement::GotoDefaultStatement(Loc loc) @@ -1517,6 +1647,11 @@ return FALSE; } +void GotoDefaultStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("goto default;\n"); +} + /******************************** GotoCaseStatement ***************************/ GotoCaseStatement::GotoCaseStatement(Loc loc, Expression *exp) @@ -1557,6 +1692,17 @@ return FALSE; } +void GotoCaseStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("goto case"); + if (exp) + { buf->writebyte(' '); + exp->toCBuffer(buf, hgs); + } + buf->writebyte(';'); + buf->writenl(); +} + /******************************** SwitchErrorStatement ***************************/ SwitchErrorStatement::SwitchErrorStatement(Loc loc) @@ -1569,6 +1715,12 @@ return FALSE; } +void SwitchErrorStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("SwitchErrorStatement::toCBuffer()"); + buf->writenl(); +} + /******************************** ReturnStatement ***************************/ ReturnStatement::ReturnStatement(Loc loc, Expression *exp) @@ -1744,11 +1896,11 @@ return FALSE; } -void ReturnStatement::toCBuffer(OutBuffer *buf) +void ReturnStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->printf("return "); if (exp) - exp->toCBuffer(buf); + exp->toCBuffer(buf, hgs); buf->writeByte(';'); buf->writenl(); } @@ -1830,6 +1982,17 @@ return FALSE; } +void BreakStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("break"); + if (ident) + { buf->writebyte(' '); + buf->writestring(ident->toChars()); + } + buf->writebyte(';'); + buf->writenl(); +} + /******************************** ContinueStatement ***************************/ ContinueStatement::ContinueStatement(Loc loc, Identifier *ident) @@ -1907,6 +2070,17 @@ return FALSE; } +void ContinueStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("continue"); + if (ident) + { buf->writebyte(' '); + buf->writestring(ident->toChars()); + } + buf->writebyte(';'); + buf->writenl(); +} + /******************************** SynchronizedStatement ***************************/ SynchronizedStatement::SynchronizedStatement(Loc loc, Expression *exp, Statement *body) @@ -1974,6 +2148,21 @@ return body->fallOffEnd(); } +void SynchronizedStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("synchronized"); + if (exp) + { buf->writebyte('('); + exp->toCBuffer(buf, hgs); + buf->writebyte(')'); + } + if (body) + { + buf->writebyte(' '); + body->toCBuffer(buf, hgs); + } +} + /******************************** WithStatement ***************************/ WithStatement::WithStatement(Loc loc, Expression *exp, Statement *body) @@ -2038,13 +2227,12 @@ return this; } -void WithStatement::toCBuffer(OutBuffer *buf) +void WithStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("with ("); - exp->toCBuffer(buf); - buf->writestring(")\n{\n"); - body->toCBuffer(buf); - buf->writestring("\n}\n"); + exp->toCBuffer(buf, hgs); + buf->writestring(")\n"); + body->toCBuffer(buf, hgs); } int WithStatement::usesEH() @@ -2130,6 +2318,20 @@ return result; } +void TryCatchStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("try"); + buf->writenl(); + if (body) + body->toCBuffer(buf, hgs); + int i; + for (i = 0; i < catches->dim; i++) + { + Catch *c = (Catch *)catches->data[i]; + c->toCBuffer(buf, hgs); + } +} + /******************************** Catch ***************************/ Catch::Catch(Loc loc, Type *t, Identifier *id, Statement *handler) @@ -2187,6 +2389,22 @@ sc->pop(); } +void Catch::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("catch"); + if (type) + { buf->writebyte('('); + type->toCBuffer(buf, ident, hgs); + buf->writebyte(')'); + } + buf->writenl(); + buf->writebyte('{'); + buf->writenl(); + handler->toCBuffer(buf, hgs); + buf->writebyte('}'); + buf->writenl(); +} + /******************************** TryFinallyStatement ***************************/ TryFinallyStatement::TryFinallyStatement(Loc loc, Statement *body, Statement *finalbody) @@ -2215,12 +2433,12 @@ return this; } -void TryFinallyStatement::toCBuffer(OutBuffer *buf) +void TryFinallyStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->printf("try\n{\n"); - body->toCBuffer(buf); + body->toCBuffer(buf, hgs); buf->printf("}\nfinally\n{\n"); - finalbody->toCBuffer(buf); + finalbody->toCBuffer(buf, hgs); buf->writeByte('}'); buf->writenl(); } @@ -2280,10 +2498,10 @@ return FALSE; } -void ThrowStatement::toCBuffer(OutBuffer *buf) +void ThrowStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->printf("throw "); - exp->toCBuffer(buf); + exp->toCBuffer(buf, hgs); buf->writeByte(';'); buf->writenl(); } @@ -2331,6 +2549,17 @@ return statement->fallOffEnd(); } +void VolatileStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("volatile"); + if (statement) + { if (statement->isScopeStatement()) + buf->writenl(); + else + buf->writebyte(' '); + statement->toCBuffer(buf, hgs); + } +} /******************************** GotoStatement ***************************/ @@ -2381,6 +2610,14 @@ return FALSE; } +void GotoStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("goto "); + buf->writestring(ident->toChars()); + buf->writebyte(';'); + buf->writenl(); +} + /******************************** LabelStatement ***************************/ LabelStatement::LabelStatement(Loc loc, Identifier *ident, Statement *statement) @@ -2455,6 +2692,15 @@ return TRUE; } +void LabelStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring(ident->toChars()); + buf->writebyte(':'); + buf->writenl(); + if (statement) + statement->toCBuffer(buf, hgs); +} + /******************************** LabelDsymbol ***************************/ diff -uNr dmd-0.141/dmd/src/dmd/statement.h dmd-0.142/dmd/src/dmd/statement.h --- dmd-0.141/dmd/src/dmd/statement.h 2005-12-04 11:19:56.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/statement.h 2005-12-26 23:35:48.000000000 +0100 @@ -36,12 +36,11 @@ struct CompoundStatement; struct Argument; struct StaticAssert; -#ifdef _DH struct AsmStatement; struct GotoStatement; struct ScopeStatement; struct TryCatchStatement; -#endif +struct HdrGenState; // Back end struct IRState; @@ -61,16 +60,14 @@ char *toChars(); void error(const char *format, ...); - virtual void toCBuffer(OutBuffer *buf); -#ifdef _DH - virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); - virtual void toHBuffer2(OutBuffer *buf, HdrGenState *hgs) {} - virtual ScopeStatement *isScopeStatement() { return NULL; } + virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); virtual TryCatchStatement *isTryCatchStatement() { return NULL; } virtual GotoStatement *isGotoStatement() { return NULL; } virtual AsmStatement *isAsmStatement() { return NULL; } +#ifdef _DH int incontract; #endif + virtual ScopeStatement *isScopeStatement() { return NULL; } virtual Statement *semantic(Scope *sc); Statement *semanticScope(Scope *sc, Statement *sbreak, Statement *scontinue); virtual int hasBreak(); @@ -100,10 +97,7 @@ ExpStatement(Loc loc, Expression *exp); Statement *syntaxCopy(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *semantic(Scope *sc); int fallOffEnd(); @@ -122,10 +116,7 @@ DeclarationStatement(Loc loc, Dsymbol *s); DeclarationStatement(Loc loc, Expression *exp); Statement *syntaxCopy(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *callAutoDtor(); DeclarationStatement *isDeclarationStatement() { return this; } @@ -138,10 +129,7 @@ CompoundStatement(Loc loc, Array *s); CompoundStatement(Loc loc, Statement *s1, Statement *s2); Statement *syntaxCopy(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *semantic(Scope *sc); int usesEH(); int fallOffEnd(); @@ -165,7 +153,7 @@ BlockStatement(Loc loc, Array *s); BlockStatement(Loc loc, Statement *s1, Statement *s2); Statement *syntaxCopy(); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *semantic(Scope *sc); void toIR(IRState *irs); @@ -178,12 +166,8 @@ ScopeStatement(Loc loc, Statement *s); Statement *syntaxCopy(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); - void toHBuffer2(OutBuffer *buf, HdrGenState *hgs); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); ScopeStatement *isScopeStatement() { return this; } -#endif Statement *semantic(Scope *sc); int fallOffEnd(); @@ -204,9 +188,7 @@ int hasContinue(); int usesEH(); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *inlineScan(InlineScanState *iss); @@ -225,9 +207,7 @@ int hasContinue(); int usesEH(); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *inlineScan(InlineScanState *iss); @@ -248,9 +228,7 @@ int hasContinue(); int usesEH(); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *inlineScan(InlineScanState *iss); @@ -276,9 +254,7 @@ int hasContinue(); int usesEH(); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *inlineScan(InlineScanState *iss); @@ -294,10 +270,7 @@ IfStatement(Loc loc, Expression *condition, Statement *ifbody, Statement *elsebody); Statement *syntaxCopy(); Statement *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); int usesEH(); int fallOffEnd(); @@ -319,10 +292,7 @@ Statement *semantic(Scope *sc); int usesEH(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct PragmaStatement : Statement @@ -337,10 +307,7 @@ int usesEH(); int fallOffEnd(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct StaticAssertStatement : Statement @@ -351,10 +318,7 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct SwitchStatement : Statement @@ -372,9 +336,7 @@ int hasBreak(); int usesEH(); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *inlineScan(InlineScanState *iss); @@ -395,9 +357,7 @@ int usesEH(); int fallOffEnd(); int comeFrom(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *inlineScan(InlineScanState *iss); @@ -414,9 +374,7 @@ int usesEH(); int fallOffEnd(); int comeFrom(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *inlineScan(InlineScanState *iss); @@ -431,9 +389,7 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toIR(IRState *irs); }; @@ -447,9 +403,7 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toIR(IRState *irs); }; @@ -458,9 +412,7 @@ { SwitchErrorStatement(Loc loc); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toIR(IRState *irs); }; @@ -471,10 +423,7 @@ ReturnStatement(Loc loc, Expression *exp); Statement *syntaxCopy(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *semantic(Scope *sc); int fallOffEnd(); @@ -495,9 +444,7 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toIR(IRState *irs); }; @@ -510,9 +457,7 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toIR(IRState *irs); }; @@ -529,9 +474,7 @@ int hasContinue(); int usesEH(); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *inlineScan(InlineScanState *iss); @@ -550,10 +493,7 @@ WithStatement(Loc loc, Expression *exp, Statement *body); Statement *syntaxCopy(); Statement *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); int usesEH(); int fallOffEnd(); @@ -577,10 +517,8 @@ Statement *inlineScan(InlineScanState *iss); void toIR(IRState *irs); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); TryCatchStatement *isTryCatchStatement() { return this; } -#endif }; struct Catch : Object @@ -594,9 +532,7 @@ Catch(Loc loc, Type *t, Identifier *id, Statement *handler); Catch *syntaxCopy(); void semantic(Scope *sc); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; struct TryFinallyStatement : Statement @@ -606,10 +542,7 @@ TryFinallyStatement(Loc loc, Statement *body, Statement *finalbody); Statement *syntaxCopy(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *semantic(Scope *sc); int hasBreak(); int hasContinue(); @@ -628,10 +561,7 @@ ThrowStatement(Loc loc, Expression *exp); Statement *syntaxCopy(); Statement *semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); int fallOffEnd(); Statement *inlineScan(InlineScanState *iss); @@ -648,9 +578,7 @@ Statement *semantic(Scope *sc); Array *flatten(); int fallOffEnd(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *inlineScan(InlineScanState *iss); @@ -669,10 +597,8 @@ int fallOffEnd(); void toIR(IRState *irs); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); GotoStatement *isGotoStatement() { return this; } -#endif }; struct LabelStatement : Statement @@ -690,9 +616,7 @@ int usesEH(); int fallOffEnd(); int comeFrom(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Statement *inlineScan(InlineScanState *iss); @@ -721,11 +645,8 @@ Statement *semantic(Scope *sc); int comeFrom(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); virtual AsmStatement *isAsmStatement() { return this; } -#endif void toIR(IRState *irs); }; diff -uNr dmd-0.141/dmd/src/dmd/staticassert.c dmd-0.142/dmd/src/dmd/staticassert.c --- dmd-0.141/dmd/src/dmd/staticassert.c 2005-05-12 17:44:50.000000000 +0200 +++ dmd-0.142/dmd/src/dmd/staticassert.c 2005-12-11 23:47:04.000000000 +0100 @@ -64,11 +64,11 @@ return "static assert"; } -void StaticAssert::toCBuffer(OutBuffer *buf) +void StaticAssert::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring(kind()); buf->writeByte('('); - exp->toCBuffer(buf); + exp->toCBuffer(buf, hgs); buf->writestring(");"); buf->writenl(); } diff -uNr dmd-0.141/dmd/src/dmd/staticassert.h dmd-0.142/dmd/src/dmd/staticassert.h --- dmd-0.141/dmd/src/dmd/staticassert.h 2005-11-26 22:16:58.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/staticassert.h 2005-12-23 01:09:26.000000000 +0100 @@ -34,10 +34,7 @@ void inlineScan(); void toObjFile(); char *kind(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); }; #endif diff -uNr dmd-0.141/dmd/src/dmd/struct.c dmd-0.142/dmd/src/dmd/struct.c --- dmd-0.141/dmd/src/dmd/struct.c 2005-09-24 00:45:10.000000000 +0200 +++ dmd-0.142/dmd/src/dmd/struct.c 2005-12-23 01:11:40.000000000 +0100 @@ -402,10 +402,12 @@ } } -void StructDeclaration::toCBuffer(OutBuffer *buf) +void StructDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { int i; - buf->printf("%s %s", kind(), toChars()); + buf->printf("%s ", kind()); + if (!isAnonymous()) + buf->writestring(toChars()); if (!members) { buf->writeByte(';'); @@ -420,7 +422,7 @@ Dsymbol *s = (Dsymbol *)members->data[i]; buf->writestring(" "); - s->toCBuffer(buf); + s->toCBuffer(buf, hgs); } buf->writeByte('}'); buf->writenl(); diff -uNr dmd-0.141/dmd/src/dmd/template.c dmd-0.142/dmd/src/dmd/template.c --- dmd-0.141/dmd/src/dmd/template.c 2005-12-01 20:48:10.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/template.c 2005-12-28 01:55:26.000000000 +0100 @@ -28,6 +28,7 @@ #include "mars.h" #include "dsymbol.h" #include "identifier.h" +#include "hdrgen.h" #define LOG 0 @@ -412,10 +413,11 @@ return 0; } -void TemplateDeclaration::toCBuffer(OutBuffer *buf) +void TemplateDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { int i; + buf->writestring(kind()); buf->writeByte(' '); buf->writestring(ident->toChars()); @@ -425,21 +427,44 @@ TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; if (i) buf->writeByte(','); - tp->toCBuffer(buf); + tp->toCBuffer(buf, hgs); } buf->writeByte(')'); + + if (hgs->hdrgen) + { + hgs->tpltMember++; + buf->writenl(); + buf->writebyte('{'); + buf->writenl(); + for (i = 0; i < members->dim; i++) + { + Dsymbol *s = (Dsymbol *)members->data[i]; + s->toCBuffer(buf, hgs); + } + buf->writebyte('}'); + buf->writenl(); + hgs->tpltMember--; + } } char *TemplateDeclaration::toChars() -{ - OutBuffer buf; - char *s; +{ OutBuffer buf; + HdrGenState hgs; - toCBuffer(&buf); - s = buf.toChars(); - buf.data = NULL; - return s + strlen(kind()) + 1; // kludge to skip over 'template ' + memset(&hgs, 0, sizeof(hgs)); + buf.writestring(ident->toChars()); + buf.writeByte('('); + for (int i = 0; i < parameters->dim; i++) + { + TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; + if (i) + buf.writeByte(','); + tp->toCBuffer(&buf, &hgs); + } + buf.writeByte(')'); + return (char *)buf.extractData(); } /* ======================== Type ============================================ */ @@ -815,18 +840,18 @@ } -void TemplateTypeParameter::toCBuffer(OutBuffer *buf) +void TemplateTypeParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring(ident->toChars()); if (specType) { buf->writestring(" : "); - specType->toCBuffer(buf, NULL); + specType->toCBuffer(buf, NULL, hgs); } if (defaultType) { buf->writestring(" = "); - defaultType->toCBuffer(buf, NULL); + defaultType->toCBuffer(buf, NULL, hgs); } } @@ -986,19 +1011,19 @@ printf("\tArgument alias: %s\n", sa->toChars()); } -void TemplateAliasParameter::toCBuffer(OutBuffer *buf) +void TemplateAliasParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("alias "); buf->writestring(ident->toChars()); if (specAliasT) { buf->writestring(" : "); - specAliasT->toCBuffer(buf, NULL); + specAliasT->toCBuffer(buf, NULL, hgs); } if (defaultAlias) { buf->writestring(" = "); - defaultAlias->toCBuffer(buf, NULL); + defaultAlias->toCBuffer(buf, NULL, hgs); } } @@ -1178,18 +1203,18 @@ } -void TemplateValueParameter::toCBuffer(OutBuffer *buf) +void TemplateValueParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - valType->toCBuffer(buf, ident); + valType->toCBuffer(buf, ident, hgs); if (specValue) { buf->writestring(" : "); - specValue->toCBuffer(buf); + specValue->toCBuffer(buf, hgs); } if (defaultValue) { buf->writestring(" = "); - defaultValue->toCBuffer(buf); + defaultValue->toCBuffer(buf, hgs); } } @@ -1570,7 +1595,8 @@ ea = isExpression((Object *)tiargs->data[j]); assert(ea); ea = ea->semantic(sc); - ea = ea->constFold(); + ea = ea->optimize(WANTvalue); + //ea = ea->constFold(); tiargs->data[j] = ea; } //printf("1: tiargs->data[%d] = %p\n", j, tiargs->data[j]); @@ -1932,7 +1958,7 @@ } } -void TemplateInstance::toCBuffer(OutBuffer *buf) +void TemplateInstance::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { int i; @@ -1958,9 +1984,9 @@ Expression *e = isExpression(oarg); Dsymbol *s = isDsymbol(oarg); if (t) - t->toCBuffer(buf, NULL); + t->toCBuffer(buf, NULL, hgs); else if (e) - e->toCBuffer(buf); + e->toCBuffer(buf, hgs); else if (s) { char *p = s->ident ? s->ident->toChars() : s->toChars(); @@ -2016,13 +2042,13 @@ char *TemplateInstance::toChars() { OutBuffer buf; + HdrGenState hgs; char *s; - toCBuffer(&buf); + toCBuffer(&buf, &hgs); s = buf.toChars(); buf.data = NULL; return s; - //return s + 9; // kludge to skip over 'instance ' } /* ======================== TemplateMixin ================================ */ @@ -2356,25 +2382,49 @@ return Dsymbol::oneMember(); } -void TemplateMixin::toCBuffer(OutBuffer *buf) +void TemplateMixin::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { - //buf->writestring("mixin "); - if (tqual) - { tqual->toCBuffer(buf, NULL); - buf->writeByte('.'); - } - for (int i = 0; i + 1 < idents->dim; i++) - { Identifier *id = (Identifier *)idents->data[i]; + buf->writestring("mixin "); + int i; + for (i = 0; i < idents->dim; i++) + { Identifier *id = (Identifier *)idents->data[i]; + if (i) + buf->writeByte('.'); buf->writestring(id->toChars()); - buf->writeByte('.'); } - TemplateInstance::toCBuffer(buf); - if (ident) + buf->writestring("!("); + if (tiargs) { - buf->writeByte(' '); - buf->writestring(ident->toChars()); + for (i = 0; i < tiargs->dim; i++) + { if (i) + buf->writebyte(','); + Object *oarg = (Object *)tiargs->data[i]; + Type *t = isType(oarg); + Expression *e = isExpression(oarg); + Dsymbol *s = isDsymbol(oarg); + if (t) + t->toCBuffer(buf, NULL, hgs); + else if (e) + e->toCBuffer(buf, hgs); + else if (s) + { + char *p = s->ident ? s->ident->toChars() : s->toChars(); + buf->writestring(p); + } + else if (!oarg) + { + buf->writestring("NULL"); + } + else + { + assert(0); + } + } } + buf->writebyte(')'); + buf->writebyte(';'); + buf->writenl(); } diff -uNr dmd-0.141/dmd/src/dmd/template.h dmd-0.142/dmd/src/dmd/template.h --- dmd-0.141/dmd/src/dmd/template.h 2005-12-01 00:45:34.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/template.h 2005-12-26 23:13:22.000000000 +0100 @@ -28,10 +28,8 @@ struct Scope; struct Expression; struct AliasDeclaration; -enum MATCH; -#ifdef _DH struct HdrGenState; -#endif +enum MATCH; struct TemplateDeclaration : ScopeDsymbol { @@ -46,13 +44,9 @@ Dsymbol *syntaxCopy(Dsymbol *); void semantic(Scope *sc); int overloadInsert(Dsymbol *s); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); char *kind(); char *toChars(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); - char *toHChars(HdrGenState *hgs); -#endif void emitComment(Scope *sc); // void toDocBuffer(OutBuffer *buf); @@ -87,10 +81,7 @@ virtual TemplateParameter *syntaxCopy() = 0; virtual void semantic(Scope *) = 0; virtual void print(Object *oarg, Object *oded) = 0; - virtual void toCBuffer(OutBuffer *buf) = 0; -#ifdef _DH - virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs) = 0; -#endif + virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs) = 0; virtual Object *defaultArg(Scope *sc) = 0; /* If TemplateParameter's match as far as overloading goes. @@ -120,10 +111,7 @@ TemplateParameter *syntaxCopy(); void semantic(Scope *); void print(Object *oarg, Object *oded); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Object *defaultArg(Scope *sc); int overloadMatch(TemplateParameter *); MATCH matchArg(Scope *sc, Object *oarg, int i, Array *parameters, Array *dedtypes, Declaration **psparam); @@ -148,10 +136,7 @@ TemplateParameter *syntaxCopy(); void semantic(Scope *); void print(Object *oarg, Object *oded); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Object *defaultArg(Scope *sc); int overloadMatch(TemplateParameter *); MATCH matchArg(Scope *sc, Object *oarg, int i, Array *parameters, Array *dedtypes, Declaration **psparam); @@ -177,10 +162,7 @@ TemplateParameter *syntaxCopy(); void semantic(Scope *); void print(Object *oarg, Object *oded); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Object *defaultArg(Scope *sc); int overloadMatch(TemplateParameter *); MATCH matchArg(Scope *sc, Object *oarg, int i, Array *parameters, Array *dedtypes, Declaration **psparam); @@ -211,15 +193,11 @@ void semantic2(Scope *sc); void semantic3(Scope *sc); void inlineScan(); - void toCBuffer(OutBuffer *buf); + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); Dsymbol *toAlias(); // resolve real symbol char *kind(); char *toChars(); char *mangle(); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); - char *toHChars(HdrGenState *hgs); -#endif void toObjFile(); // compile to .obj file @@ -246,10 +224,7 @@ void inlineScan(); char *kind(); Dsymbol *oneMember(); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toObjFile(); // compile to .obj file diff -uNr dmd-0.141/dmd/src/dmd/version.c dmd-0.142/dmd/src/dmd/version.c --- dmd-0.141/dmd/src/dmd/version.c 2005-11-26 22:29:52.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/version.c 2005-12-11 23:24:32.000000000 +0100 @@ -81,7 +81,7 @@ //printf("DebugSymbol::semantic() %s\n", toChars()); } -void DebugSymbol::toCBuffer(OutBuffer *buf) +void DebugSymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("debug = "); if (ident) @@ -160,7 +160,7 @@ { } -void VersionSymbol::toCBuffer(OutBuffer *buf) +void VersionSymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("version = "); if (ident) diff -uNr dmd-0.141/dmd/src/dmd/version.h dmd-0.142/dmd/src/dmd/version.h --- dmd-0.141/dmd/src/dmd/version.h 2005-11-26 22:18:02.000000000 +0100 +++ dmd-0.142/dmd/src/dmd/version.h 2005-12-12 15:14:40.000000000 +0100 @@ -1,5 +1,5 @@ -// Copyright (c) 1999-2002 by Digital Mars +// Copyright (c) 1999-2005 by Digital Mars // All Rights Reserved // written by Walter Bright // www.digitalmars.com @@ -17,6 +17,7 @@ #include "dsymbol.h" struct OutBuffer; +struct HdrGenState; struct DebugSymbol : Dsymbol { @@ -28,10 +29,7 @@ void addMember(Scope *sc, ScopeDsymbol *s); void semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); char *kind(); }; @@ -45,10 +43,7 @@ void addMember(Scope *sc, ScopeDsymbol *s); void semantic(Scope *sc); - void toCBuffer(OutBuffer *buf); -#ifdef _DH - void toHBuffer(OutBuffer *buf, HdrGenState *hgs); -#endif + void toCBuffer(OutBuffer *buf, HdrGenState *hgs); char *kind(); }; diff -uNr dmd-0.141/dmd/src/phobos/internal/llmath.d dmd-0.142/dmd/src/phobos/internal/llmath.d --- dmd-0.141/dmd/src/phobos/internal/llmath.d 2005-12-04 20:50:20.000000000 +0100 +++ dmd-0.142/dmd/src/phobos/internal/llmath.d 2005-12-29 11:07:14.000000000 +0100 @@ -53,7 +53,7 @@ mov ECX,EDX ; mov EBX,EAX ; // [ECX,EBX] = [EDX,EAX] xor EAX,EAX ; - cwd ; // [EDX,EAX] = 0 + cdq ; // [EDX,EAX] = 0 even ; L4: cmp ESI,ECX ; // is [ECX,EBX] > [ESI,EDI]? ja L3 ; // yes diff -uNr dmd-0.141/dmd/src/phobos/std/asserterror.d dmd-0.142/dmd/src/phobos/std/asserterror.d --- dmd-0.141/dmd/src/phobos/std/asserterror.d 2005-12-04 20:50:18.000000000 +0100 +++ dmd-0.142/dmd/src/phobos/std/asserterror.d 2005-12-29 11:07:14.000000000 +0100 @@ -23,8 +23,6 @@ /* This code is careful to not use gc allocated memory, * as that may be the source of the problem. * Instead, stick with C functions. - * We'll never free the malloc'd memory, but that doesn't matter, - * as we're aborting anyway. */ len = 22 + filename.length + uint.sizeof * 3 + 1; @@ -42,6 +40,14 @@ super(buffer[0 .. count]); } } + + ~this() + { + if (msg.ptr) + { std.c.stdlib.free(msg.ptr); + msg = null; + } + } } diff -uNr dmd-0.141/dmd/src/phobos/std/cover.d dmd-0.142/dmd/src/phobos/std/cover.d --- dmd-0.141/dmd/src/phobos/std/cover.d 2005-12-04 20:50:18.000000000 +0100 +++ dmd-0.142/dmd/src/phobos/std/cover.d 2005-12-29 11:07:14.000000000 +0100 @@ -28,6 +28,8 @@ * $(LI the execution counters are 32 bits in size, and can overflow) * $(LI inline asm statements are not counted) * ) + * Macros: + * WIKI = StdCover */ module std.cover; @@ -171,7 +173,8 @@ } } - fwritefln(flst, "%s is %s%% covered", c.filename, (nyes * 100) / (nyes + nno)); + if (nyes + nno) // no divide by 0 bugs + fwritefln(flst, "%s is %s%% covered", c.filename, (nyes * 100) / (nyes + nno)); std.c.stdio.fclose(flst); } diff -uNr dmd-0.141/dmd/src/phobos/std/demangle.d dmd-0.142/dmd/src/phobos/std/demangle.d --- dmd-0.141/dmd/src/phobos/std/demangle.d 2005-12-04 20:50:18.000000000 +0100 +++ dmd-0.142/dmd/src/phobos/std/demangle.d 2005-12-29 11:07:14.000000000 +0100 @@ -1,5 +1,11 @@ /**** * Demangle D mangled names. + * Macros: + * WIKI = StdDemangle + */ + +/* Author: + * Walter Bright, Digital Mars, www.digitalmars.com */ module std.demangle; diff -uNr dmd-0.141/dmd/src/phobos/std/windows/charset.d dmd-0.142/dmd/src/phobos/std/windows/charset.d --- dmd-0.141/dmd/src/phobos/std/windows/charset.d 2005-12-04 20:50:20.000000000 +0100 +++ dmd-0.142/dmd/src/phobos/std/windows/charset.d 2005-12-29 11:07:14.000000000 +0100 @@ -2,6 +2,8 @@ /** * Support UTF-8 on Windows 95, 98 and ME systems. + * Macros: + * WIKI = StdWindowsCharset */ module std.windows.charset;