Browse Source

Added error storage to IParsedFile.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
aa42b1b74b
  1. 7
      ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs
  2. 21
      ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
  3. 5
      ICSharpCode.NRefactory/CSharp/Parser/ParsedFile.cs
  4. 3
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  5. 70
      ICSharpCode.NRefactory/TypeSystem/Error.cs
  6. 5
      ICSharpCode.NRefactory/TypeSystem/IParsedFile.cs

7
ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs

@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
@ -38,6 +39,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -38,6 +39,12 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
List<Error> errors = new List<Error> ();
public List<Error> Errors {
get { return errors; }
}
public CompilationUnit ()
{
}

21
ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs

@ -694,6 +694,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -694,6 +694,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override void Visit (Indexer indexer)
{
IndexerDeclaration newIndexer = new IndexerDeclaration ();
@ -2909,17 +2910,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2909,17 +2910,22 @@ namespace ICSharpCode.NRefactory.CSharp
public class ErrorReportPrinter : ReportPrinter
{
// public readonly List<Error> Errors = new List<Error> ();
readonly string fileName;
public readonly List<Error> Errors = new List<Error> ();
public ErrorReportPrinter (string fileName)
{
this.fileName = fileName;
}
public override void Print (AbstractMessage msg)
{
Console.WriteLine (msg.MessageType + " (" + msg.Location + ")" + ": "+ msg.Text);
base.Print (msg);
// Error newError = new Error (msg.IsWarning ? ErrorType.Warning : ErrorType.Error, msg.Location.Row, msg.Location.Column, msg.Text);
// Errors.Add (newError);
var newError = new Error (msg.IsWarning ? ErrorType.Warning : ErrorType.Error, msg.Text, new DomRegion (fileName, msg.Location.Row, msg.Location.Column));
Errors.Add (newError);
}
}
ErrorReportPrinter errorReportPrinter = new ErrorReportPrinter ();
ErrorReportPrinter errorReportPrinter = new ErrorReportPrinter (null);
public ErrorReportPrinter ErrorPrinter {
get {
@ -2980,8 +2986,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2980,8 +2986,11 @@ namespace ICSharpCode.NRefactory.CSharp
public CompilationUnit Parse (Stream stream, int line = 0)
{
lock (CompilerCallableEntryPoint.parseLock) {
errorReportPrinter = new ErrorReportPrinter ("");
CompilerCompilationUnit top = CompilerCallableEntryPoint.ParseFile (new string[] { "-v", "-unsafe"}, stream, "parsed.cs", errorReportPrinter);
return Parse (top, line);
var unit = Parse (top, line);
unit.Errors.AddRange (errorReportPrinter.Errors);
return unit;
}
}

5
ICSharpCode.NRefactory/CSharp/Parser/ParsedFile.cs

@ -19,6 +19,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -19,6 +19,7 @@ namespace ICSharpCode.NRefactory.CSharp
IList<ITypeDefinition> topLevelTypeDefinitions = new List<ITypeDefinition>();
IList<IAttribute> assemblyAttributes = new List<IAttribute>();
IList<UsingScope> usingScopes = new List<UsingScope>();
IList<Error> errors = new List<Error> ();
protected override void FreezeInternal()
{
@ -47,6 +48,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -47,6 +48,10 @@ namespace ICSharpCode.NRefactory.CSharp
get { return rootUsingScope; }
}
public IList<Error> Errors {
get { return errors; }
}
public IList<UsingScope> UsingScopes {
get { return usingScopes; }
}

3
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</ProjectGuid>
@ -394,6 +394,7 @@ @@ -394,6 +394,7 @@
<Compile Include="CSharp\Refactoring\ContextAction\CreateProperty.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\RemoveBackingStore.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\GenerateGetter.cs" />
<Compile Include="TypeSystem\Error.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="CSharp\" />

70
ICSharpCode.NRefactory/TypeSystem/Error.cs

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
using System;
namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// Enum that describes the type of an error.
/// </summary>
public enum ErrorType
{
Unknown,
Error,
Warning
}
/// <summary>
/// Descibes an error during parsing.
/// </summary>
public class Error
{
/// <summary>
/// The type of the error.
/// </summary>
public ErrorType ErrorType { get; private set; }
/// <summary>
/// The error description.
/// </summary>
public string Message { get; private set; }
/// <summary>
/// The region of the error.
/// </summary>
public DomRegion Region { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.TypeSystem.Error"/> class.
/// </summary>
/// <param name='errorType'>
/// The error type.
/// </param>
/// <param name='message'>
/// The description of the error.
/// </param>
/// <param name='region'>
/// The region of the error.
/// </param>
public Error (ErrorType errorType, string message, DomRegion region)
{
this.ErrorType = errorType;
this.Message = message;
this.Region = region;
}
/// <summary>
/// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.TypeSystem.Error"/> class.
/// </summary>
/// <param name='errorType'>
/// The error type.
/// </param>
/// <param name='message'>
/// The description of the error.
/// </param>
public Error (ErrorType errorType, string message)
{
this.ErrorType = errorType;
this.Message = message;
this.Region = DomRegion.Empty;
}
}
}

5
ICSharpCode.NRefactory/TypeSystem/IParsedFile.cs

@ -49,5 +49,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -49,5 +49,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// Returns null if no member is defined at that location.
/// </summary>
IMember GetMember(AstLocation location);
/// <summary>
/// Gets the parser errors.
/// </summary>
IList<Error> Errors { get; }
}
}

Loading…
Cancel
Save