Skip to content
770 changes: 418 additions & 352 deletions src/absil/il.fs

Large diffs are not rendered by default.

450 changes: 241 additions & 209 deletions src/absil/il.fsi

Large diffs are not rendered by default.

72 changes: 34 additions & 38 deletions src/absil/ilmorph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ let cattrs_typ2typ ilg f (cs: ILAttributes) =
mkILCustomAttrs (List.map (cattr_typ2typ ilg f) cs.AsList)

let fdef_typ2typ ilg ftype (fd: ILFieldDef) =
{fd with Type=ftype fd.Type;
CustomAttrs=cattrs_typ2typ ilg ftype fd.CustomAttrs}
fd.With(fieldType=ftype fd.FieldType,
customAttrs=cattrs_typ2typ ilg ftype fd.CustomAttrs)

let local_typ2typ f (l: ILLocal) = {l with Type = f l.Type}
let varargs_typ2typ f (varargs: ILVarArgs) = Option.map (List.map f) varargs
Expand Down Expand Up @@ -225,16 +225,15 @@ let morphILMethodBody (filmbody) (x: ILLazyMethodBody) =

let ospec_typ2typ f (OverridesSpec(mref,ty)) = OverridesSpec(mref_typ2typ f mref, f ty)

let mdef_typ2typ_ilmbody2ilmbody ilg fs md =
let mdef_typ2typ_ilmbody2ilmbody ilg fs (md: ILMethodDef) =
let (ftype,filmbody) = fs
let ftype' = ftype (Some md)
let body' = morphILMethodBody (filmbody (Some md)) md.mdBody
{md with
GenericParams=gparams_typ2typ ftype' md.GenericParams;
mdBody= body';
Parameters = List.map (param_typ2typ ilg ftype') md.Parameters;
Return = return_typ2typ ilg ftype' md.Return;
CustomAttrs=cattrs_typ2typ ilg ftype' md.CustomAttrs }
let body' = morphILMethodBody (filmbody (Some md)) md.Body
md.With(genericParams=gparams_typ2typ ftype' md.GenericParams,
body= body',
parameters = List.map (param_typ2typ ilg ftype') md.Parameters,
ret = return_typ2typ ilg ftype' md.Return,
customAttrs=cattrs_typ2typ ilg ftype' md.CustomAttrs)

let fdefs_typ2typ ilg f x = fdefs_fdef2fdef (fdef_typ2typ ilg f) x

Expand All @@ -244,44 +243,41 @@ let mimpl_typ2typ f e =
{ Overrides = ospec_typ2typ f e.Overrides;
OverrideBy = mspec_typ2typ (f,(fun _ -> f)) e.OverrideBy; }

let edef_typ2typ ilg f e =
{ e with
Type = Option.map f e.Type;
AddMethod = mref_typ2typ f e.AddMethod;
RemoveMethod = mref_typ2typ f e.RemoveMethod;
FireMethod = Option.map (mref_typ2typ f) e.FireMethod;
OtherMethods = List.map (mref_typ2typ f) e.OtherMethods;
CustomAttrs = cattrs_typ2typ ilg f e.CustomAttrs }

let pdef_typ2typ ilg f p =
{ p with
SetMethod = Option.map (mref_typ2typ f) p.SetMethod;
GetMethod = Option.map (mref_typ2typ f) p.GetMethod;
Type = f p.Type;
Args = List.map f p.Args;
CustomAttrs = cattrs_typ2typ ilg f p.CustomAttrs }
let edef_typ2typ ilg f (e: ILEventDef) =
e.With(eventType = Option.map f e.EventType,
addMethod = mref_typ2typ f e.AddMethod,
removeMethod = mref_typ2typ f e.RemoveMethod,
fireMethod = Option.map (mref_typ2typ f) e.FireMethod,
otherMethods = List.map (mref_typ2typ f) e.OtherMethods,
customAttrs = cattrs_typ2typ ilg f e.CustomAttrs)

let pdef_typ2typ ilg f (p: ILPropertyDef) =
p.With(setMethod = Option.map (mref_typ2typ f) p.SetMethod,
getMethod = Option.map (mref_typ2typ f) p.GetMethod,
propertyType = f p.PropertyType,
args = List.map f p.Args,
customAttrs = cattrs_typ2typ ilg f p.CustomAttrs)

let pdefs_typ2typ ilg f (pdefs: ILPropertyDefs) = mkILProperties (List.map (pdef_typ2typ ilg f) pdefs.AsList)
let edefs_typ2typ ilg f (edefs: ILEventDefs) = mkILEvents (List.map (edef_typ2typ ilg f) edefs.AsList)

let mimpls_typ2typ f (mimpls : ILMethodImplDefs) = mkILMethodImpls (List.map (mimpl_typ2typ f) mimpls.AsList)

let rec tdef_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg enc fs td =
let rec tdef_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg enc fs (td: ILTypeDef) =
let (ftype,fmdefs) = fs
let ftype' = ftype (Some (enc,td)) None
let mdefs' = fmdefs (enc,td) td.Methods
let fdefs' = fdefs_typ2typ ilg ftype' td.Fields
{td with Implements= List.map ftype' td.Implements;
GenericParams= gparams_typ2typ ftype' td.GenericParams;
Extends = Option.map ftype' td.Extends;
Methods=mdefs';
NestedTypes=tdefs_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg (enc@[td]) fs td.NestedTypes;
Fields=fdefs';
MethodImpls = mimpls_typ2typ ftype' td.MethodImpls;
Events = edefs_typ2typ ilg ftype' td.Events;
Properties = pdefs_typ2typ ilg ftype' td.Properties;
CustomAttrs = cattrs_typ2typ ilg ftype' td.CustomAttrs;
}
td.With(implements= List.map ftype' td.Implements,
genericParams= gparams_typ2typ ftype' td.GenericParams,
extends = Option.map ftype' td.Extends,
methods=mdefs',
nestedTypes=tdefs_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg (enc@[td]) fs td.NestedTypes,
fields=fdefs',
methodImpls = mimpls_typ2typ ftype' td.MethodImpls,
events = edefs_typ2typ ilg ftype' td.Events,
properties = pdefs_typ2typ ilg ftype' td.Properties,
customAttrs = cattrs_typ2typ ilg ftype' td.CustomAttrs)

and tdefs_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg enc fs tdefs =
morphILTypeDefs (tdef_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg enc fs) tdefs
Expand Down
70 changes: 35 additions & 35 deletions src/absil/ilprint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@ and goutput_permission _env os p =


match p with
| PermissionSet (sa,b) ->
| ILSecurityDecl (sa,b) ->
output_string os " .permissionset "
output_security_action os sa
output_string os " = ("
output_bytes os b
output_string os ")"

and goutput_security_decls env os (ps: ILPermissions) = output_seq " " (goutput_permission env) os ps.AsList
and goutput_security_decls env os (ps: ILSecurityDecls) = output_seq " " (goutput_permission env) os ps.AsList

and goutput_gparam env os (gf: ILGenericParameterDef) =
output_string os (tyvar_generator gf.Name);
Expand Down Expand Up @@ -469,30 +469,30 @@ let output_custom_attr_data os data =
output_string os " = "; output_parens output_bytes os data

let goutput_custom_attr env os attr =
output_string os " .custom ";
goutput_mspec env os attr.Method;
output_string os " .custom "
goutput_mspec env os attr.Method
output_custom_attr_data os attr.Data

let goutput_custom_attrs env os (attrs : ILAttributes) =
List.iter (fun attr -> goutput_custom_attr env os attr; output_string os "\n" ) attrs.AsList

let goutput_fdef _tref env os fd =
output_string os " .field ";
let goutput_fdef _tref env os (fd: ILFieldDef) =
output_string os " .field "
match fd.Offset with Some i -> output_string os "["; output_i32 os i; output_string os "] " | None -> ()
match fd.Marshal with Some _i -> output_string os "// marshal attribute not printed\n"; | None -> ()
output_member_access os fd.Access;
output_string os " ";
if fd.IsStatic then output_string os " static ";
if fd.IsLiteral then output_string os " literal ";
if fd.IsSpecialName then output_string os " specialname rtspecialname ";
if fd.IsInitOnly then output_string os " initonly ";
if fd.NotSerialized then output_string os " notserialized ";
goutput_typ env os fd.Type;
output_string os " ";
output_id os fd.Name;
output_option output_at os fd.Data;
output_option output_field_init os fd.LiteralValue;
output_string os "\n";
output_member_access os fd.Access
output_string os " "
if fd.IsStatic then output_string os " static "
if fd.IsLiteral then output_string os " literal "
if fd.IsSpecialName then output_string os " specialname rtspecialname "
if fd.IsInitOnly then output_string os " initonly "
if fd.NotSerialized then output_string os " notserialized "
goutput_typ env os fd.FieldType
output_string os " "
output_id os fd.Name
output_option output_at os fd.Data
output_option output_field_init os fd.LiteralValue
output_string os "\n"
goutput_custom_attrs env os fd.CustomAttrs


Expand Down Expand Up @@ -768,7 +768,7 @@ let goutput_ilmbody env os (il: ILMethodBody) =
output_string os ")\n"


let goutput_mbody is_entrypoint env os md =
let goutput_mbody is_entrypoint env os (md: ILMethodDef) =
if md.ImplAttributes &&& MethodImplAttributes.Native <> enum 0 then output_string os "native "
elif md.ImplAttributes &&& MethodImplAttributes.IL <> enum 0 then output_string os "cil "
else output_string os "runtime "
Expand All @@ -779,7 +779,7 @@ let goutput_mbody is_entrypoint env os md =
output_string os " \n{ \n" ;
goutput_security_decls env os md.SecurityDecls;
goutput_custom_attrs env os md.CustomAttrs;
match md.mdBody.Contents with
match md.Body.Contents with
| MethodBody.IL il -> goutput_ilmbody env os il
| _ -> ()
if is_entrypoint then output_string os " .entrypoint";
Expand All @@ -799,7 +799,7 @@ let goutput_mdef env os (md:ILMethodDef) =
elif md.IsConstructor then "rtspecialname"
elif md.IsStatic then
"static "^
(match md.mdBody.Contents with
(match md.Body.Contents with
MethodBody.PInvoke (attr) ->
"pinvokeimpl(\""^ attr.Where.Name^"\" as \""^ attr.Name ^"\""^
(match attr.CallingConv with
Expand Down Expand Up @@ -852,7 +852,7 @@ let goutput_mdef env os (md:ILMethodDef) =
(goutput_mbody is_entrypoint menv) os md;
output_string os "\n"

let goutput_pdef env os pd =
let goutput_pdef env os (pd: ILPropertyDef) =
output_string os "property\n\tgetter: ";
(match pd.GetMethod with None -> () | Some mref -> goutput_mref env os mref);
output_string os "\n\tsetter: ";
Expand Down Expand Up @@ -891,7 +891,7 @@ let goutput_mdefs env os (mdefs: ILMethodDefs) =
let goutput_pdefs env os (pdefs: ILPropertyDefs) =
List.iter (fun f -> (goutput_pdef env) os f; output_string os "\n" ) pdefs.AsList

let rec goutput_tdef (enc) env contents os cd =
let rec goutput_tdef enc env contents os (cd: ILTypeDef) =
let env = ppenv_enter_tdef cd.GenericParams env
let layout_attr,pp_layout_decls = splitTypeLayout cd.Layout
if isTypeNameForGlobalFunctions cd.Name then
Expand Down Expand Up @@ -939,26 +939,26 @@ and output_init_semantics os f =
and goutput_lambdas env os lambdas =
match lambdas with
| Lambdas_forall (gf,l) ->
output_angled (goutput_gparam env) os gf;
output_string os " ";
output_angled (goutput_gparam env) os gf
output_string os " "
(goutput_lambdas env) os l
| Lambdas_lambda (ps,l) ->
output_parens (goutput_param env) os ps;
output_string os " ";
output_string os " "
(goutput_lambdas env) os l
| Lambdas_return typ -> output_string os "--> "; (goutput_typ env) os typ

and goutput_tdefs contents (enc) env os (td: ILTypeDefs) =
and goutput_tdefs contents enc env os (td: ILTypeDefs) =
List.iter (goutput_tdef enc env contents os) td.AsList

let output_ver os (a,b,c,d) =
output_string os " .ver ";
output_u16 os a;
output_string os " : ";
output_u16 os b;
output_string os " : ";
output_u16 os c;
output_string os " : ";
output_string os " .ver "
output_u16 os a
output_string os " : "
output_u16 os b
output_string os " : "
output_u16 os c
output_string os " : "
output_u16 os d

let output_locale os s = output_string os " .Locale "; output_qstring os s
Expand Down
Loading