diff --git a/src/dmangle.d b/src/dmangle.d index 44c2734bee2d..79106afb0540 100644 --- a/src/dmangle.d +++ b/src/dmangle.d @@ -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 @@ -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) { @@ -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) @@ -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'); + } } } @@ -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; + } + } } ////////////////////////////////////////////////////////////////////////////