2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "ExecutableAllocator.h"
27 #include <wtf/Forward.h>
28 #include <wtf/RefCounted.h>
29 #include "yarr/RegexJIT.h"
30 #include "yarr/RegexInterpreter.h"
38 class RegExp : public RefCounted<RegExp> {
40 static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern);
41 static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern, const UString& flags);
46 bool global() const { return m_flagBits & Global; }
47 bool ignoreCase() const { return m_flagBits & IgnoreCase; }
48 bool multiline() const { return m_flagBits & Multiline; }
50 const UString& pattern() const { return m_pattern; }
51 const UString& flags() const { return m_flags; }
53 bool isValid() const { return !m_constructionError; }
54 const char* errorMessage() const { return m_constructionError; }
56 int match(const UString&, int startOffset, OwnArrayPtr<int>* ovector = 0);
57 unsigned numSubpatterns() const { return m_numSubpatterns; }
60 RegExp(JSGlobalData* globalData, const UString& pattern);
61 RegExp(JSGlobalData* globalData, const UString& pattern, const UString& flags);
63 void compile(JSGlobalData*);
65 enum FlagBits { Global = 1, IgnoreCase = 2, Multiline = 4 };
67 UString m_pattern; // FIXME: Just decompile m_regExp instead of storing this.
68 UString m_flags; // FIXME: Just decompile m_regExp instead of storing this.
70 const char* m_constructionError;
71 unsigned m_numSubpatterns;
74 Yarr::RegexCodeBlock m_regExpJITCode;
76 OwnPtr<Yarr::BytecodePattern> m_regExpBytecode;
79 WREC::CompiledRegExp m_wrecFunction;
80 RefPtr<ExecutablePool> m_executablePool;