]>
git.saurik.com Git - apple/javascriptcore.git/blob - wrec/WRECGenerator.h
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef WRECGenerator_h
27 #define WRECGenerator_h
29 #include <wtf/Platform.h>
33 #include "Quantifier.h"
34 #include "MacroAssembler.h"
35 #include <wtf/ASCIICType.h>
36 #include <wtf/unicode/Unicode.h>
46 class GenerateAtomFunctor
;
48 struct CharacterClass
;
50 class Generator
: private MacroAssembler
{
52 using MacroAssembler::Jump
;
53 using MacroAssembler::JumpList
;
54 using MacroAssembler::Label
;
56 enum ParenthesesType
{ Capturing
, NonCapturing
, Assertion
, InvertedAssertion
, Error
};
58 static CompiledRegExp
compileRegExp(JSGlobalData
*, const UString
& pattern
, unsigned* numSubpatterns_ptr
, const char** error_ptr
, RefPtr
<ExecutablePool
>& pool
, bool ignoreCase
= false, bool multiline
= false);
60 Generator(Parser
& parser
)
65 static const RegisterID input
= X86::eax
;
66 static const RegisterID length
= X86::ecx
;
67 static const RegisterID index
= X86::edx
;
68 static const RegisterID character
= X86::esi
;
69 static const RegisterID output
= X86::edi
;
70 static const RegisterID repeatCount
= X86::ebx
; // How many times the current atom repeats in the current match.
73 void generateSaveIndex();
74 void generateIncrementIndex(Jump
* failure
= 0);
75 void generateLoadCharacter(JumpList
& failures
);
76 void generateJumpIfNotEndOfInput(Label
);
77 void generateReturnSuccess();
78 void generateReturnFailure();
80 void generateGreedyQuantifier(JumpList
& failures
, GenerateAtomFunctor
& functor
, unsigned min
, unsigned max
);
81 void generateNonGreedyQuantifier(JumpList
& failures
, GenerateAtomFunctor
& functor
, unsigned min
, unsigned max
);
82 void generateBacktrack1();
83 void generateBacktrackBackreference(unsigned subpatternId
);
84 void generateCharacterClass(JumpList
& failures
, const CharacterClass
& charClass
, bool invert
);
85 void generateCharacterClassInverted(JumpList
& failures
, const CharacterClass
& charClass
);
86 void generateCharacterClassInvertedRange(JumpList
& failures
, JumpList
& matchDest
, const CharacterRange
* ranges
, unsigned count
, unsigned* matchIndex
, const UChar
* matches
, unsigned matchCount
);
87 void generatePatternCharacter(JumpList
& failures
, int ch
);
88 void generatePatternCharacterSequence(JumpList
& failures
, int* sequence
, size_t count
);
89 void generateAssertionWordBoundary(JumpList
& failures
, bool invert
);
90 void generateAssertionBOL(JumpList
& failures
);
91 void generateAssertionEOL(JumpList
& failures
);
92 void generateBackreference(JumpList
& failures
, unsigned subpatternID
);
93 void generateBackreferenceQuantifier(JumpList
& failures
, Quantifier::Type quantifierType
, unsigned subpatternId
, unsigned min
, unsigned max
);
94 void generateParenthesesAssertion(JumpList
& failures
);
95 void generateParenthesesInvertedAssertion(JumpList
& failures
);
96 Jump
generateParenthesesResetTrampoline(JumpList
& newFailures
, unsigned subpatternIdBefore
, unsigned subpatternIdAfter
);
97 void generateParenthesesNonGreedy(JumpList
& failures
, Label start
, Jump success
, Jump fail
);
99 void terminateAlternative(JumpList
& successes
, JumpList
& failures
);
100 void terminateDisjunction(JumpList
& successes
);
103 bool generatePatternCharacterPair(JumpList
& failures
, int ch1
, int ch2
);
108 } } // namespace JSC::WREC
110 #endif // ENABLE(WREC)
112 #endif // WRECGenerator_h