From 83f1938b840be6f26ade84a0dde714e0f21960fe Mon Sep 17 00:00:00 2001 From: UplinkCoder Date: Wed, 8 Jun 2016 14:47:12 +0200 Subject: [PATCH 1/6] first commit of back-refernce mangle --- src/dmangle.d | 67 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/src/dmangle.d b/src/dmangle.d index 44c2734bee2d..cfac415c1f10 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,7 +165,10 @@ extern (C++) final class Mangler : Visitor alias visit = super.visit; public: OutBuffer* buf; - + uint[TypeIdentifier] ftpos; /// offset of the first mangle of this type + uint[DSymbol] fspos; /// offset of the first mangle of this symbol + uint[DSymbol] fppos; /// offset of the first mangle of this parent + extern (D) this(OutBuffer* buf) { this.buf = 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) @@ -381,16 +392,25 @@ public: 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 (auto n = p in fppos) + { + buf.printf("Q%d",n); + } + else + { + fppos[p] = buf.offset; + 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'); + } } } @@ -626,10 +646,17 @@ 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 (auto n = s in fspos) { + buffer.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); + } } //////////////////////////////////////////////////////////////////////////// From f8387649fc3896360c1357b98075532565287d18 Mon Sep 17 00:00:00 2001 From: UplinkCoder Date: Wed, 8 Jun 2016 16:12:45 +0200 Subject: [PATCH 2/6] oops --- src/dmangle.d | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dmangle.d b/src/dmangle.d index cfac415c1f10..75b55ce21d6f 100644 --- a/src/dmangle.d +++ b/src/dmangle.d @@ -166,8 +166,8 @@ extern (C++) final class Mangler : Visitor public: OutBuffer* buf; uint[TypeIdentifier] ftpos; /// offset of the first mangle of this type - uint[DSymbol] fspos; /// offset of the first mangle of this symbol - uint[DSymbol] fppos; /// offset of the first mangle of this parent + uint[Dsymbol] fspos; /// offset of the first mangle of this symbol + uint[Dsymbol] fppos; /// offset of the first mangle of this parent extern (D) this(OutBuffer* buf) { @@ -314,7 +314,7 @@ public: { if (auto n = t in ftpos) { - buf.printf("Q%d", n); + buf.printf("Q%d", *n); } else { @@ -395,7 +395,7 @@ public: if (auto n = p in fppos) { - buf.printf("Q%d",n); + buf.printf("Q%d", *n); } else { @@ -648,7 +648,7 @@ public: } if (auto n = s in fspos) { - buffer.printf("Q%d", n); + buffer.printf("Q%d", *n); } else { From 1062d5a46832565668923b3766290c10d1fab40d Mon Sep 17 00:00:00 2001 From: UplinkCoder Date: Wed, 8 Jun 2016 16:18:31 +0200 Subject: [PATCH 3/6] use detab --- src/dmangle.d | 82 +++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/dmangle.d b/src/dmangle.d index 75b55ce21d6f..b4456e64708a 100644 --- a/src/dmangle.d +++ b/src/dmangle.d @@ -165,10 +165,10 @@ extern (C++) final class Mangler : Visitor alias visit = super.visit; public: OutBuffer* buf; - uint[TypeIdentifier] ftpos; /// offset of the first mangle of this type - uint[Dsymbol] fspos; /// offset of the first mangle of this symbol - uint[Dsymbol] fppos; /// offset of the first mangle of this parent - + uint[TypeIdentifier] ftpos; /// offset of the first mangle of this type + uint[Dsymbol] fspos; /// offset of the first mangle of this symbol + uint[Dsymbol] fppos; /// offset of the first mangle of this parent + extern (D) this(OutBuffer* buf) { this.buf = buf; @@ -312,18 +312,18 @@ public: override void visit(TypeIdentifier t) { - if (auto n = t in ftpos) - { - buf.printf("Q%d", *n); - } - else - { + 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) @@ -392,25 +392,25 @@ public: p = s.parent; if (p) { - - if (auto n = p in fppos) - { - buf.printf("Q%d", *n); - } - else - { - fppos[p] = buf.offset; - 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 (auto n = p in fppos) + { + buf.printf("Q%d", *n); + } + else + { + fppos[p] = buf.offset; + 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'); + } } } @@ -646,17 +646,17 @@ public: printf(" parent = %s %s", s.parent.kind(), s.parent.toChars()); printf("\n"); } - - if (auto n = s in fspos) { - buffer.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); - } + + if (auto n = s in fspos) { + buffer.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); + } } //////////////////////////////////////////////////////////////////////////// From 86236f6d2aed77849094eddb029dcb7300e13c84 Mon Sep 17 00:00:00 2001 From: UplinkCoder Date: Wed, 8 Jun 2016 16:32:17 +0200 Subject: [PATCH 4/6] fixing --- src/dmangle.d | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/dmangle.d b/src/dmangle.d index b4456e64708a..5a3051000ee5 100644 --- a/src/dmangle.d +++ b/src/dmangle.d @@ -165,9 +165,9 @@ extern (C++) final class Mangler : Visitor alias visit = super.visit; public: OutBuffer* buf; - uint[TypeIdentifier] ftpos; /// offset of the first mangle of this type - uint[Dsymbol] fspos; /// offset of the first mangle of this symbol - uint[Dsymbol] fppos; /// offset of the first mangle of this parent + 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) { @@ -647,16 +647,17 @@ public: printf("\n"); } - if (auto n = s in fspos) { - buffer.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); - } + 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; + } } //////////////////////////////////////////////////////////////////////////// From ae1a01d04fb3163076a1e7ebdcf062ddc835c097 Mon Sep 17 00:00:00 2001 From: UplinkCoder Date: Thu, 9 Jun 2016 06:46:49 +0200 Subject: [PATCH 5/6] maybe like this --- src/dmangle.d | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/dmangle.d b/src/dmangle.d index 5a3051000ee5..3005eefd4647 100644 --- a/src/dmangle.d +++ b/src/dmangle.d @@ -395,21 +395,21 @@ public: if (auto n = p in fppos) { - buf.printf("Q%d", *n); + buf.printf("Q%d", *n); } else { - fppos[p] = buf.offset; - 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'); + 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'); } } } @@ -646,7 +646,8 @@ public: printf(" parent = %s %s", s.parent.kind(), s.parent.toChars()); printf("\n"); } - + if (s) + { if (auto n = s in fspos) { buf.printf("Q%d", *n); } @@ -656,8 +657,9 @@ public: 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; + fspos[s] = buf.offset; } + } } //////////////////////////////////////////////////////////////////////////// From 240ce8a26ea223f51d2fff3a0eb78b26b8755a02 Mon Sep 17 00:00:00 2001 From: UplinkCoder Date: Thu, 9 Jun 2016 06:51:48 +0200 Subject: [PATCH 6/6] maybe like this --- src/dmangle.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dmangle.d b/src/dmangle.d index 3005eefd4647..79106afb0540 100644 --- a/src/dmangle.d +++ b/src/dmangle.d @@ -390,7 +390,7 @@ public: p = ti.isTemplateMixin() ? ti.parent : ti.tempdecl.parent; else p = s.parent; - if (p) + if (p && s) { if (auto n = p in fppos)