Line data Source code
1 : // Copyright 2017 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_OBJECTS_REGEXP_MATCH_INFO_H_
6 : #define V8_OBJECTS_REGEXP_MATCH_INFO_H_
7 :
8 : #include "src/base/compiler-specific.h"
9 : #include "src/objects.h"
10 : #include "src/objects/fixed-array.h"
11 :
12 : // Has to be the last include (doesn't have include guards):
13 : #include "src/objects/object-macros.h"
14 :
15 : namespace v8 {
16 : namespace internal {
17 :
18 : class Object;
19 : class String;
20 :
21 : // The property RegExpMatchInfo includes the matchIndices
22 : // array of the last successful regexp match (an array of start/end index
23 : // pairs for the match and all the captured substrings), the invariant is
24 : // that there are at least two capture indices. The array also contains
25 : // the subject string for the last successful match.
26 : // After creation the result must be treated as a FixedArray in all regards.
27 : class V8_EXPORT_PRIVATE RegExpMatchInfo : NON_EXPORTED_BASE(public FixedArray) {
28 : public:
29 : // Returns the number of captures, which is defined as the length of the
30 : // matchIndices objects of the last match. matchIndices contains two indices
31 : // for each capture (including the match itself), i.e. 2 * #captures + 2.
32 : inline int NumberOfCaptureRegisters();
33 : inline void SetNumberOfCaptureRegisters(int value);
34 :
35 : // Returns the subject string of the last match.
36 : inline String LastSubject();
37 : inline void SetLastSubject(String value);
38 :
39 : // Like LastSubject, but modifiable by the user.
40 : inline Object LastInput();
41 : inline void SetLastInput(Object value);
42 :
43 : // Returns the i'th capture index, 0 <= i < NumberOfCaptures(). Capture(0) and
44 : // Capture(1) determine the start- and endpoint of the match itself.
45 : inline int Capture(int i);
46 : inline void SetCapture(int i, int value);
47 :
48 : // Reserves space for captures.
49 : static Handle<RegExpMatchInfo> ReserveCaptures(
50 : Isolate* isolate, Handle<RegExpMatchInfo> match_info, int capture_count);
51 :
52 : DECL_CAST(RegExpMatchInfo)
53 :
54 : static const int kNumberOfCapturesIndex = 0;
55 : static const int kLastSubjectIndex = 1;
56 : static const int kLastInputIndex = 2;
57 : static const int kFirstCaptureIndex = 3;
58 : static const int kLastMatchOverhead = kFirstCaptureIndex;
59 :
60 : // Layout description.
61 : #define REG_EXP_MATCH_INFO_FIELDS(V) \
62 : V(kNumberOfCapturesOffset, kTaggedSize) \
63 : V(kLastSubjectOffset, kTaggedSize) \
64 : V(kLastInputOffset, kTaggedSize) \
65 : V(kFirstCaptureOffset, 0)
66 :
67 : DEFINE_FIELD_OFFSET_CONSTANTS(FixedArray::kHeaderSize,
68 : REG_EXP_MATCH_INFO_FIELDS)
69 : #undef REG_EXP_MATCH_INFO_FIELDS
70 :
71 : // Every match info is guaranteed to have enough space to store two captures.
72 : static const int kInitialCaptureIndices = 2;
73 :
74 846 : OBJECT_CONSTRUCTORS(RegExpMatchInfo, FixedArray);
75 : };
76 :
77 : } // namespace internal
78 : } // namespace v8
79 :
80 : #include "src/objects/object-macros-undef.h"
81 :
82 : #endif // V8_OBJECTS_REGEXP_MATCH_INFO_H_
|