2007-08-01 09:27:57 +00:00
|
|
|
|
using System;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
namespace Bind.Structures
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
|
public class Function : Delegate
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
|
#region --- Constructors ---
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
public Function()
|
2007-08-01 09:27:57 +00:00
|
|
|
|
: base()
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
|
|
|
|
Body = new FunctionBody();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Function(Function f)
|
2007-08-01 09:27:57 +00:00
|
|
|
|
: base(f)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
|
|
|
|
this.Body = new FunctionBody(f.Body);
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
public Function(Delegate d)
|
|
|
|
|
: base(d)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
|
this.Body = new FunctionBody();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
public override bool Unsafe
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
|
get
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
|
if (Settings.Compatibility == Settings.Legacy.Tao)
|
|
|
|
|
return false;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
return base.Unsafe;
|
|
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
#region Function body
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
FunctionBody _body;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
public FunctionBody Body
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
|
get { return _body; }
|
|
|
|
|
set { _body = value; }
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
#region public override string ToString()
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
public override string ToString()
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2007-08-01 09:27:57 +00:00
|
|
|
|
|
|
|
|
|
sb.Append(Unsafe ? "unsafe " : "");
|
|
|
|
|
sb.Append(ReturnType);
|
|
|
|
|
sb.Append(" ");
|
|
|
|
|
if (Settings.Compatibility == Settings.Legacy.Tao)
|
|
|
|
|
{
|
|
|
|
|
sb.Append("gl");
|
|
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
|
sb.Append(Name);
|
2007-08-01 09:27:57 +00:00
|
|
|
|
sb.Append(Parameters.ToString(true));
|
|
|
|
|
if (Body.Count > 0)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
|
sb.AppendLine();
|
|
|
|
|
sb.Append(Body.ToString());
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
#region public Function GetCLSCompliantFunction(Dictionary<string, string> CSTypes)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
public Function GetCLSCompliantFunction(Dictionary<string, string> CSTypes)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
|
Function f = new Function(this);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
for (int i = 0; i < f.Parameters.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
f.Parameters[i].Type = f.Parameters[i].GetCLSCompliantType(CSTypes);
|
|
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
f.Body.Clear();
|
|
|
|
|
if (!f.NeedsWrapper)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
|
f.Body.Add((f.ReturnType.Type != "void" ? "return " + this.CallString() : this.CallString()) + ";");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
f.Body.AddRange(Function.GetBodyWithPins(this, CSTypes, true));
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-01 09:27:57 +00:00
|
|
|
|
// The type system cannot differentiate between functions with the same parameters
|
|
|
|
|
// but different return types. Tough, only CLS-Compliant function in that case.
|
|
|
|
|
//f.ReturnType.Type = f.ReturnType.GetCLSCompliantType(CSTypes);
|
|
|
|
|
|
|
|
|
|
return f;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region class FunctionBody : List<string>
|
|
|
|
|
|
|
|
|
|
public class FunctionBody : List<string>
|
|
|
|
|
{
|
|
|
|
|
public FunctionBody()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FunctionBody(FunctionBody fb)
|
|
|
|
|
{
|
|
|
|
|
foreach (string s in fb)
|
|
|
|
|
{
|
|
|
|
|
this.Add(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
if (this.Count == 0)
|
|
|
|
|
return String.Empty;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(this.Count);
|
2007-08-01 09:27:57 +00:00
|
|
|
|
|
|
|
|
|
sb.AppendLine("{");
|
2007-07-23 00:15:18 +00:00
|
|
|
|
foreach (string s in this)
|
|
|
|
|
{
|
2007-08-01 09:27:57 +00:00
|
|
|
|
sb.AppendLine(" " + s);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
2007-08-01 09:27:57 +00:00
|
|
|
|
sb.AppendLine("}");
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-08-01 09:27:57 +00:00
|
|
|
|
|
|
|
|
|
class FunctionCollection : Dictionary<string, List<Function>>
|
|
|
|
|
{
|
|
|
|
|
public void Add(Function f)
|
|
|
|
|
{
|
|
|
|
|
if (!this.ContainsKey(f.Extension))
|
|
|
|
|
{
|
|
|
|
|
this.Add(f.Extension, new List<Function>());
|
|
|
|
|
this[f.Extension].Add(f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this[f.Extension].Add(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddRange(IEnumerable<Function> functions)
|
|
|
|
|
{
|
|
|
|
|
foreach (Function f in functions)
|
|
|
|
|
{
|
|
|
|
|
this.Add(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|