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
25 #include "ExecutableAllocator.h"
26 #include "MatchResult.h"
27 #include "RegExpKey.h"
28 #include "Structure.h"
30 #include "yarr/Yarr.h"
31 #include <wtf/Forward.h>
32 #include <wtf/RefCounted.h>
35 #include "yarr/YarrJIT.h"
40 struct RegExpRepresentation
;
43 JS_EXPORT_PRIVATE RegExpFlags
regExpFlags(const UString
&);
45 class RegExp
: public JSCell
{
49 JS_EXPORT_PRIVATE
static RegExp
* create(JSGlobalData
&, const UString
& pattern
, RegExpFlags
);
50 static void destroy(JSCell
*);
52 bool global() const { return m_flags
& FlagGlobal
; }
53 bool ignoreCase() const { return m_flags
& FlagIgnoreCase
; }
54 bool multiline() const { return m_flags
& FlagMultiline
; }
56 const UString
& pattern() const { return m_patternString
; }
58 bool isValid() const { return !m_constructionError
&& m_flags
!= InvalidFlags
; }
59 const char* errorMessage() const { return m_constructionError
; }
61 JS_EXPORT_PRIVATE
int match(JSGlobalData
&, const UString
&, unsigned startOffset
, Vector
<int, 32>& ovector
);
62 MatchResult
match(JSGlobalData
&, const UString
&, unsigned startOffset
);
63 unsigned numSubpatterns() const { return m_numSubpatterns
; }
67 return m_state
!= NotCompiled
;
70 void invalidateCode();
72 #if ENABLE(REGEXP_TRACING)
73 void printTraceData();
76 static Structure
* createStructure(JSGlobalData
& globalData
, JSGlobalObject
* globalObject
, JSValue prototype
)
78 return Structure::create(globalData
, globalObject
, prototype
, TypeInfo(LeafType
, 0), &s_info
);
81 static const ClassInfo s_info
;
83 RegExpKey
key() { return RegExpKey(m_flags
, m_patternString
); }
86 void finishCreation(JSGlobalData
&);
89 friend class RegExpCache
;
90 RegExp(JSGlobalData
&, const UString
&, RegExpFlags
);
92 static RegExp
* createWithoutCaching(JSGlobalData
&, const UString
&, RegExpFlags
);
101 void compile(JSGlobalData
*, Yarr::YarrCharSize
);
102 void compileIfNecessary(JSGlobalData
&, Yarr::YarrCharSize
);
104 void compileMatchOnly(JSGlobalData
*, Yarr::YarrCharSize
);
105 void compileIfNecessaryMatchOnly(JSGlobalData
&, Yarr::YarrCharSize
);
107 #if ENABLE(YARR_JIT_DEBUG)
108 void matchCompareWithInterpreter(const UString
&, int startOffset
, int* offsetVector
, int jitResult
);
111 UString m_patternString
;
113 const char* m_constructionError
;
114 unsigned m_numSubpatterns
;
115 #if ENABLE(REGEXP_TRACING)
116 unsigned m_rtMatchCallCount
;
117 unsigned m_rtMatchFoundCount
;
121 Yarr::YarrCodeBlock m_regExpJITCode
;
123 OwnPtr
<Yarr::BytecodePattern
> m_regExpBytecode
;