diff --git a/ILSpy/VB/VBLanguage.cs b/ILSpy/VB/VBLanguage.cs index 64b645c1d..e2a5327d4 100644 --- a/ILSpy/VB/VBLanguage.cs +++ b/ILSpy/VB/VBLanguage.cs @@ -173,7 +173,7 @@ namespace ICSharpCode.ILSpy.VB public ClassType GetClassTypeForAstType(ICSharpCode.NRefactory.CSharp.AstType type) { - var definition = type.Annotations.OfType().First(); + var definition = type.Annotations.OfType().First().ResolveOrThrow(); if (definition.IsClass) return ClassType.Class; diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Ast/AstNode.cs b/NRefactory/ICSharpCode.NRefactory.VB/Ast/AstNode.cs index 6be228446..2fd9aa924 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/Ast/AstNode.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/Ast/AstNode.cs @@ -681,8 +681,8 @@ namespace ICSharpCode.NRefactory.VB public static readonly Role Argument = new Role("Argument", Ast.Expression.Null); public static readonly Role Type = new Role("Type", AstType.Null); public static readonly Role Expression = new Role("Expression", Ast.Expression.Null); -// public static readonly Role TargetExpression = new Role("Target", CSharp.Expression.Null); -// public readonly static Role Condition = new Role("Condition", CSharp.Expression.Null); + public static readonly Role TargetExpression = new Role("Target", Ast.Expression.Null); + public readonly static Role Condition = new Role("Condition", Ast.Expression.Null); // public static readonly Role TypeParameter = new Role("TypeParameter"); public static readonly Role TypeArgument = new Role("TypeArgument", AstType.Null); diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Ast/Enums.cs b/NRefactory/ICSharpCode.NRefactory.VB/Ast/Enums.cs index 0746032c2..154fb58c2 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/Ast/Enums.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/Ast/Enums.cs @@ -90,72 +90,6 @@ namespace ICSharpCode.NRefactory.VB.Ast ExclusiveOr, } - 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 enum CastType { /// diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index d15756e3e..0764501c1 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -2,6 +2,7 @@ // 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 { @@ -30,4 +31,184 @@ namespace ICSharpCode.NRefactory.VB.Ast } #endregion } + + public class BinaryOperatorExpression : Expression + { + public readonly static Role LeftExpressionRole = new Role("Left"); + 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 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); + } + } } diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs b/NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs new file mode 100644 index 000000000..89e6d4ec1 --- /dev/null +++ b/NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/IdentifierExpression.cs @@ -0,0 +1,29 @@ +// 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 IdentifierExpression : Expression + { + public Identifier Identifier { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstNodeCollection TypeArguments { + get { return GetChildrenByRole(Roles.TypeArgument); } + } + + 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.VisitIdentifierExpression(this, data); + } + } +} diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs b/NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs index 73610fe70..b01ac9843 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs @@ -79,7 +79,7 @@ namespace ICSharpCode.NRefactory.VB.Ast protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { BlockStatement o = other as BlockStatement; - return o != null && !o.IsNull && this.Statements.DoMatch(o.Statements, match); + return o != null && !(o is CatchBlock) && !o.IsNull && this.Statements.DoMatch(o.Statements, match); } #region Builder methods @@ -122,4 +122,6 @@ namespace ICSharpCode.NRefactory.VB.Ast return this.Statements.GetEnumerator(); } } + + } diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs b/NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs index c20407051..07bb02ede 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/Statement.cs @@ -129,4 +129,312 @@ namespace ICSharpCode.NRefactory.VB.Ast throw new NotImplementedException(); } } + + /// + /// Label: + /// + public class LabelDeclarationStatement : Statement + { + public Identifier Label { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public VBTokenNode Colon { + get { return GetChildByRole(Roles.Colon); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitLabelDeclarationStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + LabelDeclarationStatement o = other as LabelDeclarationStatement; + return o != null && MatchString(this.Label.Name, o.Label.Name); + } + } + + /// + /// ( Dim | Static | Const ) VariableDeclarator { , VariableDeclarator } + /// + public class LocalDeclarationStatement : Statement + { + public AstNodeCollection Variables { + get { return GetChildrenByRole(VariableDeclarator.VariableDeclaratorRole); } + } + + public Modifiers Modifiers { + get { return AttributedNode.GetModifiers(this); } + set { AttributedNode.SetModifiers(this, value); } + } + + public VBModifierToken ModifierToken { + get { return GetChildByRole(AttributedNode.ModifierRole); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitLocalDeclarationStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + /// + /// With Expression
+ /// Block
+ /// End With + ///
+ public class WithStatement : Statement + { + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitWithStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + /// + /// SyncLock Expression
+ /// Block
+ /// End SyncLock + ///
+ public class SyncLockStatement : Statement + { + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitSyncLockStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + /// + /// SyncLock Expression
+ /// Block
+ /// End SyncLock + ///
+ public class TryStatement : Statement + { + public static readonly Role FinallyBlockRole = new Role("FinallyBlock", Ast.BlockStatement.Null); + + public BlockStatement Body { + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } + } + + public AstNodeCollection CatchBlocks { + get { return GetChildrenByRole(CatchBlock.CatchBlockRole); } + } + + public BlockStatement FinallyBlock { + get { return GetChildByRole(FinallyBlockRole); } + set { SetChildByRole(FinallyBlockRole, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitTryStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + public class CatchBlock : BlockStatement + { + public static readonly Role CatchBlockRole = new Role("CatchBlockRole"); + + public Identifier ExceptionVariable { + get { return GetChildByRole(Roles.Identifier); } + set { SetChildByRole(Roles.Identifier, value); } + } + + public AstType ExceptionType { + get { return GetChildByRole(Roles.Type); } + set { SetChildByRole(Roles.Type, value); } + } + + public Expression WhenExpression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitCatchBlock(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + public class IfElseStatement : Statement + { + public static readonly Role FalseStatementRole = new Role("False", Ast.Statement.Null); + public static readonly Role TrueStatementRole = new Role("True", Ast.Statement.Null); + + public Expression Condition { + get { return GetChildByRole(Roles.Condition); } + set { SetChildByRole(Roles.Condition, value); } + } + + public Statement Body { + get { return GetChildByRole(TrueStatementRole); } + set { SetChildByRole(TrueStatementRole, value); } + } + + public Statement ElseBlock { + get { return GetChildByRole(FalseStatementRole); } + set { SetChildByRole(FalseStatementRole, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitIfElseStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + throw new NotImplementedException(); + } + } + + /// + /// Expression + /// + public class ExpressionStatement : Statement + { + public Expression Expression { + get { return GetChildByRole (Roles.Expression); } + set { SetChildByRole (Roles.Expression, value); } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return visitor.VisitExpressionStatement(this, data); + } + + public ExpressionStatement() + { + } + + public ExpressionStatement(Expression expression) + { + this.Expression = expression; + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ExpressionStatement o = other as ExpressionStatement; + return o != null && this.Expression.DoMatch(o.Expression, match); + } + } + + /// + /// Throw Expression + /// + public class ThrowStatement : Statement + { + public VBTokenNode ThrowToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public ThrowStatement() + { + } + + public ThrowStatement(Expression expression) + { + AddChild (expression, Roles.Expression); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitThrowStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ThrowStatement o = other as ThrowStatement; + return o != null && this.Expression.DoMatch(o.Expression, match); + } + } + + /// + /// Return Expression + /// + public class ReturnStatement : Statement + { + public VBTokenNode ReturnToken { + get { return GetChildByRole (Roles.Keyword); } + } + + public Expression Expression { + get { return GetChildByRole(Roles.Expression); } + set { SetChildByRole(Roles.Expression, value); } + } + + public ReturnStatement() + { + } + + public ReturnStatement(Expression expression) + { + AddChild (expression, Roles.Expression); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + return visitor.VisitReturnStatement(this, data); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + ReturnStatement o = other as ReturnStatement; + return o != null && this.Expression.DoMatch(o.Expression, match); + } + } + } diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs b/NRefactory/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs index 87a2f53e2..be9751b6a 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/Ast/TypeMembers/Accessor.cs @@ -26,8 +26,8 @@ namespace ICSharpCode.NRefactory.VB.Ast } public BlockStatement Body { - get { return GetChildByRole (Roles.Body); } - set { SetChildByRole (Roles.Body, value); } + get { return GetChildByRole(Roles.Body); } + set { SetChildByRole(Roles.Body, value); } } public AstNodeCollection Parameters { diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs b/NRefactory/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs index 427d3e53d..205058261 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/Ast/VBModifierToken.cs @@ -46,6 +46,7 @@ namespace ICSharpCode.NRefactory.VB.Ast new KeyValuePair(Modifiers.Overridable, "Overridable".Length), new KeyValuePair(Modifiers.NotInheritable, "NotInheritable".Length), new KeyValuePair(Modifiers.NotOverridable, "NotOverridable".Length), + new KeyValuePair(Modifiers.Dim, "Dim".Length), new KeyValuePair(Modifiers.Const, "Const".Length), new KeyValuePair(Modifiers.Shared, "Shared".Length), new KeyValuePair(Modifiers.Static, "Static".Length), @@ -62,7 +63,6 @@ namespace ICSharpCode.NRefactory.VB.Ast new KeyValuePair(Modifiers.ByVal, "ByVal".Length), new KeyValuePair(Modifiers.ByRef, "ByRef".Length), new KeyValuePair(Modifiers.ParamArray, "ParamArray".Length), - // even though it's used for patterns only, it needs to be in this table to be usable in the AST new KeyValuePair(Modifiers.Any, "Any".Length) }; diff --git a/NRefactory/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/NRefactory/ICSharpCode.NRefactory.VB/IAstVisitor.cs index 394b3ae2a..e96f9c117 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -54,6 +54,22 @@ namespace ICSharpCode.NRefactory.VB { S VisitGetXmlNamespaceExpression(GetXmlNamespaceExpression getXmlNamespaceExpression, T data); S VisitMemberAccessExpression(MemberAccessExpression memberAccessExpression, T data); S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data); + S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, T data); + S VisitAssignmentExpression(AssignmentExpression assignmentExpression, T data); + S VisitIdentifierExpression(IdentifierExpression identifierExpression, T data); + S VisitInvocationExpression(InvocationExpression invocationExpression, T data); + + // Statement scope + S VisitLabelDeclarationStatement(LabelDeclarationStatement labelDeclarationStatement, T data); + S VisitLocalDeclarationStatement(LocalDeclarationStatement localDeclarationStatement, T data); + S VisitExpressionStatement(ExpressionStatement expressionStatement, T data); + S VisitWithStatement(WithStatement withStatement, T data); + S VisitSyncLockStatement(SyncLockStatement syncLockStatement, T data); + S VisitIfElseStatement(IfElseStatement ifElseStatement, T data); + S VisitTryStatement(TryStatement tryStatement, T data); + S VisitThrowStatement(ThrowStatement throwStatement, T data); + S VisitCatchBlock(CatchBlock catchBlock, T data); + S VisitReturnStatement(ReturnStatement returnStatement, T data); // TypeName S VisitPrimitiveType(PrimitiveType primitiveType, T data); diff --git a/NRefactory/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/NRefactory/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index 5034fbfd7..427cd102d 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/NRefactory/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -51,6 +51,7 @@ + diff --git a/NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 7d069f9fd..6a183a7ff 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -67,7 +67,12 @@ namespace ICSharpCode.NRefactory.VB public object VisitBlockStatement(BlockStatement blockStatement, object data) { - throw new NotImplementedException(); + StartNode(blockStatement); + foreach (var stmt in blockStatement) { + stmt.AcceptVisitor(this, data); + NewLine(); + } + return EndNode(blockStatement); } public object VisitPatternPlaceholder(AstNode placeholder, Pattern pattern, object data) @@ -513,9 +518,9 @@ namespace ICSharpCode.NRefactory.VB WriteHandlesClause(methodDeclaration.HandlesClause); WriteImplementsClause(methodDeclaration.ImplementsClause); NewLine(); - - // TODO Body - + Indent(); + WriteBlock(methodDeclaration.Body); + Unindent(); WriteKeyword("End"); if (methodDeclaration.IsSub) WriteKeyword("Sub"); @@ -1319,5 +1324,252 @@ namespace ICSharpCode.NRefactory.VB return EndNode(propertyDeclaration); } + + public object VisitLabelDeclarationStatement(LabelDeclarationStatement labelDeclarationStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitLocalDeclarationStatement(LocalDeclarationStatement localDeclarationStatement, object data) + { + StartNode(localDeclarationStatement); + + WriteModifiers(new [] { localDeclarationStatement.ModifierToken }); + WriteCommaSeparatedList(localDeclarationStatement.Variables); + + return EndNode(localDeclarationStatement); + } + + public object VisitWithStatement(WithStatement withStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitSyncLockStatement(SyncLockStatement syncLockStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitTryStatement(TryStatement tryStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitCatchBlock(CatchBlock catchBlock, object data) + { + throw new NotImplementedException(); + } + + public object VisitExpressionStatement(ExpressionStatement expressionStatement, object data) + { + StartNode(expressionStatement); + expressionStatement.Expression.AcceptVisitor(this, data); + return EndNode(expressionStatement); + } + + public object VisitThrowStatement(ThrowStatement throwStatement, object data) + { + throw new NotImplementedException(); + } + + public object VisitIfElseStatement(IfElseStatement ifElseStatement, object data) + { + StartNode(ifElseStatement); + WriteKeyword("If"); + ifElseStatement.Condition.AcceptVisitor(this, data); + WriteKeyword("Then"); + NewLine(); + Indent(); + ifElseStatement.Body.AcceptVisitor(this, data); + Unindent(); + if (!ifElseStatement.ElseBlock.IsNull) { + WriteKeyword("Else"); + NewLine(); + Indent(); + ifElseStatement.ElseBlock.AcceptVisitor(this, data); + Unindent(); + } + WriteKeyword("End"); + WriteKeyword("If"); + return EndNode(ifElseStatement); + } + + public object VisitReturnStatement(ReturnStatement returnStatement, object data) + { + StartNode(returnStatement); + WriteKeyword("Return"); + returnStatement.Expression.AcceptVisitor(this, data); + return EndNode(returnStatement); + } + + public object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) + { + StartNode(binaryOperatorExpression); + binaryOperatorExpression.Left.AcceptVisitor(this, data); + Space(); + switch (binaryOperatorExpression.Operator) { + case BinaryOperatorType.None: + + break; + case BinaryOperatorType.BitwiseAnd: + + break; + case BinaryOperatorType.BitwiseOr: + + break; + case BinaryOperatorType.LogicalAnd: + + break; + case BinaryOperatorType.LogicalOr: + + break; + case BinaryOperatorType.ExclusiveOr: + + break; + case BinaryOperatorType.GreaterThan: + + break; + case BinaryOperatorType.GreaterThanOrEqual: + + break; + case BinaryOperatorType.Equality: + WriteToken("=", BinaryOperatorExpression.Roles.Assign); + break; + case BinaryOperatorType.InEquality: + + break; + case BinaryOperatorType.LessThan: + + break; + case BinaryOperatorType.LessThanOrEqual: + + break; + case BinaryOperatorType.Add: + + break; + case BinaryOperatorType.Subtract: + + break; + case BinaryOperatorType.Multiply: + + break; + case BinaryOperatorType.Divide: + + break; + case BinaryOperatorType.Modulus: + + break; + case BinaryOperatorType.DivideInteger: + + break; + case BinaryOperatorType.Power: + + break; + case BinaryOperatorType.Concat: + + break; + case BinaryOperatorType.ShiftLeft: + + break; + case BinaryOperatorType.ShiftRight: + + break; + case BinaryOperatorType.ReferenceEquality: + + break; + case BinaryOperatorType.ReferenceInequality: + + break; + case BinaryOperatorType.Like: + + break; + case BinaryOperatorType.NullCoalescing: + + break; + case BinaryOperatorType.DictionaryAccess: + + break; + default: + throw new Exception("Invalid value for BinaryOperatorType"); + } + Space(); + binaryOperatorExpression.Right.AcceptVisitor(this, data); + return EndNode(binaryOperatorExpression); + } + + public object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) + { + StartNode(identifierExpression); + identifierExpression.Identifier.AcceptVisitor(this, data); + WriteTypeArguments(identifierExpression.TypeArguments); + return EndNode(identifierExpression); + } + + public object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) + { + StartNode(assignmentExpression); + assignmentExpression.Left.AcceptVisitor(this, data); + Space(); + switch (assignmentExpression.Operator) { + case AssignmentOperatorType.None: + + break; + case AssignmentOperatorType.Assign: + WriteToken("=", AssignmentExpression.Roles.Assign); + break; + case AssignmentOperatorType.Add: + + break; + case AssignmentOperatorType.Subtract: + + break; + case AssignmentOperatorType.Multiply: + + break; + case AssignmentOperatorType.Divide: + + break; + case AssignmentOperatorType.Modulus: + + break; + case AssignmentOperatorType.Power: + + break; + case AssignmentOperatorType.DivideInteger: + + break; + case AssignmentOperatorType.ConcatString: + + break; + case AssignmentOperatorType.ShiftLeft: + + break; + case AssignmentOperatorType.ShiftRight: + + break; + case AssignmentOperatorType.BitwiseAnd: + + break; + case AssignmentOperatorType.BitwiseOr: + + break; + case AssignmentOperatorType.ExclusiveOr: + + break; + default: + throw new Exception("Invalid value for AssignmentOperatorType"); + } + Space(); + assignmentExpression.Right.AcceptVisitor(this, data); + return EndNode(assignmentExpression); + } + + public object VisitInvocationExpression(InvocationExpression invocationExpression, object data) + { + StartNode(invocationExpression); + invocationExpression.Target.AcceptVisitor(this, data); + WriteCommaSeparatedListInParenthesis(invocationExpression.Arguments, false); + return EndNode(invocationExpression); + } } } diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 8a0e33d78..ebeddbabf 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -56,7 +56,54 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitAssignmentExpression(CSharp.AssignmentExpression assignmentExpression, object data) { - throw new NotImplementedException(); + var left = (Expression)assignmentExpression.Left.AcceptVisitor(this, data); + var op = AssignmentOperatorType.None; + + switch (assignmentExpression.Operator) { + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Assign: + op = AssignmentOperatorType.Assign; + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Add: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Subtract: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Multiply: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Divide: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Modulus: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftLeft: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ShiftRight: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseAnd: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.BitwiseOr: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.ExclusiveOr: + + break; + case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Any: + + break; + default: + throw new Exception("Invalid value for AssignmentOperatorType"); + } + + var right = (Expression)assignmentExpression.Right.AcceptVisitor(this, data); + + var expr = new AssignmentExpression(left, op, right); + return EndNode(assignmentExpression, expr); } public AstNode VisitBaseReferenceExpression(CSharp.BaseReferenceExpression baseReferenceExpression, object data) @@ -68,7 +115,76 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitBinaryOperatorExpression(CSharp.BinaryOperatorExpression binaryOperatorExpression, object data) { - throw new NotImplementedException(); + var left = (Expression)binaryOperatorExpression.Left.AcceptVisitor(this, data); + var op = BinaryOperatorType.None; + var right = (Expression)binaryOperatorExpression.Right.AcceptVisitor(this, data); + + switch (binaryOperatorExpression.Operator) { + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.BitwiseAnd: + op = BinaryOperatorType.BitwiseAnd; + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.BitwiseOr: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ConditionalAnd: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ConditionalOr: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ExclusiveOr: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.GreaterThan: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.GreaterThanOrEqual: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Equality: + op = BinaryOperatorType.Equality; + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.InEquality: + op = BinaryOperatorType.InEquality; + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.LessThan: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.LessThanOrEqual: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Add: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Subtract: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Multiply: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Divide: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Modulus: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ShiftLeft: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ShiftRight: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.NullCoalescing: + + break; + case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Any: + + break; + default: + throw new Exception("Invalid value for BinaryOperatorType"); + } + + return EndNode(binaryOperatorExpression, new BinaryOperatorExpression(left, op, right)); } public AstNode VisitCastExpression(CSharp.CastExpression castExpression, object data) @@ -98,7 +214,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitIdentifierExpression(CSharp.IdentifierExpression identifierExpression, object data) { - throw new NotImplementedException(); + var expr = new IdentifierExpression(); + expr.Identifier = new Identifier(identifierExpression.Identifier, AstLocation.Empty); + ConvertNodes(identifierExpression.TypeArguments, expr.TypeArguments); + + return EndNode(identifierExpression, expr); } public AstNode VisitIndexerExpression(CSharp.IndexerExpression indexerExpression, object data) @@ -108,7 +228,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitInvocationExpression(CSharp.InvocationExpression invocationExpression, object data) { - throw new NotImplementedException(); + var expr = new InvocationExpression( + (Expression)invocationExpression.Target.AcceptVisitor(this, data)); + ConvertNodes(invocationExpression.Arguments, expr.Arguments); + + return EndNode(invocationExpression, expr); } public AstNode VisitIsExpression(CSharp.IsExpression isExpression, object data) @@ -139,7 +263,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitNullReferenceExpression(CSharp.NullReferenceExpression nullReferenceExpression, object data) { - throw new NotImplementedException(); + return EndNode(nullReferenceExpression, new PrimitiveExpression(null)); } public AstNode VisitObjectCreateExpression(CSharp.ObjectCreateExpression objectCreateExpression, object data) @@ -403,7 +527,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitBlockStatement(CSharp.BlockStatement blockStatement, object data) { - return null; + var block = new BlockStatement(); + ConvertNodes(blockStatement, block.Statements); + + return EndNode(blockStatement, block); } public AstNode VisitBreakStatement(CSharp.BreakStatement breakStatement, object data) @@ -433,7 +560,8 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitExpressionStatement(CSharp.ExpressionStatement expressionStatement, object data) { - throw new NotImplementedException(); + var expr = new ExpressionStatement((Expression)expressionStatement.Expression.AcceptVisitor(this, data)); + return EndNode(expressionStatement, expr); } public AstNode VisitFixedStatement(CSharp.FixedStatement fixedStatement, object data) @@ -468,7 +596,13 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitIfElseStatement(CSharp.IfElseStatement ifElseStatement, object data) { - throw new NotImplementedException(); + var stmt = new IfElseStatement(); + + stmt.Condition = (Expression)ifElseStatement.Condition.AcceptVisitor(this, data); + stmt.Body = (Statement)ifElseStatement.TrueStatement.AcceptVisitor(this, data); + stmt.ElseBlock = (Statement)ifElseStatement.FalseStatement.AcceptVisitor(this, data); + + return EndNode(ifElseStatement, stmt); } public AstNode VisitLabelStatement(CSharp.LabelStatement labelStatement, object data) @@ -483,7 +617,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitReturnStatement(CSharp.ReturnStatement returnStatement, object data) { - throw new NotImplementedException(); + var stmt = new ReturnStatement((Expression)returnStatement.Expression.AcceptVisitor(this, data)); + + return EndNode(returnStatement, stmt); } public AstNode VisitSwitchStatement(CSharp.SwitchStatement switchStatement, object data) @@ -533,7 +669,11 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitVariableDeclarationStatement(CSharp.VariableDeclarationStatement variableDeclarationStatement, object data) { - throw new NotImplementedException(); + var decl = new LocalDeclarationStatement(); + decl.Modifiers = Modifiers.Dim; + ConvertNodes(variableDeclarationStatement.Variables, decl.Variables); + + return EndNode(variableDeclarationStatement, decl); } public AstNode VisitWhileStatement(CSharp.WhileStatement whileStatement, object data) @@ -569,6 +709,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors ConvertNodes(constructorDeclaration.Attributes, result.Attributes); ConvertNodes(constructorDeclaration.ModifierTokens, result.ModifierTokens); ConvertNodes(constructorDeclaration.Parameters, result.Parameters); + result.Body = (BlockStatement)constructorDeclaration.Body.AcceptVisitor(this, data); return EndNode(constructorDeclaration, result); } @@ -633,10 +774,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors decl.Setter = (Accessor)indexerDeclaration.Setter.AcceptVisitor(this, data); if (!decl.Setter.IsNull) { -// decl.Setter.Parameters.Add(new ParameterDeclaration() { -// Name = new Identifier("value", AstLocation.Empty), -// Type = (AstType)indexerDeclaration.ReturnType.AcceptVisitor(this, data), -// }); + decl.Setter.Parameters.Add(new ParameterDeclaration() { + Name = new Identifier("value", AstLocation.Empty), + Type = (AstType)indexerDeclaration.ReturnType.AcceptVisitor(this, data), + }); } return EndNode(indexerDeclaration, decl); @@ -659,6 +800,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors methodDeclaration.Name)); if (!result.IsSub) result.ReturnType = (AstType)methodDeclaration.ReturnType.AcceptVisitor(this, data); + result.Body = (BlockStatement)methodDeclaration.Body.AcceptVisitor(this, data); return EndNode(methodDeclaration, result); }