160 case polymorphism_of_type_enc type_enc of |
160 case polymorphism_of_type_enc type_enc of |
161 Raw_Polymorphic _ => true |
161 Raw_Polymorphic _ => true |
162 | Type_Class_Polymorphic => true |
162 | Type_Class_Polymorphic => true |
163 | _ => false |
163 | _ => false |
164 |
164 |
|
165 fun is_type_enc_mangling type_enc = |
|
166 polymorphism_of_type_enc type_enc = Mangled_Monomorphic |
|
167 |
165 fun level_of_type_enc (Native (_, _, level)) = level |
168 fun level_of_type_enc (Native (_, _, level)) = level |
166 | level_of_type_enc (Guards (_, level)) = level |
169 | level_of_type_enc (Guards (_, level)) = level |
167 | level_of_type_enc (Tags (_, level)) = level |
170 | level_of_type_enc (Tags (_, level)) = level |
168 |
171 |
169 fun is_type_level_uniform (Nonmono_Types (_, Non_Uniform)) = false |
172 fun is_type_level_uniform (Nonmono_Types (_, Non_Uniform)) = false |
832 else x :: filter_out (type_generalization thy T o get_T) xs |
835 else x :: filter_out (type_generalization thy T o get_T) xs |
833 end |
836 end |
834 |
837 |
835 (* The Booleans indicate whether all type arguments should be kept. *) |
838 (* The Booleans indicate whether all type arguments should be kept. *) |
836 datatype type_arg_policy = |
839 datatype type_arg_policy = |
837 Mangled_Type_Args | (* ### TODO: get rid of this *) |
|
838 All_Type_Args | |
840 All_Type_Args | |
839 Noninfer_Type_Args | |
841 Noninfer_Type_Args | |
840 Constr_Infer_Type_Args | |
842 Constr_Infer_Type_Args | |
841 No_Type_Args |
843 No_Type_Args |
842 |
844 |
843 fun type_arg_policy constrs type_enc s = |
845 fun type_arg_policy constrs type_enc s = |
844 let val poly = polymorphism_of_type_enc type_enc in |
846 let val poly = polymorphism_of_type_enc type_enc in |
845 if s = type_tag_name then |
847 if s = type_tag_name then (* ### FIXME: why not "type_guard_name" as well? *) |
846 if poly = Mangled_Monomorphic then Mangled_Type_Args else All_Type_Args |
848 All_Type_Args |
847 else case type_enc of |
849 else case type_enc of |
848 Native (_, Raw_Polymorphic _, _) => All_Type_Args |
850 Native (_, Raw_Polymorphic _, _) => All_Type_Args |
849 | Native (_, Type_Class_Polymorphic, _) => All_Type_Args |
851 | Native (_, Type_Class_Polymorphic, _) => All_Type_Args |
850 | _ => |
852 | _ => |
851 let val level = level_of_type_enc type_enc in |
853 let val level = level_of_type_enc type_enc in |
852 if level = No_Types orelse s = @{const_name HOL.eq} orelse |
854 if level = No_Types orelse s = @{const_name HOL.eq} orelse |
853 (case level of Const_Types _ => s = app_op_name | _ => false) then |
855 (case level of Const_Types _ => s = app_op_name | _ => false) then |
854 No_Type_Args |
856 No_Type_Args |
855 else if poly = Mangled_Monomorphic then |
857 else if poly = Mangled_Monomorphic then |
856 Mangled_Type_Args |
858 All_Type_Args |
857 else if level = All_Types then |
859 else if level = All_Types then |
858 case type_enc of |
860 case type_enc of |
859 Guards _ => Noninfer_Type_Args |
861 Guards _ => Noninfer_Type_Args |
860 | Tags _ => No_Type_Args |
862 | Tags _ => No_Type_Args |
861 else if level = Undercover_Types then |
863 else if level = Undercover_Types then |
1121 |
1123 |
1122 fun mangle_type_args_in_const type_enc (name as (s, _)) T_args = |
1124 fun mangle_type_args_in_const type_enc (name as (s, _)) T_args = |
1123 case unprefix_and_unascii const_prefix s of |
1125 case unprefix_and_unascii const_prefix s of |
1124 NONE => (name, T_args) |
1126 NONE => (name, T_args) |
1125 | SOME s'' => |
1127 | SOME s'' => |
1126 case type_arg_policy [] type_enc (invert_const s'') of |
1128 if is_type_enc_mangling type_enc then |
1127 Mangled_Type_Args => (mangled_const_name type_enc T_args name, []) |
1129 (mangled_const_name type_enc T_args name, []) |
1128 | _ => (name, T_args) |
1130 else |
|
1131 (name, T_args) |
1129 fun mangle_type_args_in_iterm type_enc = |
1132 fun mangle_type_args_in_iterm type_enc = |
1130 if polymorphism_of_type_enc type_enc = Mangled_Monomorphic then |
1133 if is_type_enc_mangling type_enc then |
1131 let |
1134 let |
1132 fun mangle (IApp (tm1, tm2)) = IApp (mangle tm1, mangle tm2) |
1135 fun mangle (IApp (tm1, tm2)) = IApp (mangle tm1, mangle tm2) |
1133 | mangle (tm as IConst (_, _, [])) = tm |
1136 | mangle (tm as IConst (_, _, [])) = tm |
1134 | mangle (IConst (name, T, T_args)) = |
1137 | mangle (IConst (name, T, T_args)) = |
1135 mangle_type_args_in_const type_enc name T_args |
1138 mangle_type_args_in_const type_enc name T_args |
1169 if level_of_type_enc type_enc = No_Types orelse s = tptp_choice then [] |
1172 if level_of_type_enc type_enc = No_Types orelse s = tptp_choice then [] |
1170 else T_args |
1173 else T_args |
1171 | SOME s'' => |
1174 | SOME s'' => |
1172 let val s'' = invert_const s'' in |
1175 let val s'' = invert_const s'' in |
1173 case type_arg_policy constrs type_enc s'' of |
1176 case type_arg_policy constrs type_enc s'' of |
1174 Mangled_Type_Args => raise Fail "unexpected (un)mangled symbol" |
1177 All_Type_Args => T_args |
1175 | All_Type_Args => T_args |
|
1176 | Noninfer_Type_Args => |
1178 | Noninfer_Type_Args => |
1177 filter_type_args (not o fst) thy s'' (chop_fun ary) T_args |
1179 filter_type_args (not o fst) thy s'' (chop_fun ary) T_args |
1178 | Constr_Infer_Type_Args => |
1180 | Constr_Infer_Type_Args => |
1179 filter_type_args fst thy s'' strip_type T_args |
1181 filter_type_args fst thy s'' strip_type T_args |
1180 | No_Type_Args => [] |
1182 | No_Type_Args => [] |
2258 fun add_undefined_const T = |
2260 fun add_undefined_const T = |
2259 let |
2261 let |
2260 (* FIXME: make sure type arguments are filtered / clean up code *) |
2262 (* FIXME: make sure type arguments are filtered / clean up code *) |
2261 val (s, s') = |
2263 val (s, s') = |
2262 `(make_fixed_const NONE) @{const_name undefined} |
2264 `(make_fixed_const NONE) @{const_name undefined} |
2263 |> (case type_arg_policy [] type_enc @{const_name undefined} of |
2265 |> (is_type_enc_mangling type_enc ? mangled_const_name type_enc [T]) |
2264 Mangled_Type_Args => mangled_const_name type_enc [T] |
|
2265 | _ => I) |
|
2266 in |
2266 in |
2267 Symtab.map_default (s, []) |
2267 Symtab.map_default (s, []) |
2268 (insert_type thy #3 (s', [T], T, false, 0, false)) |
2268 (insert_type thy #3 (s', [T], T, false, 0, false)) |
2269 end |
2269 end |
2270 fun add_TYPE_const () = |
2270 fun add_TYPE_const () = |