Browse Source

correctly implement ForEachStatement and ForStatement; add output for ForStatement

pull/254/head
Siegfried Pammer 14 years ago
parent
commit
0eb61a2524
  1. 36
      NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs
  2. 8
      NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs
  3. 24
      NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs
  4. 6
      NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs
  5. 33
      NRefactory/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs
  6. 63
      NRefactory/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs
  7. 5
      NRefactory/ICSharpCode.NRefactory.VB/IAstVisitor.cs
  8. 1
      NRefactory/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  9. 84
      NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
  10. 11
      NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs

36
NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs

@ -312,6 +312,42 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -312,6 +312,42 @@ namespace ICSharpCode.NRefactory.VB.Ast
}
}
/// <summary>
/// Identifier As Type = Expression
/// </summary>
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<T, S>(IAstVisitor<T, S> 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);
}
}
/// <summary>
/// [ Key ] .Identifier = Expression
/// </summary>

8
NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/ForEachStatement.cs

@ -8,11 +8,11 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -8,11 +8,11 @@ namespace ICSharpCode.NRefactory.VB.Ast
{
public class ForEachStatement : Statement
{
public static readonly Role<Statement> InitializerRole = new Role<Statement>("InitializerRole", Statement.Null);
public static readonly Role<AstNode> VariableRole = new Role<AstNode>("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 {

24
NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/ForStatement.cs

@ -8,6 +8,30 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -8,6 +8,30 @@ namespace ICSharpCode.NRefactory.VB.Ast
{
public class ForStatement : Statement
{
public static readonly Role<AstNode> VariableRole = new Role<AstNode>("Variable", AstNode.Null);
public static readonly Role<Expression> ToExpressionRole = new Role<Expression>("ToExpression", Expression.Null);
public static readonly Role<Expression> StepExpressionRole = new Role<Expression>("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();

6
NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/SelectStatement.cs

@ -13,6 +13,10 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -13,6 +13,10 @@ namespace ICSharpCode.NRefactory.VB.Ast
set { SetChildByRole(Roles.Expression, value); }
}
public AstNodeCollection<CaseStatement> 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 @@ -26,7 +30,7 @@ namespace ICSharpCode.NRefactory.VB.Ast
public class CaseStatement : Statement
{
public static readonly Role<CaseStatement> CaseStatementRole = new Role<CaseStatement>("CaseStatement");
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
{

33
NRefactory/ICSharpCode.NRefactory.VB/Ast/TypeMembers/FieldDeclaration.cs

@ -25,38 +25,7 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -25,38 +25,7 @@ namespace ICSharpCode.NRefactory.VB.Ast
}
}
/// <remarks>
/// VariableIdentifiers As ObjectCreationExpression <br />
/// VariableIdentifiers ( As TypeName )? ( Equals Expression )?
/// </remarks>
public class VariableDeclarator : AstNode
{
public static readonly Role<VariableDeclarator> VariableDeclaratorRole = new Role<VariableDeclarator>("VariableDeclarator");
public AstNodeCollection<VariableIdentifier> 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<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitVariableDeclarator(this, data);
}
}
/// <remarks>
/// Identifier IdentifierModifiers

63
NRefactory/ICSharpCode.NRefactory.VB/Ast/TypeMembers/VariableDeclarator.cs

@ -0,0 +1,63 @@ @@ -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
{
/// <remarks>
/// VariableIdentifiers As ObjectCreationExpression <br />
/// VariableIdentifiers ( As TypeName )? ( Equals Expression )?
/// </remarks>
public abstract class VariableDeclarator : AstNode
{
public static readonly Role<VariableDeclarator> VariableDeclaratorRole = new Role<VariableDeclarator>("VariableDeclarator");
public AstNodeCollection<VariableIdentifier> 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<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitVariableDeclaratorWithTypeAndInitializer(this, data);
}
}
public class VariableDeclaratorWithObjectCreation : VariableDeclarator
{
public static readonly Role<ObjectCreationExpression> InitializerRole = new Role<ObjectCreationExpression>("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<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitVariableDeclaratorWithObjectCreation(this, data);
}
}
}

5
NRefactory/ICSharpCode.NRefactory.VB/IAstVisitor.cs

@ -36,7 +36,8 @@ namespace ICSharpCode.NRefactory.VB { @@ -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 { @@ -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);
}
}

1
NRefactory/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj

@ -110,6 +110,7 @@ @@ -110,6 +110,7 @@
<Compile Include="Ast\TypeMembers\MethodDeclaration.cs" />
<Compile Include="Ast\TypeMembers\OperatorDeclaration.cs" />
<Compile Include="Ast\TypeMembers\PropertyDeclaration.cs" />
<Compile Include="Ast\TypeMembers\VariableDeclarator.cs" />
<Compile Include="Ast\TypeName\AstType.cs" />
<Compile Include="Ast\TypeName\ComposedType.cs" />
<Compile Include="Ast\TypeName\PrimitiveType.cs" />

84
NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -1251,27 +1251,6 @@ namespace ICSharpCode.NRefactory.VB @@ -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 @@ -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 @@ -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 @@ -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);
}
}
}

11
NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs

@ -774,15 +774,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -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 @@ -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);

Loading…
Cancel
Save