private void ProcessConditionalDirective(string directive, string line, CompileResults results)
{
string macroName = GetNextWord(ref line, true, true);
if (macroName.Length == 0)
{
RecordError(ErrorCode.MacroNameMissing, "Expected something after '" + directive + "'");
return;
}
bool includeCodeBlock = true;
if ((_conditionalStatements.Count > 0) &&
(_conditionalStatements.Peek() == false))
{
includeCodeBlock = false;
}
else if (directive.EndsWith("def"))
{
includeCodeBlock = _state.Macros.Contains(macroName);
if (directive == "ifndef")
{
includeCodeBlock = !includeCodeBlock;
}
}
else if (directive == "ifver" || directive == "ifnver")
{
// Compare provided version number with the current application version
try
{
Version appVersion = new Version(_applicationVersion);
Version macroVersion = new Version(macroName);
includeCodeBlock = appVersion.CompareTo(macroVersion) >= 0;
if (directive == "ifnver")
{
includeCodeBlock = !includeCodeBlock;
}
}
catch (Exception e)
{
RecordError(ErrorCode.InvalidVersionNumber, String.Format("Cannot parse version number: {0}", e.Message));
}
}
_conditionalStatements.Push(includeCodeBlock);
}