PageRenderTime 25ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/jsregexp.h

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 192 lines | 94 code | 27 blank | 71 comment | 3 complexity | da89c68f5ba63c2ae327c3e58e0d9cd3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  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. #ifndef jsregexp_h___
  40. #define jsregexp_h___
  41. /*
  42. * JS regular expression interface.
  43. */
  44. #include <stddef.h>
  45. #include "jspubtd.h"
  46. #include "jsstr.h"
  47. #ifdef JS_THREADSAFE
  48. #include "jsdhash.h"
  49. #endif
  50. JS_BEGIN_EXTERN_C
  51. struct JSRegExpStatics {
  52. JSString *input; /* input string to match (perl $_, GC root) */
  53. JSBool multiline; /* whether input contains newlines (perl $*) */
  54. uint16 parenCount; /* number of valid elements in parens[] */
  55. uint16 moreLength; /* number of allocated elements in moreParens */
  56. JSSubString parens[9]; /* last set of parens matched (perl $1, $2) */
  57. JSSubString *moreParens; /* null or realloc'd vector for $10, etc. */
  58. JSSubString lastMatch; /* last string matched (perl $&) */
  59. JSSubString lastParen; /* last paren matched (perl $+) */
  60. JSSubString leftContext; /* input to left of last match (perl $`) */
  61. JSSubString rightContext; /* input to right of last match (perl $') */
  62. };
  63. /*
  64. * This struct holds a bitmap representation of a class from a regexp.
  65. * There's a list of these referenced by the classList field in the JSRegExp
  66. * struct below. The initial state has startIndex set to the offset in the
  67. * original regexp source of the beginning of the class contents. The first
  68. * use of the class converts the source representation into a bitmap.
  69. *
  70. */
  71. typedef struct RECharSet {
  72. JSPackedBool converted;
  73. JSPackedBool sense;
  74. uint16 length;
  75. union {
  76. uint8 *bits;
  77. struct {
  78. size_t startIndex;
  79. size_t length;
  80. } src;
  81. } u;
  82. } RECharSet;
  83. /*
  84. * This macro is safe because moreParens is guaranteed to be allocated and big
  85. * enough to hold parenCount, or else be null when parenCount is 0.
  86. */
  87. #define REGEXP_PAREN_SUBSTRING(res, num) \
  88. (((jsuint)(num) < (jsuint)(res)->parenCount) \
  89. ? ((jsuint)(num) < 9) \
  90. ? &(res)->parens[num] \
  91. : &(res)->moreParens[(num) - 9] \
  92. : &js_EmptySubString)
  93. typedef struct RENode RENode;
  94. struct JSRegExp {
  95. jsrefcount nrefs; /* reference count */
  96. uint16 flags; /* flags, see jsapi.h's JSREG_* defines */
  97. size_t parenCount; /* number of parenthesized submatches */
  98. size_t classCount; /* count [...] bitmaps */
  99. RECharSet *classList; /* list of [...] bitmaps */
  100. JSString *source; /* locked source string, sans // */
  101. jsbytecode program[1]; /* regular expression bytecode */
  102. };
  103. extern JSRegExp *
  104. js_NewRegExp(JSContext *cx, JSTokenStream *ts,
  105. JSString *str, uintN flags, JSBool flat);
  106. extern JSRegExp *
  107. js_NewRegExpOpt(JSContext *cx, JSString *str, JSString *opt, JSBool flat);
  108. #define HOLD_REGEXP(cx, re) JS_ATOMIC_INCREMENT(&(re)->nrefs)
  109. #define DROP_REGEXP(cx, re) js_DestroyRegExp(cx, re)
  110. extern void
  111. js_DestroyRegExp(JSContext *cx, JSRegExp *re);
  112. /*
  113. * Execute re on input str at *indexp, returning null in *rval on mismatch.
  114. * On match, return true if test is true, otherwise return an array object.
  115. * Update *indexp and cx->regExpStatics always on match.
  116. */
  117. extern JSBool
  118. js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
  119. JSBool test, jsval *rval);
  120. /*
  121. * These two add and remove GC roots, respectively, so their calls must be
  122. * well-ordered.
  123. */
  124. extern JSBool
  125. js_InitRegExpStatics(JSContext *cx, JSRegExpStatics *res);
  126. extern void
  127. js_FreeRegExpStatics(JSContext *cx, JSRegExpStatics *res);
  128. #define VALUE_IS_REGEXP(cx, v) \
  129. (JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) && \
  130. OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_RegExpClass)
  131. extern JSClass js_RegExpClass;
  132. enum regexp_tinyid {
  133. REGEXP_SOURCE = -1,
  134. REGEXP_GLOBAL = -2,
  135. REGEXP_IGNORE_CASE = -3,
  136. REGEXP_LAST_INDEX = -4,
  137. REGEXP_MULTILINE = -5,
  138. REGEXP_STICKY = -6
  139. };
  140. extern JSObject *
  141. js_InitRegExpClass(JSContext *cx, JSObject *obj);
  142. /*
  143. * Export js_regexp_toString to the decompiler.
  144. */
  145. extern JSBool
  146. js_regexp_toString(JSContext *cx, JSObject *obj, jsval *vp);
  147. /*
  148. * Create, serialize/deserialize, or clone a RegExp object.
  149. */
  150. extern JSObject *
  151. js_NewRegExpObject(JSContext *cx, JSTokenStream *ts,
  152. jschar *chars, size_t length, uintN flags);
  153. extern JSBool
  154. js_XDRRegExp(JSXDRState *xdr, JSObject **objp);
  155. extern JSObject *
  156. js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *parent);
  157. /*
  158. * Get and set the per-object (clone or clone-parent) lastIndex slot.
  159. */
  160. extern JSBool
  161. js_GetLastIndex(JSContext *cx, JSObject *obj, jsdouble *lastIndex);
  162. extern JSBool
  163. js_SetLastIndex(JSContext *cx, JSObject *obj, jsdouble lastIndex);
  164. JS_END_EXTERN_C
  165. #endif /* jsregexp_h___ */