1 // Copyright (c) 2019, Facebook, Inc.
2 // All rights reserved.
4 // This source code is licensed under the MIT license found in the
5 // LICENSE file in the "hack" directory of this source tree.
7 use facts_rust as facts;
8 use hhbc_string_utils_rust::without_xhp_mangling;
9 use ocamlrep::{bytes_from_ocamlrep, ptr::UnsafeOcamlPtr};
10 use ocamlrep_ocamlpool::ocaml_ffi_no_panic;
11 use oxidized::relative_path::RelativePath;
13 use facts::facts_parser::*;
16 fn extract_as_json_ffi(
18 filename: RelativePath,
19 text_ptr: UnsafeOcamlPtr,
22 // Safety: the OCaml garbage collector must not run as long as text_ptr
23 // and text_value exist. We don't call into OCaml here, so it won't.
24 let text_value = unsafe { text_ptr.as_value() };
25 let text = bytes_from_ocamlrep(text_value).expect("expected string");
27 ((1 << 0) & flags) != 0, // php5_compat_mode
28 ((1 << 1) & flags) != 0, // hhvm_compat_mode
29 ((1 << 2) & flags) != 0, // allow_new_attribute_syntax
30 ((1 << 3) & flags) != 0, // enable_xhp_class_modifier
31 ((1 << 4) & flags) != 0, // disable_xhp_element_mangling
39 fn extract_as_json_ffi0(
40 php5_compat_mode: bool,
41 hhvm_compat_mode: bool,
42 allow_new_attribute_syntax: bool,
43 enable_xhp_class_modifier: bool,
44 disable_xhp_element_mangling: bool,
45 filename: RelativePath,
49 let opts = ExtractAsJsonOpts {
52 allow_new_attribute_syntax,
53 enable_xhp_class_modifier,
54 disable_xhp_element_mangling,
58 extract_as_json(text, opts)
60 without_xhp_mangling(|| extract_as_json(text, opts))