Changeset 112564 in webkit for trunk/Source/JavaScriptCore/yarr/YarrInterpreter.cpp
- Timestamp:
- Mar 29, 2012, 1:16:03 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/yarr/YarrInterpreter.cpp
r112143 r112564 43 43 namespace JSC { namespace Yarr { 44 44 45 template<typename CharType> 45 46 class Interpreter { 46 47 public: … … 171 172 } 172 173 173 // This class is a placeholder for future character iterator, current174 // proposed name StringConstCharacterIterator.175 class CharAccess {176 public:177 CharAccess(const UString& s)178 {179 if (s.is8Bit()) {180 m_charSize = Char8;181 m_ptr.ptr8 = s.characters8();182 } else {183 m_charSize = Char16;184 m_ptr.ptr16 = s.characters16();185 }186 }187 188 CharAccess(const LChar* ptr)189 : m_charSize(Char8)190 {191 m_ptr.ptr8 = ptr;192 }193 194 CharAccess(const UChar* ptr)195 : m_charSize(Char16)196 {197 m_ptr.ptr16 = ptr;198 }199 200 ~CharAccess()201 {202 }203 204 inline UChar operator[](unsigned index)205 {206 if (m_charSize == Char8)207 return m_ptr.ptr8[index];208 return m_ptr.ptr16[index];209 }210 211 private:212 union {213 const LChar* ptr8;214 const UChar* ptr16;215 } m_ptr;216 YarrCharSize m_charSize;217 };218 219 174 class InputStream { 220 175 public: 221 InputStream(const UString&input, unsigned start, unsigned length)176 InputStream(const CharType* input, unsigned start, unsigned length) 222 177 : input(input) 223 178 , pos(start) … … 333 288 334 289 private: 335 CharAccessinput;290 const CharType* input; 336 291 unsigned pos; 337 292 unsigned length; … … 1490 1445 } 1491 1446 1492 Interpreter(BytecodePattern* pattern, unsigned* output, const UString input, unsigned start, unsigned length)1447 Interpreter(BytecodePattern* pattern, unsigned* output, const CharType* input, unsigned length, unsigned start) 1493 1448 : pattern(pattern) 1494 1449 , output(output) … … 1980 1935 } 1981 1936 1982 unsigned interpret(BytecodePattern* bytecode, const UString& input, unsigned start, unsigned length, unsigned* output)1937 unsigned interpret(BytecodePattern* bytecode, const UString& input, unsigned start, unsigned* output) 1983 1938 { 1984 return Interpreter(bytecode, output, input, start, length).interpret(); 1939 if (input.is8Bit()) 1940 return Interpreter<LChar>(bytecode, output, input.characters8(), input.length(), start).interpret(); 1941 return Interpreter<UChar>(bytecode, output, input.characters16(), input.length(), start).interpret(); 1985 1942 } 1986 1943 1987 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoPatternCharacter) == (YarrStackSpaceForBackTrackInfoPatternCharacter * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoPatternCharacter); 1988 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoCharacterClass) == (YarrStackSpaceForBackTrackInfoCharacterClass * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoCharacterClass); 1989 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoBackReference) == (YarrStackSpaceForBackTrackInfoBackReference * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoBackReference); 1990 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoAlternative) == (YarrStackSpaceForBackTrackInfoAlternative * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoAlternative); 1991 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoParentheticalAssertion) == (YarrStackSpaceForBackTrackInfoParentheticalAssertion * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParentheticalAssertion); 1992 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoParenthesesOnce) == (YarrStackSpaceForBackTrackInfoParenthesesOnce * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParenthesesOnce); 1993 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoParentheses) == (YarrStackSpaceForBackTrackInfoParentheses * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParentheses); 1944 unsigned interpret(BytecodePattern* bytecode, const LChar* input, unsigned length, unsigned start, unsigned* output) 1945 { 1946 return Interpreter<LChar>(bytecode, output, input, length, start).interpret(); 1947 } 1948 1949 unsigned interpret(BytecodePattern* bytecode, const UChar* input, unsigned length, unsigned start, unsigned* output) 1950 { 1951 return Interpreter<UChar>(bytecode, output, input, length, start).interpret(); 1952 } 1953 1954 // These should be the same for both UChar & LChar. 1955 COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoPatternCharacter) == (YarrStackSpaceForBackTrackInfoPatternCharacter * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoPatternCharacter); 1956 COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoCharacterClass) == (YarrStackSpaceForBackTrackInfoCharacterClass * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoCharacterClass); 1957 COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoBackReference) == (YarrStackSpaceForBackTrackInfoBackReference * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoBackReference); 1958 COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoAlternative) == (YarrStackSpaceForBackTrackInfoAlternative * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoAlternative); 1959 COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoParentheticalAssertion) == (YarrStackSpaceForBackTrackInfoParentheticalAssertion * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParentheticalAssertion); 1960 COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoParenthesesOnce) == (YarrStackSpaceForBackTrackInfoParenthesesOnce * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParenthesesOnce); 1961 COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoParentheses) == (YarrStackSpaceForBackTrackInfoParentheses * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParentheses); 1994 1962 1995 1963
Note:
See TracChangeset
for help on using the changeset viewer.