Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -8920,9 +8920,6 @@ struct Token final
};
Identifier* ident;
};
void setString(const char* ptr, size_t length);
void setString(const OutBuffer& buf);
void setString();
const char* toChars() const;
static const char* toChars(TOK value);
Token() :
Expand Down
20 changes: 10 additions & 10 deletions compiler/src/dmd/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ class Lexer
case 0:
case 0x1A:
error("unterminated string constant starting at %s", start.toChars());
result.setString();
result.setString(null);
// rewind `p` so it points to the EOF character
p--;
return;
Expand All @@ -1645,7 +1645,7 @@ class Lexer
if (supportInterpolation)
result.appendInterpolatedPart(stringbuffer);
else
result.setString(stringbuffer);
result.setString(stringbuffer[]);

stringPostfix(result);
return;
Expand Down Expand Up @@ -1698,7 +1698,7 @@ class Lexer
case 0:
case 0x1A:
error("unterminated string constant starting at %s", start.toChars());
t.setString();
t.setString(null);
// decrement `p`, because it needs to point to the next token (the 0 or 0x1A character is the TOK.endOfFile token).
p--;
return TOK.hexadecimalString;
Expand All @@ -1708,7 +1708,7 @@ class Lexer
error("odd number (%d) of hex characters in hex string", n);
stringbuffer.writeByte(cast(char)v);
}
t.setString(stringbuffer);
t.setString(stringbuffer[]);
stringPostfix(t);
return TOK.hexadecimalString;
default:
Expand Down Expand Up @@ -1801,7 +1801,7 @@ class Lexer
case 0:
case 0x1A:
error("unterminated delimited string constant starting at %s", start.toChars());
result.setString();
result.setString(null);
// decrement `p`, because it needs to point to the next token (the 0 or 0x1A character is the TOK.endOfFile token).
p--;
return;
Expand Down Expand Up @@ -1907,7 +1907,7 @@ class Lexer
error("delimited string must end in `\"`");
else
error(token.loc, "delimited string must end in `%c\"`", delimright);
result.setString(stringbuffersecondary);
result.setString(stringbuffersecondary[]);
stringPostfix(result);
}

Expand Down Expand Up @@ -1954,7 +1954,7 @@ class Lexer
if (supportInterpolation)
result.appendInterpolatedPart(pstart, p - 1 - pstart);
else
result.setString(pstart, p - 1 - pstart);
result.setString(pstart[0 .. p - 1 - pstart]);

stringPostfix(result);
return;
Expand All @@ -1976,7 +1976,7 @@ class Lexer
continue;
case TOK.endOfFile:
error("unterminated token string constant starting at %s", start.toChars());
result.setString();
result.setString(null);
return;
default:
continue;
Expand Down Expand Up @@ -2121,7 +2121,7 @@ class Lexer
if (supportInterpolation)
t.appendInterpolatedPart(stringbuffer);
else
t.setString(stringbuffer);
t.setString(stringbuffer[]);
if (!Ccompile)
stringPostfix(t);
return;
Expand All @@ -2131,7 +2131,7 @@ class Lexer
p--;
Lunterminated:
error("unterminated string constant starting at %s", start.toChars());
t.setString();
t.setString(null);
return;
default:
if (c & 0x80)
Expand Down
43 changes: 13 additions & 30 deletions compiler/src/dmd/tokens.d
Original file line number Diff line number Diff line change
Expand Up @@ -949,40 +949,23 @@ nothrow:
}

/****
* Set to contents of ptr[0..length]
* Set to contents of str
* Params:
* ptr = pointer to string
* length = length of string
* str = string
*/
void setString(const(char)* ptr, size_t length)
extern (D) void setString(const(char)[] str)
{
value = TOK.string_;
auto s = cast(char*)mem.xmalloc_noscan(length + 1);
memcpy(s, ptr, length);
s[length] = 0;
ustring = s;
len = cast(uint)length;
postfix = 0;
}

/****
* Set to contents of buf
* Params:
* buf = string (not zero terminated)
*/
void setString(const ref OutBuffer buf)
{
setString(cast(const(char)*)buf[].ptr, buf.length);
}

/****
* Set to empty string
*/
void setString()
{
value = TOK.string_;
ustring = "";
len = 0;
len = cast(uint)str.length;
if (len)
{
auto s = cast(char*)mem.xmalloc_noscan(len + 1);
memcpy(s, str.ptr, len);
s[len] = 0;
ustring = s;
}
else
ustring = "";
postfix = 0;
}

Expand Down
Loading