diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs
index 5a6dbb3d5f..b26ec73bb0 100644
--- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs
+++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs
@@ -312,6 +312,42 @@ namespace ICSharpCode.NRefactory.VB.Ast
}
}
+ ///
+ /// Identifier As Type = Expression
+ ///
+ public class VariableInitializer : AstNode
+ {
+ public VariableIdentifier Identifier {
+ get { return GetChildByRole(VariableIdentifier.VariableIdentifierRole); }
+ set { SetChildByRole(VariableIdentifier.VariableIdentifierRole, value); }
+ }
+
+ public AstType Type {
+ get { return GetChildByRole(Roles.Type); }
+ set { SetChildByRole(Roles.Type, value); }
+ }
+
+ public VBTokenNode AssignToken {
+ get { return GetChildByRole (Roles.Assign); }
+ }
+
+ public Expression Expression {
+ get { return GetChildByRole (Roles.Expression); }
+ set { SetChildByRole (Roles.Expression, value); }
+ }
+
+ public override S AcceptVisitor(IAstVisitor visitor, T data)
+ {
+ return visitor.VisitVariableInitializer(this, data);
+ }
+
+ protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
+ {
+ VariableInitializer o = other as VariableInitializer;
+ return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match);
+ }
+ }
+
///
/// [ Key ] .Identifier = Expression
///
diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs
index 5f9532d146..7c0cd90b14 100644
--- a/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs
+++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs
@@ -8,11 +8,11 @@ namespace ICSharpCode.NRefactory.VB.Ast
{
public class ForEachStatement : Statement
{
- public static readonly Role InitializerRole = new Role("InitializerRole", Statement.Null);
+ public static readonly Role VariableRole = new Role("Variable", AstNode.Null);
- public Statement Initializer {
- get { return GetChildByRole(InitializerRole); }
- set { SetChildByRole(InitializerRole, value); }
+ public AstNode Variable {
+ get { return GetChildByRole(VariableRole); }
+ set { SetChildByRole(VariableRole, value); }
}
public Expression InExpression {
diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs
index f4abbebff9..c28ea0fd56 100644
--- a/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs
+++ b/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs
@@ -8,6 +8,30 @@ namespace ICSharpCode.NRefactory.VB.Ast
{
public class ForStatement : Statement
{
+ public static readonly Role VariableRole = new Role("Variable", AstNode.Null);
+ public static readonly Role ToExpressionRole = new Role("ToExpression", Expression.Null);
+ public static readonly Role StepExpressionRole = new Role("StepExpression", Expression.Null);
+
+ public AstNode Variable {
+ get { return GetChildByRole(VariableRole); }
+ set { SetChildByRole(VariableRole, value); }
+ }
+
+ public Expression ToExpression {
+ get { return GetChildByRole(ToExpressionRole); }
+ set { SetChildByRole(ToExpressionRole, value); }
+ }
+
+ public Expression StepExpression {
+ get { return GetChildByRole(StepExpressionRole); }
+ set { SetChildByRole(StepExpressionRole, value); }
+ }
+
+ public BlockStatement Body {
+ get { return GetChildByRole(Roles.Body); }
+ set { SetChildByRole(Roles.Body, value); }
+ }
+
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
{
throw new NotImplementedException();
diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs
index 95b576fd7e..21de4c435d 100644
--- a/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs
+++ b/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs
@@ -13,6 +13,10 @@ namespace ICSharpCode.NRefactory.VB.Ast
set { SetChildByRole(Roles.Expression, value); }
}
+ public AstNodeCollection Cases {
+ get { return GetChildrenByRole(CaseStatement.CaseStatementRole); }
+ }
+
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
{
throw new NotImplementedException();
@@ -26,7 +30,7 @@ namespace ICSharpCode.NRefactory.VB.Ast
public class CaseStatement : Statement
{
-
+ public static readonly Role CaseStatementRole = new Role("CaseStatement");
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
{
diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs
index fa093e0457..e9679da636 100644
--- a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs
+++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs
@@ -25,38 +25,7 @@ namespace ICSharpCode.NRefactory.VB.Ast
}
}
- ///
- /// VariableIdentifiers As ObjectCreationExpression
- /// VariableIdentifiers ( As TypeName )? ( Equals Expression )?
- ///
- public class VariableDeclarator : AstNode
- {
- public static readonly Role VariableDeclaratorRole = new Role("VariableDeclarator");
-
- public AstNodeCollection Identifiers {
- get { return GetChildrenByRole(VariableIdentifier.VariableIdentifierRole); }
- }
-
- public AstType Type {
- get { return GetChildByRole(Roles.Type); }
- set { SetChildByRole(Roles.Type, value); }
- }
-
- public Expression Initializer {
- get { return GetChildByRole(Roles.Expression); }
- set { SetChildByRole(Roles.Expression, value); }
- }
-
- protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
- {
- throw new NotImplementedException();
- }
-
- public override S AcceptVisitor(IAstVisitor visitor, T data)
- {
- return visitor.VisitVariableDeclarator(this, data);
- }
- }
+
///
/// Identifier IdentifierModifiers
diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs
new file mode 100644
index 0000000000..94227bdc7d
--- /dev/null
+++ b/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs
@@ -0,0 +1,63 @@
+// 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
+{
+ ///
+ /// VariableIdentifiers As ObjectCreationExpression
+ /// VariableIdentifiers ( As TypeName )? ( Equals Expression )?
+ ///
+ public abstract class VariableDeclarator : AstNode
+ {
+ public static readonly Role VariableDeclaratorRole = new Role("VariableDeclarator");
+
+ public AstNodeCollection Identifiers {
+ get { return GetChildrenByRole(VariableIdentifier.VariableIdentifierRole); }
+ }
+ }
+
+ public class VariableDeclaratorWithTypeAndInitializer : VariableDeclarator
+ {
+ public AstType Type {
+ get { return GetChildByRole(Roles.Type); }
+ set { SetChildByRole(Roles.Type, value); }
+ }
+
+ public Expression Initializer {
+ get { return GetChildByRole(Roles.Expression); }
+ set { SetChildByRole(Roles.Expression, value); }
+ }
+
+ protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override S AcceptVisitor(IAstVisitor visitor, T data)
+ {
+ return visitor.VisitVariableDeclaratorWithTypeAndInitializer(this, data);
+ }
+ }
+
+ public class VariableDeclaratorWithObjectCreation : VariableDeclarator
+ {
+ public static readonly Role InitializerRole = new Role("InitializerRole");
+
+ public ObjectCreationExpression Initializer {
+ get { return GetChildByRole(InitializerRole); }
+ set { SetChildByRole(InitializerRole, value); }
+ }
+
+ protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override S AcceptVisitor(IAstVisitor visitor, T data)
+ {
+ return visitor.VisitVariableDeclaratorWithObjectCreation(this, data);
+ }
+ }
+}
diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs
index c2753f2358..3a4ed86737 100644
--- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs
+++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs
@@ -36,7 +36,8 @@ namespace ICSharpCode.NRefactory.VB {
S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data);
S VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data);
S VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data);
- S VisitVariableDeclarator(VariableDeclarator variableDeclarator, T data);
+ S VisitVariableDeclaratorWithTypeAndInitializer(VariableDeclaratorWithTypeAndInitializer variableDeclaratorWithTypeAndInitializer, T data);
+ S VisitVariableDeclaratorWithObjectCreation(VariableDeclaratorWithObjectCreation variableDeclaratorWithObjectCreation, T data);
S VisitVariableIdentifier(VariableIdentifier variableIdentifier, T data);
S VisitAccessor(Accessor accessor, T data);
S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data);
@@ -94,5 +95,7 @@ namespace ICSharpCode.NRefactory.VB {
S VisitComposedType(ComposedType composedType, T data);
S VisitArraySpecifier(ArraySpecifier arraySpecifier, T data);
S VisitSimpleType(SimpleType simpleType, T data);
+
+ S VisitVariableInitializer(VariableInitializer variableInitializer, T data);
}
}
diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
index a961a368d7..948c353cdc 100644
--- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
+++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
@@ -110,6 +110,7 @@
+
diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
index aedffea21a..f85a48cb70 100644
--- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
+++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
@@ -1251,27 +1251,6 @@ namespace ICSharpCode.NRefactory.VB
return EndNode(fieldDeclaration);
}
- public object VisitVariableDeclarator(VariableDeclarator variableDeclarator, object data)
- {
- StartNode(variableDeclarator);
-
- WriteCommaSeparatedList(variableDeclarator.Identifiers);
- WriteKeyword("As");
- if (variableDeclarator.Initializer is ObjectCreationExpression)
- variableDeclarator.Initializer.AcceptVisitor(this, data);
- else {
- variableDeclarator.Type.AcceptVisitor(this, data);
- if (!variableDeclarator.Initializer.IsNull) {
- Space();
- WriteToken("=", VariableDeclarator.Roles.Assign);
- Space();
- variableDeclarator.Initializer.AcceptVisitor(this, data);
- }
- }
-
- return EndNode(variableDeclarator);
- }
-
public object VisitVariableIdentifier(VariableIdentifier variableIdentifier, object data)
{
StartNode(variableIdentifier);
@@ -1943,7 +1922,19 @@ namespace ICSharpCode.NRefactory.VB
{
StartNode(forStatement);
- throw new NotImplementedException();
+ WriteKeyword("For");
+ forStatement.Variable.AcceptVisitor(this, data);
+ WriteKeyword("To");
+ forStatement.ToExpression.AcceptVisitor(this, data);
+ if (!forStatement.StepExpression.IsNull) {
+ WriteKeyword("Step");
+ forStatement.StepExpression.AcceptVisitor(this, data);
+ }
+ NewLine();
+ Indent();
+ forStatement.Body.AcceptVisitor(this, data);
+ Unindent();
+ WriteKeyword("Next");
return EndNode(forStatement);
}
@@ -1954,7 +1945,7 @@ namespace ICSharpCode.NRefactory.VB
WriteKeyword("For");
WriteKeyword("Each");
- forEachStatement.Initializer.AcceptVisitor(this, data);
+ forEachStatement.Variable.AcceptVisitor(this, data);
WriteKeyword("In");
forEachStatement.InExpression.AcceptVisitor(this, data);
NewLine();
@@ -2083,5 +2074,52 @@ namespace ICSharpCode.NRefactory.VB
yieldStatement.Expression.AcceptVisitor(this, data);
return EndNode(yieldStatement);
}
+
+ public object VisitVariableInitializer(VariableInitializer variableInitializer, object data)
+ {
+ StartNode(variableInitializer);
+
+ variableInitializer.Identifier.AcceptVisitor(this, data);
+ if (!variableInitializer.Type.IsNull) {
+ WriteKeyword("As");
+ variableInitializer.Type.AcceptVisitor(this, data);
+ }
+ if (!variableInitializer.Expression.IsNull) {
+ Space();
+ WriteToken("=", VariableInitializer.Roles.Assign);
+ Space();
+ variableInitializer.Expression.AcceptVisitor(this, data);
+ }
+
+ return EndNode(variableInitializer);
+ }
+
+ public object VisitVariableDeclaratorWithTypeAndInitializer(VariableDeclaratorWithTypeAndInitializer variableDeclaratorWithTypeAndInitializer, object data)
+ {
+ StartNode(variableDeclaratorWithTypeAndInitializer);
+
+ WriteCommaSeparatedList(variableDeclaratorWithTypeAndInitializer.Identifiers);
+ WriteKeyword("As");
+ variableDeclaratorWithTypeAndInitializer.Type.AcceptVisitor(this, data);
+ if (!variableDeclaratorWithTypeAndInitializer.Initializer.IsNull) {
+ Space();
+ WriteToken("=", VariableDeclarator.Roles.Assign);
+ Space();
+ variableDeclaratorWithTypeAndInitializer.Initializer.AcceptVisitor(this, data);
+ }
+
+ return EndNode(variableDeclaratorWithTypeAndInitializer);
+ }
+
+ public object VisitVariableDeclaratorWithObjectCreation(VariableDeclaratorWithObjectCreation variableDeclaratorWithObjectCreation, object data)
+ {
+ StartNode(variableDeclaratorWithObjectCreation);
+
+ WriteCommaSeparatedList(variableDeclaratorWithObjectCreation.Identifiers);
+ WriteKeyword("As");
+ variableDeclaratorWithObjectCreation.Initializer.AcceptVisitor(this, data);
+
+ return EndNode(variableDeclaratorWithObjectCreation);
+ }
}
}
diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs
index 617f258e7f..35569db9c0 100644
--- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs
+++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs
@@ -774,15 +774,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors
public AstNode VisitForeachStatement(CSharp.ForeachStatement foreachStatement, object data)
{
- var var = new LocalDeclarationStatement();
-
- var.Variables.Add(new VariableDeclarator() { Type = (AstType)foreachStatement.VariableType.AcceptVisitor(this, data) });
- var.Variables.Last().Identifiers.Add(new VariableIdentifier() { Name = foreachStatement.VariableName });
-
var stmt = new ForEachStatement() {
Body = (BlockStatement)foreachStatement.EmbeddedStatement.AcceptVisitor(this, data),
InExpression = (Expression)foreachStatement.InExpression.AcceptVisitor(this, data),
- Initializer = var
+ Variable = new VariableInitializer() { Identifier = new VariableIdentifier() { Name = foreachStatement.VariableName }, Type = (AstType)foreachStatement.VariableType.AcceptVisitor(this, data) }
};
return EndNode(foreachStatement, stmt);
@@ -1256,13 +1251,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors
public AstNode VisitVariableInitializer(CSharp.VariableInitializer variableInitializer, object data)
{
- var decl = new VariableDeclarator();
+ var decl = new VariableDeclaratorWithTypeAndInitializer();
// look for type in parent
decl.Type = (AstType)variableInitializer.Parent
.GetChildByRole(CSharp.VariableInitializer.Roles.Type)
.AcceptVisitor(this, data);
- decl.Identifiers.Add(new VariableIdentifier() { Name = new Identifier(variableInitializer.Name, AstLocation.Empty) });
+ decl.Identifiers.Add(new VariableIdentifier() { Name = variableInitializer.Name });
decl.Initializer = (Expression)variableInitializer.Initializer.AcceptVisitor(this, data);
return EndNode(variableInitializer, decl);