]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) | |
3 | * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. | |
ba379fdc | 4 | * Copyright (C) 2009 Torch Mobile, Inc. |
9dae56ea A |
5 | * |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | * | |
20 | */ | |
21 | ||
22 | #ifndef RegExp_h | |
23 | #define RegExp_h | |
24 | ||
9dae56ea | 25 | #include "ExecutableAllocator.h" |
6fe7ccc8 | 26 | #include "MatchResult.h" |
14957cd0 | 27 | #include "RegExpKey.h" |
6fe7ccc8 A |
28 | #include "Structure.h" |
29 | #include "UString.h" | |
30 | #include "yarr/Yarr.h" | |
9dae56ea A |
31 | #include <wtf/Forward.h> |
32 | #include <wtf/RefCounted.h> | |
9dae56ea | 33 | |
6fe7ccc8 A |
34 | #if ENABLE(YARR_JIT) |
35 | #include "yarr/YarrJIT.h" | |
36 | #endif | |
37 | ||
9dae56ea A |
38 | namespace JSC { |
39 | ||
14957cd0 | 40 | struct RegExpRepresentation; |
9dae56ea A |
41 | class JSGlobalData; |
42 | ||
6fe7ccc8 | 43 | JS_EXPORT_PRIVATE RegExpFlags regExpFlags(const UString&); |
14957cd0 A |
44 | |
45 | class RegExp : public JSCell { | |
9dae56ea | 46 | public: |
6fe7ccc8 A |
47 | typedef JSCell Base; |
48 | ||
49 | JS_EXPORT_PRIVATE static RegExp* create(JSGlobalData&, const UString& pattern, RegExpFlags); | |
50 | static void destroy(JSCell*); | |
9dae56ea | 51 | |
14957cd0 A |
52 | bool global() const { return m_flags & FlagGlobal; } |
53 | bool ignoreCase() const { return m_flags & FlagIgnoreCase; } | |
54 | bool multiline() const { return m_flags & FlagMultiline; } | |
9dae56ea | 55 | |
14957cd0 | 56 | const UString& pattern() const { return m_patternString; } |
9dae56ea | 57 | |
14957cd0 | 58 | bool isValid() const { return !m_constructionError && m_flags != InvalidFlags; } |
9dae56ea A |
59 | const char* errorMessage() const { return m_constructionError; } |
60 | ||
6fe7ccc8 A |
61 | JS_EXPORT_PRIVATE int match(JSGlobalData&, const UString&, unsigned startOffset, Vector<int, 32>& ovector); |
62 | MatchResult match(JSGlobalData&, const UString&, unsigned startOffset); | |
9dae56ea A |
63 | unsigned numSubpatterns() const { return m_numSubpatterns; } |
64 | ||
14957cd0 A |
65 | bool hasCode() |
66 | { | |
6fe7ccc8 | 67 | return m_state != NotCompiled; |
14957cd0 A |
68 | } |
69 | ||
70 | void invalidateCode(); | |
71 | ||
72 | #if ENABLE(REGEXP_TRACING) | |
73 | void printTraceData(); | |
74 | #endif | |
75 | ||
6fe7ccc8 | 76 | static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype) |
14957cd0 | 77 | { |
6fe7ccc8 | 78 | return Structure::create(globalData, globalObject, prototype, TypeInfo(LeafType, 0), &s_info); |
14957cd0 A |
79 | } |
80 | ||
6fe7ccc8 | 81 | static const ClassInfo s_info; |
14957cd0 A |
82 | |
83 | RegExpKey key() { return RegExpKey(m_flags, m_patternString); } | |
84 | ||
6fe7ccc8 A |
85 | protected: |
86 | void finishCreation(JSGlobalData&); | |
87 | ||
9dae56ea | 88 | private: |
14957cd0 | 89 | friend class RegExpCache; |
6fe7ccc8 A |
90 | RegExp(JSGlobalData&, const UString&, RegExpFlags); |
91 | ||
92 | static RegExp* createWithoutCaching(JSGlobalData&, const UString&, RegExpFlags); | |
9dae56ea | 93 | |
14957cd0 A |
94 | enum RegExpState { |
95 | ParseError, | |
96 | JITCode, | |
97 | ByteCode, | |
6fe7ccc8 | 98 | NotCompiled |
14957cd0 | 99 | } m_state; |
9dae56ea | 100 | |
6fe7ccc8 A |
101 | void compile(JSGlobalData*, Yarr::YarrCharSize); |
102 | void compileIfNecessary(JSGlobalData&, Yarr::YarrCharSize); | |
103 | ||
104 | void compileMatchOnly(JSGlobalData*, Yarr::YarrCharSize); | |
105 | void compileIfNecessaryMatchOnly(JSGlobalData&, Yarr::YarrCharSize); | |
14957cd0 A |
106 | |
107 | #if ENABLE(YARR_JIT_DEBUG) | |
108 | void matchCompareWithInterpreter(const UString&, int startOffset, int* offsetVector, int jitResult); | |
109 | #endif | |
9dae56ea | 110 | |
14957cd0 A |
111 | UString m_patternString; |
112 | RegExpFlags m_flags; | |
9dae56ea A |
113 | const char* m_constructionError; |
114 | unsigned m_numSubpatterns; | |
14957cd0 A |
115 | #if ENABLE(REGEXP_TRACING) |
116 | unsigned m_rtMatchCallCount; | |
117 | unsigned m_rtMatchFoundCount; | |
9dae56ea | 118 | #endif |
14957cd0 | 119 | |
6fe7ccc8 A |
120 | #if ENABLE(YARR_JIT) |
121 | Yarr::YarrCodeBlock m_regExpJITCode; | |
122 | #endif | |
123 | OwnPtr<Yarr::BytecodePattern> m_regExpBytecode; | |
9dae56ea A |
124 | }; |
125 | ||
126 | } // namespace JSC | |
127 | ||
128 | #endif // RegExp_h |