Commit 09580ccf authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] fix formatting of derefence and addressof operators

Bug: v8:7793
Change-Id: Ie573b3feef58329d524e51c942b67cf0525963ff
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2300545
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68885}
parent e996b743
......@@ -71,7 +71,7 @@ macro EnsureArrayLengthWritable(implicit context: Context)(map: Map):
// guaranteed to stay the first property.
const descriptors: DescriptorArray = map.instance_descriptors;
const descriptor:&DescriptorEntry =
& descriptors.descriptors[kLengthDescriptorIndex];
&descriptors.descriptors[kLengthDescriptorIndex];
assert(TaggedEqual(descriptor->key, LengthStringConstant()));
const details: Smi = UnsafeCast<Smi>(descriptor->details);
if ((details & kAttributesReadOnlyMask) != 0) {
......
......@@ -118,7 +118,7 @@ transitioning macro MorphAndEnqueuePromiseReaction(implicit context: Context)(
kPromiseReactionSize ==
kPromiseReactionJobTaskSizeOfAllPromiseReactionJobTasks);
if constexpr (reactionType == kPromiseReactionFulfill) {
* UnsafeConstCast(& promiseReaction.map) =
*UnsafeConstCast(&promiseReaction.map) =
PromiseFulfillReactionJobTaskMapConstant();
const promiseReactionJobTask =
UnsafeCast<PromiseFulfillReactionJobTask>(promiseReaction);
......@@ -133,7 +133,7 @@ transitioning macro MorphAndEnqueuePromiseReaction(implicit context: Context)(
kPromiseReactionJobTaskPromiseOrCapabilityOffset);
} else {
StaticAssert(reactionType == kPromiseReactionReject);
* UnsafeConstCast(& promiseReaction.map) =
*UnsafeConstCast(&promiseReaction.map) =
PromiseRejectReactionJobTaskMapConstant();
const promiseReactionJobTask =
UnsafeCast<PromiseRejectReactionJobTask>(promiseReaction);
......
......@@ -44,7 +44,7 @@ macro InnerNewJSPromise(implicit context: Context)(): JSPromise {
assert(IsFunctionWithPrototypeSlotMap(promiseFun.map));
const promiseMap = UnsafeCast<Map>(promiseFun.prototype_or_initial_map);
const promiseHeapObject = promise_internal::AllocateJSPromise(context);
* UnsafeConstCast(& promiseHeapObject.map) = promiseMap;
*UnsafeConstCast(&promiseHeapObject.map) = promiseMap;
const promise = UnsafeCast<JSPromise>(promiseHeapObject);
promise.properties_or_hash = kEmptyFixedArray;
promise.elements = kEmptyFixedArray;
......
......@@ -100,7 +100,7 @@ struct SliceIterator<T: type> {
}
macro Next(): T labels NoMore {
return * this.NextReference() otherwise NoMore;
return *this.NextReference() otherwise NoMore;
}
macro NextReference():&T labels NoMore {
......@@ -172,7 +172,7 @@ macro InitializeFieldsFromIterator<T: type, Iterator: type>(
let originIterator = originIterator;
while (true) {
const ref:&T = targetIterator.NextReference() otherwise break;
* ref = originIterator.Next() otherwise unreachable;
*ref = originIterator.Next() otherwise unreachable;
}
}
// Dummy implementations: do not initialize for UninitializedIterator.
......@@ -187,14 +187,14 @@ extern macro StoreDoubleHole(HeapObject, intptr);
macro LoadFloat64OrHole(r:&float64_or_hole): float64_or_hole {
return float64_or_hole{
is_hole: IsDoubleHole(r.object, r.offset - kHeapObjectTag),
value: * unsafe::NewReference<float64>(r.object, r.offset)
value: *unsafe::NewReference<float64>(r.object, r.offset)
};
}
macro StoreFloat64OrHole(r:&float64_or_hole, value: float64_or_hole) {
if (value.is_hole) {
StoreDoubleHole(r.object, r.offset - kHeapObjectTag);
} else {
* unsafe::NewReference<float64>(r.object, r.offset) = value.value;
*unsafe::NewReference<float64>(r.object, r.offset) = value.value;
}
}
......
......@@ -233,7 +233,7 @@ builtin WasmAllocateStruct(implicit context: Context)(mapIndex: Smi):
const instanceSize: intptr =
unsafe::TimesTaggedSize(Convert<intptr>(map.instance_size_in_words));
const result: HeapObject = unsafe::Allocate(instanceSize);
* UnsafeConstCast(& result.map) = map;
*UnsafeConstCast(&result.map) = map;
return result;
}
......@@ -247,7 +247,7 @@ builtin WasmAllocateStructWithRtt(implicit context: Context)(rtt: Map):
const instanceSize: intptr =
unsafe::TimesTaggedSize(Convert<intptr>(rtt.instance_size_in_words));
const result: HeapObject = unsafe::Allocate(instanceSize);
* UnsafeConstCast(& result.map) = rtt;
*UnsafeConstCast(&result.map) = rtt;
return result;
}
......
......@@ -129,7 +129,7 @@ macro ExtractFixedArray(
return NewFixedArray(
capacity,
IteratorSequence<Object>(
(& source.objects).Iterator(first, first + count),
(&source.objects).Iterator(first, first + count),
ConstantIterator(TheHole)));
}
macro ExtractFixedDoubleArray(
......@@ -139,7 +139,7 @@ macro ExtractFixedDoubleArray(
return NewFixedDoubleArray(
capacity,
IteratorSequence<float64_or_hole>(
(& source.floats).Iterator(first, first + count),
(&source.floats).Iterator(first, first + count),
ConstantIterator(kDoubleHole)));
}
......
......@@ -6,12 +6,13 @@
/* Test mulitline
comment
*/
/*multiline_without_whitespace*/
namespace test {
macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool {
if constexpr (
(kind == ElementsKind::UINT8_ELEMENTS) ||
(kind == ElementsKind::UINT16_ELEMENTS)) {
kind == ElementsKind::UINT8_ELEMENTS ||
kind == ElementsKind::UINT16_ELEMENTS) {
return true;
} else {
return false;
......@@ -19,9 +20,8 @@ macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool {
}
macro ElementsKindTestHelper2(kind: constexpr ElementsKind): constexpr bool {
return (
(kind == ElementsKind::UINT8_ELEMENTS) ||
(kind == ElementsKind::UINT16_ELEMENTS));
return kind == ElementsKind::UINT8_ELEMENTS ||
kind == ElementsKind::UINT16_ELEMENTS;
}
macro LabelTestHelper1(): never
......@@ -826,25 +826,25 @@ macro TestNewFixedArrayFromSpread(implicit context: Context)(): Object {
class SmiPair extends HeapObject {
macro GetA():&Smi {
return & this.a;
return &this.a;
}
a: Smi;
b: Smi;
}
macro Swap<T: type>(a:&T, b:&T) {
const tmp = * a;
* a = * b;
* b = tmp;
const tmp = *a;
*a = *b;
*b = tmp;
}
@export
macro TestReferences() {
const array = new SmiPair{a: 7, b: 2};
const ref:&Smi = & array.a;
* ref = 3 + * ref;
-- * ref;
Swap(& array.b, array.GetA());
const ref:&Smi = &array.a;
*ref = 3 + *ref;
-- *ref;
Swap(&array.b, array.GetA());
check(array.a == 2);
check(array.b == 9);
}
......@@ -857,15 +857,15 @@ macro TestSlices() {
const oneTwoThree = Convert<Smi>(123);
a.objects[0] = oneTwoThree;
const firstRef:&Object = & a.objects[0];
check(TaggedEqual(* firstRef, oneTwoThree));
const firstRef:&Object = &a.objects[0];
check(TaggedEqual(*firstRef, oneTwoThree));
const slice: torque_internal::Slice<Object> = & a.objects;
const slice: torque_internal::Slice<Object> = &a.objects;
const firstRefAgain:&Object = slice.TryAtIndex(0) otherwise unreachable;
check(TaggedEqual(* firstRefAgain, oneTwoThree));
check(TaggedEqual(*firstRefAgain, oneTwoThree));
const threeTwoOne = Convert<Smi>(321);
* firstRefAgain = threeTwoOne;
*firstRefAgain = threeTwoOne;
check(TaggedEqual(a.objects[0], threeTwoOne));
// *slice; // error, not allowed
......@@ -885,12 +885,12 @@ macro TestSliceEnumeration(implicit context: Context)(): Undefined {
fixedArray.objects[i] = Convert<Smi>(i) + 3;
}
let slice = & fixedArray.objects;
let slice = &fixedArray.objects;
for (let i: intptr = 0; i < slice.length; i++) {
let ref = slice.TryAtIndex(i) otherwise unreachable;
const value = UnsafeCast<Smi>(* ref);
const value = UnsafeCast<Smi>(*ref);
check(value == Convert<Smi>(i) + 3);
* ref = value + 4;
*ref = value + 4;
}
let it = slice.Iterator();
......
......@@ -16,8 +16,20 @@ import re
from subprocess import Popen, PIPE
kPercentEscape = r'α'; # Unicode alpha
kDerefEscape = r'☆'; # Unicode star
kAddressofEscape = r'⌂'; # Unicode house
def preprocess(input):
# Special handing of '%' for intrinsics, turn the percent
# into a unicode character so that it gets treated as part of the
# intrinsic's name if it's already adjacent to it.
input = re.sub(r'%([A-Za-z])', kPercentEscape + r'\1', input)
# Similarly, avoid treating * and & as binary operators when they're
# probably used as address operators.
input = re.sub(r'([^/])\*([a-zA-Z(])', r'\1' + kDerefEscape + r'\2', input)
input = re.sub(r'&([a-zA-Z(])', kAddressofEscape + r'\1', input)
input = re.sub(r'(if\s+)constexpr(\s*\()', r'\1/*COxp*/\2', input)
input = re.sub(r'(\s+)operator\s*(\'[^\']+\')', r'\1/*_OPE \2*/', input)
input = re.sub(r'\btypeswitch\s*(\([^{]*\))\s{', r' if /*tPsW*/ \1 {', input)
......@@ -35,12 +47,7 @@ def preprocess(input):
input = re.sub(r'@if\(', r'@iF(', input)
input = re.sub(r'@export', r'@eXpOrT', input)
input = re.sub(r'js-implicit[ \n]+', r'jS_iMpLiCiT_', input)
input = re.sub(r'^(\s*namespace\s+[a-zA-Z_0-9]+\s*{)(\s*)$', r'\1}\2', input, flags = re.MULTILINE);
# Special handing of '%' for intrinsics, turn the percent
# into a unicode character so that it gets treated as part of the
# intrinsic's name if it's already adjacent to it.
input = re.sub(r'%([A-Za-z])', kPercentEscape + r'\1', input)
input = re.sub(r'^(\s*namespace\s+[a-zA-Z_0-9]+\s*{)(\s*)$', r'\1}\2', input, flags = re.MULTILINE)
# includes are not recognized, change them into comments so that the
# formatter ignores them first, until we can figure out a way to format cpp
......@@ -78,6 +85,9 @@ def postprocess(output):
output = re.sub(r'^(\s*namespace\s+[a-zA-Z_0-9]+\s*{)}(\s*)$', r'\1\2', output, flags = re.MULTILINE);
output = re.sub(kPercentEscape, r'%', output)
output = re.sub(kDerefEscape, r'*', output)
output = re.sub(kAddressofEscape, r'&', output)
output = re.sub( r'^// InClUdE',r'#include', output, flags=re.MULTILINE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment