Avoid using singletons

The IBind generator and the Settings class are now passed directly as
parameters. This allows us to run multiple generators in a single
process.
This commit is contained in:
Stefanos A. 2013-11-01 08:59:20 +01:00
parent 6022ea9fbd
commit 2eac75ea4d

View file

@ -42,11 +42,17 @@ namespace Bind
const string Path = "/signatures/replace/enum[@name='{0}']"; const string Path = "/signatures/replace/enum[@name='{0}']";
string Overrides { get; set; } string Overrides { get; set; }
public EnumProcessor(string overrides) IBind Generator { get; set; }
Settings Settings { get { return Generator.Settings; } }
public EnumProcessor(IBind generator, string overrides)
{ {
if (generator == null)
throw new ArgumentNullException("generator");
if (overrides == null) if (overrides == null)
throw new ArgumentNullException("overrides"); throw new ArgumentNullException("overrides");
Generator = generator;
Overrides = overrides; Overrides = overrides;
} }
@ -94,7 +100,7 @@ namespace Bind
if (String.IsNullOrEmpty(name)) if (String.IsNullOrEmpty(name))
return name; return name;
if (Utilities.Keywords.Contains(name)) if (Utilities.Keywords(Settings.Language).Contains(name))
return name; return name;
if (Char.IsDigit(name[0])) if (Char.IsDigit(name[0]))
@ -217,7 +223,7 @@ namespace Bind
} }
} }
public static string TranslateConstantName(string s, bool isValue) public string TranslateConstantName(string s, bool isValue)
{ {
if (String.IsNullOrEmpty(s)) if (String.IsNullOrEmpty(s))
return s; return s;
@ -277,7 +283,7 @@ namespace Bind
return translator.ToString(); return translator.ToString();
} }
public static string TranslateConstantValue(string value) public string TranslateConstantValue(string value)
{ {
// Remove decorations to get a pure number (e.g. 0x80u -> 80). // Remove decorations to get a pure number (e.g. 0x80u -> 80).
if (value.ToLower().StartsWith("0x")) if (value.ToLower().StartsWith("0x"))