コード例 #1
0
        private bool ShouldUseFixedForParam(XmlCommandParamData param)
        {
            if (this.ShouldUseGenericsForType(param.Type))
                return false;

            string dotNetType = this.InflectFunctionParamDotNetType(param);

            if (this.IsTypePointer(param.Type) &&
                dotNetType != "string" &&
                dotNetType != "string[]" &&
                dotNetType != "StringBuilder" &&
                dotNetType != "IntPtr")
            {
                return true;
            }

            return false;
        }
コード例 #2
0
 private bool ShouldChangeFunctionParamToRefOrOut(XmlCommandParamData param)
 {
     return !string.IsNullOrEmpty(param.Length) &&
            !(param.Type.Contains("GLchar*") || param.Type.Contains("GLchar *")) &&
            this.InflectFunctionParamDotNetType(param) != "IntPtr";
 }
コード例 #3
0
        private bool ShouldUseAddressOfOperatorForParam(XmlCommandParamData param)
        {
            if (this.IsTypePointer(param.Type))
                return false;

            if (!string.IsNullOrEmpty(param.Length))
                return true;

            return false;
        }
コード例 #4
0
 private bool ShouldChangeFunctionParamToIntPtr(XmlCommandParamData param)
 {
     return !string.IsNullOrEmpty(param.Length) &&
            this.ShouldUseGenericsForType(param.Type);
 }
コード例 #5
0
        private string InflectFunctionParamNativeType(XmlCommandParamData param)
        {
            string type = param.Type;

            if (type == "const GLchar*" || type == "const GLchar *")
                return "string";

            if (type.StartsWith("const "))
                type = type.Substring("const ".Length);

            switch (type)
            {
                case "GLchar*":
                case "GLchar *":
                    type = "StringBuilder";
                    break;

                case "void*":
                case "void *":
                case "GLvoid*":
                case "GLvoid *":
                case "void**":
                case "void **":
                case "void *const*":
                case "GLvoid**":
                case "GLvoid **":
                    type = "IntPtr";
                    break;

                default:
                    type = this.InflectType(type, true);
                    break;
            }

            return type;
        }
コード例 #6
0
        private string InflectFunctionParamDotNetType(XmlCommandParamData param)
        {
            string type = param.Type;

            switch (param.Type)
            {
                case "const GLchar**":
                case "const GLchar **":
                    type = "string[]";
                    break;

                case "const GLchar*":
                case "const GLchar *":
                    type = "string";
                    break;

                case "GLchar*":
                case "GLchar *":
                    type = "StringBuilder";
                    break;

                case "void*":
                case "void *":
                case "GLvoid*":
                case "GLvoid *":
                case "void**":
                case "void **":
                case "const void *const*":
                case "GLvoid**":
                case "GLvoid **":
                case "const GLvoid**":
                case "const GLvoid **":
                    type = "IntPtr";
                    break;

                default:
                    type = this.InflectType(type, false);
                    break;
            }

            if (this.ShouldUseGenericsForType(param.Type))
            {
                type = type
                    .Replace("GLvoid", "T")
                    .Replace("void", "T");
            }

            if (this.IsTypePointer(param.Type) &&
                type != "string" &&
                type != "string[]" &&
                type != "StringBuilder" &&
                type != "IntPtr")
            {
                type += "[]";
            }

            return type;
        }
コード例 #7
0
 public bool IsTypeEnum(XmlCommandParamData param, DotNetApiData api)
 {
     return (param.Type == "GLenum" || param.Type == "GLbitfield") &&
            !string.IsNullOrEmpty(param.TypeGroup) &&
            api.EnumGroups.Any(x => x.Name == param.TypeGroup);
 }
コード例 #8
0
ファイル: XmlSpecParser.cs プロジェクト: smack0007/GLDotNet
        private void ParseCommands(XDocument doc, XmlSpecData data, Options options)
		{
			foreach (var commandSetNode in doc.Root.Elements("commands"))
			{
				foreach (var commandNode in commandSetNode.Elements())
				{
					XmlCommandData commandData = new XmlCommandData()
					{
                        Name = this.EnsureCommandNameHasPrefix(commandNode.GetElementValue("proto", "name"), options),
						ReturnType = commandNode.GetElementValue("proto", "ptype"),
						ReturnTypeGroup = commandNode.GetElementAttributeValue("proto", "group"),
						Alias = commandNode.GetElementAttributeValue("alias", "name")
					};
									
					if (commandData.ReturnType == null)
						commandData.ReturnType = commandNode.Element("proto").GetTexts().First().Trim();

					// "void *" => "void*"
					if (commandData.ReturnType.EndsWith(" *"))
						commandData.ReturnType = commandData.ReturnType.Substring(0, commandData.ReturnType.Length - 2) + "*";

					foreach (var commandParamNode in commandNode.Elements("param"))
					{
						XmlCommandParamData commandParamData = new XmlCommandParamData()
						{
							Name = commandParamNode.GetElementValue("name"),
							Type = commandParamNode.GetElementValue("ptype"),
							TypeGroup = commandParamNode.GetAttributeValue("group"),
							Length = commandParamNode.GetAttributeValue("len")
						};

						if (commandParamData.Type == null)
						{
							commandParamData.Type = commandParamNode.GetTexts().First().Trim();
						}
						else
						{
							var texts = commandParamNode.GetTexts();

							if (texts.Count() == 1 &&
								texts.First().Contains("*"))
							{
								commandParamData.Type = commandParamData.Type + new string('*', texts.First().Count(x => x == '*'));
							}
							else if (
								texts.Count() == 2 &&
								texts.First().Trim() == "const" &&
								texts.Last().Contains("*"))
							{
								commandParamData.Type = "const " + commandParamData.Type + new string('*', texts.Last().Count(x => x == '*'));
							}
						}

						// "const void *" => "const void*"
						if (commandParamData.Type.EndsWith(" *"))
							commandParamData.Type = commandParamData.Type.Substring(0, commandParamData.Type.Length - 2) + "*";

						commandData.Params.Add(commandParamData);
					}

					data.Commands.Add(commandData);
				}
			}
		}