2
* MTASC - MotionTwin ActionScript2 Compiler
3
* Copyright (c)2004 Nicolas Cannasse
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
63
| Add | And | Or | Eq | Ne | KwdNot | Le | Lt | Ge | Gt
64
| IfFrameLoaded | On | OnClipEvent | TellTarget
109
| CommentLine of string
146
type type_path = string list * string
150
fargs : (string * type_path option) list;
151
ftype : type_path option;
152
fstatic : static_flag;
153
fpublic : public_flag;
154
fgetter : getter_flag;
159
| HExtends of type_path
160
| HImplements of type_path
166
| EArray of eval * eval
167
| EBinop of binop * eval * eval
168
| EField of eval * string
169
| EParenthesis of eval
170
| EObjDecl of (string * eval) list
171
| EArrayDecl of eval list
172
| ECall of eval * eval list
173
| ENew of eval * eval list
174
| EUnop of unop * unop_flag * eval
175
| EQuestion of eval * eval * eval
177
| EStatic of type_path
178
| ECast of eval * eval
180
and eval = eval_def * pos
183
| EVars of static_flag * public_flag * (string * type_path option * eval option) list
185
| EBlock of expr list
186
| EFor of expr list * eval list * eval list * expr
187
| EForIn of expr * eval * expr
188
| EIf of eval * expr * expr option
189
| EWhile of eval * expr * while_flag
190
| ESwitch of eval * (eval option * expr) list
191
| ETry of expr * (string * type_path option * expr) list ref * expr option
192
| EWith of eval * expr
193
| EReturn of eval option
198
and expr = expr_def * pos
201
| EClass of type_path * herit list * expr
202
| EInterface of type_path * herit list * expr
203
| EImport of string list * string option
205
and signature = sign_def * pos
209
let is_postfix (e,_) = function
210
| Increment | Decrement -> (match e with EConst _ | EField _ | EStatic _ | EArray _ -> true | _ -> false)
211
| Not | Neg | NegBits -> false
213
let is_prefix = function
214
| Increment | Decrement -> true
215
| Not | Neg | NegBits -> true
217
let base_class_name = snd
219
let null_pos = { pfile = "<null>"; pmin = -1; pmax = -1 }
221
let set_eval (e : eval) (v : eval_def) =
222
Obj.set_field (Obj.repr e) 0 (Obj.repr v)
227
pmin = min p.pmin p2.pmin;
228
pmax = max p.pmax p2.pmax;
231
let s_type_path (p,s) = match p with [] -> s | _ -> String.concat "." p ^ "." ^ s
234
let b = Buffer.create (String.length s) in
235
for i = 0 to (String.length s) - 1 do
237
| '\n' -> Buffer.add_string b "\\n"
238
| '\t' -> Buffer.add_string b "\\t"
239
| '\r' -> Buffer.add_string b "\\r"
240
| c -> Buffer.add_char b c
244
let s_constant = function
247
| String s -> "\"" ^ s_escape s ^ "\""
250
let s_keyword = function
251
| Function -> "function"
262
| Continue -> "continue"
263
| Interface -> "interface"
264
| Extends -> "extends"
265
| Implements -> "implements"
269
| Default -> "default"
270
| Intrinsic -> "intrinsic"
271
| Dynamic -> "dynamic"
272
| Private -> "private"
276
| Finally -> "finally"
279
| InstanceOf -> "instanceof"
297
| IfFrameLoaded -> "ifFrameLoaded"
299
| OnClipEvent -> "onClipEvent"
300
| TellTarget -> "tellTarget"
302
let rec s_binop = function
311
| OpPhysNotEq -> "!=="
325
| OpAssignOp op -> s_binop op ^ "="
327
let s_unop = function
334
let s_token = function
335
| Eof -> "<end of file>"
336
| Const c -> s_constant c
337
| Kwd k -> s_keyword k
338
| Comment s -> "/*"^s^"*/"
339
| CommentLine s -> "//"^s
340
| Binop o -> s_binop o
355
exception Invalid_expression of pos
357
let rec check_val (v,p) =
359
| EBinop (OpAssign,_,_)
360
| EBinop (OpAssignOp _,_,_)
362
| EUnop (Increment,_,_)
363
| EUnop (Decrement,_,_)
377
-> raise (Invalid_expression p)
381
let rec check_expr (e,p) =
383
| EVars (_,_,vl) -> ()
385
(match f.fexpr with None -> () | Some e -> check_expr e)
387
List.iter check_expr el
388
| EFor (el, _ , _ , e ) ->
389
List.iter check_expr el;
395
(match eo with None -> () | Some e -> check_expr e)
399
List.iter (fun (_,e) -> check_expr e) cl;
402
List.iter (fun (_,_,e) -> check_expr e) !cl;
403
(match eo with None -> () | Some e -> check_expr e)
412
let check_sign (s,p) =
414
| EClass (_,_,e) -> check_expr e
415
| EInterface (_,_,e) -> check_expr e