Przeglądaj źródła

Add top-level option '-cppia' as a shorthand for '-D cppia -cpp'. Flip over to using cppast by default, with -D no_cppast to revert

hughsando 9 lat temu
rodzic
commit
ab5f10802a
4 zmienionych plików z 20 dodań i 10 usunięć
  1. 10 5
      src/generators/gencpp.ml
  2. 7 1
      src/main.ml
  3. 2 0
      src/typing/common.ml
  4. 1 4
      tests/unit/compile-cppia.hxml

+ 10 - 5
src/generators/gencpp.ml

@@ -2188,14 +2188,19 @@ let ctx_arg_list ctx arg_list prefix =
 
 
 let rec ctx_tfun_arg_list ctx arg_list =
+   let oType o arg_type =
+      let type_str = (ctx_type_string ctx arg_type) in
+      (* type_str may have already converted Null<X> to Dynamic because of NotNull tag ... *)
+      if o && (cant_be_null arg_type) && type_str<>"Dynamic" then
+         "hx::Null< " ^ type_str ^ " > "
+      else
+         type_str
+   in
    match arg_list with
    | [] -> ""
-   | [(name,o,arg_type)] -> ctx_arg ctx name None arg_type ""
+   | [(name,o,arg_type)] -> (oType o arg_type) ^ " " ^ (keyword_remap name)
    | (name,o,arg_type) :: remaining  ->
-      (ctx_arg ctx name None arg_type "") ^ "," ^ (ctx_tfun_arg_list ctx remaining)
-
-
-
+      (oType o arg_type) ^ " " ^ (keyword_remap name) ^  "," ^ (ctx_tfun_arg_list ctx remaining)
 
 let cpp_var_type_of ctx var =
    tcpp_to_string (cpp_type_of ctx var.v_type)

+ 7 - 1
src/main.ml

@@ -988,7 +988,7 @@ and do_connect host port args =
 
 and init ctx =
 	let usage = Printf.sprintf
-		"Haxe Compiler %s - (C)2005-2016 Haxe Foundation\n Usage : haxe%s -main <class> [-swf|-js|-neko|-php|-cpp|-as3|-cs|-java|-python|-hl] <output> [options]\n Options :"
+		"Haxe Compiler %s - (C)2005-2016 Haxe Foundation\n Usage : haxe%s -main <class> [-swf|-js|-neko|-php|-cpp|-cppia|-as3|-cs|-java|-python|-hl] <output> [options]\n Options :"
 		s_version (if Sys.os_type = "Win32" then ".exe" else "")
 	in
 	let com = ctx.com in
@@ -1074,6 +1074,10 @@ try
 		("-cpp",Arg.String (fun dir ->
 			set_platform Cpp dir;
 		),"<directory> : generate C++ code into target directory");
+		("-cppia",Arg.String (fun file ->
+			set_platform Cpp file;
+			Common.define com Define.Cppia;
+		),"<file> : generate Cppia code into target file");
 		("-cs",Arg.String (fun dir ->
 			cp_libs := "hxcs" :: !cp_libs;
 			set_platform Cs dir;
@@ -1460,6 +1464,8 @@ try
 			add_std "php";
 			"php"
 		| Cpp ->
+			if Common.defined_value_safe com Define.NoCppAst="" then
+			   Common.define_value com Define.CppAst "1";
 			Common.define_value com Define.HxcppApiLevel (if Common.defined_value_safe com Define.CppAst <>"" then "330" else "321");
 			add_std "cpp";
 			if Common.defined com Define.Cppia then

+ 2 - 0
src/typing/common.ml

@@ -210,6 +210,7 @@ module Define = struct
 		| NoAnalyzer
 		| NoCompilation
 		| NoCOpt
+		| NoCppAst
 		| NoDeprecationWarnings
 		| NoFlashOverride
 		| NoDebug
@@ -299,6 +300,7 @@ module Define = struct
 		| NoAnalyzer -> ("no-analyzer","Disable the static analyzer")
 		| NoCompilation -> ("no-compilation","Disable final compilation for Cs, Cpp and Java")
 		| NoCOpt -> ("no_copt","Disable completion optimization (for debug purposes)")
+		| NoCppAst -> ("no_cppast", "Do not generate experimental cpp code")
 		| NoDebug -> ("no_debug","Remove all debug macros from cpp output")
 		| NoDeprecationWarnings -> ("no-deprecation-warnings","Do not warn if fields annotated with @:deprecated are used")
 		| NoFlashOverride -> ("no-flash-override", "Change overrides on some basic classes into HX suffixed methods, flash only")

+ 1 - 4
tests/unit/compile-cppia.hxml

@@ -1,6 +1,3 @@
 compile-each.hxml
 -main unit.Test
--cpp bin/unit.cppia
--D cppia
--D NO_PRECOMPILED_HEADERS
---macro cpp.cppia.HostClasses.exclude()
+-cppia bin/unit.cppia