Debian Codegraph @

js/src/irregexp/RegExpTypes.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 // This file forward-defines Irregexp classes that need to be visible
8 // to the rest of Spidermonkey and re-exports them into js::irregexp.
9
10 #ifndef regexp_RegExpTypes_h
11 #define regexp_RegExpTypes_h
12
13 #include "js/UniquePtr.h"
14
15 namespace js {
16 class MatchPairs;
17 }
18
19 namespace v8 {
20 namespace internal {
21
22 class ByteArrayData {
23 public:
24 ByteArrayData(uint32_t length) : length_(length) {}
25
26 uint32_t length() { return length_; };
27 uint8_t* data();
28
29 uint8_t get(uint32_t index) {
30 MOZ_ASSERT(index < length());
31 return data()[index];
32 }
33 void set(uint32_t index, uint8_t val) {
34 MOZ_ASSERT(index < length());
35 data()[index] = val;
36 }
37
38 // Used for FixedIntegerArray.
39 template <typename T>
40 T getTyped(uint32_t index);
41 template <typename T>
42 void setTyped(uint32_t index, T value);
43
44 #ifdef DEBUG
45 const static uint32_t ExpectedMagic = 0x12344321;
46 uint32_t magic() const { return magic_; }
47
48 private:
49 uint32_t magic_ = ExpectedMagic;
50 #endif
51
52 private:
53 template <typename T>
54 T* typedData();
55
56 uint32_t length_;
57 };
58
59 class Isolate;
60 class RegExpStack;
61 class RegExpStackScope;
62
63 struct InputOutputData {
64 const void* inputStart;
65 const void* inputEnd;
66
67 // Index into inputStart (in chars) at which to begin matching.
68 size_t startIndex;
69
70 js::MatchPairs* matches;
71
72 template <typename CharT>
73 InputOutputData(const CharT* inputStart, const CharT* inputEnd,
74 size_t startIndex, js::MatchPairs* matches)
75 : inputStart(inputStart),
76 inputEnd(inputEnd),
77 startIndex(startIndex),
78 matches(matches) {}
79
80 // Note: return int32_t instead of size_t to prevent signed => unsigned
81 // conversions in caller functions.
82 static constexpr int32_t offsetOfInputStart() {
83 return int32_t(offsetof(InputOutputData, inputStart));
84 }
85 static constexpr int32_t offsetOfInputEnd() {
86 return int32_t(offsetof(InputOutputData, inputEnd));
87 }
88 static constexpr int32_t offsetOfStartIndex() {
89 return int32_t(offsetof(InputOutputData, startIndex));
90 }
91 static constexpr int32_t offsetOfMatches() {
92 return int32_t(offsetof(InputOutputData, matches));
93 }
94 };
95
96 } // namespace internal
97 } // namespace v8
98
99 namespace js {
100 namespace irregexp {
101
102 using Isolate = v8::internal::Isolate;
103 using RegExpStack = v8::internal::RegExpStack;
104 using RegExpStackScope = v8::internal::RegExpStackScope;
105 using ByteArrayData = v8::internal::ByteArrayData;
106 using ByteArray = js::UniquePtr<v8::internal::ByteArrayData, JS::FreePolicy>;
107 using InputOutputData = v8::internal::InputOutputData;
108
109 } // namespace irregexp
110 } // namespace js
111
112 #endif // regexp_RegExpTypes_h