Browse Source

[macros] report macro-in-macro calls when -D macro-debug

Dan Korostelev 9 years ago
parent
commit
cd15769ad1
2 changed files with 4 additions and 0 deletions
  1. 2 0
      src/typing/common.ml
  2. 2 0
      src/typing/typer.ml

+ 2 - 0
src/typing/common.ml

@@ -271,6 +271,7 @@ module Define = struct
 		| LuaVer
 		| LuaJit
 		| Macro
+		| MacroDebug
 		| MacroTimes
 		| NekoSource
 		| NekoV1
@@ -363,6 +364,7 @@ module Define = struct
 		| LuaJit -> ("lua_jit","Enable the jit compiler for lua (version 5.2 only")
 		| LuaVer -> ("lua_ver","The lua version to target")
 		| Macro -> ("macro","Defined when code is compiled in the macro context")
+		| MacroDebug -> ("macro_debug","Show warnings for potential macro problems (e.g. macro-in-macro calls)")
 		| MacroTimes -> ("macro_times","Display per-macro timing when used with --times")
 		| NetVer -> ("net_ver", "<version:20-45> Sets the .NET version to be targeted")
 		| NetTarget -> ("net_target", "<name> Sets the .NET target. Defaults to \"net\". xbox, micro (Micro Framework), compact (Compact Framework) are some valid values")

+ 2 - 0
src/typing/typer.ml

@@ -5227,6 +5227,8 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 			);
 		);
 		ctx.m.curmod.m_extra.m_time <- -1.; (* disable caching for modules having macro-in-macro *)
+		if Common.defined ctx.com Define.MacroDebug then
+			ctx.com.warning "Macro-in-macro call detected" p;
 		let e = (EConst (Ident "__dollar__delay_call"),p) in
 		Some (EUntyped (ECall (e,[EConst (Int (string_of_int pos)),p]),p),p)
 	end else