Browse Source

[cpp] Add meta for injecting include files into generated headers and cpp. Add meta for including external implementation files into the build.

hughsando 10 years ago
parent
commit
18793906b5
3 changed files with 28 additions and 9 deletions
  1. 3 0
      ast.ml
  2. 7 4
      common.ml
  3. 18 5
      gencpp.ml

+ 3 - 0
ast.ml

@@ -52,6 +52,7 @@ module Meta = struct
 		| CoreApi
 		| CoreType
 		| CppFileCode
+		| CppInclude
 		| CppNamespaceCode
 		| CsNative
 		| Dce
@@ -87,6 +88,7 @@ module Meta = struct
 		| HaxeGeneric
 		| HeaderClassCode
 		| HeaderCode
+		| HeaderInclude
 		| HeaderNamespaceCode
 		| HxGen
 		| IfFeature
@@ -148,6 +150,7 @@ module Meta = struct
 		| SkipCtor
 		| SkipReflection
 		| Sound
+		| SourceFile
 		| StoredTypedExpr
 		| Strict
 		| Struct

+ 7 - 4
common.ml

@@ -373,7 +373,7 @@ module MetaInfo = struct
 		| Bitmap -> ":bitmap",("Embeds given bitmap data into the class (must extend flash.display.BitmapData)",[HasParam "Bitmap file path";UsedOn TClass;Platform Flash])
 		| BridgeProperties -> ":bridgeProperties",("Creates native property bridges for all Haxe properties in this class",[UsedOn TClass;Platform Cs])
 		| Build -> ":build",("Builds a class or enum from a macro",[HasParam "Build macro call";UsedOnEither [TClass;TEnum]])
-		| BuildXml -> ":buildXml",("",[Platform Cpp])
+		| BuildXml -> ":buildXml",("Specify xml data to be injected into Build.xml",[Platform Cpp])
 		| Callable -> ":callable",("Abstract forwards call to its underlying type",[UsedOn TAbstract])
 		| Class -> ":class",("Used internally to annotate an enum that will be generated as a class",[Platforms [Java;Cs]; UsedOn TEnum; Internal])
 		| ClassCode -> ":classCode",("Used to inject platform-native code into a class",[Platforms [Java;Cs]; UsedOn TClass])
@@ -381,7 +381,8 @@ module MetaInfo = struct
 		| CompilerGenerated -> ":compilerGenerated",("Marks a field as generated by the compiler. Shouldn't be used by the end user",[Platforms [Java;Cs]])
 		| CoreApi -> ":coreApi",("Identifies this class as a core api class (forces Api check)",[UsedOnEither [TClass;TEnum;TTypedef;TAbstract]])
 		| CoreType -> ":coreType",("Identifies an abstract as core type so that it requires no implementation",[UsedOn TAbstract])
-		| CppFileCode -> ":cppFileCode",("",[Platform Cpp])
+		| CppFileCode -> ":cppFileCode",("Code to be injected into generated cpp file",[Platform Cpp])
+		| CppInclude -> ":cppFileCode",("File to be included in generated cpp file",[Platform Cpp])
 		| CppNamespaceCode -> ":cppNamespaceCode",("",[Platform Cpp])
 		| CsNative -> ":csNative",("Automatically added by -net-lib on classes generated from .NET DLL files",[Platform Cs; UsedOnEither[TClass;TEnum]; Internal])
 		| Dce -> ":dce",("Forces dead code elimination even when -dce full is not specified",[UsedOnEither [TClass;TEnum]])
@@ -415,8 +416,9 @@ module MetaInfo = struct
 		| Hack -> ":hack",("Allows extending classes marked as @:final",[UsedOn TClass])
 		| HasUntyped -> (":has_untyped",("Used by the typer to mark fields that have untyped expressions",[Internal]))
 		| HaxeGeneric -> ":haxeGeneric",("Used internally to annotate non-native generic classes",[Platform Cs; UsedOnEither[TClass;TEnum]; Internal])
-		| HeaderClassCode -> ":headerClassCode",("",[Platform Cpp])
-		| HeaderCode -> ":headerCode",("",[Platform Cpp])
+		| HeaderClassCode -> ":headerClassCode",("Code to be injected into the generated class, in the header",[Platform Cpp])
+		| HeaderCode -> ":headerCode",("Code to be injected into the generated header file",[Platform Cpp])
+		| HeaderInclude -> ":headerInclude",("File to be included in generated header file",[Platform Cpp])
 		| HeaderNamespaceCode -> ":headerNamespaceCode",("",[Platform Cpp])
 		| HxGen -> ":hxGen",("Annotates that an extern class was generated by Haxe",[Platforms [Java;Cs]; UsedOnEither [TClass;TEnum]])
 		| IfFeature -> ":ifFeature",("Causes a field to be kept by DCE if the given feature is part of the compilation",[HasParam "Feature name";UsedOn TClassField])
@@ -479,6 +481,7 @@ module MetaInfo = struct
 		| SkipCtor -> ":skipCtor",("Used internally to generate a constructor as if it were a native type (no __hx_ctor)",[Platforms [Java;Cs]; Internal])
 		| SkipReflection -> ":skipReflection",("Used internally to annotate a field that shouldn't have its reflection data generated",[Platforms [Java;Cs]; UsedOn TClassField; Internal])
 		| Sound -> ":sound",( "Includes a given .wav or .mp3 file into the target Swf and associates it with the class (must extend flash.media.Sound)",[HasParam "File path";UsedOn TClass;Platform Flash])
