2009-06-30 12:07:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml.XPath;
|
2009-08-21 20:28:14 +00:00
|
|
|
|
using Bind.GL2;
|
2009-06-30 12:07:03 +00:00
|
|
|
|
using Bind.Structures;
|
2009-08-21 20:28:14 +00:00
|
|
|
|
using Delegate=Bind.Structures.Delegate;
|
|
|
|
|
using Enum=Bind.Structures.Enum;
|
2009-06-30 12:07:03 +00:00
|
|
|
|
|
2009-07-15 14:59:10 +00:00
|
|
|
|
namespace Bind.ES
|
2009-06-30 12:07:03 +00:00
|
|
|
|
{
|
2009-08-21 20:28:14 +00:00
|
|
|
|
class ESGenerator : Generator
|
2009-06-30 12:07:03 +00:00
|
|
|
|
{
|
2009-08-25 15:46:22 +00:00
|
|
|
|
public ESGenerator(string nsName, string dirName)
|
2009-06-30 12:07:03 +00:00
|
|
|
|
{
|
2009-08-25 15:46:22 +00:00
|
|
|
|
if (String.IsNullOrEmpty(nsName))
|
|
|
|
|
throw new ArgumentNullException("nsName");
|
|
|
|
|
if (dirName == null)
|
|
|
|
|
dirName = nsName;
|
2009-06-30 12:07:03 +00:00
|
|
|
|
|
|
|
|
|
glTypemap = "GL2/gl.tm";
|
|
|
|
|
csTypemap = "csharp.tm";
|
2009-08-25 15:46:22 +00:00
|
|
|
|
|
|
|
|
|
enumSpec = dirName + "/signatures.xml";
|
2009-06-30 12:07:03 +00:00
|
|
|
|
enumSpecExt = String.Empty;
|
2009-08-25 15:46:22 +00:00
|
|
|
|
glSpec = dirName + "/signatures.xml";
|
2009-06-30 12:07:03 +00:00
|
|
|
|
glSpecExt = String.Empty;
|
2009-08-25 15:46:22 +00:00
|
|
|
|
functionOverridesFile = dirName + "/overrides.xml";
|
2009-06-30 12:07:03 +00:00
|
|
|
|
|
|
|
|
|
importsFile = "Core.cs";
|
|
|
|
|
delegatesFile = "Delegates.cs";
|
|
|
|
|
enumsFile = "Enums.cs";
|
2009-07-15 14:59:10 +00:00
|
|
|
|
wrappersFile = "ES.cs";
|
2009-06-30 12:07:03 +00:00
|
|
|
|
Settings.ImportsClass = "Core";
|
|
|
|
|
Settings.DelegatesClass = "Delegates";
|
|
|
|
|
|
2009-08-26 07:52:58 +00:00
|
|
|
|
Settings.OutputClass = "GL";
|
2009-08-25 15:46:22 +00:00
|
|
|
|
Settings.OutputNamespace = "OpenTK.Graphics." + nsName;
|
|
|
|
|
Settings.OutputPath = Path.Combine(Settings.OutputPath, dirName);
|
2009-06-30 12:07:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-21 20:28:14 +00:00
|
|
|
|
public override DelegateCollection ReadDelegates(StreamReader specFile)
|
2009-06-30 12:07:03 +00:00
|
|
|
|
{
|
|
|
|
|
DelegateCollection delegates = new DelegateCollection();
|
|
|
|
|
|
|
|
|
|
XPathDocument overrides = new XPathDocument(new StreamReader(Path.Combine(Settings.InputPath, functionOverridesFile)));
|
2009-08-25 15:46:22 +00:00
|
|
|
|
|
2009-07-15 22:33:26 +00:00
|
|
|
|
XPathNavigator nav = new XPathDocument(specFile).CreateNavigator().SelectSingleNode("/signatures");
|
|
|
|
|
|
2009-07-15 14:59:10 +00:00
|
|
|
|
foreach (XPathNavigator node in nav.SelectChildren("function", String.Empty))
|
2009-06-30 12:07:03 +00:00
|
|
|
|
{
|
2009-08-21 20:28:14 +00:00
|
|
|
|
Delegate d = new Delegate();
|
2009-06-30 12:07:03 +00:00
|
|
|
|
d.Name = node.GetAttribute("name", String.Empty);
|
|
|
|
|
//d.Extension = node.GetAttribute("extension");
|
|
|
|
|
d.Version = node.GetAttribute("version", String.Empty);
|
|
|
|
|
d.Category = node.GetAttribute("category", String.Empty);
|
|
|
|
|
foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
|
|
|
|
|
{
|
|
|
|
|
switch (param.Name)
|
|
|
|
|
{
|
|
|
|
|
case "returns":
|
|
|
|
|
d.ReturnType.CurrentType = param.GetAttribute("type", String.Empty);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "param":
|
|
|
|
|
Parameter p = new Parameter();
|
|
|
|
|
p.CurrentType = param.GetAttribute("type", String.Empty);
|
|
|
|
|
p.Name = param.GetAttribute("name", String.Empty);
|
2009-07-15 22:33:26 +00:00
|
|
|
|
|
2009-06-30 12:07:03 +00:00
|
|
|
|
string element_count = param.GetAttribute("elementcount", String.Empty);
|
|
|
|
|
if (!String.IsNullOrEmpty(element_count))
|
|
|
|
|
p.ElementCount = Int32.Parse(element_count);
|
2009-07-15 22:33:26 +00:00
|
|
|
|
|
|
|
|
|
p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty));
|
|
|
|
|
|
2009-06-30 12:07:03 +00:00
|
|
|
|
d.Parameters.Add(p);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d.Translate(overrides);
|
|
|
|
|
delegates.Add(d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return delegates;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Dictionary<string, string> ReadTypeMap(StreamReader specFile)
|
|
|
|
|
{
|
|
|
|
|
return base.ReadTypeMap(specFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Dictionary<string, string> ReadCSTypeMap(StreamReader specFile)
|
|
|
|
|
{
|
|
|
|
|
return base.ReadCSTypeMap(specFile);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-21 20:28:14 +00:00
|
|
|
|
public override EnumCollection ReadEnums(StreamReader specFile)
|
2009-06-30 12:07:03 +00:00
|
|
|
|
{
|
|
|
|
|
EnumCollection enums = new EnumCollection();
|
2009-08-21 20:28:14 +00:00
|
|
|
|
Enum all = new Enum(Settings.CompleteEnumName);
|
2009-06-30 12:07:03 +00:00
|
|
|
|
XPathDocument doc = new XPathDocument(specFile);
|
2009-07-15 14:59:10 +00:00
|
|
|
|
XPathNavigator nav = doc.CreateNavigator().SelectSingleNode("/signatures");
|
2009-08-11 14:12:20 +00:00
|
|
|
|
|
|
|
|
|
XPathDocument overrides = new XPathDocument(new StreamReader(Path.Combine(Settings.InputPath, functionOverridesFile)));
|
2009-06-30 12:07:03 +00:00
|
|
|
|
|
2009-07-15 14:59:10 +00:00
|
|
|
|
foreach (XPathNavigator node in nav.SelectChildren("enum", String.Empty))
|
2009-06-30 12:07:03 +00:00
|
|
|
|
{
|
2009-08-21 20:28:14 +00:00
|
|
|
|
Enum e = new Enum(node.GetAttribute("name", String.Empty));
|
2009-07-15 14:59:10 +00:00
|
|
|
|
if (String.IsNullOrEmpty(e.Name))
|
|
|
|
|
throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString()));
|
2009-06-30 12:07:03 +00:00
|
|
|
|
|
|
|
|
|
foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
|
|
|
|
|
{
|
|
|
|
|
Constant c = new Constant(param.GetAttribute("name", String.Empty), param.GetAttribute("value", String.Empty));
|
|
|
|
|
Utilities.Merge(all, c);
|
|
|
|
|
e.ConstantCollection.Add(c.Name, c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utilities.Merge(enums, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utilities.Merge(enums, all);
|
2009-08-11 14:12:20 +00:00
|
|
|
|
enums.Translate(overrides);
|
2009-06-30 12:07:03 +00:00
|
|
|
|
return enums;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|