diff --git a/ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs b/ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs index f862c80ef6..ac16e963ac 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs @@ -225,6 +225,11 @@ namespace ICSharpCode.NRefactory.CSharp return VisitChildren (continueStatement, data); } + public virtual S VisitDoWhileStatement (DoWhileStatement doWhileStatement, T data) + { + return VisitChildren (doWhileStatement, data); + } + public virtual S VisitEmptyStatement (EmptyStatement emptyStatement, T data) { return VisitChildren (emptyStatement, data); diff --git a/ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs b/ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs index e61922a881..a7dd061cf4 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs @@ -65,6 +65,7 @@ namespace ICSharpCode.NRefactory.CSharp S VisitBreakStatement(BreakStatement breakStatement, T data); S VisitCheckedStatement(CheckedStatement checkedStatement, T data); S VisitContinueStatement(ContinueStatement continueStatement, T data); + S VisitDoWhileStatement(DoWhileStatement doWhileStatement, T data); S VisitEmptyStatement(EmptyStatement emptyStatement, T data); S VisitExpressionStatement(ExpressionStatement expressionStatement, T data); S VisitFixedStatement(FixedStatement fixedStatement, T data); diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs new file mode 100644 index 0000000000..5cd0ad5ac7 --- /dev/null +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs @@ -0,0 +1,73 @@ +// +// DoWhileStatement.cs +// +// Author: +// Mike Krüger +// +// Copyright (c) 2011 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE.using System; + +namespace ICSharpCode.NRefactory.CSharp +{ + /// + /// "do EmbeddedStatement while(Condition);" + /// + public class DoWhileStatement : Statement + { + public static readonly Role DoKeywordRole = new Role("DoKeyword", CSharpTokenNode.Null); + public static readonly Role WhileKeywordRole = new Role("WhileKeyword", CSharpTokenNode.Null); + + public CSharpTokenNode DoToken { + get { return GetChildByRole (DoKeywordRole); } + } + + public Statement EmbeddedStatement { + get { return GetChildByRole (Roles.EmbeddedStatement); } + set { SetChildByRole (Roles.EmbeddedStatement, value); } + } + + public CSharpTokenNode WhileToken { + get { return GetChildByRole (WhileKeywordRole); } + } + + public CSharpTokenNode LParToken { + get { return GetChildByRole (Roles.LPar); } + } + + public Expression Condition { + get { return GetChildByRole (Roles.Condition); } + set { SetChildByRole (Roles.Condition, value); } + } + + public CSharpTokenNode RParToken { + get { return GetChildByRole (Roles.RPar); } + } + + public CSharpTokenNode SemicolonToken { + get { return GetChildByRole (Roles.Semicolon); } + } + + public override S AcceptVisitor (AstVisitor visitor, T data) + { + return visitor.VisitDoWhileStatement (this, data); + } + } +} + diff --git a/ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs b/ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs index 2e78196d72..ab8ac2f131 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs @@ -28,22 +28,11 @@ namespace ICSharpCode.NRefactory.CSharp { /// /// "while (Condition) EmbeddedStatement" - /// or "do EmbeddedStatement while(Condition);" /// public class WhileStatement : Statement { - public static readonly Role DoKeywordRole = new Role("DoKeyword", CSharpTokenNode.Null); public static readonly Role WhileKeywordRole = new Role("WhileKeyword", CSharpTokenNode.Null); - public WhilePosition WhilePosition { - get; - set; - } - - public CSharpTokenNode DoToken { - get { return GetChildByRole (DoKeywordRole); } - } - public CSharpTokenNode WhileToken { get { return GetChildByRole (WhileKeywordRole); } } @@ -70,15 +59,5 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitWhileStatement (this, data); } - - public WhileStatement (WhilePosition whilePosition) - { - this.WhilePosition = whilePosition; - } - } - - public enum WhilePosition { - Begin, - End } } diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index c6e6605b23..94c537aaf3 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -1239,6 +1239,22 @@ namespace ICSharpCode.NRefactory.CSharp return EndNode(continueStatement); } + public object VisitDoWhileStatement(DoWhileStatement doWhileStatement, object data) + { + StartNode(doWhileStatement); + WriteKeyword("do", DoWhileStatement.DoKeywordRole); + WriteEmbeddedStatement(doWhileStatement.EmbeddedStatement); + WriteKeyword("while", DoWhileStatement.WhileKeywordRole); + Space(policy.WhileParentheses); + LPar(); + Space(policy.WithinWhileParentheses); + doWhileStatement.Condition.AcceptVisitor(this, data); + Space(policy.WithinWhileParentheses); + RPar(); + Semicolon(); + return EndNode(doWhileStatement); + } + public object VisitEmptyStatement(EmptyStatement emptyStatement, object data) { StartNode(emptyStatement); @@ -1512,11 +1528,6 @@ namespace ICSharpCode.NRefactory.CSharp public object VisitWhileStatement(WhileStatement whileStatement, object data) { StartNode(whileStatement); - if (whileStatement.WhilePosition == WhilePosition.End) { - // do .. while - WriteKeyword("do", WhileStatement.DoKeywordRole); - WriteEmbeddedStatement(whileStatement.EmbeddedStatement); - } WriteKeyword("while", WhileStatement.WhileKeywordRole); Space(policy.WhileParentheses); LPar(); @@ -1524,11 +1535,7 @@ namespace ICSharpCode.NRefactory.CSharp whileStatement.Condition.AcceptVisitor(this, data); Space(policy.WithinWhileParentheses); RPar(); - if (whileStatement.WhilePosition == WhilePosition.Begin) { - WriteEmbeddedStatement(whileStatement.EmbeddedStatement); - } else { - Semicolon(); - } + WriteEmbeddedStatement(whileStatement.EmbeddedStatement); return EndNode(whileStatement); } diff --git a/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs b/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs index ee69f7164e..cb4fc37c54 100644 --- a/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs +++ b/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs @@ -907,18 +907,18 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (Do doStatement) { - var result = new WhileStatement (WhilePosition.End); + var result = new DoWhileStatement (); var location = LocationsBag.GetLocations (doStatement); - result.AddChild (new CSharpTokenNode (Convert (doStatement.loc), "do".Length), WhileStatement.DoKeywordRole); + result.AddChild (new CSharpTokenNode (Convert (doStatement.loc), "do".Length), DoWhileStatement.DoKeywordRole); result.AddChild ((Statement)doStatement.EmbeddedStatement.Accept (this), WhileStatement.Roles.EmbeddedStatement); if (location != null) - result.AddChild (new CSharpTokenNode (Convert (location[0]), "while".Length), WhileStatement.WhileKeywordRole); + result.AddChild (new CSharpTokenNode (Convert (location[0]), "while".Length), DoWhileStatement.WhileKeywordRole); if (location != null) - result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), WhileStatement.Roles.LPar); - result.AddChild ((Expression)doStatement.expr.Accept (this), WhileStatement.Roles.Condition); + result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DoWhileStatement.Roles.LPar); + result.AddChild ((Expression)doStatement.expr.Accept (this), DoWhileStatement.Roles.Condition); if (location != null) { - result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), WhileStatement.Roles.RPar); - result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), WhileStatement.Roles.Semicolon); + result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DoWhileStatement.Roles.RPar); + result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), DoWhileStatement.Roles.Semicolon); } return result; @@ -926,7 +926,7 @@ namespace ICSharpCode.NRefactory.CSharp public override object Visit (While whileStatement) { - var result = new WhileStatement (WhilePosition.Begin); + var result = new WhileStatement (); var location = LocationsBag.GetLocations (whileStatement); result.AddChild (new CSharpTokenNode (Convert (whileStatement.loc), "while".Length), WhileStatement.WhileKeywordRole); diff --git a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj index 1ff587cd2c..6fa9834881 100644 --- a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj +++ b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj @@ -1,4 +1,4 @@ - + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} @@ -329,10 +329,10 @@ + - \ No newline at end of file