Forráskód Böngészése

make get_macro_path context aware so it can look up class statics and imported globals

Simon Krajewski 11 éve
szülő
commit
9373fd9d3a
1 módosított fájl, 18 hozzáadás és 4 törlés
  1. 18 4
      codegen.ml

+ 18 - 4
codegen.ml

@@ -505,14 +505,28 @@ let build_metadata com t =
 (* -------------------------------------------------------------------------- *)
 (* MACRO TYPE *)
 
-let get_macro_path e args p =
+let get_macro_path ctx e args p =
 	let rec loop e =
 		match fst e with
 		| EField (e,f) -> f :: loop e
 		| EConst (Ident i) -> [i]
 		| _ -> error "Invalid macro call" p
 	in
-	(match loop e with
+	let path = match e with
+		| (EConst(Ident i)),_ ->
+			let path = try
+				if not (PMap.mem i ctx.curclass.cl_statics) then raise Not_found;
+				ctx.curclass.cl_path
+			with Not_found -> try
+				(t_infos (fst (PMap.find i ctx.m.module_globals))).mt_path
+			with Not_found ->
+				error "Invalid macro call" p
+			in
+			i :: (snd path) :: (fst path)
+		| _ ->
+			loop e
+	in
+	(match path with
 	| meth :: cl :: path -> (List.rev path,cl), meth, args
 	| _ -> error "Invalid macro call" p)
 
@@ -520,7 +534,7 @@ let build_macro_type ctx pl p =
 	let path, field, args = (match pl with
 		| [TInst ({ cl_kind = KExpr (ECall (e,args),_) },_)]
 		| [TInst ({ cl_kind = KExpr (EArrayDecl [ECall (e,args),_],_) },_)] ->
-			get_macro_path e args p
+			get_macro_path ctx e args p
 		| _ ->
 			error "MacroType requires a single expression call parameter" p
 	) in
@@ -534,7 +548,7 @@ let build_macro_type ctx pl p =
 
 let build_macro_build ctx c pl cfl p =
 	let path, field, args = match Meta.get Meta.GenericBuild c.cl_meta with
-		| _,[ECall(e,args),_],_ -> get_macro_path e args p
+		| _,[ECall(e,args),_],_ -> get_macro_path ctx e args p
 		| _ -> error "genericBuild requires a single expression call parameter" p
 	in
 	let old = ctx.ret,ctx.g.get_build_infos in