diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs index 26876e4161..39d3878952 100644 --- a/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs @@ -30,5 +30,78 @@ namespace ICSharpCode.NRefactory.VB.Ast } } #endregion + + #region Builder methods + /// + /// Builds an member reference expression using this expression as target. + /// + public MemberAccessExpression Member(string memberName) + { + return new MemberAccessExpression { Target = this, Member = memberName }; + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(string methodName, IEnumerable arguments) + { + return Invoke(methodName, null, arguments); + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(string methodName, params Expression[] arguments) + { + return Invoke(methodName, null, arguments); + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(string methodName, IEnumerable typeArguments, IEnumerable arguments) + { + InvocationExpression ie = new InvocationExpression(); + MemberAccessExpression mre = new MemberAccessExpression(); + mre.Target = this; + mre.Member = methodName; + mre.TypeArguments.AddRange(typeArguments); + ie.Target = mre; + ie.Arguments.AddRange(arguments); + return ie; + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(IEnumerable arguments) + { + InvocationExpression ie = new InvocationExpression(); + ie.Target = this; + ie.Arguments.AddRange(arguments); + return ie; + } + + /// + /// Builds an invocation expression using this expression as target. + /// + public InvocationExpression Invoke(params Expression[] arguments) + { + InvocationExpression ie = new InvocationExpression(); + ie.Target = this; + ie.Arguments.AddRange(arguments); + return ie; + } + + public CastExpression CastTo(AstType type) + { + return new CastExpression { CastType = CastType.CType, Type = type, Expression = this }; + } + + public CastExpression CastTo(Type type) + { + return new CastExpression { CastType = CastType.CType, Type = AstType.Create(type), Expression = this }; + } + #endregion } } diff --git a/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs b/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs new file mode 100644 index 0000000000..19cf4db4ec --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs @@ -0,0 +1,68 @@ +// 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 QueryExpression : Expression + { + public AstNodeCollection QueryOperators { + get { return GetChildrenByRole(QueryOperator.QueryOperatorRole); } + } + + 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.VisitQueryExpression(this, data); + } + } + + public abstract class QueryOperator : AstNode + { + #region Null + public new static readonly QueryOperator Null = new NullQueryOperator(); + + sealed class NullQueryOperator : QueryOperator + { + public override bool IsNull { + get { + return true; + } + } + + public override S AcceptVisitor (IAstVisitor visitor, T data) + { + return default (S); + } + + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) + { + return other == null || other.IsNull; + } + } + #endregion + + public static readonly Role QueryOperatorRole = new Role("QueryOperator", QueryOperator.Null); + } + + public class FromQueryOperator : QueryOperator + { + + + protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) + { + throw new NotImplementedException(); + } + + public override S AcceptVisitor(IAstVisitor visitor, T data) + { + throw new NotImplementedException(); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs b/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs index 13ba3ee971..0fe6228a27 100644 --- a/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs +++ b/ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs @@ -70,38 +70,37 @@ namespace ICSharpCode.NRefactory.VB.Ast return new ComposedType { BaseType = this }.MakeArrayType(rank); } - // TODO : reimplement this -// /// -// /// Builds an expression that can be used to access a static member on this type. -// /// -// public MemberReferenceExpression Member(string memberName) -// { -// return new TypeReferenceExpression { Type = this }.Member(memberName); -// } -// -// /// -// /// Builds an invocation expression using this type as target. -// /// -// public InvocationExpression Invoke(string methodName, IEnumerable arguments) -// { -// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); -// } -// -// /// -// /// Builds an invocation expression using this type as target. -// /// -// public InvocationExpression Invoke(string methodName, params Expression[] arguments) -// { -// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); -// } -// -// /// -// /// Builds an invocation expression using this type as target. -// /// -// public InvocationExpression Invoke(string methodName, IEnumerable typeArguments, IEnumerable arguments) -// { -// return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments); -// } + /// + /// Builds an expression that can be used to access a static member on this type. + /// + public MemberAccessExpression Member(string memberName) + { + return new TypeReferenceExpression { Type = this }.Member(memberName); + } + + /// + /// Builds an invocation expression using this type as target. + /// + public InvocationExpression Invoke(string methodName, IEnumerable arguments) + { + return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); + } + + /// + /// Builds an invocation expression using this type as target. + /// + public InvocationExpression Invoke(string methodName, params Expression[] arguments) + { + return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); + } + + /// + /// Builds an invocation expression using this type as target. + /// + public InvocationExpression Invoke(string methodName, IEnumerable typeArguments, IEnumerable arguments) + { + return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments); + } public static AstType Create(Type type) { diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index aa830d455d..bf969a8430 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -107,5 +107,7 @@ namespace ICSharpCode.NRefactory.VB { S VisitSingleLineSubLambdaExpression(SingleLineSubLambdaExpression singleLineSubLambdaExpression, T data); S VisitMultiLineLambdaExpression(MultiLineLambdaExpression multiLineLambdaExpression, T data); S VisitSingleLineFunctionLambdaExpression(SingleLineFunctionLambdaExpression singleLineFunctionLambdaExpression, T data); + + S VisitQueryExpression(QueryExpression queryExpression, T data); } } diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index d297fb2e0f..2f3ab9777e 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -66,6 +66,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index c3ad147afb..ea01b11265 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -2307,6 +2307,16 @@ namespace ICSharpCode.NRefactory.VB return EndNode(multiLineLambdaExpression); } - + + public object VisitQueryExpression(QueryExpression queryExpression, object data) + { + StartNode(queryExpression); + + foreach (var op in queryExpression.QueryOperators) { + op.AcceptVisitor(this, data); + } + + return EndNode(queryExpression); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 95c4db70a6..3b0d7a1abd 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -469,13 +469,19 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitStackAllocExpression(CSharp.StackAllocExpression stackAllocExpression, object data) { - throw new NotImplementedException(); + return EndNode( + stackAllocExpression, + new InvocationExpression( + new IdentifierExpression() { Identifier = "__StackĄlloc" }, + new TypeReferenceExpression((AstType)stackAllocExpression.Type.AcceptVisitor(this, data)), + (Expression)stackAllocExpression.CountExpression.AcceptVisitor(this, data) + ) + ); } public AstNode VisitThisReferenceExpression(CSharp.ThisReferenceExpression thisReferenceExpression, object data) { - InstanceExpression result = new InstanceExpression(InstanceExpressionType.Me, ConvertLocation(thisReferenceExpression.StartLocation)); - + InstanceExpression result = new InstanceExpression(InstanceExpressionType.Me, ConvertLocation(thisReferenceExpression.StartLocation); return EndNode(thisReferenceExpression, result); } @@ -518,22 +524,22 @@ namespace ICSharpCode.NRefactory.VB.Visitors break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Increment: expr = new InvocationExpression(); - ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "Increment" }; + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "__Increment" }; ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.PostIncrement: expr = new InvocationExpression(); - ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "PostIncrement" }; + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "__PostIncrement" }; ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.Decrement: expr = new InvocationExpression(); - ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "Decrement" }; + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "__Decrement" }; ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.PostDecrement: expr = new InvocationExpression(); - ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "PostDecrement" }; + ((InvocationExpression)expr).Target = new IdentifierExpression() { Identifier = "__PostDecrement" }; ((InvocationExpression)expr).Arguments.Add((Expression)unaryOperatorExpression.Expression.AcceptVisitor(this, data)); break; case ICSharpCode.NRefactory.CSharp.UnaryOperatorType.AddressOf: @@ -562,7 +568,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitQueryExpression(CSharp.QueryExpression queryExpression, object data) { - throw new NotImplementedException(); + var expr = new QueryExpression(); + ConvertNodes(queryExpression.Clauses, expr.QueryOperators); + return EndNode(queryExpression, expr); } public AstNode VisitQueryContinuationClause(CSharp.QueryContinuationClause queryContinuationClause, object data)