|
@@ -15,8 +15,8 @@ open Sourcemaps
|
|
*)
|
|
*)
|
|
let escape_bin s =
|
|
let escape_bin s =
|
|
let b = Buffer.create 0 in
|
|
let b = Buffer.create 0 in
|
|
- for i = 0 to String.length s - 1 do
|
|
|
|
- match Char.code (String.unsafe_get s i) with
|
|
|
|
|
|
+ for i = 0 to ExtString.String.length s - 1 do
|
|
|
|
+ match Char.code (ExtString.String.unsafe_get s i) with
|
|
| c when c = Char.code('\\') || c = Char.code('"') || c = Char.code('$') ->
|
|
| c when c = Char.code('\\') || c = Char.code('"') || c = Char.code('$') ->
|
|
Buffer.add_string b "\\";
|
|
Buffer.add_string b "\\";
|
|
Buffer.add_char b (Char.chr c)
|
|
Buffer.add_char b (Char.chr c)
|
|
@@ -46,7 +46,7 @@ let write_resource dir name data =
|
|
*)
|
|
*)
|
|
let copy_file src dst =
|
|
let copy_file src dst =
|
|
let buffer_size = 8192 in
|
|
let buffer_size = 8192 in
|
|
- let buffer = String.create buffer_size in
|
|
|
|
|
|
+ let buffer = ExtString.String.create buffer_size in
|
|
let fd_in = Unix.openfile src [O_RDONLY] 0 in
|
|
let fd_in = Unix.openfile src [O_RDONLY] 0 in
|
|
let fd_out = Unix.openfile dst [O_WRONLY; O_CREAT; O_TRUNC] 0o644 in
|
|
let fd_out = Unix.openfile dst [O_WRONLY; O_CREAT; O_TRUNC] 0o644 in
|
|
let rec copy_loop () =
|
|
let rec copy_loop () =
|
|
@@ -196,7 +196,7 @@ end
|
|
(**
|
|
(**
|
|
Check if specified string is a reserved word in PHP
|
|
Check if specified string is a reserved word in PHP
|
|
*)
|
|
*)
|
|
-let is_keyword str = Hashtbl.mem php_keywords_tbl (String.lowercase str)
|
|
|
|
|
|
+let is_keyword str = Hashtbl.mem php_keywords_tbl (ExtString.String.lowercase str)
|
|
|
|
|
|
(**
|
|
(**
|
|
Check if specified type is php.NativeArray
|
|
Check if specified type is php.NativeArray
|
|
@@ -531,10 +531,10 @@ let get_full_type_name ?(escape=false) ?(omit_first_slash=false) (type_path:path
|
|
else
|
|
else
|
|
"" :: get_real_path module_path
|
|
"" :: get_real_path module_path
|
|
in
|
|
in
|
|
- (String.concat "\\" parts) ^ "\\" ^ type_name
|
|
|
|
|
|
+ (ExtString.String.concat "\\" parts) ^ "\\" ^ type_name
|
|
in
|
|
in
|
|
if escape then
|
|
if escape then
|
|
- String.escaped name
|
|
|
|
|
|
+ ExtString.String.escaped name
|
|
else
|
|
else
|
|
name
|
|
name
|
|
|
|
|
|
@@ -618,7 +618,7 @@ let fix_call_args callee_type exprs =
|
|
Escapes all "$" chars and encloses `str` into double quotes
|
|
Escapes all "$" chars and encloses `str` into double quotes
|
|
*)
|
|
*)
|
|
let quote_string str =
|
|
let quote_string str =
|
|
- "\"" ^ (Str.global_replace (Str.regexp "\\$") "\\$" (String.escaped str)) ^ "\""
|
|
|
|
|
|
+ "\"" ^ (Str.global_replace (Str.regexp "\\$") "\\$" (ExtString.String.escaped str)) ^ "\""
|
|
|
|
|
|
(**
|
|
(**
|
|
Check if specified field is a var with non-constant expression
|
|
Check if specified field is a var with non-constant expression
|
|
@@ -1296,21 +1296,21 @@ class code_writer (ctx:php_generator_context) hx_type_path php_name =
|
|
Decrease indentation by one level
|
|
Decrease indentation by one level
|
|
*)
|
|
*)
|
|
method indent_less =
|
|
method indent_less =
|
|
- indentation <- String.make ((String.length indentation) - 1) '\t';
|
|
|
|
|
|
+ indentation <- ExtString.String.make ((ExtString.String.length indentation) - 1) '\t';
|
|
(**
|
|
(**
|
|
Set indentation level (starting from zero for no indentation)
|
|
Set indentation level (starting from zero for no indentation)
|
|
*)
|
|
*)
|
|
method indent level =
|
|
method indent level =
|
|
- indentation <- String.make level '\t';
|
|
|
|
|
|
+ indentation <- ExtString.String.make level '\t';
|
|
(**
|
|
(**
|
|
Get indentation level (starting from zero for no indentation)
|
|
Get indentation level (starting from zero for no indentation)
|
|
*)
|
|
*)
|
|
- method get_indentation = String.length indentation
|
|
|
|
|
|
+ method get_indentation = ExtString.String.length indentation
|
|
(**
|
|
(**
|
|
Set indentation level (starting from zero for no indentation)
|
|
Set indentation level (starting from zero for no indentation)
|
|
*)
|
|
*)
|
|
method set_indentation level =
|
|
method set_indentation level =
|
|
- indentation <- String.make level '\t'
|
|
|
|
|
|
+ indentation <- ExtString.String.make level '\t'
|
|
(**
|
|
(**
|
|
Specify local var name declared in current scope
|
|
Specify local var name declared in current scope
|
|
*)
|
|
*)
|
|
@@ -1326,7 +1326,7 @@ class code_writer (ctx:php_generator_context) hx_type_path php_name =
|
|
else if get_type_name type_path = "" then
|
|
else if get_type_name type_path = "" then
|
|
match get_module_path type_path with
|
|
match get_module_path type_path with
|
|
| [] -> "\\"
|
|
| [] -> "\\"
|
|
- | module_path -> "\\" ^ (String.concat "\\" (get_real_path module_path)) ^ "\\"
|
|
|
|
|
|
+ | module_path -> "\\" ^ (ExtString.String.concat "\\" (get_real_path module_path)) ^ "\\"
|
|
else begin
|
|
else begin
|
|
let orig_type_path = type_path in
|
|
let orig_type_path = type_path in
|
|
let type_path = match type_path with (pack, name) -> (pack, get_real_name name) in
|
|
let type_path = match type_path with (pack, name) -> (pack, get_real_name name) in
|
|
@@ -1942,7 +1942,7 @@ class code_writer (ctx:php_generator_context) hx_type_path php_name =
|
|
set_sourcemap_pointer sourcemap sm_pointer_before_body;
|
|
set_sourcemap_pointer sourcemap sm_pointer_before_body;
|
|
let locals = vars#pop_captured in
|
|
let locals = vars#pop_captured in
|
|
if List.length locals > 0 then begin
|
|
if List.length locals > 0 then begin
|
|
- self#write ("unset($" ^ (String.concat ", $" locals) ^ ");\n");
|
|
|
|
|
|
+ self#write ("unset($" ^ (ExtString.String.concat ", $" locals) ^ ");\n");
|
|
self#write_indentation
|
|
self#write_indentation
|
|
end;
|
|
end;
|
|
self#write_bypassing_sourcemap body;
|
|
self#write_bypassing_sourcemap body;
|
|
@@ -2999,7 +2999,7 @@ class virtual type_builder ctx (wrapper:type_wrapper) =
|
|
Returns generated file contents
|
|
Returns generated file contents
|
|
*)
|
|
*)
|
|
method get_contents =
|
|
method get_contents =
|
|
- if (String.length contents) = 0 then begin
|
|
|
|
|
|
+ if (ExtString.String.length contents) = 0 then begin
|
|
self#write_declaration;
|
|
self#write_declaration;
|
|
writer#write_line " {"; (** opening bracket for a class *)
|
|
writer#write_line " {"; (** opening bracket for a class *)
|
|
self#write_body;
|
|
self#write_body;
|
|
@@ -3016,7 +3016,7 @@ class virtual type_builder ctx (wrapper:type_wrapper) =
|
|
writer#write_statement ("require_once __DIR__.'/" ^ polyfills_file ^ "'");
|
|
writer#write_statement ("require_once __DIR__.'/" ^ polyfills_file ^ "'");
|
|
writer#write_statement (boot_class ^ "::__hx__init()")
|
|
writer#write_statement (boot_class ^ "::__hx__init()")
|
|
end;
|
|
end;
|
|
- let haxe_class = match wrapper#get_type_path with (path, name) -> String.concat "." (path @ [name]) in
|
|
|
|
|
|
+ let haxe_class = match wrapper#get_type_path with (path, name) -> ExtString.String.concat "." (path @ [name]) in
|
|
writer#write_statement (boot_class ^ "::registerClass(" ^ (self#get_name) ^ "::class, '" ^ haxe_class ^ "')");
|
|
writer#write_statement (boot_class ^ "::registerClass(" ^ (self#get_name) ^ "::class, '" ^ haxe_class ^ "')");
|
|
self#write_rtti_meta;
|
|
self#write_rtti_meta;
|
|
self#write_pre_hx_init;
|
|
self#write_pre_hx_init;
|
|
@@ -3051,7 +3051,7 @@ class virtual type_builder ctx (wrapper:type_wrapper) =
|
|
writer#write "\n";
|
|
writer#write "\n";
|
|
let namespace = self#get_namespace in
|
|
let namespace = self#get_namespace in
|
|
if List.length namespace > 0 then
|
|
if List.length namespace > 0 then
|
|
- writer#write_line ("namespace " ^ (String.concat "\\" namespace) ^ ";\n");
|
|
|
|
|
|
+ writer#write_line ("namespace " ^ (ExtString.String.concat "\\" namespace) ^ ";\n");
|
|
writer#write_use
|
|
writer#write_use
|
|
(**
|
|
(**
|
|
Generates PHP docblock and attributes to output buffer.
|
|
Generates PHP docblock and attributes to output buffer.
|
|
@@ -3082,11 +3082,11 @@ class virtual type_builder ctx (wrapper:type_wrapper) =
|
|
Writes description section of docblocks
|
|
Writes description section of docblocks
|
|
*)
|
|
*)
|
|
method write_doc_description (doc:string) =
|
|
method write_doc_description (doc:string) =
|
|
- let lines = Str.split (Str.regexp "\n") (String.trim doc)
|
|
|
|
|
|
+ let lines = Str.split (Str.regexp "\n") (ExtString.String.trim doc)
|
|
and write_line line =
|
|
and write_line line =
|
|
- let trimmed = String.trim line in
|
|
|
|
- if String.length trimmed > 0 then (
|
|
|
|
- if String.get trimmed 0 = '*' then
|
|
|
|
|
|
+ let trimmed = ExtString.String.trim line in
|
|
|
|
+ if ExtString.String.length trimmed > 0 then (
|
|
|
|
+ if ExtString.String.get trimmed 0 = '*' then
|
|
writer#write_line (" " ^ trimmed)
|
|
writer#write_line (" " ^ trimmed)
|
|
else
|
|
else
|
|
writer#write_line (" * " ^ trimmed)
|
|
writer#write_line (" * " ^ trimmed)
|
|
@@ -3554,7 +3554,7 @@ class class_builder ctx (cls:tclass) =
|
|
cls.cl_implements
|
|
cls.cl_implements
|
|
in
|
|
in
|
|
let interfaces = List.map use_interface unique in
|
|
let interfaces = List.map use_interface unique in
|
|
- writer#write (String.concat ", " interfaces);
|
|
|
|
|
|
+ writer#write (ExtString.String.concat ", " interfaces);
|
|
end;
|
|
end;
|
|
(**
|
|
(**
|
|
Returns either user-defined constructor or creates empty constructor if instance initialization is required.
|
|
Returns either user-defined constructor or creates empty constructor if instance initialization is required.
|
|
@@ -3667,7 +3667,7 @@ class class_builder ctx (cls:tclass) =
|
|
List.iter
|
|
List.iter
|
|
(fun field ->
|
|
(fun field ->
|
|
if not !required then
|
|
if not !required then
|
|
- required := (String.lowercase field.cf_name = String.lowercase self#get_name)
|
|
|
|
|
|
+ required := (ExtString.String.lowercase field.cf_name = ExtString.String.lowercase self#get_name)
|
|
)
|
|
)
|
|
(cls.cl_ordered_statics @ cls.cl_ordered_fields);
|
|
(cls.cl_ordered_statics @ cls.cl_ordered_fields);
|
|
!required
|
|
!required
|
|
@@ -3676,10 +3676,10 @@ class class_builder ctx (cls:tclass) =
|
|
Writes `-D php-prefix` value as class constant PHP_PREFIX
|
|
Writes `-D php-prefix` value as class constant PHP_PREFIX
|
|
*)
|
|
*)
|
|
method private write_php_prefix () =
|
|
method private write_php_prefix () =
|
|
- let prefix = String.concat "\\" ctx.pgc_prefix in
|
|
|
|
|
|
+ let prefix = ExtString.String.concat "\\" ctx.pgc_prefix in
|
|
let indentation = writer#get_indentation in
|
|
let indentation = writer#get_indentation in
|
|
writer#indent 1;
|
|
writer#indent 1;
|
|
- writer#write_statement ("const PHP_PREFIX = \"" ^ (String.escaped prefix) ^ "\"");
|
|
|
|
|
|
+ writer#write_statement ("const PHP_PREFIX = \"" ^ (ExtString.String.escaped prefix) ^ "\"");
|
|
writer#indent indentation
|
|
writer#indent indentation
|
|
(**
|
|
(**
|
|
Writes expressions for `__hx__init` method
|
|
Writes expressions for `__hx__init` method
|
|
@@ -3998,8 +3998,8 @@ class generator (ctx:php_generator_context) =
|
|
if front_dirs <> [] then
|
|
if front_dirs <> [] then
|
|
ignore(create_dir_recursive (root_dir :: front_dirs));
|
|
ignore(create_dir_recursive (root_dir :: front_dirs));
|
|
let lib_path =
|
|
let lib_path =
|
|
- (String.concat "" (List.fold_left (fun acc s -> if s <> "." then "../" :: acc else acc) [] front_dirs))
|
|
|
|
- ^ (String.concat "/" self#get_lib_path)
|
|
|
|
|
|
+ (ExtString.String.concat "" (List.fold_left (fun acc s -> if s <> "." then "../" :: acc else acc) [] front_dirs))
|
|
|
|
+ ^ (ExtString.String.concat "/" self#get_lib_path)
|
|
in
|
|
in
|
|
let channel = open_out (root_dir ^ "/" ^ filename) in
|
|
let channel = open_out (root_dir ^ "/" ^ filename) in
|
|
output_string channel "<?php\n";
|
|
output_string channel "<?php\n";
|