Skip to content

Commit

Permalink
Merge pull request #3188 from Ingrater/cv8improve1
Browse files Browse the repository at this point in the history
Disambiguate type names for templates and arrays in cv8 debug symbols.
  • Loading branch information
WalterBright committed Jun 2, 2014
2 parents 276a693 + 342603a commit aef104e
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/declaration.h
Expand Up @@ -662,7 +662,7 @@ class FuncDeclaration : public Declaration
int getLevel(Loc loc, Scope *sc, FuncDeclaration *fd); // lexical nesting level difference
void appendExp(Expression *e);
void appendState(Statement *s);
const char *toPrettyChars();
const char *toPrettyChars(bool QualifyTypes = false);
const char *toFullSignature(); // for diagnostics, e.g. 'int foo(int x, int y) pure'
bool isMain();
bool isWinMain();
Expand Down Expand Up @@ -757,7 +757,7 @@ class FuncLiteralDeclaration : public FuncDeclaration

FuncLiteralDeclaration *isFuncLiteralDeclaration() { return this; }
const char *kind();
const char *toPrettyChars();
const char *toPrettyChars(bool QualifyTypes = false);
void accept(Visitor *v) { v->visit(this); }
};

Expand Down
3 changes: 2 additions & 1 deletion src/doc.c
Expand Up @@ -1306,7 +1306,8 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc)
if (ed->memtype)
{
buf->writestring(": $(DDOC_ENUM_BASETYPE ");
ed->memtype->toCBuffer(buf, NULL, NULL);
HdrGenState hgs;
ed->memtype->toCBuffer(buf, NULL, &hgs);
buf->writestring(")");
}
buf->writestring(";\n");
Expand Down
11 changes: 8 additions & 3 deletions src/dsymbol.c
Expand Up @@ -209,7 +209,12 @@ char *Dsymbol::toChars()
return ident ? ident->toChars() : (char *)"__anonymous";
}

const char *Dsymbol::toPrettyChars()
char *Dsymbol::toPrettyCharsHelper()
{
return toChars();
}

const char *Dsymbol::toPrettyChars(bool QualifyTypes)
{ Dsymbol *p;
char *s;
char *q;
Expand All @@ -221,14 +226,14 @@ const char *Dsymbol::toPrettyChars()

len = 0;
for (p = this; p; p = p->parent)
len += strlen(p->toChars()) + 1;
len += strlen(QualifyTypes ? p->toPrettyCharsHelper() : p->toChars()) + 1;

s = (char *)mem.malloc(len);
q = s + len - 1;
*q = 0;
for (p = this; p; p = p->parent)
{
char *t = p->toChars();
char *t = QualifyTypes ? p->toPrettyCharsHelper() : p->toChars();
len = strlen(t);
q -= len;
memcpy(q, t, len);
Expand Down
3 changes: 2 additions & 1 deletion src/dsymbol.h
Expand Up @@ -149,6 +149,7 @@ class Dsymbol : public RootObject
Dsymbol(Identifier *);
static Dsymbol *create(Identifier *);
char *toChars();
virtual char *toPrettyCharsHelper(); // helper to print fully qualified (template) arguments
Loc& getLoc();
char *locToChars();
bool equals(RootObject *o);
Expand All @@ -173,7 +174,7 @@ class Dsymbol : public RootObject
static Dsymbols *arraySyntaxCopy(Dsymbols *a);

virtual Identifier *getIdent();
virtual const char *toPrettyChars();
virtual const char *toPrettyChars(bool QualifyTypes = false);
virtual const char *kind();
virtual Dsymbol *toAlias(); // resolve real symbol
virtual int apply(Dsymbol_apply_ft_t fp, void *param);
Expand Down
10 changes: 5 additions & 5 deletions src/func.c
Expand Up @@ -3495,12 +3495,12 @@ void FuncDeclaration::appendState(Statement *s)
}
}

const char *FuncDeclaration::toPrettyChars()
const char *FuncDeclaration::toPrettyChars(bool QualifyTypes)
{
if (isMain())
return "D main";
else
return Dsymbol::toPrettyChars();
return Dsymbol::toPrettyChars(QualifyTypes);
}

/** for diagnostics, e.g. 'int foo(int x, int y) pure' */
Expand Down Expand Up @@ -4526,15 +4526,15 @@ void FuncLiteralDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
}
}

const char *FuncLiteralDeclaration::toPrettyChars()
const char *FuncLiteralDeclaration::toPrettyChars(bool QualifyTypes)
{
if (parent)
{
TemplateInstance *ti = parent->isTemplateInstance();
if (ti)
return ti->tempdecl->toPrettyChars();
return ti->tempdecl->toPrettyChars(QualifyTypes);
}
return Dsymbol::toPrettyChars();
return Dsymbol::toPrettyChars(QualifyTypes);
}

/********************************* CtorDeclaration ****************************/
Expand Down
8 changes: 4 additions & 4 deletions src/hdrgen.c
Expand Up @@ -942,18 +942,18 @@ class PrettyPrintVisitor : public Visitor
{
TemplateInstance *ti = t->sym->parent->isTemplateInstance();
if (ti && ti->toAlias() == t->sym)
buf->writestring(ti->toChars());
buf->writestring((hgs->fullQualification) ? ti->toPrettyChars() : ti->toChars());
else
buf->writestring(t->sym->toChars());
buf->writestring((hgs->fullQualification) ? t->sym->toPrettyChars() : t->sym->toChars());
}

