2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Torch Mobile, Inc.
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.
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.
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
26 #include "ExecutableAllocator.h"
27 #include "Structure.h"
28 #include "RegExpKey.h"
29 #include "yarr/Yarr.h"
30 #include <wtf/Forward.h>
31 #include <wtf/RefCounted.h>
35 struct RegExpRepresentation;
38 RegExpFlags regExpFlags(const UString&);
40 class RegExp : public JSCell {
44 static RegExp* create(JSGlobalData&, const UString& pattern, RegExpFlags);
47 bool global() const { return m_flags & FlagGlobal; }
48 bool ignoreCase() const { return m_flags & FlagIgnoreCase; }
49 bool multiline() const { return m_flags & FlagMultiline; }
51 const UString& pattern() const { return m_patternString; }
53 bool isValid() const { return !m_constructionError && m_flags != InvalidFlags; }
54 const char* errorMessage() const { return m_constructionError; }
56 int match(JSGlobalData&, const UString&, int startOffset, Vector<int, 32>* ovector = 0);
57 unsigned numSubpatterns() const { return m_numSubpatterns; }
61 return m_representation;
64 void invalidateCode();
66 #if ENABLE(REGEXP_TRACING)
67 void printTraceData();
70 static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
72 return Structure::create(globalData, globalObject, prototype, TypeInfo(LeafType, 0), &s_info);
75 static JS_EXPORTDATA const ClassInfo s_info;
77 RegExpKey key() { return RegExpKey(m_flags, m_patternString); }
80 void finishCreation(JSGlobalData&);
83 friend class RegExpCache;
84 RegExp(JSGlobalData&, const UString&, RegExpFlags);
86 static RegExp* createWithoutCaching(JSGlobalData&, const UString&, RegExpFlags);
95 void compile(JSGlobalData*, Yarr::YarrCharSize);
96 void compileIfNecessary(JSGlobalData&, Yarr::YarrCharSize);
98 #if ENABLE(YARR_JIT_DEBUG)
99 void matchCompareWithInterpreter(const UString&, int startOffset, int* offsetVector, int jitResult);
102 UString m_patternString;
104 const char* m_constructionError;
105 unsigned m_numSubpatterns;
106 #if ENABLE(REGEXP_TRACING)
107 unsigned m_rtMatchCallCount;
108 unsigned m_rtMatchFoundCount;
111 OwnPtr<RegExpRepresentation> m_representation;