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.
This commit is contained in:
Stefanos A. 2013-11-01 09:17:34 +01:00
parent 9c5d43b72b
commit 679afcc27a

View file

@ -72,9 +72,6 @@ namespace Bind.Structures
{ {
get get
{ {
if ((Settings.Compatibility & Settings.Legacy.NoPublicUnsafeFunctions) != Settings.Legacy.None)
return false;
return base.Unsafe; return base.Unsafe;
} }
} }
@ -99,52 +96,14 @@ namespace Bind.Structures
#endregion #endregion
#region public override string ToString() #region ToString
public override string ToString() public override string ToString()
{ {
StringBuilder sb = new StringBuilder(); return String.Format("{0} {1}({2})",
ReturnType,
sb.Append(Unsafe ? "unsafe " : ""); TrimmedName,
sb.Append(ReturnType); Parameters);
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();
} }
#endregion #endregion
@ -153,10 +112,11 @@ namespace Bind.Structures
public bool Equals(Function other) public bool Equals(Function other)
{ {
return bool result =
!String.IsNullOrEmpty(TrimmedName) && !String.IsNullOrEmpty(other.TrimmedName) && !String.IsNullOrEmpty(TrimmedName) && !String.IsNullOrEmpty(other.TrimmedName) &&
TrimmedName == other.TrimmedName && TrimmedName.Equals(other.TrimmedName) &&
Parameters.ToString(true) == other.Parameters.ToString(true); Parameters.Equals(other.Parameters);
return result;
} }
#endregion #endregion
@ -201,13 +161,15 @@ namespace Bind.Structures
public void Unindent() public void Unindent()
{ {
if (indent.Length >= 4) if (indent.Length > 4)
indent = indent.Substring(4); indent = indent.Substring(4);
else
indent = String.Empty;
} }
new public void Add(string s) new public void Add(string s)
{ {
base.Add(indent + s); base.Add(indent + s.TrimEnd('\r', '\n'));
} }
new public void AddRange(IEnumerable<string> collection) new public void AddRange(IEnumerable<string> collection)
@ -244,7 +206,7 @@ namespace Bind.Structures
{ {
Regex unsignedFunctions = new Regex(@".+(u[dfisb]v?)", RegexOptions.Compiled); Regex unsignedFunctions = new Regex(@".+(u[dfisb]v?)", RegexOptions.Compiled);
public void Add(Function f) void Add(Function f)
{ {
if (!ContainsKey(f.Extension)) if (!ContainsKey(f.Extension))
{ {
@ -261,7 +223,7 @@ namespace Bind.Structures
{ {
foreach (Function f in functions) 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)) || if ((existing.Parameters.HasUnsignedParameters && !unsignedFunctions.IsMatch(existing.Name) && unsignedFunctions.IsMatch(f.Name)) ||
(!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][index] = f;
this[f.Extension].Add(f);
} }
} }
} }