[svn] r7394: nemerle/trunk: lib/nstring.n ncc/hierarchy/XmlDump.n
pbludov
svnadmin at nemerle.org
Wed Feb 7 05:46:34 CET 2007
Log:
xmldoc: Inner generic types, special handling of op_Explicit & op_Impicit.
Author: pbludov
Date: Wed Feb 7 05:46:31 2007
New Revision: 7394
Modified:
nemerle/trunk/lib/nstring.n
nemerle/trunk/ncc/hierarchy/XmlDump.n
Modified: nemerle/trunk/lib/nstring.n
==============================================================================
--- nemerle/trunk/lib/nstring.n (original)
+++ nemerle/trunk/lib/nstring.n Wed Feb 7 05:46:31 2007
@@ -26,7 +26,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-using System.Text;
using Nemerle.Collections;
namespace Nemerle.Utility
@@ -108,7 +107,7 @@
*/
public Concat (sep : string, l : list [string]) : string
{
- def loop (l : list[string], acc : System.Text.StringBuilder)
+ def loop (l : list[string], acc : NStringBuilder)
{
match (l) {
| [x] => acc.Append (x)
@@ -117,7 +116,7 @@
}
}
- loop (l, System.Text.StringBuilder ("")).ToString ()
+ loop (l, NStringBuilder ("")).ToString ()
}
@@ -129,7 +128,7 @@
* so that this function looks more Fold-like.
*/
public SeparatedCalls ['a] (sep : string, l : list ['a], f : 'a -> void,
- acc : System.Text.StringBuilder) : void
+ acc : NStringBuilder) : void
{
def loop (l)
{
@@ -145,7 +144,7 @@
/** Same as [Implode (List.Map (Explode (s), f))] but a lot faster. */
public Map (this s : string, f : char -> char) : string
{
- def res = StringBuilder (s.Length);
+ def res = NStringBuilder (s.Length);
for (mutable i = 0; i < s.Length; ++i)
_ = res.Append (f (s [i]));
res.ToString ()
@@ -155,7 +154,7 @@
/** Same as [Concat ("", List.Map (Explode (s), f))] but a lot faster. */
public MapCS (this s : string, f : char -> string) : string
{
- def res = StringBuilder (s.Length);
+ def res = NStringBuilder (s.Length);
for (mutable i = 0; i < s.Length; ++i)
_ = res.Append (f (s [i]));
res.ToString ()
@@ -249,24 +248,26 @@
the program, because of list's memory overheads. */
public Implode (s : list [char]) : string
{
- def sb = StringBuilder ();
+ def sb = NStringBuilder ();
foreach (ch in s)
_ = sb.Append (ch);
sb.ToString ()
}
}
-}
-namespace Nemerle.Utility.Text
-{
- public module NStringBuilder
- {
- /// <summary>Appends the string representation of a specified list items to the end of a <see href="StringBuilder"/> instance.</summary>
- /// <returns>A reference to the StringBuilder instance after the append operation has completed.</returns>
- /// <param name="sb">A <see href="StringBuilder"/> instance pointer. </param>
+ // Usually, import of namespace System.Text used to get access to the StringBuilder type.
+ // The rest is used rarely. Inventing a public alias for StringBuilder hepls us to avoid such import.
+ //
+ public type NStringBuilder = System.Text.StringBuilder;
+
+ public module NStringBuilderExtensions
+ {
+ /// <summary>Appends the string representation of a specified list items to the end of a <see cref="NStringBuilder"/> instance.</summary>
+ /// <returns>A reference to the NStringBuilder instance after the append operation has completed.</returns>
+ /// <param name="sb">A <see cref="NStringBuilder"/> instance pointer. </param>
/// <param name="l">A list. </param>
/// <param name="sep">The string used as element separator. </param>
- public AppendList['a] (this sb : StringBuilder, l : list ['a], sep : string) : StringBuilder
+ public AppendList['a] (this sb : NStringBuilder, l : list ['a], sep : string) : NStringBuilder
{
match (l) {
| [x] => sb.Append (x)
@@ -275,13 +276,13 @@
}
}
- /// <summary>Appends the string representation of a specified list items to the end of a <see href="StringBuilder"/> instance.</summary>
- /// <returns>A reference to the StringBuilder instance after the append operation has completed.</returns>
- /// <param name="sb">A <see href="StringBuilder"/> instance pointer. </param>
+ /// <summary>Appends the string representation of a specified list items to the end of a <see cref="NStringBuilder"/> instance.</summary>
+ /// <returns>A reference to the NStringBuilder instance after the append operation has completed.</returns>
+ /// <param name="sb">A <see cref="NStringBuilder"/> instance pointer. </param>
/// <param name="l">A list. </param>
/// <param name="append">A function used to append elements. </param>
/// <param name="sep">The string used as element separator. </param>
- public AppendList['a] (this sb : StringBuilder, l : list ['a], append : StringBuilder * 'a -> StringBuilder, sep : string) : StringBuilder
+ public AppendList['a] (this sb : NStringBuilder, l : list ['a], append : NStringBuilder * 'a -> NStringBuilder, sep : string) : NStringBuilder
{
match (l) {
| [x] => append (sb, x)
@@ -290,12 +291,12 @@
}
}
- /// <summary>Appends to the end of a <see href="StringBuilder"/> instance if a condition is true.</summary>
- /// <returns>A reference to the StringBuilder instance after the append operation has completed.</returns>
- /// <param name="sb">A <see href="StringBuilder"/> instance pointer. </param>
+ /// <summary>Appends to the end of a <see cref="NStringBuilder"/> instance if a condition is true.</summary>
+ /// <returns>A reference to the NStringBuilder instance after the append operation has completed.</returns>
+ /// <param name="sb">A <see cref="NStringBuilder"/> instance pointer. </param>
/// <param name="condition">true to cause a message to be written; otherwise, false. </param>
/// <param name="append">A function used to append elements. </param>
- public AppendWhen (this sb : StringBuilder, condition : bool, append : StringBuilder -> StringBuilder) : StringBuilder
+ public AppendWhen (this sb : NStringBuilder, condition : bool, append : NStringBuilder -> NStringBuilder) : NStringBuilder
{
if (condition)
append (sb)
@@ -303,12 +304,12 @@
sb
}
- /// <summary>Appends to the end of a <see href="StringBuilder"/> instance if a condition is false.</summary>
- /// <returns>A reference to the StringBuilder instance after the append operation has completed.</returns>
- /// <param name="sb">A <see href="StringBuilder"/> instance pointer. </param>
+ /// <summary>Appends to the end of a <see cref="NStringBuilder"/> instance if a condition is false.</summary>
+ /// <returns>A reference to the NStringBuilder instance after the append operation has completed.</returns>
+ /// <param name="sb">A <see cref="NStringBuilder"/> instance pointer. </param>
/// <param name="condition">true to cause a message to be written; otherwise, false. </param>
/// <param name="append">A function used to append elements. </param>
- public AppendUnless (this sb : StringBuilder, condition : bool, append : StringBuilder -> StringBuilder) : StringBuilder
+ public AppendUnless (this sb : NStringBuilder, condition : bool, append : NStringBuilder -> NStringBuilder) : NStringBuilder
{
if (condition)
sb
@@ -316,13 +317,13 @@
append (sb)
}
- /// <summary>Appends the string representation of a specified item to the end of a <see href="StringBuilder"/> instance number of times.</summary>
- /// <returns>A reference to the StringBuilder instance after the append operation has completed.</returns>
- /// <param name="sb">A <see href="StringBuilder"/> instance pointer. </param>
+ /// <summary>Appends the string representation of a specified item to the end of a <see cref="NStringBuilder"/> instance number of times.</summary>
+ /// <returns>A reference to the NStringBuilder instance after the append operation has completed.</returns>
+ /// <param name="sb">A <see cref="NStringBuilder"/> instance pointer. </param>
/// <param name="count">The number of times when the item should be written. </param>
/// <param name="a">The item. </param>
/// <param name="sep">The string used as element separator. </param>
- public AppendNTimes['a] (this sb : StringBuilder, count : int, a : 'a, sep : string) : StringBuilder
+ public AppendNTimes['a] (this sb : NStringBuilder, count : int, a : 'a, sep : string) : NStringBuilder
{
def loop (cnt) {
| 1 => sb.Append(a)
@@ -333,13 +334,13 @@
loop (count)
}
- /// <summary>Appends to the end of a <see href="StringBuilder"/> instance number of times.</summary>
- /// <returns>A reference to the StringBuilder instance after the append operation has completed.</returns>
- /// <param name="sb">A <see href="StringBuilder"/> instance pointer. </param>
+ /// <summary>Appends to the end of a <see cref="NStringBuilder"/> instance number of times.</summary>
+ /// <returns>A reference to the NStringBuilder instance after the append operation has completed.</returns>
+ /// <param name="sb">A <see cref="NStringBuilder"/> instance pointer. </param>
/// <param name="count">The number of times when the function should be invoked. </param>
/// <param name="append">A function used to append elements. </param>
/// <param name="sep">The string used as element separator. </param>
- public AppendNTimes (this sb : StringBuilder, count : int, append : StringBuilder -> StringBuilder, sep : string) : StringBuilder
+ public AppendNTimes (this sb : NStringBuilder, count : int, append : NStringBuilder -> NStringBuilder, sep : string) : NStringBuilder
{
def loop (cnt) {
| 1 => append(sb)
Modified: nemerle/trunk/ncc/hierarchy/XmlDump.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/XmlDump.n (original)
+++ nemerle/trunk/ncc/hierarchy/XmlDump.n Wed Feb 7 05:46:31 2007
@@ -32,11 +32,9 @@
using Nemerle.Compiler;
using Nemerle.Compiler.Parsetree;
using Nemerle.Utility;
-using Nemerle.Utility.Text;
using System;
using System.Xml;
-using System.Text;
namespace Nemerle.Compiler
{
@@ -232,7 +230,7 @@
// stack of currently active tags, along with information if
// they were user-supplied
mutable tags = [];
- def sb = StringBuilder ("");
+ def sb = NStringBuilder ("");
def skip_ws () {
match (tokens.Current) {
@@ -387,23 +385,21 @@
// Append a method parameter type name.
//
- static AppendParmTypeName (sb : StringBuilder, p : TyVar, m : IMethod) : StringBuilder
+ static AppendParmTypeName (sb : NStringBuilder, p : TyVar, m : IMethod) : NStringBuilder
{
// Append a generic parameter type name, which is an index actually.
//
def appendStaticTyVarName (sb, tyvar) {
- def indexOf (mutable lst, elem) {
- mutable i = 0;
- while (!lst.IsEmpty && !lst.Head.Equals (elem)) {
- ++i;
- lst = lst.Tail;
+ def indexOf (lst, elem) {
+ def loop(l, a, idx) {
+ match (l) {
+ | h :: t => if (h.Equals (a)) idx else loop (t, a, idx + 1)
+ | [] => -1
+ }
}
- if (lst.IsEmpty)
- -1
- else
- i
+ loop(lst, elem, 0)
}
match (indexOf (m.GetHeader ().typarms, tyvar)) {
@@ -422,7 +418,8 @@
//
def appendTypeNameAndArgs (sb, typeName, args) {
sb.Append (typeName)
- .AppendUnless (args.IsEmpty, sb => sb.Append ("{").AppendList (args, (sb, e) => AppendParmTypeName (sb, e, m), ",").Append ("}"));
+ .AppendUnless (args.IsEmpty,
+ sb => sb.Append ("{").AppendList (args, (sb, e) => AppendParmTypeName (sb, e, m), ",").Append ("}"));
}
// Append function argument types & return type.
@@ -458,13 +455,19 @@
// (prefix, declaring type, dot, name) it is good
// to use a string builder here.
//
- def sb = StringBuilder ();
+ def sb = NStringBuilder ();
def appendTypeName (sb, typeInfo) {
def tyParmsCount = typeInfo.Typarms.Length;
+ if (tyParmsCount == 0)
sb.Append (typeInfo.FullName)
- .AppendUnless (tyParmsCount == 0, sb => sb.Append ("`").Append (tyParmsCount));
+ else if (typeInfo.DeclaringType == null)
+ sb.Append (typeInfo.FullName).Append ("`").Append (tyParmsCount);
+ else
+ appendTypeName (sb, typeInfo.DeclaringType)
+ .Append (".").Append (typeInfo.Name)
+ .Append ("`").Append (tyParmsCount - typeInfo.DeclaringType.Typarms.Length);
}
(match (m.MemberKind) {
@@ -482,8 +485,12 @@
appendTypeName (sb.Append ("M:"), method.DeclaringType)
.Append (".").Append (m.Name.Replace ('.', '#'))
- .AppendUnless (tyParmsCount == 0, sb => sb.Append ("``").Append (tyParmsCount))
- .AppendUnless (parms.IsEmpty, sb => sb.Append ("(").AppendList (parms, (sb, p) => AppendParmTypeName (sb, p.ty, method), ",").Append (")"));
+ .AppendUnless (tyParmsCount == 0,
+ sb => sb.Append ("``").Append (tyParmsCount))
+ .AppendUnless (parms.IsEmpty,
+ sb => sb.Append ("(").AppendList (parms, (sb, p) => AppendParmTypeName (sb, p.ty, method), ",").Append (")"))
+ .AppendWhen (method.Name == "op_Explicit" || method.Name == "op_Implicit",
+ sb => AppendParmTypeName (sb.Append("~"), method.ReturnType, method));
| MemberKinds.TypeInfo
| MemberKinds.NestedType =>
More information about the svn
mailing list