using System; using System.Collections.Generic; using Semmle.Util; namespace Semmle.Extraction.CSharp { public sealed class Options : CommonOptions { /// /// The compiler exe, or null if unspecified. /// public string? CompilerName { get; set; } /// /// Specified .Net Framework dir, or null if unspecified. /// public string? Framework { get; set; } /// /// Project files whose source files should be added to the compilation. /// Only used in tests. /// public IList ProjectsToLoad { get; } = new List(); /// /// All other arguments passed to the compilation. /// public IList CompilerArguments { get; } = new List(); /// /// Holds if assembly information should be prefixed to TRAP labels. /// public bool AssemblySensitiveTrap { get; private set; } = false; /// /// The paths to the binary log files, or null if unspecified. /// public string[]? BinaryLogPaths { get; set; } public static Options CreateWithEnvironment(string[] arguments) { var options = new Options(); var argsList = new List(arguments); options.ParseArguments(argsList); return options; } public override bool HandleArgument(string argument) { CompilerArguments.Add(argument); return true; } public override void InvalidArgument(string argument) { // Unrecognised arguments are passed to the compiler. CompilerArguments.Add(argument); } public override bool HandleOption(string key, string value) { switch (key) { case "compiler": CompilerName = value; return true; case "framework": Framework = value; return true; case "load-sources-from-project": ProjectsToLoad.Add(value); return true; case "binlog": BinaryLogPaths = value.Split(FileUtils.NewLineCharacters, StringSplitOptions.RemoveEmptyEntries); return true; default: return base.HandleOption(key, value); } } public override bool HandleFlag(string flag, bool value) { switch (flag) { case "assemblysensitivetrap": AssemblySensitiveTrap = value; return true; default: return base.HandleFlag(flag, value); } } private Options() { } } }