diff -uNr dmd-0.140/dmd/src/dmd/aggregate.h dmd-0.141/dmd/src/dmd/aggregate.h --- dmd-0.140/dmd/src/dmd/aggregate.h 2005-09-24 00:40:04.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/aggregate.h 2005-11-26 22:12: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 @@ -104,6 +104,9 @@ Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif char *mangle(); char *kind(); @@ -181,6 +184,9 @@ Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif int isBaseOf2(ClassDeclaration *cd); #define OFFSET_RUNTIME 0x76543210 diff -uNr dmd-0.140/dmd/src/dmd/attrib.h dmd-0.141/dmd/src/dmd/attrib.h --- dmd-0.140/dmd/src/dmd/attrib.h 2005-10-24 00:01:24.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/attrib.h 2005-11-26 22:22:32.000000000 +0100 @@ -22,6 +22,9 @@ struct Initializer; struct Module; struct Condition; +#ifdef _DH +struct HdrGenState; +#endif /**************************************************************/ @@ -43,6 +46,9 @@ void checkCtorConstInit(); void addLocalClass(Array *); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif AttribDeclaration *isAttribDeclaration() { return this; } void toObjFile(); // compile to .obj file @@ -57,6 +63,9 @@ Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; struct LinkDeclaration : AttribDeclaration @@ -68,6 +77,9 @@ void semantic(Scope *sc); void semantic3(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif char *toChars(); }; @@ -79,6 +91,9 @@ Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; struct AlignDeclaration : AttribDeclaration @@ -89,6 +104,9 @@ Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; struct AnonDeclaration : AttribDeclaration @@ -99,6 +117,9 @@ Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif char *kind(); }; @@ -110,6 +131,9 @@ Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif char *kind(); void toObjFile(); // compile to .obj file }; @@ -125,6 +149,9 @@ Array *include(Scope *sc, ScopeDsymbol *s); void addComment(unsigned char *comment); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; #endif /* DMD_ATTRIB_H */ diff -uNr dmd-0.140/dmd/src/dmd/cast.c dmd-0.141/dmd/src/dmd/cast.c --- dmd-0.140/dmd/src/dmd/cast.c 2005-11-24 01:04:34.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/cast.c 2005-12-04 13:28:54.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 diff -uNr dmd-0.140/dmd/src/dmd/class.c dmd-0.141/dmd/src/dmd/class.c --- dmd-0.140/dmd/src/dmd/class.c 2005-09-24 00:45:10.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/class.c 2005-12-04 11:31:48.000000000 +0100 @@ -57,7 +57,7 @@ vtblsym = NULL; vclassinfo = NULL; - if (id == Id::__sizeof || id == Id::alignof) + if (id == Id::__sizeof || id == Id::alignof || id == Id::mangleof) error("illegal class name"); // BUG: What if this is the wrong ClassInfo, i.e. it is nested? diff -uNr dmd-0.140/dmd/src/dmd/cond.c dmd-0.141/dmd/src/dmd/cond.c --- dmd-0.140/dmd/src/dmd/cond.c 2005-10-05 13:00:16.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/cond.c 2005-11-26 22:07:56.000000000 +0100 @@ -19,6 +19,10 @@ #include "module.h" #include "template.h" #include "lexer.h" +#ifdef _DH +#include "mtype.h" +#include "scope.h" +#endif int findCondition(Array *ids, Identifier *ident) { diff -uNr dmd-0.140/dmd/src/dmd/cond.h dmd-0.141/dmd/src/dmd/cond.h --- dmd-0.140/dmd/src/dmd/cond.h 2005-10-03 01:30:40.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/cond.h 2005-12-02 00:02:50.000000000 +0100 @@ -16,7 +16,13 @@ struct Module; struct Scope; struct ScopeDsymbol; +#ifdef _DH +#include "lexer.h" // dmdhg +#endif enum TOK; +#ifdef _DH +struct HdrGenState; +#endif int findCondition(Array *ids, Identifier *ident); @@ -32,6 +38,9 @@ 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 }; struct DVCondition : Condition @@ -78,6 +87,9 @@ Condition *syntaxCopy(); int include(Scope *sc, ScopeDsymbol *s); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; struct IftypeCondition : Condition @@ -93,6 +105,9 @@ Condition *syntaxCopy(); int include(Scope *sc, ScopeDsymbol *s); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; diff -uNr dmd-0.140/dmd/src/dmd/declaration.c dmd-0.141/dmd/src/dmd/declaration.c --- dmd-0.140/dmd/src/dmd/declaration.c 2005-11-24 01:27:52.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/declaration.c 2005-12-01 11:26:36.000000000 +0100 @@ -85,6 +85,10 @@ this->type = new TypeTypedef(this); this->basetype = basetype->toBasetype(); this->init = init; +#ifdef _DH + this->htype = NULL; + this->hbasetype = NULL; +#endif this->sem = 0; this->loc = loc; } @@ -100,6 +104,25 @@ assert(!s); TypedefDeclaration *st; st = new TypedefDeclaration(loc, ident, basetype, init); +#ifdef _DH + // Syntax copy for header file + if (!htype) // Don't overwrite original + { if (type) // Make copy for both old and new instances + { htype = type->syntaxCopy(); + st->htype = type->syntaxCopy(); + } + } + else // Make copy of original for new instance + st->htype = htype->syntaxCopy(); + if (!hbasetype) + { if (basetype) + { hbasetype = basetype->syntaxCopy(); + st->hbasetype = basetype->syntaxCopy(); + } + } + else + st->hbasetype = hbasetype->syntaxCopy(); +#endif return st; } @@ -166,6 +189,10 @@ this->loc = loc; this->type = type; this->aliassym = NULL; +#ifdef _DH + this->htype = NULL; + this->haliassym = NULL; +#endif this->overnext = NULL; this->inSemantic = 0; assert(type); @@ -179,6 +206,10 @@ this->loc = loc; this->type = NULL; this->aliassym = s; +#ifdef _DH + this->htype = NULL; + this->haliassym = NULL; +#endif this->overnext = NULL; this->inSemantic = 0; assert(s); @@ -192,6 +223,25 @@ sa = new AliasDeclaration(loc, ident, type->syntaxCopy()); else sa = new AliasDeclaration(loc, ident, aliassym->syntaxCopy(NULL)); +#ifdef _DH + // Syntax copy for header file + if (!htype) // Don't overwrite original + { if (type) // Make copy for both old and new instances + { htype = type->syntaxCopy(); + sa->htype = type->syntaxCopy(); + } + } + else // Make copy of original for new instance + sa->htype = htype->syntaxCopy(); + if (!haliassym) + { if (aliassym) + { haliassym = aliassym->syntaxCopy(s); + sa->haliassym = aliassym->syntaxCopy(s); + } + } + else + sa->haliassym = haliassym->syntaxCopy(s); +#endif return sa; } @@ -365,6 +415,10 @@ assert(type || init); this->type = type; this->init = init; +#ifdef _DH + this->htype = NULL; + this->hinit = NULL; +#endif this->loc = loc; offset = 0; noauto = 0; @@ -393,6 +447,25 @@ sv = new VarDeclaration(loc, type ? type->syntaxCopy() : NULL, ident, init); sv->storage_class = storage_class; } +#ifdef _DH + // Syntax copy for header file + if (!htype) // Don't overwrite original + { if (type) // Make copy for both old and new instances + { htype = type->syntaxCopy(); + sv->htype = type->syntaxCopy(); + } + } + else // Make copy of original for new instance + sv->htype = htype->syntaxCopy(); + if (!hinit) + { if (init) + { hinit = init->syntaxCopy(); + sv->hinit = init->syntaxCopy(); + } + } + else + sv->hinit = hinit->syntaxCopy(); +#endif return sv; } diff -uNr dmd-0.140/dmd/src/dmd/declaration.h dmd-0.141/dmd/src/dmd/declaration.h --- dmd-0.140/dmd/src/dmd/declaration.h 2005-09-18 22:14:22.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/declaration.h 2005-12-01 00:41:08.000000000 +0100 @@ -15,6 +15,8 @@ #endif /* __DMC__ */ #include "dsymbol.h" +#include "lexer.h" +#include "mtype.h" struct Expression; struct Statement; @@ -125,6 +127,11 @@ char *kind(); Type *getType(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + Type *htype; + Type *hbasetype; + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void toDocBuffer(OutBuffer *buf); @@ -150,6 +157,11 @@ Type *getType(); Dsymbol *toAlias(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); + Type *htype; + Dsymbol *haliassym; +#endif void toDocBuffer(OutBuffer *buf); @@ -171,6 +183,11 @@ void semantic2(Scope *sc); char *kind(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); + Type *htype; + Initializer *hinit; +#endif int needThis(); int isImportedSymbol(); int isDataseg(); @@ -334,6 +351,14 @@ 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 @@ -360,8 +385,10 @@ Dsymbol *syntaxCopy(Dsymbol *); void semantic(Scope *sc); void semantic3(Scope *sc); - void toHBuffer(OutBuffer *buf); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif int overrides(FuncDeclaration *fd); int overloadInsert(Dsymbol *s); FuncDeclaration *overloadExactMatch(Type *t); @@ -386,7 +413,11 @@ 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(); @@ -537,6 +568,9 @@ int isVirtual(); int addPreInvariant(); int addPostInvariant(); +#ifdef _DH + DeleteDeclaration *isDeleteDeclaration() { return this; } +#endif }; #endif /* DMD_DECLARATION_H */ diff -uNr dmd-0.140/dmd/src/dmd/doc.c dmd-0.141/dmd/src/dmd/doc.c --- dmd-0.140/dmd/src/dmd/doc.c 2005-11-05 15:37:56.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/doc.c 2005-11-26 22:33:18.000000000 +0100 @@ -11,6 +11,7 @@ #include #include #include +#include #if _WIN32 #include "..\root\mem.h" @@ -27,6 +28,12 @@ #include "macro.h" #include "template.h" #include "lexer.h" +#include "aggregate.h" +#include "declaration.h" +#include "enum.h" +#include "id.h" +#include "module.h" +#include "scope.h" #include "doc.h" struct Section diff -uNr dmd-0.140/dmd/src/dmd/dsymbol.c dmd-0.141/dmd/src/dmd/dsymbol.c --- dmd-0.140/dmd/src/dmd/dsymbol.c 2005-09-21 21:04:24.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/dsymbol.c 2005-12-04 11:32:08.000000000 +0100 @@ -193,8 +193,7 @@ void Dsymbol::toCBuffer(OutBuffer *buf) { - buf->printf("Dsymbol '%s' to C file", toChars()); - buf->writenl(); + buf->writestring(toChars()); } unsigned Dsymbol::size(Loc loc) @@ -281,7 +280,7 @@ } if (sd->isAggregateDeclaration() || sd->isEnumDeclaration()) { - if (ident == Id::__sizeof || ident == Id::alignof) + if (ident == Id::__sizeof || ident == Id::alignof || ident == Id::mangleof) error(".%s property cannot be redefined", ident->toChars()); } } diff -uNr dmd-0.140/dmd/src/dmd/dsymbol.h dmd-0.141/dmd/src/dmd/dsymbol.h --- dmd-0.140/dmd/src/dmd/dsymbol.h 2005-10-24 00:01:24.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/dsymbol.h 2005-12-01 00:42:40.000000000 +0100 @@ -60,6 +60,10 @@ struct ArrayScopeSymbol; struct SymbolDeclaration; struct Expression; +#ifdef _DH +struct DeleteDeclaration; +struct HdrGenState; +#endif struct TYPE; @@ -112,6 +116,10 @@ virtual void inlineScan(); virtual Dsymbol *search(Identifier *ident, int flags); virtual int overloadInsert(Dsymbol *s); +#ifdef _DH + char *toHChars(); + virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif virtual void toCBuffer(OutBuffer *buf); virtual void toDocBuffer(OutBuffer *buf); virtual unsigned size(Loc loc); @@ -179,6 +187,9 @@ virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; } virtual Import *isImport() { return NULL; } virtual EnumDeclaration *isEnumDeclaration() { return NULL; } +#ifdef _DH + virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; } +#endif virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; } virtual AttribDeclaration *isAttribDeclaration() { return NULL; } }; diff -uNr dmd-0.140/dmd/src/dmd/enum.h dmd-0.141/dmd/src/dmd/enum.h --- dmd-0.140/dmd/src/dmd/enum.h 2005-09-18 21:55:10.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/enum.h 2005-11-26 22:13:44.000000000 +0100 @@ -20,6 +20,9 @@ struct Identifier; struct Type; struct Expression; +#ifdef _DH +struct HdrGenState; +#endif struct EnumDeclaration : ScopeDsymbol { @@ -34,6 +37,9 @@ void semantic(Scope *sc); Dsymbol *oneMember(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Type *getType(); char *kind(); @@ -55,6 +61,9 @@ EnumMember(Loc loc, Identifier *id, Expression *value); Dsymbol *syntaxCopy(Dsymbol *s); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif char *kind(); void emitComment(Scope *sc); diff -uNr dmd-0.140/dmd/src/dmd/expression.c dmd-0.141/dmd/src/dmd/expression.c --- dmd-0.140/dmd/src/dmd/expression.c 2005-11-24 17:12:24.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/expression.c 2005-12-04 17:07:36.000000000 +0100 @@ -13,6 +13,14 @@ #include #include +#if __GNUC__ +extern "C" long double strtold(const char *p,char **endp); +#endif + +#if _WIN32 && __DMC__ +extern "C" char * __cdecl __locale_decpoint; +#endif + #if _WIN32 #include "..\root\mem.h" #endif @@ -513,6 +521,7 @@ void Expression::toMangleBuffer(OutBuffer *buf) { + dump(0); assert(0); } @@ -683,6 +692,7 @@ IntegerExp::IntegerExp(Loc loc, integer_t value, Type *type) : Expression(loc, TOKint64, sizeof(IntegerExp)) { + //printf("IntegerExp(value = %lld, type = '%s')\n", value, type ? type->toChars() : ""); if (type && !type->isscalar()) { error("integral constant must be scalar type, not %s", type->toChars()); @@ -824,18 +834,88 @@ void IntegerExp::toCBuffer(OutBuffer *buf) { + integer_t v = toInteger(); + if (type) - { - if (type->ty == Tenum) - { TypeEnum *te = (TypeEnum *)type; + { Type *t = type; + + L1: + switch (t->ty) + { + case Tenum: + { TypeEnum *te = (TypeEnum *)t; + buf->printf("cast(%s)", te->sym->toChars()); + t = te->sym->memtype; + goto L1; + } + + case Ttypedef: + { TypeTypedef *tt = (TypeTypedef *)t; + buf->printf("cast(%s)", tt->sym->toChars()); + t = tt->sym->basetype; + goto L1; + } - buf->printf("cast(%s)", te->sym->toChars()); + case Twchar: // BUG: need to cast(wchar) + case Tdchar: // BUG: need to cast(dchar) + if ((uinteger_t)v > 0xFF) + { + buf->printf("'\\U%08x'", v); + break; + } + case Tchar: + if (isprint(v)) + buf->printf("'%c'", (int)v); + else + buf->printf("'\\x%02x'", (int)v); + break; + + case Tint8: + buf->writestring("cast(byte)"); + goto L2; + + case Tint16: + buf->writestring("cast(short)"); + goto L2; + + case Tint32: + L2: + buf->printf("%ld", (int)v); + break; + + case Tuns8: + buf->writestring("cast(ubyte)"); + goto L3; + + case Tuns16: + buf->writestring("cast(ushort)"); + goto L3; + + case Tuns32: + L3: + buf->printf("%ldu", (unsigned)v); + break; + + case Tint64: + buf->printf("%lldL", v); + break; + + case Tuns64: + buf->printf("%lldLU", v); + break; + + case Tbit: + buf->writestring((char *)(v ? "true" : "false")); + break; + + default: + assert(0); } } - if (value & 0x8000000000000000LL) - buf->printf("0x%llx", value); + else if (v & 0x8000000000000000LL) + buf->printf("0x%llx", v); else - buf->printf("%lld", value); + buf->printf("%lld", v); } void IntegerExp::toMangleBuffer(OutBuffer *buf) @@ -894,6 +974,17 @@ #endif } +int RealExp::equals(Object *o) +{ RealExp *ne; + + if (this == o || + (((Expression *)o)->op == TOKfloat64 && + ((ne = (RealExp *)o), type->equals(ne->type)) && + memcmp(&value, &ne->value, sizeof(value)) == 0)) + return 1; + return 0; +} + Expression *RealExp::semantic(Scope *sc) { if (!type) @@ -909,13 +1000,58 @@ : (value == 0); } -void RealExp::toCBuffer(OutBuffer *buf) +void floatToBuffer(OutBuffer *buf, Type *type, real_t value) { - buf->printf("%Lg", value); - if (type->isimaginary()) - buf->writeByte('i'); + /* In order to get an exact representation, try converting it + * to decimal then back again. If it matches, use it. + * If it doesn't, fall back to hex, which is + * always exact. + */ + char buffer[25]; + sprintf(buffer, "%Lg", value); + assert(strlen(buffer) < sizeof(buffer)); +#if _WIN32 && __DMC__ + char *save = __locale_decpoint; + __locale_decpoint = "."; + real_t r = strtold(buffer, NULL); + __locale_decpoint = save; +#else + real_t r = strtold(buffer, NULL); +#endif + if (r == value) // if exact duplication + buf->writestring(buffer); + else + buf->printf("%La", value); // ensure exact duplication + + if (type) + { + Type *t = type->toBasetype(); + switch (t->ty) + { + case Tfloat32: + case Timaginary32: + case Tcomplex32: + buf->writeByte('F'); + break; + + case Tfloat80: + case Timaginary80: + case Tcomplex80: + buf->writeByte('L'); + break; + + default: + break; + } + if (t->isimaginary()) + buf->writeByte('i'); + } } +void RealExp::toCBuffer(OutBuffer *buf) +{ + floatToBuffer(buf, type, value); +} void RealExp::toMangleBuffer(OutBuffer *buf) { @@ -970,6 +1106,17 @@ return value; } +int ComplexExp::equals(Object *o) +{ ComplexExp *ne; + + if (this == o || + (((Expression *)o)->op == TOKcomplex80 && + ((ne = (ComplexExp *)o), type->equals(ne->type)) && + memcmp(&value, &ne->value, sizeof(value)) == 0)) + return 1; + return 0; +} + Expression *ComplexExp::semantic(Scope *sc) { if (!type) @@ -987,7 +1134,14 @@ void ComplexExp::toCBuffer(OutBuffer *buf) { - buf->printf("(%Lg+%Lgi)", creall(value), cimagl(value)); + /* Print as: + * (re+imi) + */ + buf->writeByte('('); + floatToBuffer(buf, type, creall(value)); + buf->writeByte('+'); + floatToBuffer(buf, type, cimagl(value)); + buf->writestring("i)"); } void ComplexExp::toMangleBuffer(OutBuffer *buf) @@ -1636,6 +1790,7 @@ break; case '"': + case '\\': buf->writeByte('\\'); default: if (isprint(c)) @@ -1841,11 +1996,11 @@ /********************** NewExp **************************************/ -NewExp::NewExp(Loc loc, Array *newargs, Type *type, Array *arguments) +NewExp::NewExp(Loc loc, Array *newargs, Type *newtype, Array *arguments) : Expression(loc, TOKnew, sizeof(NewExp)) { this->newargs = newargs; - this->type = type; + this->newtype = newtype; this->arguments = arguments; member = NULL; allocator = NULL; @@ -1854,7 +2009,7 @@ Expression *NewExp::syntaxCopy() { return new NewExp(loc, arraySyntaxCopy(newargs), - type->syntaxCopy(), arraySyntaxCopy(arguments)); + newtype->syntaxCopy(), arraySyntaxCopy(arguments)); } @@ -1864,9 +2019,11 @@ #if LOGSEMANTIC printf("NewExp::semantic() %s\n", toChars()); - printf("type: %s\n", type->toChars()); + printf("newtype: %s\n", newtype->toChars()); #endif - type = type->semantic(loc, sc); + if (type) + return this; + type = newtype->semantic(loc, sc); tb = type->toBasetype(); //printf("tb: %s, deco = %s\n", tb->toChars(), tb->deco); @@ -2025,7 +2182,7 @@ argsToCBuffer(buf, newargs); buf->writeByte(')'); } - type->toCBuffer(buf, NULL); + newtype->toCBuffer(buf, NULL); if (arguments && arguments->dim) { buf->writeByte('('); @@ -3035,7 +3192,8 @@ } else if (e1->type->ty == Tpointer && ident != Id::init && ident != Id::__sizeof && - ident != Id::alignof && ident != Id::offsetof) + ident != Id::alignof && ident != Id::offsetof && + ident != Id::mangleof) { e = new PtrExp(loc, e1); e->type = e1->type->next; diff -uNr dmd-0.140/dmd/src/dmd/expression.h dmd-0.141/dmd/src/dmd/expression.h --- dmd-0.140/dmd/src/dmd/expression.h 2005-11-20 23:15:04.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/expression.h 2005-12-04 17:07:36.000000000 +0100 @@ -34,6 +34,10 @@ struct AggregateDeclaration; struct TemplateInstance; struct ClassDeclaration; +#ifdef _DH +struct HdrGenState; +struct BinExp; +#endif // Back end struct IRState; @@ -73,6 +77,11 @@ 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 toMangleBuffer(OutBuffer *buf); virtual Expression *toLvalue(Expression *e); virtual Expression *modifiableLvalue(Scope *sc, Expression *e); @@ -131,6 +140,9 @@ int isBool(int result); int implicitConvTo(Type *t); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void toMangleBuffer(OutBuffer *buf); Expression *toLvalue(Expression *e); elem *toElem(IRState *irs); @@ -142,6 +154,7 @@ real_t value; RealExp(Loc loc, real_t value, Type *type); + int equals(Object *o); Expression *semantic(Scope *sc); char *toChars(); integer_t toInteger(); @@ -153,6 +166,9 @@ int isBool(int result); void toCBuffer(OutBuffer *buf); void toMangleBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); dt_t **toDt(dt_t **pdt); }; @@ -162,6 +178,7 @@ complex_t value; ComplexExp(Loc loc, complex_t value, Type *type); + int equals(Object *o); Expression *semantic(Scope *sc); char *toChars(); integer_t toInteger(); @@ -173,6 +190,10 @@ int isBool(int result); void toCBuffer(OutBuffer *buf); 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); }; @@ -188,6 +209,9 @@ char *toChars(); void dump(int indent); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Expression *toLvalue(Expression *e); }; @@ -205,6 +229,9 @@ char *toChars(); void dump(int indent); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Expression *toLvalue(Expression *e); }; @@ -216,6 +243,9 @@ Expression *semantic(Scope *sc); int isBool(int result); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Expression *toLvalue(Expression *e); int inlineCost(InlineCostState *ics); @@ -230,6 +260,9 @@ SuperExp(Loc loc); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif int inlineCost(InlineCostState *ics); Expression *doInline(InlineDoState *ids); @@ -242,6 +275,9 @@ Expression *semantic(Scope *sc); int isBool(int result); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void toMangleBuffer(OutBuffer *buf); int implicitConvTo(Type *t); Expression *castTo(Type *t); @@ -268,6 +304,9 @@ int isBool(int result); void toCBuffer(OutBuffer *buf); void toMangleBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); dt_t **toDt(dt_t **pdt); }; @@ -280,6 +319,9 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); }; @@ -287,6 +329,9 @@ { TypeExp(Loc loc, Type *type); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); }; @@ -299,20 +344,27 @@ Expression *semantic(Scope *sc); elem *toElem(IRState *irs); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; struct NewExp : Expression { + Type *newtype; Array *newargs; // Array of Expression's to call new operator Array *arguments; // Array of Expression's CtorDeclaration *member; // constructor function NewDeclaration *allocator; // allocator function - NewExp(Loc loc, Array *newargs, Type *type, Array *arguments); + NewExp(Loc loc, Array *newargs, Type *newtype, Array *arguments); Expression *syntaxCopy(); Expression *semantic(Scope *sc); elem *toElem(IRState *irs); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif //int inlineCost(InlineCostState *ics); Expression *doInline(InlineDoState *ids); @@ -329,6 +381,9 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; // Offset from symbol @@ -342,6 +397,9 @@ Expression *semantic(Scope *sc); void checkEscape(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif int isConst(); int isBool(int result); Expression *doInline(InlineDoState *ids); @@ -362,6 +420,9 @@ void dump(int indent); char *toChars(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void checkEscape(); Expression *toLvalue(Expression *e); Expression *modifiableLvalue(Scope *sc, Expression *e); @@ -384,6 +445,9 @@ Expression *semantic(Scope *sc); char *toChars(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); int inlineCost(InlineCostState *ics); @@ -401,6 +465,9 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); int inlineCost(InlineCostState *ics); @@ -416,6 +483,9 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; struct HaltExp : Expression @@ -423,6 +493,9 @@ HaltExp(Loc loc); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); }; @@ -442,6 +515,9 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; /****************************************************************/ @@ -454,6 +530,9 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Expression *optimize(int result); void dump(int indent); @@ -476,6 +555,10 @@ 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 Expression *scaleFactor(); Expression *typeCombine(); Expression *optimize(int result); @@ -498,6 +581,9 @@ AssertExp(Loc loc, Expression *e); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); }; @@ -508,6 +594,9 @@ 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 dump(int i); }; @@ -520,6 +609,9 @@ Expression *toLvalue(Expression *e); Expression *modifiableLvalue(Scope *sc, Expression *e); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void dump(int indent); elem *toElem(IRState *irs); }; @@ -532,6 +624,9 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void dump(int indent); }; @@ -544,6 +639,9 @@ int implicitConvTo(Type *t); Expression *castTo(Type *t); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void dump(int indent); int inlineCost(InlineCostState *ics); @@ -557,6 +655,9 @@ DotTypeExp(Loc loc, Expression *e, Dsymbol *sym); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); }; @@ -567,6 +668,9 @@ 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 @@ -581,6 +685,9 @@ Expression *syntaxCopy(); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); int inlineCost(InlineCostState *ics); @@ -605,6 +712,9 @@ Expression *semantic(Scope *sc); Expression *toLvalue(Expression *e); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); Expression *optimize(int result); }; @@ -678,6 +788,9 @@ Expression *semantic(Scope *sc); Expression *optimize(int result); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Expression *constFold(); elem *toElem(IRState *irs); @@ -699,6 +812,9 @@ Expression *toLvalue(Expression *e); Expression *modifiableLvalue(Scope *sc, Expression *e); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Expression *optimize(int result); void dump(int indent); elem *toElem(IRState *irs); @@ -713,6 +829,9 @@ ArrayLengthExp(Loc loc, Expression *e1); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif elem *toElem(IRState *irs); }; @@ -727,6 +846,9 @@ Expression *semantic(Scope *sc); Expression *toLvalue(Expression *e); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif // For operator overloading Identifier *opId(); @@ -766,6 +888,9 @@ Expression *toLvalue(Expression *e); Expression *modifiableLvalue(Scope *sc, Expression *e); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Expression *optimize(int result); Expression *doInline(InlineDoState *ids); @@ -777,6 +902,9 @@ PostIncExp(Loc loc, Expression *e); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Identifier *opId(); // For operator overloading elem *toElem(IRState *irs); }; @@ -786,6 +914,9 @@ PostDecExp(Loc loc, Expression *e); Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Identifier *opId(); // For operator overloading elem *toElem(IRState *irs); }; @@ -1185,6 +1316,9 @@ Expression *modifiableLvalue(Scope *sc, Expression *e); Expression *checkToBoolean(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif int implicitConvTo(Type *t); Expression *castTo(Type *t); diff -uNr dmd-0.140/dmd/src/dmd/func.c dmd-0.141/dmd/src/dmd/func.c --- dmd-0.140/dmd/src/dmd/func.c 2005-10-16 14:56:50.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/func.c 2005-12-01 01:45:54.000000000 +0100 @@ -41,6 +41,13 @@ 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; @@ -73,6 +80,9 @@ f->fensure = fensure ? fensure->syntaxCopy() : NULL; f->fbody = fbody ? fbody->syntaxCopy() : NULL; assert(!fthrows); // deprecated +#ifdef _DH + hdrSyntaxCopy(f); +#endif return f; } @@ -750,8 +760,15 @@ // Merge contracts together with body into one compound statement +#ifdef _DH if (frequire && global.params.useIn) + { frequire->incontract = 1; a->push(frequire); + } +#else + if (frequire && global.params.useIn) + a->push(frequire); +#endif // Precondition invariant if (addPreInvariant()) @@ -814,13 +831,6 @@ } } -void FuncDeclaration::toHBuffer(OutBuffer *buf) -{ - type->toCBuffer(buf, ident); - buf->writeByte(';'); - buf->writenl(); -} - void FuncDeclaration::toCBuffer(OutBuffer *buf) { type->toCBuffer(buf, ident); @@ -1460,6 +1470,10 @@ f->arguments = Argument::arraySyntaxCopy(arguments); +#ifdef _DH + FuncDeclaration::hdrSyntaxCopy(f); +#endif + return f; } diff -uNr dmd-0.140/dmd/src/dmd/hdrgen.c dmd-0.141/dmd/src/dmd/hdrgen.c --- dmd-0.140/dmd/src/dmd/hdrgen.c 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/hdrgen.c 2005-12-02 21:19:22.000000000 +0100 @@ -0,0 +1,2467 @@ + +// 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. + +// Routines to emit header files + +#ifdef _DH + +#define PRETTY_PRINT +//#define TEST_EMIT_ALL // For Testing + +#define LOG 0 + +#include +#include +#include +#if __DMC__ +#include +#endif + +#include "id.h" +#include "init.h" + +#include "attrib.h" +#include "cond.h" +#include "enum.h" +#include "import.h" +#include "module.h" +#include "mtype.h" +#include "scope.h" +#include "staticassert.h" +#include "template.h" +#include "utf.h" +#include "version.h" + +#include "declaration.h" +#include "aggregate.h" +#include "expression.h" +#include "statement.h" +#include "mtype.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 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(' '); + } + + cs.writestring("case "); + de.writestring("default:"); + cs.fill0(1); + de.fill0(1); + + if (hdrbufr.offset && (hdrbufr.data[hdrbufr.offset - 1] != '\n')) + hdrbufr.writenl(); + + 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; + +#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) +{ + // 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 + { + 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->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]; + + 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(')'); + +} + +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(); + } +} + +/*************************************/ + +#endif // #ifdef _DH diff -uNr dmd-0.140/dmd/src/dmd/identifier.h dmd-0.141/dmd/src/dmd/identifier.h --- dmd-0.140/dmd/src/dmd/identifier.h 2004-12-18 15:32:38.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/identifier.h 2005-12-01 00:35:58.000000000 +0100 @@ -28,6 +28,10 @@ int compare(Object *o); void print(); char *toChars(); +#ifdef _DH + char *toHChars(); + char *toHChars2(); //New +#endif int dyncast(); static Identifier *generateId(char *prefix); diff -uNr dmd-0.140/dmd/src/dmd/idgen.c dmd-0.141/dmd/src/dmd/idgen.c --- dmd-0.140/dmd/src/dmd/idgen.c 2005-06-02 00:10:00.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/idgen.c 2005-12-04 11:26:52.000000000 +0100 @@ -43,6 +43,7 @@ { "size" }, { "__sizeof", "sizeof" }, { "alignof" }, + { "mangleof" }, { "length" }, { "remove" }, { "ptr" }, @@ -61,6 +62,7 @@ { "line" }, { "empty", "" }, { "p" }, + { "coverage", "__coverage" }, { "TypeInfo" }, { "TypeInfo_Class" }, diff -uNr dmd-0.140/dmd/src/dmd/import.h dmd-0.141/dmd/src/dmd/import.h --- dmd-0.140/dmd/src/dmd/import.h 2005-04-29 15:18:54.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/import.h 2005-11-26 22:16:02.000000000 +0100 @@ -22,6 +22,9 @@ struct OutBuffer; struct Module; struct Package; +#ifdef _DH +struct HdrGenState; +#endif struct Import : Dsymbol { @@ -39,6 +42,9 @@ Dsymbol *search(Identifier *ident, int flags); int overloadInsert(Dsymbol *s); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Import *isImport() { return this; } }; diff -uNr dmd-0.140/dmd/src/dmd/init.h dmd-0.141/dmd/src/dmd/init.h --- dmd-0.140/dmd/src/dmd/init.h 2005-10-19 23:33:04.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/init.h 2005-12-01 00:35:12.000000000 +0100 @@ -22,6 +22,9 @@ struct AggregateDeclaration; struct VoidInitializer; struct ExpInitializer; +#ifdef _DH +struct HdrGenState; +#endif struct Initializer : Object { @@ -33,6 +36,9 @@ 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 static Array *arraySyntaxCopy(Array *ai); @@ -51,6 +57,9 @@ Initializer *semantic(Scope *sc, Type *t); Expression *toExpression(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif dt_t *toDt(); @@ -69,6 +78,9 @@ Initializer *semantic(Scope *sc, Type *t); Expression *toExpression(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif dt_t *toDt(); }; @@ -87,6 +99,9 @@ Initializer *semantic(Scope *sc, Type *t); Expression *toExpression(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif dt_t *toDt(); dt_t *toDtBit(); // for bit arrays @@ -102,6 +117,9 @@ Type *inferType(Scope *sc); Expression *toExpression(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif dt_t *toDt(); diff -uNr dmd-0.140/dmd/src/dmd/inline.c dmd-0.141/dmd/src/dmd/inline.c --- dmd-0.140/dmd/src/dmd/inline.c 2005-10-15 00:20:12.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/inline.c 2005-12-01 02:53:28.000000000 +0100 @@ -33,6 +33,9 @@ { int nested; int hasthis; +#ifdef _DH + int hdrscan; // Is this an inline scan for 'header' content? +#endif FuncDeclaration *fd; }; @@ -57,6 +60,19 @@ 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; @@ -117,6 +133,9 @@ 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); } } @@ -343,8 +362,13 @@ for (int i = 0; i < a->dim; i++) { Expression *e = (Expression *)a->data[i]; - e = e->doInline(ids); - newa->data[i] = (void *)e; +#ifdef _DH + if (e) // To avoid crash with DMDFE for some expressions +#endif + { + e = e->doInline(ids); + newa->data[i] = (void *)e; + } } } return newa; @@ -810,8 +834,13 @@ for (int i = 0; i < arguments->dim; i++) { Expression *e = (Expression *)arguments->data[i]; - e = e->inlineScan(iss); - arguments->data[i] = (void *)e; +#ifdef _DH + if (e) // to avoid a crash with DMDFE when scanning arguments with variadic parameters +#endif + { + e = e->inlineScan(iss); + arguments->data[i] = (void *)e; + } } } } @@ -933,7 +962,11 @@ } } +#ifdef _DH +int FuncDeclaration::canInline(int hasthis, int hdrscan) +#else int FuncDeclaration::canInline(int hasthis) +#endif { InlineCostState ics; int cost; @@ -1010,6 +1043,9 @@ memset(&ics, 0, sizeof(ics)); ics.hasthis = hasthis; ics.fd = this; +#ifdef _DH + ics.hdrscan = hdrscan ? 1 : 0; +#endif cost = fbody->inlineCost(&ics); #if CANINLINE_LOG printf("cost = %d\n", cost); @@ -1017,9 +1053,15 @@ if (cost >= COST_MAX) goto Lno; +#ifdef _DH + if (!hdrscan) // Don't scan recursively for header content scan +#endif inlineScan(); Lyes: +#ifdef _DH + if (!hdrscan) // Don't modify inlineStatus for header content scan +#endif inlineStatus = ILSyes; #if CANINLINE_LOG printf("\tyes\n"); @@ -1027,6 +1069,9 @@ return 1; Lno: +#ifdef _DH + if (!hdrscan) // Don't modify inlineStatus for header content scan +#endif inlineStatus = ILSno; #if CANINLINE_LOG printf("\tno\n"); diff -uNr dmd-0.140/dmd/src/dmd/lexer.c dmd-0.141/dmd/src/dmd/lexer.c --- dmd-0.140/dmd/src/dmd/lexer.c 2005-10-17 19:39:06.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/lexer.c 2005-12-01 23:38:38.000000000 +0100 @@ -2448,8 +2448,7 @@ Token::tochars[TOKge] = ">="; Token::tochars[TOKequal] = "=="; Token::tochars[TOKnotequal] = "!="; - Token::tochars[TOKidentity] = "==="; - Token::tochars[TOKnotidentity] = "!=="; + Token::tochars[TOKnotidentity] = "!is"; Token::tochars[TOKunord] = "!<>="; Token::tochars[TOKue] = "!<>"; diff -uNr dmd-0.140/dmd/src/dmd/macro.c dmd-0.141/dmd/src/dmd/macro.c --- dmd-0.140/dmd/src/dmd/macro.c 2005-10-14 20:41:22.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/macro.c 2005-11-26 22:30:16.000000000 +0100 @@ -14,6 +14,7 @@ #include #include #include +#include #if _WIN32 #include "..\root\mem.h" diff -uNr dmd-0.140/dmd/src/dmd/mars.c dmd-0.141/dmd/src/dmd/mars.c --- dmd-0.140/dmd/src/dmd/mars.c 2005-11-13 00:43:02.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/mars.c 2005-12-01 11:42:02.000000000 +0100 @@ -38,6 +38,9 @@ { mars_ext = "d"; sym_ext = "d"; +#ifdef _DH + hdr_ext = "d"; +#endif doc_ext = "html"; ddoc_ext = "ddoc"; @@ -51,7 +54,7 @@ copyright = "Copyright (c) 1999-2005 by Digital Mars"; written = "written by Walter Bright"; - version = "v0.140"; + version = "v0.141"; global.structalign = 8; memset(¶ms, 0, sizeof(Param)); @@ -139,6 +142,8 @@ -debug=level compile in debug code <= level\n\ -debug=ident compile in debug code identified by ident\n\ -g add symbolic debug info\n\ + -Hdhdrdir write 'header' file to hdrdir directory\n\ + -Hffilename write 'header' file to filename\n\ --help print help\n\ -Ipath where to look for imports\n\ -inline do function inlining\n\ @@ -211,6 +216,7 @@ VersionCondition::addPredefinedGlobalIdent("X86"); VersionCondition::addPredefinedGlobalIdent("LittleEndian"); VersionCondition::addPredefinedGlobalIdent("D_InlineAsm"); + VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86"); VersionCondition::addPredefinedGlobalIdent("all"); #if _WIN32 @@ -237,6 +243,8 @@ global.params.useDeprecated = 1; else if (strcmp(p + 1, "c") == 0) global.params.link = 0; + else if (strcmp(p + 1, "cov") == 0) + global.params.cov = 1; else if (strcmp(p + 1, "fPIC") == 0) global.params.pic = 1; else if (strcmp(p + 1, "g") == 0) @@ -311,6 +319,31 @@ goto Lerror; } } +#ifdef _DH + else if (p[1] == 'H') + { global.params.doHdrGeneration = 1; + switch (p[2]) + { + case 'd': + if (!p[3]) + goto Lnoarg; + global.params.hdrdir = p + 3; + break; + + case 'f': + if (!p[3]) + goto Lnoarg; + global.params.hdrname = p + 3; + break; + + case 0: + break; + + default: + goto Lerror; + } + } +#endif else if (strcmp(p + 1, "inline") == 0) global.params.useInline = 1; else if (strcmp(p + 1, "quiet") == 0) @@ -447,6 +480,9 @@ fatal(); } } + if (global.params.cov) + VersionCondition::addPredefinedGlobalIdent("D_Coverage"); + //printf("%d source files\n",files.dim); @@ -567,7 +603,11 @@ } 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); @@ -604,6 +644,19 @@ global.params.link = 0; } } +#ifdef _DH + if (global.params.doHdrGeneration) + { + /* Make syntax copies for header file generation after parsing but + * prior to semantic analysis. + */ + for (i = 0; i < modules.dim; i++) + { + m = (Module *)modules.data[i]; + m->syntaxCopy(NULL); // The original data is *not* overwritten + } + } +#endif if (global.errors) fatal(); @@ -640,6 +693,22 @@ 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) { @@ -666,7 +735,10 @@ m->deleteObjFile(); else { - //m->gensymfile(); +#ifdef _DH + if (global.params.doHdrGeneration) + m->genhdrfile(); // format and output header content +#endif if (global.params.doDocComments) m->gendocfile(); } diff -uNr dmd-0.140/dmd/src/dmd/mars.h dmd-0.141/dmd/src/dmd/mars.h --- dmd-0.140/dmd/src/dmd/mars.h 2005-10-26 00:37:58.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/mars.h 2005-11-28 16:44:08.000000000 +0100 @@ -43,6 +43,7 @@ char preservePaths; // !=0 means don't strip path from source file char warnings; // enable warnings char pic; // generate position-independent-code for shared libs + char cov; // generate code coverage data char *argv0; // program name Array *imppath; // array of char*'s of where to look for import modules @@ -54,6 +55,12 @@ 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 @@ -86,6 +93,9 @@ 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 *copyright; char *written; Array *path; // Array of char*'s which form the import lookup path diff -uNr dmd-0.140/dmd/src/dmd/module.c dmd-0.141/dmd/src/dmd/module.c --- dmd-0.140/dmd/src/dmd/module.c 2005-10-09 23:51:00.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/module.c 2005-12-01 01:53:38.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 @@ -11,6 +11,10 @@ #include #include +#ifdef _MSC_VER +#include +#endif + #include "mars.h" #include "module.h" #include "parse.h" @@ -34,7 +38,11 @@ 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; @@ -47,6 +55,7 @@ this->arg = filename; md = NULL; errors = 0; + numlines = 0; members = NULL; isHtml = 0; isDocFile = 0; @@ -76,6 +85,8 @@ versionidsNot = NULL; macrotable = NULL; + cov = NULL; + covb = NULL; srcfilename = FileName::defaultExt(filename, global.mars_ext); if (!srcfilename->equalsExt(global.mars_ext)) @@ -111,6 +122,13 @@ setDocfile(); } +#ifdef _DH + if (doHdrGen) + { + setHdrfile(); + } +#endif + objfile = new File(objfilename); symfile = new File(symfilename); } @@ -141,6 +159,34 @@ docfile = new File(docfilename); } +#ifdef _DH +void Module::setHdrfile() +{ + FileName *hdrfilename; + char *arghdr; + + if (global.params.hdrname) + arghdr = global.params.hdrname; + else if (global.params.preservePaths) + arghdr = (char *)arg; + else + arghdr = FileName::name((char *)arg); + if (!FileName::absolute(arghdr)) + arghdr = FileName::combine(global.params.hdrdir, arghdr); + if (global.params.hdrname) + hdrfilename = new FileName(arghdr, 0); + else + hdrfilename = FileName::forceExt(arghdr, global.hdr_ext); + + if (hdrfilename->equals(srcfile->name)) + { error("Source file and 'header' file have same name '%s'", srcfile->name->str); + fatal(); + } + + hdrfile = new File(hdrfilename); +} +#endif + void Module::deleteObjFile() { if (global.params.obj) @@ -189,7 +235,11 @@ 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 @@ -443,6 +493,7 @@ Parser p(this, buf, buflen, docfile != NULL); members = p.parseModule(); md = p.md; + numlines = p.loc.linnum; DsymbolTable *dst; @@ -645,7 +696,7 @@ int Module::needModuleInfo() { - return needmoduleinfo; + return needmoduleinfo || global.params.cov; } Dsymbol *Module::search(Identifier *ident, int flags) diff -uNr dmd-0.140/dmd/src/dmd/module.h dmd-0.141/dmd/src/dmd/module.h --- dmd-0.140/dmd/src/dmd/module.h 2005-10-09 11:31:28.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/module.h 2005-11-29 14:13:00.000000000 +0100 @@ -21,6 +21,7 @@ struct ClassDeclaration; struct ModuleDeclaration; struct Macro; +struct VarDeclaration; // Back end struct elem; @@ -50,9 +51,13 @@ 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 + unsigned numlines; // number of lines in source file int isHtml; // if it is an HTML file int isDocFile; // if it is a documentation input file, not D source int needmoduleinfo; @@ -83,7 +88,11 @@ 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); @@ -96,6 +105,12 @@ 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 +#endif void genobjfile(); void gensymfile(); void gendocfile(); @@ -107,6 +122,9 @@ // Back end + Symbol *cov; // private uint[] __coverage; + unsigned *covb; // bit array of valid code line numbers + Symbol *sctor; // module constructor Symbol *sdtor; // module destructor Symbol *stest; // module unit test @@ -122,6 +140,7 @@ static Symbol *gencritsec(); elem *toEfilename(); + elem *toEmodulename(); Symbol *toSymbol(); void genmoduleinfo(); diff -uNr dmd-0.140/dmd/src/dmd/mtype.c dmd-0.141/dmd/src/dmd/mtype.c --- dmd-0.140/dmd/src/dmd/mtype.c 2005-11-23 14:47:42.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/mtype.c 2005-12-04 13:26:52.000000000 +0100 @@ -9,13 +9,19 @@ #include #include +#include #ifdef __DMC__ #include #endif -#include +#if _MSC_VER +#include +#include +#include +#else #include +#endif #ifdef __APPLE__ #include @@ -29,6 +35,7 @@ #include "mem.h" +#include "dsymbol.h" #include "mtype.h" #include "scope.h" #include "init.h" @@ -513,6 +520,10 @@ e = defaultInit(); e->loc = loc; } + else if (ident == Id::mangleof) + { assert(deco); + e = new StringExp(loc, deco, strlen(deco), 'c'); + } else { error(loc, "no property '%s' for type '%s'", ident->toChars(), toChars()); @@ -944,6 +955,11 @@ foo = -foo; fvalue = foo; } +#elif _MSC_VER + { + unsigned long nan[2]= { 0xFFFFFFFF, 0x7FFFFFFF }; + fvalue = *(double*)nan; + } #else fvalue = NAN; #endif @@ -965,6 +981,8 @@ case Tfloat80: #if __GNUC__ fvalue = 1 / zero; +#elif _MSC_VER + fvalue = std::numeric_limits::infinity(); #else fvalue = INFINITY; #endif @@ -2710,12 +2728,21 @@ return; } #endif + v = s->isVarDeclaration(); + if (v && id == Id::length) + { + if (v->isConst() && v->getExpInitializer()) + e = v->getExpInitializer()->exp; + else + e = new VarExp(loc, v); + t = e->type; + goto L3; + } t = s->getType(); if (!t && s->isDeclaration()) t = s->isDeclaration()->type; if (t) { -//<<>> sm = t->toDsymbol(sc); if (sm) { sm = sm->search(id, 0); @@ -2724,6 +2751,7 @@ } e = t->getProperty(loc, id); i++; + L3: for (; i < idents.dim; i++) { id = (Identifier *)idents.data[i]; @@ -3438,6 +3466,21 @@ return sym->basetype->isfloating(); } +int TypeTypedef::isreal() +{ + return sym->basetype->isreal(); +} + +int TypeTypedef::isimaginary() +{ + return sym->basetype->isimaginary(); +} + +int TypeTypedef::iscomplex() +{ + return sym->basetype->iscomplex(); +} + int TypeTypedef::isunsigned() { return sym->basetype->isunsigned(); diff -uNr dmd-0.140/dmd/src/dmd/mtype.h dmd-0.141/dmd/src/dmd/mtype.h --- dmd-0.140/dmd/src/dmd/mtype.h 2005-11-09 10:25:10.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/mtype.h 2005-12-04 13:25:40.000000000 +0100 @@ -33,6 +33,9 @@ enum LINK; struct TypeBasic; +#ifdef _DH +struct HdrGenState; +#endif // Back end typedef struct TYPE type; @@ -188,6 +191,10 @@ 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 virtual int isbit(); virtual int isintegral(); virtual int isfloating(); // real, imaginary, or complex @@ -248,6 +255,9 @@ 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 int isintegral(); int isbit(); int isfloating(); @@ -270,6 +280,9 @@ 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 Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); }; @@ -351,6 +364,9 @@ 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 int implicitConvTo(Type *to); int isscalar(); Expression *defaultInit(); @@ -366,6 +382,9 @@ Type *syntaxCopy(); d_uns64 size(Loc loc); void toCBuffer2(OutBuffer *buf, Identifier *ident); +#ifdef _DH + void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); +#endif Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); Expression *defaultInit(); int isZeroInit(); @@ -390,6 +409,11 @@ 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 MATCH deduceType(Type *tparam, Array *parameters, Array *atypes); TypeInfoDeclaration *getTypeInfoDeclaration(); @@ -407,6 +431,9 @@ 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 Expression *defaultInit(); int isZeroInit(); int checkBoolean(); @@ -424,6 +451,9 @@ 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 d_uns64 size(Loc loc); void resolveHelper(Loc loc, Scope *sc, Dsymbol *s, Dsymbol *scopesym, Expression **pe, Type **pt, Dsymbol **ps); @@ -438,6 +468,9 @@ //char *toChars(); void toDecoBuffer(OutBuffer *buf); void toCBuffer2(OutBuffer *buf, Identifier *ident); +#ifdef _DH + void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); +#endif void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps); Dsymbol *toDsymbol(Scope *sc); Type *semantic(Loc loc, Scope *sc); @@ -455,6 +488,9 @@ //char *toChars(); //void toDecoBuffer(OutBuffer *buf); void toCBuffer2(OutBuffer *buf, Identifier *ident); +#ifdef _DH + void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); +#endif 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); @@ -468,6 +504,9 @@ Type *syntaxCopy(); Dsymbol *toDsymbol(Scope *sc); void toCBuffer2(OutBuffer *buf, Identifier *ident); +#ifdef _DH + void toHBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); +#endif Type *semantic(Loc loc, Scope *sc); d_uns64 size(Loc loc); }; @@ -486,6 +525,9 @@ 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 Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); unsigned memalign(unsigned salign); Expression *defaultInit(); @@ -510,6 +552,9 @@ 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 Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); Expression *getProperty(Loc loc, Identifier *ident); int isintegral(); @@ -540,10 +585,16 @@ 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 Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); int isbit(); int isintegral(); int isfloating(); + int isreal(); + int isimaginary(); + int iscomplex(); int isscalar(); int isunsigned(); int checkBoolean(); @@ -571,6 +622,9 @@ 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 Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); ClassDeclaration *isClassHandle(); int isBaseOf(Type *t); @@ -587,7 +641,7 @@ Symbol *toSymbol(); }; -enum InOut { In, Out, InOut }; +enum InOut { None, In, Out, InOut }; struct Argument : Object { diff -uNr dmd-0.140/dmd/src/dmd/optimize.c dmd-0.141/dmd/src/dmd/optimize.c --- dmd-0.140/dmd/src/dmd/optimize.c 2005-11-24 01:03:40.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/optimize.c 2005-12-04 12:53:40.000000000 +0100 @@ -113,6 +113,7 @@ Expression *CastExp::optimize(int result) { + //printf("CastExp::optimize(result = %d) %s\n", result, toChars()); if (e1->op == TOKstring && (type->ty == Tpointer || type->ty == Tarray) && type->next->equals(e1->type->next) diff -uNr dmd-0.140/dmd/src/dmd/parse.c dmd-0.141/dmd/src/dmd/parse.c --- dmd-0.140/dmd/src/dmd/parse.c 2005-11-10 10:59:38.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/parse.c 2005-12-04 11:59:18.000000000 +0100 @@ -936,7 +936,7 @@ * at ai ... */ - if (inout != In) + if (inout == Out || inout == InOut) error("variadic argument cannot be out or inout"); varargs = 2; a = new Argument(inout, at, ai, ae); @@ -3428,13 +3428,18 @@ if (!isBasicType(&t)) return FALSE; tmp = FALSE; - if (!isDeclarator(&t, &tmp, TOKreserved)) + if (t->value != TOKdotdotdot && + !isDeclarator(&t, &tmp, TOKreserved)) return FALSE; if (t->value == TOKassign) { t = peek(t); if (!isExpression(&t)) return FALSE; - continue; + } + if (t->value == TOKdotdotdot) + { + t = peek(t); + break; } if (t->value == TOKcomma) { t = peek(t); diff -uNr dmd-0.140/dmd/src/dmd/statement.c dmd-0.141/dmd/src/dmd/statement.c --- dmd-0.140/dmd/src/dmd/statement.c 2005-08-25 23:54:26.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/statement.c 2005-12-04 11:50:14.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,6 +30,11 @@ Statement::Statement(Loc loc) : loc(loc) { +#ifdef _DH + // If this is an in{} contract scope statement (skip for determining + // inlineStatus of a function body for header content) + incontract = 0; +#endif } Statement *Statement::syntaxCopy() @@ -736,6 +741,7 @@ { case In: var->storage_class |= STCin; break; case Out: var->storage_class |= STCout; break; case InOut: var->storage_class |= STCin | STCout; break; + default: assert(0); } var->semantic(sc); if (!sc->insert(var)) @@ -1006,10 +1012,15 @@ Statement *IfStatement::syntaxCopy() { + Statement *i = NULL; + if (ifbody) + i = ifbody->syntaxCopy(); + Statement *e = NULL; if (elsebody) e = elsebody->syntaxCopy(); - IfStatement *s = new IfStatement(loc, condition->syntaxCopy(), ifbody->syntaxCopy(), e); + + IfStatement *s = new IfStatement(loc, condition->syntaxCopy(), i, e); return s; } @@ -1710,7 +1721,7 @@ if (exp) { Statement *s; - s = new ExpStatement(loc, exp); + s = new ExpStatement(0, exp); return new CompoundStatement(loc, s, gs); } return gs; @@ -1720,6 +1731,7 @@ { Statement *s; s = new ExpStatement(loc, exp); + loc = 0; exp = NULL; return new CompoundStatement(loc, s, this); } @@ -2286,7 +2298,8 @@ Statement *VolatileStatement::syntaxCopy() { - VolatileStatement *s = new VolatileStatement(loc, statement); + VolatileStatement *s = new VolatileStatement(loc, + statement ? statement->syntaxCopy() : NULL); return s; } diff -uNr dmd-0.140/dmd/src/dmd/statement.h dmd-0.141/dmd/src/dmd/statement.h --- dmd-0.140/dmd/src/dmd/statement.h 2005-06-30 00:41:36.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/statement.h 2005-12-04 11:19:56.000000000 +0100 @@ -36,6 +36,12 @@ struct CompoundStatement; struct Argument; struct StaticAssert; +#ifdef _DH +struct AsmStatement; +struct GotoStatement; +struct ScopeStatement; +struct TryCatchStatement; +#endif // Back end struct IRState; @@ -56,6 +62,15 @@ 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 TryCatchStatement *isTryCatchStatement() { return NULL; } + virtual GotoStatement *isGotoStatement() { return NULL; } + virtual AsmStatement *isAsmStatement() { return NULL; } + int incontract; +#endif virtual Statement *semantic(Scope *sc); Statement *semanticScope(Scope *sc, Statement *sbreak, Statement *scontinue); virtual int hasBreak(); @@ -86,6 +101,9 @@ ExpStatement(Loc loc, Expression *exp); Statement *syntaxCopy(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *semantic(Scope *sc); int fallOffEnd(); @@ -105,6 +123,9 @@ DeclarationStatement(Loc loc, Expression *exp); Statement *syntaxCopy(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *callAutoDtor(); DeclarationStatement *isDeclarationStatement() { return this; } @@ -118,6 +139,9 @@ CompoundStatement(Loc loc, Statement *s1, Statement *s2); Statement *syntaxCopy(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *semantic(Scope *sc); int usesEH(); int fallOffEnd(); @@ -155,6 +179,11 @@ 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); + ScopeStatement *isScopeStatement() { return this; } +#endif Statement *semantic(Scope *sc); int fallOffEnd(); @@ -175,6 +204,9 @@ int hasContinue(); int usesEH(); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *inlineScan(InlineScanState *iss); @@ -193,6 +225,9 @@ int hasContinue(); int usesEH(); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *inlineScan(InlineScanState *iss); @@ -213,6 +248,9 @@ int hasContinue(); int usesEH(); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *inlineScan(InlineScanState *iss); @@ -238,6 +276,9 @@ int hasContinue(); int usesEH(); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *inlineScan(InlineScanState *iss); @@ -254,6 +295,9 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif int usesEH(); int fallOffEnd(); @@ -276,6 +320,9 @@ int usesEH(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; struct PragmaStatement : Statement @@ -291,6 +338,9 @@ int fallOffEnd(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; struct StaticAssertStatement : Statement @@ -302,6 +352,9 @@ Statement *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; struct SwitchStatement : Statement @@ -319,6 +372,9 @@ int hasBreak(); int usesEH(); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *inlineScan(InlineScanState *iss); @@ -339,6 +395,9 @@ int usesEH(); int fallOffEnd(); int comeFrom(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *inlineScan(InlineScanState *iss); @@ -355,6 +414,9 @@ int usesEH(); int fallOffEnd(); int comeFrom(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *inlineScan(InlineScanState *iss); @@ -369,6 +431,9 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void toIR(IRState *irs); }; @@ -382,6 +447,9 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void toIR(IRState *irs); }; @@ -390,6 +458,9 @@ { SwitchErrorStatement(Loc loc); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void toIR(IRState *irs); }; @@ -401,6 +472,9 @@ ReturnStatement(Loc loc, Expression *exp); Statement *syntaxCopy(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *semantic(Scope *sc); int fallOffEnd(); @@ -421,6 +495,9 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void toIR(IRState *irs); }; @@ -433,6 +510,9 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void toIR(IRState *irs); }; @@ -449,6 +529,9 @@ int hasContinue(); int usesEH(); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *inlineScan(InlineScanState *iss); @@ -468,6 +551,9 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif int usesEH(); int fallOffEnd(); @@ -491,6 +577,10 @@ Statement *inlineScan(InlineScanState *iss); void toIR(IRState *irs); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); + TryCatchStatement *isTryCatchStatement() { return this; } +#endif }; struct Catch : Object @@ -504,6 +594,9 @@ Catch(Loc loc, Type *t, Identifier *id, Statement *handler); Catch *syntaxCopy(); void semantic(Scope *sc); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; struct TryFinallyStatement : Statement @@ -514,6 +607,9 @@ TryFinallyStatement(Loc loc, Statement *body, Statement *finalbody); Statement *syntaxCopy(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *semantic(Scope *sc); int hasBreak(); int hasContinue(); @@ -533,6 +629,9 @@ Statement *syntaxCopy(); Statement *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif int fallOffEnd(); Statement *inlineScan(InlineScanState *iss); @@ -549,6 +648,9 @@ Statement *semantic(Scope *sc); Array *flatten(); int fallOffEnd(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *inlineScan(InlineScanState *iss); @@ -567,6 +669,10 @@ int fallOffEnd(); void toIR(IRState *irs); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); + GotoStatement *isGotoStatement() { return this; } +#endif }; struct LabelStatement : Statement @@ -584,6 +690,9 @@ int usesEH(); int fallOffEnd(); int comeFrom(); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Statement *inlineScan(InlineScanState *iss); @@ -613,6 +722,10 @@ int comeFrom(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); + virtual AsmStatement *isAsmStatement() { return this; } +#endif void toIR(IRState *irs); }; diff -uNr dmd-0.140/dmd/src/dmd/staticassert.h dmd-0.141/dmd/src/dmd/staticassert.h --- dmd-0.140/dmd/src/dmd/staticassert.h 2005-05-12 17:43:18.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/staticassert.h 2005-11-26 22:16:58.000000000 +0100 @@ -17,6 +17,9 @@ #include "dsymbol.h" struct Expression; +#ifdef _DH +struct HdrGenState; +#endif struct StaticAssert : Dsymbol { @@ -32,6 +35,9 @@ void toObjFile(); char *kind(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif }; #endif diff -uNr dmd-0.140/dmd/src/dmd/template.c dmd-0.141/dmd/src/dmd/template.c --- dmd-0.140/dmd/src/dmd/template.c 2005-11-20 23:24:52.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/template.c 2005-12-01 20:48:10.000000000 +0100 @@ -1539,6 +1539,7 @@ void TemplateInstance::semanticTiargs(Scope *sc) { // Run semantic on each argument, place results in tiargs[] + //printf("TemplateInstance::semanticTiargs()\n"); for (int j = 0; j < tiargs->dim; j++) { Type *ta = isType((Object *)tiargs->data[j]); Expression *ea; @@ -1549,7 +1550,11 @@ // It might really be an Expression or an Alias ta->resolve(loc, sc, &ea, &ta, &sa); if (ea) + { + ea = ea->semantic(sc); + ea = ea->constFold(); tiargs->data[j] = ea; + } else if (sa) tiargs->data[j] = sa; else if (ta) diff -uNr dmd-0.140/dmd/src/dmd/template.h dmd-0.141/dmd/src/dmd/template.h --- dmd-0.140/dmd/src/dmd/template.h 2005-09-19 10:29:16.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/template.h 2005-12-01 00:45:34.000000000 +0100 @@ -29,6 +29,9 @@ struct Expression; struct AliasDeclaration; enum MATCH; +#ifdef _DH +struct HdrGenState; +#endif struct TemplateDeclaration : ScopeDsymbol { @@ -46,6 +49,10 @@ void toCBuffer(OutBuffer *buf); 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); @@ -81,6 +88,9 @@ 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 Object *defaultArg(Scope *sc) = 0; /* If TemplateParameter's match as far as overloading goes. @@ -111,6 +121,9 @@ void semantic(Scope *); void print(Object *oarg, Object *oded); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Object *defaultArg(Scope *sc); int overloadMatch(TemplateParameter *); MATCH matchArg(Scope *sc, Object *oarg, int i, Array *parameters, Array *dedtypes, Declaration **psparam); @@ -136,6 +149,9 @@ void semantic(Scope *); void print(Object *oarg, Object *oded); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Object *defaultArg(Scope *sc); int overloadMatch(TemplateParameter *); MATCH matchArg(Scope *sc, Object *oarg, int i, Array *parameters, Array *dedtypes, Declaration **psparam); @@ -162,6 +178,9 @@ void semantic(Scope *); void print(Object *oarg, Object *oded); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif Object *defaultArg(Scope *sc); int overloadMatch(TemplateParameter *); MATCH matchArg(Scope *sc, Object *oarg, int i, Array *parameters, Array *dedtypes, Declaration **psparam); @@ -197,6 +216,10 @@ 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 @@ -224,6 +247,9 @@ char *kind(); Dsymbol *oneMember(); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif void toObjFile(); // compile to .obj file diff -uNr dmd-0.140/dmd/src/dmd/tocsym.c dmd-0.141/dmd/src/dmd/tocsym.c --- dmd-0.140/dmd/src/dmd/tocsym.c 2005-05-31 17:55:54.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/tocsym.c 2005-12-04 11:23:24.000000000 +0100 @@ -67,6 +67,7 @@ char *n; n = mangle(); //ident->toChars(); + assert(n); id = (char *) alloca(strlen(prefix) + strlen(n) + 1); sprintf(id,"%s%s", prefix, n); s = symbol_name(id, sclass, t); diff -uNr dmd-0.140/dmd/src/dmd/todt.c dmd-0.141/dmd/src/dmd/todt.c --- dmd-0.140/dmd/src/dmd/todt.c 2005-11-10 11:31:50.000000000 +0100 +++ dmd-0.141/dmd/src/dmd/todt.c 2005-11-27 11:36:34.000000000 +0100 @@ -448,6 +448,7 @@ dt_t **ComplexExp::toDt(dt_t **pdt) { + //printf("ComplexExp::toDt() '%s'\n", toChars()); d_float32 fvalue; d_float64 dvalue; d_float80 evalue; @@ -473,8 +474,8 @@ pdt = dtnbytes(pdt,REALSIZE - REALPAD,(char *)&evalue); pdt = dtnbytes(pdt,REALPAD,zeropad); evalue = cimagl(value); - pdt = dtnbytes(pdt,REALSIZE,(char *)&evalue); - pdt = dtnbytes(pdt,REALSIZE - REALPAD,zeropad); + pdt = dtnbytes(pdt,REALSIZE - REALPAD,(char *)&evalue); + pdt = dtnbytes(pdt,REALPAD,zeropad); break; default: diff -uNr dmd-0.140/dmd/src/dmd/version.c dmd-0.141/dmd/src/dmd/version.c --- dmd-0.140/dmd/src/dmd/version.c 2005-09-13 21:41:04.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/version.c 2005-11-26 22:29:52.000000000 +0100 @@ -8,6 +8,7 @@ // See the included readme.txt for details. #include +#include #include "root.h" diff -uNr dmd-0.140/dmd/src/dmd/version.h dmd-0.141/dmd/src/dmd/version.h --- dmd-0.140/dmd/src/dmd/version.h 2005-05-12 17:43:18.000000000 +0200 +++ dmd-0.141/dmd/src/dmd/version.h 2005-11-26 22:18:02.000000000 +0100 @@ -29,6 +29,9 @@ void addMember(Scope *sc, ScopeDsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif char *kind(); }; @@ -43,6 +46,9 @@ void addMember(Scope *sc, ScopeDsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf); +#ifdef _DH + void toHBuffer(OutBuffer *buf, HdrGenState *hgs); +#endif char *kind(); }; diff -uNr dmd-0.140/dmd/src/phobos/internal/gc/gc.d dmd-0.141/dmd/src/phobos/internal/gc/gc.d --- dmd-0.140/dmd/src/phobos/internal/gc/gc.d 2005-11-24 17:12:56.000000000 +0100 +++ dmd-0.141/dmd/src/phobos/internal/gc/gc.d 2005-12-04 20:50:20.000000000 +0100 @@ -1,6 +1,6 @@ /* - * Copyright (C) 2004 by Digital Mars, www.digitalmars.com + * Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com * Written by Walter Bright * * This software is provided 'as-is', without any express or implied @@ -193,7 +193,7 @@ } } -ulong _d_new(uint length, uint size) +ulong _d_new(size_t length, size_t size) { void *p; ulong result; @@ -211,7 +211,7 @@ return result; } -ulong _d_newarrayi(uint length, uint size, ...) +ulong _d_newarrayi(size_t length, size_t size, ...) { void *p; ulong result; @@ -223,7 +223,7 @@ { //void* q = cast(void*)(&size + 1); // pointer to initializer va_list q; - va_start!(uint)(q, size); // q is pointer to ... initializer + va_start!(size_t)(q, size); // q is pointer to ... initializer p = _gc.malloc(length * size + 1); debug(PRINTF) printf(" p = %p\n", p); if (size == 1) @@ -241,7 +241,7 @@ return result; } -ulong _d_newbitarray(uint length, bit value) +ulong _d_newbitarray(size_t length, bit value) { void *p; ulong result; @@ -250,7 +250,7 @@ if (length == 0) result = 0; else - { uint size = (length + 8) >> 3; // number of bytes + { size_t size = (length + 8) >> 3; // number of bytes ubyte fill = value ? 0xFF : 0; p = _gc.malloc(size); @@ -263,7 +263,7 @@ struct Array { - uint length; + size_t length; byte *data; }; @@ -342,10 +342,15 @@ */ extern (C) -byte[] _d_arraysetlength(uint newlength, uint sizeelem, Array *p) +byte[] _d_arraysetlength(size_t newlength, size_t sizeelem, Array *p) +in +{ + assert(sizeelem); + assert(!p.length || p.data); +} +body { byte* newdata; - uint newsize; debug(PRINTF) { @@ -354,18 +359,37 @@ printf("\tp.data = %p, p.length = %d\n", p.data, p.length); } - assert(sizeelem); - assert(!p.length || p.data); if (newlength) { - newsize = sizeelem * newlength; - if (p.length) - { uint size = p.length * sizeelem; + version (D_InlineAsm_X86) + { + size_t newsize = void; + + asm + { + mov EAX,newlength ; + mul EAX,sizeelem ; + mov newsize,EAX ; + jc Loverflow ; + } + } + else + { + size_t newsize = sizeelem * newlength; + + if (newsize / newlength != sizeelem) + goto Loverflow; + } + //printf("newsize = %x, newlength = %x\n", newsize, newlength); + if (p.length) + { newdata = p.data; - if (newsize > size) + if (newlength > p.length) { - uint cap = _gc.capacity(p.data); + size_t size = p.length * sizeelem; + size_t cap = _gc.capacity(p.data); + if (cap <= newsize) { newdata = cast(byte *)_gc.malloc(newsize + 1); @@ -387,6 +411,9 @@ p.data = newdata; p.length = newlength; return newdata[0 .. newlength]; + +Loverflow: + _d_OutOfMemory(); } /*************************** @@ -394,10 +421,10 @@ */ extern (C) -bit[] _d_arraysetlengthb(uint newlength, Array *p) +bit[] _d_arraysetlengthb(size_t newlength, Array *p) { byte* newdata; - uint newsize; + size_t newsize; debug (PRINTF) printf("p = %p, newlength = %d\n", p, newlength); @@ -407,12 +434,12 @@ { newsize = ((newlength + 31) >> 5) * 4; // # bytes rounded up to uint if (p.length) - { uint size = ((p.length + 31) >> 5) * 4; + { size_t size = ((p.length + 31) >> 5) * 4; newdata = p.data; if (newsize > size) { - uint cap = _gc.capacity(p.data); + size_t cap = _gc.capacity(p.data); if (cap <= newsize) { newdata = cast(byte *)_gc.malloc(newsize + 1); @@ -442,16 +469,15 @@ */ extern (C) -long _d_arrayappend(Array *px, byte[] y, uint size) +long _d_arrayappend(Array *px, byte[] y, size_t size) { - uint cap = _gc.capacity(px.data); - uint length = px.length; - uint newlength = length + y.length; + size_t cap = _gc.capacity(px.data); + size_t length = px.length; + size_t newlength = length + y.length; if (newlength * size > cap) { byte* newdata; - //newdata = cast(byte *)_gc.malloc(newlength * size); newdata = cast(byte *)_gc.malloc(newCapacity(newlength, size) + 1); memcpy(newdata, px.data, length * size); px.data = newdata; @@ -465,10 +491,10 @@ long _d_arrayappendb(Array *px, bit[] y) { - uint cap = _gc.capacity(px.data); - uint length = px.length; - uint newlength = length + y.length; - uint newsize = (newlength + 7) / 8; + size_t cap = _gc.capacity(px.data); + size_t length = px.length; + size_t newlength = length + y.length; + size_t newsize = (newlength + 7) / 8; if (newsize > cap) { void* newdata; @@ -493,11 +519,11 @@ } -uint newCapacity(uint newlength, uint size) +size_t newCapacity(size_t newlength, size_t size) { version(none) { - uint newcap = newlength * size; + size_t newcap = newlength * size; } else { @@ -519,8 +545,8 @@ * - Perhaps most importantly, overall memory usage and stress on the GC * is decreased significantly for demanding environments. */ - uint newcap = newlength * size; - uint newext = 0; + size_t newcap = newlength * size; + size_t newext = 0; if (newcap > 4096) { @@ -528,22 +554,22 @@ // Redo above line using only integer math - int log2plus1(uint c) + static int log2plus1(size_t c) { int i; - if (c == 0) - i = -1; - else - for (i = 1; c >>= 1; i++) - { } - return i; + if (c == 0) + i = -1; + else + for (i = 1; c >>= 1; i++) + { } + return i; } long mult = 100 + (1000L * size) / (6 * log2plus1(newcap)); // testing shows 1.02 for large arrays is about the point of diminishing return if (mult < 102) mult = 102; - newext = cast(uint)((newcap * mult) / 100); + newext = cast(size_t)((newcap * mult) / 100); newext -= newext % size; //printf("mult: %2.2f, mult2: %2.2f, alloc: %2.2f\n",mult/100.0,mult2,newext / cast(double)size); } @@ -554,7 +580,7 @@ } extern (C) -byte[] _d_arrayappendc(inout byte[] x, in uint size, ...) +byte[] _d_arrayappendc(inout byte[] x, in size_t size, ...) { size_t cap = _gc.capacity(x); size_t length = x.length; @@ -578,23 +604,23 @@ *cast(size_t *)&x = newlength; (cast(byte *)x)[length * size .. newlength * size] = argp[0 .. size]; - assert((cast(uint)x.ptr & 15) == 0); + assert((cast(size_t)x.ptr & 15) == 0); assert(_gc.capacity(x.ptr) > x.length * size); return x; } extern (C) -byte[] _d_arraycat(byte[] x, byte[] y, uint size) +byte[] _d_arraycat(byte[] x, byte[] y, size_t size) out (result) { //printf("_d_arraycat(%d,%p ~ %d,%p size = %d => %d,%p)\n", x.length, x.ptr, y.length, y.ptr, size, result.length, result.ptr); assert(result.length == x.length + y.length); - for (uint i = 0; i < x.length * size; i++) + for (size_t i = 0; i < x.length * size; i++) assert((cast(byte*)result)[i] == (cast(byte*)x)[i]); - for (uint i = 0; i < y.length * size; i++) + for (size_t i = 0; i < y.length * size; i++) assert((cast(byte*)result)[x.length * size + i] == (cast(byte*)y)[i]); - uint cap = _gc.capacity(result.ptr); + size_t cap = _gc.capacity(result.ptr); assert(!cap || cap > result.length * size); } body diff -uNr dmd-0.140/dmd/src/phobos/linux.mak dmd-0.141/dmd/src/phobos/linux.mak --- dmd-0.140/dmd/src/phobos/linux.mak 2005-11-24 17:12:54.000000000 +0100 +++ dmd-0.141/dmd/src/phobos/linux.mak 2005-12-04 20:50:18.000000000 +0100 @@ -57,7 +57,7 @@ process.o syserror.o \ socket.o socketstream.o stdarg.o stdio.o format.o \ perf.o openrj.o uni.o trace.o boxer.o \ - demangle.o \ + demangle.o cover.o \ ti_wchar.o ti_uint.o ti_short.o ti_ushort.o \ ti_byte.o ti_ubyte.o ti_long.o ti_ulong.o ti_ptr.o \ ti_float.o ti_double.o ti_real.o ti_delegate.o \ @@ -100,7 +100,7 @@ std/regexp.d std/random.d std/stream.d std/process.d std/recls.d \ std/socket.d std/socketstream.d std/loader.d std/stdarg.d \ std/stdio.d std/format.d std/perf.d std/openrj.d std/uni.d \ - std/boxer.d std/cstream.d std/demangle.d + std/boxer.d std/cstream.d std/demangle.d std/cover.d SRC_STD_C= std/c/process.d std/c/stdlib.d std/c/time.d std/c/stdio.d \ std/c/math.d std/c/stdarg.d std/c/stddef.d @@ -482,6 +482,9 @@ conv.o : std/conv.d $(DMD) -c $(DFLAGS) std/conv.d +cover.o : std/cover.d + $(DMD) -c $(DFLAGS) std/cover.d + cstream.o : std/cstream.d $(DMD) -c $(DFLAGS) std/cstream.d diff -uNr dmd-0.140/dmd/src/phobos/std/cover.d dmd-0.141/dmd/src/phobos/std/cover.d --- dmd-0.140/dmd/src/phobos/std/cover.d 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.141/dmd/src/phobos/std/cover.d 2005-12-04 20:50:18.000000000 +0100 @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2005 by Digital Mars, www.digitalmars.com + * Written by Walter Bright + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, in both source and binary form, subject to the following + * restrictions: + * + * o The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * o Altered source versions must be plainly marked as such, and must not + * be misrepresented as being the original software. + * o This notice may not be removed or altered from any source + * distribution. + */ + +/** + * Code coverage analyzer. + * Bugs: + * $(UL + * $(LI the execution counters are 32 bits in size, and can overflow) + * $(LI inline asm statements are not counted) + * ) + */ + +module std.cover; + +private import std.stdio; +private import std.file; + +private +{ + struct Cover + { + char[] filename; + bit[] valid; + uint[] data; + } + + Cover[] gdata; + char[] srcpath; + char[] dstpath; + bit merge; +} + +/*********************************** + * Set path to where source files are located. + */ + +void setSourceDir(char[] pathname) +{ + srcpath = pathname; +} + +/*********************************** + * Set path to where listing files are to be written. + */ + +void setDestDir(char[] pathname) +{ + srcpath = pathname; +} + +/*********************************** + * Set merge mode. + * Params: + * flag = true means new data is summed with existing data in the + * listing file; false means a new listing file is always + * created. + */ + +void setMerge(bit flag) +{ + merge = flag; +} + +extern (C) void _d_cover_register(char[] filename, bit[] valid, uint[] data) +{ + //printf("_d_cover_register()\n"); + //printf("\tfilename = '%.*s'\n", filename); + + Cover c; + c.filename = filename; + c.valid = valid; + c.data = data; + + gdata ~= c; +} + +static ~this() +{ + //printf("cover.~this()\n"); + + foreach (Cover c; gdata) + { + //printf("filename = '%.*s'\n", c.filename); + + // Generate source file name + char[] srcfilename = std.path.join(srcpath, c.filename); + + char[] buf = cast(char[])std.file.read(srcfilename); + char[][] lines = std.string.splitlines(buf); + + // Generate listing file name + char[] lstfilename = std.path.addExt(std.path.getBaseName(c.filename), "lst"); + + if (merge && exists(lstfilename) && isfile(lstfilename)) + { + char[] lst = cast(char[])std.file.read(lstfilename); + char[][] lstlines = std.string.splitlines(lst); + + for (size_t i = 0; i < lstlines.length; i++) + { + if (i >= c.data.length) + break; + int count = 0; + foreach (char c; lstlines[i]) + { + switch (c) + { case ' ': + continue; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + count = count * 10 + c - '0'; + continue; + default: + break; + } + break; + } + //printf("[%d] %d\n", i, count); + c.data[i] += count; + } + } + + FILE *flst = std.c.stdio.fopen(lstfilename, "wb"); + if (!flst) + throw new std.file.FileException(lstfilename, "cannot open for write"); + + uint nno; + uint nyes; + + for (int i = 0; i < c.data.length; i++) + { + //printf("[%2d] = %u\n", i, c.data[i]); + if (i < lines.length) + { + uint n = c.data[i]; + char[] line = lines[i]; + line = std.string.expandtabs(line); + if (n == 0) + { + if (c.valid[i]) + { nno++; + fwritefln(flst, "0000000|%s", line); + } + else + fwritefln(flst, " |%s", line); + } + else + { nyes++; + fwritefln(flst, "%7s|%s", n, line); + } + } + } + + fwritefln(flst, "%s is %s%% covered", c.filename, (nyes * 100) / (nyes + nno)); + + std.c.stdio.fclose(flst); + } +} + diff -uNr dmd-0.140/dmd/src/phobos/std/math.d dmd-0.141/dmd/src/phobos/std/math.d --- dmd-0.140/dmd/src/phobos/std/math.d 2005-11-24 17:12:54.000000000 +0100 +++ dmd-0.141/dmd/src/phobos/std/math.d 2005-12-04 20:50:18.000000000 +0100 @@ -1612,7 +1612,7 @@ } body { - version (D_InlineAsm) + version (D_InlineAsm_X86) { asm // assembler by W. Bright { diff -uNr dmd-0.140/dmd/src/phobos/std/string.d dmd-0.141/dmd/src/phobos/std/string.d --- dmd-0.140/dmd/src/phobos/std/string.d 2005-11-24 17:12:54.000000000 +0100 +++ dmd-0.141/dmd/src/phobos/std/string.d 2005-12-04 20:50:18.000000000 +0100 @@ -90,8 +90,9 @@ int iswhite(dchar c) { - return (c <= 0x7F) ? find(whitespace, c) != -1 - : (c == PS || c == LS); + return (c <= 0x7F) + ? find(whitespace, c) != -1 + : (c == PS || c == LS); } /********************************* diff -uNr dmd-0.140/dmd/src/phobos/std/system.d dmd-0.141/dmd/src/phobos/std/system.d --- dmd-0.140/dmd/src/phobos/std/system.d 2005-11-24 17:12:54.000000000 +0100 +++ dmd-0.141/dmd/src/phobos/std/system.d 2005-12-04 20:50:18.000000000 +0100 @@ -36,8 +36,10 @@ { Windows95 = 1, Windows98, + WindowsME, WindowsNT, Windows2000, + WindowsXP, RedHatLinux, } @@ -58,7 +60,7 @@ // The rest should get filled in dynamically at runtime -OS os = OS.WindowsNT; +OS os = OS.WindowsXP; // Operating system version as in // os_major.os_minor diff -uNr dmd-0.140/dmd/src/phobos/std/uri.d dmd-0.141/dmd/src/phobos/std/uri.d --- dmd-0.140/dmd/src/phobos/std/uri.d 2005-11-24 17:12:54.000000000 +0100 +++ dmd-0.141/dmd/src/phobos/std/uri.d 2005-12-04 20:50:18.000000000 +0100 @@ -21,6 +21,18 @@ * distribution. */ +/************************* + * Encode and decode Uniform Resource Identifiers (URIs). + * URIs are used in internet transfer protocols. + * Valid URI characters consist of letters, digits, + * and the characters ;/?:@&=+$,-_.!~*'(). Escape sequences consist of '%' + * followed by two hex digits. + * + * See_Also: + * $(LINK2 http://www.ietf.org/rfc/rfc3986.txt, RFC 3986)
+ * $(LINK2 http://en.wikipedia.org/wiki/Uniform_resource_identifier, Wikipedia) + */ + module std.uri; //debug=uri; // uncomment to turn on debugging printf's @@ -319,6 +331,12 @@ return null; } +/************************************* + * Decodes the URI string encodedURI into a UTF-8 string and returns it. Escape + * sequences that resolve to valid URI characters are not replaced. Escape + * sequences that resolve to the '#' character are not replaced. + */ + char[] decode(char[] encodedURI) { dchar[] s; @@ -327,6 +345,11 @@ return std.utf.toUTF8(s); } +/******************************* + * Decodes the URI string encodedURI into a UTF-8 string and returns it. All + * escape sequences are decoded. + */ + char[] decodeComponent(char[] encodedURIComponent) { dchar[] s; @@ -335,6 +358,11 @@ return std.utf.toUTF8(s); } +/***************************** + * Encodes the UTF-8 string uri into a URI and returns that URI. Any character + * not a valid URI character is escaped. The '#' character is not escaped. + */ + char[] encode(char[] uri) { dchar[] s; @@ -343,6 +371,11 @@ return URI_Encode(s, URI_Reserved | URI_Hash | URI_Alpha | URI_Digit | URI_Mark); } +/******************************** + * Encodes the UTF-8 string uriComponent into a URI and returns that URI. + * Any character not a letter, digit, or one of -_.!~*'() is escaped. + */ + char[] encodeComponent(char[] uriComponent) { dchar[] s; diff -uNr dmd-0.140/dmd/src/phobos/std/windows/charset.d dmd-0.141/dmd/src/phobos/std/windows/charset.d --- dmd-0.140/dmd/src/phobos/std/windows/charset.d 2005-11-24 17:12:56.000000000 +0100 +++ dmd-0.141/dmd/src/phobos/std/windows/charset.d 2005-12-04 20:50:20.000000000 +0100 @@ -83,7 +83,7 @@ * 0 - ANSI, * 1 - OEM, * 2 - Mac - * Authors: Steward Gordon, Walter Bright + * Authors: Stewart Gordon, Walter Bright */ char[] fromMBSz(char* s, int codePage = 0) diff -uNr dmd-0.140/dmd/src/phobos/std.ddoc dmd-0.141/dmd/src/phobos/std.ddoc --- dmd-0.140/dmd/src/phobos/std.ddoc 2005-11-24 17:12:54.000000000 +0100 +++ dmd-0.141/dmd/src/phobos/std.ddoc 2005-12-04 20:50:18.000000000 +0100 @@ -52,6 +52,7 @@  std.boxer
 std.compiler
 std.conv
std.cover
 std.ctype
 std.date
 std.demangle