#define YarrInterpreter_h
#include "YarrPattern.h"
-#include <wtf/PassOwnPtr.h>
-#include <wtf/unicode/Unicode.h>
namespace WTF {
class BumpPointerAllocator;
unsigned frameLocation;
bool m_capture : 1;
bool m_invert : 1;
- int inputPosition;
+ unsigned inputPosition;
- ByteTerm(UChar ch, int inputPos, unsigned frameLocation, unsigned quantityCount, QuantifierType quantityType)
+ ByteTerm(UChar ch, int inputPos, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
: frameLocation(frameLocation)
, m_capture(false)
, m_invert(false)
atom.patternCharacter = ch;
atom.quantityType = quantityType;
- atom.quantityCount = quantityCount;
+ atom.quantityCount = quantityCount.unsafeGet();
inputPosition = inputPos;
}
- ByteTerm(UChar lo, UChar hi, int inputPos, unsigned frameLocation, unsigned quantityCount, QuantifierType quantityType)
+ ByteTerm(UChar lo, UChar hi, int inputPos, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
: frameLocation(frameLocation)
, m_capture(false)
, m_invert(false)
atom.casedCharacter.lo = lo;
atom.casedCharacter.hi = hi;
atom.quantityType = quantityType;
- atom.quantityCount = quantityCount;
+ atom.quantityCount = quantityCount.unsafeGet();
inputPosition = inputPos;
}
return term;
}
- static ByteTerm CheckInput(unsigned count)
+ static ByteTerm CheckInput(Checked<unsigned> count)
{
ByteTerm term(TypeCheckInput);
- term.checkInputCount = count;
+ term.checkInputCount = count.unsafeGet();
return term;
}
- static ByteTerm UncheckInput(unsigned count)
+ static ByteTerm UncheckInput(Checked<unsigned> count)
{
ByteTerm term(TypeUncheckInput);
- term.checkInputCount = count;
+ term.checkInputCount = count.unsafeGet();
return term;
}
struct BytecodePattern {
WTF_MAKE_FAST_ALLOCATED;
public:
- BytecodePattern(PassOwnPtr<ByteDisjunction> body, Vector<ByteDisjunction*> allParenthesesInfo, YarrPattern& pattern, BumpPointerAllocator* allocator)
- : m_body(body)
+ BytecodePattern(std::unique_ptr<ByteDisjunction> body, Vector<std::unique_ptr<ByteDisjunction>>& parenthesesInfoToAdopt, YarrPattern& pattern, BumpPointerAllocator* allocator)
+ : m_body(WTF::move(body))
, m_ignoreCase(pattern.m_ignoreCase)
, m_multiline(pattern.m_multiline)
, m_allocator(allocator)
{
+ m_body->terms.shrinkToFit();
+
newlineCharacterClass = pattern.newlineCharacterClass();
wordcharCharacterClass = pattern.wordcharCharacterClass();
- m_allParenthesesInfo.append(allParenthesesInfo);
- m_userCharacterClasses.append(pattern.m_userCharacterClasses);
- // 'Steal' the YarrPattern's CharacterClasses! We clear its
- // array, so that it won't delete them on destruction. We'll
- // take responsibility for that.
- pattern.m_userCharacterClasses.clear();
- }
+ m_allParenthesesInfo.swap(parenthesesInfoToAdopt);
+ m_allParenthesesInfo.shrinkToFit();
- ~BytecodePattern()
- {
- deleteAllValues(m_allParenthesesInfo);
- deleteAllValues(m_userCharacterClasses);
+ m_userCharacterClasses.swap(pattern.m_userCharacterClasses);
+ m_userCharacterClasses.shrinkToFit();
}
- OwnPtr<ByteDisjunction> m_body;
+ std::unique_ptr<ByteDisjunction> m_body;
bool m_ignoreCase;
bool m_multiline;
// Each BytecodePattern is associated with a RegExp, each RegExp is associated
- // with a JSGlobalData. Cache a pointer to out JSGlobalData's m_regExpAllocator.
+ // with a VM. Cache a pointer to out VM's m_regExpAllocator.
BumpPointerAllocator* m_allocator;
CharacterClass* newlineCharacterClass;
CharacterClass* wordcharCharacterClass;
private:
- Vector<ByteDisjunction*> m_allParenthesesInfo;
- Vector<CharacterClass*> m_userCharacterClasses;
+ Vector<std::unique_ptr<ByteDisjunction>> m_allParenthesesInfo;
+ Vector<std::unique_ptr<CharacterClass>> m_userCharacterClasses;
};
+JS_EXPORT_PRIVATE std::unique_ptr<BytecodePattern> byteCompile(YarrPattern&, BumpPointerAllocator*);
+JS_EXPORT_PRIVATE unsigned interpret(BytecodePattern*, const String& input, unsigned start, unsigned* output);
+unsigned interpret(BytecodePattern*, const LChar* input, unsigned length, unsigned start, unsigned* output);
+unsigned interpret(BytecodePattern*, const UChar* input, unsigned length, unsigned start, unsigned* output);
+
} } // namespace JSC::Yarr
#endif // YarrInterpreter_h