Przeglądaj źródła

add JVM annotations within annotations (#10749)

Co-authored-by: Simon Krajewski <[email protected]>
Bulby 2 lat temu
rodzic
commit
ee91cf22e4

+ 1 - 1
opam

@@ -32,4 +32,4 @@ depends: [
   "conf-zlib"
   "conf-neko"
   "luv"
-]
+]

+ 9 - 3
src/generators/genjvm.ml

@@ -269,9 +269,15 @@ module AnnotationHandler = struct
 			| EField(e1,s,_) ->
 				let path = parse_path e1 in
 				AEnum(object_path_sig path,s)
+			| ECall(e1, el) -> 
+				let path = parse_path e1 in
+				let _,name = ExtString.String.replace (snd path) "." "$" in
+				let path = (fst path, name) in
+				let values = List.map parse_value_pair el in 
+				AAnnotation(TObject(path, []),values)	
+				
 			| _ -> Error.typing_error "Expected value expression" (pos e)
-		in
-		let parse_value_pair e = match fst e with
+		and parse_value_pair e = match fst e with
 			| EBinop(OpAssign,(EConst(Ident s),_),e1) ->
 				s,parse_value e1
 			| _ ->
@@ -3097,4 +3103,4 @@ let generate jvm_flag com =
 		"\n\n"
 	in
 	gctx.out#add_entry manifest_content "META-INF/MANIFEST.MF";
-	gctx.out#close;
+	gctx.out#close;

+ 2 - 2
src/generators/jvm/jvmAttribute.ml

@@ -167,7 +167,7 @@ let rec write_annotation ch ann =
 			| ValClass i ->
 				write_ui16 ch i
 			| ValAnnotation a ->
-				write_annotation ch ann
+				write_annotation ch a
 			| ValArray annl ->
 				write_array16 ch loop annl
 		in
@@ -250,4 +250,4 @@ let write_attribute pool jvma =
 	{
 		attr_index = pool#add (ConstUtf8 name);
 		attr_data = IO.close_out ch
-	}
+	}

+ 11 - 5
src/generators/jvm/jvmBuilder.ml

@@ -29,6 +29,7 @@ type annotation_kind =
 	| ABool of bool
 	| AEnum of jsignature * string
 	| AArray of annotation_kind list
+	| AAnnotation of jsignature * annotation 
 
 and annotation = (string * annotation_kind) list
 
@@ -37,7 +38,7 @@ type export_config = {
 }
 
 let convert_annotations pool annotations =
-	let a = Array.map (fun (jsig,l) ->
+	let rec process_annotation (jsig, l) = 		
 		let offset = pool#add_string (generate_signature false jsig) in
 		let l = List.map (fun (name,ak) ->
 			let offset = pool#add_string name in
@@ -55,14 +56,19 @@ let convert_annotations pool annotations =
 				| AArray l ->
 					let l = List.map (fun ak -> loop ak) l in
 					'[',ValArray(Array.of_list l)
+				| AAnnotation (jsig, a) -> 
+					let ann = process_annotation (jsig, a) in 
+					'@',ValAnnotation(ann)
+					
 			in
 			offset,loop ak
 		) l in
-		{
+		{ 
 			ann_type = offset;
 			ann_elements = Array.of_list l;
-		}
-	) annotations in
+		} 
+	in  
+	let a = Array.map process_annotation annotations in
 	a
 
 class base_builder = object(self)
@@ -89,4 +95,4 @@ class base_builder = object(self)
 
 	method export_attributes (pool : JvmConstantPool.constant_pool) =
 		DynArray.to_array (DynArray.map (write_attribute pool) attributes)
-end
+end