--- sbbs/include/mozilla/js/jsscan.h 2018/04/24 16:41:23 1.1 +++ sbbs/include/mozilla/js/jsscan.h 2018/04/24 16:42:11 1.1.1.2 @@ -44,12 +44,18 @@ */ #include #include +#include "jsconfig.h" #include "jsopcode.h" #include "jsprvtd.h" #include "jspubtd.h" JS_BEGIN_EXTERN_C +#define JS_KEYWORD(keyword, type, op, version) \ + extern const char js_##keyword##_str[]; +#include "jskeyword.tbl" +#undef JS_KEYWORD + typedef enum JSTokenType { TOK_ERROR = -1, /* well-known as the only code < EOF */ TOK_EOF = 0, /* end of file */ @@ -107,6 +113,31 @@ typedef enum JSTokenType { TOK_THROW = 58, /* throw keyword */ TOK_INSTANCEOF = 59, /* instanceof keyword */ TOK_DEBUGGER = 60, /* debugger keyword */ + TOK_XMLSTAGO = 61, /* XML start tag open (<) */ + TOK_XMLETAGO = 62, /* XML end tag open () */ + TOK_XMLTAGC = 64, /* XML start or end tag close (>) */ + TOK_XMLNAME = 65, /* XML start-tag non-final fragment */ + TOK_XMLATTR = 66, /* XML quoted attribute value */ + TOK_XMLSPACE = 67, /* XML whitespace */ + TOK_XMLTEXT = 68, /* XML text */ + TOK_XMLCOMMENT = 69, /* XML comment */ + TOK_XMLCDATA = 70, /* XML CDATA section */ + TOK_XMLPI = 71, /* XML processing instruction */ + TOK_AT = 72, /* XML attribute op (@) */ + TOK_DBLCOLON = 73, /* namespace qualified name op (::) */ + TOK_ANYNAME = 74, /* XML AnyName singleton (*) */ + TOK_DBLDOT = 75, /* XML descendant op (..) */ + TOK_FILTER = 76, /* XML filtering predicate op (.()) */ + TOK_XMLELEM = 77, /* XML element node type (no token) */ + TOK_XMLLIST = 78, /* XML list node type (no token) */ + TOK_YIELD = 79, /* yield from generator function */ + TOK_ARRAYCOMP = 80, /* array comprehension initialiser */ + TOK_ARRAYPUSH = 81, /* array push within comprehension */ + TOK_LEXICALSCOPE = 82, /* block scope AST node label */ + TOK_LET = 83, /* let keyword */ + TOK_BODY = 84, /* synthetic body of function with + destructuring formal parameters */ TOK_RESERVED, /* reserved keywords */ TOK_LIMIT /* domain size */ } JSTokenType; @@ -114,6 +145,46 @@ typedef enum JSTokenType { #define IS_PRIMARY_TOKEN(tt) \ ((uintN)((tt) - TOK_NAME) <= (uintN)(TOK_PRIMARY - TOK_NAME)) +#define TOKEN_TYPE_IS_XML(tt) \ + (tt == TOK_AT || tt == TOK_DBLCOLON || tt == TOK_ANYNAME) + +#if JS_HAS_BLOCK_SCOPE +# define TOKEN_TYPE_IS_DECL(tt) ((tt) == TOK_VAR || (tt) == TOK_LET) +#else +# define TOKEN_TYPE_IS_DECL(tt) ((tt) == TOK_VAR) +#endif + +struct JSStringBuffer { + jschar *base; + jschar *limit; /* length limit for quick bounds check */ + jschar *ptr; /* slot for next non-NUL char to store */ + void *data; + JSBool (*grow)(JSStringBuffer *sb, size_t newlength); + void (*free)(JSStringBuffer *sb); +}; + +#define STRING_BUFFER_ERROR_BASE ((jschar *) 1) +#define STRING_BUFFER_OK(sb) ((sb)->base != STRING_BUFFER_ERROR_BASE) +#define STRING_BUFFER_OFFSET(sb) ((sb)->ptr -(sb)->base) + +extern void +js_InitStringBuffer(JSStringBuffer *sb); + +extern void +js_FinishStringBuffer(JSStringBuffer *sb); + +extern void +js_AppendChar(JSStringBuffer *sb, jschar c); + +extern void +js_RepeatChar(JSStringBuffer *sb, jschar c, uintN count); + +extern void +js_AppendCString(JSStringBuffer *sb, const char *asciiz); + +extern void +js_AppendJSString(JSStringBuffer *sb, JSString *str); + struct JSTokenPtr { uint16 index; /* index of char in physical line */ uint16 lineno; /* physical line number */ @@ -129,16 +200,21 @@ struct JSToken { JSTokenPos pos; /* token position in file */ jschar *ptr; /* beginning of token in line buffer */ union { - struct { + struct { /* non-numeric literal */ JSOp op; /* operator, for minimal parser */ JSAtom *atom; /* atom table entry */ } s; + struct { /* atom pair, for XML PIs */ + JSAtom *atom2; /* auxiliary atom table entry */ + JSAtom *atom; /* main atom table entry */ + } p; jsdouble dval; /* floating point number */ } u; }; #define t_op u.s.op #define t_atom u.s.atom +#define t_atom2 u.p.atom2 #define t_dval u.dval typedef struct JSTokenBuf { @@ -164,7 +240,7 @@ struct JSTokenStream { ptrdiff_t linepos; /* linebuf offset in physical line */ JSTokenBuf linebuf; /* line buffer for diagnostics */ JSTokenBuf userbuf; /* user input buffer if !file */ - JSTokenBuf tokenbuf; /* current token string buffer */ + JSStringBuffer tokenbuf; /* current token string buffer */ const char *filename; /* input filename or null */ FILE *file; /* stdio stream if reading from file */ JSPrincipals *principals; /* principals associated with source */ @@ -187,6 +263,36 @@ struct JSTokenStream { #define TSF_CRFLAG 0x40 /* linebuf would have ended with \r */ #define TSF_DIRTYLINE 0x80 /* non-whitespace since start of line */ #define TSF_OWNFILENAME 0x100 /* ts->filename is malloc'd */ +#define TSF_XMLTAGMODE 0x200 /* scanning within an XML tag in E4X */ +#define TSF_XMLTEXTMODE 0x400 /* scanning XMLText terminal from E4X */ +#define TSF_XMLONLYMODE 0x800 /* don't scan {expr} within text/tag */ + +/* Flag indicating unexpected end of input, i.e. TOK_EOF not at top-level. */ +#define TSF_UNEXPECTED_EOF 0x1000 + +/* + * To handle the hard case of contiguous HTML comments, we want to clear the + * TSF_DIRTYINPUT flag at the end of each such comment. But we'd rather not + * scan for --> within every //-style comment unless we have to. So we set + * TSF_IN_HTML_COMMENT when a either on a clean line, or + * only if (ts->flags & TSF_IN_HTML_COMMENT), in a //-style comment. + * + * This still works as before given a malformed comment hiding hack such as: + * + * + * + * It does not cope with malformed comment hiding hacks where --> is hidden + * by C-style comments, or on a dirty line. Such cases are already broken. + */ +#define TSF_IN_HTML_COMMENT 0x2000 + +/* Ignore keywords and return TOK_NAME instead to the parser. */ +#define TSF_KEYWORD_IS_NAME 0x4000 /* Unicode separators that are treated as line terminators, in addition to \n, \r */ #define LINE_SEPARATOR 0x2028 @@ -213,11 +319,18 @@ js_NewFileTokenStream(JSContext *cx, con extern JS_FRIEND_API(JSBool) js_CloseTokenStream(JSContext *cx, JSTokenStream *ts); +extern JS_FRIEND_API(int) +js_fgets(char *buf, int size, FILE *file); + /* - * Initialize the scanner, installing JS keywords into cx's global scope. + * If the given char array forms JavaScript keyword, return corresponding + * token. Otherwise return TOK_EOF. */ -extern JSBool -js_InitScanner(JSContext *cx); +extern JSTokenType +js_CheckKeyword(const jschar *chars, size_t length); + +#define js_IsKeyword(chars, length) \ + (js_CheckKeyword(chars, length) != TOK_EOF) /* * Friend-exported API entry point to call a mapping function on each reserved @@ -231,9 +344,18 @@ js_MapKeywords(void (*mapfun)(const char * Return true for a warning, false for an error. */ extern JSBool -js_ReportCompileErrorNumber(JSContext *cx, JSTokenStream *ts, - JSCodeGenerator *cg, uintN flags, - const uintN errorNumber, ...); +js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags, + uintN errorNumber, ...); + +extern JSBool +js_ReportCompileErrorNumberUC(JSContext *cx, void *handle, uintN flags, + uintN errorNumber, ...); + +/* Steal some JSREPORT_* bits (see jsapi.h) to tell handle's type. */ +#define JSREPORT_HANDLE 0x300 +#define JSREPORT_TS 0x000 +#define JSREPORT_CG 0x100 +#define JSREPORT_PN 0x200 /* * Look ahead one token and return its type.