Inheritance: IDiagnosticsCollection
示例#1
0
        public static IDiagnosticsSink InsertSink(
            this IDiagnosticsSink sink)
        {
            var subSink = new DiagnosticSink();

            sink.Add(subSink);
            return(subSink);
        }
 public static IDiagnosticsSink InsertSink(
     this IDiagnosticsSink sink)
 {
     var subSink = new DiagnosticSink();
     sink.Add(subSink);
     return subSink;
 }
示例#3
0
            public static Options Parse(string[] args)
            {
                var diagnostics = new DiagnosticSink();
                var range = new SourceRange("<command line>");

                Options result = new Options();

                int argCount = args.Length;
                int argIdx = 0;

                while (argIdx < argCount)
                {
                    var argStr = args[argIdx++];
                    if (argStr.StartsWith("-"))
                    {
                        if (argStr.StartsWith("-o"))
                        {
                            var option = argStr.Substring(2);
                            if( string.IsNullOrWhiteSpace(option) )
                            {
                                option = args[argIdx++];
                            }

                            result.outputPrefix = option;
                        }
                        else
                        {
                            diagnostics.Add(
                                Severity.Error,
                                range,
                                "Unknown option '{0}'",
                                argStr);
                        }
                    }
                    else
                    {
                        result.fileNames.Add(argStr);
                    }
                }

                int fileCount = result.fileNames.Count;
                if (fileCount == 1)
                {
                    if (result.outputPrefix == null)
                    {
                        result.outputPrefix = result.fileNames[0];
                    }
                }
                else if (fileCount == 0)
                {
                    diagnostics.Add(
                        Severity.Error,
                        range,
                        "No input files given");
                }
                else
                {
                    if (result.outputPrefix == null)
                    {
                        diagnostics.Add(
                            Severity.Error,
                            range,
                            "When multiple input files are given, an output prefix must be selected with -o");
                    }
                }

                int errorCount = diagnostics.Flush(System.Console.Error);
                if (errorCount != 0)
                {
                    System.Console.Error.WriteLine(
                        "Usage: sparkc [-o outputPrefix] file.spark file2.spark");
                    return null;
                }

                return result;
            }