Browse Source

Splitted while & do while statements.

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
b8cf7d35c3
  1. 5
      ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs
  2. 1
      ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs
  3. 73
      ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs
  4. 21
      ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs
  5. 27
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
  6. 16
      ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
  7. 4
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

5
ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs

@ -225,6 +225,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);

1
ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs

@ -65,6 +65,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);

73
ICSharpCode.NRefactory/CSharp/Ast/Statements/DoWhileStatement.cs

@ -0,0 +1,73 @@ @@ -0,0 +1,73 @@
//
// DoWhileStatement.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// 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
{
/// <summary>
/// "do EmbeddedStatement while(Condition);"
/// </summary>
public class DoWhileStatement : Statement
{
public static readonly Role<CSharpTokenNode> DoKeywordRole = new Role<CSharpTokenNode>("DoKeyword", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> WhileKeywordRole = new Role<CSharpTokenNode>("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<T, S> (AstVisitor<T, S> visitor, T data)
{
return visitor.VisitDoWhileStatement (this, data);
}
}
}

21
ICSharpCode.NRefactory/CSharp/Ast/Statements/WhileStatement.cs

@ -28,22 +28,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -28,22 +28,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// "while (Condition) EmbeddedStatement"
/// or "do EmbeddedStatement while(Condition);"
/// </summary>
public class WhileStatement : Statement
{
public static readonly Role<CSharpTokenNode> DoKeywordRole = new Role<CSharpTokenNode>("DoKeyword", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> WhileKeywordRole = new Role<CSharpTokenNode>("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 @@ -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
}
}

27
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -1239,6 +1239,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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 @@ -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 @@ -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);
}

16
ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs

@ -907,18 +907,18 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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 @@ -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);

4
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</ProjectGuid>
@ -329,10 +329,10 @@ @@ -329,10 +329,10 @@
<Compile Include="CSharp\Ast\TypeMembers\EnumMemberDeclaration.cs" />
<Compile Include="CSharp\Ast\GeneralScope\Comment.cs" />
<Compile Include="CSharp\Parser\mcs\reflection.cs" />
<Compile Include="CSharp\Ast\Statements\DoWhileStatement.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="CSharp\" />
<Folder Include="CSharp\OutputVisitor" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Loading…
Cancel
Save