regexp-match-info.tq 1.31 KB
Newer Older
Tobias Tebbi's avatar
Tobias Tebbi committed
1 2 3 4 5
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

@hasSameInstanceTypeAsParent
6
@doNotGenerateCast
Tobias Tebbi's avatar
Tobias Tebbi committed
7
extern class RegExpMatchInfo extends FixedArray {
8 9
  macro GetStartOfCapture(implicit context: Context)(captureIndex:
                                                         constexpr int31): Smi {
Tobias Tebbi's avatar
Tobias Tebbi committed
10 11 12
    const index: constexpr int31 = GetStartOfCaptureIndex(captureIndex);
    return UnsafeCast<Smi>(this.objects[index]);
  }
13 14
  macro GetEndOfCapture(implicit context: Context)(captureIndex:
                                                       constexpr int31): Smi {
Tobias Tebbi's avatar
Tobias Tebbi committed
15 16 17
    const index: constexpr int31 = GetStartOfCaptureIndex(captureIndex) + 1;
    return UnsafeCast<Smi>(this.objects[index]);
  }
18
  macro NumberOfCaptures(implicit context: Context)(): Smi {
Tobias Tebbi's avatar
Tobias Tebbi committed
19 20 21 22 23 24 25 26 27 28 29 30
    return UnsafeCast<Smi>(this.objects[kRegExpMatchInfoNumberOfCapturesIndex]);
  }
}

const kRegExpMatchInfoFirstCaptureIndex:
    constexpr int31 generates 'RegExpMatchInfo::kFirstCaptureIndex';
const kRegExpMatchInfoNumberOfCapturesIndex:
    constexpr int31 generates 'RegExpMatchInfo::kNumberOfCapturesIndex';

macro GetStartOfCaptureIndex(captureIndex: constexpr int31): constexpr int31 {
  return kRegExpMatchInfoFirstCaptureIndex + (captureIndex * 2);
}