Explorar el Código

sub-types generalization

Nicolas Cannasse hace 15 años
padre
commit
8eef095ada
Se han modificado 8 ficheros con 126 adiciones y 109 borrados
  1. 3 2
      ast.ml
  2. 6 7
      codegen.ml
  3. 2 0
      doc/CHANGES.txt
  4. 15 5
      main.ml
  5. 14 21
      parser.ml
  6. 0 1
      type.ml
  7. 75 60
      typeload.ml
  8. 11 13
      typer.ml

+ 3 - 2
ast.ml

@@ -137,6 +137,7 @@ type type_path_normal = {
 	tpackage : string list;
 	tname : string;
 	tparams : type_param_or_const list;
+	tsub : string option;
 }
 
 and type_param_or_const =
@@ -235,8 +236,8 @@ type type_def =
 	| EClass of (class_flag, (class_field * pos) list) definition
 	| EEnum of (enum_flag, enum_constructor list) definition
 	| ETypedef of (enum_flag, type_path) definition
-	| EImport of string list * string * string option
-	| EUsing of string list * string
+	| EImport of type_path_normal
+	| EUsing of type_path_normal
 
 type type_decl = type_def * pos
 

+ 6 - 7
codegen.ml

@@ -63,7 +63,7 @@ let extend_remoting ctx c t p async prot =
 	let new_name = (if async then "Async_" else "Remoting_") ^ t.tname in
 	(* check if the proxy already exists *)
 	let t = (try
-		Typeload.load_type_def ctx p (fst path,new_name)
+		Typeload.load_type_def ctx p { tpackage = fst path; tname = new_name; tparams = []; tsub = None }
 	with
 		Error (Module_not_found _,p2) when p == p2 ->
 	(* build it *)
@@ -71,10 +71,10 @@ let extend_remoting ctx c t p async prot =
 	let decls = (try Typeload.parse_module ctx path p with e -> ctx.com.package_rules <- rules; raise e) in
 	ctx.com.package_rules <- rules;
 	let base_fields = [
-		(FVar ("__cnx",None,[],Some (TPNormal { tpackage = ["haxe";"remoting"]; tname = if async then "AsyncConnection" else "Connection"; tparams = [] }),None),p);
+		(FVar ("__cnx",None,[],Some (TPNormal { tpackage = ["haxe";"remoting"]; tname = if async then "AsyncConnection" else "Connection"; tparams = []; tsub = None }),None),p);
 		(FFun ("new",None,[APublic],[],{ f_args = ["c",false,None,None]; f_type = None; f_expr = (EBinop (OpAssign,(EConst (Ident "__cnx"),p),(EConst (Ident "c"),p)),p) }),p);
 	] in
-	let tvoid = TPNormal { tpackage = []; tname = "Void"; tparams = [] } in
+	let tvoid = TPNormal { tpackage = []; tname = "Void"; tparams = []; tsub = None } in
 	let build_field is_public acc (f,p) =
 		match f with
 		| FFun ("new",_,_,_,_) ->
@@ -152,15 +152,14 @@ let build_generic ctx c p tl =
 	if !recurse then
 		TInst (c,tl) (* build a normal instance *)
 	else try
-		Typeload.load_normal_type ctx { tpackage = pack; tname = name; tparams = [] } p false
+		Typeload.load_instance ctx { tpackage = pack; tname = name; tparams = []; tsub = None } p false
 	with Error(Module_not_found path,_) when path = (pack,name) ->
 		let m = (try Hashtbl.find ctx.modules (Hashtbl.find ctx.types_module c.cl_path) with Not_found -> assert false) in
 		let ctx = { ctx with local_types = m.mtypes @ ctx.local_types } in
 		let cg = mk_class (pack,name) c.cl_pos None false in
 		let mg = {
 			mpath = cg.cl_path;
-			mtypes = [TClassDecl cg];
-			mimports = [];
+			mtypes = [TClassDecl cg];			
 		} in
 		Hashtbl.add ctx.modules mg.mpath mg;
 		let rec loop l1 l2 =
@@ -206,7 +205,7 @@ let build_generic ctx c p tl =
 (* HAXE.XML.PROXY *)
 
 let extend_xml_proxy ctx c t file p =
-	let t = Typeload.load_type ctx p t in
+	let t = Typeload.load_complex_type ctx p t in
 	let file = (try Common.find_file ctx.com file with Not_found -> file) in
 	let used = ref PMap.empty in
 	let rec delay() =

+ 2 - 0
doc/CHANGES.txt

@@ -35,6 +35,8 @@
 	php : added php.db.PDO (php.db.Sqlite is now deprecated)
 	php : fixed bug in Type.getClassFields() that reported duplicated entries
 	php : fixed errror in XML error reporting
+	all : allow sub-types declarations everywhere (pack.Type.Sub)
+	all : added completion for sub-types declarations
 
 2009-07-26: 2.04
 	flash9 : fixed get_full_path error with -D fdb

+ 15 - 5
main.ml

@@ -377,7 +377,7 @@ try
 		("--display", Arg.String (fun file_pos ->
 			match file_pos with
 			| "classes" ->
-				pre_compilation := (fun() -> raise (Parser.TypePath ["."])) :: !pre_compilation;
+				pre_compilation := (fun() -> raise (Parser.TypePath (["."],None))) :: !pre_compilation;
 			| "keywords" ->
 				report_list (Hashtbl.fold (fun k _ acc -> (k,"","") :: acc) Lexer.keywords []);
 				exit 0;
@@ -558,10 +558,20 @@ with
 			prerr_endline (htmlescape (Type.s_type ctx t));
 			prerr_endline "</type>");
 		exit 0;
-	| Parser.TypePath p ->
-		let packs, classes = read_type_path com p in
-		if packs = [] && classes = [] then report ("No classes found in " ^ String.concat "." p) Ast.null_pos;
-		report_list (List.map (fun f -> f,"","") (packs @ classes));
+	| Parser.TypePath (p,c) ->
+		(match c with
+		| None -> 
+			let packs, classes = read_type_path com p in
+			if packs = [] && classes = [] then report ("No classes found in " ^ String.concat "." p) Ast.null_pos;
+			report_list (List.map (fun f -> f,"","") (packs @ classes))
+		| Some c ->
+			try 
+				let ctx = Typer.create com in
+				let m = Typeload.load_module ctx (p,c) Ast.null_pos in
+				report_list (List.map (fun t -> snd (Type.t_path t),"","") (List.filter (fun t -> not (Type.t_private t)) m.Type.mtypes))
+			with _ -> 
+				report ("Could not load module " ^ (Ast.s_type_path (p,c))) Ast.null_pos
+		);
 		exit 0;
 	| e when (try Sys.getenv "OCAMLRUNPARAM" <> "b" with _ -> true) ->
 		report (Printexc.to_string e) Ast.null_pos

+ 14 - 21
parser.ml

@@ -27,7 +27,7 @@ type error_msg =
 	| Missing_type
 
 exception Error of error_msg * pos
-exception TypePath of string list
+exception TypePath of string list * string option
 exception Display of expr
 
 let error_msg = function
@@ -163,8 +163,8 @@ let rec	parse_file s =
 
 and parse_type_decl s =
 	match s with parser
-	| [< '(Kwd Import,p1); p, t, s = parse_import []; p2 = semicolon >] -> EImport (p,t,s) , punion p1 p2
-	| [< '(Kwd Using,p1); p, t = parse_using []; p2 = semicolon >] -> EUsing (p,t) , punion p1 p2
+	| [< '(Kwd Import,p1); t = parse_type_path_normal; p2 = semicolon >] -> EImport t, punion p1 p2
+	| [< '(Kwd Using,p1); t = parse_type_path_normal; p2 = semicolon >] -> EUsing t, punion p1 p2
 	| [< c = parse_common_flags; s >] ->
 		match s with parser
 		| [< n , p1 = parse_enum_flags; doc = get_doc; '(Const (Type name),_); tl = parse_constraint_params; '(BrOpen,_); l = plist parse_enum; '(BrClose,p2) >] ->
@@ -239,22 +239,6 @@ and parse_class_field_resume s =
 				with
 					Stream.Error _ | Stream.Failure -> parse_class_field_resume s
 
-and parse_import acc = parser
-	| [< '(Const (Ident k),_); '(Dot,p); s >] ->
-		if is_resuming p then raise (TypePath (List.rev (k :: acc)));
-		parse_import (k :: acc) s
-	| [< '(Const (Type t),_); s >] ->
-		List.rev acc , t , match s with parser
-			| [< '(Dot,_); '(Const (Type s),_) >] -> Some s
-			| [< >] -> None
-
-and parse_using acc = parser
-	| [< '(Const (Ident k),_); '(Dot,p); s >] ->
-		if is_resuming p then raise (TypePath (List.rev (k :: acc)));
-		parse_using (k :: acc) s
-	| [< '(Const (Type t),_) >] ->
-		List.rev acc , t
-
 and parse_common_flags = parser
 	| [< '(Kwd Private,_); l = parse_common_flags >] -> (HPrivate, EPrivate) :: l
 	| [< '(Kwd Extern,_); l = parse_common_flags >] -> (HExtern, EExtern) :: l
@@ -292,10 +276,18 @@ and parse_type_path_normal s = parse_type_path1 [] s
 and parse_type_path1 pack = parser
 	| [< '(Const (Ident name),_); '(Dot,p); s >] ->
 		if is_resuming p then
-			raise  (TypePath (List.rev (name :: pack)))
+			raise (TypePath (List.rev (name :: pack),None))
 		else
 			parse_type_path1 (name :: pack) s
 	| [< '(Const (Type name),_); s >] ->
+		let sub = (match s with parser
+			| [< '(Dot,p); s >] ->
+				(if is_resuming p then
+					raise (TypePath (List.rev pack,Some name))
+				else match s with parser
+					[< '(Const (Type name),_) >] -> Some name)
+			| [< >] -> None
+		) in
 		let params = (match s with parser
 			| [< '(Binop OpLt,_); l = psep Comma parse_type_path_or_const; '(Binop OpGt,_) >] -> l
 			| [< >] -> []
@@ -303,7 +295,8 @@ and parse_type_path1 pack = parser
 		{
 			tpackage = List.rev pack;
 			tname = name;
-			tparams = params
+			tparams = params;
+			tsub = sub;
 		}
 
 and parse_type_path_or_const = parser

+ 0 - 1
type.ml

@@ -180,7 +180,6 @@ and module_type =
 type module_def = {
 	mpath : path;
 	mtypes : module_type list;
-	mutable mimports : (module_def * string option) list;
 }
 
 let mk e t p = { eexpr = e; etype = t; epos = p }

+ 75 - 60
typeload.ml

@@ -62,18 +62,22 @@ let type_static_var ctx t e p =
 	| TType ({ t_path = ([],"UInt") },[]) -> { e with etype = t }
 	| _ -> e
 
-(** since load_type is used in PASS2 , it cannot access the structure of a type **)
+(** since load_type_def and load_instance are used in PASS2, they should not access the structure of a type **)
 
-let load_type_def ctx p tpath =
-	let no_pack = fst tpath = [] in
+(*
+	load a type or a subtype definition 
+*)
+let load_type_def ctx p t =
+	let no_pack = t.tpackage = [] in
+	let tname = (match t.tsub with None -> t.tname | Some n -> n) in
 	try
-		List.find (fun t ->
-			let tp = t_path t in
-			tp = tpath || (no_pack && snd tp = snd tpath)
+		List.find (fun t2 ->
+			let tp = t_path t2 in
+			tp = (t.tpackage,tname) || (no_pack && snd tp = tname)
 		) ctx.local_types
 	with
 		Not_found ->
-			let tpath, m = (try
+			let t, m = (try
 				if not no_pack then raise Exit;
 				(match fst ctx.current.mpath with
 				| [] -> raise Exit
@@ -86,25 +90,27 @@ let load_type_def ctx p tpath =
 						| Forbidden -> raise Exit
 						| _ -> ())
 					with Not_found -> ());
-				let tpath2 = fst ctx.current.mpath , snd tpath in
-				tpath2, ctx.api.load_module tpath2 p
+				let tpath2 = fst ctx.current.mpath, t.tname in
+				{ t with tpackage = fst tpath2 }, ctx.api.load_module tpath2 p
 			with
-				| Error (Module_not_found _,p2) when p == p2 -> tpath, ctx.api.load_module tpath p
-				| Exit -> tpath, ctx.api.load_module tpath p
+				| Error (Module_not_found _,p2) when p == p2 -> t, ctx.api.load_module (t.tpackage,t.tname) p
+				| Exit -> t, ctx.api.load_module (t.tpackage,t.tname) p
 			) in
+			let tpath = (t.tpackage,tname) in
 			try
 				List.find (fun t -> not (t_private t) && t_path t = tpath) m.mtypes
 			with
-				Not_found -> error ("Module " ^ s_type_path tpath ^ " does not define type " ^ snd tpath) p
+				Not_found -> error ("Module " ^ s_type_path m.mpath ^ " does not define type " ^ snd tpath) p
 
-let rec load_normal_type ctx t p allow_no_params =
+(* build an instance from a full type *)
+let rec load_instance ctx t p allow_no_params =
 	try
-		if t.tpackage <> [] then raise Not_found;
+		if t.tpackage <> [] || t.tsub <> None then raise Not_found;
 		let pt = List.assoc t.tname ctx.type_params in
 		if t.tparams <> [] then error ("Class type parameter " ^ t.tname ^ " can't have parameters") p;
 		pt
 	with Not_found ->
-		let types , path , f = ctx.api.build_instance (load_type_def ctx p (t.tpackage,t.tname)) p in
+		let types , path , f = ctx.api.build_instance (load_type_def ctx p t) p in
 		if allow_no_params && t.tparams = [] then
 			f (List.map (fun (name,t) ->
 				match follow t with
@@ -114,7 +120,7 @@ let rec load_normal_type ctx t p allow_no_params =
 		else if path = ([],"Dynamic") then
 			match t.tparams with
 			| [] -> t_dynamic
-			| [TPType t] -> TDynamic (load_type ctx p t)
+			| [TPType t] -> TDynamic (load_complex_type ctx p t)
 			| _ -> error "Too many parameters for Dynamic" p
 		else begin
 			if List.length types <> List.length t.tparams then error ("Invalid number of type parameters for " ^ s_type_path path) p;
@@ -130,7 +136,7 @@ let rec load_normal_type ctx t p allow_no_params =
 					let c = mk_class ([],name) p None false in
 					c.cl_kind <- KConstant const;
 					TInst (c,[])
-				| TPType t -> load_type ctx p t
+				| TPType t -> load_complex_type ctx p t
 			) t.tparams in
 			let params = List.map2 (fun t (name,t2) ->
 				let isconst = (match t with TInst ({ cl_kind = KConstant _ },_) -> true | _ -> false) in
@@ -152,13 +158,15 @@ let rec load_normal_type ctx t p allow_no_params =
 			) tparams types in
 			f params
 		end
-
-and load_type ctx p t =
+(*
+	build an instance from a complex type
+*)
+and load_complex_type ctx p t =
 	match t with
-	| TPParent t -> load_type ctx p t
-	| TPNormal t -> load_normal_type ctx t p false
+	| TPParent t -> load_complex_type ctx p t
+	| TPNormal t -> load_instance ctx t p false
 	| TPExtend (t,l) ->
-		(match load_type ctx p (TPAnonymous l) with
+		(match load_complex_type ctx p (TPAnonymous l) with
 		| TAnon a ->
 			let rec loop t =
 				match follow t with
@@ -185,17 +193,17 @@ and load_type ctx p t =
 					mk_anon (PMap.foldi PMap.add a.a_fields a2.a_fields)
 				| _ -> error "Cannot only extend classes and anonymous" p
 			in
-			loop (load_normal_type ctx t p false)
+			loop (load_instance ctx t p false)
 		| _ -> assert false)
 	| TPAnonymous l ->
 		let rec loop acc (n,pub,f,p) =
 			if PMap.mem n acc then error ("Duplicate field declaration : " ^ n) p;
 			let t , get, set = (match f with
 				| AFVar t ->
-					load_type ctx p t, NormalAccess, NormalAccess
+					load_complex_type ctx p t, NormalAccess, NormalAccess
 				| AFFun (tl,t) ->
-					let t = load_type ctx p t in
-					let args = List.map (fun (name,o,t) -> name , o, load_type ctx p t) tl in
+					let t = load_complex_type ctx p t in
+					let args = List.map (fun (name,o,t) -> name , o, load_complex_type ctx p t) tl in
 					TFun (args,t), NormalAccess, MethodAccess false
 				| AFProp (t,i1,i2) ->
 					let access m get =
@@ -206,7 +214,7 @@ and load_type ctx p t =
 						| "dynamic" -> CallAccess ((if get then "get_"  else "set_") ^ n)
 						| _ -> CallAccess m
 					in
-					load_type ctx p t, access i1 true, access i2 false
+					load_complex_type ctx p t, access i1 true, access i2 false
 			) in
 			PMap.add n {
 				cf_name = n;
@@ -223,9 +231,9 @@ and load_type ctx p t =
 	| TPFunction (args,r) ->
 		match args with
 		| [TPNormal { tpackage = []; tparams = []; tname = "Void" }] ->
-			TFun ([],load_type ctx p r)
+			TFun ([],load_complex_type ctx p r)
 		| _ ->
-			TFun (List.map (fun t -> "",false,load_type ctx p t) args,load_type ctx p r)
+			TFun (List.map (fun t -> "",false,load_complex_type ctx p t) args,load_complex_type ctx p r)
 
 let hide_types ctx =
 	let old_locals = ctx.local_types in
@@ -237,15 +245,18 @@ let hide_types ctx =
 		ctx.type_params <- old_type_params;
 	)
 
+(*
+	load a type while ignoring the current imports or local types
+*)
 let load_core_type ctx name =
 	let show = hide_types ctx in
-	let t = load_normal_type ctx { tpackage = []; tname = name; tparams = [] } null_pos false in
+	let t = load_instance ctx { tpackage = []; tname = name; tparams = []; tsub = None; } null_pos false in
 	show();
 	t
 
 let t_iterator ctx =
 	let show = hide_types ctx in
-	match load_type_def ctx null_pos ([],"Iterator") with
+	match load_type_def ctx null_pos { tpackage = []; tname = "Iterator"; tparams = []; tsub = None } with
 	| TTypeDecl t ->
 		show();
 		if List.length t.t_types <> 1 then assert false;
@@ -254,8 +265,11 @@ let t_iterator ctx =
 	| _ ->
 		assert false
 
+(*
+	load either a type t or Null<Unknown> if not defined
+*)
 let load_type_opt ?(opt=false) ctx p t =
-	let t = (match t with None -> mk_mono() | Some t -> load_type ctx p t) in
+	let t = (match t with None -> mk_mono() | Some t -> load_complex_type ctx p t) in
 	if opt then ctx.api.tnull t else t
 
 (* ---------------------------------------------------------------------- *)
@@ -403,7 +417,7 @@ let set_heritance ctx c herits p =
 			()
 		| HExtends t ->
 			if c.cl_super <> None then error "Cannot extend several classes" p;
-			let t = load_normal_type ctx t p false in
+			let t = load_instance ctx t p false in
 			(match follow t with
 			| TInst ({ cl_path = [],"Array" },_)
 			| TInst ({ cl_path = [],"String" },_)
@@ -417,7 +431,7 @@ let set_heritance ctx c herits p =
 				c.cl_super <- Some (cl,params)
 			| _ -> error "Should extend by using a class" p)
 		| HImplements t ->
-			let t = load_normal_type ctx t p false in
+			let t = load_instance ctx t p false in
 			(match follow t with
 			| TInst ({ cl_path = [],"ArrayAccess"; cl_extern = true; },[t]) ->
 				if c.cl_array_access <> None then error "Duplicate array access" p;
@@ -581,7 +595,7 @@ let init_class ctx c p herits fields =
 				| Some t ->
 					let old = ctx.type_params in
 					if stat then ctx.type_params <- [];
-					let t = load_type ctx p t in
+					let t = load_complex_type ctx p t in
 					if stat then ctx.type_params <- old;
 					t
 			) in
@@ -673,7 +687,7 @@ let init_class ctx c p herits fields =
 			) in
 			access, constr, cf, delay
 		| FProp (name,doc,access,get,set,t) ->
-			let ret = load_type ctx p t in
+			let ret = load_complex_type ctx p t in
 			let check_get = ref (fun() -> ()) in
 			let check_set = ref (fun() -> ()) in
 			let check_method m t () =
@@ -869,7 +883,6 @@ let type_module ctx m tdecls loadp =
 	let m = {
 		mpath = m;
 		mtypes = List.rev !decls;
-		mimports = [];
 	} in
 	Hashtbl.add ctx.modules m.mpath m;
 	(* PASS 2 : build types structure - does not type any expression ! *)
@@ -932,23 +945,25 @@ let type_module ctx m tdecls loadp =
 	(* back to PASS2 *)
 	List.iter (fun (d,p) ->
 		match d with
-		| EImport (pack,name,topt) ->
-			let md = ctx.api.load_module (pack,name) p in
-			let types = List.filter (fun t -> not (t_private t)) md.mtypes in
-			(match topt with
-			| None -> ctx.local_types <- ctx.local_types @ types
-			| Some t ->
-				try
-					let t = List.find (fun tdecl -> snd (t_path tdecl) = t) types in
-					ctx.local_types <- ctx.local_types @ [t]
-				with
-					Not_found -> error ("Module " ^ s_type_path (pack,name) ^ " does not define type " ^ t) p
-			);
-			m.mimports <- (md,topt) :: m.mimports;
-		| EUsing (pack,name) ->
-			let md = ctx.api.load_module (pack,name) p in
-			let types = List.filter (fun t -> not (t_private t)) md.mtypes in
-			ctx.local_using <- ctx.local_using @ types;
+		| EImport t ->
+			(match t.tsub with
+			| None ->
+				let md = ctx.api.load_module (t.tpackage,t.tname) p in
+				let types = List.filter (fun t -> not (t_private t)) md.mtypes in
+				ctx.local_types <- ctx.local_types @ types
+			| Some _ ->
+				let t = load_type_def ctx p t in
+				ctx.local_types <- ctx.local_types @ [t]
+			)
+		| EUsing t ->
+			(match t.tsub with
+			| None ->
+				let md = ctx.api.load_module (t.tpackage,t.tname) p in
+				let types = List.filter (fun t -> not (t_private t)) md.mtypes in
+				ctx.local_using <- ctx.local_using @ types;
+			| Some _ ->
+				let t = load_type_def ctx p t in
+				ctx.local_using<- ctx.local_using @ [t])
 		| EClass d ->
 			let c = get_class d.d_name in
 			delays := !delays @ check_overriding ctx c p :: check_interfaces ctx c p :: init_class ctx c p d.d_flags d.d_data
@@ -985,7 +1000,7 @@ let type_module ctx m tdecls loadp =
 		| ETypedef d ->
 			let t = get_tdef d.d_name in
 			ctx.type_params <- t.t_types;
-			let tt = load_type ctx p d.d_data in
+			let tt = load_complex_type ctx p d.d_data in
 			if t.t_type == follow tt then error "Recursive typedef is not allowed" p;
 			(match t.t_type with
 			| TMono r ->
@@ -995,8 +1010,7 @@ let type_module ctx m tdecls loadp =
 			| _ -> assert false);
 	) tdecls;
 	(* PASS 3 : type checking, delayed until all modules and types are built *)
-	ctx.delays := !delays :: !(ctx.delays);
-	m.mimports <- List.rev m.mimports;
+	ctx.delays := !delays :: !(ctx.delays);	
 	m
 
 let parse_module ctx m p =
@@ -1037,13 +1051,14 @@ let parse_module ctx m p =
 					d_doc = None;
 					d_params = d.d_params;
 					d_flags = if priv then [EPrivate] else [];
-					d_data = TPNormal (if priv then { tpackage = []; tname = "Dynamic"; tparams = []; } else 
+					d_data = TPNormal (if priv then { tpackage = []; tname = "Dynamic"; tparams = []; tsub = None; } else 
 						{
 							tpackage = !remap;
 							tname = d.d_name;
 							tparams = List.map (fun (s,_) ->
-								TPType (TPNormal { tpackage = []; tname = s; tparams = [] })
+								TPType (TPNormal { tpackage = []; tname = s; tparams = []; tsub = None; })
 							) d.d_params;
+							tsub = None;
 						});
 				},p) :: acc
 			in
@@ -1052,7 +1067,7 @@ let parse_module ctx m p =
 			| EEnum d -> build EPrivate d
 			| ETypedef d -> build EPrivate d
 			| EImport _ | EUsing _ -> acc
-		) [(EImport (!remap, snd m, None),null_pos)] decls)
+		) [(EImport { tpackage = !remap; tname = snd m; tparams = []; tsub = None; },null_pos)] decls)
 	else
 		decls
 

+ 11 - 13
typer.ml

@@ -246,7 +246,7 @@ let rec type_module_type ctx t tparams p =
 			error (s_type_path s.t_path ^ " is not a value") p
 
 let type_type ctx tpath p =
-	type_module_type ctx (Typeload.load_type_def ctx p tpath) None p
+	type_module_type ctx (Typeload.load_type_def ctx p { tpackage = fst tpath; tname = snd tpath; tparams = []; tsub = None }) None p
 
 let get_constructor c p =
 	let rec loop c = 
@@ -422,7 +422,7 @@ let type_ident ctx i is_type p mode =
 		let infos = mk_infos ctx p [] in
 		let e = type_expr ctx infos true in
 		if mode = MGet then
-			AccExpr { e with etype = Typeload.load_normal_type ctx { tpackage = ["haxe"]; tname = "PosInfos"; tparams = [] } p false }
+			AccExpr { e with etype = Typeload.load_instance ctx { tpackage = ["haxe"]; tname = "PosInfos"; tparams = []; tsub = None } p false }
 		else
 			AccNo i
 	| _ ->
@@ -1084,7 +1084,7 @@ and type_access ctx e p mode =
 									raise (Error (Module_not_found (List.rev !path,name),p))
 								with
 									Not_found ->
-										if ctx.in_display then raise (Parser.TypePath (List.map (fun (n,_,_) -> n) (List.rev acc)));
+										if ctx.in_display then raise (Parser.TypePath (List.map (fun (n,_,_) -> n) (List.rev acc),None));
 										raise e)
 				| (_,false,_) as x :: path ->
 					loop (x :: acc) path
@@ -1346,7 +1346,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 	| ETry (e1,catches) ->
 		let e1 = type_expr ctx ~need_val e1 in
 		let catches = List.map (fun (v,t,e) ->
-			let t = Typeload.load_type ctx (pos e) t in
+			let t = Typeload.load_complex_type ctx (pos e) t in
 			let name = (match follow t with
 				| TInst ({ cl_path = path },params) | TEnum ({ e_path = path },params) ->
 					List.iter (fun pt ->
@@ -1373,7 +1373,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 	| ECall (e,el) ->
 		type_call ctx e el p
 	| ENew (t,el) ->
-		let t = Typeload.load_normal_type ctx t p true in
+		let t = Typeload.load_instance ctx t p true in
 		let el, c , params = (match follow t with
 		| TInst (c,params) ->
 			let name = (match c.cl_path with [], name -> name | x :: _ , _ -> x) in
@@ -1436,7 +1436,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 	| ECast (e, Some t) ->
 		(* // if( Std.is(tmp,T) ) tmp else throw "Class cast error" *)
 		let etmp = (EConst (Ident "tmp"),p) in
-		let t = Typeload.load_type ctx (pos e) t in
+		let t = Typeload.load_complex_type ctx (pos e) t in
 		let tname = (match follow t with
 		| TInst (_,params) | TEnum (_,params) ->
 			List.iter (fun pt ->
@@ -1463,7 +1463,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 	| EDisplay e ->
 		let old = ctx.in_display in
 		ctx.in_display <- true;
-		let e = (try type_expr ctx e with Error (Unknown_ident n,_) -> raise (Parser.TypePath [n])) in
+		let e = (try type_expr ctx e with Error (Unknown_ident n,_) -> raise (Parser.TypePath ([n],None))) in
 		ctx.in_display <- old;
 		let t = (match follow e.etype with
 			| TInst (c,params) ->
@@ -1519,7 +1519,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 		) in
 		raise (Display t)
 	| EDisplayNew t ->
-		let t = Typeload.load_normal_type ctx t p true in
+		let t = Typeload.load_instance ctx t p true in
 		(match follow t with
 		| TInst (c,params) ->
 			let f = get_constructor c p in
@@ -1659,8 +1659,7 @@ let get_type_module ctx t =
 		(* @Main, other generated classes ? *)
 		{
 			mtypes = [t];
-			mpath = t_path t;
-			mimports = [];
+			mpath = t_path t;			
 		}
 	with
 		Exit -> !mfound
@@ -1771,7 +1770,7 @@ let types ctx main excludes =
 	(match main with
 	| None -> ()
 	| Some cl ->
-		let t = Typeload.load_type_def ctx null_pos cl in
+		let t = Typeload.load_type_def ctx null_pos { tpackage = fst cl; tname = snd cl; tparams = []; tsub = None } in
 		let ft, r = (match t with
 		| TEnumDecl _ | TTypeDecl _ ->
 			error ("Invalid -main : " ^ s_type_path cl ^ " is not a class") null_pos
@@ -1810,8 +1809,7 @@ let types ctx main excludes =
 let create com =
 	let empty =	{
 		mpath = [] , "";
-		mtypes = [];
-		mimports = [];
+		mtypes = [];		
 	} in
 	let ctx = {
 		com = com;