1 // helper for mangling tests with back references 2 3 module imports.testmangle; 4 5 public import core.demangle : demangle, demangleType; 6 7 // detect mangle version 8 private 9 { 10 struct Detect; 11 Detect* detectMangle(Detect*); 12 void DetectTmpl(T)() {} 13 } 14 15 pragma(msg,detectMangle.mangleof); 16 static if(detectMangle.mangleof == "_D7imports10testmangle12detectMangleFPSQL3H6DetectZQ1e") 17 enum { BackRefs = true, BackRefSymbols = true } 18 else static if(detectMangle.mangleof == "_D7imports10testmangle12detectMangleFPSQBlQBg6DetectZQq") 19 enum { BackRefs = true, BackRefSymbols = false } 20 else static if(detectMangle.mangleof == "_D7imports10testmangle12detectMangleFPS7imports10testmangle6DetectZPS7imports10testmangle6Detect") 21 enum { BackRefs = false, BackRefSymbols = false } 22 else 23 static assert(false, "unknown mangling"); 24 25 private enum tmplMangle = (DetectTmpl!int).mangleof; 26 pragma(msg,tmplMangle); 27 static if(tmplMangle[0..40] == "_D7imports10testmangle__T10DetectTmplTiZ") 28 enum HasTemplateLength = false; 29 else static if(tmplMangle[0..42] == "_D7imports10testmangle18__T10DetectTmplTiZ") 30 enum HasTemplateLength = true; 31 else 32 static assert(false, "unknown mangling"); 33 34 pragma(msg,BackRefs); 35 pragma(msg,BackRefSymbols); 36 37 static if (BackRefs) 38 { 39 string tl(string s)() { return null; } 40 string id(string s, string r, string r2 = null)() { return BackRefSymbols && r2 !is null ? r2 : r; } 41 } 42 else 43 { 44 string tl(string s)() { return HasTemplateLength ? s : null; } 45 string id(string s, string r, string r2 = null)() { return s; } 46 } 47 48 bool equalDemangle(string m1, string m2) 49 { 50 auto dm1 = demangle(m1); 51 auto dm2 = demangle(m2); 52 return dm1 == dm2; 53 } 54 55 string unsignedToString(ulong x) 56 { 57 string s; 58 s ~= cast(char)('0' + (x % 10)); 59 x /= 10; 60 while (x > 0) 61 { 62 s = cast(char)('0' + (x % 10)) ~ s; 63 x /= 10; 64 } 65 return s; 66 }