Skip to content

Commit

Permalink
Support for C# methods and constructors (at least with patched FSharp…
Browse files Browse the repository at this point in the history
….Compiler.Service commit, c5dfd4dd488f6dcd1024b0ed2b564ce9d2d414fa).
  • Loading branch information
matthid committed Sep 28, 2014
1 parent 58e94ba commit 1bf4f92
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions src/FSharp.MetadataFormat/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,53 @@ module Reader =

let tryReadMember (ctx:ReadingContext) kind (memb:FSharpMemberFunctionOrValue) =
let xmlSig =
if memb.XmlDocSig = ""
if memb.XmlDocSig = "" &&
not memb.IsEventAddMethod && not memb.IsEventRemoveMethod &&
not memb.IsPropertyGetterMethod && not memb.IsPropertySetterMethod
then // support for C# member
let memberType = if memb.IsProperty then "P" else "M"
sprintf "%s:%s" memberType memb.FullName
let membFullName =
// because of generics (memb.FullName is not a correct xmlsig in this case)...
sprintf "%s.%s" (memb.EnclosingEntity.FullName) memb.CompiledName
let memberType, sigName =
if memb.IsEvent then "E", membFullName
elif memb.IsProperty then "P", membFullName
else
let name = membFullName.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 ""
let fullname = sprintf "%s%s%s" name typeargs paramList
"M", fullname
sprintf "%s:%s" memberType sigName
else
memb.XmlDocSig
readCommentsInto ctx xmlSig (fun cat _ comment ->
Expand Down Expand Up @@ -665,7 +708,7 @@ module Reader =
let xmlDocSig =
if typ.XmlDocSig = "" && typ.XmlDoc.Count > 0 && typ.IsProvided
then registerTypeProviderXmlDocs ctx typ
else if typ.XmlDocSig = ""
else if typ.XmlDocSig = "" && (typ.IsClass || typ.IsInterface)
then // support for C# types
sprintf "T:%s" typ.FullName
else
Expand All @@ -690,6 +733,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")

Expand Down

0 comments on commit 1bf4f92

Please sign in to comment.