46 changed files with 1539 additions and 1108 deletions
@ -1,35 +0,0 @@
@@ -1,35 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Ensures that all nodes have the Parent property correctly set.
|
||||
/// </summary>
|
||||
public class CheckParentVisitor : NodeTrackingAstVisitor |
||||
{ |
||||
Stack<INode> nodeStack = new Stack<INode>(); |
||||
|
||||
public CheckParentVisitor() |
||||
{ |
||||
nodeStack.Push(null); |
||||
} |
||||
|
||||
protected override void BeginVisit(INode node) |
||||
{ |
||||
nodeStack.Push(node); |
||||
} |
||||
|
||||
protected override void EndVisit(INode node) |
||||
{ |
||||
Assert.AreSame(node, nodeStack.Pop(), "nodeStack was corrupted!"); |
||||
Assert.AreSame(nodeStack.Peek(), node.Parent, "node " + node + " is missing parent: " + nodeStack.Peek()); |
||||
} |
||||
} |
||||
} |
@ -1,42 +0,0 @@
@@ -1,42 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class DelegateDeclarationTests |
||||
{ |
||||
void TestDelegateDeclaration(DelegateDeclaration dd) |
||||
{ |
||||
Assert.AreEqual("System.Void", dd.ReturnType.Type); |
||||
Assert.AreEqual("MyDelegate", dd.Name); |
||||
} |
||||
|
||||
void TestParameters(DelegateDeclaration dd) |
||||
{ |
||||
Assert.AreEqual(3, dd.Parameters.Count); |
||||
|
||||
Assert.AreEqual("a", ((ParameterDeclarationExpression)dd.Parameters[0]).ParameterName); |
||||
Assert.AreEqual("System.Int32", ((ParameterDeclarationExpression)dd.Parameters[0]).TypeReference.Type); |
||||
|
||||
Assert.AreEqual("secondParam", ((ParameterDeclarationExpression)dd.Parameters[1]).ParameterName); |
||||
Assert.AreEqual("System.Int32", ((ParameterDeclarationExpression)dd.Parameters[1]).TypeReference.Type); |
||||
|
||||
Assert.AreEqual("lastParam", ((ParameterDeclarationExpression)dd.Parameters[2]).ParameterName); |
||||
Assert.AreEqual("MyObj", ((ParameterDeclarationExpression)dd.Parameters[2]).TypeReference.Type); |
||||
} |
||||
|
||||
#region VB.NET
|
||||
[Test] |
||||
public void SimpleVBNetDelegateDeclarationTest() |
||||
{ |
||||
string program = "Public Delegate Sub MyDelegate(ByVal a As Integer, ByVal secondParam As Integer, ByVal lastParam As MyObj)\n"; |
||||
TestDelegateDeclaration(ParseUtil.ParseGlobal<DelegateDeclaration>(program)); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -1,87 +0,0 @@
@@ -1,87 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class OptionDeclarationTests |
||||
{ |
||||
[Test] |
||||
public void VBNetStrictOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Strict On\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.Strict, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetExplicitOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Explicit Off\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.Explicit, opDec.OptionType); |
||||
Assert.IsFalse(opDec.OptionValue, "Off option value excepted!"); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetCompareBinaryOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Compare Binary\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.CompareBinary, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetCompareTextOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Compare Text\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.CompareText, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInferOnOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Infer On\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.Infer, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInferOffOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Infer\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.Infer, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInferOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Infer\n"; |
||||
OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program); |
||||
Assert.AreEqual(OptionType.Infer, opDec.OptionType); |
||||
Assert.IsTrue(opDec.OptionValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void VBNetInvalidOptionDeclarationTest() |
||||
{ |
||||
string program = "Option\n"; |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
[TestFixture] |
||||
public class OptionStatementTests |
||||
{ |
||||
[Test] |
||||
public void VBNetStrictOptionDeclarationTest() |
||||
{ |
||||
string program = "Option Strict On\n"; |
||||
|
||||
var node = new OptionStatement { |
||||
OptionType = OptionType.Strict, |
||||
OptionValue = OptionValue.On |
||||
}; |
||||
|
||||
ParseUtil.AssertGlobal(program, node); |
||||
} |
||||
//
|
||||
// [Test]
|
||||
// public void VBNetExplicitOptionDeclarationTest()
|
||||
// {
|
||||
// string program = "Option Explicit Off\n";
|
||||
// OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program);
|
||||
// Assert.AreEqual(OptionType.Explicit, opDec.OptionType);
|
||||
// Assert.IsFalse(opDec.OptionValue, "Off option value excepted!");
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetCompareBinaryOptionDeclarationTest()
|
||||
// {
|
||||
// string program = "Option Compare Binary\n";
|
||||
// OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program);
|
||||
// Assert.AreEqual(OptionType.CompareBinary, opDec.OptionType);
|
||||
// Assert.IsTrue(opDec.OptionValue);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetCompareTextOptionDeclarationTest()
|
||||
// {
|
||||
// string program = "Option Compare Text\n";
|
||||
// OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program);
|
||||
// Assert.AreEqual(OptionType.CompareText, opDec.OptionType);
|
||||
// Assert.IsTrue(opDec.OptionValue);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetInferOnOptionDeclarationTest()
|
||||
// {
|
||||
// string program = "Option Infer On\n";
|
||||
// OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program);
|
||||
// Assert.AreEqual(OptionType.Infer, opDec.OptionType);
|
||||
// Assert.IsTrue(opDec.OptionValue);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetInferOffOptionDeclarationTest()
|
||||
// {
|
||||
// string program = "Option Infer\n";
|
||||
// OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program);
|
||||
// Assert.AreEqual(OptionType.Infer, opDec.OptionType);
|
||||
// Assert.IsTrue(opDec.OptionValue);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetInferOptionDeclarationTest()
|
||||
// {
|
||||
// string program = "Option Infer\n";
|
||||
// OptionDeclaration opDec = ParseUtil.ParseGlobal<OptionDeclaration>(program);
|
||||
// Assert.AreEqual(OptionType.Infer, opDec.OptionType);
|
||||
// Assert.IsTrue(opDec.OptionValue);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void VBNetInvalidOptionDeclarationTest()
|
||||
// {
|
||||
// string program = "Option\n";
|
||||
// VBParser parser = ParserFactory.CreateParser(new StringReader(program));
|
||||
// parser.Parse();
|
||||
// Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully");
|
||||
// }
|
||||
} |
||||
} |
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Ast |
||||
{ |
||||
public class LocationAssignmentCheckVisitor : NodeTrackingAstVisitor |
||||
{ |
||||
protected override void BeginVisit(INode node) |
||||
{ |
||||
if (node is CompilationUnit) |
||||
return; |
||||
if (node is INullable && ((INullable)node).IsNull) |
||||
return; |
||||
if (node is TypeReference) |
||||
return; |
||||
|
||||
Assert.IsFalse(node.StartLocation.IsEmpty, "StartLocation of {0}", node); |
||||
Assert.IsFalse(node.EndLocation.IsEmpty, "EndLocation of {0}", node); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// Description of XmlIdentifier.
|
||||
/// </summary>
|
||||
public class XmlIdentifier : AstNode |
||||
{ |
||||
public static readonly new XmlIdentifier Null = new NullXmlIdentifier(); |
||||
|
||||
class NullXmlIdentifier : XmlIdentifier |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default(S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
|
||||
public string Name { get; set; } |
||||
|
||||
AstLocation startLocation; |
||||
public override AstLocation StartLocation { |
||||
get { return startLocation; } |
||||
} |
||||
|
||||
public override AstLocation EndLocation { |
||||
get { return new AstLocation(startLocation.Line, startLocation.Column + Name.Length); } |
||||
} |
||||
|
||||
private XmlIdentifier() |
||||
{ |
||||
this.Name = string.Empty; |
||||
} |
||||
|
||||
public XmlIdentifier(string name, AstLocation startLocation) |
||||
{ |
||||
this.Name = name; |
||||
this.startLocation = startLocation; |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var ident = other as XmlIdentifier; |
||||
return ident != null |
||||
&& MatchString(Name, ident.Name) |
||||
&& ident.startLocation == startLocation; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitXmlIdentifier(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
public class AttributeBlock : AstNode |
||||
{ |
||||
public readonly static Role<AttributeBlock> AttributeBlockRole = new Role<AttributeBlock>("AttributeBlock"); |
||||
|
||||
public VBTokenNode LChevron { |
||||
get { return GetChildByRole(Roles.LChevron); } |
||||
} |
||||
|
||||
public AstNodeCollection<Attribute> Attributes { |
||||
get { return GetChildrenByRole(Attribute.AttributeRole); } |
||||
} |
||||
|
||||
public VBTokenNode RChevron { |
||||
get { return GetChildByRole(Roles.RChevron); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
var node = other as AttributeBlock; |
||||
return node != null && Attributes.DoMatch(node.Attributes, match); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAttributeBlock(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,145 @@
@@ -0,0 +1,145 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Ast |
||||
{ |
||||
/// <summary>
|
||||
/// A type reference in the VB AST.
|
||||
/// </summary>
|
||||
public abstract class AstType : AstNode |
||||
{ |
||||
#region Null
|
||||
public new static readonly AstType Null = new NullAstType(); |
||||
|
||||
sealed class NullAstType : AstType |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return default (S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator AstType(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : AstType, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public virtual AstType MakeArrayType(int rank = 1) |
||||
{ |
||||
return new ComposedType { BaseType = this }.MakeArrayType(rank); |
||||
} |
||||
|
||||
// TODO : reimplement this
|
||||
// /// <summary>
|
||||
// /// Builds an expression that can be used to access a static member on this type.
|
||||
// /// </summary>
|
||||
// public MemberReferenceExpression Member(string memberName)
|
||||
// {
|
||||
// return new TypeReferenceExpression { Type = this }.Member(memberName);
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Builds an invocation expression using this type as target.
|
||||
// /// </summary>
|
||||
// public InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments)
|
||||
// {
|
||||
// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Builds an invocation expression using this type as target.
|
||||
// /// </summary>
|
||||
// public InvocationExpression Invoke(string methodName, params Expression[] arguments)
|
||||
// {
|
||||
// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Builds an invocation expression using this type as target.
|
||||
// /// </summary>
|
||||
// public InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments)
|
||||
// {
|
||||
// return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments);
|
||||
// }
|
||||
|
||||
public static AstType Create(Type type) |
||||
{ |
||||
switch (Type.GetTypeCode(type)) { |
||||
case TypeCode.Object: |
||||
return new PrimitiveType("Object"); |
||||
case TypeCode.Boolean: |
||||
return new PrimitiveType("Boolean"); |
||||
case TypeCode.Char: |
||||
return new PrimitiveType("Char"); |
||||
case TypeCode.SByte: |
||||
return new PrimitiveType("SByte"); |
||||
case TypeCode.Byte: |
||||
return new PrimitiveType("Byte"); |
||||
case TypeCode.Int16: |
||||
return new PrimitiveType("Short"); |
||||
case TypeCode.UInt16: |
||||
return new PrimitiveType("UShort"); |
||||
case TypeCode.Int32: |
||||
return new PrimitiveType("Integer"); |
||||
case TypeCode.UInt32: |
||||
return new PrimitiveType("UInteger"); |
||||
case TypeCode.Int64: |
||||
return new PrimitiveType("Long"); |
||||
case TypeCode.UInt64: |
||||
return new PrimitiveType("ULong"); |
||||
case TypeCode.Single: |
||||
return new PrimitiveType("Single"); |
||||
case TypeCode.Double: |
||||
return new PrimitiveType("Double"); |
||||
case TypeCode.Decimal: |
||||
return new PrimitiveType("Decimal"); |
||||
case TypeCode.String: |
||||
return new PrimitiveType("String"); |
||||
case TypeCode.DateTime: |
||||
return new PrimitiveType("Date"); |
||||
} |
||||
return new SimpleType(type.FullName); // TODO: implement this correctly
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// Output formatter for the Output visitor.
|
||||
/// </summary>
|
||||
public interface IOutputFormatter |
||||
{ |
||||
void StartNode(AstNode node); |
||||
void EndNode(AstNode node); |
||||
|
||||
/// <summary>
|
||||
/// Writes an identifier.
|
||||
/// If the identifier conflicts with a keyword, the output visitor will
|
||||
/// call <c>WriteToken("@")</c> before calling WriteIdentifier().
|
||||
/// </summary>
|
||||
void WriteIdentifier(string identifier); |
||||
|
||||
/// <summary>
|
||||
/// Writes a keyword to the output.
|
||||
/// </summary>
|
||||
void WriteKeyword(string keyword); |
||||
|
||||
/// <summary>
|
||||
/// Writes a token to the output.
|
||||
/// </summary>
|
||||
void WriteToken(string token); |
||||
void Space(); |
||||
|
||||
void Indent(); |
||||
void Unindent(); |
||||
|
||||
void NewLine(); |
||||
} |
||||
} |
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
|
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// Description of OutputVisitor.
|
||||
/// </summary>
|
||||
public class OutputVisitor : IAstVisitor<object, object>, IPatternAstVisitor<object, object> |
||||
{ |
||||
readonly IOutputFormatter formatter; |
||||
readonly VBFormattingOptions policy; |
||||
|
||||
readonly Stack<AstNode> containerStack = new Stack<AstNode>(); |
||||
readonly Stack<AstNode> positionStack = new Stack<AstNode>(); |
||||
|
||||
public OutputVisitor(TextWriter textWriter, VBFormattingOptions formattingPolicy) |
||||
{ |
||||
if (textWriter == null) |
||||
throw new ArgumentNullException("textWriter"); |
||||
if (formattingPolicy == null) |
||||
throw new ArgumentNullException("formattingPolicy"); |
||||
this.formatter = new TextWriterOutputFormatter(textWriter); |
||||
this.policy = formattingPolicy; |
||||
} |
||||
|
||||
public OutputVisitor(IOutputFormatter formatter, VBFormattingOptions formattingPolicy) |
||||
{ |
||||
if (formatter == null) |
||||
throw new ArgumentNullException("formatter"); |
||||
if (formattingPolicy == null) |
||||
throw new ArgumentNullException("formattingPolicy"); |
||||
this.formatter = formatter; |
||||
this.policy = formattingPolicy; |
||||
} |
||||
|
||||
public object VisitPatternPlaceholder(AstNode placeholder, Pattern pattern, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitVBTokenNode(ICSharpCode.NRefactory.VB.Ast.VBTokenNode vBTokenNode, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitCompilationUnit(ICSharpCode.NRefactory.VB.Ast.CompilationUnit compilationUnit, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitBlockStatement(ICSharpCode.NRefactory.VB.Ast.BlockStatement blockStatement, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitOptionStatement(ICSharpCode.NRefactory.VB.Ast.OptionStatement optionStatement, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitImportsStatement(ICSharpCode.NRefactory.VB.Ast.ImportsStatement importsStatement, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitAliasImportsClause(ICSharpCode.NRefactory.VB.Ast.AliasImportsClause aliasImportsClause, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitMembersImportsClause(ICSharpCode.NRefactory.VB.Ast.MemberImportsClause membersImportsClause, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitXmlNamespaceImportsClause(ICSharpCode.NRefactory.VB.Ast.XmlNamespaceImportsClause xmlNamespaceImportsClause, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitAttribute(ICSharpCode.NRefactory.VB.Ast.Attribute attribute, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitAttributeBlock(ICSharpCode.NRefactory.VB.Ast.AttributeBlock attributeBlock, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitIdentifier(ICSharpCode.NRefactory.VB.Ast.Identifier identifier, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitXmlIdentifier(ICSharpCode.NRefactory.VB.Ast.XmlIdentifier xmlIdentifier, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitSimpleNameExpression(ICSharpCode.NRefactory.VB.Ast.SimpleNameExpression identifierExpression, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitPrimitiveExpression(ICSharpCode.NRefactory.VB.Ast.PrimitiveExpression primitiveExpression, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitPrimitiveType(ICSharpCode.NRefactory.VB.Ast.PrimitiveType primitiveType, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitComposedType(ICSharpCode.NRefactory.VB.Ast.ComposedType composedType, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitArraySpecifier(ICSharpCode.NRefactory.VB.Ast.ArraySpecifier arraySpecifier, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitSimpleType(ICSharpCode.NRefactory.VB.Ast.SimpleType simpleType, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitAnyNode(AnyNode anyNode, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitBackreference(Backreference backreference, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitChoice(Choice choice, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitNamedNode(NamedNode namedNode, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitRepeat(Repeat repeat, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitOptionalNode(OptionalNode optionalNode, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object VisitIdentifierExpressionBackreference(IdentifierExpressionBackreference identifierExpressionBackreference, object data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// Writes VB code into a TextWriter.
|
||||
/// </summary>
|
||||
public class TextWriterOutputFormatter : IOutputFormatter |
||||
{ |
||||
readonly TextWriter textWriter; |
||||
int indentation; |
||||
bool needsIndent = true; |
||||
|
||||
public TextWriterOutputFormatter(TextWriter textWriter) |
||||
{ |
||||
if (textWriter == null) |
||||
throw new ArgumentNullException("textWriter"); |
||||
this.textWriter = textWriter; |
||||
} |
||||
|
||||
public void WriteIdentifier(string ident) |
||||
{ |
||||
WriteIndentation(); |
||||
textWriter.Write(ident); |
||||
} |
||||
|
||||
public void WriteKeyword(string keyword) |
||||
{ |
||||
WriteIndentation(); |
||||
textWriter.Write(keyword); |
||||
} |
||||
|
||||
public void WriteToken(string token) |
||||
{ |
||||
WriteIndentation(); |
||||
textWriter.Write(token); |
||||
} |
||||
|
||||
public void Space() |
||||
{ |
||||
WriteIndentation(); |
||||
textWriter.Write(' '); |
||||
} |
||||
|
||||
void WriteIndentation() |
||||
{ |
||||
if (needsIndent) { |
||||
needsIndent = false; |
||||
for (int i = 0; i < indentation; i++) { |
||||
textWriter.Write('\t'); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void NewLine() |
||||
{ |
||||
textWriter.WriteLine(); |
||||
needsIndent = true; |
||||
} |
||||
|
||||
public void Indent() |
||||
{ |
||||
indentation++; |
||||
} |
||||
|
||||
public void Unindent() |
||||
{ |
||||
indentation--; |
||||
} |
||||
|
||||
public virtual void StartNode(AstNode node) |
||||
{ |
||||
} |
||||
|
||||
public virtual void EndNode(AstNode node) |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// Description of VBFormattingOptions.
|
||||
/// </summary>
|
||||
public class VBFormattingOptions |
||||
{ |
||||
public VBFormattingOptions() |
||||
{ |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue