as3: Ast supports brackets now, too. Fixed Math bug in builtins.c
[swftools.git] / lib / as3 / expr.h
1 /* ast.h
2
3    Extension module for the rfxswf library.
4    Part of the swftools package.
5
6    Copyright (c) 2009 Matthias Kramm <kramm@quiss.org>
7  
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
21
22 #ifndef __expr_h__
23 #define __expr_h__
24
25 #include "../q.h"
26 #include "code.h"
27 #include "registry.h"
28
29 DECLARE(node);
30 DECLARE(typedcode);
31 DECLARE(nodetype);
32 DECLARE_LIST(node);
33
34 struct _typedcode {
35     code_t*c;
36     classinfo_t*t;
37 };
38
39 #define NODE_HAS_CHILDREN 1
40
41 struct _nodetype {
42     char*name;
43     int flags;
44     typedcode_t (*write)(node_t*n);
45     typedcode_t (*read)(node_t*n);
46     code_t* (*exec)(node_t*n);
47 };
48
49 extern nodetype_t node_plus;
50 extern nodetype_t node_minus;
51 extern nodetype_t node_lplusplus; //++x
52 extern nodetype_t node_lminusminus; //--x
53 extern nodetype_t node_rplusplus; //x++
54 extern nodetype_t node_rminusminus; //x--
55 extern nodetype_t node_multiply;
56 extern nodetype_t node_div;
57 extern nodetype_t node_mod;
58 extern nodetype_t node_dot;
59 extern nodetype_t node_lt;
60 extern nodetype_t node_gt;
61 extern nodetype_t node_le; //<=
62 extern nodetype_t node_ge; //>=
63 extern nodetype_t node_eqeq; //==
64 extern nodetype_t node_eqeqeq; //===
65 extern nodetype_t node_noteqeq; //!==
66 extern nodetype_t node_noteq; //!=
67 extern nodetype_t node_oror; //||
68 extern nodetype_t node_andand; //&&
69 extern nodetype_t node_not;
70 extern nodetype_t node_bitnot;
71 extern nodetype_t node_bitand;
72 extern nodetype_t node_bitxor;
73 extern nodetype_t node_bitor;
74 extern nodetype_t node_shr; //>>
75 extern nodetype_t node_shl; //<<
76 extern nodetype_t node_ushr; //>>>
77 extern nodetype_t node_in; //in
78 extern nodetype_t node_as; //as
79 extern nodetype_t node_instanceof; //instanceof
80 extern nodetype_t node_is; //is
81 extern nodetype_t node_typeof; //typeof
82 extern nodetype_t node_void; //void
83 extern nodetype_t node_neg; //-
84 extern nodetype_t node_muleq; //*=
85 extern nodetype_t node_modeq; //%=
86 extern nodetype_t node_shleq; //<<=
87 extern nodetype_t node_shreq; //>>=
88 extern nodetype_t node_ushreq; //>>>=
89 extern nodetype_t node_diveq; ///=
90 extern nodetype_t node_bitoreq; //|=
91 extern nodetype_t node_bitxoreq; //^=
92 extern nodetype_t node_bitandeq; //&=
93 extern nodetype_t node_pluseq; //+=
94 extern nodetype_t node_minuseq; //-=
95 extern nodetype_t node_assign; //-=
96 extern nodetype_t node_tenary; //?:
97 extern nodetype_t node_arraylookup; //x[y]
98 extern nodetype_t node_comma; //(y1,y2,...,yn)
99
100 extern nodetype_t node_const;
101 extern nodetype_t node_code;
102
103 #if 0
104 extern nodetype_t node_dotdot; //..
105 extern nodetype_t node_dotat; //.@
106 extern nodetype_t node_dotstar; //.*
107 extern nodetype_t node_filter; //.(
108 extern nodetype_t node_new; //new
109 extern nodetype_t node_delete; //delete
110 extern nodetype_t node_call; //functioncall
111 extern nodetype_t node_at; //@
112 extern nodetype_t node_dotns; //.::
113 #endif
114
115 node_t* multinode_extend(node_t*n, node_t*add);
116
117 struct _node {
118     nodetype_t*type;
119     node_t*parent;
120     union {
121         struct {
122             node_t**child;
123             int num_children;
124         };
125         constant_t*value;
126         char*id;
127         typedcode_t code;
128     };
129 };
130
131 node_t* mkdummynode();
132 node_t* mkconstnode(constant_t*c);
133 node_t* mkcodenode(typedcode_t c);
134 node_t* mkmultinode(nodetype_t*t, node_t*one);
135 node_t* mknode1(nodetype_t*t, node_t*node);
136 node_t* mknode2(nodetype_t*t, node_t*left, node_t*right);
137 node_t* mknode3(nodetype_t*t, node_t*one, node_t*two, node_t*three);
138 void node_free(node_t*n);
139 typedcode_t node_read(node_t*n); //read and free
140 code_t* node_exec(node_t*n); //exec and free
141 void node_dump(node_t*n);
142
143 #endif