From 3531735e970b3215658433fedd750014b3e3ee25 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 7 Jul 2011 17:43:33 +0200 Subject: [PATCH] implemented DoLoopStatement and UsingStatement --- ICSharpCode.NRefactory.VB/Ast/Enums.cs | 19 ++------ .../Ast/Statements/DoLoopStatement.cs | 14 +++++- .../Ast/Statements/UsingStatement.cs | 33 +++++++++++++ ICSharpCode.NRefactory.VB/IAstVisitor.cs | 13 +++--- .../ICSharpCode.NRefactory.VB.csproj | 1 + .../OutputVisitor/OutputVisitor.cs | 46 +++++++++++++++++++ .../Visitors/CSharpToVBConverterVisitor.cs | 22 +++++++-- 7 files changed, 121 insertions(+), 27 deletions(-) create mode 100644 ICSharpCode.NRefactory.VB/Ast/Statements/UsingStatement.cs diff --git a/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/ICSharpCode.NRefactory.VB/Ast/Enums.cs index 5ce7c29bed..c7f6dc08e1 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -102,25 +102,12 @@ namespace ICSharpCode.NRefactory.VB.Ast public enum ConditionType { None, - Until, - While, + LoopUntil, + LoopWhile, + DoUntil, DoWhile } - public enum ConditionPosition - { - None, - Start, - End - } - - public enum ConstructorInitializerType - { - None, - Base, - This - } - public enum ConversionType { None, diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs index 0b2101c176..9335926f89 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/DoLoopStatement.cs @@ -8,6 +8,18 @@ namespace ICSharpCode.NRefactory.VB.Ast { public class DoLoopStatement : Statement { + public ConditionType ConditionType { get; set; } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, 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(); @@ -15,7 +27,7 @@ namespace ICSharpCode.NRefactory.VB.Ast public override S AcceptVisitor(IAstVisitor visitor, T data) { - throw new NotImplementedException(); + return visitor.VisitDoLoopStatement(this, data); } } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Statements/UsingStatement.cs b/ICSharpCode.NRefactory.VB/Ast/Statements/UsingStatement.cs new file mode 100644 index 0000000000..c2147e447a --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Statements/UsingStatement.cs @@ -0,0 +1,33 @@ +// 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.Ast +{ + public class UsingStatement : Statement + { + public static readonly Role ResourceRole = new Role("Resource", AstNode.Null); + + /// either multiple VariableInitializers or one Expression + public AstNodeCollection Resources { + get { return GetChildrenByRole(ResourceRole); } + } + + 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(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitUsingStatement(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index ed4ddb06ff..4d7e638995 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -88,6 +88,13 @@ namespace ICSharpCode.NRefactory.VB { S VisitExitStatement(ExitStatement exitStatement, T data); S VisitSelectStatement(SelectStatement selectStatement, T data); S VisitYieldStatement(YieldStatement yieldStatement, T data); + S VisitVariableInitializer(VariableInitializer variableInitializer, T data); + S VisitRangeCaseClause(RangeCaseClause rangeCaseClause, T data); + S VisitComparisonCaseClause(ComparisonCaseClause comparisonCaseClause, T data); + S VisitSimpleCaseClause(SimpleCaseClause simpleCaseClause, T data); + S VisitCaseStatement(CaseStatement caseStatement, T data); + S VisitDoLoopStatement(DoLoopStatement doLoopStatement, T data); + S VisitUsingStatement(UsingStatement usingStatement, T data); // TypeName S VisitPrimitiveType(PrimitiveType primitiveType, T data); @@ -95,11 +102,5 @@ 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); - S VisitRangeCaseClause(RangeCaseClause rangeCaseClause, T data); - S VisitComparisonCaseClause(ComparisonCaseClause comparisonCaseClause, T data); - S VisitSimpleCaseClause(SimpleCaseClause simpleCaseClause, T data); - S VisitCaseStatement(CaseStatement caseStatement, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 948c353cdc..5a14a81400 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -100,6 +100,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index cf0d7310ea..e73946064f 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2201,5 +2201,51 @@ namespace ICSharpCode.NRefactory.VB return EndNode(variableDeclaratorWithObjectCreation); } + + public object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data) + { + StartNode(doLoopStatement); + + WriteKeyword("Do"); + if (doLoopStatement.ConditionType == ConditionType.DoUntil) { + WriteKeyword("Until"); + doLoopStatement.Expression.AcceptVisitor(this, data); + } + if (doLoopStatement.ConditionType == ConditionType.DoWhile) { + WriteKeyword("While"); + doLoopStatement.Expression.AcceptVisitor(this, data); + } + NewLine(); + Indent(); + doLoopStatement.Body.AcceptVisitor(this, data); + Unindent(); + WriteKeyword("Loop"); + if (doLoopStatement.ConditionType == ConditionType.LoopUntil) { + WriteKeyword("Until"); + doLoopStatement.Expression.AcceptVisitor(this, data); + } + if (doLoopStatement.ConditionType == ConditionType.LoopWhile) { + WriteKeyword("While"); + doLoopStatement.Expression.AcceptVisitor(this, data); + } + + return EndNode(doLoopStatement); + } + + public object VisitUsingStatement(UsingStatement usingStatement, object data) + { + StartNode(usingStatement); + + WriteKeyword("Using"); + WriteCommaSeparatedList(usingStatement.Resources); + NewLine(); + Indent(); + usingStatement.Body.AcceptVisitor(this, data); + Unindent(); + WriteKeyword("End"); + WriteKeyword("Using"); + + return EndNode(usingStatement); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 2de4730590..48dc0c1d59 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -791,12 +791,18 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitDoWhileStatement(CSharp.DoWhileStatement doWhileStatement, object data) { - throw new NotImplementedException(); + var stmt = new DoLoopStatement(); + + stmt.ConditionType = ConditionType.LoopWhile; + stmt.Expression = (Expression)doWhileStatement.Condition.AcceptVisitor(this, data); + stmt.Body = (BlockStatement)doWhileStatement.EmbeddedStatement.AcceptVisitor(this, data); + + return EndNode(doWhileStatement, stmt); } public AstNode VisitEmptyStatement(CSharp.EmptyStatement emptyStatement, object data) { - throw new NotImplementedException(); + return EndNode(emptyStatement, null); } public AstNode VisitExpressionStatement(CSharp.ExpressionStatement expressionStatement, object data) @@ -816,7 +822,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors var stmt = new ForEachStatement() { Body = (BlockStatement)foreachStatement.EmbeddedStatement.AcceptVisitor(this, data), InExpression = (Expression)foreachStatement.InExpression.AcceptVisitor(this, data), - Variable = new VariableInitializer() { Identifier = new VariableIdentifier() { Name = foreachStatement.VariableName }, Type = (AstType)foreachStatement.VariableType.AcceptVisitor(this, data) } + Variable = new VariableInitializer() { + Identifier = new VariableIdentifier() { Name = foreachStatement.VariableName }, + Type = (AstType)foreachStatement.VariableType.AcceptVisitor(this, data) + } }; return EndNode(foreachStatement, stmt); @@ -954,7 +963,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitUsingStatement(CSharp.UsingStatement usingStatement, object data) { - throw new NotImplementedException(); + var stmt = new UsingStatement(); + + stmt.Resources.Add(usingStatement.ResourceAcquisition.AcceptVisitor(this, data)); + stmt.Body = (BlockStatement)usingStatement.EmbeddedStatement.AcceptVisitor(this, data); + + return EndNode(usingStatement, stmt); } public AstNode VisitVariableDeclarationStatement(CSharp.VariableDeclarationStatement variableDeclarationStatement, object data)