PageRenderTime 34ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 389 lines | 236 code | 44 blank | 109 comment | 11 complexity | 37ab25a4f6cdf0353a1d00d19c9cf481 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 jsscan_h___
  40. #define jsscan_h___
  41. /*
  42. * JS lexical scanner interface.
  43. */
  44. #include <stddef.h>
  45. #include <stdio.h>
  46. #include "jsversion.h"
  47. #include "jsopcode.h"
  48. #include "jsprvtd.h"
  49. #include "jspubtd.h"
  50. JS_BEGIN_EXTERN_C
  51. #define JS_KEYWORD(keyword, type, op, version) \
  52. extern const char js_##keyword##_str[];
  53. #include "jskeyword.tbl"
  54. #undef JS_KEYWORD
  55. typedef enum JSTokenType {
  56. TOK_ERROR = -1, /* well-known as the only code < EOF */
  57. TOK_EOF = 0, /* end of file */
  58. TOK_EOL = 1, /* end of line */
  59. TOK_SEMI = 2, /* semicolon */
  60. TOK_COMMA = 3, /* comma operator */
  61. TOK_ASSIGN = 4, /* assignment ops (= += -= etc.) */
  62. TOK_HOOK = 5, TOK_COLON = 6, /* conditional (?:) */
  63. TOK_OR = 7, /* logical or (||) */
  64. TOK_AND = 8, /* logical and (&&) */
  65. TOK_BITOR = 9, /* bitwise-or (|) */
  66. TOK_BITXOR = 10, /* bitwise-xor (^) */
  67. TOK_BITAND = 11, /* bitwise-and (&) */
  68. TOK_EQOP = 12, /* equality ops (== !=) */
  69. TOK_RELOP = 13, /* relational ops (< <= > >=) */
  70. TOK_SHOP = 14, /* shift ops (<< >> >>>) */
  71. TOK_PLUS = 15, /* plus */
  72. TOK_MINUS = 16, /* minus */
  73. TOK_STAR = 17, TOK_DIVOP = 18, /* multiply/divide ops (* / %) */
  74. TOK_UNARYOP = 19, /* unary prefix operator */
  75. TOK_INC = 20, TOK_DEC = 21, /* increment/decrement (++ --) */
  76. TOK_DOT = 22, /* member operator (.) */
  77. TOK_LB = 23, TOK_RB = 24, /* left and right brackets */
  78. TOK_LC = 25, TOK_RC = 26, /* left and right curlies (braces) */
  79. TOK_LP = 27, TOK_RP = 28, /* left and right parentheses */
  80. TOK_NAME = 29, /* identifier */
  81. TOK_NUMBER = 30, /* numeric constant */
  82. TOK_STRING = 31, /* string constant */
  83. TOK_REGEXP = 32, /* RegExp constant */
  84. TOK_PRIMARY = 33, /* true, false, null, this, super */
  85. TOK_FUNCTION = 34, /* function keyword */
  86. TOK_IF = 35, /* if keyword */
  87. TOK_ELSE = 36, /* else keyword */
  88. TOK_SWITCH = 37, /* switch keyword */
  89. TOK_CASE = 38, /* case keyword */
  90. TOK_DEFAULT = 39, /* default keyword */
  91. TOK_WHILE = 40, /* while keyword */
  92. TOK_DO = 41, /* do keyword */
  93. TOK_FOR = 42, /* for keyword */
  94. TOK_BREAK = 43, /* break keyword */
  95. TOK_CONTINUE = 44, /* continue keyword */
  96. TOK_IN = 45, /* in keyword */
  97. TOK_VAR = 46, /* var keyword */
  98. TOK_WITH = 47, /* with keyword */
  99. TOK_RETURN = 48, /* return keyword */
  100. TOK_NEW = 49, /* new keyword */
  101. TOK_DELETE = 50, /* delete keyword */
  102. TOK_DEFSHARP = 51, /* #n= for object/array initializers */
  103. TOK_USESHARP = 52, /* #n# for object/array initializers */
  104. TOK_TRY = 53, /* try keyword */
  105. TOK_CATCH = 54, /* catch keyword */
  106. TOK_FINALLY = 55, /* finally keyword */
  107. TOK_THROW = 56, /* throw keyword */
  108. TOK_INSTANCEOF = 57, /* instanceof keyword */
  109. TOK_DEBUGGER = 58, /* debugger keyword */
  110. TOK_XMLSTAGO = 59, /* XML start tag open (<) */
  111. TOK_XMLETAGO = 60, /* XML end tag open (</) */
  112. TOK_XMLPTAGC = 61, /* XML point tag close (/>) */
  113. TOK_XMLTAGC = 62, /* XML start or end tag close (>) */
  114. TOK_XMLNAME = 63, /* XML start-tag non-final fragment */
  115. TOK_XMLATTR = 64, /* XML quoted attribute value */
  116. TOK_XMLSPACE = 65, /* XML whitespace */
  117. TOK_XMLTEXT = 66, /* XML text */
  118. TOK_XMLCOMMENT = 67, /* XML comment */
  119. TOK_XMLCDATA = 68, /* XML CDATA section */
  120. TOK_XMLPI = 69, /* XML processing instruction */
  121. TOK_AT = 70, /* XML attribute op (@) */
  122. TOK_DBLCOLON = 71, /* namespace qualified name op (::) */
  123. TOK_ANYNAME = 72, /* XML AnyName singleton (*) */
  124. TOK_DBLDOT = 73, /* XML descendant op (..) */
  125. TOK_FILTER = 74, /* XML filtering predicate op (.()) */
  126. TOK_XMLELEM = 75, /* XML element node type (no token) */
  127. TOK_XMLLIST = 76, /* XML list node type (no token) */
  128. TOK_YIELD = 77, /* yield from generator function */
  129. TOK_ARRAYCOMP = 78, /* array comprehension initialiser */
  130. TOK_ARRAYPUSH = 79, /* array push within comprehension */
  131. TOK_LEXICALSCOPE = 80, /* block scope AST node label */
  132. TOK_LET = 81, /* let keyword */
  133. TOK_SEQ = 82, /* synthetic sequence of statements,
  134. not a block */
  135. TOK_FORHEAD = 83, /* head of for(;;)-style loop */
  136. TOK_RESERVED, /* reserved keywords */
  137. TOK_LIMIT /* domain size */
  138. } JSTokenType;
  139. #define IS_PRIMARY_TOKEN(tt) \
  140. ((uintN)((tt) - TOK_NAME) <= (uintN)(TOK_PRIMARY - TOK_NAME))
  141. #define TOKEN_TYPE_IS_XML(tt) \
  142. (tt == TOK_AT || tt == TOK_DBLCOLON || tt == TOK_ANYNAME)
  143. #if JS_HAS_BLOCK_SCOPE
  144. # define TOKEN_TYPE_IS_DECL(tt) ((tt) == TOK_VAR || (tt) == TOK_LET)
  145. #else
  146. # define TOKEN_TYPE_IS_DECL(tt) ((tt) == TOK_VAR)
  147. #endif
  148. struct JSStringBuffer {
  149. jschar *base;
  150. jschar *limit; /* length limit for quick bounds check */
  151. jschar *ptr; /* slot for next non-NUL char to store */
  152. void *data;
  153. JSBool (*grow)(JSStringBuffer *sb, size_t newlength);
  154. void (*free)(JSStringBuffer *sb);
  155. };
  156. #define STRING_BUFFER_ERROR_BASE ((jschar *) 1)
  157. #define STRING_BUFFER_OK(sb) ((sb)->base != STRING_BUFFER_ERROR_BASE)
  158. #define STRING_BUFFER_OFFSET(sb) ((sb)->ptr -(sb)->base)
  159. extern void
  160. js_InitStringBuffer(JSStringBuffer *sb);
  161. extern void
  162. js_FinishStringBuffer(JSStringBuffer *sb);
  163. extern void
  164. js_AppendChar(JSStringBuffer *sb, jschar c);
  165. extern void
  166. js_RepeatChar(JSStringBuffer *sb, jschar c, uintN count);
  167. extern void
  168. js_AppendCString(JSStringBuffer *sb, const char *asciiz);
  169. extern void
  170. js_AppendUCString(JSStringBuffer *sb, const jschar *buf, uintN len);
  171. extern void
  172. js_AppendJSString(JSStringBuffer *sb, JSString *str);
  173. struct JSTokenPtr {
  174. uint16 index; /* index of char in physical line */
  175. uint16 lineno; /* physical line number */
  176. };
  177. struct JSTokenPos {
  178. JSTokenPtr begin; /* first character and line of token */
  179. JSTokenPtr end; /* index 1 past last char, last line */
  180. };
  181. struct JSToken {
  182. JSTokenType type; /* char value or above enumerator */
  183. JSTokenPos pos; /* token position in file */
  184. jschar *ptr; /* beginning of token in line buffer */
  185. union {
  186. struct { /* name or string literal */
  187. JSOp op; /* operator, for minimal parser */
  188. JSAtom *atom; /* atom table entry */
  189. } s;
  190. uintN reflags; /* regexp flags, use tokenbuf to access
  191. regexp chars */
  192. struct { /* atom pair, for XML PIs */
  193. JSAtom *atom2; /* auxiliary atom table entry */
  194. JSAtom *atom; /* main atom table entry */
  195. } p;
  196. jsdouble dval; /* floating point number */
  197. } u;
  198. };
  199. #define t_op u.s.op
  200. #define t_reflags u.reflags
  201. #define t_atom u.s.atom
  202. #define t_atom2 u.p.atom2
  203. #define t_dval u.dval
  204. typedef struct JSTokenBuf {
  205. jschar *base; /* base of line or stream buffer */
  206. jschar *limit; /* limit for quick bounds check */
  207. jschar *ptr; /* next char to get, or slot to use */
  208. } JSTokenBuf;
  209. #define JS_LINE_LIMIT 256 /* logical line buffer size limit --
  210. physical line length is unlimited */
  211. #define NTOKENS 4 /* 1 current + 2 lookahead, rounded */
  212. #define NTOKENS_MASK (NTOKENS-1) /* to power of 2 to avoid divmod by 3 */
  213. struct JSTokenStream {
  214. JSToken tokens[NTOKENS];/* circular token buffer */
  215. uintN cursor; /* index of last parsed token */
  216. uintN lookahead; /* count of lookahead tokens */
  217. uintN lineno; /* current line number */
  218. uintN ungetpos; /* next free char slot in ungetbuf */
  219. jschar ungetbuf[6]; /* at most 6, for \uXXXX lookahead */
  220. uintN flags; /* flags -- see below */
  221. ptrdiff_t linelen; /* physical linebuf segment length */
  222. ptrdiff_t linepos; /* linebuf offset in physical line */
  223. JSTokenBuf linebuf; /* line buffer for diagnostics */
  224. JSTokenBuf userbuf; /* user input buffer if !file */
  225. JSStringBuffer tokenbuf; /* current token string buffer */
  226. const char *filename; /* input filename or null */
  227. FILE *file; /* stdio stream if reading from file */
  228. JSSourceHandler listener; /* callback for source; eg debugger */
  229. void *listenerData; /* listener 'this' data */
  230. void *listenerTSData;/* listener data for this TokenStream */
  231. jschar *saveEOL; /* save next end of line in userbuf, to
  232. optimize for very long lines */
  233. };
  234. #define CURRENT_TOKEN(ts) ((ts)->tokens[(ts)->cursor])
  235. #define ON_CURRENT_LINE(ts,pos) ((uint16)(ts)->lineno == (pos).end.lineno)
  236. /* JSTokenStream flags */
  237. #define TSF_ERROR 0x01 /* fatal error while compiling */
  238. #define TSF_EOF 0x02 /* hit end of file */
  239. #define TSF_NEWLINES 0x04 /* tokenize newlines */
  240. #define TSF_OPERAND 0x08 /* looking for operand, not operator */
  241. #define TSF_NLFLAG 0x20 /* last linebuf ended with \n */
  242. #define TSF_CRFLAG 0x40 /* linebuf would have ended with \r */
  243. #define TSF_DIRTYLINE 0x80 /* non-whitespace since start of line */
  244. #define TSF_OWNFILENAME 0x100 /* ts->filename is malloc'd */
  245. #define TSF_XMLTAGMODE 0x200 /* scanning within an XML tag in E4X */
  246. #define TSF_XMLTEXTMODE 0x400 /* scanning XMLText terminal from E4X */
  247. #define TSF_XMLONLYMODE 0x800 /* don't scan {expr} within text/tag */
  248. /* Flag indicating unexpected end of input, i.e. TOK_EOF not at top-level. */
  249. #define TSF_UNEXPECTED_EOF 0x1000
  250. /*
  251. * To handle the hard case of contiguous HTML comments, we want to clear the
  252. * TSF_DIRTYINPUT flag at the end of each such comment. But we'd rather not
  253. * scan for --> within every //-style comment unless we have to. So we set
  254. * TSF_IN_HTML_COMMENT when a <!-- is scanned as an HTML begin-comment, and
  255. * clear it (and TSF_DIRTYINPUT) when we scan --> either on a clean line, or
  256. * only if (ts->flags & TSF_IN_HTML_COMMENT), in a //-style comment.
  257. *
  258. * This still works as before given a malformed comment hiding hack such as:
  259. *
  260. * <script>
  261. * <!-- comment hiding hack #1
  262. * code goes here
  263. * // --> oops, markup for script-unaware browsers goes here!
  264. * </script>
  265. *
  266. * It does not cope with malformed comment hiding hacks where --> is hidden
  267. * by C-style comments, or on a dirty line. Such cases are already broken.
  268. */
  269. #define TSF_IN_HTML_COMMENT 0x2000
  270. /* Ignore keywords and return TOK_NAME instead to the parser. */
  271. #define TSF_KEYWORD_IS_NAME 0x4000
  272. /* Unicode separators that are treated as line terminators, in addition to \n, \r */
  273. #define LINE_SEPARATOR 0x2028
  274. #define PARA_SEPARATOR 0x2029
  275. /*
  276. * Create a new token stream, either from an input buffer or from a file.
  277. * Return null on file-open or memory-allocation failure.
  278. *
  279. * The function uses JSContext.tempPool to allocate internal buffers. The
  280. * caller should release them using JS_ARENA_RELEASE after it has finished
  281. * with the token stream and has called js_CloseTokenStream.
  282. */
  283. extern JSBool
  284. js_InitTokenStream(JSContext *cx, JSTokenStream *ts,
  285. const jschar *base, size_t length,
  286. FILE *fp, const char *filename, uintN lineno);
  287. extern void
  288. js_CloseTokenStream(JSContext *cx, JSTokenStream *ts);
  289. extern JS_FRIEND_API(int)
  290. js_fgets(char *buf, int size, FILE *file);
  291. /*
  292. * If the given char array forms JavaScript keyword, return corresponding
  293. * token. Otherwise return TOK_EOF.
  294. */
  295. extern JSTokenType
  296. js_CheckKeyword(const jschar *chars, size_t length);
  297. /*
  298. * Friend-exported API entry point to call a mapping function on each reserved
  299. * identifier in the scanner's keyword table.
  300. */
  301. extern JS_FRIEND_API(void)
  302. js_MapKeywords(void (*mapfun)(const char *));
  303. /*
  304. * Check that str forms a valid JS identifier name. The function does not
  305. * check if str is a JS keyword.
  306. */
  307. extern JSBool
  308. js_IsIdentifier(JSString *str);
  309. /*
  310. * Report a compile-time error by its number. Return true for a warning, false
  311. * for an error. When pn is not null, use it to report error's location.
  312. * Otherwise use ts, which must not be null.
  313. */
  314. JSBool
  315. js_ReportCompileErrorNumber(JSContext *cx, JSTokenStream *ts, JSParseNode *pn,
  316. uintN flags, uintN errorNumber, ...);
  317. /*
  318. * Steal one JSREPORT_* bit (see jsapi.h) to tell that arguments to the error
  319. * message have const jschar* type, not const char*.
  320. */
  321. #define JSREPORT_UC 0x100
  322. /*
  323. * Look ahead one token and return its type.
  324. */
  325. extern JSTokenType
  326. js_PeekToken(JSContext *cx, JSTokenStream *ts);
  327. extern JSTokenType
  328. js_PeekTokenSameLine(JSContext *cx, JSTokenStream *ts);
  329. /*
  330. * Get the next token from ts.
  331. */
  332. extern JSTokenType
  333. js_GetToken(JSContext *cx, JSTokenStream *ts);
  334. /*
  335. * Push back the last scanned token onto ts.
  336. */
  337. extern void
  338. js_UngetToken(JSTokenStream *ts);
  339. /*
  340. * Get the next token from ts if its type is tt.
  341. */
  342. extern JSBool
  343. js_MatchToken(JSContext *cx, JSTokenStream *ts, JSTokenType tt);
  344. JS_END_EXTERN_C
  345. #endif /* jsscan_h___ */