Browse Source

started implementation of QueryExpression

newNRvisualizers
Siegfried Pammer 14 years ago
parent
commit
2e3d9fa7ab
  1. 73
      ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs
  2. 68
      ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs
  3. 63
      ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs
  4. 2
      ICSharpCode.NRefactory.VB/IAstVisitor.cs
  5. 1
      ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  6. 12
      ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
  7. 24
      ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs

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

@ -30,5 +30,78 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -30,5 +30,78 @@ namespace ICSharpCode.NRefactory.VB.Ast
}
}
#endregion
#region Builder methods
/// <summary>
/// Builds an member reference expression using this expression as target.
/// </summary>
public MemberAccessExpression Member(string memberName)
{
return new MemberAccessExpression { Target = this, Member = memberName };
}
/// <summary>
/// Builds an invocation expression using this expression as target.
/// </summary>
public InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments)
{
return Invoke(methodName, null, arguments);
}
/// <summary>
/// Builds an invocation expression using this expression as target.
/// </summary>
public InvocationExpression Invoke(string methodName, params Expression[] arguments)
{
return Invoke(methodName, null, arguments);
}
/// <summary>
/// Builds an invocation expression using this expression as target.
/// </summary>
public InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> 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;
}
/// <summary>
/// Builds an invocation expression using this expression as target.
/// </summary>
public InvocationExpression Invoke(IEnumerable<Expression> arguments)
{
InvocationExpression ie = new InvocationExpression();
ie.Target = this;
ie.Arguments.AddRange(arguments);
return ie;
}
/// <summary>
/// Builds an invocation expression using this expression as target.
/// </summary>
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
}
}

68
ICSharpCode.NRefactory.VB/Ast/Expressions/QueryExpression.cs

@ -0,0 +1,68 @@ @@ -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<QueryOperator> 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<T, S>(IAstVisitor<T, S> 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<T, S> (IAstVisitor<T, S> 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<QueryOperator> QueryOperatorRole = new Role<QueryOperator>("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<T, S>(IAstVisitor<T, S> visitor, T data)
{
throw new NotImplementedException();
}
}
}

63
ICSharpCode.NRefactory.VB/Ast/TypeName/AstType.cs

@ -70,38 +70,37 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -70,38 +70,37 @@ namespace ICSharpCode.NRefactory.VB.Ast
return new ComposedType { BaseType = this }.MakeArrayType(rank);
}
// TODO : reimplement this
// /// <summary>
// /// Builds an expression that can be used to access a static member on this type.
// /// </summary>
// public MemberReferenceExpression Member(string memberName)
// {
// return new TypeReferenceExpression { Type = this }.Member(memberName);
// }
//
// /// <summary>
// /// Builds an invocation expression using this type as target.
// /// </summary>
// public InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments)
// {
// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
// }
//
// /// <summary>
// /// Builds an invocation expression using this type as target.
// /// </summary>
// public InvocationExpression Invoke(string methodName, params Expression[] arguments)
// {
// return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
// }
//
// /// <summary>
// /// Builds an invocation expression using this type as target.
// /// </summary>
// public InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments)
// {
// return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments);
// }
/// <summary>
/// Builds an expression that can be used to access a static member on this type.
/// </summary>
public MemberAccessExpression Member(string memberName)
{
return new TypeReferenceExpression { Type = this }.Member(memberName);
}
/// <summary>
/// Builds an invocation expression using this type as target.
/// </summary>
public InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments)
{
return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
}
/// <summary>
/// Builds an invocation expression using this type as target.
/// </summary>
public InvocationExpression Invoke(string methodName, params Expression[] arguments)
{
return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
}
/// <summary>
/// Builds an invocation expression using this type as target.
/// </summary>
public InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments)
{
return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments);
}
public static AstType Create(Type type)
{

2
ICSharpCode.NRefactory.VB/IAstVisitor.cs

@ -107,5 +107,7 @@ namespace ICSharpCode.NRefactory.VB { @@ -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);
}
}

1
ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj

@ -66,6 +66,7 @@ @@ -66,6 +66,7 @@
<Compile Include="Ast\Expressions\NamedArgumentExpression.cs" />
<Compile Include="Ast\Expressions\ObjectCreationExpression.cs" />
<Compile Include="Ast\Expressions\ParenthesizedExpression.cs" />
<Compile Include="Ast\Expressions\QueryExpression.cs" />
<Compile Include="Ast\Expressions\SimpleNameExpression.cs" />
<Compile Include="Ast\Expressions\PrimitiveExpression.cs" />
<Compile Include="Ast\Expressions\TypeOfIsExpression.cs" />

12
ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -2307,6 +2307,16 @@ namespace ICSharpCode.NRefactory.VB @@ -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);
}
}
}

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

@ -469,13 +469,19 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -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 @@ -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 @@ -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)

Loading…
Cancel
Save