1 /* 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. 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 25 #include "UString.h" 26 #include "ExecutableAllocator.h" 27 #include "RegExpKey.h" 28 #include <wtf/Forward.h> 29 #include <wtf/RefCounted.h> 30 31 namespace JSC { 32 33 struct RegExpRepresentation; 34 class JSGlobalData; 35 36 RegExpFlags regExpFlags(const UString&); 37 38 class RegExp : public RefCounted<RegExp> { 39 public: 40 static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern, RegExpFlags); 41 ~RegExp(); 42 global()43 bool global() const { return m_flags & FlagGlobal; } ignoreCase()44 bool ignoreCase() const { return m_flags & FlagIgnoreCase; } multiline()45 bool multiline() const { return m_flags & FlagMultiline; } 46 pattern()47 const UString& pattern() const { return m_patternString; } 48 isValid()49 bool isValid() const { return !m_constructionError && m_flags != InvalidFlags; } errorMessage()50 const char* errorMessage() const { return m_constructionError; } 51 52 int match(const UString&, int startOffset, Vector<int, 32>* ovector = 0); numSubpatterns()53 unsigned numSubpatterns() const { return m_numSubpatterns; } 54 55 #if ENABLE(REGEXP_TRACING) 56 void printTraceData(); 57 #endif 58 59 private: 60 RegExp(JSGlobalData* globalData, const UString& pattern, RegExpFlags); 61 62 enum RegExpState { 63 ParseError, 64 JITCode, 65 ByteCode 66 } m_state; 67 68 RegExpState compile(JSGlobalData*); 69 70 #if ENABLE(YARR_JIT_DEBUG) 71 void matchCompareWithInterpreter(const UString&, int startOffset, int* offsetVector, int jitResult); 72 #endif 73 74 UString m_patternString; 75 RegExpFlags m_flags; 76 const char* m_constructionError; 77 unsigned m_numSubpatterns; 78 #if ENABLE(REGEXP_TRACING) 79 unsigned m_rtMatchCallCount; 80 unsigned m_rtMatchFoundCount; 81 #endif 82 83 OwnPtr<RegExpRepresentation> m_representation; 84 }; 85 86 } // namespace JSC 87 88 #endif // RegExp_h 89