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"
29 #include "yarr/Yarr.h"
30 #include <wtf/Forward.h>
31 #include <wtf/RefCounted.h>
32 #include <wtf/text/WTFString.h>
35 #include "yarr/YarrJIT.h"
40 struct RegExpRepresentation
;
43 JS_EXPORT_PRIVATE RegExpFlags
regExpFlags(const String
&);
45 class RegExp
: public JSCell
{
49 JS_EXPORT_PRIVATE
static RegExp
* create(VM
&, const String
& pattern
, RegExpFlags
);
50 static const bool needsDestruction
= true;
51 static const bool hasImmortalStructure
= true;
52 static void destroy(JSCell
*);
54 bool global() const { return m_flags
& FlagGlobal
; }
55 bool ignoreCase() const { return m_flags
& FlagIgnoreCase
; }
56 bool multiline() const { return m_flags
& FlagMultiline
; }
58 const String
& pattern() const { return m_patternString
; }
60 bool isValid() const { return !m_constructionError
&& m_flags
!= InvalidFlags
; }
61 const char* errorMessage() const { return m_constructionError
; }
63 JS_EXPORT_PRIVATE
int match(VM
&, const String
&, unsigned startOffset
, Vector
<int, 32>& ovector
);
64 MatchResult
match(VM
&, const String
&, unsigned startOffset
);
65 unsigned numSubpatterns() const { return m_numSubpatterns
; }
69 return m_state
!= NotCompiled
;
72 void invalidateCode();
74 #if ENABLE(REGEXP_TRACING)
75 void printTraceData();
78 static Structure
* createStructure(VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
)
80 return Structure::create(vm
, globalObject
, prototype
, TypeInfo(LeafType
, 0), &s_info
);
83 static const ClassInfo s_info
;
85 RegExpKey
key() { return RegExpKey(m_flags
, m_patternString
); }
88 void finishCreation(VM
&);
91 friend class RegExpCache
;
92 RegExp(VM
&, const String
&, RegExpFlags
);
94 static RegExp
* createWithoutCaching(VM
&, const String
&, RegExpFlags
);
103 void compile(VM
*, Yarr::YarrCharSize
);
104 void compileIfNecessary(VM
&, Yarr::YarrCharSize
);
106 void compileMatchOnly(VM
*, Yarr::YarrCharSize
);
107 void compileIfNecessaryMatchOnly(VM
&, Yarr::YarrCharSize
);
109 #if ENABLE(YARR_JIT_DEBUG)
110 void matchCompareWithInterpreter(const String
&, int startOffset
, int* offsetVector
, int jitResult
);
113 String m_patternString
;
115 const char* m_constructionError
;
116 unsigned m_numSubpatterns
;
117 #if ENABLE(REGEXP_TRACING)
118 unsigned m_rtMatchCallCount
;
119 unsigned m_rtMatchFoundCount
;
123 Yarr::YarrCodeBlock m_regExpJITCode
;
125 OwnPtr
<Yarr::BytecodePattern
> m_regExpBytecode
;