Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 51 additions & 21 deletions src/dmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private immutable char[TMAX] mangleChar =
// N // Nh:vector Ng:wild
// O // shared
Tpointer : 'P',
// Q
// Q // LookHere
Treference : 'R',
Tstruct : 'S',
// T // Ttypedef
Expand Down Expand Up @@ -165,6 +165,9 @@ extern (C++) final class Mangler : Visitor
alias visit = super.visit;
public:
OutBuffer* buf;
size_t[TypeIdentifier] ftpos; /// offset of the first mangle of this type
size_t[Dsymbol] fspos; /// offset of the first mangle of this symbol
size_t[Dsymbol] fppos; /// offset of the first mangle of this parent

extern (D) this(OutBuffer* buf)
{
Expand Down Expand Up @@ -309,10 +312,18 @@ public:

override void visit(TypeIdentifier t)
{
visit(cast(Type)t);
const(char)* name = t.ident.toChars();
size_t len = strlen(name);
buf.printf("%u%s", cast(uint)len, name);
if (auto n = t in ftpos)
{
buf.printf("Q%d", *n);
}
else
{
ftpos[t] = buf.offset;
visit(cast(Type)t);
const(char)* name = t.ident.toChars();
size_t len = strlen(name);
buf.printf("%u%s", cast(uint)len, name);
}
}

override void visit(TypeEnum t)
Expand Down Expand Up @@ -379,18 +390,27 @@ public:
p = ti.isTemplateMixin() ? ti.parent : ti.tempdecl.parent;
else
p = s.parent;
if (p)
{
mangleParent(p);
if (p.getIdent())
{
const(char)* id = p.ident.toChars();
toBuffer(id, s);
if (FuncDeclaration f = p.isFuncDeclaration())
mangleFunc(f, true);
}
else
buf.writeByte('0');
if (p && s)
{

if (auto n = p in fppos)
{
buf.printf("Q%d", *n);
}
else
{
mangleParent(p);
fppos[p] = buf.offset;
if (p.getIdent())
{
const(char)* id = p.ident.toChars();
toBuffer(id, s);
if (FuncDeclaration f = p.isFuncDeclaration())
mangleFunc(f, true);
}
else
buf.writeByte('0');
}
}
}

Expand Down Expand Up @@ -626,10 +646,20 @@ public:
printf(" parent = %s %s", s.parent.kind(), s.parent.toChars());
printf("\n");
}
mangleParent(s);
auto id = s.ident ? s.ident.toChars() : s.toChars();
toBuffer(id, s);
//printf("Dsymbol.mangle() %s = %s\n", s.toChars(), id);
if (s)
{
if (auto n = s in fspos) {
buf.printf("Q%d", *n);
}
else
{
mangleParent(s);
auto id = s.ident ? s.ident.toChars() : s.toChars();
toBuffer(id, s);
//printf("Dsymbol.mangle() %s = %s\n", s.toChars(), id);
fspos[s] = buf.offset;
}
}
}

////////////////////////////////////////////////////////////////////////////
Expand Down