|
| 1 | +(* Copyright (C) 2019- Authors of BuckleScript |
| 2 | + * |
| 3 | + * This program is free software: you can redistribute it and/or modify |
| 4 | + * it under the terms of the GNU Lesser General Public License as published by |
| 5 | + * the Free Software Foundation, either version 3 of the License, or |
| 6 | + * (at your option) any later version. |
| 7 | + * |
| 8 | + * In addition to the permissions granted to you by the LGPL, you may combine |
| 9 | + * or link a "work that uses the Library" with a publicly distributed version |
| 10 | + * of this file to produce a combined library or application, then distribute |
| 11 | + * that combined work under the terms of your choosing, with no requirement |
| 12 | + * to comply with the obligations normally placed on you by section 4 of the |
| 13 | + * LGPL version 3 (or the corresponding section of a later version of the LGPL |
| 14 | + * should you choose to use a later version). |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Lesser General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Lesser General Public License |
| 22 | + * along with this program; if not, write to the Free Software |
| 23 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) |
| 24 | + |
| 25 | +type label = Types.label_description |
| 26 | + |
| 27 | +let fn = (fun (attr : Parsetree.attribute) -> |
| 28 | +match attr with |
| 29 | +| {txt = "bs.as"}, PStr |
| 30 | + [{pstr_desc = Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string(s,_))},_ )}] -> |
| 31 | + (* Bs_ast_invariant.mark_used_bs_attribute attr; *) |
| 32 | + Some s |
| 33 | +| _ -> None |
| 34 | +) |
| 35 | + |
| 36 | +let fld_record (lbl : label) = |
| 37 | + Lambda.Fld_record |
| 38 | + {name = Ext_list.find_def lbl.lbl_attributes fn lbl.lbl_name; mutable_flag = lbl.Types.lbl_mut} |
| 39 | + |
| 40 | +let fld_record_set (lbl : label) = |
| 41 | + Lambda.Fld_record_set |
| 42 | + (Ext_list.find_def lbl.lbl_attributes fn lbl.lbl_name) |
| 43 | + |
| 44 | +let blk_record fields = |
| 45 | + let all_labels_info = |
| 46 | + Ext_array.map fields |
| 47 | + (fun ((lbl : label),_) -> |
| 48 | + Ext_list.find_def lbl.Types.lbl_attributes fn lbl.lbl_name) in |
| 49 | + Lambda.Blk_record all_labels_info |
| 50 | + |
| 51 | +let check_bs_attributes_inclusion |
| 52 | + (attrs1 : Parsetree.attributes) |
| 53 | + (attrs2 : Parsetree.attributes) |
| 54 | + lbl_name = |
| 55 | + let a = Ext_list.find_def attrs1 fn lbl_name in |
| 56 | + let b = Ext_list.find_def attrs2 fn lbl_name in |
| 57 | + if a = b then None |
| 58 | + else Some (a,b) |
| 59 | + |
| 60 | + |
| 61 | + |
0 commit comments