Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: src/jsregexp.h

Issue 28311: Flattened the representation of compiled RegExp data. (Closed)
Patch Set: ... and it lints. Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/factory.cc ('k') | src/jsregexp.cc » ('j') | src/jsregexp.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 bool* has_pending_exception); 44 bool* has_pending_exception);
45 45
46 // Returns a string representation of a regular expression. 46 // Returns a string representation of a regular expression.
47 // Implements RegExp.prototype.toString, see ECMA-262 section 15.10.6.4. 47 // Implements RegExp.prototype.toString, see ECMA-262 section 15.10.6.4.
48 // This function calls the garbage collector if necessary. 48 // This function calls the garbage collector if necessary.
49 static Handle<String> ToString(Handle<Object> value); 49 static Handle<String> ToString(Handle<Object> value);
50 50
51 // Parses the RegExp pattern and prepares the JSRegExp object with 51 // Parses the RegExp pattern and prepares the JSRegExp object with
52 // generic data and choice of implementation - as well as what 52 // generic data and choice of implementation - as well as what
53 // the implementation wants to store in the data field. 53 // the implementation wants to store in the data field.
54 // Returns false if compilation fails.
54 static Handle<Object> Compile(Handle<JSRegExp> re, 55 static Handle<Object> Compile(Handle<JSRegExp> re,
55 Handle<String> pattern, 56 Handle<String> pattern,
56 Handle<String> flags); 57 Handle<String> flags);
57 58
58 // See ECMA-262 section 15.10.6.2. 59 // See ECMA-262 section 15.10.6.2.
59 // This function calls the garbage collector if necessary. 60 // This function calls the garbage collector if necessary.
60 static Handle<Object> Exec(Handle<JSRegExp> regexp, 61 static Handle<Object> Exec(Handle<JSRegExp> regexp,
61 Handle<String> subject, 62 Handle<String> subject,
62 int index, 63 int index,
63 Handle<JSArray> lastMatchInfo); 64 Handle<JSArray> lastMatchInfo);
64 65
65 // Call RegExp.prototyp.exec(string) in a loop. 66 // Call RegExp.prototyp.exec(string) in a loop.
66 // Used by String.prototype.match and String.prototype.replace. 67 // Used by String.prototype.match and String.prototype.replace.
67 // This function calls the garbage collector if necessary. 68 // This function calls the garbage collector if necessary.
68 static Handle<Object> ExecGlobal(Handle<JSRegExp> regexp, 69 static Handle<Object> ExecGlobal(Handle<JSRegExp> regexp,
69 Handle<String> subject, 70 Handle<String> subject,
70 Handle<JSArray> lastMatchInfo); 71 Handle<JSArray> lastMatchInfo);
71 72
72 // Prepares a JSRegExp object with Irregexp-specific data. 73 // Prepares a JSRegExp object with Irregexp-specific data.
73 static Handle<Object> IrregexpPrepare(Handle<JSRegExp> re, 74 static void IrregexpPrepare(Handle<JSRegExp> re,
74 Handle<String> pattern, 75 Handle<String> pattern,
75 JSRegExp::Flags flags); 76 JSRegExp::Flags flags,
77 int capture_register_count);
76 78
77 79
78 static Handle<Object> AtomCompile(Handle<JSRegExp> re, 80 static void AtomCompile(Handle<JSRegExp> re,
79 Handle<String> pattern, 81 Handle<String> pattern,
80 JSRegExp::Flags flags, 82 JSRegExp::Flags flags,
81 Handle<String> match_pattern); 83 Handle<String> match_pattern);
82 static Handle<Object> AtomExec(Handle<JSRegExp> regexp, 84 static Handle<Object> AtomExec(Handle<JSRegExp> regexp,
83 Handle<String> subject, 85 Handle<String> subject,
84 int index, 86 int index,
85 Handle<JSArray> lastMatchInfo); 87 Handle<JSArray> lastMatchInfo);
86 88
87 static Handle<Object> AtomExecGlobal(Handle<JSRegExp> regexp, 89 static Handle<Object> AtomExecGlobal(Handle<JSRegExp> regexp,
88 Handle<String> subject, 90 Handle<String> subject,
89 Handle<JSArray> lastMatchInfo); 91 Handle<JSArray> lastMatchInfo);
90 92
91 // Execute an Irregexp bytecode pattern. 93 // Execute an Irregexp bytecode pattern.
92 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp, 94 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp,
93 Handle<String> subject, 95 Handle<String> subject,
94 int index, 96 int index,
95 Handle<JSArray> lastMatchInfo); 97 Handle<JSArray> lastMatchInfo);
96 98
97 static Handle<Object> IrregexpExecGlobal(Handle<JSRegExp> regexp, 99 static Handle<Object> IrregexpExecGlobal(Handle<JSRegExp> regexp,
98 Handle<String> subject, 100 Handle<String> subject,
99 Handle<JSArray> lastMatchInfo); 101 Handle<JSArray> lastMatchInfo);
100 102
101 static void NewSpaceCollectionPrologue(); 103 static void NewSpaceCollectionPrologue();
102 static void OldSpaceCollectionPrologue(); 104 static void OldSpaceCollectionPrologue();
103 105
104 // Converts a source string to a 16 bit flat string. The string 106 // Converts a source string to a 16 bit flat string. The string
105 // will be either sequential or it will be a SlicedString backed 107 // will be either sequential or it will be a SlicedString backed
106 // by a flat string. 108 // by a flat string.
107 static Handle<String> StringToTwoByte(Handle<String> pattern); 109 static Handle<String> StringToTwoByte(Handle<String> pattern);
108 static Handle<String> CachedStringToTwoByte(Handle<String> pattern); 110 static Handle<String> CachedStringToTwoByte(Handle<String> pattern);
109 111
110 static const int kIrregexpImplementationIndex = 0;
111 static const int kIrregexpNumberOfCapturesIndex = 1;
112 static const int kIrregexpNumberOfRegistersIndex = 2;
113 static const int kIrregexpCodeIndex = 3;
114 static const int kIrregexpDataLength = 4;
115
116 // Offsets in the lastMatchInfo array. 112 // Offsets in the lastMatchInfo array.
117 static const int kLastCaptureCount = 0; 113 static const int kLastCaptureCount = 0;
118 static const int kLastSubject = 1; 114 static const int kLastSubject = 1;
119 static const int kLastInput = 2; 115 static const int kLastInput = 2;
120 static const int kFirstCapture = 1; 116 static const int kFirstCapture = 1;
121 static const int kLastMatchOverhead = 3; 117 static const int kLastMatchOverhead = 3;
122 static int GetCapture(FixedArray* array, int index) { 118 static int GetCapture(FixedArray* array, int index) {
123 return Smi::cast(array->get(index + kFirstCapture))->value(); 119 return Smi::cast(array->get(index + kFirstCapture))->value();
124 } 120 }
125 static void SetLastCaptureCount(FixedArray* array, int to) { 121 static void SetLastCaptureCount(FixedArray* array, int to) {
126 array->set(kLastCaptureCount, Smi::FromInt(to)); 122 array->set(kLastCaptureCount, Smi::FromInt(to));
127 } 123 }
128 static void SetLastSubject(FixedArray* array, String* to) { 124 static void SetLastSubject(FixedArray* array, String* to) {
129 int capture_count = GetLastCaptureCount(array); 125 int capture_count = GetLastCaptureCount(array);
130 array->set(capture_count + kLastSubject, to); 126 array->set(capture_count + kLastSubject, to);
131 } 127 }
132 static void SetLastInput(FixedArray* array, String* to) { 128 static void SetLastInput(FixedArray* array, String* to) {
133 int capture_count = GetLastCaptureCount(array); 129 int capture_count = GetLastCaptureCount(array);
134 array->set(capture_count + kLastInput, to); 130 array->set(capture_count + kLastInput, to);
135 } 131 }
136 static void SetCapture(FixedArray* array, int index, int to) { 132 static void SetCapture(FixedArray* array, int index, int to) {
137 array->set(index + kFirstCapture, Smi::FromInt(to)); 133 array->set(index + kFirstCapture, Smi::FromInt(to));
138 } 134 }
139 135
140 private: 136 private:
141 static String* last_ascii_string_; 137 static String* last_ascii_string_;
142 static String* two_byte_cached_string_; 138 static String* two_byte_cached_string_;
143 139
140 static bool EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii);
141
142 static int IrregexpMaxRegisterCount(Handle<FixedArray> re);
143 static void SetIrregexpMaxRegisterCount(Handle<FixedArray> re, int value);
144 static int IrregexpNumberOfCaptures(Handle<FixedArray> re); 144 static int IrregexpNumberOfCaptures(Handle<FixedArray> re);
145 static int IrregexpNumberOfRegisters(Handle<FixedArray> re); 145 static int IrregexpNumberOfRegisters(Handle<FixedArray> re);
146 static Handle<ByteArray> IrregexpByteCode(Handle<FixedArray> re); 146 static Handle<ByteArray> IrregexpByteCode(Handle<FixedArray> re,
147 static Handle<Code> IrregexpNativeCode(Handle<FixedArray> re); 147 bool is_ascii);
148 static Handle<Code> IrregexpNativeCode(Handle<FixedArray> re, bool is_ascii);
148 149
149 // On a successful match, the result is a JSArray containing 150 // On a successful match, the result is a JSArray containing
150 // captured positions. On a failure, the result is the null value. 151 // captured positions. On a failure, the result is the null value.
151 // Returns an empty handle in case of an exception. 152 // Returns an empty handle in case of an exception.
152 static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp, 153 static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp,
153 int num_captures, 154 int num_captures,
154 Handle<JSArray> lastMatchInfo, 155 Handle<JSArray> lastMatchInfo,
155 Handle<String> subject16, 156 Handle<String> subject16,
156 int previous_index, 157 int previous_index,
157 int* ovector, 158 int* ovector,
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 RegExpNode* node; 1348 RegExpNode* node;
1348 bool simple; 1349 bool simple;
1349 bool contains_anchor; 1350 bool contains_anchor;
1350 Handle<String> error; 1351 Handle<String> error;
1351 int capture_count; 1352 int capture_count;
1352 }; 1353 };
1353 1354
1354 1355
1355 class RegExpEngine: public AllStatic { 1356 class RegExpEngine: public AllStatic {
1356 public: 1357 public:
1357 static Handle<FixedArray> Compile(RegExpCompileData* input, 1358 struct CompilationResult {
1358 bool ignore_case, 1359 explicit CompilationResult(const char* error_message)
1359 bool multiline, 1360 : error_message(error_message),
1360 Handle<String> pattern, 1361 code(Heap::the_hole_value()),
1361 bool is_ascii); 1362 num_registers(0) {}
1363 CompilationResult(Object* code, int registers)
1364 : error_message(NULL),
1365 code(code),
1366 num_registers(registers) {}
1367 const char* error_message;
1368 Object* code;
1369 int num_registers;
1370 };
1371
1372 static CompilationResult Compile(RegExpCompileData* input,
1373 bool ignore_case,
1374 bool multiline,
1375 Handle<String> pattern,
1376 bool is_ascii);
1362 1377
1363 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); 1378 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case);
1364 }; 1379 };
1365 1380
1366 1381
1367 } } // namespace v8::internal 1382 } } // namespace v8::internal
1368 1383
1369 #endif // V8_JSREGEXP_H_ 1384 #endif // V8_JSREGEXP_H_
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/jsregexp.cc » ('j') | src/jsregexp.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698