Made the escape character for reserved keywords customizable. (C# uses '@' and Java/C++ use '_' by default). Updated the Parameter class to return escaped names by default and added a RawName parameter to access the raw names.

This commit is contained in:
the_fiddler 2011-12-05 11:49:59 +00:00
parent 6443b271dd
commit 154ce76303
3 changed files with 33 additions and 10 deletions

View file

@ -94,6 +94,7 @@ namespace Bind
// Settings.DefaultLanguageTypeMapFile = "cpp.tm"; // Todo: create this file! // Settings.DefaultLanguageTypeMapFile = "cpp.tm"; // Todo: create this file!
Settings.EnumsNamespace = ""; Settings.EnumsNamespace = "";
Settings.NamespaceSeparator = "::"; Settings.NamespaceSeparator = "::";
Settings.DefaultKeywordEscapeCharacter = "_";
} }
else if (arg == "java") else if (arg == "java")
{ {
@ -103,6 +104,7 @@ namespace Bind
Settings.DefaultLanguageTypeMapFile = "java.tm"; Settings.DefaultLanguageTypeMapFile = "java.tm";
Settings.EnumsNamespace = ""; Settings.EnumsNamespace = "";
Settings.NamespaceSeparator = "."; Settings.NamespaceSeparator = ".";
Settings.DefaultKeywordEscapeCharacter = "_";
} }
break; break;
} }

View file

@ -21,9 +21,10 @@ namespace Bind
public static string DefaultLicenseFile = "License.txt"; public static string DefaultLicenseFile = "License.txt";
public static string DefaultOverridesFile = "GL2/gloverrides.xml"; public static string DefaultOverridesFile = "GL2/gloverrides.xml";
public static string DefaultLanguageTypeMapFile = "csharp.tm"; public static string DefaultLanguageTypeMapFile = "csharp.tm";
public static string DefaultKeywordEscapeCharacter = "@";
static string inputPath, outputPath, outputNamespace, docPath, docFile, licenseFile, overridesFile, static string inputPath, outputPath, outputNamespace, docPath, docFile, licenseFile, overridesFile,
languageTypeMapFile; languageTypeMapFile, keywordEscapeCharacter;
public static string InputPath { get { return inputPath ?? DefaultInputPath; } set { inputPath = value; } } public static string InputPath { get { return inputPath ?? DefaultInputPath; } set { inputPath = value; } }
public static string OutputPath { get { return outputPath ?? DefaultOutputPath; } set { outputPath = value; } } public static string OutputPath { get { return outputPath ?? DefaultOutputPath; } set { outputPath = value; } }
public static string OutputNamespace { get { return outputNamespace ?? DefaultOutputNamespace; } set { outputNamespace = value; } } public static string OutputNamespace { get { return outputNamespace ?? DefaultOutputNamespace; } set { outputNamespace = value; } }
@ -32,6 +33,7 @@ namespace Bind
public static string LicenseFile { get { return licenseFile ?? DefaultLicenseFile; } set { licenseFile = value; } } public static string LicenseFile { get { return licenseFile ?? DefaultLicenseFile; } set { licenseFile = value; } }
public static string OverridesFile { get { return overridesFile ?? DefaultOverridesFile; } set { overridesFile = value; } } public static string OverridesFile { get { return overridesFile ?? DefaultOverridesFile; } set { overridesFile = value; } }
public static string LanguageTypeMapFile { get { return languageTypeMapFile ?? DefaultLanguageTypeMapFile; } set { languageTypeMapFile = value; } } public static string LanguageTypeMapFile { get { return languageTypeMapFile ?? DefaultLanguageTypeMapFile; } set { languageTypeMapFile = value; } }
public static string KeywordEscapeCharacter { get { return keywordEscapeCharacter ?? DefaultKeywordEscapeCharacter; } set { keywordEscapeCharacter = value; } }
public static string GLClass = "GL"; // Needed by Glu for the AuxEnumsClass. Can be set through -gl:"xxx". public static string GLClass = "GL"; // Needed by Glu for the AuxEnumsClass. Can be set through -gl:"xxx".
public static string OutputClass = "GL"; // The real output class. Can be set through -class:"xxx". public static string OutputClass = "GL"; // The real output class. Can be set through -class:"xxx".

View file

@ -52,25 +52,44 @@ namespace Bind.Structures
#endregion #endregion
#region public string Name #region RawName
string _name = String.Empty;
/// <summary> /// <summary>
/// Gets or sets the name of the parameter. /// Gets or sets the raw name of the parameter.
/// </summary>
public string RawName
{
get;
private set;
}
#endregion
#region Name
/// <summary>
/// Gets the name of the parameter. If the name matches a keyword of the current language,
/// then it is escaped with <see cref="Settings.KeywordEscapeCharacter"/>.
/// </summary> /// </summary>
public string Name public string Name
{ {
get { return _name; } get
{
if (Utilities.Keywords.Contains(RawName))
return Settings.KeywordEscapeCharacter + RawName;
else
return RawName;
}
set set
{ {
if (_name != value) if (RawName != value)
{ {
while (value.StartsWith("*")) while (value.StartsWith("*"))
{ {
Pointer++; Pointer++;
value = value.Substring(1); value = value.Substring(1);
} }
_name = value; RawName = value;
rebuild = true; rebuild = true;
} }
} }
@ -270,7 +289,7 @@ namespace Bind.Structures
if (!String.IsNullOrEmpty(Name)) if (!String.IsNullOrEmpty(Name))
{ {
sb.Append(" "); sb.Append(" ");
sb.Append(Utilities.Keywords.Contains(Name) ? "@" + Name : Name); sb.Append(Name);
} }
rebuild = false; rebuild = false;
@ -329,7 +348,7 @@ namespace Bind.Structures
WrapperType |= WrapperTypes.ReferenceParameter; WrapperType |= WrapperTypes.ReferenceParameter;
if (Utilities.Keywords.Contains(Name)) if (Utilities.Keywords.Contains(Name))
Name = "@" + Name; Name = Settings.KeywordEscapeCharacter + Name;
// This causes problems with bool arrays // This causes problems with bool arrays
//if (CurrentType.ToLower().Contains("bool")) //if (CurrentType.ToLower().Contains("bool"))
@ -626,7 +645,7 @@ namespace Bind.Structures
} }
} }
sb.Append(Utilities.Keywords.Contains(p.Name) ? "@" + p.Name : p.Name); sb.Append(p.Name);
if (p.Unchecked) if (p.Unchecked)
sb.Append(")"); sb.Append(")");