[sgen] Untag the vtable during concurrent mark
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / Vbc.cs
1 //
2 // UpdateManifest.cs
3 //
4 // Author:
5 //      Leszek Ciesielski  <skolima@gmail.com>
6 //      Marek Sieradzki  <marek.sieradzki@gmail.com>
7 //
8 // Copyright (C) 2006 Forcom (http://www.forcom.com.pl/)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29
30 using System;
31 using System.IO;
32 using System.Text;
33 using System.Text.RegularExpressions;
34
35 using Microsoft.Build.Framework;
36 using Microsoft.Build.Utilities;
37 using Mono.XBuild.Utilities;
38
39 namespace Microsoft.Build.Tasks {
40
41         public class Vbc : ManagedCompiler {
42
43                 public Vbc ()
44                 {
45                 }
46
47                 [MonoTODO]
48                 protected internal override void AddResponseFileCommands (
49                                 CommandLineBuilderExtension commandLine )
50                 {
51                         base.AddResponseFileCommands (commandLine);
52
53                         commandLine.AppendSwitchIfNotNull ("/libpath:", AdditionalLibPaths, ",");
54
55                         commandLine.AppendSwitchIfNotNull ("/baseaddress:", BaseAddress);
56
57                         if (DefineConstants != null)
58                                 commandLine.AppendSwitchUnquotedIfNotNull ("/define:",
59                                                 String.Format ("\"{0}\"", EscapeDoubleQuotes (DefineConstants)));
60
61                         // DisabledWarnings
62
63                         commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
64
65                         // ErrorReport
66                         
67                         // GenerateDocumentation
68                         
69                         if (Imports != null)
70                                 foreach (ITaskItem item in Imports)
71                                         commandLine.AppendSwitchIfNotNull ("/imports:", item.ItemSpec);
72                         
73                         commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
74
75                         // NoStandardLib
76                         if (Bag ["NoStandardLib"] != null && NoStandardLib)
77                                 commandLine.AppendSwitch ("/nostdlib");
78                         
79                         if (NoWarnings)
80                                 commandLine.AppendSwitch ("/nowarn");
81
82                         commandLine.AppendSwitchIfNotNull ("/optioncompare:", OptionCompare);
83
84                         if (Bag ["OptionExplicit"] != null)
85                                 if (OptionExplicit)
86                                         commandLine.AppendSwitch ("/optionexplicit+");
87                                 else
88                                         commandLine.AppendSwitch ("/optionexplicit-");
89
90                         if (Bag ["OptionStrict"] != null)
91                                 if (OptionStrict)
92                                         commandLine.AppendSwitch ("/optionstrict+");
93                                 else
94                                         commandLine.AppendSwitch ("/optionstrict-");
95
96                         if (Bag ["OptionInfer"] != null)
97                                 if (OptionInfer)
98                                         commandLine.AppendSwitch ("/optioninfer+");
99                                 else
100                                         commandLine.AppendSwitch ("/optioninfer-");
101
102                         // OptionStrictType
103                         
104                         // Platform
105                         
106                         if (References != null)
107                                 foreach (ITaskItem item in References)
108                                         commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
109         
110                         if (Bag ["RemoveIntegerChecks"] != null)
111                                 if (RemoveIntegerChecks)
112                                         commandLine.AppendSwitch ("/removeintchecks+");
113                                 else
114                                         commandLine.AppendSwitch ("/removeintchecks-");
115
116                         if (ResponseFiles != null)
117                                 foreach (ITaskItem item in ResponseFiles)
118                                         commandLine.AppendFileNameIfNotNull (String.Format ("@{0}", item.ItemSpec));
119
120                         commandLine.AppendSwitchIfNotNull ("/rootnamespace:", RootNamespace);
121
122                         commandLine.AppendSwitchIfNotNull ("/sdkpath:", SdkPath);
123
124                         // TargetCompactFramework
125
126                         if (String.Compare (VBRuntime, "Embed", StringComparison.OrdinalIgnoreCase) == 0) 
127                                 commandLine.AppendSwitch ("/vbruntime*");
128                         
129                         // Verbosity
130
131                         // WarningsAsErrors
132
133                         // WarningsNotAsErrors
134
135                 }
136
137                 string EscapeDoubleQuotes (string text)
138                 {
139                         if (text == null)
140                                 return null;
141
142                         return text.Replace ("\"", "\\\"");
143                 }
144                 
145                 [MonoTODO]
146                 protected override bool CallHostObjectToExecute ()
147                 {
148                         throw new NotImplementedException ();
149                 }
150                 
151                 [MonoTODO]
152                 protected override string GenerateFullPathToTool ()
153                 {
154                         if (!string.IsNullOrEmpty (ToolPath))
155                                 return Path.Combine (ToolPath, ToolExe);
156                         return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
157                 }
158                 
159                 [MonoTODO]
160                 protected override HostObjectInitializationStatus InitializeHostObject ()
161                 {
162                         throw new NotImplementedException ();
163                 }
164
165                 [MonoTODO]
166                 protected override bool ValidateParameters ()
167                 {
168                         return true;
169                 }
170
171                 protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
172                 {
173                         singleLine = singleLine.Trim ();
174                         if (singleLine.Length == 0)
175                                 return;
176
177                         // When IncludeDebugInformation is true, prevents the debug symbols stats from braeking this.
178                         if (singleLine.StartsWith ("WROTE SYMFILE") ||
179                                 singleLine.StartsWith ("OffsetTable") ||
180                                 singleLine.StartsWith ("Compilation succeeded") ||
181                                 singleLine.StartsWith ("Compilation failed"))
182                                 return;
183
184                         Match match = ErrorRegex.Match (singleLine);
185                         if (!match.Success) {
186                                 Log.LogMessage (messageImportance, singleLine);
187                                 return;
188                         }
189
190                         string filename = match.Result ("${file}") ?? "";
191
192                         string line = match.Result ("${line}");
193                         int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0;
194
195                         string col = match.Result ("${column}");
196                         int columnNumber = 0;
197                         if (!string.IsNullOrEmpty (col))
198                                 columnNumber = col.IndexOf ("+") >= 0 ? -1 : Int32.Parse (col);
199
200                         string category = match.Result ("${level}");
201                         string code = match.Result ("${number}");
202                         string text = match.Result ("${message}");
203
204                         if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) {
205                                 Log.LogWarning (null, code, null, filename, lineNumber, columnNumber, -1,
206                                         -1, text, null);
207                         } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) {
208                                 Log.LogError (null, code, null, filename, lineNumber, columnNumber, -1,
209                                         -1, text, null);
210                         } else {
211                                 Log.LogMessage (messageImportance, singleLine);
212                         }
213                 }
214
215                 [MonoTODO]
216                 public string BaseAddress {
217                         get { return (string) Bag ["BaseAddress"]; }
218                         set { Bag ["BaseAddress"] = value; }
219                 }
220                 
221                 [MonoTODO]
222                 public string DisabledWarnings  {
223                         get { return (string) Bag ["DisabledWarnings"]; }
224                         set { Bag ["DisabledWarnings"] = value; }
225                 }
226                 
227                 [MonoTODO]
228                 public string DocumentationFile {
229                         get { return (string) Bag ["DocumentationFile"]; }
230                         set { Bag ["DocumentationFile"] = value; }
231                 }
232                 
233                 [MonoTODO]
234                 public string ErrorReport {
235                         get { return (string) Bag ["ErrorReport"]; }
236                         set { Bag ["ErrorReport"] = value; }
237                 }
238                 
239                 [MonoTODO]
240                 public bool GenerateDocumentation {
241                         get { return GetBoolParameterWithDefault ("GenerateDocumentation", false); }
242                         set { Bag ["GenerateDocumentation"] = value; }
243                 }
244                 
245                 [MonoTODO]
246                 public ITaskItem [] Imports {
247                         get { return (ITaskItem []) Bag ["Imports"]; }
248                         set { Bag ["Imports"] = value; }
249                 }
250                 
251                 [MonoTODO]
252                 public bool NoStandardLib {
253                         get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
254                         set { Bag ["NoStandardLib"] = value; }
255                 }
256                 
257                 [MonoTODO]
258                 public bool NoWarnings {
259                         get { return GetBoolParameterWithDefault ("NoWarnings", false); }
260                         set { Bag ["NoWarnings"] = value; }
261                 }
262                 
263                 [MonoTODO]
264                 public string OptionCompare {
265                         get { return (string) Bag ["OptionCompare"]; }
266                         set { Bag ["OptionCompare"] = value; }
267                 }
268                 
269                 [MonoTODO]
270                 public bool OptionExplicit {
271                         get { return GetBoolParameterWithDefault ("OptionExplicit", false); }
272                         set { Bag ["OpExplicit"] = value; }
273                 }
274                 
275                 [MonoTODO]
276                 public bool OptionStrict {
277                         get { return GetBoolParameterWithDefault ("OptionStrict", false); }
278                         set { Bag ["OptionStrict"] = value; }
279                 }
280                 
281                 [MonoTODO]
282                 public string OptionStrictType {
283                         get { return (string) Bag ["OptionStrictType"]; }
284                         set { Bag ["OptionStrictType"] = value; }
285                 }
286
287                 [MonoTODO]
288                 public bool OptionInfer {
289                         get { return GetBoolParameterWithDefault ("OptionInfer", false); }
290                         set { Bag ["OptionInfer"] = value; }
291                 }
292                 
293                 [MonoTODO]
294                 public string Platform {
295                         get { return (string) Bag ["Platfrom"]; }
296                         set { Bag ["Platform"] = value; }
297                 }
298                 
299                 [MonoTODO]
300                 public bool RemoveIntegerChecks {
301                         get { return GetBoolParameterWithDefault ("RemoveIntegerChecks", false); }
302                         set { Bag ["RemoveIntegerChecks"] = value; }
303                 }
304
305                 [MonoTODO]
306                 public string RootNamespace {
307                         get { return (string) Bag ["RootNamespace"]; }
308                         set { Bag ["RootNamespace"] = value; }
309                 }
310
311                 [MonoTODO]
312                 public string SdkPath {
313                         get { return (string) Bag ["SdkPath"]; }
314                         set { Bag ["SdkPath"] = value; }
315                 }
316
317                 [MonoTODO]
318                 public bool TargetCompactFramework {
319                         get { return (bool) Bag ["TargetCompactFramework"]; }
320                         set { Bag ["TargetCompactFramework"] = value; }
321                 }
322
323                 [MonoTODO]
324                 protected override string ToolName {
325                         get {
326                                 return MSBuildUtils.RunningOnWindows ? "vbnc.bat" : "vbnc";
327                         }
328                 }
329
330                 [MonoTODO]
331                 public bool UseHostCompilerIfAvailable {
332                         get { return (bool) Bag ["UseHostCompilerIfAvailable"]; }
333                         set { Bag ["UseHostCompilerIfAvailable"] = value; }
334                 }
335
336                 [MonoTODO]
337                 public string VBRuntime {
338                         get { return (string) Bag ["VBRuntime"]; }
339                         set { Bag ["VBRuntime"] = value; }
340                 }
341
342                 [MonoTODO]
343                 public string Verbosity {
344                         get { return (string) Bag ["Verbosity"]; }
345                         set { Bag ["Verbosity"] = value; }
346                 }
347
348                 [MonoTODO]
349                 public string WarningsAsErrors {
350                         get { return (string) Bag ["WarningsAsErrors"]; }
351                         set { Bag ["WarningsAsErrors"] = value; }
352                 }
353                 
354                 [MonoTODO]
355                 public string WarningsNotAsErrors {
356                         get { return (string) Bag ["WarningsNotAsErrors"]; }
357                         set { Bag ["WarningsNotAsErrors"] = value; }
358                 }
359
360                 // from md's VBBindingCompilerServices.cs
361                 //matches "/home/path/Default.aspx.vb (40,31) : Error VBNC30205: Expected end of statement."
362                 //and "Error : VBNC99999: vbnc crashed nearby this location in the source code."
363                 //and "Error : VBNC99999: Unexpected error: Object reference not set to an instance of an object"
364                 static Regex errorRegex;
365                 static Regex ErrorRegex {
366                         get {
367                                 if (errorRegex == null)
368                                         errorRegex = new Regex (@"^\s*((?<file>.*)\s?\((?<line>\d*)(,(?<column>\d*))?\) : )?(?<level>\w+) :? ?(?<number>[^:]*): (?<message>.*)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
369                                 return errorRegex;
370                         }
371                 }
372
373         }
374 }
375