diff --git a/src/attrib.c b/src/attrib.c index 03a6144282f4..20db0f19c704 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -47,6 +47,24 @@ Dsymbols *AttribDeclaration::include(Scope *sc, ScopeDsymbol *sd) return decl; } +int AttribDeclaration::apply(Dsymbol_apply_ft_t fp, void *param) +{ + Dsymbols *d = include(NULL, NULL); + + if (d) + { + for (size_t i = 0; i < d->dim; i++) + { Dsymbol *s = (*d)[i]; + if (s) + { + if (s->apply(fp, param)) + return 1; + } + } + } + return 0; +} + int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) { int m = 0; @@ -246,6 +264,7 @@ void AttribDeclaration::toObjFile(int multiobj) int AttribDeclaration::cvMember(unsigned char *p) { + assert(0); int nwritten = 0; int n; Dsymbols *d = include(NULL, NULL); diff --git a/src/attrib.h b/src/attrib.h index ab04c075ee78..2f854eb2a2d3 100644 --- a/src/attrib.h +++ b/src/attrib.h @@ -1,6 +1,6 @@ // Compiler implementation of the D programming language -// Copyright (c) 1999-2011 by Digital Mars +// Copyright (c) 1999-2012 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com @@ -33,6 +33,7 @@ struct AttribDeclaration : Dsymbol AttribDeclaration(Dsymbols *decl); virtual Dsymbols *include(Scope *sc, ScopeDsymbol *s); + int apply(Dsymbol_apply_ft_t fp, void *param); int addMember(Scope *sc, ScopeDsymbol *s, int memnum); void setScopeNewSc(Scope *sc, StorageClass newstc, enum LINK linkage, enum PROT protection, int explictProtection, diff --git a/src/dsymbol.c b/src/dsymbol.c index c05423f75965..88d51870bed1 100644 --- a/src/dsymbol.c +++ b/src/dsymbol.c @@ -558,6 +558,11 @@ int Dsymbol::needThis() return FALSE; } +int Dsymbol::apply(Dsymbol_apply_ft_t fp, void *param) +{ + return (*fp)(this, param); +} + int Dsymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) { //printf("Dsymbol::addMember('%s')\n", toChars()); diff --git a/src/dsymbol.h b/src/dsymbol.h index f76d04bb76d3..7e03f90e2df0 100644 --- a/src/dsymbol.h +++ b/src/dsymbol.h @@ -109,6 +109,8 @@ enum PASS PASSobj, // toObjFile() run }; +typedef int (*Dsymbol_apply_ft_t)(Dsymbol *, void *); + struct Dsymbol : Object { Identifier *ident; @@ -146,6 +148,7 @@ struct Dsymbol : Object virtual const char *toPrettyChars(); virtual const char *kind(); virtual Dsymbol *toAlias(); // resolve real symbol + virtual int apply(Dsymbol_apply_ft_t fp, void *param); virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); virtual void setScope(Scope *sc); virtual void importAll(Scope *sc); diff --git a/src/tocvdebug.c b/src/tocvdebug.c index e54bfeb018a1..2a6627c7a2c6 100644 --- a/src/tocvdebug.c +++ b/src/tocvdebug.c @@ -1,5 +1,5 @@ -// Copyright (c) 2004-2011 by Digital Mars +// Copyright (c) 2004-2012 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com @@ -281,6 +281,34 @@ void EnumDeclaration::toDebug() } } +// Closure variables for Lambda cv_mem_count +struct CvMemberCount +{ + unsigned nfields; + unsigned fnamelen; +}; + +// Lambda function +int cv_mem_count(Dsymbol *s, void *param) +{ CvMemberCount *pmc = (CvMemberCount *)param; + + int nwritten = s->cvMember(NULL); + if (nwritten) + { + pmc->fnamelen += nwritten; + pmc->nfields++; + } + return 0; +} + +// Lambda function +int cv_mem_p(Dsymbol *s, void *param) +{ + unsigned char **pp = (unsigned char **)param; + *pp += s->cvMember(*pp); + return 0; +} + void StructDeclaration::toDebug() { @@ -354,24 +382,18 @@ void StructDeclaration::toDebug() return /*typidx*/; } - // Compute the number of fields, and the length of the fieldlist record - nfields = 0; - fnamelen = 2; - - count = nfields; + // Compute the number of fields (nfields), and the length of the fieldlist record (fnamelen) + CvMemberCount mc; + mc.nfields = 0; + mc.fnamelen = 2; for (size_t i = 0; i < members->dim; i++) - { Dsymbol *s = members->tdata()[i]; - int nwritten; - - nwritten = s->cvMember(NULL); - if (nwritten) - { - fnamelen += nwritten; - nfields++; - count++; - } + { Dsymbol *s = (*members)[i]; + s->apply(&cv_mem_count, &mc); } + nfields = mc.nfields; + fnamelen = mc.fnamelen; + count = nfields; TOWORD(d->data + 2,count); TOWORD(d->data + 6,property); @@ -383,9 +405,8 @@ void StructDeclaration::toDebug() TOWORD(p,LF_FIELDLIST); p += 2; for (size_t i = 0; i < members->dim; i++) - { Dsymbol *s = members->tdata()[i]; - - p += s->cvMember(p); + { Dsymbol *s = (*members)[i]; + s->apply(&cv_mem_p, &p); } //dbg_printf("fnamelen = %d, p-dt->data = %d\n",fnamelen,p-dt->data); @@ -516,32 +537,25 @@ void ClassDeclaration::toDebug() return /*typidx*/; } - // Compute the number of fields, and the length of the fieldlist record - nfields = 0; - fnamelen = 2; - + // Compute the number of fields (nfields), and the length of the fieldlist record (fnamelen) + CvMemberCount mc; + mc.nfields = 0; + mc.fnamelen = 2; // Add in base classes for (size_t i = 0; i < baseclasses->dim; i++) - { BaseClass *bc = baseclasses->tdata()[i]; + { BaseClass *bc = (*baseclasses)[i]; - nfields++; - fnamelen += 6 + cv4_numericbytes(bc->offset); + mc.nfields++; + mc.fnamelen += 6 + cv4_numericbytes(bc->offset); } - - count = nfields; for (size_t i = 0; i < members->dim; i++) - { Dsymbol *s = members->tdata()[i]; - int nwritten; - - nwritten = s->cvMember(NULL); - if (nwritten) - { - fnamelen += nwritten; - nfields++; - count++; - } + { Dsymbol *s = (*members)[i]; + s->apply(&cv_mem_count, &mc); } + nfields = mc.nfields; + fnamelen = mc.fnamelen; + count = nfields; TOWORD(d->data + 2,count); TOWORD(d->data + 6,property); @@ -555,7 +569,7 @@ void ClassDeclaration::toDebug() // Add in base classes for (size_t i = 0; i < baseclasses->dim; i++) - { BaseClass *bc = baseclasses->tdata()[i]; + { BaseClass *bc = (*baseclasses)[i]; idx_t typidx; unsigned attribute; @@ -572,12 +586,9 @@ void ClassDeclaration::toDebug() p += cv4_numericbytes(bc->offset); } - - for (size_t i = 0; i < members->dim; i++) - { Dsymbol *s = members->tdata()[i]; - - p += s->cvMember(p); + { Dsymbol *s = (*members)[i]; + s->apply(&cv_mem_p, &p); } //dbg_printf("fnamelen = %d, p-dt->data = %d\n",fnamelen,p-dt->data);