]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - wrec/WRECGenerator.h
JavaScriptCore-525.tar.gz
[apple/javascriptcore.git] / wrec / WRECGenerator.h
... / ...
CommitLineData
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#ifndef WRECGenerator_h
27#define WRECGenerator_h
28
29#include <wtf/Platform.h>
30
31#if ENABLE(WREC)
32
33#include "Quantifier.h"
34#include "MacroAssembler.h"
35#include <wtf/ASCIICType.h>
36#include <wtf/unicode/Unicode.h>
37#include "WREC.h"
38
39namespace JSC {
40
41 class JSGlobalData;
42
43 namespace WREC {
44
45 class CharacterRange;
46 class GenerateAtomFunctor;
47 class Parser;
48 struct CharacterClass;
49
50 class Generator : private MacroAssembler {
51 public:
52 using MacroAssembler::Jump;
53 using MacroAssembler::JumpList;
54 using MacroAssembler::Label;
55
56 enum ParenthesesType { Capturing, NonCapturing, Assertion, InvertedAssertion, Error };
57
58 static CompiledRegExp compileRegExp(JSGlobalData*, const UString& pattern, unsigned* numSubpatterns_ptr, const char** error_ptr, RefPtr<ExecutablePool>& pool, bool ignoreCase = false, bool multiline = false);
59
60 Generator(Parser& parser)
61 : m_parser(parser)
62 {
63 }
64
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.
71
72 void generateEnter();
73 void generateSaveIndex();
74 void generateIncrementIndex(Jump* failure = 0);
75 void generateLoadCharacter(JumpList& failures);
76 void generateJumpIfNotEndOfInput(Label);
77 void generateReturnSuccess();
78 void generateReturnFailure();
79
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);
98
99 void terminateAlternative(JumpList& successes, JumpList& failures);
100 void terminateDisjunction(JumpList& successes);
101
102 private:
103 bool generatePatternCharacterPair(JumpList& failures, int ch1, int ch2);
104
105 Parser& m_parser;
106 };
107
108} } // namespace JSC::WREC
109
110#endif // ENABLE(WREC)
111
112#endif // WRECGenerator_h