Browse Source

Added YieldBreakStatement.

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
ecc17721fd
  1. 5
      ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs
  2. 1
      ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs
  3. 54
      ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldBreakStatement.cs
  4. 11
      ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldStatement.cs
  5. 19
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
  6. 8
      ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
  7. 1
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

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

@ -330,6 +330,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -330,6 +330,11 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (whileStatement, data);
}
public virtual S VisitYieldBreakStatement (YieldBreakStatement yieldBreakStatement, T data)
{
return VisitChildren (yieldBreakStatement, data);
}
public virtual S VisitYieldStatement (YieldStatement yieldStatement, T data)
{
return VisitChildren (yieldStatement, data);

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

@ -87,6 +87,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -87,6 +87,7 @@ namespace ICSharpCode.NRefactory.CSharp
S VisitUsingStatement(UsingStatement usingStatement, T data);
S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, T data);
S VisitWhileStatement(WhileStatement whileStatement, T data);
S VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, T data);
S VisitYieldStatement(YieldStatement yieldStatement, T data);
S VisitAccessor(Accessor accessor, T data);

54
ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldBreakStatement.cs

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
//
// YieldBreakStatement.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.
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// yield break;
/// </summary>
public class YieldBreakStatement : Statement
{
public static readonly Role<CSharpTokenNode> YieldKeywordRole = new Role<CSharpTokenNode>("YieldKeyword", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> BreakKeywordRole = new Role<CSharpTokenNode>("BreakKeyword", CSharpTokenNode.Null);
public CSharpTokenNode YieldToken {
get { return GetChildByRole (YieldKeywordRole); }
}
public CSharpTokenNode BreakToken {
get { return GetChildByRole (BreakKeywordRole); }
}
public CSharpTokenNode SemicolonToken {
get { return GetChildByRole (Roles.Semicolon); }
}
public override S AcceptVisitor<T, S> (AstVisitor<T, S> visitor, T data)
{
return visitor.VisitYieldBreakStatement (this, data);
}
}
}

11
ICSharpCode.NRefactory/CSharp/Ast/Statements/YieldStatement.cs

@ -26,11 +26,13 @@ @@ -26,11 +26,13 @@
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// yield return Expression;
/// </summary>
public class YieldStatement : Statement
{
public static readonly Role<CSharpTokenNode> YieldKeywordRole = new Role<CSharpTokenNode>("YieldKeyword", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> ReturnKeywordRole = new Role<CSharpTokenNode>("ReturnKeyword", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> BreakKeywordRole = new Role<CSharpTokenNode>("BreakKeyword", CSharpTokenNode.Null);
public CSharpTokenNode YieldToken {
get { return GetChildByRole (YieldKeywordRole); }
@ -40,10 +42,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -40,10 +42,6 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (ReturnKeywordRole); }
}
public CSharpTokenNode BreakToken {
get { return GetChildByRole (BreakKeywordRole); }
}
public Expression Expression {
get { return GetChildByRole (Roles.Expression); }
set { SetChildByRole (Roles.Expression, value); }
@ -58,4 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -58,4 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitYieldStatement (this, data);
}
}
}

19
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -1539,17 +1539,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1539,17 +1539,22 @@ namespace ICSharpCode.NRefactory.CSharp
return EndNode(whileStatement);
}
public object VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, object data)
{
StartNode(yieldBreakStatement);
WriteKeyword("yield", YieldBreakStatement.YieldKeywordRole);
WriteKeyword("break", YieldBreakStatement.BreakKeywordRole);
Semicolon();
return EndNode(yieldBreakStatement);
}
public object VisitYieldStatement(YieldStatement yieldStatement, object data)
{
StartNode(yieldStatement);
WriteKeyword("yield", YieldStatement.YieldKeywordRole);
if (yieldStatement.Expression.IsNull) {
WriteKeyword("break", YieldStatement.BreakKeywordRole);
} else {
WriteKeyword("return", YieldStatement.ReturnKeywordRole);
Space();
yieldStatement.Expression.AcceptVisitor(this, data);
}
WriteKeyword("return", YieldStatement.ReturnKeywordRole);
Space();
yieldStatement.Expression.AcceptVisitor(this, data);
Semicolon();
return EndNode(yieldStatement);
}

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

@ -1376,12 +1376,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1376,12 +1376,12 @@ namespace ICSharpCode.NRefactory.CSharp
public override object Visit (YieldBreak yieldBreakStatement)
{
var result = new YieldStatement ();
var result = new YieldBreakStatement ();
var location = LocationsBag.GetLocations (yieldBreakStatement);
result.AddChild (new CSharpTokenNode (Convert (yieldBreakStatement.loc), "yield".Length), YieldStatement.YieldKeywordRole);
result.AddChild (new CSharpTokenNode (Convert (yieldBreakStatement.loc), "yield".Length), YieldBreakStatement.YieldKeywordRole);
if (location != null) {
result.AddChild (new CSharpTokenNode (Convert (location[0]), "break".Length), YieldStatement.BreakKeywordRole);
result.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), YieldStatement.Roles.Semicolon);
result.AddChild (new CSharpTokenNode (Convert (location[0]), "break".Length), YieldBreakStatement.BreakKeywordRole);
result.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), YieldBreakStatement.Roles.Semicolon);
}
return result;
}

1
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -330,6 +330,7 @@ @@ -330,6 +330,7 @@
<Compile Include="CSharp\Ast\GeneralScope\Comment.cs" />
<Compile Include="CSharp\Parser\mcs\reflection.cs" />
<Compile Include="CSharp\Ast\Statements\DoWhileStatement.cs" />
<Compile Include="CSharp\Ast\Statements\YieldBreakStatement.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="CSharp\" />

Loading…
Cancel
Save