ast.ml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. (*
  2. * Copyright (C)2005-2013 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. *)
  22. type pos = {
  23. pfile : string;
  24. pmin : int;
  25. pmax : int;
  26. }
  27. module IntMap = Map.Make(struct type t = int let compare a b = a - b end)
  28. module Meta = struct
  29. type strict_meta =
  30. | Abstract
  31. | Access
  32. | Accessor
  33. | Allow
  34. | Analyzer
  35. | Annotation
  36. | ArrayAccess
  37. | Ast
  38. | AutoBuild
  39. | Bind
  40. | Bitmap
  41. | BridgeProperties
  42. | Build
  43. | BuildXml
  44. | Callable
  45. | Class
  46. | ClassCode
  47. | Commutative
  48. | CompilerGenerated
  49. | CoreApi
  50. | CoreType
  51. | CppFileCode
  52. | CppInclude
  53. | CppNamespaceCode
  54. | CsNative
  55. | Dce
  56. | Debug
  57. | Decl
  58. | DefParam
  59. | Delegate
  60. | Depend
  61. | Deprecated
  62. | DirectlyUsed
  63. | DynamicObject
  64. | Enum
  65. | EnumConstructorParam
  66. | Event
  67. | Exhaustive
  68. | Expose
  69. | Extern
  70. | FakeEnum
  71. | File
  72. | Final
  73. | FlatEnum
  74. | Font
  75. | Forward
  76. | From
  77. | FunctionCode
  78. | FunctionTailCode
  79. | Generic
  80. | GenericBuild
  81. | GenericInstance
  82. | Getter
  83. | Hack
  84. | HasUntyped
  85. | HaxeGeneric
  86. | HeaderClassCode
  87. | HeaderCode
  88. | HeaderInclude
  89. | HeaderNamespaceCode
  90. | HxGen
  91. | IfFeature
  92. | Impl
  93. | PythonImport
  94. | ImplicitCast
  95. | Include
  96. | InitPackage
  97. | Internal
  98. | IsVar
  99. | JavaCanonical
  100. | JavaNative
  101. | JsRequire
  102. | Keep
  103. | KeepInit
  104. | KeepSub
  105. | LibType
  106. | Meta
  107. | Macro
  108. | MaybeUsed
  109. | MergeBlock
  110. | MultiType
  111. | Native
  112. | NativeChildren
  113. | NativeGen
  114. | NativeGeneric
  115. | NativeProperty
  116. | NoCompletion
  117. | NoDebug
  118. | NoDoc
  119. | NoExpr
  120. | NoImportGlobal
  121. | NoPackageRestrict
  122. | NoStack
  123. | NotNull
  124. | NoUsing
  125. | Ns
  126. | Op
  127. | Optional
  128. | Overload
  129. | PrivateAccess
  130. | Property
  131. | Protected
  132. | Public
  133. | PublicFields
  134. | QuotedField
  135. | ReadOnly
  136. | RealPath
  137. | Remove
  138. | Require
  139. | RequiresAssign
  140. (* | Resolve *)
  141. | ReplaceReflection
  142. | Rtti
  143. | Runtime
  144. | RuntimeValue
  145. | SelfCall
  146. | Setter
  147. | SkipCtor
  148. | SkipReflection
  149. | Sound
  150. | SourceFile
  151. | StoredTypedExpr
  152. | Strict
  153. | Struct
  154. | StructAccess
  155. | SuppressWarnings
  156. | This
  157. | Throws
  158. | To
  159. | ToString
  160. | Transient
  161. | ValueUsed
  162. | Volatile
  163. | Unbound
  164. | UnifyMinDynamic
  165. | Unreflective
  166. | Unsafe
  167. | Usage
  168. | Used
  169. | Value
  170. | Void
  171. | Last
  172. (* do not put any custom metadata after Last *)
  173. | Dollar of string
  174. | Custom of string
  175. let has m ml = List.exists (fun (m2,_,_) -> m = m2) ml
  176. let get m ml = List.find (fun (m2,_,_) -> m = m2) ml
  177. let to_string_ref = ref (fun _ -> assert false)
  178. let to_string (m : strict_meta) : string = !to_string_ref m
  179. end
  180. type keyword =
  181. | Function
  182. | Class
  183. | Var
  184. | If
  185. | Else
  186. | While
  187. | Do
  188. | For
  189. | Break
  190. | Continue
  191. | Return
  192. | Extends
  193. | Implements
  194. | Import
  195. | Switch
  196. | Case
  197. | Default
  198. | Static
  199. | Public
  200. | Private
  201. | Try
  202. | Catch
  203. | New
  204. | This
  205. | Throw
  206. | Extern
  207. | Enum
  208. | In
  209. | Interface
  210. | Untyped
  211. | Cast
  212. | Override
  213. | Typedef
  214. | Dynamic
  215. | Package
  216. | Inline
  217. | Using
  218. | Null
  219. | True
  220. | False
  221. | Abstract
  222. | Macro
  223. type binop =
  224. | OpAdd
  225. | OpMult
  226. | OpDiv
  227. | OpSub
  228. | OpAssign
  229. | OpEq
  230. | OpNotEq
  231. | OpGt
  232. | OpGte
  233. | OpLt
  234. | OpLte
  235. | OpAnd
  236. | OpOr
  237. | OpXor
  238. | OpBoolAnd
  239. | OpBoolOr
  240. | OpShl
  241. | OpShr
  242. | OpUShr
  243. | OpMod
  244. | OpAssignOp of binop
  245. | OpInterval
  246. | OpArrow
  247. type unop =
  248. | Increment
  249. | Decrement
  250. | Not
  251. | Neg
  252. | NegBits
  253. type constant =
  254. | Int of string
  255. | Float of string
  256. | String of string
  257. | Ident of string
  258. | Regexp of string * string
  259. type token =
  260. | Eof
  261. | Const of constant
  262. | Kwd of keyword
  263. | Comment of string
  264. | CommentLine of string
  265. | Binop of binop
  266. | Unop of unop
  267. | Semicolon
  268. | Comma
  269. | BrOpen
  270. | BrClose
  271. | BkOpen
  272. | BkClose
  273. | POpen
  274. | PClose
  275. | Dot
  276. | DblDot
  277. | Arrow
  278. | IntInterval of string
  279. | Sharp of string
  280. | Question
  281. | At
  282. | Dollar of string
  283. type unop_flag =
  284. | Prefix
  285. | Postfix
  286. type while_flag =
  287. | NormalWhile
  288. | DoWhile
  289. type type_path = {
  290. tpackage : string list;
  291. tname : string;
  292. tparams : type_param_or_const list;
  293. tsub : string option;
  294. }
  295. and type_param_or_const =
  296. | TPType of complex_type
  297. | TPExpr of expr
  298. and complex_type =
  299. | CTPath of type_path
  300. | CTFunction of complex_type list * complex_type
  301. | CTAnonymous of class_field list
  302. | CTParent of complex_type
  303. | CTExtend of type_path list * class_field list
  304. | CTOptional of complex_type
  305. and func = {
  306. f_params : type_param list;
  307. f_args : (string * bool * complex_type option * expr option) list;
  308. f_type : complex_type option;
  309. f_expr : expr option;
  310. }
  311. and expr_def =
  312. | EConst of constant
  313. | EArray of expr * expr
  314. | EBinop of binop * expr * expr
  315. | EField of expr * string
  316. | EParenthesis of expr
  317. | EObjectDecl of (string * expr) list
  318. | EArrayDecl of expr list
  319. | ECall of expr * expr list
  320. | ENew of type_path * expr list
  321. | EUnop of unop * unop_flag * expr
  322. | EVars of (string * complex_type option * expr option) list
  323. | EFunction of string option * func
  324. | EBlock of expr list
  325. | EFor of expr * expr
  326. | EIn of expr * expr
  327. | EIf of expr * expr * expr option
  328. | EWhile of expr * expr * while_flag
  329. | ESwitch of expr * (expr list * expr option * expr option) list * expr option option
  330. | ETry of expr * (string * complex_type * expr) list
  331. | EReturn of expr option
  332. | EBreak
  333. | EContinue
  334. | EUntyped of expr
  335. | EThrow of expr
  336. | ECast of expr * complex_type option
  337. | EDisplay of expr * bool
  338. | EDisplayNew of type_path
  339. | ETernary of expr * expr * expr
  340. | ECheckType of expr * complex_type
  341. | EMeta of metadata_entry * expr
  342. and expr = expr_def * pos
  343. and type_param = {
  344. tp_name : string;
  345. tp_params : type_param list;
  346. tp_constraints : complex_type list;
  347. }
  348. and documentation = string option
  349. and metadata_entry = (Meta.strict_meta * expr list * pos)
  350. and metadata = metadata_entry list
  351. and access =
  352. | APublic
  353. | APrivate
  354. | AStatic
  355. | AOverride
  356. | ADynamic
  357. | AInline
  358. | AMacro
  359. and class_field_kind =
  360. | FVar of complex_type option * expr option
  361. | FFun of func
  362. | FProp of string * string * complex_type option * expr option
  363. and class_field = {
  364. cff_name : string;
  365. cff_doc : documentation;
  366. cff_pos : pos;
  367. mutable cff_meta : metadata;
  368. mutable cff_access : access list;
  369. mutable cff_kind : class_field_kind;
  370. }
  371. type enum_flag =
  372. | EPrivate
  373. | EExtern
  374. type class_flag =
  375. | HInterface
  376. | HExtern
  377. | HPrivate
  378. | HExtends of type_path
  379. | HImplements of type_path
  380. type abstract_flag =
  381. | APrivAbstract
  382. | AFromType of complex_type
  383. | AToType of complex_type
  384. | AIsType of complex_type
  385. type enum_constructor = {
  386. ec_name : string;
  387. ec_doc : documentation;
  388. ec_meta : metadata;
  389. ec_args : (string * bool * complex_type) list;
  390. ec_pos : pos;
  391. ec_params : type_param list;
  392. ec_type : complex_type option;
  393. }
  394. type ('a,'b) definition = {
  395. d_name : string;
  396. d_doc : documentation;
  397. d_params : type_param list;
  398. d_meta : metadata;
  399. d_flags : 'a list;
  400. d_data : 'b;
  401. }
  402. type import_mode =
  403. | INormal
  404. | IAsName of string
  405. | IAll
  406. type type_def =
  407. | EClass of (class_flag, class_field list) definition
  408. | EEnum of (enum_flag, enum_constructor list) definition
  409. | ETypedef of (enum_flag, complex_type) definition
  410. | EAbstract of (abstract_flag, class_field list) definition
  411. | EImport of (string * pos) list * import_mode
  412. | EUsing of type_path
  413. type type_decl = type_def * pos
  414. type package = string list * type_decl list
  415. exception Error of string * pos
  416. let is_lower_ident i =
  417. let rec loop p =
  418. match String.unsafe_get i p with
  419. | 'a'..'z' -> true
  420. | '_' -> if p + 1 < String.length i then loop (p + 1) else true
  421. | _ -> false
  422. in
  423. loop 0
  424. let pos = snd
  425. let rec is_postfix (e,_) op = match op with
  426. | Increment | Decrement -> true
  427. | Not | Neg | NegBits -> false
  428. let is_prefix = function
  429. | Increment | Decrement -> true
  430. | Not | Neg | NegBits -> true
  431. let base_class_name = snd
  432. let null_pos = { pfile = "?"; pmin = -1; pmax = -1 }
  433. let punion p p2 =
  434. {
  435. pfile = p.pfile;
  436. pmin = min p.pmin p2.pmin;
  437. pmax = max p.pmax p2.pmax;
  438. }
  439. let rec punion_el el = match el with
  440. | [] ->
  441. null_pos
  442. | (_,p) :: [] ->
  443. p
  444. | (_,p) :: el ->
  445. punion p (punion_el el)
  446. let s_type_path (p,s) = match p with [] -> s | _ -> String.concat "." p ^ "." ^ s
  447. let parse_path s =
  448. match List.rev (ExtString.String.nsplit s ".") with
  449. | [] -> failwith "Invalid empty path"
  450. | x :: l -> List.rev l, x
  451. let s_escape ?(hex=true) s =
  452. let b = Buffer.create (String.length s) in
  453. for i = 0 to (String.length s) - 1 do
  454. match s.[i] with
  455. | '\n' -> Buffer.add_string b "\\n"
  456. | '\t' -> Buffer.add_string b "\\t"
  457. | '\r' -> Buffer.add_string b "\\r"
  458. | '"' -> Buffer.add_string b "\\\""
  459. | '\\' -> Buffer.add_string b "\\\\"
  460. | c when int_of_char c < 32 && hex -> Buffer.add_string b (Printf.sprintf "\\x%.2X" (int_of_char c))
  461. | c -> Buffer.add_char b c
  462. done;
  463. Buffer.contents b
  464. let s_constant = function
  465. | Int s -> s
  466. | Float s -> s
  467. | String s -> "\"" ^ s_escape s ^ "\""
  468. | Ident s -> s
  469. | Regexp (r,o) -> "~/" ^ r ^ "/"
  470. let s_access = function
  471. | APublic -> "public"
  472. | APrivate -> "private"
  473. | AStatic -> "static"
  474. | AOverride -> "override"
  475. | ADynamic -> "dynamic"
  476. | AInline -> "inline"
  477. | AMacro -> "macro"
  478. let s_keyword = function
  479. | Function -> "function"
  480. | Class -> "class"
  481. | Static -> "static"
  482. | Var -> "var"
  483. | If -> "if"
  484. | Else -> "else"
  485. | While -> "while"
  486. | Do -> "do"
  487. | For -> "for"
  488. | Break -> "break"
  489. | Return -> "return"
  490. | Continue -> "continue"
  491. | Extends -> "extends"
  492. | Implements -> "implements"
  493. | Import -> "import"
  494. | Switch -> "switch"
  495. | Case -> "case"
  496. | Default -> "default"
  497. | Private -> "private"
  498. | Public -> "public"
  499. | Try -> "try"
  500. | Catch -> "catch"
  501. | New -> "new"
  502. | This -> "this"
  503. | Throw -> "throw"
  504. | Extern -> "extern"
  505. | Enum -> "enum"
  506. | In -> "in"
  507. | Interface -> "interface"
  508. | Untyped -> "untyped"
  509. | Cast -> "cast"
  510. | Override -> "override"
  511. | Typedef -> "typedef"
  512. | Dynamic -> "dynamic"
  513. | Package -> "package"
  514. | Inline -> "inline"
  515. | Using -> "using"
  516. | Null -> "null"
  517. | True -> "true"
  518. | False -> "false"
  519. | Abstract -> "abstract"
  520. | Macro -> "macro"
  521. let rec s_binop = function
  522. | OpAdd -> "+"
  523. | OpMult -> "*"
  524. | OpDiv -> "/"
  525. | OpSub -> "-"
  526. | OpAssign -> "="
  527. | OpEq -> "=="
  528. | OpNotEq -> "!="
  529. | OpGte -> ">="
  530. | OpLte -> "<="
  531. | OpGt -> ">"
  532. | OpLt -> "<"
  533. | OpAnd -> "&"
  534. | OpOr -> "|"
  535. | OpXor -> "^"
  536. | OpBoolAnd -> "&&"
  537. | OpBoolOr -> "||"
  538. | OpShr -> ">>"
  539. | OpUShr -> ">>>"
  540. | OpShl -> "<<"
  541. | OpMod -> "%"
  542. | OpAssignOp op -> s_binop op ^ "="
  543. | OpInterval -> "..."
  544. | OpArrow -> "=>"
  545. let s_unop = function
  546. | Increment -> "++"
  547. | Decrement -> "--"
  548. | Not -> "!"
  549. | Neg -> "-"
  550. | NegBits -> "~"
  551. let s_token = function
  552. | Eof -> "<end of file>"
  553. | Const c -> s_constant c
  554. | Kwd k -> s_keyword k
  555. | Comment s -> "/*"^s^"*/"
  556. | CommentLine s -> "//"^s
  557. | Binop o -> s_binop o
  558. | Unop o -> s_unop o
  559. | Semicolon -> ";"
  560. | Comma -> ","
  561. | BkOpen -> "["
  562. | BkClose -> "]"
  563. | BrOpen -> "{"
  564. | BrClose -> "}"
  565. | POpen -> "("
  566. | PClose -> ")"
  567. | Dot -> "."
  568. | DblDot -> ":"
  569. | Arrow -> "->"
  570. | IntInterval s -> s ^ "..."
  571. | Sharp s -> "#" ^ s
  572. | Question -> "?"
  573. | At -> "@"
  574. | Dollar v -> "$" ^ v
  575. let unescape s =
  576. let b = Buffer.create 0 in
  577. let rec loop esc i =
  578. if i = String.length s then
  579. ()
  580. else
  581. let c = s.[i] in
  582. if esc then begin
  583. let inext = ref (i + 1) in
  584. (match c with
  585. | 'n' -> Buffer.add_char b '\n'
  586. | 'r' -> Buffer.add_char b '\r'
  587. | 't' -> Buffer.add_char b '\t'
  588. | '"' | '\'' | '\\' -> Buffer.add_char b c
  589. | '0'..'3' ->
  590. let c = (try char_of_int (int_of_string ("0o" ^ String.sub s i 3)) with _ -> raise Exit) in
  591. Buffer.add_char b c;
  592. inext := !inext + 2;
  593. | 'x' ->
  594. let c = (try char_of_int (int_of_string ("0x" ^ String.sub s (i+1) 2)) with _ -> raise Exit) in
  595. Buffer.add_char b c;
  596. inext := !inext + 2;
  597. | 'u' ->
  598. let (u, a) =
  599. try
  600. (int_of_string ("0x" ^ String.sub s (i+1) 4), 4)
  601. with _ -> try
  602. assert (s.[i+1] = '{');
  603. let l = String.index_from s (i+3) '}' - (i+2) in
  604. let u = int_of_string ("0x" ^ String.sub s (i+2) l) in
  605. assert (u <= 0x10FFFF);
  606. (u, l+2)
  607. with _ ->
  608. raise Exit
  609. in
  610. let ub = UTF8.Buf.create 0 in
  611. UTF8.Buf.add_char ub (UChar.uchar_of_int u);
  612. Buffer.add_string b (UTF8.Buf.contents ub);
  613. inext := !inext + a;
  614. | _ ->
  615. raise Exit);
  616. loop false !inext;
  617. end else
  618. match c with
  619. | '\\' -> loop true (i + 1)
  620. | c ->
  621. Buffer.add_char b c;
  622. loop false (i + 1)
  623. in
  624. loop false 0;
  625. Buffer.contents b
  626. let map_expr loop (e,p) =
  627. let opt f o =
  628. match o with None -> None | Some v -> Some (f v)
  629. in
  630. let rec tparam = function
  631. | TPType t -> TPType (ctype t)
  632. | TPExpr e -> TPExpr (loop e)
  633. and cfield f =
  634. { f with cff_kind = (match f.cff_kind with
  635. | FVar (t,e) -> FVar (opt ctype t, opt loop e)
  636. | FFun f -> FFun (func f)
  637. | FProp (get,set,t,e) -> FProp (get,set,opt ctype t,opt loop e))
  638. }
  639. and ctype = function
  640. | CTPath t -> CTPath (tpath t)
  641. | CTFunction (cl,c) -> CTFunction (List.map ctype cl, ctype c)
  642. | CTAnonymous fl -> CTAnonymous (List.map cfield fl)
  643. | CTParent t -> CTParent (ctype t)
  644. | CTExtend (tl,fl) -> CTExtend (List.map tpath tl, List.map cfield fl)
  645. | CTOptional t -> CTOptional (ctype t)
  646. and tparamdecl t =
  647. { tp_name = t.tp_name; tp_constraints = List.map ctype t.tp_constraints; tp_params = List.map tparamdecl t.tp_params }
  648. and func f =
  649. {
  650. f_params = List.map tparamdecl f.f_params;
  651. f_args = List.map (fun (n,o,t,e) -> n,o,opt ctype t,opt loop e) f.f_args;
  652. f_type = opt ctype f.f_type;
  653. f_expr = opt loop f.f_expr;
  654. }
  655. and tpath t = { t with tparams = List.map tparam t.tparams }
  656. in
  657. let e = (match e with
  658. | EConst _ -> e
  659. | EArray (e1,e2) -> EArray (loop e1, loop e2)
  660. | EBinop (op,e1,e2) -> EBinop (op,loop e1, loop e2)
  661. | EField (e,f) -> EField (loop e, f)
  662. | EParenthesis e -> EParenthesis (loop e)
  663. | EObjectDecl fl -> EObjectDecl (List.map (fun (f,e) -> f,loop e) fl)
  664. | EArrayDecl el -> EArrayDecl (List.map loop el)
  665. | ECall (e,el) -> ECall (loop e, List.map loop el)
  666. | ENew (t,el) -> ENew (tpath t,List.map loop el)
  667. | EUnop (op,f,e) -> EUnop (op,f,loop e)
  668. | EVars vl -> EVars (List.map (fun (n,t,eo) -> n,opt ctype t,opt loop eo) vl)
  669. | EFunction (n,f) -> EFunction (n,func f)
  670. | EBlock el -> EBlock (List.map loop el)
  671. | EFor (e1,e2) -> EFor (loop e1, loop e2)
  672. | EIn (e1,e2) -> EIn (loop e1, loop e2)
  673. | EIf (e,e1,e2) -> EIf (loop e, loop e1, opt loop e2)
  674. | EWhile (econd,e,f) -> EWhile (loop econd, loop e, f)
  675. | ESwitch (e,cases,def) -> ESwitch (loop e, List.map (fun (el,eg,e) -> List.map loop el, opt loop eg, opt loop e) cases, opt (opt loop) def)
  676. | ETry (e, catches) -> ETry (loop e, List.map (fun (n,t,e) -> n,ctype t,loop e) catches)
  677. | EReturn e -> EReturn (opt loop e)
  678. | EBreak -> EBreak
  679. | EContinue -> EContinue
  680. | EUntyped e -> EUntyped (loop e)
  681. | EThrow e -> EThrow (loop e)
  682. | ECast (e,t) -> ECast (loop e,opt ctype t)
  683. | EDisplay (e,f) -> EDisplay (loop e,f)
  684. | EDisplayNew t -> EDisplayNew (tpath t)
  685. | ETernary (e1,e2,e3) -> ETernary (loop e1,loop e2,loop e3)
  686. | ECheckType (e,t) -> ECheckType (loop e, ctype t)
  687. | EMeta (m,e) -> EMeta(m, loop e)
  688. ) in
  689. (e,p)
  690. let rec s_expr (e,_) =
  691. match e with
  692. | EConst c -> s_constant c
  693. | EParenthesis e -> "(" ^ (s_expr e) ^ ")"
  694. | EArrayDecl el -> "[" ^ (String.concat "," (List.map s_expr el)) ^ "]"
  695. | EObjectDecl fl -> "{" ^ (String.concat "," (List.map (fun (n,e) -> n ^ ":" ^ (s_expr e)) fl)) ^ "}"
  696. | EBinop (op,e1,e2) -> s_expr e1 ^ s_binop op ^ s_expr e2
  697. | ECall (e,el) -> s_expr e ^ "(" ^ (String.concat ", " (List.map s_expr el)) ^ ")"
  698. | EField (e,f) -> s_expr e ^ "." ^ f
  699. | _ -> "'???'"
  700. let get_value_meta meta =
  701. try
  702. begin match Meta.get Meta.Value meta with
  703. | (_,[EObjectDecl values,_],_) -> List.fold_left (fun acc (s,e) -> PMap.add s e acc) PMap.empty values
  704. | _ -> raise Not_found
  705. end
  706. with Not_found ->
  707. PMap.empty
  708. let rec string_list_of_expr_path_raise (e,p) =
  709. match e with
  710. | EConst (Ident i) -> [i]
  711. | EField (e,f) -> f :: string_list_of_expr_path_raise e
  712. | _ -> raise Exit