Browse Source

make AddressOfExpression a UnaryOperatorExpression, move expressions to separate files, implement LambdaExpression

newNRvisualizers
Siegfried Pammer 14 years ago
parent
commit
d340669da1
  1. 31
      ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs
  2. 44
      ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs
  3. 110
      ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs
  4. 44
      ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs
  5. 393
      ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs
  6. 49
      ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs
  7. 52
      ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs
  8. 124
      ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs
  9. 39
      ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs
  10. 80
      ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs
  11. 44
      ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs
  12. 5
      ICSharpCode.NRefactory.VB/IAstVisitor.cs
  13. 10
      ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  14. 68
      ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
  15. 18
      ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs

31
ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs

@ -1,31 +0,0 @@ @@ -1,31 +0,0 @@
// 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
{
public class AddressOfExpression : Expression
{
public AddressOfExpression()
{
}
public Expression Expression {
get { return GetChildByRole(Roles.Expression); }
set { SetChildByRole(Roles.Expression, value); }
}
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
{
var expr = other as AddressOfExpression;
return expr != null &&
Expression.DoMatch(expr.Expression, match);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitAddressOfExpression(this, data);
}
}
}

44
ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
// 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;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.VB.Ast
{
public class AssignmentExpression : Expression
{
public readonly static Role<Expression> LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole;
public readonly static Role<VBTokenNode> OperatorRole = BinaryOperatorExpression.OperatorRole;
public readonly static Role<Expression> RightExpressionRole = BinaryOperatorExpression.RightExpressionRole;
public AssignmentExpression(Expression left, AssignmentOperatorType type, Expression right)
{
AddChild(left, LeftExpressionRole);
AddChild(right, RightExpressionRole);
Operator = type;
}
public Expression Left {
get { return GetChildByRole(LeftExpressionRole); }
set { SetChildByRole(LeftExpressionRole, value); }
}
public AssignmentOperatorType Operator { get; set; }
public Expression Right {
get { return GetChildByRole(RightExpressionRole); }
set { SetChildByRole(RightExpressionRole, 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.VisitAssignmentExpression(this, data);
}
}
}

110
ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs

@ -0,0 +1,110 @@ @@ -0,0 +1,110 @@
// 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;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.VB.Ast
{
public class BinaryOperatorExpression : Expression
{
public readonly static Role<Expression> LeftExpressionRole = new Role<Expression>("Left");
public readonly static Role<VBTokenNode> OperatorRole = new Role<VBTokenNode>("Operator");
public readonly static Role<Expression> RightExpressionRole = new Role<Expression>("Right");
public BinaryOperatorExpression(Expression left, BinaryOperatorType type, Expression right)
{
AddChild(left, LeftExpressionRole);
AddChild(right, RightExpressionRole);
Operator = type;
}
public Expression Left {
get { return GetChildByRole(LeftExpressionRole); }
set { SetChildByRole(LeftExpressionRole, value); }
}
public BinaryOperatorType Operator { get; set; }
public Expression Right {
get { return GetChildByRole(RightExpressionRole); }
set { SetChildByRole(RightExpressionRole, 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.VisitBinaryOperatorExpression(this, data);
}
}
public enum BinaryOperatorType
{
None,
/// <summary>'&amp;' in C#, 'And' in VB.</summary>
BitwiseAnd,
/// <summary>'|' in C#, 'Or' in VB.</summary>
BitwiseOr,
/// <summary>'&amp;&amp;' in C#, 'AndAlso' in VB.</summary>
LogicalAnd,
/// <summary>'||' in C#, 'OrElse' in VB.</summary>
LogicalOr,
/// <summary>'^' in C#, 'Xor' in VB.</summary>
ExclusiveOr,
/// <summary>&gt;</summary>
GreaterThan,
/// <summary>&gt;=</summary>
GreaterThanOrEqual,
/// <summary>'==' in C#, '=' in VB.</summary>
Equality,
/// <summary>'!=' in C#, '&lt;&gt;' in VB.</summary>
InEquality,
/// <summary>&lt;</summary>
LessThan,
/// <summary>&lt;=</summary>
LessThanOrEqual,
/// <summary>+</summary>
Add,
/// <summary>-</summary>
Subtract,
/// <summary>*</summary>
Multiply,
/// <summary>/</summary>
Divide,
/// <summary>'%' in C#, 'Mod' in VB.</summary>
Modulus,
/// <summary>VB-only: \</summary>
DivideInteger,
/// <summary>VB-only: ^</summary>
Power,
/// <summary>VB-only: &amp;</summary>
Concat,
/// <summary>C#: &lt;&lt;</summary>
ShiftLeft,
/// <summary>C#: &gt;&gt;</summary>
ShiftRight,
/// <summary>VB-only: Is</summary>
ReferenceEquality,
/// <summary>VB-only: IsNot</summary>
ReferenceInequality,
/// <summary>VB-only: Like</summary>
Like,
/// <summary>
/// C#: ??
/// VB: IF(x, y)
/// </summary>
NullCoalescing,
/// <summary>VB-only: !</summary>
DictionaryAccess
}
}

44
ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
// 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;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.VB.Ast
{
public class ConditionalExpression : Expression
{
public readonly static Role<Expression> ConditionExpressionRole = new Role<Expression>("ConditionExpressionRole", Expression.Null);
public readonly static Role<Expression> TrueExpressionRole = new Role<Expression>("TrueExpressionRole", Expression.Null);
public readonly static Role<Expression> FalseExpressionRole = new Role<Expression>("FalseExpressionRole", Expression.Null);
public VBTokenNode IfToken {
get { return GetChildByRole (Roles.Keyword); }
}
public Expression ConditionExpression {
get { return GetChildByRole (ConditionExpressionRole); }
set { SetChildByRole (ConditionExpressionRole, value); }
}
public Expression TrueExpression {
get { return GetChildByRole (TrueExpressionRole); }
set { SetChildByRole (TrueExpressionRole, value); }
}
public Expression FalseExpression {
get { return GetChildByRole (FalseExpressionRole); }
set { SetChildByRole (FalseExpressionRole, 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.VisitConditionalExpression(this, data);
}
}
}

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

@ -31,397 +31,4 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -31,397 +31,4 @@ namespace ICSharpCode.NRefactory.VB.Ast
}
#endregion
}
public class BinaryOperatorExpression : Expression
{
public readonly static Role<Expression> LeftExpressionRole = new Role<Expression>("Left");
public readonly static Role<VBTokenNode> OperatorRole = new Role<VBTokenNode>("Operator");
public readonly static Role<Expression> RightExpressionRole = new Role<Expression>("Right");
public BinaryOperatorExpression(Expression left, BinaryOperatorType type, Expression right)
{
AddChild(left, LeftExpressionRole);
AddChild(right, RightExpressionRole);
Operator = type;
}
public Expression Left {
get { return GetChildByRole(LeftExpressionRole); }
set { SetChildByRole(LeftExpressionRole, value); }
}
public BinaryOperatorType Operator { get; set; }
public Expression Right {
get { return GetChildByRole(RightExpressionRole); }
set { SetChildByRole(RightExpressionRole, 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.VisitBinaryOperatorExpression(this, data);
}
}
public enum BinaryOperatorType
{
None,
/// <summary>'&amp;' in C#, 'And' in VB.</summary>
BitwiseAnd,
/// <summary>'|' in C#, 'Or' in VB.</summary>
BitwiseOr,
/// <summary>'&amp;&amp;' in C#, 'AndAlso' in VB.</summary>
LogicalAnd,
/// <summary>'||' in C#, 'OrElse' in VB.</summary>
LogicalOr,
/// <summary>'^' in C#, 'Xor' in VB.</summary>
ExclusiveOr,
/// <summary>&gt;</summary>
GreaterThan,
/// <summary>&gt;=</summary>
GreaterThanOrEqual,
/// <summary>'==' in C#, '=' in VB.</summary>
Equality,
/// <summary>'!=' in C#, '&lt;&gt;' in VB.</summary>
InEquality,
/// <summary>&lt;</summary>
LessThan,
/// <summary>&lt;=</summary>
LessThanOrEqual,
/// <summary>+</summary>
Add,
/// <summary>-</summary>
Subtract,
/// <summary>*</summary>
Multiply,
/// <summary>/</summary>
Divide,
/// <summary>'%' in C#, 'Mod' in VB.</summary>
Modulus,
/// <summary>VB-only: \</summary>
DivideInteger,
/// <summary>VB-only: ^</summary>
Power,
/// <summary>VB-only: &amp;</summary>
Concat,
/// <summary>C#: &lt;&lt;</summary>
ShiftLeft,
/// <summary>C#: &gt;&gt;</summary>
ShiftRight,
/// <summary>VB-only: Is</summary>
ReferenceEquality,
/// <summary>VB-only: IsNot</summary>
ReferenceInequality,
/// <summary>VB-only: Like</summary>
Like,
/// <summary>
/// C#: ??
/// VB: IF(x, y)
/// </summary>
NullCoalescing,
/// <summary>VB-only: !</summary>
DictionaryAccess
}
public class AssignmentExpression : Expression
{
public readonly static Role<Expression> LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole;
public readonly static Role<VBTokenNode> OperatorRole = BinaryOperatorExpression.OperatorRole;
public readonly static Role<Expression> RightExpressionRole = BinaryOperatorExpression.RightExpressionRole;
public AssignmentExpression(Expression left, AssignmentOperatorType type, Expression right)
{
AddChild(left, LeftExpressionRole);
AddChild(right, RightExpressionRole);
Operator = type;
}
public Expression Left {
get { return GetChildByRole(LeftExpressionRole); }
set { SetChildByRole(LeftExpressionRole, value); }
}
public AssignmentOperatorType Operator { get; set; }
public Expression Right {
get { return GetChildByRole(RightExpressionRole); }
set { SetChildByRole(RightExpressionRole, 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.VisitAssignmentExpression(this, data);
}
}
/// <summary>
/// Target(Arguments)
/// </summary>
public class InvocationExpression : Expression
{
public Expression Target {
get { return GetChildByRole (Roles.TargetExpression); }
set { SetChildByRole(Roles.TargetExpression, value); }
}
public AstNodeCollection<Expression> Arguments {
get { return GetChildrenByRole<Expression>(Roles.Argument); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitInvocationExpression(this, data);
}
public InvocationExpression ()
{
}
public InvocationExpression (Expression target, IEnumerable<Expression> arguments)
{
AddChild (target, Roles.TargetExpression);
if (arguments != null) {
foreach (var arg in arguments) {
AddChild (arg, Roles.Argument);
}
}
}
public InvocationExpression (Expression target, params Expression[] arguments) : this (target, (IEnumerable<Expression>)arguments)
{
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
InvocationExpression o = other as InvocationExpression;
return o != null && this.Target.DoMatch(o.Target, match) && this.Arguments.DoMatch(o.Arguments, match);
}
}
/// <summary>
/// Operator Expression
/// </summary>
public class UnaryOperatorExpression : Expression
{
public readonly static Role<VBTokenNode> OperatorRole = BinaryOperatorExpression.OperatorRole;
public UnaryOperatorExpression()
{
}
public UnaryOperatorExpression(UnaryOperatorType op, Expression expression)
{
this.Operator = op;
this.Expression = expression;
}
public UnaryOperatorType Operator {
get;
set;
}
public VBTokenNode OperatorToken {
get { return GetChildByRole (OperatorRole); }
}
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.VisitUnaryOperatorExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
UnaryOperatorExpression o = other as UnaryOperatorExpression;
return o != null && this.Operator == o.Operator && this.Expression.DoMatch(o.Expression, match);
}
public static string GetOperatorSymbol(UnaryOperatorType op)
{
switch (op) {
case UnaryOperatorType.Not:
return "Not";
case UnaryOperatorType.Minus:
return "-";
case UnaryOperatorType.Plus:
return "+";
default:
throw new NotSupportedException("Invalid value for UnaryOperatorType");
}
}
}
public enum UnaryOperatorType
{
/// <summary>Logical/Bitwise not (Not a)</summary>
Not,
/// <summary>Unary minus (-a)</summary>
Minus,
/// <summary>Unary plus (+a)</summary>
Plus
}
/// <summary>
/// Represents a named argument passed to a method or attribute.
/// </summary>
public class NamedArgumentExpression : Expression
{
public Identifier Identifier {
get { return GetChildByRole(Roles.Identifier); }
set { SetChildByRole(Roles.Identifier, 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.VisitNamedArgumentExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
NamedArgumentExpression o = other as NamedArgumentExpression;
return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match);
}
}
/// <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>
public class FieldInitializerExpression : Expression
{
public bool IsKey { get; set; }
public VBTokenNode KeyToken {
get { return GetChildByRole (Roles.Keyword); }
}
public VBTokenNode DotToken {
get { return GetChildByRole (Roles.Dot); }
}
public Identifier Identifier {
get { return GetChildByRole(Roles.Identifier); }
set { SetChildByRole(Roles.Identifier, 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.VisitFieldInitializerExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
FieldInitializerExpression o = other as FieldInitializerExpression;
return o != null && this.IsKey == o.IsKey && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match);
}
}
public class ConditionalExpression : Expression
{
public readonly static Role<Expression> ConditionExpressionRole = new Role<Expression>("ConditionExpressionRole", Expression.Null);
public readonly static Role<Expression> TrueExpressionRole = new Role<Expression>("TrueExpressionRole", Expression.Null);
public readonly static Role<Expression> FalseExpressionRole = new Role<Expression>("FalseExpressionRole", Expression.Null);
public VBTokenNode IfToken {
get { return GetChildByRole (Roles.Keyword); }
}
public Expression ConditionExpression {
get { return GetChildByRole (ConditionExpressionRole); }
set { SetChildByRole (ConditionExpressionRole, value); }
}
public Expression TrueExpression {
get { return GetChildByRole (TrueExpressionRole); }
set { SetChildByRole (TrueExpressionRole, value); }
}
public Expression FalseExpression {
get { return GetChildByRole (FalseExpressionRole); }
set { SetChildByRole (FalseExpressionRole, 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.VisitConditionalExpression(this, data);
}
}
}

49
ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// 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;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.VB.Ast
{
/// <summary>
/// [ Key ] .Identifier = Expression
/// </summary>
public class FieldInitializerExpression : Expression
{
public bool IsKey { get; set; }
public VBTokenNode KeyToken {
get { return GetChildByRole (Roles.Keyword); }
}
public VBTokenNode DotToken {
get { return GetChildByRole (Roles.Dot); }
}
public Identifier Identifier {
get { return GetChildByRole(Roles.Identifier); }
set { SetChildByRole(Roles.Identifier, 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.VisitFieldInitializerExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
FieldInitializerExpression o = other as FieldInitializerExpression;
return o != null && this.IsKey == o.IsKey && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match);
}
}
}

52
ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
// 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;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.VB.Ast
{
/// <summary>
/// Target(Arguments)
/// </summary>
public class InvocationExpression : Expression
{
public Expression Target {
get { return GetChildByRole (Roles.TargetExpression); }
set { SetChildByRole(Roles.TargetExpression, value); }
}
public AstNodeCollection<Expression> Arguments {
get { return GetChildrenByRole<Expression>(Roles.Argument); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitInvocationExpression(this, data);
}
public InvocationExpression ()
{
}
public InvocationExpression (Expression target, IEnumerable<Expression> arguments)
{
AddChild (target, Roles.TargetExpression);
if (arguments != null) {
foreach (var arg in arguments) {
AddChild (arg, Roles.Argument);
}
}
}
public InvocationExpression (Expression target, params Expression[] arguments) : this (target, (IEnumerable<Expression>)arguments)
{
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
InvocationExpression o = other as InvocationExpression;
return o != null && this.Target.DoMatch(o.Target, match) && this.Arguments.DoMatch(o.Arguments, match);
}
}
}

124
ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs

@ -0,0 +1,124 @@ @@ -0,0 +1,124 @@
// 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;
using System.Collections.Generic;
using System.Linq;
namespace ICSharpCode.NRefactory.VB.Ast
{
public abstract class LambdaExpression : Expression
{
public static readonly Role<VBModifierToken> ModifierRole = AttributedNode.ModifierRole;
public LambdaExpressionModifiers Modifiers {
get { return GetModifiers(this); }
set { SetModifiers(this, value); }
}
public AstNodeCollection<VBModifierToken> ModifierTokens {
get { return GetChildrenByRole (ModifierRole); }
}
internal static LambdaExpressionModifiers GetModifiers(AstNode node)
{
LambdaExpressionModifiers m = 0;
foreach (VBModifierToken t in node.GetChildrenByRole (ModifierRole)) {
m |= (LambdaExpressionModifiers)t.Modifier;
}
return m;
}
internal static void SetModifiers(AstNode node, LambdaExpressionModifiers newValue)
{
LambdaExpressionModifiers oldValue = GetModifiers(node);
AstNode insertionPos = null;
foreach (Modifiers m in VBModifierToken.AllModifiers) {
if ((m & (Modifiers)newValue) != 0) {
if ((m & (Modifiers)oldValue) == 0) {
// Modifier was added
var newToken = new VBModifierToken(AstLocation.Empty, m);
node.InsertChildAfter(insertionPos, newToken, ModifierRole);
insertionPos = newToken;
} else {
// Modifier already exists
insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m);
}
} else {
if ((m & (Modifiers)oldValue) != 0) {
// Modifier was removed
node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove();
}
}
}
}
public AstNodeCollection<ParameterDeclaration> Parameters {
get { return GetChildrenByRole(Roles.Parameter); }
}
}
public class SingleLineSubLambdaExpression : LambdaExpression
{
public static readonly Role<Statement> StatementRole = BlockStatement.StatementRole;
public Statement EmbeddedStatement {
get { return GetChildByRole(StatementRole); }
set { SetChildByRole(StatementRole, 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.VisitSingleLineSubLambdaExpression(this, data);
}
}
public class SingleLineFunctionLambdaExpression : LambdaExpression
{
public Expression EmbeddedExpression {
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.VisitSingleLineFunctionLambdaExpression(this, data);
}
}
public class MultiLineLambdaExpression : LambdaExpression
{
public bool IsSub { get; set; }
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<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitMultiLineLambdaExpression(this, data);
}
}
public enum LambdaExpressionModifiers
{
Async = Modifiers.Async,
Iterator = Modifiers.Iterator
}
}

39
ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
// 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;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.VB.Ast
{
/// <summary>
/// Represents a named argument passed to a method or attribute.
/// </summary>
public class NamedArgumentExpression : Expression
{
public Identifier Identifier {
get { return GetChildByRole(Roles.Identifier); }
set { SetChildByRole(Roles.Identifier, 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.VisitNamedArgumentExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
NamedArgumentExpression o = other as NamedArgumentExpression;
return o != null && this.Identifier.DoMatch(o.Identifier, match) && this.Expression.DoMatch(o.Expression, match);
}
}
}

80
ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
// 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;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.VB.Ast
{
/// <summary>
/// Operator Expression
/// </summary>
public class UnaryOperatorExpression : Expression
{
public readonly static Role<VBTokenNode> OperatorRole = BinaryOperatorExpression.OperatorRole;
public UnaryOperatorExpression()
{
}
public UnaryOperatorExpression(UnaryOperatorType op, Expression expression)
{
this.Operator = op;
this.Expression = expression;
}
public UnaryOperatorType Operator {
get;
set;
}
public VBTokenNode OperatorToken {
get { return GetChildByRole (OperatorRole); }
}
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.VisitUnaryOperatorExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
UnaryOperatorExpression o = other as UnaryOperatorExpression;
return o != null && this.Operator == o.Operator && this.Expression.DoMatch(o.Expression, match);
}
public static string GetOperatorSymbol(UnaryOperatorType op)
{
switch (op) {
case UnaryOperatorType.Not:
return "Not";
case UnaryOperatorType.Minus:
return "-";
case UnaryOperatorType.Plus:
return "+";
default:
throw new NotSupportedException("Invalid value for UnaryOperatorType");
}
}
}
public enum UnaryOperatorType
{
/// <summary>Logical/Bitwise not (Not a)</summary>
Not,
/// <summary>Unary minus (-a)</summary>
Minus,
/// <summary>Unary plus (+a)</summary>
Plus,
/// <summary>AddressOf</summary>
AddressOf,
/// <summary>Await</summary>
Await
}
}

44
ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
// 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;
using System.Collections.Generic;
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);
}
}
}

5
ICSharpCode.NRefactory.VB/IAstVisitor.cs

@ -52,7 +52,6 @@ namespace ICSharpCode.NRefactory.VB { @@ -52,7 +52,6 @@ namespace ICSharpCode.NRefactory.VB {
S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data);
S VisitInstanceExpression(InstanceExpression instanceExpression, T data);
S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data);
S VisitAddressOfExpression(AddressOfExpression addressOfExpression, T data);
S VisitGetTypeExpression(GetTypeExpression getTypeExpression, T data);
S VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, T data);
S VisitGetXmlNamespaceExpression(GetXmlNamespaceExpression getXmlNamespaceExpression, T data);
@ -104,5 +103,9 @@ namespace ICSharpCode.NRefactory.VB { @@ -104,5 +103,9 @@ namespace ICSharpCode.NRefactory.VB {
S VisitSimpleType(SimpleType simpleType, T data);
S VisitGoToStatement(GoToStatement goToStatement, T data);
S VisitSingleLineSubLambdaExpression(SingleLineSubLambdaExpression singleLineSubLambdaExpression, T data);
S VisitMultiLineLambdaExpression(MultiLineLambdaExpression multiLineLambdaExpression, T data);
S VisitSingleLineFunctionLambdaExpression(SingleLineFunctionLambdaExpression singleLineFunctionLambdaExpression, T data);
}
}

10
ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj

@ -48,22 +48,30 @@ @@ -48,22 +48,30 @@
<Compile Include="Ast\AstNodeCollection.cs" />
<Compile Include="Ast\Comment.cs" />
<Compile Include="Ast\Enums.cs" />
<Compile Include="Ast\Expressions\AddressOfExpression.cs" />
<Compile Include="Ast\Expressions\ArrayCreateExpression.cs" />
<Compile Include="Ast\Expressions\ArrayInitializerExpression.cs" />
<Compile Include="Ast\Expressions\AssignmentExpression.cs" />
<Compile Include="Ast\Expressions\BinaryOperatorExpression.cs" />
<Compile Include="Ast\Expressions\CastExpression.cs" />
<Compile Include="Ast\Expressions\ConditionalExpression.cs" />
<Compile Include="Ast\Expressions\Expression.cs" />
<Compile Include="Ast\Expressions\FieldInitializerExpression.cs" />
<Compile Include="Ast\Expressions\GetTypeExpression.cs" />
<Compile Include="Ast\Expressions\GetXmlNamespaceExpression.cs" />
<Compile Include="Ast\Expressions\IdentifierExpression.cs" />
<Compile Include="Ast\Expressions\InstanceExpression.cs" />
<Compile Include="Ast\Expressions\InvocationExpression.cs" />
<Compile Include="Ast\Expressions\LambdaExpression.cs" />
<Compile Include="Ast\Expressions\MemberAccessExpression.cs" />
<Compile Include="Ast\Expressions\NamedArgumentExpression.cs" />
<Compile Include="Ast\Expressions\ObjectCreationExpression.cs" />
<Compile Include="Ast\Expressions\ParenthesizedExpression.cs" />
<Compile Include="Ast\Expressions\SimpleNameExpression.cs" />
<Compile Include="Ast\Expressions\PrimitiveExpression.cs" />
<Compile Include="Ast\Expressions\TypeOfIsExpression.cs" />
<Compile Include="Ast\Expressions\TypeReferenceExpression.cs" />
<Compile Include="Ast\Expressions\UnaryOperatorExpression.cs" />
<Compile Include="Ast\Expressions\VariableInitializer.cs" />
<Compile Include="Ast\Expressions\XmlIdentifier.cs" />
<Compile Include="Ast\Expressions\XmlLiteralString.cs" />
<Compile Include="Ast\General\Attribute.cs" />

68
ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -407,17 +407,6 @@ namespace ICSharpCode.NRefactory.VB @@ -407,17 +407,6 @@ namespace ICSharpCode.NRefactory.VB
return EndNode(parenthesizedExpression);
}
public object VisitAddressOfExpression(AddressOfExpression addressOfExpression, object data)
{
StartNode(addressOfExpression);
WriteKeyword("AddressOf");
addressOfExpression.Expression.AcceptVisitor(this, data);
return EndNode(addressOfExpression);
}
public object VisitGetTypeExpression(GetTypeExpression getTypeExpression, object data)
{
StartNode(getTypeExpression);
@ -1455,6 +1444,7 @@ namespace ICSharpCode.NRefactory.VB @@ -1455,6 +1444,7 @@ namespace ICSharpCode.NRefactory.VB
StartNode(ifElseStatement);
WriteKeyword("If");
ifElseStatement.Condition.AcceptVisitor(this, data);
Space();
WriteKeyword("Then");
NewLine();
Indent();
@ -1810,6 +1800,12 @@ namespace ICSharpCode.NRefactory.VB @@ -1810,6 +1800,12 @@ namespace ICSharpCode.NRefactory.VB
case UnaryOperatorType.Plus:
WriteToken("+", UnaryOperatorExpression.OperatorRole);
break;
case UnaryOperatorType.AddressOf:
WriteKeyword("AddressOf");
break;
case UnaryOperatorType.Await:
WriteKeyword("Await");
break;
default:
throw new Exception("Invalid value for UnaryOperatorType");
}
@ -2262,5 +2258,55 @@ namespace ICSharpCode.NRefactory.VB @@ -2262,5 +2258,55 @@ namespace ICSharpCode.NRefactory.VB
return EndNode(goToStatement);
}
public object VisitSingleLineSubLambdaExpression(SingleLineSubLambdaExpression singleLineSubLambdaExpression, object data)
{
StartNode(singleLineSubLambdaExpression);
WriteModifiers(singleLineSubLambdaExpression.ModifierTokens);
WriteKeyword("Sub");
WriteCommaSeparatedListInParenthesis(singleLineSubLambdaExpression.Parameters, false);
Space();
singleLineSubLambdaExpression.EmbeddedStatement.AcceptVisitor(this, data);
return EndNode(singleLineSubLambdaExpression);
}
public object VisitSingleLineFunctionLambdaExpression(SingleLineFunctionLambdaExpression singleLineFunctionLambdaExpression, object data)
{
StartNode(singleLineFunctionLambdaExpression);
WriteModifiers(singleLineFunctionLambdaExpression.ModifierTokens);
WriteKeyword("Function");
WriteCommaSeparatedListInParenthesis(singleLineFunctionLambdaExpression.Parameters, false);
Space();
singleLineFunctionLambdaExpression.EmbeddedExpression.AcceptVisitor(this, data);
return EndNode(singleLineFunctionLambdaExpression);
}
public object VisitMultiLineLambdaExpression(MultiLineLambdaExpression multiLineLambdaExpression, object data)
{
StartNode(multiLineLambdaExpression);
WriteModifiers(multiLineLambdaExpression.ModifierTokens);
if (multiLineLambdaExpression.IsSub)
WriteKeyword("Sub");
else
WriteKeyword("Function");
WriteCommaSeparatedListInParenthesis(multiLineLambdaExpression.Parameters, false);
NewLine();
Indent();
multiLineLambdaExpression.Body.AcceptVisitor(this, data);
Unindent();
WriteKeyword("End");
if (multiLineLambdaExpression.IsSub)
WriteKeyword("Sub");
else
WriteKeyword("Function");
return EndNode(multiLineLambdaExpression);
}
}
}

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

@ -327,7 +327,18 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -327,7 +327,18 @@ namespace ICSharpCode.NRefactory.VB.Visitors
public AstNode VisitLambdaExpression(CSharp.LambdaExpression lambdaExpression, object data)
{
throw new NotImplementedException();
LambdaExpression expr = null;
if (lambdaExpression.Body is CSharp.Expression) {
var singleLine = new SingleLineFunctionLambdaExpression() {
EmbeddedExpression = (Expression)lambdaExpression.Body.AcceptVisitor(this, data)
};
ConvertNodes(lambdaExpression.Parameters, singleLine.Parameters);
expr = singleLine;
} else
throw new NotImplementedException();
return EndNode(lambdaExpression, expr);
}
public AstNode VisitMemberReferenceExpression(CSharp.MemberReferenceExpression memberReferenceExpression, object data)
@ -526,8 +537,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -526,8 +537,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors
((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data));
break;
case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.AddressOf:
expr = new AddressOfExpression() {
Expression = (Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)
expr = new UnaryOperatorExpression() {
Expression = (Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data),
Operator = UnaryOperatorType.AddressOf
};
break;
// case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Dereference:

Loading…
Cancel
Save