Browse Source

add support for EventDeclaration and some more binary operators

newNRvisualizers
Siegfried Pammer 14 years ago
parent
commit
48774e40e4
  1. 5
      ICSharpCode.NRefactory.VB/Ast/Enums.cs
  2. 2
      ICSharpCode.NRefactory.VB/Ast/Expressions/Expression.cs
  3. 59
      ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs
  4. 4
      ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs
  5. 1
      ICSharpCode.NRefactory.VB/IAstVisitor.cs
  6. 1
      ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  7. 144
      ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
  8. 68
      ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs

5
ICSharpCode.NRefactory.VB/Ast/Enums.cs

@ -76,7 +76,6 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -76,7 +76,6 @@ namespace ICSharpCode.NRefactory.VB.Ast
Subtract,
Multiply,
Divide,
Modulus,
Power, // (VB only)
DivideInteger, // (VB only)
@ -84,10 +83,6 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -84,10 +83,6 @@ namespace ICSharpCode.NRefactory.VB.Ast
ShiftLeft,
ShiftRight,
BitwiseAnd,
BitwiseOr,
ExclusiveOr,
}
public enum CastType

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

@ -35,6 +35,7 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -35,6 +35,7 @@ namespace ICSharpCode.NRefactory.VB.Ast
public class BinaryOperatorExpression : Expression
{
public readonly static Role<Expression> LeftExpressionRole = new Role<Expression>("Left");
public readonly static Role<VBTokenNode> OperatorRole = new Role<VBTokenNode>("Operator");
public readonly static Role<Expression> RightExpressionRole = new Role<Expression>("Right");
public BinaryOperatorExpression(Expression left, BinaryOperatorType type, Expression right)
@ -136,6 +137,7 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -136,6 +137,7 @@ namespace ICSharpCode.NRefactory.VB.Ast
public class AssignmentExpression : Expression
{
public readonly static Role<Expression> LeftExpressionRole = BinaryOperatorExpression.LeftExpressionRole;
public readonly static Role<VBTokenNode> OperatorRole = BinaryOperatorExpression.OperatorRole;
public readonly static Role<Expression> RightExpressionRole = BinaryOperatorExpression.RightExpressionRole;
public AssignmentExpression(Expression left, AssignmentOperatorType type, Expression right)

59
ICSharpCode.NRefactory.VB/Ast/TypeMembers/EventDeclaration.cs

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
// 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 EventDeclaration : MemberDeclaration
{
public bool IsCustom { get; set; }
public static readonly Role<Accessor> AddHandlerRole = new Role<Accessor>("AddHandler", Accessor.Null);
public static readonly Role<Accessor> RemoveHandlerRole = new Role<Accessor>("RemoveHandler", Accessor.Null);
public static readonly Role<Accessor> RaiseEventRole = new Role<Accessor>("RaiseEvent", Accessor.Null);
public Identifier Name {
get { return GetChildByRole(Roles.Identifier); }
set { SetChildByRole(Roles.Identifier, value); }
}
public AstType ReturnType {
get { return GetChildByRole(Roles.Type); }
set { SetChildByRole(Roles.Type, value); }
}
public AstNodeCollection<ParameterDeclaration> Parameters {
get { return GetChildrenByRole(Roles.Parameter); }
}
public AstNodeCollection<InterfaceMemberSpecifier> ImplementsClause {
get { return GetChildrenByRole(InterfaceMemberSpecifier.InterfaceMemberSpecifierRole); }
}
public Accessor AddHandlerBlock {
get { return GetChildByRole(AddHandlerRole); }
set { SetChildByRole(AddHandlerRole, value); }
}
public Accessor RemoveHandlerBlock {
get { return GetChildByRole(RemoveHandlerRole); }
set { SetChildByRole(RemoveHandlerRole, value); }
}
public Accessor RaiseEventBlock {
get { return GetChildByRole(RaiseEventRole); }
set { SetChildByRole(RaiseEventRole, value); }
}
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
{
throw new NotImplementedException();
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitEventDeclaration(this, data);
}
}
}

4
ICSharpCode.NRefactory.VB/Ast/TypeMembers/MethodDeclaration.cs

@ -69,8 +69,4 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -69,8 +69,4 @@ namespace ICSharpCode.NRefactory.VB.Ast
return visitor.VisitMethodDeclaration(this, data);
}
}
}

1
ICSharpCode.NRefactory.VB/IAstVisitor.cs

