diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs deleted file mode 100644 index 81eaca8126..0000000000 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/AddressOfExpression.cs +++ /dev/null @@ -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(IAstVisitor visitor, T data) - { - return visitor.VisitAddressOfExpression(this, data); - } - } -} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs new file mode 100644 index 0000000000..250e27b71a --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/AssignmentExpression.cs @@ -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 LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole; + public readonly static Role OperatorRole = BinaryOperatorExpression.OperatorRole; + public readonly static Role 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(IAstVisitor visitor, T data) + { + return visitor.VisitAssignmentExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs new file mode 100644 index 0000000000..d406be1996 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/BinaryOperatorExpression.cs @@ -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 LeftExpressionRole = new Role("Left"); + public readonly static Role OperatorRole = new Role("Operator"); + public readonly static Role RightExpressionRole = new Role("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(IAstVisitor visitor, T data) + { + return visitor.VisitBinaryOperatorExpression(this, data); + } + } + + public enum BinaryOperatorType + { + None, + + /// '&' in C#, 'And' in VB. + BitwiseAnd, + /// '|' in C#, 'Or' in VB. + BitwiseOr, + /// '&&' in C#, 'AndAlso' in VB. + LogicalAnd, + /// '||' in C#, 'OrElse' in VB. + LogicalOr, + /// '^' in C#, 'Xor' in VB. + ExclusiveOr, + + /// > + GreaterThan, + /// >= + GreaterThanOrEqual, + /// '==' in C#, '=' in VB. + Equality, + /// '!=' in C#, '<>' in VB. + InEquality, + /// < + LessThan, + /// <= + LessThanOrEqual, + + /// + + Add, + /// - + Subtract, + /// * + Multiply, + /// / + Divide, + /// '%' in C#, 'Mod' in VB. + Modulus, + /// VB-only: \ + DivideInteger, + /// VB-only: ^ + Power, + /// VB-only: & + Concat, + + /// C#: << + ShiftLeft, + /// C#: >> + ShiftRight, + /// VB-only: Is + ReferenceEquality, + /// VB-only: IsNot + ReferenceInequality, + + /// VB-only: Like + Like, + /// + /// C#: ?? + /// VB: IF(x, y) + /// + NullCoalescing, + + /// VB-only: ! + DictionaryAccess + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs new file mode 100644 index 0000000000..94d9949bda --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/ConditionalExpression.cs @@ -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 ConditionExpressionRole = new Role("ConditionExpressionRole", Expression.Null); + public readonly static Role TrueExpressionRole = new Role("TrueExpressionRole", Expression.Null); + public readonly static Role FalseExpressionRole = new Role("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(IAstVisitor visitor, T data) + { + return visitor.VisitConditionalExpression(this, data); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index b26ec73bb0..26876e4161 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -31,397 +31,4 @@ namespace ICSharpCode.NRefactory.VB.Ast } #endregion } - - public class BinaryOperatorExpression : Expression - { - public readonly static Role LeftExpressionRole = new Role("Left"); - public readonly static Role OperatorRole = new Role("Operator"); - public readonly static Role RightExpressionRole = new Role("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(IAstVisitor visitor, T data) - { - return visitor.VisitBinaryOperatorExpression(this, data); - } - } - - public enum BinaryOperatorType - { - None, - - /// '&' in C#, 'And' in VB. - BitwiseAnd, - /// '|' in C#, 'Or' in VB. - BitwiseOr, - /// '&&' in C#, 'AndAlso' in VB. - LogicalAnd, - /// '||' in C#, 'OrElse' in VB. - LogicalOr, - /// '^' in C#, 'Xor' in VB. - ExclusiveOr, - - /// > - GreaterThan, - /// >= - GreaterThanOrEqual, - /// '==' in C#, '=' in VB. - Equality, - /// '!=' in C#, '<>' in VB. - InEquality, - /// < - LessThan, - /// <= - LessThanOrEqual, - - /// + - Add, - /// - - Subtract, - /// * - Multiply, - /// / - Divide, - /// '%' in C#, 'Mod' in VB. - Modulus, - /// VB-only: \ - DivideInteger, - /// VB-only: ^ - Power, - /// VB-only: & - Concat, - - /// C#: << - ShiftLeft, - /// C#: >> - ShiftRight, - /// VB-only: Is - ReferenceEquality, - /// VB-only: IsNot - ReferenceInequality, - - /// VB-only: Like - Like, - /// - /// C#: ?? - /// VB: IF(x, y) - /// - NullCoalescing, - - /// VB-only: ! - DictionaryAccess - } - - public class AssignmentExpression : Expression - { - public readonly static Role LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole; - public readonly static Role OperatorRole = BinaryOperatorExpression.OperatorRole; - public readonly static Role 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(IAstVisitor visitor, T data) - { - return visitor.VisitAssignmentExpression(this, data); - } - } - - /// - /// Target(Arguments) - /// - public class InvocationExpression : Expression - { - public Expression Target { - get { return GetChildByRole (Roles.TargetExpression); } - set { SetChildByRole(Roles.TargetExpression, value); } - } - - public AstNodeCollection Arguments { - get { return GetChildrenByRole(Roles.Argument); } - } - - public override S AcceptVisitor (IAstVisitor visitor, T data) - { - return visitor.VisitInvocationExpression(this, data); - } - - public InvocationExpression () - { - } - - public InvocationExpression (Expression target, IEnumerable 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)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); - } - } - - /// - /// Operator Expression - /// - public class UnaryOperatorExpression : Expression - { - public readonly static Role 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 (IAstVisitor 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 - { - /// Logical/Bitwise not (Not a) - Not, - /// Unary minus (-a) - Minus, - /// Unary plus (+a) - Plus - } - - /// - /// Represents a named argument passed to a method or attribute. - /// - 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(IAstVisitor 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); - } - } - - /// - /// Identifier As Type = Expression - /// - 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(IAstVisitor 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); - } - } - - /// - /// [ Key ] .Identifier = Expression - /// - 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(IAstVisitor 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 ConditionExpressionRole = new Role("ConditionExpressionRole", Expression.Null); - public readonly static Role TrueExpressionRole = new Role("TrueExpressionRole", Expression.Null); - public readonly static Role FalseExpressionRole = new Role("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(IAstVisitor visitor, T data) - { - return visitor.VisitConditionalExpression(this, data); - } - } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs new file mode 100644 index 0000000000..7a005a4fdb --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/FieldInitializerExpression.cs @@ -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 +{ + /// + /// [ Key ] .Identifier = Expression + /// + 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(IAstVisitor 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); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs new file mode 100644 index 0000000000..e0eec7b052 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/InvocationExpression.cs @@ -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 +{ + /// + /// Target(Arguments) + /// + public class InvocationExpression : Expression + { + public Expression Target { + get { return GetChildByRole (Roles.TargetExpression); } + set { SetChildByRole(Roles.TargetExpression, value); } + } + + public AstNodeCollection Arguments { + get { return GetChildrenByRole(Roles.Argument); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitInvocationExpression(this, data); + } + + public InvocationExpression () + { + } + + public InvocationExpression (Expression target, IEnumerable 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)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); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs new file mode 100644 index 0000000000..25090d7ad4 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs @@ -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 ModifierRole = AttributedNode.ModifierRole; + + public LambdaExpressionModifiers Modifiers { + get { return GetModifiers(this); } + set { SetModifiers(this, value); } + } + + public AstNodeCollection 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 Parameters { + get { return GetChildrenByRole(Roles.Parameter); } + } + } + + public class SingleLineSubLambdaExpression : LambdaExpression + { + public static readonly Role 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(IAstVisitor 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(IAstVisitor 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(IAstVisitor visitor, T data) + { + return visitor.VisitMultiLineLambdaExpression(this, data); + } + } + + public enum LambdaExpressionModifiers + { + Async = Modifiers.Async, + Iterator = Modifiers.Iterator + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs new file mode 100644 index 0000000000..be4c3249da --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/NamedArgumentExpression.cs @@ -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 +{ + /// + /// Represents a named argument passed to a method or attribute. + /// + 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(IAstVisitor 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); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs new file mode 100644 index 0000000000..43c7881c86 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/UnaryOperatorExpression.cs @@ -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 +{ + /// + /// Operator Expression + /// + public class UnaryOperatorExpression : Expression + { + public readonly static Role 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 (IAstVisitor 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 + { + /// Logical/Bitwise not (Not a) + Not, + /// Unary minus (-a) + Minus, + /// Unary plus (+a) + Plus, + /// AddressOf + AddressOf, + /// Await + Await + } + +} diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs new file mode 100644 index 0000000000..49acf4a3cd --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/VariableInitializer.cs @@ -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 +{ + /// + /// Identifier As Type = Expression + /// + 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(IAstVisitor 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); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 875ff210a5..aa830d455d 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -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 { 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); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 0cccd7a54d..d297fb2e0f 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -48,22 +48,30 @@ - + + + + + + + + + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 3de803f957..c3ad147afb 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -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 StartNode(ifElseStatement); WriteKeyword("If"); ifElseStatement.Condition.AcceptVisitor(this, data); + Space(); WriteKeyword("Then"); NewLine(); Indent(); @@ -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 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); + } + } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index bfd373a765..95c4db70a6 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -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 ((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: