From 3e8dced0e7a021f9a03d59e7565561a7c2a227a5 Mon Sep 17 00:00:00 2001 From: Stian Gulpen Date: Mon, 18 Nov 2019 04:35:03 +0100 Subject: [PATCH] Hide most of the cases of slicing based on `strlen` using the `toDString()` helper --- CONTRIBUTING.md | 6 ++++-- src/dmd/cond.d | 2 +- src/dmd/dmangle.d | 3 ++- src/dmd/doc.d | 2 +- src/dmd/dsymbol.d | 22 ++++++++++------------ src/dmd/errors.d | 3 ++- src/dmd/expression.d | 15 ++++++++------- src/dmd/expressionsem.d | 5 ++--- src/dmd/func.d | 3 ++- src/dmd/identifier.d | 2 +- src/dmd/json.d | 2 +- src/dmd/libelf.d | 4 ++-- src/dmd/libmach.d | 4 ++-- src/dmd/libmscoff.d | 4 ++-- src/dmd/libomf.d | 4 ++-- src/dmd/link.d | 4 ++-- src/dmd/mars.d | 14 +++++++------- src/dmd/parse.d | 6 +++--- src/dmd/root/outbuffer.d | 3 ++- src/dmd/root/response.d | 3 ++- src/dmd/scanmscoff.d | 4 ++-- src/dmd/scanomf.d | 3 ++- src/dmd/statementsem.d | 4 ++-- src/dmd/traits.d | 12 ++++++++---- src/dmd/typesem.d | 5 +++-- 25 files changed, 75 insertions(+), 64 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e982b32303..f716e180d8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -81,9 +81,11 @@ overrides unless the overriding function does something different (as far as the caller is concerned) than the overridden function. Ddoc comment blocks are often overkill for nested functions and function literals; use ordinary comments for those. Follow the [D Style](https://dlang.org/dstyle.html#phobos_documentation) -for for comment blocks. +for comment blocks. 3. Do not use `strlen`/`strcmp` and their ilk. Use D arrays instead. +If slicing from a `char*` is required then use `dmd.utils.toDString` +or the member function `.toString` that is implemented in many classes. 4. Use `ref`/`out` instead of raw pointers. @@ -158,7 +160,7 @@ Such functions should not be mutating the data nor issuing error messages. across the source tree is likely to be disruptive and unlikely to provide significant improvement. -3. Reformatting into your personal style. Please stick with the existing style. +3. Reformatting into your personal style. Please stick with the existing style. Use the [D Style](https://dlang.org/dstyle.html#phobos_documentation) for new code. As always, treating the above as sacred writ is a huge mistake. Use diff --git a/src/dmd/cond.d b/src/dmd/cond.d index 94d0c48d02..309797fa42 100644 --- a/src/dmd/cond.d +++ b/src/dmd/cond.d @@ -742,7 +742,7 @@ extern (C++) final class VersionCondition : DVCondition deprecated("Kept for C++ compat - Use the string overload instead") static void addPredefinedGlobalIdent(const(char)* ident) { - addPredefinedGlobalIdent(ident[0 .. ident.strlen]); + addPredefinedGlobalIdent(ident.toDString()); } /// Ditto diff --git a/src/dmd/dmangle.d b/src/dmd/dmangle.d index 9d15df8e11..4bb3c1e892 100644 --- a/src/dmd/dmangle.d +++ b/src/dmd/dmangle.d @@ -35,6 +35,7 @@ import dmd.root.aav; import dmd.target; import dmd.tokens; import dmd.utf; +import dmd.utils; import dmd.visitor; private immutable char[TMAX] mangleChar = @@ -577,7 +578,7 @@ public: case LINK.cpp: { const p = target.cpp.toMangle(d); - return p[0 .. strlen(p)]; + return p.toDString(); } case LINK.default_: case LINK.system: diff --git a/src/dmd/doc.d b/src/dmd/doc.d index 4be3633a66..9770468b15 100644 --- a/src/dmd/doc.d +++ b/src/dmd/doc.d @@ -414,7 +414,7 @@ extern(C++) void gendocfile(Module m) time(&t); char* p = ctime(&t); p = mem.xstrdup(p); - m.macrotable.define("DATETIME", p[0 .. strlen(p)]); + m.macrotable.define("DATETIME", p.toDString()); m.macrotable.define("YEAR", p[20 .. 20 + 4]); } const srcfilename = m.srcfile.toString(); diff --git a/src/dmd/dsymbol.d b/src/dmd/dsymbol.d index 7bab6c11b9..ce3ad9b32b 100644 --- a/src/dmd/dsymbol.d +++ b/src/dmd/dsymbol.d @@ -314,13 +314,17 @@ extern (C++) class Dsymbol : ASTNode return ident is null; } + extern(D) private const(char)[] prettyFormatHelper() + { + const cstr = toPrettyChars(); + return '`' ~ cstr.toDString() ~ "`\0"; + } + final void error(const ref Loc loc, const(char)* format, ...) { va_list ap; va_start(ap, format); - const cstr = toPrettyChars(); - const pretty = '`' ~ cstr[0 .. strlen(cstr)] ~ "`\0"; - .verror(loc, format, ap, kind(), pretty.ptr); + .verror(loc, format, ap, kind(), prettyFormatHelper().ptr); va_end(ap); } @@ -328,10 +332,8 @@ extern (C++) class Dsymbol : ASTNode { va_list ap; va_start(ap, format); - const cstr = toPrettyChars(); - const pretty = '`' ~ cstr[0 .. strlen(cstr)] ~ "`\0"; const loc = getLoc(); - .verror(loc, format, ap, kind(), pretty.ptr); + .verror(loc, format, ap, kind(), prettyFormatHelper().ptr); va_end(ap); } @@ -339,9 +341,7 @@ extern (C++) class Dsymbol : ASTNode { va_list ap; va_start(ap, format); - const cstr = toPrettyChars(); - const pretty = '`' ~ cstr[0 .. strlen(cstr)] ~ "`\0"; - .vdeprecation(loc, format, ap, kind(), pretty.ptr); + .vdeprecation(loc, format, ap, kind(), prettyFormatHelper().ptr); va_end(ap); } @@ -349,10 +349,8 @@ extern (C++) class Dsymbol : ASTNode { va_list ap; va_start(ap, format); - const cstr = toPrettyChars(); - const pretty = '`' ~ cstr[0 .. strlen(cstr)] ~ "`\0"; const loc = getLoc(); - .vdeprecation(loc, format, ap, kind(), pretty.ptr); + .vdeprecation(loc, format, ap, kind(), prettyFormatHelper().ptr); va_end(ap); } diff --git a/src/dmd/errors.d b/src/dmd/errors.d index 2faa82a5fa..3cc08fb995 100644 --- a/src/dmd/errors.d +++ b/src/dmd/errors.d @@ -20,6 +20,7 @@ import dmd.globals; import dmd.root.outbuffer; import dmd.root.rmem; import dmd.console; +import dmd.utils; nothrow: @@ -474,7 +475,7 @@ private void verrorPrint(const ref Loc loc, Color headerColor, const(char)* head !global.params.mixinOut) { import dmd.filecache : FileCache; - auto fllines = FileCache.fileCache.addOrGetFile(loc.filename[0 .. strlen(loc.filename)]); + auto fllines = FileCache.fileCache.addOrGetFile(loc.filename.toDString()); if (loc.linnum - 1 < fllines.lines.length) { diff --git a/src/dmd/expression.d b/src/dmd/expression.d index 030a415739..2bbf6f6311 100644 --- a/src/dmd/expression.d +++ b/src/dmd/expression.d @@ -65,6 +65,7 @@ import dmd.target; import dmd.tokens; import dmd.typesem; import dmd.utf; +import dmd.utils; import dmd.visitor; enum LOGSEMANTIC = false; @@ -2304,7 +2305,7 @@ extern (C++) final class StringExp : Expression static StringExp create(Loc loc, char* s) { - return new StringExp(loc, s[0 .. strlen(s)]); + return new StringExp(loc, s.toDString()); } static StringExp create(Loc loc, void* string, size_t len) @@ -2315,7 +2316,7 @@ extern (C++) final class StringExp : Expression // Same as create, but doesn't allocate memory. static void emplace(UnionExp* pue, Loc loc, char* s) { - emplaceExp!(StringExp)(pue, loc, s[0 .. strlen(s)]); + emplaceExp!(StringExp)(pue, loc, s.toDString()); } extern (D) static void emplace(UnionExp* pue, Loc loc, const(void)[] string) @@ -6575,7 +6576,7 @@ extern (C++) final class FileInitExp : DefaultInitExp else s = loc.isValid() ? loc.filename : sc._module.ident.toChars(); - Expression e = new StringExp(loc, s[0 .. strlen(s)]); + Expression e = new StringExp(loc, s.toDString()); e = e.expressionSemantic(sc); e = e.castTo(sc, type); return e; @@ -6620,8 +6621,8 @@ extern (C++) final class ModuleInitExp : DefaultInitExp override Expression resolveLoc(const ref Loc loc, Scope* sc) { - const char* s = (sc.callsc ? sc.callsc : sc)._module.toPrettyChars(); - Expression e = new StringExp(loc, s[0 .. strlen(s)]); + const auto s = (sc.callsc ? sc.callsc : sc)._module.toPrettyChars().toDString(); + Expression e = new StringExp(loc, s); e = e.expressionSemantic(sc); e = e.castTo(sc, type); return e; @@ -6651,7 +6652,7 @@ extern (C++) final class FuncInitExp : DefaultInitExp s = sc.func.Dsymbol.toPrettyChars(); else s = ""; - Expression e = new StringExp(loc, s[0 .. strlen(s)]); + Expression e = new StringExp(loc, s.toDString()); e = e.expressionSemantic(sc); e.type = Type.tstring; return e; @@ -6691,7 +6692,7 @@ extern (C++) final class PrettyFuncInitExp : DefaultInitExp s = ""; } - Expression e = new StringExp(loc, s[0 .. strlen(s)]); + Expression e = new StringExp(loc, s.toDString()); e = e.expressionSemantic(sc); e.type = Type.tstring; return e; diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index 0da7d871ae..6960b5e1c8 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -13,7 +13,6 @@ module dmd.expressionsem; import core.stdc.stdio; -import core.stdc.string; import dmd.access; import dmd.aggregate; @@ -8855,9 +8854,9 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor if (global.params.tracegc) { auto funcname = (sc.callsc && sc.callsc.func) ? sc.callsc.func.toPrettyChars() : sc.func.toPrettyChars(); - arguments.push(new StringExp(exp.loc, exp.loc.filename[0 .. strlen(exp.loc.filename)])); + arguments.push(new StringExp(exp.loc, exp.loc.filename.toDString())); arguments.push(new IntegerExp(exp.loc, exp.loc.linnum, Type.tint32)); - arguments.push(new StringExp(exp.loc, funcname[0 .. strlen(funcname)])); + arguments.push(new StringExp(exp.loc, funcname.toDString())); } arguments.push(ale.e1); arguments.push(exp.e2); diff --git a/src/dmd/func.d b/src/dmd/func.d index 9a2d68ace7..4aeac79627 100644 --- a/src/dmd/func.d +++ b/src/dmd/func.d @@ -46,6 +46,7 @@ import dmd.statement_rewrite_walker; import dmd.statement; import dmd.statementsem; import dmd.tokens; +import dmd.utils; import dmd.visitor; /// Inline Status @@ -2744,7 +2745,7 @@ private const(char)* prependSpace(const(char)* str) { if (!str || !*str) return ""; - return (" " ~ str[0 .. strlen(str)] ~ "\0").ptr; + return (" " ~ str.toDString() ~ "\0").ptr; } /// Flag used by $(LREF resolveFuncCall). diff --git a/src/dmd/identifier.d b/src/dmd/identifier.d index b158bd7f75..a4e81b0f76 100644 --- a/src/dmd/identifier.d +++ b/src/dmd/identifier.d @@ -63,7 +63,7 @@ public: extern (D) this(const(char)* name) nothrow { //printf("Identifier('%s', %d)\n", name, value); - this(name[0 .. strlen(name)], TOK.identifier); + this(name.toDString(), TOK.identifier); } /// Sentinel for an anonymous identifier. diff --git a/src/dmd/json.d b/src/dmd/json.d index a406cd10dc..e677cbaedf 100644 --- a/src/dmd/json.d +++ b/src/dmd/json.d @@ -1050,7 +1050,7 @@ Returns: JsonFieldFlags.none on error, otherwise the JsonFieldFlags value */ extern (C++) JsonFieldFlags tryParseJsonField(const(char)* fieldName) { - auto fieldNameString = fieldName[0 .. strlen(fieldName)]; + auto fieldNameString = fieldName.toDString(); foreach (idx, enumName; __traits(allMembers, JsonFieldFlags)) { static if (idx > 0) diff --git a/src/dmd/libelf.d b/src/dmd/libelf.d index 5200eaa160..b1cfcbcf06 100644 --- a/src/dmd/libelf.d +++ b/src/dmd/libelf.d @@ -224,7 +224,7 @@ final class LibElf : Library return corrupt(__LINE__); for (uint i = 0; i < nsymbols; i++) { - const(char)[] name = s[0 .. strlen(s)]; + const(char)[] name = s.toDString(); s += name.length + 1; if (s - symtab > symtab_size) return corrupt(__LINE__); @@ -254,7 +254,7 @@ final class LibElf : Library om.length = cast(uint)buflen; om.offset = 0; auto n = cast(char*)FileName.name(module_name); // remove path, but not extension - om.name = n[0 .. strlen(n)]; + om.name = n.toDString(); om.name_offset = -1; om.scan = 1; if (fromfile) diff --git a/src/dmd/libmach.d b/src/dmd/libmach.d index fb5a91157c..51bc0ac7b5 100644 --- a/src/dmd/libmach.d +++ b/src/dmd/libmach.d @@ -153,7 +153,7 @@ final class LibMach : Library om.length = cast(uint)(size + MachLibHeader.sizeof); om.offset = 0; const n = cast(const(char)*)(om.base + MachLibHeader.sizeof); - om.name = n[0 .. strlen(n)]; + om.name = n.toDString(); om.file_time = cast(uint)strtoul(header.file_time.ptr, &endptr, 10); om.user_id = cast(uint)strtoul(header.user_id.ptr, &endptr, 10); om.group_id = cast(uint)strtoul(header.group_id.ptr, &endptr, 10); @@ -209,7 +209,7 @@ final class LibMach : Library om.length = cast(uint)buflen; om.offset = 0; const n = cast(const(char)*)FileName.name(module_name); // remove path, but not extension - om.name = n[0 .. strlen(n)]; + om.name = n.toDString(); om.scan = 1; if (fromfile) { diff --git a/src/dmd/libmscoff.d b/src/dmd/libmscoff.d index fa64296490..cd9952a210 100644 --- a/src/dmd/libmscoff.d +++ b/src/dmd/libmscoff.d @@ -280,7 +280,7 @@ final class LibMSCoff : Library char* s = string_table; for (uint i = 0; i < number_of_symbols; i++) { - const(char)[] name = s[0 .. strlen(s)]; + const(char)[] name = s.toDString(); s += name.length + 1; uint memi = indices[i] - 1; if (memi >= number_of_members) @@ -310,7 +310,7 @@ final class LibMSCoff : Library om.length = cast(uint)buflen; om.offset = 0; const(char)* n = global.params.preservePaths ? module_name : FileName.name(module_name); // remove path, but not extension - om.name = n[0 .. strlen(n)]; + om.name = n.toDString(); om.scan = 1; if (fromfile) { diff --git a/src/dmd/libomf.d b/src/dmd/libomf.d index 9d1f17287b..3be22b3364 100644 --- a/src/dmd/libomf.d +++ b/src/dmd/libomf.d @@ -149,7 +149,7 @@ final class LibOMF : Library { // Remove path and extension auto n = cast(char*)Mem.check(strdup(FileName.name(module_name))); - om.name = n[0 .. strlen(n)]; + om.name = n.toDString(); char* ext = cast(char*)FileName.ext(n); if (ext) ext[-1] = 0; @@ -160,7 +160,7 @@ final class LibOMF : Library * removing path and extension. */ auto n = cast(char*)Mem.check(strdup(FileName.name(name))); - om.name = n[0 .. strlen(n)]; + om.name = n.toDString(); char* ext = cast(char*)FileName.ext(n); if (ext) ext[-1] = 0; diff --git a/src/dmd/link.d b/src/dmd/link.d index be319651e7..2d645b8415 100644 --- a/src/dmd/link.d +++ b/src/dmd/link.d @@ -615,14 +615,14 @@ public int runLINK() */ static bool startsWith(const(char)* p, string needle) { - const f = p[0 .. strlen(p)]; + const f = p.toDString(); return f.length >= needle.length && f[0 .. needle.length] == needle; } // return true if flagp should be ordered in with the library flags static bool flagIsLibraryRelated(const char* p) { - const flag = p[0 .. strlen(p)]; + const flag = p.toDString(); return startsWith(p, "-l") || startsWith(p, "-L") || flag == "-(" || flag == "-)" diff --git a/src/dmd/mars.d b/src/dmd/mars.d index abda308571..d0c8ca2a79 100644 --- a/src/dmd/mars.d +++ b/src/dmd/mars.d @@ -356,10 +356,10 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params) // Add in command line versions if (params.versionids) foreach (charz; *params.versionids) - VersionCondition.addGlobalIdent(charz[0 .. strlen(charz)]); + VersionCondition.addGlobalIdent(charz.toDString()); if (params.debugids) foreach (charz; *params.debugids) - DebugCondition.addGlobalIdent(charz[0 .. strlen(charz)]); + DebugCondition.addGlobalIdent(charz.toDString()); setTarget(params); @@ -1304,7 +1304,7 @@ extern(C) void printGlobalConfigs(FILE* stream) foreach (flag; dflags[]) { bool needsQuoting; - foreach (c; flag[0 .. strlen(flag)]) + foreach (c; flag.toDString()) { if (!(isalnum(c) || c == '_')) { @@ -1543,7 +1543,7 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param return buf; } const ident = ps + 1; - switch (ident[0 .. strlen(ident)]) + switch (ident.toDString()) { mixin(generateTransitionsText()); default: @@ -1563,7 +1563,7 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param for (size_t i = 1; i < arguments.dim; i++) { const(char)* p = arguments[i]; - const(char)[] arg = p[0 .. strlen(p)]; + const(char)[] arg = p.toDString(); if (*p != '-') { static if (TARGET.Windows) @@ -1876,7 +1876,7 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param if (Identifier.isValidIdentifier(p + len)) { const ident = p + len; - switch (ident[0 .. strlen(ident)]) + switch (ident.toDString()) { case "baseline": params.cpu = CPU.baseline; @@ -1970,7 +1970,7 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param else if (Identifier.isValidIdentifier(p + len)) { const ident = p + len; - switch (ident[0 .. strlen(ident)]) + switch (ident.toDString()) { case "import": params.bug10378 = true; diff --git a/src/dmd/parse.d b/src/dmd/parse.d index 04cfc34e3f..a25bbf23b8 100644 --- a/src/dmd/parse.d +++ b/src/dmd/parse.d @@ -7694,7 +7694,7 @@ final class Parser(AST) : Lexer case TOK.file: { const(char)* s = loc.filename ? loc.filename : mod.ident.toChars(); - e = new AST.StringExp(loc, s[0 .. strlen(s)]); + e = new AST.StringExp(loc, s.toDString()); nextToken(); break; } @@ -7702,7 +7702,7 @@ final class Parser(AST) : Lexer { assert(loc.isValid(), "__FILE_FULL_PATH__ does not work with an invalid location"); const s = FileName.toAbsolute(loc.filename); - e = new AST.StringExp(loc, s[0 .. strlen(s)]); + e = new AST.StringExp(loc, s.toDString()); nextToken(); break; } @@ -7715,7 +7715,7 @@ final class Parser(AST) : Lexer case TOK.moduleString: { const(char)* s = md ? md.toChars() : mod.toChars(); - e = new AST.StringExp(loc, s[0 .. strlen(s)]); + e = new AST.StringExp(loc, s.toDString()); nextToken(); break; } diff --git a/src/dmd/root/outbuffer.d b/src/dmd/root/outbuffer.d index ef48a7f932..b1f1d13f89 100644 --- a/src/dmd/root/outbuffer.d +++ b/src/dmd/root/outbuffer.d @@ -17,6 +17,7 @@ import core.stdc.stdio; import core.stdc.string; import dmd.root.rmem; import dmd.root.rootobject; +import dmd.utils; debug { @@ -124,7 +125,7 @@ struct OutBuffer extern (C++) void writestring(const(char)* string) pure nothrow { - write(string[0 .. strlen(string)]); + write(string.toDString); } void writestring(const(char)[] s) pure nothrow diff --git a/src/dmd/root/response.d b/src/dmd/root/response.d index e6718497e8..5333c88033 100644 --- a/src/dmd/root/response.d +++ b/src/dmd/root/response.d @@ -16,6 +16,7 @@ module dmd.root.response; import dmd.root.file; import dmd.root.filename; +import dmd.utils; /// alias responseExpand = responseExpandFrom!lookupInEnvironment; @@ -90,7 +91,7 @@ version (unittest) char[] testEnvironment(const(char)* str) nothrow pure { import core.stdc.string: strlen; - switch (str[0 .. strlen(str)]) + switch (str.toDString()) { case "Foo": return "foo @Bar #\0".dup; diff --git a/src/dmd/scanmscoff.d b/src/dmd/scanmscoff.d index d0262c0e97..fed673d569 100644 --- a/src/dmd/scanmscoff.d +++ b/src/dmd/scanmscoff.d @@ -18,7 +18,7 @@ import core.stdc.string, core.stdc.stdlib, core.sys.windows.winnt; import dmd.root.rmem; -import dmd.globals, dmd.errors; +import dmd.globals, dmd.errors, dmd.utils; private enum LOG = false; @@ -175,7 +175,7 @@ void scanMSCoffObjModule(void delegate(const(char)[] name, int pickAny) pAddSymb default: continue; } - pAddSymbol(p[0 .. strlen(p)], 1); + pAddSymbol(p.toDString(), 1); } } diff --git a/src/dmd/scanomf.d b/src/dmd/scanomf.d index aa1a6e0c4d..28fbf69fc1 100644 --- a/src/dmd/scanomf.d +++ b/src/dmd/scanomf.d @@ -21,6 +21,7 @@ import dmd.root.rmem; import dmd.root.outbuffer; import dmd.arraytypes; import dmd.errors; +import dmd.utils; private enum LOG = false; @@ -115,7 +116,7 @@ void scanOmfObjModule(void delegate(const(char)[] name, int pickAny) pAddSymbol, } //printf("[s] name='%s'\n",name); const(char)* n = names[idx]; - pAddSymbol(n[0 .. strlen(n)], pickAny); + pAddSymbol(n.toDString(), pickAny); break; } case COMDEF: diff --git a/src/dmd/statementsem.d b/src/dmd/statementsem.d index 9276ffddbc..7805b19736 100644 --- a/src/dmd/statementsem.d +++ b/src/dmd/statementsem.d @@ -13,7 +13,6 @@ module dmd.statementsem; import core.stdc.stdio; -import core.stdc.string; import dmd.aggregate; import dmd.aliasthis; @@ -55,6 +54,7 @@ import dmd.statement; import dmd.target; import dmd.tokens; import dmd.typesem; +import dmd.utils; import dmd.visitor; /***************************************** @@ -2654,7 +2654,7 @@ else sl = new DotIdExp(ss.loc, sl, Id.__switch_error); Expressions* args = new Expressions(2); - (*args)[0] = new StringExp(ss.loc, ss.loc.filename[0 .. strlen(ss.loc.filename)]); + (*args)[0] = new StringExp(ss.loc, ss.loc.filename.toDString()); (*args)[1] = new IntegerExp(ss.loc.linnum); sl = new CallExp(ss.loc, sl, args); diff --git a/src/dmd/traits.d b/src/dmd/traits.d index 71ac34aec2..120e9d808c 100644 --- a/src/dmd/traits.d +++ b/src/dmd/traits.d @@ -13,7 +13,6 @@ module dmd.traits; import core.stdc.stdio; -import core.stdc.string; import dmd.aggregate; import dmd.arraytypes; @@ -49,6 +48,7 @@ import dmd.typesem; import dmd.visitor; import dmd.root.rootobject; import dmd.root.outbuffer; +import dmd.utils; enum LOGSEMANTIC = false; @@ -1406,7 +1406,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc) } } auto linkage = linkageToChars(link); - auto se = new StringExp(e.loc, linkage[0 .. strlen(linkage)]); + auto se = new StringExp(e.loc, linkage.toDString()); return se.expressionSemantic(sc); } if (e.ident == Id.allMembers || @@ -1484,7 +1484,11 @@ Expression semanticTraits(TraitsExp e, Scope* sc) return 0; // Avoid using strcmp in the first place due to the performance impact in an O(N^2) loop. - debug assert(strcmp(id.toChars(), sm.ident.toChars()) != 0); + debug + { + import core.stdc.string : strcmp; + assert(strcmp(id.toChars(), sm.ident.toChars()) != 0); + } } idents.push(sm.ident); } @@ -1911,7 +1915,7 @@ Lnext: } auto exps = new Expressions(3); - (*exps)[0] = new StringExp(e.loc, s.loc.filename[0 .. strlen(s.loc.filename)]); + (*exps)[0] = new StringExp(e.loc, s.loc.filename.toDString()); (*exps)[1] = new IntegerExp(e.loc, s.loc.linnum,Type.tint32); (*exps)[2] = new IntegerExp(e.loc, s.loc.charnum,Type.tint32); auto tup = new TupleExp(e.loc, exps); diff --git a/src/dmd/typesem.d b/src/dmd/typesem.d index 9b4e07f20b..40004122d2 100644 --- a/src/dmd/typesem.d +++ b/src/dmd/typesem.d @@ -61,6 +61,7 @@ import dmd.sideeffect; import dmd.target; import dmd.tokens; import dmd.typesem; +import dmd.utils; /************************** * This evaluates exp while setting length to be the number @@ -2123,7 +2124,7 @@ Expression getProperty(Type t, const ref Loc loc, Identifier ident, int flag) } else { - e = new StringExp(loc, mt.deco[0 .. strlen(mt.deco)]); + e = new StringExp(loc, mt.deco.toDString()); Scope sc; e = e.expressionSemantic(&sc); } @@ -2131,7 +2132,7 @@ Expression getProperty(Type t, const ref Loc loc, Identifier ident, int flag) else if (ident == Id.stringof) { const s = mt.toChars(); - e = new StringExp(loc, s[0 .. strlen(s)]); + e = new StringExp(loc, s.toDString()); Scope sc; e = e.expressionSemantic(&sc); }