Browse Source

Added some Parse methods to the compilation unit.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
196e6184d6
  1. 47
      ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs
  2. 2
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

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

@ -28,6 +28,10 @@ using System.Collections.Generic; @@ -28,6 +28,10 @@ using System.Collections.Generic;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
using Mono.CSharp;
using System.IO;
using ICSharpCode.NRefactory.Editor;
namespace ICSharpCode.NRefactory.CSharp
{
@ -108,14 +112,45 @@ namespace ICSharpCode.NRefactory.CSharp @@ -108,14 +112,45 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// Converts this compilation unit into a parsed file that can be stored in the type system.
/// </summary>
public CSharpParsedFile ToTypeSystem()
public CSharpParsedFile ToTypeSystem ()
{
if (string.IsNullOrEmpty(this.FileName))
throw new InvalidOperationException("Cannot use ToTypeSystem() on a compilation unit without file name.");
var v = new TypeSystemConvertVisitor(this.FileName);
v.VisitCompilationUnit(this, null);
if (string.IsNullOrEmpty (this.FileName))
throw new InvalidOperationException ("Cannot use ToTypeSystem() on a compilation unit without file name.");
var v = new TypeSystemConvertVisitor (this.FileName);
v.VisitCompilationUnit (this, null);
return v.ParsedFile;
}
public static CompilationUnit Parse (string text, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
var parser = new CSharpParser ();
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (text, fileName);
}
public static CompilationUnit Parse (TextReader reader, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
var parser = new CSharpParser ();
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (reader, fileName, 0);
}
public static CompilationUnit Parse (Stream stream, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
var parser = new CSharpParser ();
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (stream, fileName, 0);
}
public static CompilationUnit Parse (ITextSource textSource, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
var parser = new CSharpParser ();
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (textSource, fileName, 0);
}
}
}

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

@ -3634,7 +3634,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -3634,7 +3634,7 @@ namespace ICSharpCode.NRefactory.CSharp
public CompilerSettings CompilerSettings {
get;
private set;
internal set;
}
public Action<CompilerCompilationUnit> CompilationUnitCallback {

Loading…
Cancel
Save