[HttpWebRequest] Support 4.0 Host property.
[mono.git] / mcs / mcs / rootcontext.cs
1 //
2 // rootcontext.cs: keeps track of our tree representation, and assemblies loaded.
3 //
4 // Author: Miguel de Icaza (miguel@ximian.com)
5 //            Ravi Pratap  (ravi@ximian.com)
6 //            Marek Safar  (marek.safar@gmail.com)
7 //
8 //
9 // Dual licensed under the terms of the MIT X11 or GNU GPL
10 //
11 // Copyright 2001 Ximian, Inc (http://www.ximian.com)
12 // Copyright 2004-2008 Novell, Inc
13
14 using System.Collections.Generic;
15 using System.IO;
16 using System.Text;
17
18 namespace Mono.CSharp {
19
20         public enum LanguageVersion
21         {
22                 ISO_1           = 1,
23                 ISO_2           = 2,
24                 V_3             = 3,
25                 V_4             = 4,
26                 Future          = 100,
27
28                 Default         = LanguageVersion.V_4,
29         }
30
31         public enum RuntimeVersion
32         {
33                 v1,
34                 v2,
35                 v4
36         }
37
38         public enum SdkVersion
39         {
40                 v2,
41                 v4
42         }
43
44         public enum Target
45         {
46                 Library, Exe, Module, WinExe
47         }
48
49         public enum Platform
50         {
51                 AnyCPU, X86, X64, IA64
52         }
53
54         public class RootContext {
55
56                 //
57                 // COMPILER OPTIONS CLASS
58                 //
59                 public static Target Target;
60                 public static Platform Platform;
61                 public static string TargetExt;
62                 public static bool VerifyClsCompliance;
63                 public static bool Optimize;
64                 public static LanguageVersion Version;
65                 public static bool EnhancedWarnings;
66                 public static bool LoadDefaultReferences;
67                 public static SdkVersion SdkVersion;
68
69                 //
70                 // We keep strongname related info here because
71                 // it's also used as complier options from CSC 8.x
72                 //
73                 public static string StrongNameKeyFile;
74                 public static string StrongNameKeyContainer;
75                 public static bool StrongNameDelaySign;
76
77                 //
78                 // Assemblies references to be loaded
79                 //
80                 public static List<string> AssemblyReferences;
81
82                 // 
83                 // External aliases for assemblies
84                 //
85                 public static List<Tuple<string, string>> AssemblyReferencesAliases;
86
87                 //
88                 // Modules to be embedded
89                 //
90                 public static List<string> Modules;
91
92                 //
93                 // Lookup paths for referenced assemblies
94                 //
95                 public static List<string> ReferencesLookupPaths;
96
97                 //
98                 // Encoding.
99                 //
100                 public static Encoding Encoding;
101
102                 //
103                 // If set, enable XML documentation generation
104                 //
105                 public static Documentation Documentation;
106
107                 static public string MainClass;
108
109                 //
110                 // Output file
111                 //
112                 static string output_file;
113                 public static string OutputFile {
114                         set {
115                                 output_file = value;
116                         }
117                         get {
118                                 return output_file;
119                         }
120                 }
121
122
123                 // 
124                 // The default compiler checked state
125                 //
126                 static public bool Checked;
127
128                 //
129                 // If true, it means that the compiler is executing as
130                 // in eval mode so unresolved variables are resolved in
131                 // static classes maintained by the eval engine.
132                 //
133                 static public bool EvalMode;
134
135                 //
136                 // If true, the compiler is operating in statement mode,
137                 // this currently turns local variable declaration into
138                 // static variables of a class
139                 //
140                 static public bool StatementMode;
141                 
142                 //
143                 // Whether to allow Unsafe code
144                 //
145                 static public bool Unsafe;
146
147                 static public string Win32ResourceFile;
148                 static public string Win32IconFile;
149
150                 //
151                 // A list of resource files for embedding
152                 //
153                 static public  List<AssemblyResource> Resources;
154
155                 static public bool GenerateDebugInfo;
156
157                 // Compiler debug flags only
158                 public static bool ParseOnly, TokenizeOnly;
159
160                 //
161                 // Whether we are being linked against the standard libraries.
162                 // This is only used to tell whether `System.Object' should
163                 // have a base class or not.
164                 //
165                 public static bool StdLib;
166
167                 public static RuntimeVersion StdLibRuntimeVersion;
168
169                 public static bool NeedsEntryPoint {
170                         get { return Target == Target.Exe || Target == Target.WinExe; }
171                 }
172
173                 //
174                 // COMPILER OPTIONS CLASS END
175                 //
176
177                 //
178                 // Contains the parsed tree
179                 //
180                 static ModuleContainer root;
181
182                 //
183                 // This hashtable contains all of the #definitions across the source code
184                 // it is used by the ConditionalAttribute handler.
185                 //
186                 static List<string> AllDefines;
187
188                 //
189                 // Constructor
190                 //
191                 static RootContext ()
192                 {
193                         Reset (true);
194                 }
195
196                 public static void PartialReset ()
197                 {
198                         Reset (false);
199                 }
200                 
201                 public static void Reset (bool full)
202                 {
203                         if (!full)
204                                 return;
205                         
206                         Checked = false;
207                         Unsafe = false;
208                         StdLib = true;
209                         StrongNameKeyFile = null;
210                         StrongNameKeyContainer = null;
211                         StrongNameDelaySign = false;
212                         MainClass = null;
213                         OutputFile = null;
214                         Target = Target.Exe;
215                         SdkVersion = SdkVersion.v2;
216                         TargetExt = ".exe";
217                         Platform = Platform.AnyCPU;
218                         Version = LanguageVersion.Default;
219                         VerifyClsCompliance = true;
220                         Optimize = true;
221                         Encoding = Encoding.Default;
222                         Documentation = null;
223                         GenerateDebugInfo = false;
224                         ParseOnly = false;
225                         TokenizeOnly = false;
226                         Win32IconFile = null;
227                         Win32ResourceFile = null;
228                         Resources = null;
229                         LoadDefaultReferences = true;
230                         AssemblyReferences = new List<string> ();
231                         AssemblyReferencesAliases = new List<Tuple<string, string>> ();
232                         Modules = new List<string> ();
233                         ReferencesLookupPaths = new List<string> ();
234                         StdLibRuntimeVersion = RuntimeVersion.v2;
235
236                         //
237                         // Setup default defines
238                         //
239                         AllDefines = new List<string> ();
240                         AddConditional ("__MonoCS__");
241                 }
242
243                 public static void AddConditional (string p)
244                 {
245                         if (AllDefines.Contains (p))
246                                 return;
247                         AllDefines.Add (p);
248                 }
249
250                 public static bool IsConditionalDefined (string value)
251                 {
252                         return AllDefines.Contains (value);
253                 }
254
255                 static public ModuleContainer ToplevelTypes {
256                         get { return root; }
257                         set { root = value; }
258                 }
259         }
260 }