]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/RegExp.h
JavaScriptCore-7600.1.4.9.tar.gz
[apple/javascriptcore.git] / runtime / RegExp.h
CommitLineData
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 28#include "Structure.h"
6fe7ccc8 29#include "yarr/Yarr.h"
9dae56ea
A
30#include <wtf/Forward.h>
31#include <wtf/RefCounted.h>
93a37866 32#include <wtf/text/WTFString.h>
9dae56ea 33
6fe7ccc8
A
34#if ENABLE(YARR_JIT)
35#include "yarr/YarrJIT.h"
36#endif
37
9dae56ea
A
38namespace JSC {
39
14957cd0 40 struct RegExpRepresentation;
93a37866 41 class VM;
9dae56ea 42
93a37866 43 JS_EXPORT_PRIVATE RegExpFlags regExpFlags(const String&);
14957cd0
A
44
45 class RegExp : public JSCell {
9dae56ea 46 public:
6fe7ccc8
A
47 typedef JSCell Base;
48
93a37866
A
49 JS_EXPORT_PRIVATE static RegExp* create(VM&, const String& pattern, RegExpFlags);
50 static const bool needsDestruction = true;
51 static const bool hasImmortalStructure = true;
6fe7ccc8 52 static void destroy(JSCell*);
9dae56ea 53
14957cd0
A
54 bool global() const { return m_flags & FlagGlobal; }
55 bool ignoreCase() const { return m_flags & FlagIgnoreCase; }
56 bool multiline() const { return m_flags & FlagMultiline; }
9dae56ea 57
93a37866 58 const String& pattern() const { return m_patternString; }
9dae56ea 59
14957cd0 60 bool isValid() const { return !m_constructionError && m_flags != InvalidFlags; }
9dae56ea
A
61 const char* errorMessage() const { return m_constructionError; }
62
93a37866
A
63 JS_EXPORT_PRIVATE int match(VM&, const String&, unsigned startOffset, Vector<int, 32>& ovector);
64 MatchResult match(VM&, const String&, unsigned startOffset);
9dae56ea
A
65 unsigned numSubpatterns() const { return m_numSubpatterns; }
66
14957cd0
A
67 bool hasCode()
68 {
6fe7ccc8 69 return m_state != NotCompiled;
14957cd0
A
70 }
71
72 void invalidateCode();
73
74#if ENABLE(REGEXP_TRACING)
75 void printTraceData();
76#endif
77
93a37866 78 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
14957cd0 79 {
81345200 80 return Structure::create(vm, globalObject, prototype, TypeInfo(LeafType, StructureFlags), info());
14957cd0
A
81 }
82
81345200 83 DECLARE_INFO;
14957cd0
A
84
85 RegExpKey key() { return RegExpKey(m_flags, m_patternString); }
86
6fe7ccc8 87 protected:
81345200
A
88 static const unsigned StructureFlags = StructureIsImmortal;
89
93a37866 90 void finishCreation(VM&);
6fe7ccc8 91
9dae56ea 92 private:
14957cd0 93 friend class RegExpCache;
93a37866 94 RegExp(VM&, const String&, RegExpFlags);
6fe7ccc8 95
93a37866 96 static RegExp* createWithoutCaching(VM&, const String&, RegExpFlags);
9dae56ea 97
14957cd0
A
98 enum RegExpState {
99 ParseError,
100 JITCode,
101 ByteCode,
6fe7ccc8 102 NotCompiled
14957cd0 103 } m_state;
9dae56ea 104
93a37866
A
105 void compile(VM*, Yarr::YarrCharSize);
106 void compileIfNecessary(VM&, Yarr::YarrCharSize);
6fe7ccc8 107
93a37866
A
108 void compileMatchOnly(VM*, Yarr::YarrCharSize);
109 void compileIfNecessaryMatchOnly(VM&, Yarr::YarrCharSize);
14957cd0
A
110
111#if ENABLE(YARR_JIT_DEBUG)
93a37866 112 void matchCompareWithInterpreter(const String&, int startOffset, int* offsetVector, int jitResult);
14957cd0 113#endif
9dae56ea 114
93a37866 115 String m_patternString;
14957cd0 116 RegExpFlags m_flags;
9dae56ea
A
117 const char* m_constructionError;
118 unsigned m_numSubpatterns;
14957cd0 119#if ENABLE(REGEXP_TRACING)
81345200
A
120 double m_rtMatchOnlyTotalSubjectStringLen;
121 double m_rtMatchTotalSubjectStringLen;
122 unsigned m_rtMatchOnlyCallCount;
123 unsigned m_rtMatchOnlyFoundCount;
14957cd0
A
124 unsigned m_rtMatchCallCount;
125 unsigned m_rtMatchFoundCount;
9dae56ea 126#endif
14957cd0 127
6fe7ccc8
A
128#if ENABLE(YARR_JIT)
129 Yarr::YarrCodeBlock m_regExpJITCode;
130#endif
131 OwnPtr<Yarr::BytecodePattern> m_regExpBytecode;
9dae56ea
A
132 };
133
134} // namespace JSC
135
136#endif // RegExp_h