Debian Codegraph @

mcs/tools/ccrewrite/Program.cs

raw
1 #define CONTRACTS_FULL
2
3 using System;
4 using System.Collections.Generic;
5 using System.Diagnostics.Contracts;
6 using System.Linq;
7 using System.Text;
8 using System.IO;
9 using Mono.CodeContracts.Rewrite;
10 using Mono.Options;
11
12 namespace ccrewrite {
13
14 class Program {
15
16 static void Main (string [] args)
17 {
18 RewriterOptions options = new RewriterOptions ();
19
20 bool showOptions = false;
21 string showMsg = null;
22
23 var optionSet = new OptionSet {
24 { "help", "Show this help.", v => showOptions = v != null },
25 { "debug", "Use MDB or PDB debug information (default=true).", v => options.Debug = v != null },
26 { "level=", "Instrumentation level, 0 - 4 (default=4).", (int var) => options.Level = var},
27 { "writePDBFile", "Write MDB or PDB file (default=true).", v => options.WritePdbFile = v != null },
28 { "rewrite", "Rewrite the assembly (default=true).", v => options.Rewrite = v != null },
29 { "assembly=", "Assembly to rewrite.", v => options.Assembly = v },
30 { "breakIntoDebugger|break", "Break into debugger on contract failure.", v => options.BreakIntoDebugger = v != null },
31 { "throwOnFailure|throw", "Throw ContractException on contract failure.", v => options.ThrowOnFailure = v != null },
32 { "output|out=", "Output filename of rewritten file.", v => options.OutputFile = v },
33 };
34
35 try {
36 optionSet.Parse (args);
37 } catch (OptionException e) {
38 showOptions = true;
39 showMsg = e.Message;
40 }
41
42 if (showOptions) {
43 Console.WriteLine ("ccrewrite");
44 Console.WriteLine ();
45 Console.WriteLine ("Options:");
46 optionSet.WriteOptionDescriptions (Console.Out);
47 Console.WriteLine ();
48 if (showMsg != null) {
49 Console.WriteLine (showMsg);
50 Console.WriteLine ();
51 }
52 return;
53 }
54
55 var results = Rewriter.Rewrite (options);
56
57 if (results.AnyErrors) {
58 foreach (var error in results.Errors) {
59 Console.WriteLine ("Error: " + error);
60 }
61 }
62 if (results.AnyWarnings) {
63 foreach (var warning in results.Warnings) {
64 Console.WriteLine ("Warning: " + warning);
65 }
66 }
67
68 Console.WriteLine ();
69 Console.WriteLine ("*** done ***");
70 //Console.ReadKey ();
71 }
72
73 }
74 }