| 1 |
module imports.issue18919b; |
| 2 |
|
| 3 |
import core.stdc.stdio; |
| 4 |
|
| 5 |
// Remove directories from paths. Used to make the output platform-independent. |
| 6 |
string baseName(string path) |
| 7 |
{ |
| 8 |
foreach_reverse (i, char c; path) |
| 9 |
{ |
| 10 |
if (c == '/' || c == '\\') |
| 11 |
return path[i + 1 .. $]; |
| 12 |
} |
| 13 |
return path; |
| 14 |
} |
| 15 |
const(char)* baseName(const(char)* path) |
| 16 |
{ |
| 17 |
for (const(char)* ptr = path; *ptr; ptr++) |
| 18 |
{ |
| 19 |
if (*ptr == '/' || *ptr == '\\') |
| 20 |
path = ptr + 1; |
| 21 |
} |
| 22 |
return path; |
| 23 |
} |
| 24 |
|
| 25 |
void func1(string file = __FILE__, size_t line = __LINE__, |
| 26 |
string func = __FUNCTION__, |
| 27 |
string pfunc = __PRETTY_FUNCTION__, |
| 28 |
string mod = __MODULE__) |
| 29 |
{ |
| 30 |
file = baseName(file); |
| 31 |
printf("%s: %.*s:%d %.*s %.*s %.*s\n", __FUNCTION__.ptr, |
| 32 |
cast(int) file.length, file.ptr, cast(int) line, |
| 33 |
cast(int) func.length, func.ptr, |
| 34 |
cast(int) pfunc.length, pfunc.ptr, |
| 35 |
cast(int) mod.length, mod.ptr); |
| 36 |
} |
| 37 |
|
| 38 |
// https://issues.dlang.org/show_bug.cgi?id=21211 |
| 39 |
void func2(const(char)* file = __FILE__.ptr, size_t line = __LINE__, |
| 40 |
const(char)* func = __FUNCTION__.ptr, |
| 41 |
const(char)* pfunc = __PRETTY_FUNCTION__.ptr, |
| 42 |
const(char)* mod = __MODULE__.ptr) |
| 43 |
{ |
| 44 |
file = baseName(file); |
| 45 |
printf("%s: %s:%d %s %s %s\n", __FUNCTION__.ptr, |
| 46 |
file, cast(int) line, func, pfunc, mod); |
| 47 |
} |
| 48 |
|
| 49 |
// https://issues.dlang.org/show_bug.cgi?id=18919 |
| 50 |
struct Loc3 |
| 51 |
{ |
| 52 |
string file; |
| 53 |
size_t line; |
| 54 |
string func; |
| 55 |
string pfunc; |
| 56 |
string mod; |
| 57 |
} |
| 58 |
void func3(Loc3 loc = Loc3(__FILE__, __LINE__, |
| 59 |
__FUNCTION__, __PRETTY_FUNCTION__, __MODULE__)) |
| 60 |
{ |
| 61 |
loc.file = baseName(loc.file); |
| 62 |
printf("%s: %.*s:%d %.*s %.*s %.*s\n", __FUNCTION__.ptr, |
| 63 |
cast(int) loc.file.length, loc.file.ptr, cast(int) loc.line, |
| 64 |
cast(int) loc.func.length, loc.func.ptr, |
| 65 |
cast(int) loc.pfunc.length, loc.pfunc.ptr, |
| 66 |
cast(int) loc.mod.length, loc.mod.ptr); |
| 67 |
} |
| 68 |
Loc3 defaultLoc3(string file = __FILE__, size_t line = __LINE__, |
| 69 |
string func = __FUNCTION__, |
| 70 |
string pfunc = __PRETTY_FUNCTION__, |
| 71 |
string mod = __MODULE__) |
| 72 |
{ |
| 73 |
return Loc3(file, line, func, pfunc, mod); |
| 74 |
} |
| 75 |
void func3b(Loc3 loc = defaultLoc3) |
| 76 |
{ |
| 77 |
loc.file = baseName(loc.file); |
| 78 |
printf("%s: %.*s:%d %.*s %.*s %.*s\n", __FUNCTION__.ptr, |
| 79 |
cast(int) loc.file.length, loc.file.ptr, cast(int) loc.line, |
| 80 |
cast(int) loc.func.length, loc.func.ptr, |
| 81 |
cast(int) loc.pfunc.length, loc.pfunc.ptr, |
| 82 |
cast(int) loc.mod.length, loc.mod.ptr); |
| 83 |
} |
| 84 |
enum Loc3Mixin = q{Loc3(__FILE__, __LINE__, |
| 85 |
__FUNCTION__, __PRETTY_FUNCTION__, __MODULE__)}; |
| 86 |
void func3c(Loc3 loc = mixin(Loc3Mixin)) |
| 87 |
{ |
| 88 |
loc.file = baseName(loc.file); |
| 89 |
printf("%s: %.*s:%d %.*s %.*s %.*s\n", __FUNCTION__.ptr, |
| 90 |
cast(int) loc.file.length, loc.file.ptr, cast(int) loc.line, |
| 91 |
cast(int) loc.func.length, loc.func.ptr, |
| 92 |
cast(int) loc.pfunc.length, loc.pfunc.ptr, |
| 93 |
cast(int) loc.mod.length, loc.mod.ptr); |
| 94 |
} |
| 95 |
void func3d(Loc3* loc = new Loc3(__FILE__, __LINE__, |
| 96 |
__FUNCTION__, __PRETTY_FUNCTION__, __MODULE__)) |
| 97 |
{ |
| 98 |
loc.file = baseName(loc.file); |
| 99 |
printf("%s: %.*s:%d %.*s %.*s %.*s\n", __FUNCTION__.ptr, |
| 100 |
cast(int) loc.file.length, loc.file.ptr, cast(int) loc.line, |
| 101 |
cast(int) loc.func.length, loc.func.ptr, |
| 102 |
cast(int) loc.pfunc.length, loc.pfunc.ptr, |
| 103 |
cast(int) loc.mod.length, loc.mod.ptr); |
| 104 |
} |
| 105 |
|
| 106 |
struct Loc4 |
| 107 |
{ |
| 108 |
const(char)* file; |
| 109 |
size_t line; |
| 110 |
const(char)* func; |
| 111 |
const(char)* pfunc; |
| 112 |
const(char)* mod; |
| 113 |
} |
| 114 |
void func4(Loc4 loc = Loc4(__FILE__.ptr, __LINE__, |
| 115 |
__FUNCTION__.ptr, __PRETTY_FUNCTION__.ptr, __MODULE__.ptr)) |
| 116 |
{ |
| 117 |
loc.file = baseName(loc.file); |
| 118 |
printf("%s: %s:%d %s %s %s\n", __FUNCTION__.ptr, |
| 119 |
loc.file, cast(int) loc.line, |
| 120 |
loc.func, |
| 121 |
loc.pfunc, |
| 122 |
loc.mod); |
| 123 |
} |
| 124 |
Loc4 defaultLoc4(const(char)* file = __FILE__.ptr, size_t line = __LINE__, |
| 125 |
const(char)* func = __FUNCTION__.ptr, |
| 126 |
const(char)* pfunc = __PRETTY_FUNCTION__.ptr, |
| 127 |
const(char)* mod = __MODULE__.ptr) |
| 128 |
{ |
| 129 |
return Loc4(file, line, func, pfunc, mod); |
| 130 |
} |
| 131 |
void func4b(Loc4 loc = defaultLoc4) |
| 132 |
{ |
| 133 |
loc.file = baseName(loc.file); |
| 134 |
printf("%s: %s:%d %s %s %s\n", __FUNCTION__.ptr, |
| 135 |
loc.file, cast(int) loc.line, |
| 136 |
loc.func, |
| 137 |
loc.pfunc, |
| 138 |
loc.mod); |
| 139 |
} |
| 140 |
enum Loc4Mixin = q{Loc4(__FILE__.ptr, __LINE__, |
| 141 |
__FUNCTION__.ptr, __PRETTY_FUNCTION__.ptr, __MODULE__.ptr)}; |
| 142 |
void func4c(Loc4 loc = mixin(Loc4Mixin)) |
| 143 |
{ |
| 144 |
loc.file = baseName(loc.file); |
| 145 |
printf("%s: %s:%d %s %s %s\n", __FUNCTION__.ptr, |
| 146 |
loc.file, cast(int) loc.line, |
| 147 |
loc.func, |
| 148 |
loc.pfunc, |
| 149 |
loc.mod); |
| 150 |
} |
| 151 |
void func4d(Loc4* loc = new Loc4(__FILE__.ptr, __LINE__, |
| 152 |
__FUNCTION__.ptr, __PRETTY_FUNCTION__.ptr, __MODULE__.ptr)) |
| 153 |
{ |
| 154 |
loc.file = baseName(loc.file); |
| 155 |
printf("%s: %s:%d %s %s %s\n", __FUNCTION__.ptr, |
| 156 |
loc.file, cast(int) loc.line, |
| 157 |
loc.func, |
| 158 |
loc.pfunc, |
| 159 |
loc.mod); |
| 160 |
} |
| 161 |
|
| 162 |
void func5(string file = baseName(__FILE__), int line = __LINE__, |
| 163 |
string func = __FUNCTION__, |
| 164 |
string pfunc = __PRETTY_FUNCTION__, |
| 165 |
string mod = __MODULE__)() |
| 166 |
{ |
| 167 |
printf("%s: %.*s:%d %.*s %.*s %.*s\n", __FUNCTION__.ptr, |
| 168 |
cast(int) file.length, file.ptr, line, |
| 169 |
cast(int) func.length, func.ptr, |
| 170 |
cast(int) pfunc.length, pfunc.ptr, |
| 171 |
cast(int) mod.length, mod.ptr); |
| 172 |
} |
| 173 |
|
| 174 |
void func6(string file = baseName(__FILE__), int line = __LINE__, |
| 175 |
const(char)* func = __FUNCTION__.ptr, |
| 176 |
const(char)* pfunc = __PRETTY_FUNCTION__.ptr, |
| 177 |
const(char)* mod = __MODULE__.ptr)() |
| 178 |
{ |
| 179 |
printf("%s: %.*s:%d %s %s %s\n", __FUNCTION__.ptr, |
| 180 |
cast(int) file.length, file.ptr, line, func, pfunc, mod); |
| 181 |
} |
| 182 |
|
| 183 |
void func7(int expr1 = 1000 + __LINE__ * 2, |
| 184 |
string expr2 = "file=" ~ baseName(__FILE__) ~ " func=" ~ __FUNCTION__, |
| 185 |
int expr3 = __LINE__ > 5 ? 1 : 2) |
| 186 |
{ |
| 187 |
printf("%s: expr1=%d, %.*s, expr3=%d\n", __FUNCTION__.ptr, expr1, cast(int) expr2.length, expr2.ptr, expr3); |
| 188 |
} |
| 189 |
|
| 190 |
immutable string[2] constants = ["constant1", "constant2"]; |
| 191 |
void func8(int[] expr1 = [__LINE__, __LINE__ + 1000], |
| 192 |
int[string] expr2 = [baseName(__FILE__): __LINE__], |
| 193 |
string expr3 = constants[__LINE__ > 5], |
| 194 |
string expr4 = __FILE__[0 .. __FILE__.length - 2]) |
| 195 |
{ |
| 196 |
expr4 = baseName(expr4); |
| 197 |
printf("%s: expr1=[", __FUNCTION__.ptr); |
| 198 |
foreach (i, x; expr1) |
| 199 |
printf("%d, ", x); |
| 200 |
printf("], expr2=["); |
| 201 |
foreach (k, v; expr2) |
| 202 |
printf("%.*s: %d, ", cast(int) k.length, k.ptr, v); |
| 203 |
printf("], expr3=%.*s", cast(int) expr3.length, expr3.ptr); |
| 204 |
printf(", expr4=%.*s\n", cast(int) expr4.length, expr4.ptr); |
| 205 |
} |
| 206 |
|
| 207 |
void func9(void function(string file = __FILE__, size_t line = __LINE__, string mod = __MODULE__) |
| 208 |
fp = (string file, size_t line, string mod) |
| 209 |
{ |
| 210 |
file = baseName(file); |
| 211 |
printf("imports.issue18919b.func9.fp: %.*s:%d %.*s\n", |
| 212 |
cast(int) file.length, file.ptr, cast(int) line, |
| 213 |
cast(int) mod.length, mod.ptr); |
| 214 |
}) |
| 215 |
{ |
| 216 |
fp(); |
| 217 |
} |
| 218 |
|
| 219 |
void func10(string expr1 = mixin(() { return "\"expr1=" ~ __MODULE__ ~ "\""; } ()), |
| 220 |
string expr2 = mixin("\"expr2=" ~ __MODULE__ ~ "\"")) |
| 221 |
{ |
| 222 |
printf("%s: %.*s, %.*s\n", __FUNCTION__.ptr, |
| 223 |
cast(int) expr1.length, expr1.ptr, |
| 224 |
cast(int) expr2.length, expr2.ptr); |
| 225 |
} |
| 226 |
|
| 227 |
template ctLoc3(string file, int line, |
| 228 |
string func, string pfunc, string mod) |
| 229 |
{ |
| 230 |
enum Loc3 ctLoc3 = Loc3(file, line, func, pfunc, mod); |
| 231 |
} |
| 232 |
|
| 233 |
void func11(Loc3 loc = ctLoc3!(baseName(__FILE__), __LINE__, |
| 234 |
__FUNCTION__, __PRETTY_FUNCTION__, __MODULE__)) |
| 235 |
{ |
| 236 |
printf("%s: %.*s:%d %.*s %.*s %.*s\n", __FUNCTION__.ptr, |
| 237 |
cast(int) loc.file.length, loc.file.ptr, cast(int) loc.line, |
| 238 |
cast(int) loc.func.length, loc.func.ptr, |
| 239 |
cast(int) loc.pfunc.length, loc.pfunc.ptr, |
| 240 |
cast(int) loc.mod.length, loc.mod.ptr); |
| 241 |
} |
| 242 |
|
| 243 |
void func12(const(char)*[] args = [baseName(__FILE__.ptr), |
| 244 |
__FUNCTION__.ptr, __PRETTY_FUNCTION__.ptr, __MODULE__.ptr]) |
| 245 |
{ |
| 246 |
printf("%s:", __FUNCTION__.ptr); |
| 247 |
foreach (arg; args) |
| 248 |
printf(" %s", arg); |
| 249 |
printf("\n"); |
| 250 |
} |
| 251 |
|
| 252 |
// https://issues.dlang.org/show_bug.cgi?id=24519 |
| 253 |
void func13(string file = __FILE__[]) |
| 254 |
{ |
| 255 |
printf("%s: %s\n", __FUNCTION__.ptr, file.ptr); |
| 256 |
} |