void visit(TypeClass *t)
{
TemplateInstance *ti = t->sym->parent->isTemplateInstance();
if (ti && ti->toAlias() == t->sym)
buf->writestring(ti->toChars());
buf->writestring((hgs->fullQualification) ? ti->toPrettyChars() : ti->toChars());
else
buf->writestring(t->sym->toChars());
buf->writestring((hgs->fullQualification) ? t->sym->toPrettyChars() : t->sym->toChars());
}

void visit(TypeTuple *t)
Expand Down
1 change: 1 addition & 0 deletions src/hdrgen.h
Expand Up @@ -26,6 +26,7 @@ struct HdrGenState
int inArrExp;
int emitInst;
int autoMember;
bool fullQualification; // fully qualify types when printing

struct
{
Expand Down
11 changes: 11 additions & 0 deletions src/mtype.c
Expand Up @@ -1583,6 +1583,17 @@ char *Type::toChars()
return buf.extractString();
}

char *Type::toPrettyChars(bool QualifyTypes)
{
OutBuffer buf;
buf.reserve(16);
HdrGenState hgs;
hgs.fullQualification = QualifyTypes;

toCBuffer(&buf, NULL, &hgs);
return buf.extractString();
}

void Type::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs)
{
::toCBuffer(this, buf, ident, hgs);
Expand Down
1 change: 1 addition & 0 deletions src/mtype.h
Expand Up @@ -238,6 +238,7 @@ class Type : public RootObject
int dyncast() { return DYNCAST_TYPE; }
int covariant(Type *t, StorageClass *pstc = NULL);
char *toChars();
char *toPrettyChars(bool QualifyTypes = false);
static char needThisPrefix();
static void init();

Expand Down
10 changes: 10 additions & 0 deletions src/template.c
Expand Up @@ -7839,6 +7839,16 @@ char *TemplateInstance::toChars()
return s;
}

char *TemplateInstance::toPrettyCharsHelper()
{
OutBuffer buf;
HdrGenState hgs;
hgs.fullQualification = 1;
toCBuffer(&buf, &hgs);

return buf.extractString();
}

int TemplateInstance::compare(RootObject *o)
{
TemplateInstance *ti = (TemplateInstance *)o;
Expand Down
1 change: 1 addition & 0 deletions src/template.h
Expand Up @@ -344,6 +344,7 @@ class TemplateInstance : public ScopeDsymbol
const char *kind();
bool oneMember(Dsymbol **ps, Identifier *ident);
char *toChars();
char* toPrettyCharsHelper();
void printInstantiationTrace();
Identifier *getIdent();
int compare(RootObject *o);
Expand Down
4 changes: 2 additions & 2 deletions src/toctype.c
Expand Up @@ -54,7 +54,7 @@ class ToCtypeVisitor : public Visitor
void visit(TypeDArray *t)
{
t->ctype = type_dyn_array(Type_toCtype(t->next));
t->ctype->Tident = t->toChars(); // needed to generate sensible debug info for cv8
t->ctype->Tident = t->toPrettyChars(true);
}

void visit(TypeAArray *t)
Expand Down Expand Up @@ -136,7 +136,7 @@ class ToCtypeVisitor : public Visitor
else
{
StructDeclaration *sym = t->sym;
t->ctype = type_struct_class(sym->toPrettyChars(), sym->alignsize, sym->structsize,
t->ctype = type_struct_class(sym->toPrettyChars(true), sym->alignsize, sym->structsize,
sym->arg1type ? Type_toCtype(sym->arg1type) : NULL,
sym->arg2type ? Type_toCtype(sym->arg2type) : NULL,
sym->isUnionDeclaration() != 0,
Expand Down
8 changes: 4 additions & 4 deletions src/tocvdebug.c
Expand Up @@ -299,7 +299,7 @@ void toDebug(TypedefDeclaration *tdd)
if (tdd->basetype->ty == Ttuple)
return;

const char *id = tdd->toPrettyChars();
const char *id = tdd->toPrettyChars(true);
idx_t typidx = cv4_typidx(Type_toCtype(tdd->basetype));
if (config.fulltypes == CV8)
cv8_udt(id, typidx);
Expand Down Expand Up @@ -331,7 +331,7 @@ void toDebug(EnumDeclaration *ed)
// If it is a member, it is handled by cvMember()
if (!ed->isMember())
{
const char *id = ed->toPrettyChars();
const char *id = ed->toPrettyChars(true);
idx_t typidx = cv4_Denum(ed);
if (config.fulltypes == CV8)
cv8_udt(id, typidx);
Expand Down Expand Up @@ -416,7 +416,7 @@ void toDebug(StructDeclaration *sd)
// if (st->Sopeq && !(st->Sopeq->Sfunc->Fflags & Fnodebug))
// property |= 0x20; // class has overloaded assignment

const char *id = sd->toPrettyChars();
const char *id = sd->toPrettyChars(true);

unsigned leaf = sd->isUnionDeclaration() ? LF_UNION : LF_STRUCTURE;
if (config.fulltypes == CV8)
Expand Down Expand Up @@ -581,7 +581,7 @@ void toDebug(ClassDeclaration *cd)
// if (st->Sopeq && !(st->Sopeq->Sfunc->Fflags & Fnodebug))
// property |= 0x20; // class has overloaded assignment

const char *id = cd->isCPPinterface() ? cd->ident->toChars() : cd->toPrettyChars();
const char *id = cd->isCPPinterface() ? cd->ident->toChars() : cd->toPrettyChars(true);
unsigned leaf = config.fulltypes == CV8 ? LF_CLASS_V3 : LF_CLASS;

unsigned numidx = (leaf == LF_CLASS_V3) ? 18 : 12;
Expand Down

0 comments on commit aef104e

Please sign in to comment.