@ -40,6 +40,7 @@ namespace ICSharpCode.NRefactory.VB { @@ -40,6 +40,7 @@ namespace ICSharpCode.NRefactory.VB {
S VisitVariableIdentifier(VariableIdentifier variableIdentifier, T data);
S VisitAccessor(Accessor accessor, T data);
S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data);
S VisitEventDeclaration(EventDeclaration eventDeclaration, T data);
// Expression scope
S VisitIdentifier(Identifier identifier, T data);

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

@ -87,6 +87,7 @@ @@ -87,6 +87,7 @@
<Compile Include="Ast\Statements\Statement.cs" />
<Compile Include="Ast\TypeMembers\Accessor.cs" />
<Compile Include="Ast\TypeMembers\ConstructorDeclaration.cs" />
<Compile Include="Ast\TypeMembers\EventDeclaration.cs" />
<Compile Include="Ast\TypeMembers\FieldDeclaration.cs" />
<Compile Include="Ast\TypeMembers\MethodDeclaration.cs" />
<Compile Include="Ast\TypeMembers\PropertyDeclaration.cs" />

144
ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -1285,6 +1285,12 @@ namespace ICSharpCode.NRefactory.VB @@ -1285,6 +1285,12 @@ namespace ICSharpCode.NRefactory.VB
WriteKeyword("Get");
} else if (accessor.Role == PropertyDeclaration.SetterRole) {
WriteKeyword("Set");
} else if (accessor.Role == EventDeclaration.AddHandlerRole) {
WriteKeyword("AddHandler");
} else if (accessor.Role == EventDeclaration.RemoveHandlerRole) {
WriteKeyword("RemoveHandler");
} else if (accessor.Role == EventDeclaration.RaiseEventRole) {
WriteKeyword("RaiseEvent");
}
if (accessor.Parameters.Any())
WriteCommaSeparatedListInParenthesis(accessor.Parameters, false);
@ -1298,6 +1304,12 @@ namespace ICSharpCode.NRefactory.VB @@ -1298,6 +1304,12 @@ namespace ICSharpCode.NRefactory.VB
WriteKeyword("Get");
} else if (accessor.Role == PropertyDeclaration.SetterRole) {
WriteKeyword("Set");
} else if (accessor.Role == EventDeclaration.AddHandlerRole) {
WriteKeyword("AddHandler");
} else if (accessor.Role == EventDeclaration.RemoveHandlerRole) {
WriteKeyword("RemoveHandler");
} else if (accessor.Role == EventDeclaration.RaiseEventRole) {
WriteKeyword("RaiseEvent");
}
NewLine();
@ -1431,89 +1443,83 @@ namespace ICSharpCode.NRefactory.VB @@ -1431,89 +1443,83 @@ namespace ICSharpCode.NRefactory.VB
binaryOperatorExpression.Left.AcceptVisitor(this, data);
Space();
switch (binaryOperatorExpression.Operator) {
case BinaryOperatorType.None:
break;
case BinaryOperatorType.BitwiseAnd:
WriteKeyword("And");
break;
case BinaryOperatorType.BitwiseOr:
WriteKeyword("Or");
break;
case BinaryOperatorType.LogicalAnd:
WriteKeyword("AndAlso");
break;
case BinaryOperatorType.LogicalOr:
WriteKeyword("OrElse");
break;
case BinaryOperatorType.ExclusiveOr:
WriteKeyword("Xor");
break;
case BinaryOperatorType.GreaterThan:
WriteToken(">", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.GreaterThanOrEqual:
WriteToken(">=", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.Equality:
WriteToken("=", BinaryOperatorExpression.Roles.Assign);
WriteToken("=", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.InEquality:
WriteToken("<>", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.LessThan:
WriteToken("<", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.LessThanOrEqual:
WriteToken("<=", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.Add:
WriteToken("+", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.Subtract:
WriteToken("-", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.Multiply:
WriteToken("*", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.Divide:
WriteToken("/", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.Modulus:
WriteKeyword("Mod");
break;
case BinaryOperatorType.DivideInteger:
WriteToken("\\", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.Power:
WriteToken("*", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.Concat:
WriteToken("&", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.ShiftLeft:
WriteToken("<<", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.ShiftRight:
WriteToken(">>", BinaryOperatorExpression.OperatorRole);
break;
case BinaryOperatorType.ReferenceEquality:
WriteKeyword("Is");
break;
case BinaryOperatorType.ReferenceInequality:
WriteKeyword("IsNot");
break;
case BinaryOperatorType.Like:
break;
case BinaryOperatorType.NullCoalescing:
WriteKeyword("Like");
break;
case BinaryOperatorType.DictionaryAccess:
WriteToken("!", BinaryOperatorExpression.OperatorRole);
break;
default:
throw new Exception("Invalid value for BinaryOperatorType");
throw new Exception("Invalid value for BinaryOperatorType: " + binaryOperatorExpression.Operator);
}
Space();
binaryOperatorExpression.Right.AcceptVisitor(this, data);
@ -1534,53 +1540,39 @@ namespace ICSharpCode.NRefactory.VB @@ -1534,53 +1540,39 @@ namespace ICSharpCode.NRefactory.VB
assignmentExpression.Left.AcceptVisitor(this, data);
Space();
switch (assignmentExpression.Operator) {
case AssignmentOperatorType.None:
break;
case AssignmentOperatorType.Assign:
WriteToken("=", AssignmentExpression.Roles.Assign);
WriteToken("=", AssignmentExpression.OperatorRole);
break;
case AssignmentOperatorType.Add:
WriteToken("+=", AssignmentExpression.OperatorRole);
break;
case AssignmentOperatorType.Subtract:
WriteToken("-=", AssignmentExpression.OperatorRole);
break;
case AssignmentOperatorType.Multiply:
WriteToken("*=", AssignmentExpression.OperatorRole);
break;
case AssignmentOperatorType.Divide:
break;
case AssignmentOperatorType.Modulus:
WriteToken("/=", AssignmentExpression.OperatorRole);
break;
case AssignmentOperatorType.Power:
WriteToken("^=", AssignmentExpression.OperatorRole);
break;
case AssignmentOperatorType.DivideInteger:
WriteToken("\\=", AssignmentExpression.OperatorRole);
break;
break;
case AssignmentOperatorType.ConcatString:
WriteToken("&=", AssignmentExpression.OperatorRole);
break;
case AssignmentOperatorType.ShiftLeft:
WriteToken("<<=", AssignmentExpression.OperatorRole);
break;
case AssignmentOperatorType.ShiftRight:
break;
case AssignmentOperatorType.BitwiseAnd:
break;
case AssignmentOperatorType.BitwiseOr:
break;
case AssignmentOperatorType.ExclusiveOr:
WriteToken(">>=", AssignmentExpression.OperatorRole);
break;
default:
throw new Exception("Invalid value for AssignmentOperatorType");
throw new Exception("Invalid value for AssignmentOperatorType: " + assignmentExpression.Operator);
}
Space();
assignmentExpression.Right.AcceptVisitor(this, data);
@ -1623,5 +1615,41 @@ namespace ICSharpCode.NRefactory.VB @@ -1623,5 +1615,41 @@ namespace ICSharpCode.NRefactory.VB
formatter.WriteComment(comment.IsDocumentationComment, comment.Content);
return null;
}
public object VisitEventDeclaration(EventDeclaration eventDeclaration, object data)
{
StartNode(eventDeclaration);
WriteAttributes(eventDeclaration.Attributes);
WriteModifiers(eventDeclaration.ModifierTokens);
if (eventDeclaration.IsCustom)
WriteKeyword("Custom");
WriteKeyword("Event");
WriteIdentifier(eventDeclaration.Name.Name);
if (!eventDeclaration.IsCustom && eventDeclaration.ReturnType.IsNull)
WriteCommaSeparatedListInParenthesis(eventDeclaration.Parameters, false);
if (!eventDeclaration.ReturnType.IsNull) {
Space();
WriteKeyword("As");
eventDeclaration.ReturnType.AcceptVisitor(this, data);
}
WriteImplementsClause(eventDeclaration.ImplementsClause);
if (eventDeclaration.IsCustom) {
NewLine();
Indent();
eventDeclaration.AddHandlerBlock.AcceptVisitor(this, data);
eventDeclaration.RemoveHandlerBlock.AcceptVisitor(this, data);
eventDeclaration.RaiseEventBlock.AcceptVisitor(this, data);
Unindent();
WriteKeyword("End");
WriteKeyword("Event");
}
NewLine();
return EndNode(eventDeclaration);
}
}
}

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

@ -64,10 +64,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -64,10 +64,10 @@ namespace ICSharpCode.NRefactory.VB.Visitors
op = AssignmentOperatorType.Assign;
break;
case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Add:
op = AssignmentOperatorType.Add;
break;
case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Subtract:
op = AssignmentOperatorType.Subtract;
break;
case ICSharpCode.NRefactory.CSharp.AssignmentOperatorType.Multiply:
@ -97,7 +97,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -97,7 +97,7 @@ namespace ICSharpCode.NRefactory.VB.Visitors
break;
default:
throw new Exception("Invalid value for AssignmentOperatorType");
throw new Exception("Invalid value for AssignmentOperatorType: " + assignmentExpression.Operator);
}
var right = (Expression)assignmentExpression.Right.AcceptVisitor(this, data);
@ -124,22 +124,22 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -124,22 +124,22 @@ namespace ICSharpCode.NRefactory.VB.Visitors
op = BinaryOperatorType.BitwiseAnd;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.BitwiseOr:
op = BinaryOperatorType.BitwiseOr;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ConditionalAnd:
op = BinaryOperatorType.LogicalAnd;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ConditionalOr:
op = BinaryOperatorType.LogicalOr;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ExclusiveOr:
op = BinaryOperatorType.ExclusiveOr;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.GreaterThan:
op = BinaryOperatorType.GreaterThan;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.GreaterThanOrEqual:
op = BinaryOperatorType.GreaterThanOrEqual;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Equality:
op = BinaryOperatorType.Equality;
@ -148,40 +148,34 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -148,40 +148,34 @@ namespace ICSharpCode.NRefactory.VB.Visitors
op = BinaryOperatorType.InEquality;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.LessThan:
op = BinaryOperatorType.LessThan;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.LessThanOrEqual:
op = BinaryOperatorType.LessThanOrEqual;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Add:
op = BinaryOperatorType.Add;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Subtract:
op = BinaryOperatorType.Subtract;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Multiply:
op = BinaryOperatorType.Multiply;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Divide:
op = BinaryOperatorType.Divide;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Modulus:
op = BinaryOperatorType.Modulus;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ShiftLeft:
op = BinaryOperatorType.ShiftLeft;
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.ShiftRight:
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.NullCoalescing:
break;
case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Any:
op = BinaryOperatorType.ShiftRight;
break;
default:
throw new Exception("Invalid value for BinaryOperatorType");
throw new Exception("Invalid value for BinaryOperatorType: " + binaryOperatorExpression.Operator);
}
return EndNode(binaryOperatorExpression, new BinaryOperatorExpression(left, op, right));
@ -745,12 +739,32 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -745,12 +739,32 @@ namespace ICSharpCode.NRefactory.VB.Visitors
public AstNode VisitEventDeclaration(CSharp.EventDeclaration eventDeclaration, object data)
{
throw new NotImplementedException();
var result = new EventDeclaration();
// TODO event declaration
// ConvertNodes(eventDeclaration.Attributes, result.Attributes);
// result.Modifiers = ConvertModifiers(eventDeclaration.Modifiers, eventDeclaration);
// result.Name = new Identifier(eventDeclaration., AstLocation.Empty);
return EndNode(eventDeclaration, result);
}
public AstNode VisitCustomEventDeclaration(CSharp.CustomEventDeclaration customEventDeclaration, object data)
{
throw new NotImplementedException();
var result = new EventDeclaration();
ConvertNodes(customEventDeclaration.Attributes, result.Attributes);
result.Modifiers = ConvertModifiers(customEventDeclaration.Modifiers, customEventDeclaration);
result.IsCustom = true;
result.Name = new Identifier(customEventDeclaration.Name, AstLocation.Empty);
result.ReturnType = (AstType)customEventDeclaration.ReturnType.AcceptVisitor(this, data);
if (!customEventDeclaration.PrivateImplementationType.IsNull)
result.ImplementsClause.Add(
new InterfaceMemberSpecifier((AstType)customEventDeclaration.PrivateImplementationType.AcceptVisitor(this, data), customEventDeclaration.Name));
result.AddHandlerBlock = (Accessor)customEventDeclaration.AddAccessor.AcceptVisitor(this, data);
result.RemoveHandlerBlock = (Accessor)customEventDeclaration.RemoveAccessor.AcceptVisitor(this, data);
return EndNode(customEventDeclaration, result);
}
public AstNode VisitFieldDeclaration(CSharp.FieldDeclaration fieldDeclaration, object data)

Loading…
Cancel
Save