Selaa lähdekoodia

added :final support for classes and fields (fixed issue #449)

Nicolas Cannasse 13 vuotta sitten
vanhempi
commit
89e34228e6
2 muutettua tiedostoa jossa 10 lisäystä ja 8 poistoa
  1. 8 6
      genas3.ml
  2. 2 2
      genswf9.ml

+ 8 - 6
genas3.ml

@@ -850,6 +850,9 @@ and gen_value ctx e =
 		)) e.etype e.epos);
 		v()
 
+let final m =
+	if has_meta ":final" m then "final " else ""
+
 let generate_field ctx static f =
 	newline ctx;
 	ctx.in_static <- static;
@@ -878,11 +881,11 @@ let generate_field ctx static f =
 		| _ -> ()
 	) f.cf_meta;
 	let public = f.cf_public || Hashtbl.mem ctx.get_sets (f.cf_name,static) || (f.cf_name = "main" && static) || f.cf_name = "resolve" || has_meta ":public" f.cf_meta in
-	let rights = (if static then "static " else "") ^ (if public then "public" else "protected") in
+	let rights = (if static then "static final " else "") ^ (if public then "public" else "protected") in
 	let p = ctx.curclass.cl_pos in
 	match f.cf_expr, f.cf_kind with
 	| Some { eexpr = TFunction fd }, Method (MethNormal | MethInline) ->
-		print ctx "%s " rights;
+		print ctx "%s%s " rights (if static then "" else final f.cf_meta);
 		let rec loop c =
 			match c.cl_super with
 			| None -> ()
@@ -982,14 +985,13 @@ let rec define_getset ctx stat c =
 	| Some (c,_) when not stat -> define_getset ctx stat c
 	| _ -> ()
 
-
 let generate_class ctx c =
 	ctx.curclass <- c;
 	define_getset ctx true c;
 	define_getset ctx false c;
 	ctx.local_types <- List.map snd c.cl_types;
 	let pack = open_block ctx in
-	print ctx "\tpublic %s%s %s " (match c.cl_dynamic with None -> "" | Some _ -> if c.cl_interface then "" else "dynamic ") (if c.cl_interface then "interface" else "class") (snd c.cl_path);
+	print ctx "\tpublic %s%s%s %s " (final c.cl_meta) (match c.cl_dynamic with None -> "" | Some _ -> if c.cl_interface then "" else "dynamic ") (if c.cl_interface then "interface" else "class") (snd c.cl_path);
 	(match c.cl_super with
 	| None -> ()
 	| Some (csup,_) -> print ctx "extends %s " (s_path ctx true csup.cl_path c.cl_pos));
@@ -1051,7 +1053,7 @@ let generate_enum ctx e =
 	ctx.local_types <- List.map snd e.e_types;
 	let pack = open_block ctx in
 	let ename = snd e.e_path in
-	print ctx "\tpublic class %s extends enum {" ename;
+	print ctx "\tpublic final class %s extends enum {" ename;
 	let cl = open_block ctx in
 	newline ctx;
 	print ctx "public static const __isenum : Boolean = true";
@@ -1061,7 +1063,7 @@ let generate_enum ctx e =
 		newline ctx;
 		match c.ef_type with
 		| TFun (args,_) ->
-			print ctx "public static function %s(" c.ef_name;
+			print ctx "public static final function %s(" c.ef_name;
 			concat ctx ", " (fun (a,o,t) ->
 				print ctx "%s : %s" (s_ident a) (type_str ctx t c.ef_pos);
 				if o then spr ctx " = null";

+ 2 - 2
genswf9.ml

@@ -1924,7 +1924,7 @@ let generate_field_kind ctx f c stat =
 			ctx.debug <- old;
 			Some (HFMethod {
 				hlm_type = m;
-				hlm_final = stat;
+				hlm_final = stat || (has_meta ":final" f.cf_meta);
 				hlm_override = not stat && loop c name;
 				hlm_kind = kind;
 			})
@@ -2138,7 +2138,7 @@ let generate_class ctx c =
 		hlc_name = name;
 		hlc_super = (if c.cl_interface then None else Some (type_path ctx (match c.cl_super with None -> [],"Object" | Some (c,_) -> c.cl_path)));
 		hlc_sealed = not (is_dynamic c);
-		hlc_final = false;
+		hlc_final = has_meta ":final" c.cl_meta;
 		hlc_interface = c.cl_interface;
 		hlc_namespace = (match !has_protected with None -> None | Some p -> Some (HNProtected p));
 		hlc_implements = Array.of_list (List.map (fun (c,_) ->