Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed generic type parameters (for real this time!), suppressed point…

…er parameters and shuffled code for improved readability.

git-svn-id: https://opentk.svn.sourceforge.net/svnroot/opentk/trunk@3098 ebc5dd9b-fb1d-0410-b6f8-d24c324e9604
  • Loading branch information...
commit db172f7e2c96cc499cb4b92d0791866ee0e7c324 1 parent a9fa266
the_fiddler authored
Showing with 86 additions and 72 deletions.
  1. +86 −72 Source/Bind/JavaSpecWriter.cs
View
158 Source/Bind/JavaSpecWriter.cs
@@ -161,12 +161,15 @@ public void WriteEnums(BindStreamWriter sw, EnumCollection enums)
static void WriteWrapper(Function f, BindStreamWriter sw)
{
- var parameters = GenerateParameterString(f);
+ var valid = true;
var generic_parameters = GenerateGenericParameterString(f);
+ var parameters = GenerateParameterString(f, out valid);
+ if (!valid)
+ return;
if (!String.IsNullOrEmpty(generic_parameters))
- sw.WriteLine("public static {0} <1> {2}({3})", f.ReturnType, generic_parameters,
- f.TrimmedName, parameters);
+ sw.WriteLine("public static <{0}> {1} {2}({3})", generic_parameters,
+ f.ReturnType, f.TrimmedName, parameters);
else
sw.WriteLine("public static {0} {1}({2})", f.ReturnType, f.TrimmedName,
parameters);
@@ -187,6 +190,86 @@ static void WriteMethodBody(BindStreamWriter sw, Function f)
// sw.WriteLine("GLES20.{0}{1};", f.WrappedDelegate.Name, callstring);
}
+ #region GenerateParameterString
+
+ static string GenerateParameterString(Function f, out bool valid)
+ {
+ if (f == null)
+ throw new ArgumentNullException("f");
+
+ valid = true;
+ var sb = new StringBuilder();
+
+ if (f.Parameters.Count > 0)
+ {
+ foreach (var p in f.Parameters)
+ {
+ if (p.Reference)
+ {
+ if (p.Flow == FlowDirection.Out)
+ sb.Append("Out<");
+ else
+ sb.Append("Ref<");
+
+ sb.Append(p.CurrentType);
+ sb.Append(">");
+ }
+ else if (p.Pointer > 0 && p.Array > 0)
+ {
+ sb.Append(p.CurrentType);
+ if (p.Array > 0)
+ sb.Append("[]");
+ }
+ else if (p.Pointer > 0)
+ {
+ // Java does not support pointers
+ // Todo: maybe use one of the java.nio.* pointer classes?
+ valid = false;
+ return String.Empty;
+ }
+ else
+ {
+ sb.Append(p.CurrentType);
+ }
+
+ sb.Append(" ");
+ sb.Append(p.Name);
+ sb.Append(", ");
+ }
+
+ if (f.Parameters.Count > 0)
+ sb.Remove(sb.Length - 2, 2);
+ }
+
+ return sb.ToString();
+ }
+
+ #endregion
+
+ #region GenerateGenericParameterString
+
+ static string GenerateGenericParameterString(Function f)
+ {
+ var parameters = f.Parameters.Where(p => p.Generic);
+ if (parameters.Count() > 0)
+ {
+ var sb = new StringBuilder();
+ foreach (var p in f.Parameters.Where(p => p.Generic))
+ {
+ sb.Append(p.CurrentType);
+ sb.Append(", ");
+ }
+ if (parameters.Count() > 0)
+ sb.Remove(sb.Length - 2, 2);
+
+ return sb.ToString();
+ }
+
+ return String.Empty;
+ }
+
+ #endregion
+
static DocProcessor processor = new DocProcessor(Path.Combine(Settings.DocPath, Settings.DocFile));
static Dictionary<string, string> docfiles;
void WriteDocumentation(BindStreamWriter sw, Function f)
@@ -261,74 +344,5 @@ public void WriteLicense(BindStreamWriter sw)
}
#endregion
-
- #region GenerateParameterString
-
- static string GenerateParameterString(Function f)
- {
- if (f == null)
- throw new ArgumentNullException("f");
-
- var sb = new StringBuilder();
-
- if (f.Parameters.Count > 0)
- {
- foreach (var p in f.Parameters)
- {
- if (p.Array == 0 || (p.Array > 0 && p.ElementCount != 1))
- {
- sb.Append(p.CurrentType);
- if (p.Array > 0)
- sb.Append("[]");
- }
- else if (p.Array > 0 && p.ElementCount == 1)
- {
- if (p.Flow == FlowDirection.Out)
- sb.Append("Out<");
- else
- sb.Append("Ref<");
-
- sb.Append(p.CurrentType);
- sb.Append(">");
- }
- else
- {
- throw new Exception();
- }
-
- sb.Append(" ");
- sb.Append(p.Name);
- sb.Append(", ");
- }
- sb.Remove(sb.Length - 2, 2);
- }
-
- return sb.ToString();
- }
-
- #endregion
-
- #region GenerateGenericParameterString
-
- static string GenerateGenericParameterString(Function f)
- {
- var parameters = f.Parameters.Where(p => p.Generic);
- if (parameters.Count() > 0)
- {
- var sb = new StringBuilder();
- foreach (var p in f.Parameters.Where(p => p.Generic))
- {
- sb.Append(p.CurrentType);
- }
- if (parameters.Count() > 1)
- sb.Remove(sb.Length - 2, 2);
-
- return sb.ToString();
- }
-
- return String.Empty;
- }
-
- #endregion
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.