[torque] Fix multi-line AssertStatements
R=tebbi@chromium.org Bug: v8:7793 Change-Id: I691b3682aec3269350ee02c29b48ce1d46a1ffcb Reviewed-on: https://chromium-review.googlesource.com/1098656 Reviewed-by: Tobias Tebbi <tebbi@chromium.org> Commit-Queue: Simon Zünd <szuend@google.com> Cr-Commit-Position: refs/heads/master@{#53701}
This commit is contained in:
parent
e3d957e34b
commit
696e8ea9f1
@ -622,9 +622,8 @@ module array {
|
||||
let element: Object = Load<E>(context, elements, i) otherwise Bailout;
|
||||
let j: Smi = i - 1;
|
||||
for (; j >= from; --j) {
|
||||
// TODO(szuend): Introduce line breaks when multi-line asserts are
|
||||
// fixed in Torque.
|
||||
assert(CanUseSameAccessor<E>(context, receiver, initialReceiverMap, initialReceiverLength));
|
||||
assert(CanUseSameAccessor<E>(
|
||||
context, receiver, initialReceiverMap, initialReceiverLength));
|
||||
|
||||
let tmp: Object = Load<E>(context, elements, j) otherwise Bailout;
|
||||
let order: Number = CallCompareFn<E>(
|
||||
@ -783,9 +782,8 @@ module array {
|
||||
// From low_end to idx are elements equal to pivot.
|
||||
// From idx to high_start are elements that haven"t been compared yet.
|
||||
for (let idx: Smi = low_end + 1; idx < high_start; idx++) {
|
||||
// TODO(szuend): Introduce line breaks when multi-line asserts are
|
||||
// fixed in Torque.
|
||||
assert(CanUseSameAccessor<E>(context, receiver, initialReceiverMap, initialReceiverLength));
|
||||
assert(CanUseSameAccessor<E>(
|
||||
context, receiver, initialReceiverMap, initialReceiverLength));
|
||||
|
||||
let element: Object = Load<E>(context, elements, idx) otherwise Bailout;
|
||||
let order: Number = CallCompareFn<E>(
|
||||
|
@ -679,6 +679,24 @@ const Type* ImplementationVisitor::Visit(DebugStatement* stmt) {
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
std::string FormatAssertSource(const std::string& str) {
|
||||
// Replace all whitespace characters with a space character.
|
||||
std::string str_no_newlines = str;
|
||||
std::replace_if(str_no_newlines.begin(), str_no_newlines.end(),
|
||||
[](unsigned char c) { return isspace(c); }, ' ');
|
||||
|
||||
// str might include indentation, squash multiple space characters into one.
|
||||
std::string result;
|
||||
std::unique_copy(str_no_newlines.begin(), str_no_newlines.end(),
|
||||
std::back_inserter(result),
|
||||
[](char a, char b) { return a == ' ' && b == ' '; });
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const Type* ImplementationVisitor::Visit(AssertStatement* stmt) {
|
||||
bool do_check = !stmt->debug_only;
|
||||
#if defined(DEBUG)
|
||||
@ -717,8 +735,9 @@ const Type* ImplementationVisitor::Visit(AssertStatement* stmt) {
|
||||
GenerateLabelBind(false_label);
|
||||
GenerateIndent();
|
||||
source_out() << "Print(\""
|
||||
<< "assert '" << stmt->source << "' failed at "
|
||||
<< PositionAsString(stmt->pos) << "\");" << std::endl;
|
||||
<< "assert '" << FormatAssertSource(stmt->source)
|
||||
<< "' failed at " << PositionAsString(stmt->pos) << "\");"
|
||||
<< std::endl;
|
||||
GenerateIndent();
|
||||
source_out() << "Unreachable();" << std::endl;
|
||||
|
||||
|
@ -213,4 +213,10 @@ module test {
|
||||
let x: int32 = 0x40000000;
|
||||
let y: int32 = 0x7fffffff;
|
||||
}
|
||||
|
||||
macro TestMultilineAssert() {
|
||||
let someVeryLongVariableNameThatWillCauseLineBreaks: Smi = 5;
|
||||
check(someVeryLongVariableNameThatWillCauseLineBreaks > 0
|
||||
&& someVeryLongVariableNameThatWillCauseLineBreaks < 10);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user