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): ...@@ -71,7 +71,7 @@ macro EnsureArrayLengthWritable(implicit context: Context)(map: Map):
// guaranteed to stay the first property. // guaranteed to stay the first property.
const descriptors: DescriptorArray = map.instance_descriptors; const descriptors: DescriptorArray = map.instance_descriptors;
const descriptor:&DescriptorEntry = const descriptor:&DescriptorEntry =
& descriptors.descriptors[kLengthDescriptorIndex]; &descriptors.descriptors[kLengthDescriptorIndex];
assert(TaggedEqual(descriptor->key, LengthStringConstant())); assert(TaggedEqual(descriptor->key, LengthStringConstant()));
const details: Smi = UnsafeCast<Smi>(descriptor->details); const details: Smi = UnsafeCast<Smi>(descriptor->details);
if ((details & kAttributesReadOnlyMask) != 0) { if ((details & kAttributesReadOnlyMask) != 0) {
......
...@@ -118,7 +118,7 @@ transitioning macro MorphAndEnqueuePromiseReaction(implicit context: Context)( ...@@ -118,7 +118,7 @@ transitioning macro MorphAndEnqueuePromiseReaction(implicit context: Context)(
kPromiseReactionSize == kPromiseReactionSize ==
kPromiseReactionJobTaskSizeOfAllPromiseReactionJobTasks); kPromiseReactionJobTaskSizeOfAllPromiseReactionJobTasks);
if constexpr (reactionType == kPromiseReactionFulfill) { if constexpr (reactionType == kPromiseReactionFulfill) {
* UnsafeConstCast(& promiseReaction.map) = *UnsafeConstCast(&promiseReaction.map) =
PromiseFulfillReactionJobTaskMapConstant(); PromiseFulfillReactionJobTaskMapConstant();
const promiseReactionJobTask = const promiseReactionJobTask =
UnsafeCast<PromiseFulfillReactionJobTask>(promiseReaction); UnsafeCast<PromiseFulfillReactionJobTask>(promiseReaction);
...@@ -133,7 +133,7 @@ transitioning macro MorphAndEnqueuePromiseReaction(implicit context: Context)( ...@@ -133,7 +133,7 @@ transitioning macro MorphAndEnqueuePromiseReaction(implicit context: Context)(
kPromiseReactionJobTaskPromiseOrCapabilityOffset); kPromiseReactionJobTaskPromiseOrCapabilityOffset);
} else { } else {
StaticAssert(reactionType == kPromiseReactionReject); StaticAssert(reactionType == kPromiseReactionReject);
* UnsafeConstCast(& promiseReaction.map) = *UnsafeConstCast(&promiseReaction.map) =
PromiseRejectReactionJobTaskMapConstant(); PromiseRejectReactionJobTaskMapConstant();
const promiseReactionJobTask = const promiseReactionJobTask =
UnsafeCast<PromiseRejectReactionJobTask>(promiseReaction); UnsafeCast<PromiseRejectReactionJobTask>(promiseReaction);
......
...@@ -44,7 +44,7 @@ macro InnerNewJSPromise(implicit context: Context)(): JSPromise { ...@@ -44,7 +44,7 @@ macro InnerNewJSPromise(implicit context: Context)(): JSPromise {
assert(IsFunctionWithPrototypeSlotMap(promiseFun.map)); assert(IsFunctionWithPrototypeSlotMap(promiseFun.map));
const promiseMap = UnsafeCast<Map>(promiseFun.prototype_or_initial_map); const promiseMap = UnsafeCast<Map>(promiseFun.prototype_or_initial_map);
const promiseHeapObject = promise_internal::AllocateJSPromise(context); const promiseHeapObject = promise_internal::AllocateJSPromise(context);
* UnsafeConstCast(& promiseHeapObject.map) = promiseMap; *UnsafeConstCast(&promiseHeapObject.map) = promiseMap;
const promise = UnsafeCast<JSPromise>(promiseHeapObject); const promise = UnsafeCast<JSPromise>(promiseHeapObject);
promise.properties_or_hash = kEmptyFixedArray; promise.properties_or_hash = kEmptyFixedArray;
promise.elements = kEmptyFixedArray; promise.elements = kEmptyFixedArray;
......
...@@ -100,7 +100,7 @@ struct SliceIterator<T: type> { ...@@ -100,7 +100,7 @@ struct SliceIterator<T: type> {
} }
macro Next(): T labels NoMore { macro Next(): T labels NoMore {
return * this.NextReference() otherwise NoMore; return *this.NextReference() otherwise NoMore;
} }
macro NextReference():&T labels NoMore { macro NextReference():&T labels NoMore {
...@@ -172,7 +172,7 @@ macro InitializeFieldsFromIterator<T: type, Iterator: type>( ...@@ -172,7 +172,7 @@ macro InitializeFieldsFromIterator<T: type, Iterator: type>(
let originIterator = originIterator; let originIterator = originIterator;
while (true) { while (true) {
const ref:&T = targetIterator.NextReference() otherwise break; const ref:&T = targetIterator.NextReference() otherwise break;
* ref = originIterator.Next() otherwise unreachable; *ref = originIterator.Next() otherwise unreachable;
} }
} }
// Dummy implementations: do not initialize for UninitializedIterator. // Dummy implementations: do not initialize for UninitializedIterator.
...@@ -187,14 +187,14 @@ extern macro StoreDoubleHole(HeapObject, intptr); ...@@ -187,14 +187,14 @@ extern macro StoreDoubleHole(HeapObject, intptr);
macro LoadFloat64OrHole(r:&float64_or_hole): float64_or_hole { macro LoadFloat64OrHole(r:&float64_or_hole): float64_or_hole {
return float64_or_hole{ return float64_or_hole{
is_hole: IsDoubleHole(r.object, r.offset - kHeapObjectTag), 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) { macro StoreFloat64OrHole(r:&float64_or_hole, value: float64_or_hole) {
if (value.is_hole) { if (value.is_hole) {
StoreDoubleHole(r.object, r.offset - kHeapObjectTag); StoreDoubleHole(r.object, r.offset - kHeapObjectTag);
} else { } 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): ...@@ -233,7 +233,7 @@ builtin WasmAllocateStruct(implicit context: Context)(mapIndex: Smi):
const instanceSize: intptr = const instanceSize: intptr =
unsafe::TimesTaggedSize(Convert<intptr>(map.instance_size_in_words)); unsafe::TimesTaggedSize(Convert<intptr>(map.instance_size_in_words));
const result: HeapObject = unsafe::Allocate(instanceSize); const result: HeapObject = unsafe::Allocate(instanceSize);
* UnsafeConstCast(& result.map) = map; *UnsafeConstCast(&result.map) = map;
return result; return result;
} }
...@@ -247,7 +247,7 @@ builtin WasmAllocateStructWithRtt(implicit context: Context)(rtt: Map): ...@@ -247,7 +247,7 @@ builtin WasmAllocateStructWithRtt(implicit context: Context)(rtt: Map):
const instanceSize: intptr = const instanceSize: intptr =
unsafe::TimesTaggedSize(Convert<intptr>(rtt.instance_size_in_words)); unsafe::TimesTaggedSize(Convert<intptr>(rtt.instance_size_in_words));
const result: HeapObject = unsafe::Allocate(instanceSize); const result: HeapObject = unsafe::Allocate(instanceSize);
* UnsafeConstCast(& result.map) = rtt; *UnsafeConstCast(&result.map) = rtt;
return result; return result;
} }
......
...@@ -129,7 +129,7 @@ macro ExtractFixedArray( ...@@ -129,7 +129,7 @@ macro ExtractFixedArray(
return NewFixedArray( return NewFixedArray(
capacity, capacity,
IteratorSequence<Object>( IteratorSequence<Object>(
(& source.objects).Iterator(first, first + count), (&source.objects).Iterator(first, first + count),
ConstantIterator(TheHole))); ConstantIterator(TheHole)));
} }
macro ExtractFixedDoubleArray( macro ExtractFixedDoubleArray(
...@@ -139,7 +139,7 @@ macro ExtractFixedDoubleArray( ...@@ -139,7 +139,7 @@ macro ExtractFixedDoubleArray(
return NewFixedDoubleArray( return NewFixedDoubleArray(
capacity, capacity,
IteratorSequence<float64_or_hole>( IteratorSequence<float64_or_hole>(
(& source.floats).Iterator(first, first + count), (&source.floats).Iterator(first, first + count),
ConstantIterator(kDoubleHole))); ConstantIterator(kDoubleHole)));
} }
......
...@@ -6,12 +6,13 @@ ...@@ -6,12 +6,13 @@
/* Test mulitline /* Test mulitline
comment comment
*/ */
/*multiline_without_whitespace*/
namespace test { namespace test {
macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool { macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool {
if constexpr ( if constexpr (
(kind == ElementsKind::UINT8_ELEMENTS) || kind == ElementsKind::UINT8_ELEMENTS ||
(kind == ElementsKind::UINT16_ELEMENTS)) { kind == ElementsKind::UINT16_ELEMENTS) {
return true; return true;
} else { } else {
return false; return false;
...@@ -19,9 +20,8 @@ macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool { ...@@ -19,9 +20,8 @@ macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool {
} }
macro ElementsKindTestHelper2(kind: constexpr ElementsKind): constexpr bool { macro ElementsKindTestHelper2(kind: constexpr ElementsKind): constexpr bool {
return ( return kind == ElementsKind::UINT8_ELEMENTS ||
(kind == ElementsKind::UINT8_ELEMENTS) || kind == ElementsKind::UINT16_ELEMENTS;
(kind == ElementsKind::UINT16_ELEMENTS));
} }
macro LabelTestHelper1(): never macro LabelTestHelper1(): never
...@@ -826,25 +826,25 @@ macro TestNewFixedArrayFromSpread(implicit context: Context)(): Object { ...@@ -826,25 +826,25 @@ macro TestNewFixedArrayFromSpread(implicit context: Context)(): Object {
class SmiPair extends HeapObject { class SmiPair extends HeapObject {
macro GetA():&Smi { macro GetA():&Smi {
return & this.a; return &this.a;
} }
a: Smi; a: Smi;
b: Smi; b: Smi;
} }
macro Swap<T: type>(a:&T, b:&T) { macro Swap<T: type>(a:&T, b:&T) {
const tmp = * a; const tmp = *a;
* a = * b; *a = *b;
* b = tmp; *b = tmp;
} }
@export @export
macro TestReferences() { macro TestReferences() {
const array = new SmiPair{a: 7, b: 2}; const array = new SmiPair{a: 7, b: 2};
const ref:&Smi = & array.a; const ref:&Smi = &array.a;
* ref = 3 + * ref; *ref = 3 + *ref;
-- * ref; -- *ref;
Swap(& array.b, array.GetA()); Swap(&array.b, array.GetA());
check(array.a == 2); check(array.a == 2);
check(array.b == 9); check(array.b == 9);
} }
...@@ -857,15 +857,15 @@ macro TestSlices() { ...@@ -857,15 +857,15 @@ macro TestSlices() {
const oneTwoThree = Convert<Smi>(123); const oneTwoThree = Convert<Smi>(123);
a.objects[0] = oneTwoThree; a.objects[0] = oneTwoThree;
const firstRef:&Object = & a.objects[0]; const firstRef:&Object = &a.objects[0];
check(TaggedEqual(* firstRef, oneTwoThree)); 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; const firstRefAgain:&Object = slice.TryAtIndex(0) otherwise unreachable;
check(TaggedEqual(* firstRefAgain, oneTwoThree)); check(TaggedEqual(*firstRefAgain, oneTwoThree));
const threeTwoOne = Convert<Smi>(321); const threeTwoOne = Convert<Smi>(321);
* firstRefAgain = threeTwoOne; *firstRefAgain = threeTwoOne;
check(TaggedEqual(a.objects[0], threeTwoOne)); check(TaggedEqual(a.objects[0], threeTwoOne));
// *slice; // error, not allowed // *slice; // error, not allowed
...@@ -885,12 +885,12 @@ macro TestSliceEnumeration(implicit context: Context)(): Undefined { ...@@ -885,12 +885,12 @@ macro TestSliceEnumeration(implicit context: Context)(): Undefined {
fixedArray.objects[i] = Convert<Smi>(i) + 3; fixedArray.objects[i] = Convert<Smi>(i) + 3;
} }
let slice = & fixedArray.objects; let slice = &fixedArray.objects;
for (let i: intptr = 0; i < slice.length; i++) { for (let i: intptr = 0; i < slice.length; i++) {
let ref = slice.TryAtIndex(i) otherwise unreachable; let ref = slice.TryAtIndex(i) otherwise unreachable;
const value = UnsafeCast<Smi>(* ref); const value = UnsafeCast<Smi>(*ref);
check(value == Convert<Smi>(i) + 3); check(value == Convert<Smi>(i) + 3);
* ref = value + 4; *ref = value + 4;
} }
let it = slice.Iterator(); let it = slice.Iterator();
......
...@@ -16,8 +16,20 @@ import re ...@@ -16,8 +16,20 @@ import re
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
kPercentEscape = r'α'; # Unicode alpha kPercentEscape = r'α'; # Unicode alpha
kDerefEscape = r'☆'; # Unicode star
kAddressofEscape = r'⌂'; # Unicode house
def preprocess(input): 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'(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'(\s+)operator\s*(\'[^\']+\')', r'\1/*_OPE \2*/', input)
input = re.sub(r'\btypeswitch\s*(\([^{]*\))\s{', r' if /*tPsW*/ \1 {', input) input = re.sub(r'\btypeswitch\s*(\([^{]*\))\s{', r' if /*tPsW*/ \1 {', input)
...@@ -35,12 +47,7 @@ def preprocess(input): ...@@ -35,12 +47,7 @@ def preprocess(input):
input = re.sub(r'@if\(', r'@iF(', input) input = re.sub(r'@if\(', r'@iF(', input)
input = re.sub(r'@export', r'@eXpOrT', input) input = re.sub(r'@export', r'@eXpOrT', input)
input = re.sub(r'js-implicit[ \n]+', r'jS_iMpLiCiT_', 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); 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)
# includes are not recognized, change them into comments so that the # 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 # formatter ignores them first, until we can figure out a way to format cpp
...@@ -78,6 +85,9 @@ def postprocess(output): ...@@ -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(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(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) 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