public CompilerCommandLine()

in src/BinaryParsers/PEBinary/ProgramDatabase/CompilerCommandLine.cs [62:202]


        public CompilerCommandLine(string commandLine)
        {
            //
            // https://msdn.microsoft.com/en-us/library/thxezb7y.aspx
            //

            this.Raw = commandLine ?? "";
            this.WarningLevel = 0;
            this.WarningsAsErrors = false;
            var explicitWarnings = new Dictionary<int, WarningState>();
            foreach (string argument in ArgumentSplitter.CommandLineToArgvW(commandLine))
            {
                if (!CommandLineHelper.IsCommandLineOption(argument))
                {
                    continue;
                }

                switch (argument.Length)
                {
                    case 2:
                        // /w Disables all compiler warnings.
                        if (argument[1] == 'w')
                        {
                            this.WarningLevel = 0;
                        }
                        break;
                    case 3:
                        if (argument[1] == 'W')
                        {
                            char wChar = argument[2];
                            if (wChar == 'X')
                            {
                                // Treats all compiler warnings as errors.
                                this.WarningsAsErrors = true;
                            }
                            else if (wChar >= '0' && wChar <= '4')
                            {
                                // Specifies the level of warning to be generated by the compiler.
                                this.WarningLevel = wChar - '0';
                            }
                        }
                        break;
                    case 4:
                        if (argument.EndsWith("WX-"))
                        {
                            // (inverse of) Treats all compiler warnings as errors.
                            this.WarningsAsErrors = false;
                        }
                        break;
                    case 5:
                        if (argument.EndsWith("Wall"))
                        {
                            // Displays all /W4 warnings and any other warnings that are not included in /W4
                            this.WarningLevel = 4;
                        }
                        break;
                    case 7:
                        if (argument[1] != 'w')
                        {
                            break;
                        }

                        WarningState state;
                        char mode = argument[2];
                        if (mode == 'd')
                        {
                            // Disables the compiler warning that is specified
                            state = WarningState.Disabled;
                        }
                        else if (mode == 'e')
                        {
                            // Treats as an error the compiler warning that is specified
                            state = WarningState.AsError;
                        }
                        else if (mode == 'o')
                        {
                            // Reports the error only once for the compiler warning that is specified
                            state = WarningState.Once;
                        }
                        else if (mode >= '1' && mode <= '4')
                        {
                            // Specifies the level for a particular warning.
                            // e.g. /w14996 sets 4996 to level 1
                            state = (WarningState)(mode - '1' + (int)WarningState.Level1);
                        }
                        else
                        {
                            break;
                        }

                        int warningNumber;
                        if (!int.TryParse(argument.Remove(0, 3), 0, CultureInfo.InvariantCulture, out warningNumber))
                        {
                            break;
                        }

                        explicitWarnings[warningNumber] = state;
                        break;
                }
            }

            ImmutableArray<int>.Builder explicitlyDisabledBuilder = ImmutableArray.CreateBuilder<int>();
            foreach (KeyValuePair<int, WarningState> entry in explicitWarnings)
            {
                bool isEnabled;
                switch (entry.Value)
                {
                    case WarningState.AsError:
                    case WarningState.Once:
                        isEnabled = true;
                        break;
                    case WarningState.Disabled:
                        isEnabled = false;
                        break;
                    case WarningState.Level1:
                        isEnabled = this.WarningLevel >= 1;
                        break;
                    case WarningState.Level2:
                        isEnabled = this.WarningLevel >= 2;
                        break;
                    case WarningState.Level3:
                        isEnabled = this.WarningLevel >= 3;
                        break;
                    case WarningState.Level4:
                        isEnabled = this.WarningLevel >= 4;
                        break;
                    default:
                        isEnabled = true;
                        Debug.Fail("Unexpected WarningState");
                        break;
                }

                if (!isEnabled)
                {
                    explicitlyDisabledBuilder.Add(entry.Key);
                }
            }

            explicitlyDisabledBuilder.Sort();
            this.WarningsExplicitlyDisabled = explicitlyDisabledBuilder.ToImmutable();
        }