/// <summary> /// Determine the state of a single switch /// </summary> /// <param name="switchName">Switch name to check.</param> /// <param name="precedence">The precedence rules for this switch.</param> public SwitchState GetSwitchState(string switchName, OrderOfPrecedence precedence) { string[] switchNames = new string[1] { switchName }; return(_compilerCommandLine.GetSwitchState(switchNames, null, SwitchState.SwitchNotFound, precedence)); }
/// <summary> /// Determine if a switch is set,unset or not present on the command-line. /// </summary> /// <param name="switchNames">Array of switches that alias each other and all set the same compiler state.</param> /// <param name="overrideNames">Array of switches that invalidate the state of the switches in switchNames.</param> /// <param name="defaultState">The default state of the switch should no instance of the switch or its overrides be found.</param> /// <param name="precedence">The precedence rules for this set of switches.</param> public SwitchState GetSwitchState(string[] switchNames, string[] overrideNames, SwitchState defaultState, OrderOfPrecedence precedence) { // TODO-paddymcd-MSFT - This is an OK first pass. // Unfortunately composite switches get tricky and not all switches support the '-' semantics // e.g. /O1- gets translated to /O1 /O-, the second of which is not supported. // Additionally, currently /d2guardspecload is translated into /guardspecload, which may be a bug for ENC SwitchState namedswitchesState = SwitchState.SwitchNotFound; if (switchNames != null && switchNames.Length > 0) { // array of strings for the switch name without the preceding switchPrefix to make comparison easier string[] switchArray = new string[switchNames.Length]; string[] overridesArray = null; SwitchState namedoverridesState = SwitchState.SwitchNotFound; for (int index = 0; index < switchNames.Length; index++) { // if present remove the slash or minus switchArray[index] = switchNames[index].TrimStart(switchPrefix); } if (overrideNames != null && overrideNames.Length > 0) { overridesArray = new string[overrideNames.Length]; for (int index = 0; index < overrideNames.Length; index++) { // if present remove the slash or minus overridesArray[index] = overrideNames[index].TrimStart(switchPrefix); } } foreach (string arg in ArgumentSplitter.CommandLineToArgvW(this.Raw)) { if (IsSwitch(arg)) { string realArg = arg.TrimStart(switchPrefix); // Check if this matches one of the names switches for (int index = 0; index < switchArray.Length; index++) { if (realArg.StartsWith(switchArray[index])) { // partial stem match - now check if this is a full match or a match with a "-" on the end if (realArg.Equals(switchArray[index])) { namedswitchesState = SwitchState.SwitchEnabled; // not necessary at this time, but here for completeness... namedoverridesState = SwitchState.SwitchDisabled; } else if (realArg[switchArray[index].Length] == '-') { namedswitchesState = SwitchState.SwitchDisabled; } // Else we have a stem match - do nothing } } // check if this matches one of the named overrides if (overridesArray != null) { for (int index = 0; index < overridesArray.Length; index++) { if (realArg.StartsWith(overridesArray[index])) { // partial stem match - now check if this is a full match or a match with a "-" on the end if (realArg.Equals(overridesArray[index])) { namedoverridesState = SwitchState.SwitchEnabled; namedswitchesState = SwitchState.SwitchDisabled; } else if (realArg[overridesArray[index].Length] == '-') { namedoverridesState = SwitchState.SwitchDisabled; // Unsetting an override has no impact upon the named switches } // Else we have a stem match - do nothing } } } if (namedswitchesState != SwitchState.SwitchNotFound && namedoverridesState != SwitchState.SwitchNotFound && precedence == OrderOfPrecedence.FirstWins) { // we found a switch that impacts the desired state and FirstWins is set break; } } } if (namedswitchesState == SwitchState.SwitchNotFound) { if (namedoverridesState == SwitchState.SwitchEnabled) { namedswitchesState = SwitchState.SwitchDisabled; } else { namedswitchesState = defaultState; } } } return(namedswitchesState); }
/// <summary> /// Determine if a switch is set,unset or not present on the command-line. /// </summary> /// <param name="switchNames">Array of switches that alias each other and all set the same compiler state.</param> /// <param name="overrideNames">Array of switches that invalidate the state of the switches in switchNames.</param> /// <param name="defaultState">The default state of the switch should no instance of the switch or its overrides be found.</param> /// <param name="precedence">The precedence rules for this set of switches.</param> public SwitchState GetSwitchState(string[] switchNames, string[] overrideNames, SwitchState defaultStateOfFirst, OrderOfPrecedence precedence) { return(_compilerCommandLine.GetSwitchState(switchNames, overrideNames, defaultStateOfFirst, precedence)); }