From 679afcc27ad3c6bea8126e4373ac8f0f0638d017 Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Fri, 1 Nov 2013 09:17:34 +0100 Subject: [PATCH] Avoid singletons; logic in FuncProcessor This is part of a long-due series of source cleanup patches. All translation logic is now part of FuncProcessor. Code generation is now handled by an ISpecWriter implementation. Minor improvements to IEquatable and ToString() implementations. Reduced the surface of the public API. --- Source/Bind/Structures/Function.cs | 71 +++++++----------------------- 1 file changed, 16 insertions(+), 55 deletions(-) diff --git a/Source/Bind/Structures/Function.cs b/Source/Bind/Structures/Function.cs index 39656500..e8f5d34b 100644 --- a/Source/Bind/Structures/Function.cs +++ b/Source/Bind/Structures/Function.cs @@ -72,9 +72,6 @@ namespace Bind.Structures { get { - if ((Settings.Compatibility & Settings.Legacy.NoPublicUnsafeFunctions) != Settings.Legacy.None) - return false; - return base.Unsafe; } } @@ -99,52 +96,14 @@ namespace Bind.Structures #endregion - #region public override string ToString() + #region ToString public override string ToString() { - StringBuilder sb = new StringBuilder(); - - sb.Append(Unsafe ? "unsafe " : ""); - sb.Append(ReturnType); - sb.Append(" "); - if ((Settings.Compatibility & Settings.Legacy.NoTrimFunctionEnding) != Settings.Legacy.None) - { - sb.Append(Settings.FunctionPrefix); - } - sb.Append(!String.IsNullOrEmpty(TrimmedName) ? TrimmedName : Name); - - if (Parameters.HasGenericParameters) - { - sb.Append("<"); - foreach (Parameter p in Parameters) - { - if (p.Generic) - { - sb.Append(p.CurrentType); - sb.Append(","); - } - } - sb.Remove(sb.Length - 1, 1); - sb.Append(">"); - } - sb.AppendLine(Parameters.ToString(false)); - if (Parameters.HasGenericParameters) - { - foreach (Parameter p in Parameters) - { - if (p.Generic) - sb.AppendLine(String.Format(" where {0} : struct", p.CurrentType)); - } - - } - - if (Body.Count > 0) - { - sb.Append(Body.ToString()); - } - - return sb.ToString(); + return String.Format("{0} {1}({2})", + ReturnType, + TrimmedName, + Parameters); } #endregion @@ -153,10 +112,11 @@ namespace Bind.Structures public bool Equals(Function other) { - return + bool result = !String.IsNullOrEmpty(TrimmedName) && !String.IsNullOrEmpty(other.TrimmedName) && - TrimmedName == other.TrimmedName && - Parameters.ToString(true) == other.Parameters.ToString(true); + TrimmedName.Equals(other.TrimmedName) && + Parameters.Equals(other.Parameters); + return result; } #endregion @@ -201,13 +161,15 @@ namespace Bind.Structures public void Unindent() { - if (indent.Length >= 4) + if (indent.Length > 4) indent = indent.Substring(4); + else + indent = String.Empty; } new public void Add(string s) { - base.Add(indent + s); + base.Add(indent + s.TrimEnd('\r', '\n')); } new public void AddRange(IEnumerable collection) @@ -244,7 +206,7 @@ namespace Bind.Structures { Regex unsignedFunctions = new Regex(@".+(u[dfisb]v?)", RegexOptions.Compiled); - public void Add(Function f) + void Add(Function f) { if (!ContainsKey(f.Extension)) { @@ -261,7 +223,7 @@ namespace Bind.Structures { foreach (Function f in functions) { - Add(f); + AddChecked(f); } } @@ -284,8 +246,7 @@ namespace Bind.Structures if ((existing.Parameters.HasUnsignedParameters && !unsignedFunctions.IsMatch(existing.Name) && unsignedFunctions.IsMatch(f.Name)) || (!existing.Parameters.HasUnsignedParameters && unsignedFunctions.IsMatch(existing.Name) && !unsignedFunctions.IsMatch(f.Name))) { - this[f.Extension].RemoveAt(index); - this[f.Extension].Add(f); + this[f.Extension][index] = f; } } }