Explorar o código

avoid Not_found when checking display-mode

Simon Krajewski %!s(int64=12) %!d(string=hai) anos
pai
achega
628d455092
Modificáronse 3 ficheiros con 9 adicións e 5 borrados
  1. 4 0
      common.ml
  2. 1 1
      main.ml
  3. 4 4
      typer.ml

+ 4 - 0
common.ml

@@ -515,6 +515,10 @@ let raw_defined_value ctx k =
 let defined_value ctx v =
 	raw_defined_value ctx (fst (Define.infos v))
 
+let defined_value_safe ctx v =
+	try defined_value ctx v
+	with Not_found -> ""
+
 let raw_define ctx v =
 	let k,v = try ExtString.String.split v "=" with _ -> v,"1" in
 	ctx.defines <- PMap.add k v ctx.defines;

+ 1 - 1
main.ml

@@ -1109,7 +1109,7 @@ try
 		com.main <- main;
 		com.types <- types;
 		com.modules <- modules;
-		if Common.defined_value com Define.DisplayMode = "usage" then
+		if Common.defined_value_safe com Define.DisplayMode = "usage" then
 			Codegen.detect_usage com;
 		let filters = [
 			Codegen.handle_abstract_casts tctx;

+ 4 - 4
typer.ml

@@ -2485,7 +2485,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			error "Cast type must be a class or an enum" p
 		) in
 		mk (TCast (type_expr ctx e Value,Some texpr)) t p
-	| EDisplay (e,iscall) when Common.defined_value ctx.com Define.DisplayMode = "usage" ->
+	| EDisplay (e,iscall) when Common.defined_value_safe ctx.com Define.DisplayMode = "usage" ->
 		let e = try type_expr ctx e Value with Error (Unknown_ident n,_) -> raise (Parser.TypePath ([n],None)) in
 		(match e.eexpr with
 		| TField(_,fa) -> (match extract_field fa with
@@ -2501,7 +2501,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		let e = (try type_expr ctx e Value with Error (Unknown_ident n,_) -> raise (Parser.TypePath ([n],None))) in
 		let e = match e.eexpr with
 			| TField (e,fa) ->
-				let mode = Common.defined_value ctx.com Define.DisplayMode in
+				let mode = Common.defined_value_safe ctx.com Define.DisplayMode in
 				if field_name fa = "bind" then (match follow e.etype with
 					| TFun(args,ret) -> {e with etype = opt_args args ret}
 					| _ -> e)
@@ -2513,13 +2513,13 @@ and type_expr ctx (e,p) (with_type:with_type) =
 					| _ -> e)
 				else
 					e
-			| TTypeExpr mt when Common.defined_value ctx.com Define.DisplayMode = "position" ->
+			| TTypeExpr mt when Common.defined_value_safe ctx.com Define.DisplayMode = "position" ->
 				raise (DisplayPosition [match mt with
 					| TClassDecl c -> c.cl_pos
 					| TEnumDecl en -> en.e_pos
 					| TTypeDecl t -> t.t_pos
 					| TAbstractDecl a -> a.a_pos])
-			| TTypeExpr mt when Common.defined_value ctx.com Define.DisplayMode = "metadata" ->
+			| TTypeExpr mt when Common.defined_value_safe ctx.com Define.DisplayMode = "metadata" ->
 				raise (DisplayMetadata (match mt with
 					| TClassDecl c -> c.cl_meta
 					| TEnumDecl en -> en.e_meta