+		| SourceFile -> ":sourceFile",("Source code filename for external class",[Platform Cpp])
 		| Strict -> ":strict",("Used to declare a native C# attribute or a native Java metadata. Is type checked",[Platforms [Java;Cs]])
 		| Struct -> ":struct",("Marks a class definition as a struct",[Platform Cs; UsedOn TClass])
 		| StructAccess -> ":structAccess",("Marks an extern class as using struct access('.') not pointer('->')",[Platform Cpp; UsedOn TClass])

+ 18 - 5
gencpp.ml

@@ -108,7 +108,7 @@ class source_writer common_ctx write_func close_func =
 
    method add_include class_path =
       ( match class_path with
-         | (["@verbatim"],file) -> this#write ("#include <" ^ file ^ ">\n");
+         | (["@verbatim"],file) -> this#write ("#include \"" ^ file ^ "\"\n");
          | _ ->
             let prefix = if should_prefix_include class_path then "" else get_include_prefix common_ctx true in
             this#write ("#ifndef INCLUDED_" ^ (join_class_path class_path "_") ^ "\n");
@@ -3424,6 +3424,9 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla
       output_cpp "#include <hx/Scriptable.h>\n";
 
    output_cpp ( get_class_code class_def Meta.CppFileCode );
+   let inc = get_meta_string_path ctx class_def.cl_meta Meta.CppInclude in
+   if (inc<>"") then
+      output_cpp ("#include \"" ^ inc ^ "\"\n");
 
    gen_open_namespace output_cpp class_path;
    output_cpp "\n";
@@ -4047,6 +4050,9 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla
    List.iter ( gen_forward_decl h_file ) referenced;
 
    output_h ( get_class_code class_def Meta.HeaderCode );
+   let inc = get_meta_string_path ctx class_def.cl_meta Meta.HeaderInclude in
+   if (inc<>"") then
+      output_h ("#include \"" ^ inc ^ "\"\n");
 
    gen_open_namespace output_h class_path;
    output_h "\n\n";
@@ -4123,7 +4129,6 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla
    List.iter (gen_member_def ctx class_def true interface)  (List.filter should_implement_field class_def.cl_ordered_statics);
 
    output_h ( get_class_code class_def Meta.HeaderClassCode );
-
    output_h "};\n\n";
 
    if (class_def.cl_interface) then begin
@@ -4222,7 +4227,7 @@ let write_resources common_ctx =
 
 
 
-let write_build_data common_ctx filename classes main_deps build_extra exe_name =
+let write_build_data common_ctx filename classes main_deps build_extra extern_src exe_name =
    let buildfile = open_out filename in
    let include_prefix = get_include_prefix common_ctx true in
    let add_class_to_buildfile class_def =
@@ -4265,6 +4270,9 @@ let write_build_data common_ctx filename classes main_deps build_extra exe_name
       incr idx;
    ) common_ctx.resources;
    output_string buildfile "</files>\n";
+   output_string buildfile "<files id=\"__externs__\">\n";
+   List.iter (fun src -> output_string buildfile ("<file name=\"" ^src^ "\" />\n") ) extern_src;
+   output_string buildfile "</files>\n";
    output_string buildfile ("<set name=\"HAXE_OUTPUT\" value=\"" ^ exe_name ^ "\" />\n");
    output_string buildfile "<include name=\"${HXCPP}/build-tool/BuildCommon.xml\"/>\n";
    output_string buildfile build_extra;
@@ -5435,12 +5443,17 @@ let generate_source common_ctx =
    let super_deps = create_super_dependencies common_ctx in
    let constructor_deps = create_constructor_dependencies common_ctx in
    let main_deps = ref [] in
+   let extern_src = ref [] in
    let build_xml = ref "" in
    let scriptable = (Common.defined common_ctx Define.Scriptable) in
 
    List.iter (fun object_def ->
       (match object_def with
-      | TClassDecl class_def when is_extern_class class_def -> ()
+      | TClassDecl class_def when is_extern_class class_def ->
+         build_xml := !build_xml ^ (get_class_code class_def Meta.BuildXml);
+         let source = get_meta_string_path common_ctx class_def.cl_meta Meta.SourceFile in
+         if (source<>"") then
+            extern_src := source :: !extern_src;
       | TClassDecl class_def ->
          let name =  class_text class_def.cl_path in
          let is_internal = is_internal_class class_def.cl_path in
@@ -5515,7 +5528,7 @@ let generate_source common_ctx =
    | Some path -> (snd path)
    | _ -> "output" in
 
-   write_build_data common_ctx (common_ctx.file ^ "/Build.xml") !exe_classes !main_deps !build_xml output_name;
+   write_build_data common_ctx (common_ctx.file ^ "/Build.xml") !exe_classes !main_deps !build_xml !extern_src output_name;
    let cmd_defines = ref "" in
    PMap.iter ( fun name value -> match name with
       | "true" | "sys" | "dce" | "cpp" | "debug" -> ()