Skip to content

Commit

Permalink
Merge pull request #64 from soloman817/master
Browse files Browse the repository at this point in the history
Some features adjustment on MetadataFormat
  • Loading branch information
tpetricek committed Nov 11, 2013
2 parents 91d85e3 + 492ac3b commit dbc9702
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ packages/
TestResults.xml
TestResult.xml
temp/
tests/Benchmarks/testfiles/*/*.html
tests/Benchmarks/testfiles/*/*.html
*.sln.DotSettings.user
67 changes: 60 additions & 7 deletions src/FSharp.MetadataFormat/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type MemberKind =
| InstanceMember = 4
| StaticMember = 5

// In a class, F# special members
| UnionCase = 100
| RecordField = 101

type Member =
{ Name : string
Category : string
Expand All @@ -55,12 +59,16 @@ type Type =
UrlName : string
Comment : Comment

UnionCases : Member list
RecordFields : Member list

AllMembers : Member list
Constructors : Member list
InstanceMembers : Member list
StaticMembers : Member list }
static member Create(name, url, comment, ctors, inst, stat) =
static member Create(name, url, comment, cases, fields, ctors, inst, stat) =
{ Type.Name = name; UrlName = url; Comment = comment;
UnionCases = cases; RecordFields = fields
AllMembers = List.concat [ ctors; inst; stat] ;
Constructors = ctors; InstanceMembers = inst; StaticMembers = stat }

Expand Down Expand Up @@ -243,16 +251,20 @@ module ValueReader =
else sprintf "(%s)" s)
match v.IsMember, v.IsInstanceMember, v.LogicalName, v.DisplayName with
// Constructors and indexers
| _, _, ".ctor", _ -> "new " + tyname
| _, true, _, "Item" -> (uncapitalize tyname) + ".[" + (defaultArg args "...") + "]"
//| _, _, ".ctor", _ -> "new " + tyname
| _, _, ".ctor", _ -> "new" + (defaultArg parArgs "(...)")
//| _, true, _, "Item" -> (uncapitalize tyname) + ".[" + (defaultArg args "...") + "]"
| _, true, _, "Item" -> "[" + (defaultArg args "...") + "]"
// Ordinary instance members
| _, true, _, name -> (uncapitalize tyname) + "." + name + (defaultArg parArgs "(...)")
//| _, true, _, name -> (uncapitalize tyname) + "." + name + (defaultArg parArgs "(...)")
| _, true, _, name -> name + (defaultArg parArgs "(...)")
// Ordinary functions or values
| false, _, _, name when
not (hasAttrib<RequireQualifiedAccessAttribute> v.LogicalEnclosingEntity.Attributes) ->
name + " " + (defaultArg args "(...)")
// Ordinary static members or things (?) that require fully qualified access
| _, _, _, name -> tyname + "." + name + (defaultArg parArgs "(...)")
//| _, _, _, name -> tyname + "." + name + (defaultArg parArgs "(...)")
| _, _, _, name -> name + (defaultArg parArgs "(...)")

let modifiers =
[ // TODO: v.Accessibility does not contain anything
Expand Down Expand Up @@ -328,6 +340,22 @@ module ValueReader =
usageL , docL, noteL
*)

let readUnionCase (case:FSharpUnionCase) =
let usage (maxLength:int) = case.Name
let modifiers = List.empty
let typeparams = List.empty
let signature = case.Fields |> List.ofSeq |> List.map (fun field -> formatType field.Type) |> String.concat " * "
MemberOrValue.Create(usage, modifiers, typeparams, signature)

let readRecordField (field:FSharpRecordField) =
let usage (maxLength:int) = field.Name
let modifiers =
[ if field.IsMutable then yield "mutable"
if field.IsStatic then yield "static" ]
let typeparams = List.empty
let signature = formatType field.Type
MemberOrValue.Create(usage, modifiers, typeparams, signature)

module Reader =
open FSharp.Markdown
open System.IO
Expand Down Expand Up @@ -451,6 +479,28 @@ module Reader =
|> Seq.filter (fun v -> not v.IsCompilerGenerated)
|> Seq.filter cond |> Seq.choose (tryReadMember ctx kind) |> List.ofSeq

let readTypeName (typ:FSharpEntity) =
typ.GenericParameters
|> List.ofSeq
|> List.map (fun p -> sprintf "'%s" p.Name)
|> function
| [] -> typ.DisplayName
| gnames -> sprintf "%s<%s>" typ.DisplayName (String.concat ", " gnames)

let readUnionCases ctx (typ:FSharpEntity) =
typ.UnionCases
|> List.ofSeq
|> List.choose (fun case ->
readCommentsInto ctx case.XmlDocSig (fun cat _ comment ->
Member.Create(case.Name, MemberKind.UnionCase, cat, readUnionCase case, comment)))

let readRecordFields ctx (typ:FSharpEntity) =
typ.RecordFields
|> List.ofSeq
|> List.choose (fun field ->
readCommentsInto ctx field.XmlDocSig (fun cat _ comment ->
Member.Create(field.Name, MemberKind.RecordField, cat, readRecordField field, comment)))

// ----------------------------------------------------------------------------------------------
// Reading modules types (mutually recursive, because of nesting)
// ----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -479,12 +529,15 @@ module Reader =
newEntry1 hFile ("<pre>"+outputL widthVal (layoutType denv i)+"</pre>")))
*)


let name = readTypeName typ
let cases = readUnionCases ctx typ
let fields = readRecordFields ctx typ

let ctors = readAllMembers ctx MemberKind.Constructor cvals
let inst = readAllMembers ctx MemberKind.InstanceMember ivals
let stat = readAllMembers ctx MemberKind.StaticMember svals
Type.Create
( typ.DisplayName, urlName, comment, ctors, inst, stat ))
( name, urlName, comment, cases, fields, ctors, inst, stat ))

and readModule (ctx:ReadingContext) (modul:FSharpEntity) =
readCommentsInto ctx modul.XmlDocSig (fun cat cmd comment ->
Expand Down
21 changes: 21 additions & 0 deletions src/FSharp.MetadataFormat/templates/module.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@
@Model.Module.Comment.FullText
</div>

@if (Model.Module.NestedTypes.Length > 0) {
<h2>Nested types</h2>
<div>
<table class="table table-bordered type-list">
<thread>
<tr><td>Type</td><td>Description</td></tr>
</thread>
<tbody>
@foreach (var it in Model.Module.NestedTypes) {
<tr>
<td class="type-name">
<a href="@(it.UrlName).html">@Html.Encode(it.Name)</a>
</td>
<td class="xmldoc">@it.Comment.Blurb</td>
</tr>
}
</tbody>
</table>
</div>
}

@RenderPart("members", new {
Header = "Functions and values",
TableHeader = "Function or value",
Expand Down
12 changes: 12 additions & 0 deletions src/FSharp.MetadataFormat/templates/type.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
@Model.Type.Comment.FullText
</div>

@RenderPart("members", new {
Header = "Union Cases",
TableHeader = "Union Cases",
Members = Model.Type.UnionCases
})

@RenderPart("members", new {
Header = "Record Fields",
TableHeader = "Record Fields",
Members = Model.Type.RecordFields
})

@RenderPart("members", new {
Header = "Constructors",
TableHeader = "Constructors",
Expand Down

0 comments on commit dbc9702

Please sign in to comment.