⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsparse.h

📁 java script test programing source code
💻 H
📖 第 1 页 / 共 2 页
字号:
 * * So an XML tag with no {expr} and three attributes is a list with the form: * *    (tagname attrname1 attrvalue1 attrname2 attrvalue2 attrname2 attrvalue3) * * An XML tag with embedded expressions like so: * *    <name1{expr1} name2{expr2}name3={expr3}> * * would have the form: * *    ((name1 {expr1}) (name2 {expr2} name3) {expr3}) * * where () bracket a list with elements separated by spaces, and {expr} is a * TOK_LC unary node with expr as its kid. * * Thus, the attribute name/value pairs occupy successive odd and even list * locations, where pn_head is the TOK_XMLNAME node at list location 0.  The * parser builds the same sort of structures for elements: * *    <a x={x}>Hi there!<b y={y}>How are you?</b><answer>{x + y}</answer></a> * * translates to: * *    ((a x {x}) 'Hi there!' ((b y {y}) 'How are you?') ((answer) {x + y})) * * <Non-E4X node descriptions, continued> * * Label              Variant   Members * -----              -------   ------- * TOK_LEXICALSCOPE   name      pn_op: JSOP_LEAVEBLOCK or JSOP_LEAVEBLOCKEXPR *                              pn_atom: block object *                              pn_expr: block body * TOK_ARRAYCOMP      list      pn_head: list of pn_count (1 or 2) elements *                              if pn_count is 2, first element is #n=[...] *                                last element is block enclosing for loop(s) *                                and optionally if-guarded TOK_ARRAYPUSH *                              pn_extra: stack slot, used during code gen * TOK_ARRAYPUSH      unary     pn_op: JSOP_ARRAYCOMP *                              pn_kid: array comprehension expression */typedef enum JSParseNodeArity {    PN_FUNC     = -3,    PN_LIST     = -2,    PN_TERNARY  =  3,    PN_BINARY   =  2,    PN_UNARY    =  1,    PN_NAME     = -1,    PN_NULLARY  =  0} JSParseNodeArity;struct JSParseNode {    uint16              pn_type;    uint8               pn_op;    int8                pn_arity;    JSTokenPos          pn_pos;    ptrdiff_t           pn_offset;      /* first generated bytecode offset */    union {        struct {                        /* TOK_FUNCTION node */            JSAtom      *funAtom;       /* atomized function object */            JSParseNode *body;          /* TOK_LC list of statements */            uint32      flags;          /* accumulated tree context flags */            uint32      tryCount;       /* count of try statements in body */        } func;        struct {                        /* list of next-linked nodes */            JSParseNode *head;          /* first node in list */            JSParseNode **tail;         /* ptr to ptr to last node in list */            uint32      count;          /* number of nodes in list */            uint32      extra;          /* extra flags, see below */        } list;        struct {                        /* ternary: if, for(;;), ?: */            JSParseNode *kid1;          /* condition, discriminant, etc. */            JSParseNode *kid2;          /* then-part, case list, etc. */            JSParseNode *kid3;          /* else-part, default case, etc. */        } ternary;        struct {                        /* two kids if binary */            JSParseNode *left;            JSParseNode *right;            jsval       val;            /* switch case value */        } binary;        struct {                        /* one kid if unary */            JSParseNode *kid;            jsint       num;            /* -1 or sharp variable number */        } unary;        struct {                        /* name, labeled statement, etc. */            JSAtom      *atom;          /* name or label atom, null if slot */            JSParseNode *expr;          /* object or initializer */            jsint       slot;           /* -1 or arg or local var slot */            uintN       attrs;          /* attributes if local var or const */        } name;        struct {            JSAtom      *atom;          /* first atom in pair */            JSAtom      *atom2;         /* second atom in pair or null */        } apair;        jsdouble        dval;           /* aligned numeric literal value */    } pn_u;    JSParseNode         *pn_next;       /* to align dval and pn_u on RISCs */    JSTokenStream       *pn_ts;         /* token stream for error reports */    JSAtom              *pn_source;     /* saved source for decompilation */};#define pn_funAtom      pn_u.func.funAtom#define pn_body         pn_u.func.body#define pn_flags        pn_u.func.flags#define pn_tryCount     pn_u.func.tryCount#define pn_head         pn_u.list.head#define pn_tail         pn_u.list.tail#define pn_count        pn_u.list.count#define pn_extra        pn_u.list.extra#define pn_kid1         pn_u.ternary.kid1#define pn_kid2         pn_u.ternary.kid2#define pn_kid3         pn_u.ternary.kid3#define pn_left         pn_u.binary.left#define pn_right        pn_u.binary.right#define pn_val          pn_u.binary.val#define pn_kid          pn_u.unary.kid#define pn_num          pn_u.unary.num#define pn_atom         pn_u.name.atom#define pn_expr         pn_u.name.expr#define pn_slot         pn_u.name.slot#define pn_attrs        pn_u.name.attrs#define pn_dval         pn_u.dval#define pn_atom2        pn_u.apair.atom2/* PN_LIST pn_extra flags. */#define PNX_STRCAT      0x01            /* TOK_PLUS list has string term */#define PNX_CANTFOLD    0x02            /* TOK_PLUS list has unfoldable term */#define PNX_POPVAR      0x04            /* TOK_VAR last result needs popping */#define PNX_FORINVAR    0x08            /* TOK_VAR is left kid of TOK_IN node,                                           which is left kid of TOK_FOR */#define PNX_ENDCOMMA    0x10            /* array literal has comma at end */#define PNX_XMLROOT     0x20            /* top-most node in XML literal tree */#define PNX_GROUPINIT   0x40            /* var [a, b] = [c, d]; unit list */#define PNX_NEEDBRACES  0x80            /* braces necessary due to closure *//* * Move pn2 into pn, preserving pn->pn_pos and pn->pn_offset and handing off * any kids in pn2->pn_u, by clearing pn2. */#define PN_MOVE_NODE(pn, pn2)                                                 \    JS_BEGIN_MACRO                                                            \        (pn)->pn_type = (pn2)->pn_type;                                       \        (pn)->pn_op = (pn2)->pn_op;                                           \        (pn)->pn_arity = (pn2)->pn_arity;                                     \        (pn)->pn_u = (pn2)->pn_u;                                             \        PN_CLEAR_NODE(pn2);                                                   \    JS_END_MACRO#define PN_CLEAR_NODE(pn)                                                     \    JS_BEGIN_MACRO                                                            \        (pn)->pn_type = TOK_EOF;                                              \        (pn)->pn_op = JSOP_NOP;                                               \        (pn)->pn_arity = PN_NULLARY;                                          \    JS_END_MACRO/* True if pn is a parsenode representing a literal constant. */#define PN_IS_CONSTANT(pn)                                                    \    ((pn)->pn_type == TOK_NUMBER ||                                           \     (pn)->pn_type == TOK_STRING ||                                           \     ((pn)->pn_type == TOK_PRIMARY && (pn)->pn_op != JSOP_THIS))/* * Compute a pointer to the last JSParseNode element in a singly-linked list. * NB: list must be non-empty for correct PN_LAST usage! */#define PN_LAST(list) \    ((JSParseNode *)((char *)(list)->pn_tail - offsetof(JSParseNode, pn_next)))#define PN_INIT_LIST(list)                                                    \    JS_BEGIN_MACRO                                                            \        (list)->pn_head = NULL;                                               \        (list)->pn_tail = &(list)->pn_head;                                   \        (list)->pn_count = (list)->pn_extra = 0;                              \    JS_END_MACRO#define PN_INIT_LIST_1(list, pn)                                              \    JS_BEGIN_MACRO                                                            \        (list)->pn_head = (pn);                                               \        (list)->pn_tail = &(pn)->pn_next;                                     \        (list)->pn_count = 1;                                                 \        (list)->pn_extra = 0;                                                 \    JS_END_MACRO#define PN_APPEND(list, pn)                                                   \    JS_BEGIN_MACRO                                                            \        *(list)->pn_tail = (pn);                                              \        (list)->pn_tail = &(pn)->pn_next;                                     \        (list)->pn_count++;                                                   \    JS_END_MACRO/* * Parse a top-level JS script. * * The caller must prevent the GC from running while this function is active, * because atoms and function newborns are not rooted yet. */extern JS_FRIEND_API(JSParseNode *)js_ParseTokenStream(JSContext *cx, JSObject *chain, JSTokenStream *ts);extern JS_FRIEND_API(JSBool)js_CompileTokenStream(JSContext *cx, JSObject *chain, JSTokenStream *ts,                      JSCodeGenerator *cg);extern JSBooljs_CompileFunctionBody(JSContext *cx, JSTokenStream *ts, JSFunction *fun);extern JSBooljs_FoldConstants(JSContext *cx, JSParseNode *pn, JSTreeContext *tc);#if JS_HAS_XML_SUPPORTJS_FRIEND_API(JSParseNode *)js_ParseXMLTokenStream(JSContext *cx, JSObject *chain, JSTokenStream *ts,                       JSBool allowList);#endifJS_END_EXTERN_C#endif /* jsparse_h___ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -