From 6fbae81e70100e02f9c06a63812609f78b9bf47d Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Sun, 28 Sep 2014 23:12:59 +0200 Subject: [PATCH 1/2] Support for C# methods and constructors (at least with patched FSharp.Compiler.Service commit, c5dfd4dd488f6dcd1024b0ed2b564ce9d2d414fa). --- src/FSharp.MetadataFormat/Main.fs | 45 +++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/FSharp.MetadataFormat/Main.fs b/src/FSharp.MetadataFormat/Main.fs index 0434e3bab..88be2f7bd 100644 --- a/src/FSharp.MetadataFormat/Main.fs +++ b/src/FSharp.MetadataFormat/Main.fs @@ -559,12 +559,49 @@ module Reader = | n , _ -> n let getMemberXmlDocsSigPrefix (memb:FSharpMemberFunctionOrValue) = - if memb.IsProperty then "P" else "M" + if memb.IsEvent then "E" + elif memb.IsProperty then "P" + else "M" let getXmlDocSigForMember (memb:FSharpMemberFunctionOrValue) = + let memberName = + let name = memb.CompiledName.Replace(".ctor", "#ctor") + let typeGenericParameters = + memb.EnclosingEntity.GenericParameters |> Seq.mapi (fun num par -> par.Name, sprintf "`%d" num) + let methodGenericParameters = + memb.GenericParameters |> Seq.mapi (fun num par -> par.Name, sprintf "``%d" num) + let typeArgsMap = + Seq.append methodGenericParameters typeGenericParameters + |> Seq.groupBy fst + |> Seq.map (fun (name, grp) -> grp |> Seq.head) + |> dict + let typeargs = + if memb.GenericParameters.Count > 0 + then sprintf "``%d" memb.GenericParameters.Count + else "" + + let paramList = + if memb.CurriedParameterGroups.Count > 0 && memb.CurriedParameterGroups.[0].Count > 0 + then + let head = memb.CurriedParameterGroups.[0] + let paramTypeList = + head + |> Seq.map (fun param -> + if param.Type.IsGenericParameter then + typeArgsMap.[param.Type.GenericParameter.Name] + else + let rec reduceAbb (t:FSharpType) = + if t.IsAbbreviation + then reduceAbb t.AbbreviatedType + else t + let paramType = reduceAbb param.Type + paramType.TypeDefinition.FullName) + "(" + System.String.Join(",", paramTypeList) + ")" + else "" + sprintf "%s%s%s" name typeargs paramList match (memb.XmlDocSig, memb.EnclosingEntity.TryFullName) with | "", None -> "" - | "", Some(n) -> sprintf "%s:%s.%s" (getMemberXmlDocsSigPrefix memb) n memb.CompiledName + | "", Some(n) -> sprintf "%s:%s.%s" (getMemberXmlDocsSigPrefix memb) n memberName | n, _ -> n // @@ -692,6 +729,10 @@ module Reader = |> List.ofSeq |> List.filter (fun v -> checkAccess ctx v.Accessibility) |> List.filter (fun v -> not v.IsCompilerGenerated) + |> List.filter (fun v -> + if v.EnclosingEntity.IsFSharp then true else + not v.IsEventAddMethod && not v.IsEventRemoveMethod && + not v.IsPropertyGetterMethod && not v.IsPropertySetterMethod) |> List.partition (fun v -> v.IsInstanceMember) let cvals, svals = svals |> List.partition (fun v -> v.CompiledName = ".ctor") From 3b113f74eab4b947873570feb5dc99b62b2f5e1d Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Thu, 2 Oct 2014 03:32:25 +0200 Subject: [PATCH 2/2] handle possible exceptions while processing members. --- src/FSharp.MetadataFormat/Main.fs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/FSharp.MetadataFormat/Main.fs b/src/FSharp.MetadataFormat/Main.fs index 88be2f7bd..a84c7b924 100644 --- a/src/FSharp.MetadataFormat/Main.fs +++ b/src/FSharp.MetadataFormat/Main.fs @@ -565,6 +565,7 @@ module Reader = let getXmlDocSigForMember (memb:FSharpMemberFunctionOrValue) = let memberName = + try let name = memb.CompiledName.Replace(".ctor", "#ctor") let typeGenericParameters = memb.EnclosingEntity.GenericParameters |> Seq.mapi (fun num par -> par.Name, sprintf "`%d" num) @@ -599,6 +600,9 @@ module Reader = "(" + System.String.Join(",", paramTypeList) + ")" else "" sprintf "%s%s%s" name typeargs paramList + with exn -> + Log.logf "Error while building member-name for %s because: %s" memb.FullName exn.Message + memb.CompiledName match (memb.XmlDocSig, memb.EnclosingEntity.TryFullName) with | "", None -> "" | "", Some(n) -> sprintf "%s:%s.%s" (getMemberXmlDocsSigPrefix memb) n memberName