2 using System
.Collections
;
3 using System
.Diagnostics
;
5 using System
.CodeDom
.Compiler
;
6 using System
.Threading
;
8 using MonoDevelop
.Core
;
9 using MonoDevelop
.Projects
;
10 using MonoDevelop
.Core
.Gui
.Components
;
12 namespace NemerleBinding
14 public class NemerleBindingCompilerServices
16 class CompilerResultsParser
: CompilerResults
18 public CompilerResultsParser() : base (new TempFileCollection ())
22 bool SetErrorType(CompilerError error
, string t
)
27 error
.IsWarning
= false;
30 error
.IsWarning
= true;
33 error
.IsWarning
= true;
40 public void Parse(string l
)
42 CompilerError error
= new CompilerError();
43 error
.ErrorNumber
= String
.Empty
;
45 char [] delim
= {':'}
;
46 string [] s
= l
.Split(delim
, 7);
50 SetErrorType (error
, s
[5]);
51 if (s
[6].StartsWith ("N") && s
[6].Contains (": "))
53 string[] e
= s
[6].Split (delim
, 2);
54 error
.ErrorNumber
= s
[0];
55 error
.ErrorText
= s
[1].Trim ();
58 error
.ErrorText
= s
[6].Trim ();
59 error
.FileName
= s
[0];
60 error
.Line
= int.Parse(s
[1]);
61 error
.Column
= int.Parse(s
[2]);
65 SetErrorType (error
, s
[0]);
66 error
.ErrorText
= s
[1].Trim ();
72 /*if (SetErrorType(error, s[5]))
74 error.ErrorText = s[6]; // l.Substring(l.IndexOf(s[0]+": ") + s[0].Length+2);
79 if ((s.Length >= 4) && SetErrorType(error, s[3].Substring(1)))
81 error.ErrorText = l.Substring(l.IndexOf(s[3]+": ") + s[3].Length+2);
82 error.FileName = s[0];
83 error.Line = int.Parse(s[1]);
84 error.Column = int.Parse(s[2]);
91 error.IsWarning = false;
96 public BuildResult
GetResult()
98 return new BuildResult(this, "");
102 static string ncc
= "ncc";
104 private string GetOptionsString (DotNetProjectConfiguration configuration
, NemerleParameters cp
)
106 string options
= " ";
108 options
+= " -no-stdmacros";
110 options
+= " -no-stdlib";
114 options
+= " -greedy";
116 options
+= " -pedantic-lexer";
117 if (configuration
.CompileTarget
== CompileTarget
.Library
)
123 public bool CanCompile(string fileName
)
125 return (System
.IO
.Path
.GetExtension(fileName
).ToLower() == ".n");
128 public BuildResult
Compile (ProjectFileCollection projectFiles
, ProjectReferenceCollection projectReferences
, DotNetProjectConfiguration configuration
, IProgressMonitor monitor
)
130 NemerleParameters cp
= (NemerleParameters
) configuration
.CompilationParameters
;
131 if (cp
== null) cp
= new NemerleParameters ();
133 string references
= "";
136 foreach (ProjectReference lib
in projectReferences
)
137 foreach (string a
in lib
.GetReferencedFileNames())
138 references
+= " -r \"" + a
+ "\"";
140 foreach (ProjectFile f
in projectFiles
)
141 if (f
.Subtype
!= Subtype
.Directory
)
142 switch (f
.BuildAction
)
144 case BuildAction
.Compile
:
145 files
+= " \"" + f
.Name
+ "\"";
149 if (!Directory
.Exists (configuration
.OutputDirectory
))
150 Directory
.CreateDirectory (configuration
.OutputDirectory
);
152 string args
= "-q -no-color " + GetOptionsString (configuration
, cp
) + references
+ files
+ " -o " + configuration
.CompiledOutputName
;
153 return DoCompilation (args
);
156 // This enables check if we have output without blocking
157 class VProcess
: Process
162 while (StandardOutput
.Peek() == -1){};
164 public void OutWatch()
166 t
= new Thread(new ThreadStart(thr
));
169 public bool HasNoOut()
175 private BuildResult
DoCompilation(string arguments
)
178 ProcessStartInfo si
= new ProcessStartInfo(ncc
, arguments
);
179 si
.RedirectStandardOutput
= true;
180 si
.RedirectStandardError
= true;
181 si
.UseShellExecute
= false;
182 VProcess p
= new VProcess();
187 while ((!p
.HasExited
) && p
.HasNoOut())
188 // while ((!p.HasExited) && (p.StandardOutput.Peek() == -1)) // this could eliminate VProcess outgrowth
190 System
.Threading
.Thread
.Sleep (100);
193 CompilerResultsParser cr
= new CompilerResultsParser();
194 while ((l
= p
.StandardOutput
.ReadLine()) != null)
199 if ((l
= p
.StandardError
.ReadLine()) != null)
201 cr
.Parse("error: " + ncc
+ " execution problem");
204 return cr
.GetResult();