fill.fs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. open System
  2. open System.Xml
  3. open System.Xml.XPath
  4. open System.IO
  5. open System.Xml.Linq
  6. open System.Text
  7. open System.Globalization
  8. let load path =
  9. let f = File.OpenText path
  10. let doc = XDocument.Load f
  11. f.Close()
  12. doc
  13. let save path (doc:XDocument) =
  14. let settings = XmlWriterSettings ()
  15. settings.Indent <- true
  16. settings.Encoding <- new UTF8Encoding (false)
  17. settings.OmitXmlDeclaration <- true
  18. settings.NewLineChars <- Environment.NewLine
  19. let output = File.CreateText (path)
  20. let writer = XmlWriter.Create (output, settings)
  21. doc.Save (writer)
  22. writer.Close ()
  23. output.WriteLine ()
  24. output.Close ();
  25. let select (node:XNode) path = node.XPathSelectElement path
  26. let setval (node:XNode) path value = (select node path).Value <- value
  27. let xname s = XName.Get(s)
  28. let processType (doc:XDocument) =
  29. let typeName =
  30. let tnode = doc.XPathSelectElement ("Type")
  31. let attr = tnode.Attribute (xname "Name")
  32. attr.Value
  33. let fillBaseType =
  34. match doc.XPathSelectElement "Type/Members/Member[@MemberName='BaseType']/Docs" with
  35. | null -> ()
  36. | mdoc ->
  37. setval mdoc "summary" "Urho's type system base type."
  38. setval mdoc "value" "StringHash representing the base type for this Urho type."
  39. setval mdoc "remarks" "This returns the Urho type system base type and is surfaced for low-level Urho code."
  40. let fillType =
  41. match doc.XPathSelectElement "Type/Members/Member[@MemberName='Type']/Docs" with
  42. | null -> ()
  43. | mdoc ->
  44. setval mdoc "summary" "Urho's type system type."
  45. try
  46. setval mdoc "value" "StringHash representing the type for this C# type."
  47. with
  48. | ex -> ()
  49. setval mdoc "remarks" "This returns the Urho's type and is surfaced for low-level Urho code."
  50. let fillTypeName =
  51. match doc.XPathSelectElement "Type/Members/Member[@MemberName='TypeName']/Docs" with
  52. | null -> ()
  53. | mdoc ->
  54. setval mdoc "summary" "Urho's low-level type name."
  55. setval mdoc "value" "Stringified low-level type name."
  56. setval mdoc "remarks" ""
  57. let fillTypeNameStatic =
  58. match doc.XPathSelectElement "Type/Members/Member[@MemberName='TypeNameStatic']/Docs" with
  59. | null -> ()
  60. | mdoc ->
  61. setval mdoc "summary" "Urho's low-level type name, accessible as a static method."
  62. setval mdoc "value" "Stringified low-level type name."
  63. setval mdoc "remarks" ""
  64. let fillTypeCtor =
  65. for x in doc.XPathSelectElements "Type/Members/Member[@MemberName='.ctor']" do
  66. match x with
  67. | null -> ()
  68. | mem ->
  69. match mem.XPathSelectElement "Parameters/Parameter[@Name='handle']" with
  70. | null -> ()
  71. | hmember ->
  72. let mdoc = mem.XPathSelectElement "Docs"
  73. setval mdoc "param[@name='handle']" "Pointer to the raw unmanaged Urho object."
  74. setval mdoc "summary" <| (sprintf "Constructs a new instance of %s, given a raw pointer to an unmanaged object" typeName)
  75. let remarks = select mdoc "remarks"
  76. remarks.RemoveAll ()
  77. XElement.Parse ("<para>This creates a new managed wrapper for the type using the raw pointer to an unmanaged object.</para>") |> remarks.Add
  78. XElement.Parse ("<para>Objects that are created in this fashion get registered with the UrhoSharp runtime.</para>") |> remarks.Add
  79. XElement.Parse ("<para>This is intended to be used by the UrhoSharp runtime, and is not intended to be used by users.</para>") |> remarks.Add
  80. let fillTypeEmpty =
  81. for x in doc.XPathSelectElements "Type/Members/Member[@MemberName='.ctor']" do
  82. match x with
  83. | null -> ()
  84. | mem ->
  85. match mem.XPathSelectElement "Parameters/Parameter[@Name='emptyFlag']" with
  86. | null -> ()
  87. | hmember ->
  88. let mdoc = mem.XPathSelectElement "Docs"
  89. setval mdoc "param[@name='emptyFlag']" "Pass UrhoObjectFlag.Empty."
  90. setval mdoc "summary" "Empty constructor, chain to this constructor when you provide your own constructor that sets the handle field."
  91. let remarks = select mdoc "remarks"
  92. remarks.RemoveAll ()
  93. XElement.Parse ("<para>This constructor should be invoked by your code if you provide your own constructor that sets the handle field.</para>") |> remarks.Add
  94. XElement.Parse ("<para>This essentially circumvents the default path that creates a new object and sets the handle and does not call RegisterObject on the target, you must do this on your own constructor.</para>") |> remarks.Add
  95. XElement.Parse ("<para>You would typically chain to this constructor from your own, and then set the handle to the unmanaged object from your code, and then register your object.</para>") |> remarks.Add
  96. let fillTypeContext =
  97. for x in doc.XPathSelectElements "Type/Members/Member[@MemberName='.ctor']" do
  98. match x with
  99. | null -> ()
  100. | mem ->
  101. match mem.XPathSelectElement "Parameters/Parameter[@Name='context']" with
  102. | null -> ()
  103. | hmember ->
  104. if mem.XPathSelectElements "Parameters" |> Seq.length = 1 then
  105. let mdoc = mem.XPathSelectElement "Docs"
  106. setval mdoc "param[@name='context']" "The context that this object will be attached to."
  107. setval mdoc "summary" <| (sprintf "Creates an instance of %s that is attached to an execution context." typeName)
  108. let remarks = select mdoc "remarks"
  109. remarks.RemoveAll ()
  110. sprintf "<para>This creates an instance of %s attached to the specified execution context.</para>" typeName |> XElement.Parse |> remarks.Add
  111. ()
  112. fillBaseType
  113. fillType
  114. fillTypeName
  115. fillTypeNameStatic
  116. fillTypeCtor
  117. doc
  118. let processPath path =
  119. let xml path = load path
  120. match load path with
  121. | null ->
  122. printfn "Problem loading %A" path
  123. ()
  124. | doc -> processType doc |> save path
  125. for xmlDoc in Directory.GetFiles ("Urho", "*xml") do
  126. processPath xmlDoc