Sfoglia il codice sorgente

[jvm] "inherit" source file to inner classes

Simon Krajewski 5 anni fa
parent
commit
73ecafabe2
2 ha cambiato i file con 17 aggiunte e 1 eliminazioni
  1. 1 1
      src/generators/genjvm.ml
  2. 16 0
      src/generators/jvm/jvmClass.ml

+ 1 - 1
src/generators/genjvm.ml

@@ -2473,7 +2473,7 @@ class tclass_to_jvm gctx c = object(self)
 		if not (Meta.has Meta.NativeGen c.cl_meta) && not c.cl_interface then
 			generate_dynamic_access gctx jc (List.map (fun cf -> cf.cf_name,jsignature_of_type gctx cf.cf_type,cf.cf_kind) c.cl_ordered_fields) false;
 		self#generate_annotations;
-		jc#add_attribute (AttributeSourceFile (jc#get_pool#add_string c.cl_pos.pfile));
+		jc#set_source_file c.cl_pos.pfile;
 		let jc = jc#export_class gctx.default_export_config in
 		write_class gctx.jar c.cl_path jc
 end

+ 16 - 0
src/generators/jvm/jvmClass.ml

@@ -42,6 +42,7 @@ class builder path_this path_super = object(self)
 	val inner_classes = Hashtbl.create 0
 	val mutable spawned_methods = []
 	val mutable static_init_method = None
+	val mutable source_file = None
 
 	method add_interface (path : jpath) (params : jtype_argument list) =
 		interface_offsets <- (pool#add_path path) :: interface_offsets;
@@ -64,6 +65,9 @@ class builder path_this path_super = object(self)
 	method get_offset_this = offset_this
 	method get_access_flags = access_flags
 
+	method set_source_file (file : string) =
+		source_file <- Some file
+
 	method get_static_init_method = match static_init_method with
 		| Some jm -> jm
 		| None ->
@@ -94,6 +98,12 @@ class builder path_this path_super = object(self)
 		end;
 		let offset = pool#add_path path in
 		Hashtbl.add inner_classes offset jc;
+		begin match source_file with
+		| None ->
+			()
+		| Some file ->
+			jc#set_source_file file
+		end;
 		jc
 
 	method spawn_method (name : string) (jsig_method : jsignature) (flags : MethodAccessFlags.t list) =
@@ -158,6 +168,12 @@ class builder path_this path_super = object(self)
 
 	method export_class (config : export_config) =
 		assert (not was_exported);
+		begin match source_file with
+		| None ->
+			()
+		| Some file ->
+			self#add_attribute (AttributeSourceFile (self#get_pool#add_string file));
+		end;
 		begin match static_init_method with
 		| None ->
 			()