Browse Source

Fixed the reporting of compilation errors.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/206/head
Dimitar Dobrev 12 years ago
parent
commit
445f460b47
  1. 17
      src/AST/ASTContext.cs
  2. 4
      src/Core/Diagnostics.cs
  3. 74
      src/Generator/Driver.cs

17
src/AST/ASTContext.cs

@ -27,14 +27,17 @@ namespace CppSharp.AST
/// Finds an existing module or creates a new one given a file path. /// Finds an existing module or creates a new one given a file path.
public TranslationUnit FindOrCreateModule(string file) public TranslationUnit FindOrCreateModule(string file)
{ {
try if (!file.StartsWith("<"))
{ {
file = Path.GetFullPath(file); try
} {
catch (ArgumentException) file = Path.GetFullPath(file);
{ }
// Normalization errors are expected when dealing with virtual catch (ArgumentException)
// compiler files like <built-in>. {
// Normalization errors are expected when dealing with virtual
// compiler files like <built-in>.
}
} }
var module = TranslationUnits.Find(m => m.FilePath.Equals(file)); var module = TranslationUnits.Find(m => m.FilePath.Equals(file));

4
src/Core/Diagnostics.cs

@ -129,12 +129,12 @@ namespace CppSharp
} }
public static void EmitError(this IDiagnosticConsumer consumer, public static void EmitError(this IDiagnosticConsumer consumer,
string msg, params object[] args) string msg)
{ {
var diagInfo = new DiagnosticInfo var diagInfo = new DiagnosticInfo
{ {
Kind = DiagnosticKind.Error, Kind = DiagnosticKind.Error,
Message = string.Format(msg, args) Message = msg
}; };
consumer.Emit(diagInfo); consumer.Emit(diagInfo);

74
src/Generator/Driver.cs

@ -338,47 +338,39 @@ namespace CppSharp
public void CompileCode() public void CompileCode()
{ {
try var assemblyFile = string.IsNullOrEmpty(Options.LibraryName) ?
{ "out.dll" : Options.LibraryName + ".dll";
var assemblyFile = string.IsNullOrEmpty(Options.LibraryName) ?
"out.dll" : Options.LibraryName + ".dll"; var docFile = Path.ChangeExtension(Path.GetFileName(assemblyFile), ".xml");
var docFile = Path.ChangeExtension(Path.GetFileName(assemblyFile), ".xml"); var compilerOptions = new StringBuilder();
compilerOptions.Append(" /doc:" + docFile);
var compilerOptions = new StringBuilder(); compilerOptions.Append(" /debug:pdbonly");
compilerOptions.Append(" /doc:" + docFile); compilerOptions.Append(" /unsafe");
compilerOptions.Append(" /debug:pdbonly");
compilerOptions.Append(" /unsafe"); var compilerParameters = new CompilerParameters
{
var compilerParameters = new CompilerParameters GenerateExecutable = false,
{ TreatWarningsAsErrors = false,
GenerateExecutable = false, OutputAssembly = assemblyFile,
TreatWarningsAsErrors = false, GenerateInMemory = false,
OutputAssembly = assemblyFile, CompilerOptions = compilerOptions.ToString()
GenerateInMemory = false, };
CompilerOptions = compilerOptions.ToString()
}; compilerParameters.ReferencedAssemblies.Add(typeof (object).Assembly.Location);
var location = Assembly.GetExecutingAssembly().Location;
compilerParameters.ReferencedAssemblies.Add(typeof (object).Assembly.Location); var locationRuntime = Path.Combine(Path.GetDirectoryName(location),
var location = Assembly.GetExecutingAssembly().Location; "CppSharp.Runtime.dll");
var locationRuntime = Path.Combine(Path.GetDirectoryName(location), compilerParameters.ReferencedAssemblies.Add(locationRuntime);
"CppSharp.Runtime.dll");
compilerParameters.ReferencedAssemblies.Add(locationRuntime); var codeProvider = new CSharpCodeProvider(
new Dictionary<string, string> {{"CompilerVersion", "v4.0"}});
var codeProvider = new CSharpCodeProvider( var compilerResults = codeProvider.CompileAssemblyFromFile(
new Dictionary<string, string> {{"CompilerVersion", "v4.0"}}); compilerParameters, Options.CodeFiles.ToArray());
var compilerResults = codeProvider.CompileAssemblyFromFile(
compilerParameters, Options.CodeFiles.ToArray()); var errors = compilerResults.Errors.Cast<CompilerError>();
foreach (var error in errors.Where(error => !error.IsWarning))
var errors = compilerResults.Errors.Cast<CompilerError>(); Diagnostics.EmitError(error.ToString());
foreach (var error in errors.Where(error => !error.IsWarning))
Diagnostics.EmitError(error.ToString());
}
catch (Exception exception)
{
Diagnostics.EmitError("Could not compile the generated source code");
Diagnostics.EmitMessage(exception.ToString());
}
} }
public void AddTranslationUnitPass(TranslationUnitPass pass) public void AddTranslationUnitPass(TranslationUnitPass pass)

Loading…
Cancel
Save