Browse Source

Added the ability to specify parser arguments & provided a compiler

callback (for getting pre processor directives etc).
TODO: Move pre processor directives in the AST.
newNRvisualizers
Mike Krüger 15 years ago
parent
commit
33d588b371
  1. 28
      ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs

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

@ -64,6 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -64,6 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp
return new AstLocation (loc.Row, loc.Column);
}
#region Global
Stack<NamespaceDeclaration> namespaceStack = new Stack<NamespaceDeclaration> ();
@ -694,7 +695,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -694,7 +695,6 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override void Visit (Indexer indexer)
{
IndexerDeclaration newIndexer = new IndexerDeclaration ();
@ -2858,7 +2858,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2858,7 +2858,17 @@ namespace ICSharpCode.NRefactory.CSharp
}
#endregion
}
public CSharpParser ()
{
CompilerArguments = new string[] { "-v", "-unsafe"};
}
public CSharpParser (string[] args)
{
CompilerArguments = args;
}
public static void InsertComment (AstNode node, Comment comment)
{
if (node.EndLocation < comment.StartLocation) {
@ -2978,16 +2988,28 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2978,16 +2988,28 @@ namespace ICSharpCode.NRefactory.CSharp
conversionVisitor.AddAttributeSection (conversionVisitor.Unit, top.ModuleCompiled);
top.UsingsBag.Global.Accept (conversionVisitor);
InsertComments (top, conversionVisitor);
if (CompilationUnitCallback != null)
CompilationUnitCallback (top);
if (line != 0)
AdjustLineLocations (conversionVisitor.Unit, line);
return conversionVisitor.Unit;
}
public string[] CompilerArguments {
get;
private set;
}
public Action<CompilerCompilationUnit> CompilationUnitCallback {
get;
set;
}
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);
CompilerCompilationUnit top = CompilerCallableEntryPoint.ParseFile (CompilerArguments, stream, "parsed.cs", errorReportPrinter);
var unit = Parse (top, line);
unit.Errors.AddRange (errorReportPrinter.Errors);
return unit;

Loading…
Cancel
Save