Przeglądaj źródła

removed Type/EType (fixed issue #730)
fixed regression issue with r4719

Nicolas Cannasse 13 lat temu
rodzic
commit
453f470c4a
12 zmienionych plików z 183 dodań i 194 usunięć
  1. 6 5
      ast.ml
  2. 3 3
      codegen.ml
  3. 5 5
      genas3.ml
  4. 1 1
      genswf.ml
  5. 7 7
      genswf9.ml
  6. 63 68
      interp.ml
  7. 1 1
      lexer.mll
  8. 5 5
      optimizer.ml
  9. 58 60
      parser.ml
  10. 6 2
      std/haxe/macro/Expr.hx
  11. 7 3
      typeload.ml
  12. 21 34
      typer.ml

+ 6 - 5
ast.ml

@@ -102,7 +102,6 @@ type constant =
 	| Float of string
 	| String of string
 	| Ident of string
-	| Type of string
 	| Regexp of string * string
 
 type token =
@@ -169,7 +168,6 @@ and expr_def =
 	| EArray of expr * expr
 	| EBinop of binop * expr * expr
 	| EField of expr * string
-	| EType of expr * string
 	| EParenthesis of expr
 	| EObjectDecl of (string * expr) list
 	| EArrayDecl of expr list
@@ -259,10 +257,15 @@ type type_decl = type_def * pos
 
 type package = string list * type_decl list
 
+let is_lower_ident i =
+	match String.unsafe_get i 0 with
+	| 'a'..'z' | '_' -> true
+	| _ -> false
+
 let pos = snd
 
 let is_postfix (e,_) = function
-	| Increment | Decrement -> (match e with EConst _ | EField _ | EType _ | EArray _ -> true | _ -> false)
+	| Increment | Decrement -> (match e with EConst _ | EField _ | EArray _ -> true | _ -> false)
 	| Not | Neg | NegBits -> false
 
 let is_prefix = function
@@ -305,7 +308,6 @@ let s_constant = function
 	| Float s -> s
 	| String s -> "\"" ^ s_escape s ^ "\""
 	| Ident s -> s
-	| Type s -> s
 	| Regexp (r,o) -> "~/" ^ r ^ "/"
 
 let s_access = function
@@ -485,7 +487,6 @@ let map_expr loop (e,p) =
 	| EArray (e1,e2) -> EArray (loop e1, loop e2)
 	| EBinop (op,e1,e2) -> EBinop (op,loop e1, loop e2)
 	| EField (e,f) -> EField (loop e, f)
-	| EType (e,f) -> EType (loop e, f)
 	| EParenthesis e -> EParenthesis (loop e)
 	| EObjectDecl fl -> EObjectDecl (List.map (fun (f,e) -> f,loop e) fl)
 	| EArrayDecl el -> EArrayDecl (List.map loop el)

+ 3 - 3
codegen.ml

@@ -67,7 +67,7 @@ let type_constant com c p =
 	| Ident "true" -> mk (TConst (TBool true)) t.tbool p
 	| Ident "false" -> mk (TConst (TBool false)) t.tbool p
 	| Ident "null" -> mk (TConst TNull) (t.tnull (mk_mono())) p
-	| Ident t | Type t -> error ("Invalid constant :  " ^ t) p
+	| Ident t -> error ("Invalid constant :  " ^ t) p
 	| Regexp _ -> error "Invalid constant" p
 
 let rec type_constant_value com (e,p) =
@@ -384,8 +384,8 @@ let build_macro_type ctx pl p =
 		| [TInst ({ cl_kind = KExpr (EArrayDecl [ECall (e,args),_],_) },_)] ->
 			let rec loop e =
 				match fst e with
-				| EField (e,f) | EType (e,f) -> f :: loop e
-				| EConst (Ident i | Type i) -> [i]
+				| EField (e,f) -> f :: loop e
+				| EConst (Ident i) -> [i]
 				| _ -> error "Invalid macro call" p
 			in
 			(match loop e with

+ 5 - 5
genas3.ml

@@ -192,7 +192,7 @@ let rec type_str ctx t p =
 			| _ ->
 				let rec loop = function
 					| [] -> "Object"
-					| (":fakeEnum",[Ast.EConst (Ast.Type n),_],_) :: _ ->
+					| (":fakeEnum",[Ast.EConst (Ast.Ident n),_],_) :: _ ->
 						(match n with
 						| "Int" -> "int"
 						| "UInt" -> "uint"
@@ -285,8 +285,8 @@ let gen_function_header ctx name f params p =
 	print ctx "function%s(" (match name with None -> "" | Some (n,meta) ->
 		let rec loop = function
 			| [] -> n
-			| (":getter",[Ast.EConst (Ast.Ident i | Ast.Type i),_],_) :: _ -> "get " ^ i
-			| (":setter",[Ast.EConst (Ast.Ident i | Ast.Type i),_],_) :: _ -> "set " ^ i
+			| (":getter",[Ast.EConst (Ast.Ident i),_],_) :: _ -> "get " ^ i
+			| (":setter",[Ast.EConst (Ast.Ident i),_],_) :: _ -> "set " ^ i
 			| _ :: l -> loop l
 		in
 		" " ^ loop meta
@@ -839,11 +839,11 @@ let generate_field ctx static f =
 	ctx.gen_uid <- 0;
 	List.iter (fun(m,pl,_) ->
 		match m,pl with
-		| ":meta", [Ast.ECall ((Ast.EConst (Ast.Ident n | Ast.Type n),_),args),_] ->
+		| ":meta", [Ast.ECall ((Ast.EConst (Ast.Ident n),_),args),_] ->
 			let mk_arg (a,p) =
 				match a with
 				| Ast.EConst (Ast.String s) -> (None, s)
-				| Ast.EBinop (Ast.OpAssign,(Ast.EConst (Ast.Ident n | Ast.Type n),_),(Ast.EConst (Ast.String s),_)) -> (Some n, s)
+				| Ast.EBinop (Ast.OpAssign,(Ast.EConst (Ast.Ident n),_),(Ast.EConst (Ast.String s),_)) -> (Some n, s)
 				| _ -> error "Invalid meta definition" p
 			in
 			print ctx "[%s" n;

+ 1 - 1
genswf.ml

@@ -404,7 +404,7 @@ let build_class com c file =
 			d_name = path.tname;
 			d_doc = None;
 			d_params = [];
-			d_meta = [(":fakeEnum",[EConst (Type !real_type),pos],pos)];
+			d_meta = [(":fakeEnum",[EConst (Ident !real_type),pos],pos)];
 			d_flags = [EExtern];
 			d_data = constr;
 		} in

+ 7 - 7
genswf9.ml

@@ -218,7 +218,7 @@ let rec type_id ctx t =
 	| TEnum (e,_) ->
 		let rec loop = function
 			| [] -> type_path ctx e.e_path
-			| (":fakeEnum",[Ast.EConst (Ast.Type n),_],_) :: _ -> type_path ctx ([],n)
+			| (":fakeEnum",[Ast.EConst (Ast.Ident n),_],_) :: _ -> type_path ctx ([],n)
 			| _ :: l -> loop l
 		in
 		loop e.e_meta
@@ -248,7 +248,7 @@ let classify ctx t =
 	| TEnum (e,_) ->
 		let rec loop = function
 			| [] -> KType (type_id ctx t)
-			| (":fakeEnum",[Ast.EConst (Type n),_],_) :: _ ->
+			| (":fakeEnum",[Ast.EConst (Ident n),_],_) :: _ ->
 				(match n with
 				| "Int" -> KInt
 				| "UInt" -> KUInt
@@ -1861,11 +1861,11 @@ let generate_enum_init ctx e hc meta =
 let extract_meta meta =
 	let rec loop = function
 		| [] -> []
-		| (":meta",[ECall ((EConst (Ident n | Type n),_),args),_],_) :: l ->
+		| (":meta",[ECall ((EConst (Ident n),_),args),_],_) :: l ->
 			let mk_arg (a,p) =
 				match a with
 				| EConst (String s) -> (None, s)
-				| EBinop (OpAssign,(EConst (Ident n | Type n),_),(EConst (String s),_)) -> (Some n, s)
+				| EBinop (OpAssign,(EConst (Ident n),_),(EConst (String s),_)) -> (Some n, s)
 				| _ -> error "Invalid meta definition" p
 			in
 			{ hlmeta_name = n; hlmeta_data = Array.of_list (List.map mk_arg args) } :: loop l
@@ -1896,8 +1896,8 @@ let generate_field_kind ctx f c stat =
 		| _ ->
 			let rec lookup_kind = function
 				| [] -> f.cf_name, MK3Normal
-				| (":getter",[EConst (Ident f | Type f),_],_) :: _ -> f, MK3Getter
-				| (":setter",[EConst (Ident f | Type f),_],_) :: _ -> f, MK3Setter
+				| (":getter",[EConst (Ident f),_],_) :: _ -> f, MK3Getter
+				| (":setter",[EConst (Ident f),_],_) :: _ -> f, MK3Setter
 				| _ :: l -> lookup_kind l
 			in
 			let name, kind = lookup_kind f.cf_meta in
@@ -1986,7 +1986,7 @@ let generate_class ctx c =
 					ident f.cf_name
 			| x :: l ->
 				match x with
-				| ((":getter" | ":setter"),[EConst (Ident f | Type f),_],_) -> ident f
+				| ((":getter" | ":setter"),[EConst (Ident f),_],_) -> ident f
 				| (":ns",[EConst (String ns),_],_) -> HMName (f.cf_name,HNNamespace ns)
 				| (":protected",[],_) -> protect()
 				| _ -> loop_meta l

+ 63 - 68
interp.ml

@@ -1773,12 +1773,11 @@ let macro_lib =
 				let h_tag = hash "tag" and h_args = hash "args" in
 				let ctx = get_ctx() in
 				let error v = failwith ("Unsupported value " ^ ctx.do_string v) in
-				let is_ident n = n <> "" && n.[0] < 'A' || n.[0] > 'Z' in
 				let make_path t =
 					let rec loop = function
 						| [] -> assert false
-						| [name] -> (Ast.EConst (if is_ident name then Ast.Ident name else Ast.Type name),p)
-						| name :: l -> if is_ident name then (Ast.EField (loop l,name),p) else (Ast.EType (loop l,name),p)
+						| [name] -> (Ast.EConst (Ast.Ident name),p)
+						| name :: l -> (Ast.EField (loop l,name),p)
 					in
 					let t = t_infos t in
 					loop (List.rev (if t.mt_module.m_path = t.mt_path then fst t.mt_path @ [snd t.mt_path] else fst t.mt_module.m_path @ [snd t.mt_module.m_path;snd t.mt_path]))
@@ -3032,8 +3031,7 @@ let encode_const c =
 	| Float s -> 1, [enc_string s]
 	| String s -> 2, [enc_string s]
 	| Ident s -> 3, [enc_string s]
-	| Type s -> 4, [enc_string s]
-	| Regexp (s,opt) -> 5, [enc_string s;enc_string opt]
+	| Regexp (s,opt) -> 4, [enc_string s;enc_string opt]
 	in
 	enc_enum IConst tag pl
 
@@ -3169,25 +3167,23 @@ and encode_expr e =
 				2, [encode_binop op;loop e1;loop e2]
 			| EField (e,f) ->
 				3, [loop e;enc_string f]
-			| EType (e,f) ->
-				4, [loop e;enc_string f]
 			| EParenthesis e ->
-				5, [loop e]
+				4, [loop e]
 			| EObjectDecl fl ->
-				6, [enc_array (List.map (fun (f,e) -> enc_obj [
+				5, [enc_array (List.map (fun (f,e) -> enc_obj [
 					"field",enc_string f;
 					"expr",loop e;
 				]) fl)]
 			| EArrayDecl el ->
-				7, [enc_array (List.map loop el)]
+				6, [enc_array (List.map loop el)]
 			| ECall (e,el) ->
-				8, [loop e;enc_array (List.map loop el)]
+				7, [loop e;enc_array (List.map loop el)]
 			| ENew (p,el) ->
-				9, [encode_path p; enc_array (List.map loop el)]
+				8, [encode_path p; enc_array (List.map loop el)]
 			| EUnop (op,flag,e) ->
-				10, [encode_unop op; VBool (match flag with Prefix -> false | Postfix -> true); loop e]
+				9, [encode_unop op; VBool (match flag with Prefix -> false | Postfix -> true); loop e]
 			| EVars vl ->
-				11, [enc_array (List.map (fun (v,t,eo) ->
+				10, [enc_array (List.map (fun (v,t,eo) ->
 					enc_obj [
 						"name",enc_string v;
 						"type",null encode_type t;
@@ -3195,26 +3191,26 @@ and encode_expr e =
 					]
 				) vl)]
 			| EFunction (name,f) ->
-				12, [null enc_string name; encode_fun f]
+				11, [null enc_string name; encode_fun f]
 			| EBlock el ->
-				13, [enc_array (List.map loop el)]
+				12, [enc_array (List.map loop el)]
 			| EFor (e,eloop) ->
-				14, [loop e;loop eloop]
+				13, [loop e;loop eloop]
 			| EIn (e1,e2) ->
-				15, [loop e1;loop e2]
+				14, [loop e1;loop e2]
 			| EIf (econd,e,eelse) ->
-				16, [loop econd;loop e;null loop eelse]
+				15, [loop econd;loop e;null loop eelse]
 			| EWhile (econd,e,flag) ->
-				17, [loop econd;loop e;VBool (match flag with NormalWhile -> true | DoWhile -> false)]
+				16, [loop econd;loop e;VBool (match flag with NormalWhile -> true | DoWhile -> false)]
 			| ESwitch (e,cases,eopt) ->
-				18, [loop e;enc_array (List.map (fun (ecl,e) ->
+				17, [loop e;enc_array (List.map (fun (ecl,e) ->
 					enc_obj [
 						"values",enc_array (List.map loop ecl);
 						"expr",loop e
 					]
 				) cases);null loop eopt]
 			| ETry (e,catches) ->
-				19, [loop e;enc_array (List.map (fun (v,t,e) ->
+				18, [loop e;enc_array (List.map (fun (v,t,e) ->
 					enc_obj [
 						"name",enc_string v;
 						"type",encode_type t;
@@ -3222,25 +3218,25 @@ and encode_expr e =
 					]
 				) catches)]
 			| EReturn eo ->
-				20, [null loop eo]
+				19, [null loop eo]
 			| EBreak ->
-				21, []
+				20, []
 			| EContinue ->
-				22, []
+				21, []
 			| EUntyped e ->
-				23, [loop e]
+				22, [loop e]
 			| EThrow e ->
-				24, [loop e]
+				23, [loop e]
 			| ECast (e,t) ->
-				25, [loop e; null encode_type t]
+				24, [loop e; null encode_type t]
 			| EDisplay (e,flag) ->
-				26, [loop e; VBool flag]
+				25, [loop e; VBool flag]
 			| EDisplayNew t ->
-				27, [encode_path t]
+				26, [encode_path t]
 			| ETernary (econd,e1,e2) ->
-				28, [loop econd;loop e1;loop e2]
+				27, [loop econd;loop e1;loop e2]
 			| ECheckType (e,t) ->
-				29, [loop e; encode_type t]
+				28, [loop e; encode_type t]
 		in
 		enc_obj [
 			"pos", encode_pos p;
@@ -3299,8 +3295,8 @@ let decode_const c =
 	| 1, [s] -> Float (dec_string s)
 	| 2, [s] -> String (dec_string s)
 	| 3, [s] -> Ident (dec_string s)
-	| 4, [s] -> Type (dec_string s)
-	| 5, [s;opt] -> Regexp (dec_string s, dec_string opt)
+	| 4, [s;opt] -> Regexp (dec_string s, dec_string opt)
+	| 5, [s] -> Ident (dec_string s) (** deprecated CType, keep until 3.0 release **)
 	| _ -> raise Invalid_expr
 
 let rec decode_op op =
@@ -3429,68 +3425,68 @@ let decode_expr v =
 			EBinop (decode_op op, loop e1, loop e2)
 		| 3, [e;f] ->
 			EField (loop e, dec_string f)
-		| 4, [e;f] ->
-			EType (loop e, dec_string f)
-		| 5, [e] ->
+		| 4, [e] ->
 			EParenthesis (loop e)
-		| 6, [a] ->
+		| 5, [a] ->
 			EObjectDecl (List.map (fun o ->
 				(dec_string (field o "field"), loop (field o "expr"))
 			) (dec_array a))
-		| 7, [a] ->
+		| 6, [a] ->
 			EArrayDecl (List.map loop (dec_array a))
-		| 8, [e;el] ->
+		| 7, [e;el] ->
 			ECall (loop e,List.map loop (dec_array el))
-		| 9, [t;el] ->
+		| 8, [t;el] ->
 			ENew (decode_path t,List.map loop (dec_array el))
-		| 10, [op;VBool f;e] ->
+		| 9, [op;VBool f;e] ->
 			EUnop (decode_unop op,(if f then Postfix else Prefix),loop e)
-		| 11, [vl] ->
+		| 10, [vl] ->
 			EVars (List.map (fun v ->
 				(dec_string (field v "name"),opt decode_ctype (field v "type"),opt loop (field v "expr"))
 			) (dec_array vl))
-		| 12, [fname;f] ->
+		| 11, [fname;f] ->
 			EFunction (opt dec_string fname,decode_fun f)
-		| 13, [el] ->
+		| 12, [el] ->
 			EBlock (List.map loop (dec_array el))
-		| 14, [e1;e2] ->
+		| 13, [e1;e2] ->
 			EFor (loop e1, loop e2)
-		| 15, [e1;e2] ->
+		| 14, [e1;e2] ->
 			EIn (loop e1, loop e2)
-		| 16, [e1;e2;e3] ->
+		| 15, [e1;e2;e3] ->
 			EIf (loop e1, loop e2, opt loop e3)
-		| 17, [e1;e2;VBool flag] ->
+		| 16, [e1;e2;VBool flag] ->
 			EWhile (loop e1,loop e2,if flag then NormalWhile else DoWhile)
-		| 18, [e;cases;eo] ->
+		| 17, [e;cases;eo] ->
 			let cases = List.map (fun c ->
 				(List.map loop (dec_array (field c "values")),loop (field c "expr"))
 			) (dec_array cases) in
 			ESwitch (loop e,cases,opt loop eo)
-		| 19, [e;catches] ->
+		| 18, [e;catches] ->
 			let catches = List.map (fun c ->
 				(dec_string (field c "name"),decode_ctype (field c "type"),loop (field c "expr"))
 			) (dec_array catches) in
 			ETry (loop e, catches)
-		| 20, [e] ->
+		| 19, [e] ->
 			EReturn (opt loop e)
-		| 21, [] ->
+		| 20, [] ->
 			EBreak
-		| 22, [] ->
+		| 21, [] ->
 			EContinue
-		| 23, [e] ->
+		| 22, [e] ->
 			EUntyped (loop e)
-		| 24, [e] ->
+		| 23, [e] ->
 			EThrow (loop e)
-		| 25, [e;t] ->
+		| 24, [e;t] ->
 			ECast (loop e,opt decode_ctype t)
-		| 26, [e;f] ->
+		| 25, [e;f] ->
 			EDisplay (loop e,dec_bool f)
-		| 27, [t] ->
+		| 26, [t] ->
 			EDisplayNew (decode_path t)
-		| 28, [e1;e2;e3] ->
+		| 27, [e1;e2;e3] ->
 			ETernary (loop e1,loop e2,loop e3)
-		| 29, [e;t] ->
+		| 28, [e;t] ->
 			ECheckType (loop e, decode_ctype t)
+		| 29, [e;f] ->
+			EField (loop e, dec_string f) (*** deprecated EType, keep until haxe 3 **)
 		| _ ->
 			raise Invalid_expr
 	in
@@ -3822,14 +3818,14 @@ open Ast
 let rec make_ast e =
 	let mk_path (pack,name) p =
 		match List.rev pack with
-		| [] -> (EConst (Type name),p)
+		| [] -> (EConst (Ident name),p)
 		| pl ->
 			let rec loop = function
 				| [] -> assert false
 				| [n] -> (EConst (Ident n),p)
 				| n :: l -> (EField (loop l, n),p)
 			in
-			(EType (loop pl,name),p)
+			(EField (loop pl,name),p)
 	in
 	let mk_const = function
 		| TInt i -> Int (Int32.to_string i)
@@ -3882,12 +3878,11 @@ let rec make_ast e =
 		| _ -> Some (mk_type t)
 	in
 	let eopt = function None -> None | Some e -> Some (make_ast e) in
-	let is_ident n = n.[0] < 'A' || n.[0] > 'Z' in
 	((match e.eexpr with
 	| TConst c ->
 		EConst (mk_const c)
-	| TLocal v -> EConst (if is_ident v.v_name then Ident v.v_name else Type v.v_name)
-	| TEnumField (en,f) -> if is_ident f then EField (mk_path en.e_path e.epos,f) else EType (mk_path en.e_path e.epos,f)
+	| TLocal v -> EConst (Ident v.v_name)
+	| TEnumField (en,f) -> EField (mk_path en.e_path e.epos,f)
 	| TArray (e1,e2) -> EArray (make_ast e1,make_ast e2)
 	| TBinop (op,e1,e2) -> EBinop (op, make_ast e1, make_ast e2)
 	| TField (e,f) | TClosure (e,f) -> EField (make_ast e, f)
@@ -3916,7 +3911,7 @@ let rec make_ast e =
 			let unused = (EConst (Ident "_"),p) in
 			let args = (match args with
 				| None -> None
-				| Some l -> Some (List.map (function None -> unused | Some v -> (EConst (if is_ident v.v_name then Ident v.v_name else Type v.v_name),p)) l)
+				| Some l -> Some (List.map (function None -> unused | Some v -> (EConst (Ident v.v_name),p)) l)
 			) in
 			let mk_args n =
 				match args with
@@ -3927,7 +3922,7 @@ let rec make_ast e =
 			List.map (fun i ->
 				let c = (try List.nth en.e_names i with _ -> assert false) in
 				let cfield = (try PMap.find c en.e_constrs with Not_found -> assert false) in
-				let c = (EConst (if is_ident c then Ident c else Type c),p) in
+				let c = (EConst (Ident c),p) in
 				(match follow cfield.ef_type with TFun (eargs,_) -> (ECall (c,mk_args (List.length eargs)),p) | _ -> c)
 			) idx, make_ast e
 		in

+ 1 - 1
lexer.mll

@@ -259,7 +259,7 @@ and token = parse
 			mk lexbuf (Dollar v)
 		}
 	| ident { mk_ident lexbuf }
-	| idtype { mk lexbuf (Const (Type (lexeme lexbuf))) }
+	| idtype { mk lexbuf (Const (Ident (lexeme lexbuf))) }
 	| _ { invalid_char lexbuf }
 
 and comment = parse

+ 5 - 5
optimizer.ml

@@ -857,7 +857,7 @@ let optimize_completion_expr e =
 	let rec loop e =
 		let p = snd e in
 		match fst e with
-		| EConst (Ident n | Type n) ->
+		| EConst (Ident n) ->
 			(try
 				(match get_local n with
 				| Some _ , _ -> ()
@@ -865,7 +865,7 @@ let optimize_completion_expr e =
 			with Not_found ->
 				());
 			e
-		| EBinop (OpAssign,(EConst (Ident n | Type n),_),esub) ->
+		| EBinop (OpAssign,(EConst (Ident n),_),esub) ->
 			(try
 				(match get_local n with
 				| None, None when maybe_typed esub -> decl n None (Some esub)
@@ -901,7 +901,7 @@ let optimize_completion_expr e =
 			let e = map e in
 			old();
 			e
-		| EFor ((EIn ((EConst (Ident n | Type n),_) as id,it),p),efor) ->
+		| EFor ((EIn ((EConst (Ident n),_) as id,it),p),efor) ->
 			let it = loop it in
 			let old = save() in
 			decl n None (Some (ECall ((EField ((ECall ((EField (it,"iterator"),p),[]),p),"next"),p),[]),p));
@@ -921,7 +921,7 @@ let optimize_completion_expr e =
 					| ECall (_,pl) ->
 						List.iter (fun p ->
 							match fst p with
-							| EConst (Ident i | Type i) -> decl i None None (* sadly *)
+							| EConst (Ident i) -> decl i None None (* sadly *)
 							| _ -> ()
 						) pl
 					| _ -> ()
@@ -948,7 +948,7 @@ let optimize_completion_expr e =
 			let tmp_hlocals = ref PMap.empty in
 			let rec subst_locals locals e =
 				match fst e with
-				| EConst (Ident n | Type n) ->
+				| EConst (Ident n) ->
 					let p = snd e in
 					(try
 						(match PMap.find n locals.r with

+ 58 - 60
parser.ml

@@ -136,18 +136,17 @@ let rec psep sep f = parser
 	| [< >] -> []
 
 let ident = parser
-	| [< '(Const (Ident i),_) >] -> i
+	| [< '(Const (Ident i),p) >] -> i,p
 
-let any_ident = parser
-	| [< '(Const (Ident i),p) >] -> i, p
-	| [< '(Const (Type t),p) >] -> t, p
+let lower_ident = parser
+	| [< '(Const (Ident i),p) when is_lower_ident i >] -> i
 
 let any_enum_ident = parser
-	| [< i = any_ident >] -> i
+	| [< i = ident >] -> i
 	| [< '(Kwd k,p) when Filename.basename p.pfile = "StdTypes.hx" >] -> s_keyword k, p 
 
 let property_ident = parser
-	| [< i, _ = any_ident >] -> i
+	| [< i, _ = ident >] -> i
 	| [< '(Kwd Dynamic,_) >] -> "dynamic"
 	| [< '(Kwd Default,_) >] -> "default"
 	| [< '(Kwd Null,_) >] -> "null"
@@ -229,7 +228,7 @@ and parse_type_decl s =
 				d_data = t;
 			}, punion p1 p2)
 
-and parse_package s = psep Dot ident s
+and parse_package s = psep Dot lower_ident s
 
 and parse_class_fields tdecl p1 s =
 	let l = parse_class_field_resume tdecl s in
@@ -261,8 +260,8 @@ and parse_class_field_resume tdecl s =
 				()
 			else match List.rev_map fst (Stream.npeek k s) with
 			| Kwd Private :: _ -> junk_tokens (k - 1)
-			| (Const (Ident _ | Type _) | Kwd _) :: DblDot :: At :: l
-			| (Const (Ident _ | Type _) | Kwd _) :: At :: l ->
+			| (Const (Ident _) | Kwd _) :: DblDot :: At :: l
+			| (Const (Ident _) | Kwd _) :: At :: l ->
 				junk_tokens (List.length l)
 			| PClose :: l ->
 				(* count matching parenthesises for metadata call *)
@@ -273,8 +272,8 @@ and parse_class_field_resume tdecl s =
 					| _ :: l -> loop n l
 				in
 				(match loop 0 l with
-				| (Const (Ident _ | Type _) | Kwd _) :: At :: l
-				| (Const (Ident _ | Type _) | Kwd _) :: DblDot :: At :: l -> junk_tokens (List.length l)
+				| (Const (Ident _) | Kwd _) :: At :: l
+				| (Const (Ident _) | Kwd _) :: DblDot :: At :: l -> junk_tokens (List.length l)
 				| _ ->
 					junk k)
 			| _ ->
@@ -318,7 +317,6 @@ and parse_meta = parser
 
 and meta_name = parser
 	| [< '(Const (Ident i),p) >] -> i, p
-	| [< '(Const (Type t),p) >] -> t, p
 	| [< '(Kwd k,p) >] -> s_keyword k,p
 	| [< '(DblDot,_); s >] -> let n, p = meta_name s in ":" ^ n, p
 
@@ -358,44 +356,47 @@ and parse_type_path s = parse_type_path1 [] s
 
 and parse_type_path1 pack = parser
 	| [< '(Const (Ident name),p); s >] ->
-		(match s with parser
-		| [< '(Dot,p) >] ->
-			if is_resuming p then
-				raise (TypePath (List.rev (name :: pack),None))
-			else
-				parse_type_path1 (name :: pack) s
-		| [< '(Semicolon,_) >] ->
-			error (Custom "Type name should start with an uppercase letter") p
-		| [< >] -> serror());
-	| [< '(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,false)))
-				else match s with parser
-					| [< '(Const (Type name),_) >] -> Some name
-					| [< '(Binop OpOr,_) when do_resume() >] ->
+		if is_lower_ident name then
+			(match s with parser
+			| [< '(Dot,p) >] ->
+				if is_resuming p then
+					raise (TypePath (List.rev (name :: pack),None))
+				else
+					parse_type_path1 (name :: pack) s
+			| [< '(Semicolon,_) >] ->
+				error (Custom "Type name should start with an uppercase letter") p
+			| [< >] -> serror())
+		else
+			let sub = (match s with parser
+				| [< '(Dot,p); s >] ->
+					(if is_resuming p then
 						raise (TypePath (List.rev pack,Some (name,false)))
-					| [< >] -> serror())
-			| [< >] -> None
-		) in
-		let params = (match s with parser
-			| [< '(Binop OpLt,_); l = psep Comma parse_type_path_or_const; '(Binop OpGt,_) >] -> l
-			| [< >] -> []
-		) in
-		{
-			tpackage = List.rev pack;
-			tname = name;
-			tparams = params;
-			tsub = sub;
-		}
+					else match s with parser
+						| [< '(Const (Ident name),_) when not (is_lower_ident name) >] -> Some name
+						| [< '(Binop OpOr,_) when do_resume() >] ->
+							raise (TypePath (List.rev pack,Some (name,false)))
+						| [< >] -> serror())
+				| [< >] -> None
+			) in
+			let params = (match s with parser
+				| [< '(Binop OpLt,_); l = psep Comma parse_type_path_or_const; '(Binop OpGt,_) >] -> l
+				| [< >] -> []
+			) in
+			{
+				tpackage = List.rev pack;
+				tname = name;
+				tparams = params;
+				tsub = sub;
+			}
 	| [< '(Binop OpOr,_) when do_resume() >] ->
 		raise (TypePath (List.rev pack,None))
 
 and type_name = parser
-	| [< '(Const (Type name),_) >] -> name
 	| [< '(Const (Ident name),p) >] ->
-		error (Custom "Type name should start with an uppercase letter") p
+		if is_lower_ident name then
+			error (Custom "Type name should start with an uppercase letter") p
+		else
+			name
 
 and parse_type_path_or_const = parser
 	(* we can't allow (expr) here *)
@@ -415,7 +416,7 @@ and parse_complex_type_next t = parser
 
 and parse_type_anonymous opt = parser
 	| [< '(Question,_) when not opt; s >] -> parse_type_anonymous true s
-	| [< name, p1 = any_ident; '(DblDot,_); t = parse_complex_type; s >] ->
+	| [< name, p1 = ident; '(DblDot,_); t = parse_complex_type; s >] ->
 		let next p2 acc =
 			let t = if not opt then t else (match t with
 				| CTPath { tpackage = []; tname = "Null" } -> t
@@ -450,15 +451,15 @@ and parse_enum s =
 		| [< >] -> serror()
 
 and parse_enum_param = parser
-	| [< '(Question,_); name, _ = any_ident; '(DblDot,_); t = parse_complex_type >] -> (name,true,t)
-	| [< name, _ = any_ident; '(DblDot,_); t = parse_complex_type >] -> (name,false,t)
+	| [< '(Question,_); name, _ = ident; '(DblDot,_); t = parse_complex_type >] -> (name,true,t)
+	| [< name, _ = ident; '(DblDot,_); t = parse_complex_type >] -> (name,false,t)
 
 and parse_class_field s =
 	doc := None;
 	match s with parser
 	| [< meta = parse_meta; al = parse_cf_rights true []; doc = get_doc; s >] ->
 		let name, pos, k = (match s with parser
-		| [< '(Kwd Var,p1); name, _ = any_ident; s >] ->
+		| [< '(Kwd Var,p1); name, _ = ident; s >] ->
 			(match s with parser
 			| [< '(POpen,_); i1 = property_ident; '(Comma,_); i2 = property_ident; '(PClose,_); '(DblDot,_); t = parse_complex_type >] ->
 				let e , p2 = (match s with parser
@@ -510,20 +511,19 @@ and parse_cf_rights allow_static l = parser
 
 and parse_fun_name = parser
 	| [< '(Const (Ident name),_) >] -> name
-	| [< '(Const (Type name),_) >] -> name
 	| [< '(Kwd New,_) >] -> "new"
 
 and parse_fun_param = parser
-	| [< '(Question,_); name, _ = any_ident; t = parse_type_opt; c = parse_fun_param_value >] -> (name,true,t,c)
-	| [< name, _ = any_ident; t = parse_type_opt; c = parse_fun_param_value >] -> (name,false,t,c)
+	| [< '(Question,_); name, _ = ident; t = parse_type_opt; c = parse_fun_param_value >] -> (name,true,t,c)
+	| [< name, _ = ident; t = parse_type_opt; c = parse_fun_param_value >] -> (name,false,t,c)
 
 and parse_fun_param_value = parser
 	| [< '(Binop OpAssign,_); e = toplevel_expr >] -> Some e
 	| [< >] -> None
 
 and parse_fun_param_type = parser
-	| [< '(Question,_); name = any_ident; '(DblDot,_); t = parse_complex_type >] -> (name,true,t)
-	| [< name = any_ident; '(DblDot,_); t = parse_complex_type >] -> (name,false,t)
+	| [< '(Question,_); name = ident; '(DblDot,_); t = parse_complex_type >] -> (name,true,t)
+	| [< name = ident; '(DblDot,_); t = parse_complex_type >] -> (name,false,t)
 
 and parse_constraint_params = parser
 	| [< '(Binop OpLt,_); l = psep Comma parse_constraint_param; '(Binop OpGt,_) >] -> l
@@ -545,7 +545,6 @@ and parse_class_herit = parser
 
 and block1 = parser
 	| [< '(Const (Ident name),p); s >] -> block2 name (Ident name) p s
-	| [< '(Const (Type name),p); s >] -> block2 name (Type name) p s
 	| [< '(Const (String name),p); s >] -> block2 (quote_ident name) (String name) p s
 	| [< b = block [] >] -> EBlock b
 
@@ -584,7 +583,7 @@ and parse_block_elt = parser
 and parse_obj_decl = parser
 	| [< '(Comma,_); s >] ->
 		(match s with parser
-		| [< name, _ = any_ident; '(DblDot,_); e = expr; l = parse_obj_decl >] -> (name,e) :: l
+		| [< name, _ = ident; '(DblDot,_); e = expr; l = parse_obj_decl >] -> (name,e) :: l
 		| [< '(Const (String name),_); '(DblDot,_); e = expr; l = parse_obj_decl >] -> (quote_ident name,e) :: l
 		| [< >] -> [])
 	| [< >] -> []
@@ -598,7 +597,7 @@ and parse_array_decl = parser
 		[]
 
 and parse_var_decl = parser
-	| [< name, _ = any_ident; t = parse_type_opt; s >] ->
+	| [< name, _ = ident; t = parse_type_opt; s >] ->
 		match s with parser
 		| [< '(Binop OpAssign,_); e = expr >] -> (name,t,Some e)
 		| [< >] -> (name,t,None)
@@ -631,7 +630,7 @@ and expr = parser
 		| [< >] -> serror())
 	| [< '(POpen,p1); e = expr; '(PClose,p2); s >] -> expr_next (EParenthesis e, punion p1 p2) s
 	| [< '(BkOpen,p1); l = parse_array_decl; '(BkClose,p2); s >] -> expr_next (EArrayDecl l, punion p1 p2) s
-	| [< '(Kwd Function,p1); name = popt any_ident; pl = parse_constraint_params; '(POpen,_); al = psep Comma parse_fun_param; '(PClose,_); t = parse_type_opt; s >] ->
+	| [< '(Kwd Function,p1); name = popt ident; pl = parse_constraint_params; '(POpen,_); al = psep Comma parse_fun_param; '(PClose,_); t = parse_type_opt; s >] ->
 		let make e =
 			let f = {
 				f_params = pl;
@@ -708,7 +707,6 @@ and expr_next e1 = parser
 		if is_resuming p then display (EDisplay (e1,false),p);
 		(match s with parser
 		| [< '(Const (Ident f),p2) when p.pmax = p2.pmin; s >] -> expr_next (EField (e1,f) , punion (pos e1) p2) s
-		| [< '(Const (Type t),p2) when p.pmax = p2.pmin; s >] -> expr_next (EType (e1,t) , punion (pos e1) p2) s
 		| [< '(Binop OpOr,p2) when do_resume() >] -> display (EDisplay (e1,false),p) (* help for debug display mode *)
 		| [< >] ->
 			(* turn an integer followed by a dot into a float *)
@@ -759,7 +757,7 @@ and parse_switch_cases eswitch cases = parser
 		List.rev cases , None
 
 and parse_catch etry = parser
-	| [< '(Kwd Catch,p); '(POpen,_); name, _ = any_ident; s >] ->
+	| [< '(Kwd Catch,p); '(POpen,_); name, _ = ident; s >] ->
 		match s with parser
 		| [< '(DblDot,_); t = parse_complex_type; '(PClose,_); s >] ->
 			(try
@@ -790,7 +788,7 @@ and parse_call_params ec s =
 
 and parse_macro_cond allow_op s =
 	match s with parser
-	| [< '(Const (Ident t | Type t),p) >] ->
+	| [< '(Const (Ident t),p) >] ->
 		parse_macro_ident allow_op t p s
 	| [< '(Kwd k,p) >] ->
 		parse_macro_ident allow_op (s_keyword k) p s

+ 6 - 2
std/haxe/macro/Expr.hx

@@ -40,8 +40,10 @@ enum Constant {
 	CFloat( f : String );
 	CString( s : String );
 	CIdent( s : String );
-	CType( s : String );
 	CRegexp( r : String, opt : String );
+	#if !haxe3
+	CType( s : String );
+	#end
 }
 
 enum Binop {
@@ -94,7 +96,6 @@ enum ExprDef {
 	EArray( e1 : Expr, e2 : Expr );
 	EBinop( op : Binop, e1 : Expr, e2 : Expr );
 	EField( e : Expr, field : String );
-	EType( e : Expr, field : String );
 	EParenthesis( e : Expr );
 	EObjectDecl( fields : Array<{ field : String, expr : Expr }> );
 	EArrayDecl( values : Array<Expr> );
@@ -120,6 +121,9 @@ enum ExprDef {
 	EDisplayNew( t : TypePath );
 	ETernary( econd : Expr, eif : Expr, eelse : Expr );
 	ECheckType( e : Expr, t : ComplexType );
+	#if !haxe3
+	EType( e : Expr, field : String );
+	#end	
 }
 
 enum ComplexType {

+ 7 - 3
typeload.ml

@@ -741,8 +741,8 @@ let build_module_def ctx mt meta fvars fbuild =
 			) in
 			let rec getpath (e,p) =
 				match e with
-				| EConst (Ident i) | EConst (Type i) -> [i]
-				| EField (e,f) | EType (e,f) -> f :: getpath e
+				| EConst (Ident i) -> [i]
+				| EField (e,f) -> f :: getpath e
 				| _ -> error "Build call parameter must be a class path" p
 			in
 			let s = String.concat "." (List.rev (getpath epath)) in
@@ -1141,7 +1141,7 @@ let init_class ctx c p herits fields =
 		| (":require",conds,_) :: l ->
 			let rec loop = function
 				| [] -> check_require l
-				| (EConst (Ident i | Type i),_) :: l ->
+				| (EConst (Ident i),_) :: l ->
 					if not (Common.defined ctx.com i) then
 						Some i
 					else
@@ -1534,6 +1534,10 @@ let load_module ctx m p =
 			with Not_found ->
 				let rec loop = function
 					| [] ->
+						if s_type_path m = "neko.db._Mysql.D" then begin
+							prerr_endline (String.concat ";" (fst m));
+							assert false;
+						end;
 						raise (Error (Module_not_found m,p))
 					| load :: l ->
 						match load m p with

+ 21 - 34
typer.ml

@@ -549,7 +549,7 @@ let get_this ctx p =
 	| FConstructor | FMember ->
 		mk (TConst TThis) ctx.tthis p
 
-let type_ident ctx i is_type p mode =
+let type_ident ?(imported_enums=true) ctx i p mode =
 	match i with
 	| "true" ->
 		if mode = MGet then
@@ -611,6 +611,7 @@ let type_ident ctx i is_type p mode =
 		(* check_locals_masking already done in type_type *)
 		field_access ctx mode f (field_type f) e p
 	with Not_found ->
+		if not imported_enums then raise Not_found;
 		(* lookup imported enums *)
 		let rec loop l =
 			match l with
@@ -1148,13 +1149,13 @@ and type_switch ctx e cases def need_val p =
 		try
 			(match !enum, e with
 			| None, _ -> raise Exit
-			| Some (Some (en,params)), (EConst (Ident i | Type i),p) ->
+			| Some (Some (en,params)), (EConst (Ident i),p) ->
 				if not (PMap.mem i en.e_constrs) then error ("This constructor is not part of the enum " ^ s_type_path en.e_path) p;
 			| _ -> ());
 			let pl = List.map (fun e ->
 				match fst e with
 				| EConst (Ident "_") -> None
-				| EConst (Ident i | Type i) -> Some i
+				| EConst (Ident i) -> Some i
 				| _ -> raise Exit
 			) pl in
 			let e = type_expr ctx e in
@@ -1274,12 +1275,12 @@ and type_switch ctx e cases def need_val p =
 		let t = if not need_val then (mk_mono()) else unify_min ctx !el in
 		mk (TSwitch (eval,cases,def)) t p
 
-and type_ident_noerr ctx i is_type p mode =
+and type_ident_noerr ctx i p mode =
 	try
-		type_ident ctx i is_type p mode
+		type_ident ctx i p mode
 	with Not_found -> try
 		(* lookup type *)
-		if not is_type then raise Not_found;
+		if is_lower_ident i then raise Not_found;
 		let e = (try type_type ctx ([],i) p with Error (Module_not_found ([],name),_) when name = i -> raise Not_found) in
 		AKExpr e
 	with Not_found ->
@@ -1324,15 +1325,10 @@ and type_expr_with_type_raise ctx e t =
 			exc ->
 				ctx.param_type <- old;
 				raise exc)
-	| (EConst (Ident s | Type s),p) ->
-		let old = ctx.local_types in
-		ctx.local_types <- [];
+	| (EConst (Ident s),p) ->
 		(try
-			let e = acc_get ctx (type_ident ctx s (match fst e with EConst (Ident _) -> false | _ -> true) p MGet) p in
-			ctx.local_types <- old;
-			e
+			acc_get ctx (type_ident ~imported_enums:false ctx s p MGet) p
 		with Not_found -> try
-			ctx.local_types <- old;
 			(match t with
 			| None -> raise Not_found
 			| Some t ->
@@ -1418,11 +1414,8 @@ and type_expr_with_type ctx e t =
 and type_access ctx e p mode =
 	match e with
 	| EConst (Ident s) ->
-		type_ident_noerr ctx s false p mode
-	| EConst (Type s) ->
-		type_ident_noerr ctx s true p mode
-	| EField _
-	| EType _ ->
+		type_ident_noerr ctx s p mode
+	| EField _ ->
 		let fields path e =
 			List.fold_left (fun e (f,_,p) ->
 				let e = acc_get ctx (e MGet) p in
@@ -1437,7 +1430,7 @@ and type_access ctx e p mode =
 					| [] -> assert false
 					| (name,flag,p) :: path ->
 						try
-							fields path (type_access ctx (EConst (if flag then Type name else Ident name)) p)
+							fields path (type_access ctx (EConst (Ident name)) p)
 						with
 							Error (Unknown_ident _,p2) as e when p = p2 ->
 								try
@@ -1509,20 +1502,16 @@ and type_access ctx e p mode =
 			| [] -> assert false
 			| (name,_,p) :: pnext ->
 				try
-					fields pnext (fun _ -> type_ident ctx name false p MGet)
+					fields pnext (fun _ -> type_ident ctx name p MGet)
 				with
 					Not_found -> loop [] path
 		in
 		let rec loop acc e =
 			match fst e with
 			| EField (e,s) ->
-				loop ((s,false,p) :: acc) e
-			| EType (e,s) ->
-				loop ((s,true,p) :: acc) e
+				loop ((s,not (is_lower_ident s),p) :: acc) e
 			| EConst (Ident i) ->
-				type_path ((i,false,p) :: acc)
-			| EConst (Type i) ->
-				type_path ((i,true,p) :: acc)
+				type_path ((i,not (is_lower_ident i),p) :: acc)
 			| _ ->
 				fields acc (type_access ctx (fst e) (snd e))
 		in
@@ -1567,10 +1556,8 @@ and type_expr ctx ?(need_val=true) (e,p) =
 		if UTF8.length s <> 1 then error "String must be a single UTF8 char" p;
 		mk (TConst (TInt (Int32.of_int (UChar.code (UTF8.get s 0))))) ctx.t.tint p
 	| EField _
-	| EType _
 	| EArray _
-	| EConst (Ident _)
-	| EConst (Type _) ->
+	| EConst (Ident _) ->
 		acc_get ctx (type_access ctx e p MGet) p
 	| EConst (Regexp (r,opt)) ->
 		let str = mk (TConst (TString r)) ctx.t.tstring p in
@@ -1645,7 +1632,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 		mk (TVars vl) ctx.t.tvoid p
 	| EFor (it,e2) ->
 		let i, e1 = (match it with
-			| (EIn ((EConst (Ident i | Type i),_),e),_) -> i, e
+			| (EIn ((EConst (Ident i),_),e),_) -> i, e
 			| _ -> error "For expression should be 'v in expr'" (snd it)
 		) in
 		let e1 = type_expr ctx e1 in
@@ -1992,7 +1979,7 @@ and type_call ctx e el t p =
 		else
 		let params = (match el with [] -> [] | _ -> ["customParams",(EArrayDecl el , p)]) in
 		let infos = mk_infos ctx p params in
-		type_expr ctx (ECall ((EField ((EType ((EConst (Ident "haxe"),p),"Log"),p),"trace"),p),[e;EUntyped infos,p]),p)
+		type_expr ctx (ECall ((EField ((EField ((EConst (Ident "haxe"),p),"Log"),p),"trace"),p),[e;EUntyped infos,p]),p)
 	| (EConst (Ident "callback"),p) , e :: params ->
 		type_callback ctx e params p
 	| (EConst (Ident "type"),_) , [e] ->
@@ -2024,7 +2011,7 @@ and type_call ctx e el t p =
 		mk (TCall (mk (TConst TSuper) t sp,el)) ctx.t.tvoid p
 	| _ ->
 		(match e with
-		| EField ((EConst (Ident "super"),_),_) , _ | EType ((EConst (Ident "super"),_),_) , _ -> ctx.in_super_call <- true
+		| EField ((EConst (Ident "super"),_),_) , _ -> ctx.in_super_call <- true
 		| _ -> ());
 		let rec loop acc el =
 			match acc with
@@ -2807,8 +2794,8 @@ let call_init_macro ctx e =
 	| ECall (e,args) ->
 		let rec loop e =
 			match fst e with
-			| EField (e,f) | EType (e,f) -> f :: loop e
-			| EConst (Ident i | Type i) -> [i]
+			| EField (e,f) -> f :: loop e
+			| EConst (Ident i) -> [i]
 			| _ -> error "Invalid macro call" p
 		in
 		let path, meth = (match loop e with