/[jscoverage]/trunk/js/jsregexp.h
ViewVC logotype

Contents of /trunk/js/jsregexp.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 507 - (show annotations)
Sun Jan 10 07:23:34 2010 UTC (9 years, 8 months ago) by siliconforks
File MIME type: text/plain
File size: 7369 byte(s)
Update SpiderMonkey from Firefox 3.6rc1.

1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is Mozilla Communicator client code, released
17 * March 31, 1998.
18 *
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
23 *
24 * Contributor(s):
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 #ifndef jsregexp_h___
41 #define jsregexp_h___
42 /*
43 * JS regular expression interface.
44 */
45 #include <stddef.h>
46 #include "jspubtd.h"
47 #include "jsstr.h"
48
49 #ifdef JS_THREADSAFE
50 #include "jsdhash.h"
51 #endif
52
53 JS_BEGIN_EXTERN_C
54
55 struct JSRegExpStatics {
56 JSString *input; /* input string to match (perl $_, GC root) */
57 JSBool multiline; /* whether input contains newlines (perl $*) */
58 uint16 parenCount; /* number of valid elements in parens[] */
59 uint16 moreLength; /* number of allocated elements in moreParens */
60 JSSubString parens[9]; /* last set of parens matched (perl $1, $2) */
61 JSSubString *moreParens; /* null or realloc'd vector for $10, etc. */
62 JSSubString lastMatch; /* last string matched (perl $&) */
63 JSSubString lastParen; /* last paren matched (perl $+) */
64 JSSubString leftContext; /* input to left of last match (perl $`) */
65 JSSubString rightContext; /* input to right of last match (perl $') */
66 };
67
68 extern JS_FRIEND_API(void)
69 js_SaveAndClearRegExpStatics(JSContext *cx, JSRegExpStatics *statics,
70 JSTempValueRooter *tvr);
71
72 extern JS_FRIEND_API(void)
73 js_RestoreRegExpStatics(JSContext *cx, JSRegExpStatics *statics,
74 JSTempValueRooter *tvr);
75
76 /*
77 * This struct holds a bitmap representation of a class from a regexp.
78 * There's a list of these referenced by the classList field in the JSRegExp
79 * struct below. The initial state has startIndex set to the offset in the
80 * original regexp source of the beginning of the class contents. The first
81 * use of the class converts the source representation into a bitmap.
82 *
83 */
84 typedef struct RECharSet {
85 JSPackedBool converted;
86 JSPackedBool sense;
87 uint16 length;
88 union {
89 uint8 *bits;
90 struct {
91 size_t startIndex;
92 size_t length;
93 } src;
94 } u;
95 } RECharSet;
96
97 /*
98 * This macro is safe because moreParens is guaranteed to be allocated and big
99 * enough to hold parenCount, or else be null when parenCount is 0.
100 */
101 #define REGEXP_PAREN_SUBSTRING(res, num) \
102 (((jsuint)(num) < (jsuint)(res)->parenCount) \
103 ? ((jsuint)(num) < 9) \
104 ? &(res)->parens[num] \
105 : &(res)->moreParens[(num) - 9] \
106 : &js_EmptySubString)
107
108 typedef struct RENode RENode;
109
110 struct JSRegExp {
111 jsrefcount nrefs; /* reference count */
112 uint16 flags; /* flags, see jsapi.h's JSREG_* defines */
113 size_t parenCount; /* number of parenthesized submatches */
114 size_t classCount; /* count [...] bitmaps */
115 RECharSet *classList; /* list of [...] bitmaps */
116 JSString *source; /* locked source string, sans // */
117 jsbytecode program[1]; /* regular expression bytecode */
118 };
119
120 extern JSRegExp *
121 js_NewRegExp(JSContext *cx, JSTokenStream *ts,
122 JSString *str, uintN flags, JSBool flat);
123
124 extern JSRegExp *
125 js_NewRegExpOpt(JSContext *cx, JSString *str, JSString *opt, JSBool flat);
126
127 #define HOLD_REGEXP(cx, re) JS_ATOMIC_INCREMENT(&(re)->nrefs)
128 #define DROP_REGEXP(cx, re) js_DestroyRegExp(cx, re)
129
130 extern void
131 js_DestroyRegExp(JSContext *cx, JSRegExp *re);
132
133 /*
134 * Execute re on input str at *indexp, returning null in *rval on mismatch.
135 * On match, return true if test is true, otherwise return an array object.
136 * Update *indexp and cx->regExpStatics always on match.
137 */
138 extern JSBool
139 js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
140 JSBool test, jsval *rval);
141
142 extern void
143 js_InitRegExpStatics(JSContext *cx);
144
145 extern void
146 js_TraceRegExpStatics(JSTracer *trc, JSContext *acx);
147
148 extern void
149 js_FreeRegExpStatics(JSContext *cx);
150
151 #define VALUE_IS_REGEXP(cx, v) \
152 (JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) && \
153 OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_RegExpClass)
154
155 extern JSClass js_RegExpClass;
156
157 enum regexp_tinyid {
158 REGEXP_SOURCE = -1,
159 REGEXP_GLOBAL = -2,
160 REGEXP_IGNORE_CASE = -3,
161 REGEXP_LAST_INDEX = -4,
162 REGEXP_MULTILINE = -5,
163 REGEXP_STICKY = -6
164 };
165
166 extern JSObject *
167 js_InitRegExpClass(JSContext *cx, JSObject *obj);
168
169 /*
170 * Export js_regexp_toString to the decompiler.
171 */
172 extern JSBool
173 js_regexp_toString(JSContext *cx, JSObject *obj, jsval *vp);
174
175 /*
176 * Create, serialize/deserialize, or clone a RegExp object.
177 */
178 extern JSObject *
179 js_NewRegExpObject(JSContext *cx, JSTokenStream *ts,
180 jschar *chars, size_t length, uintN flags);
181
182 extern JSBool
183 js_XDRRegExpObject(JSXDRState *xdr, JSObject **objp);
184
185 extern JSObject *
186 js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *parent);
187
188 #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
189
190 const uint32 JSSLOT_REGEXP_LAST_INDEX = JSSLOT_PRIVATE + 1;
191 const uint32 REGEXP_CLASS_FIXED_RESERVED_SLOTS = 1;
192
193 static inline void
194 js_ClearRegExpLastIndex(JSObject *obj)
195 {
196 JS_ASSERT(obj->getClass() == &js_RegExpClass);
197 obj->fslots[JSSLOT_REGEXP_LAST_INDEX] = JSVAL_ZERO;
198 }
199
200 #endif /* __cplusplus */
201
202 /* Return whether the given character array contains RegExp meta-characters. */
203 extern bool
204 js_ContainsRegExpMetaChars(const jschar *chars, size_t length);
205
206 JS_END_EXTERN_C
207
208 #endif /* jsregexp_h___ */

  ViewVC Help
Powered by ViewVC 1.1.24