Browse Source

Fixed SD2-816: Output visitor does not output implicit/explicit operators

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1419 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
df43c0eef7
  1. 2
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 6
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitor.cs
  3. 174
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  4. 27
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  5. 12
      src/Libraries/NRefactory/Project/Src/Parser/AST/Enums.cs
  6. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  7. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  8. 1585
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  9. 7
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  10. 21
      src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs
  11. 21
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs
  12. 46
      src/Main/Base/Project/Src/Dom/ModifierEnum.cs

2
AddIns/ICSharpCode.SharpDevelop.addin

@ -1421,7 +1421,7 @@ @@ -1421,7 +1421,7 @@
<MenuItem id = "ToggleBreakpointSeparator" type = "Separator" />
<MenuItem id = "Toggle Breakpoint"
label = "Toggle Breakpoint"
label = "${res:XML.MainMenu.DebugMenu.ToggleBreakpoint}"
shortcut = "F7"
class = "ICSharpCode.SharpDevelop.Project.Commands.ToggleBreakpointCommand"/>
</ComplexCondition>

6
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitor.cs

@ -155,12 +155,6 @@ namespace NRefactoryToBooConverter @@ -155,12 +155,6 @@ namespace NRefactoryToBooConverter
currentType.Attributes.Add(MakeAttribute("System.Reflection.DefaultMember", new B.StringLiteralExpression(name)));
}
}
if ((m & Modifier.Narrowing) != 0) {
AddError(node, "Narrowing modifier is not supported");
}
if ((m & Modifier.Widening) != 0) {
AddError(node, "Widening modifier is not supported");
}
return r;
}

174
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -622,6 +622,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -622,6 +622,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Dot);
}
outputFormatter.PrintIdentifier(methodDeclaration.Name);
PrintMethodDeclaration(methodDeclaration);
return null;
}
void PrintMethodDeclaration(MethodDeclaration methodDeclaration)
{
PrintTemplates(methodDeclaration.Templates);
if (prettyPrintOptions.BeforeMethodDeclarationParentheses) {
outputFormatter.Space();
@ -630,9 +637,118 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -630,9 +637,118 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
AppendCommaSeparatedList(methodDeclaration.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
foreach (TemplateDefinition templateDefinition in methodDeclaration.Templates) {
nodeTracker.TrackedVisit(templateDefinition, data);
nodeTracker.TrackedVisit(templateDefinition, null);
}
OutputBlock(methodDeclaration.Body, this.prettyPrintOptions.MethodBraceStyle);
}
public object Visit(OperatorDeclaration operatorDeclaration, object data)
{
VisitAttributes(operatorDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(operatorDeclaration.Modifier);
if (operatorDeclaration.IsConversionOperator) {
if (operatorDeclaration.ConversionType == ConversionType.Implicit) {
outputFormatter.PrintToken(Tokens.Implicit);
} else {
outputFormatter.PrintToken(Tokens.Explicit);
}
} else {
nodeTracker.TrackedVisit(operatorDeclaration.TypeReference, data);
}
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Operator);
outputFormatter.Space();
if (operatorDeclaration.IsConversionOperator) {
nodeTracker.TrackedVisit(operatorDeclaration.TypeReference, data);
} else {
switch (operatorDeclaration.OverloadableOperator) {
case OverloadableOperatorType.Add:
outputFormatter.PrintToken(Tokens.Plus);
break;
case OverloadableOperatorType.BitNot:
outputFormatter.PrintToken(Tokens.BitwiseComplement);
break;
case OverloadableOperatorType.BitwiseAnd:
outputFormatter.PrintToken(Tokens.BitwiseAnd);
break;
case OverloadableOperatorType.BitwiseOr:
outputFormatter.PrintToken(Tokens.BitwiseOr);
break;
case OverloadableOperatorType.Concat:
outputFormatter.PrintToken(Tokens.Plus);
break;
case OverloadableOperatorType.Decrement:
outputFormatter.PrintToken(Tokens.Decrement);
break;
case OverloadableOperatorType.Divide:
case OverloadableOperatorType.DivideInteger:
outputFormatter.PrintToken(Tokens.Div);
break;
case OverloadableOperatorType.Equality:
outputFormatter.PrintToken(Tokens.Equal);
break;
case OverloadableOperatorType.ExclusiveOr:
outputFormatter.PrintToken(Tokens.Xor);
break;
case OverloadableOperatorType.GreaterThan:
outputFormatter.PrintToken(Tokens.GreaterThan);
break;
case OverloadableOperatorType.GreaterThanOrEqual:
outputFormatter.PrintToken(Tokens.GreaterEqual);
break;
case OverloadableOperatorType.Increment:
outputFormatter.PrintToken(Tokens.Increment);
break;
case OverloadableOperatorType.InEquality:
outputFormatter.PrintToken(Tokens.NotEqual);
break;
case OverloadableOperatorType.IsTrue:
outputFormatter.PrintToken(Tokens.True);
break;
case OverloadableOperatorType.IsFalse:
outputFormatter.PrintToken(Tokens.False);
break;
case OverloadableOperatorType.LessThan:
outputFormatter.PrintToken(Tokens.LessThan);
break;
case OverloadableOperatorType.LessThanOrEqual:
outputFormatter.PrintToken(Tokens.LessEqual);
break;
case OverloadableOperatorType.Like:
outputFormatter.PrintText("Like");
break;
case OverloadableOperatorType.Modulus:
outputFormatter.PrintToken(Tokens.Mod);
break;
case OverloadableOperatorType.Multiply:
outputFormatter.PrintToken(Tokens.Times);
break;
case OverloadableOperatorType.Not:
outputFormatter.PrintToken(Tokens.Not);
break;
case OverloadableOperatorType.Power:
outputFormatter.PrintText("Power");
break;
case OverloadableOperatorType.ShiftLeft:
outputFormatter.PrintToken(Tokens.ShiftLeft);
break;
case OverloadableOperatorType.ShiftRight:
outputFormatter.PrintToken(Tokens.GreaterThan);
outputFormatter.PrintToken(Tokens.GreaterThan);
break;
case OverloadableOperatorType.Subtract:
outputFormatter.PrintToken(Tokens.Minus);
break;
default:
errors.Error(-1, -1, operatorDeclaration.OverloadableOperator.ToString() + " is not supported as overloadable operator");
break;
}
}
PrintMethodDeclaration(operatorDeclaration);
return null;
}
@ -736,62 +852,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -736,62 +852,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
public object Visit(OperatorDeclaration operatorDeclaration, object data)
{
// TODO: implement me
// VisitAttributes(operatorDeclaration.Attributes, data);
// outputFormatter.Indent();
// OutputModifier(operatorDeclaration.Modifier);
// switch (operatorDeclaration.OperatorType) {
// case OperatorType.Explicit:
// outputFormatter.PrintToken(Tokens.Explicit);
// break;
// case OperatorType.Implicit:
// outputFormatter.PrintToken(Tokens.Implicit);
// break;
// default:
// Visit(operatorDeclaration.OpratorDeclarator.TypeReference, data);
// break;
// }
// outputFormatter.Space();
// outputFormatter.PrintToken(Tokens.Operator);
// outputFormatter.Space();
// if (!operatorDeclaration.OpratorDeclarator.IsConversion) {
// outputFormatter.PrintIdentifier(Tokens.GetTokenString(operatorDeclaration.OpratorDeclarator.OverloadOperatorToken));
// } else {
// Visit(operatorDeclaration.OpratorDeclarator.TypeReference, data);
// }
//
// outputFormatter.PrintToken(Tokens.OpenParenthesis);
// Visit(operatorDeclaration.OpratorDeclarator.FirstParameterType, data);
// outputFormatter.Space();
// outputFormatter.PrintIdentifier(operatorDeclaration.OpratorDeclarator.FirstParameterName);
// if (operatorDeclaration.OpratorDeclarator.OperatorType == OperatorType.Binary) {
// outputFormatter.PrintToken(Tokens.Comma);
// outputFormatter.Space();
// Visit(operatorDeclaration.OpratorDeclarator.SecondParameterType, data);
// outputFormatter.Space();
// outputFormatter.PrintIdentifier(operatorDeclaration.OpratorDeclarator.SecondParameterName);
// }
// outputFormatter.PrintToken(Tokens.CloseParenthesis);
//
// if (operatorDeclaration.Body.IsNull) {
// outputFormatter.PrintToken(Tokens.Semicolon);
// } else {
// outputFormatter.NewLine();
// outputFormatter.Indent();
// outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
// outputFormatter.NewLine();
// ++outputFormatter.IndentationLevel;
// operatorDeclaration.Body.AcceptChildren(this, data);
// --outputFormatter.IndentationLevel;
// outputFormatter.Indent();
// outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
// }
// outputFormatter.NewLine();
return null;
}
public object Visit(DeclareDeclaration declareDeclaration, object data)
{
errors.Error(-1, -1, "DeclareDeclaration is unsupported");

27
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -983,10 +983,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -983,10 +983,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(OperatorDeclaration operatorDeclaration, object data)
{
// TODO: widenting... operators
VisitAttributes(operatorDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(operatorDeclaration.Modifier);
if (operatorDeclaration.IsConversionOperator) {
if (operatorDeclaration.ConversionType == ConversionType.Implicit) {
outputFormatter.PrintToken(Tokens.Widening);
} else {
outputFormatter.PrintToken(Tokens.Narrowing);
}
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.Operator);
outputFormatter.Space();
@ -1077,13 +1086,24 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1077,13 +1086,24 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
break;
}
if(op != -1) outputFormatter.PrintToken(op);
PrintTemplates(operatorDeclaration.Templates);
if (operatorDeclaration.IsConversionOperator) {
outputFormatter.PrintToken(Tokens.CType);
} else {
if(op != -1) outputFormatter.PrintToken(op);
}
PrintTemplates(operatorDeclaration.Templates);
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(operatorDeclaration.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
if (!operatorDeclaration.TypeReference.IsNull) {
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.As);
outputFormatter.Space();
nodeTracker.TrackedVisit(operatorDeclaration.TypeReference, data);
}
outputFormatter.NewLine();
@ -1091,7 +1111,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1091,7 +1111,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
nodeTracker.TrackedVisit(operatorDeclaration.Body, data);
--outputFormatter.IndentationLevel;
outputFormatter.NewLine();
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.End);
outputFormatter.Space();

12
src/Libraries/NRefactory/Project/Src/Parser/AST/Enums.cs

@ -43,8 +43,8 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -43,8 +43,8 @@ namespace ICSharpCode.NRefactory.Parser.AST
Overloads = 0x10000, // VB specific
WithEvents = 0x20000, // VB specific
Default = 0x40000, // VB specific
Narrowing = 0x80000, // VB specific
Widening = 0x100000, // VB specific
Synthetic = 0x200000,
/// <summary>Only for VB properties.</summary>
WriteOnly = 0x400000, // VB specific
@ -61,7 +61,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -61,7 +61,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
VBEvents = Visibility | New | Overloads,
VBProperties = VBMethods | Default | ReadOnly | WriteOnly,
VBCustomEvents = Visibility | New | Overloads,
VBOperators = Public | Static | Overloads | New | Widening | Narrowing,
VBOperators = Public | Static | Overloads | New,
// this is not documented in the spec
@ -321,12 +321,10 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -321,12 +321,10 @@ namespace ICSharpCode.NRefactory.Parser.AST
Increment,
Decrement,
True,
False,
// VB specific
IsTrue,
IsFalse,
// VB specific
Like,
Power,
CType,

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

@ -3121,14 +3121,14 @@ out OverloadableOperatorType op) { @@ -3121,14 +3121,14 @@ out OverloadableOperatorType op) {
lexer.NextToken();
#line 1753 "cs.ATG"
op = OverloadableOperatorType.True;
op = OverloadableOperatorType.IsTrue;
break;
}
case 71: {
lexer.NextToken();
#line 1754 "cs.ATG"
op = OverloadableOperatorType.False;
op = OverloadableOperatorType.IsFalse;
break;
}
case 6: {

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -1750,8 +1750,8 @@ OverloadableOperator<out OverloadableOperatorType op> @@ -1750,8 +1750,8 @@ OverloadableOperator<out OverloadableOperatorType op>
| "++" (. op = OverloadableOperatorType.Increment; .)
| "--" (. op = OverloadableOperatorType.Decrement; .)
| "true" (. op = OverloadableOperatorType.True; .)
| "false" (. op = OverloadableOperatorType.False; .)
| "true" (. op = OverloadableOperatorType.IsTrue; .)
| "false" (. op = OverloadableOperatorType.IsFalse; .)
| "*" (. op = OverloadableOperatorType.Multiply; .)
| "/" (. op = OverloadableOperatorType.Divide; .)

1585
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

7
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -1317,7 +1317,9 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1317,7 +1317,9 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
decl.RaiseRegion = raiseEventAccessorDeclaration;
compilationUnit.AddChild(decl);
.)
|
| (. ConversionType opConversionType = ConversionType.None; .)
[ "Widening" (. opConversionType = ConversionType.Implicit; .)
| "Narrowing" (. opConversionType = ConversionType.Explicit;.) ]
"Operator"
(.
m.Check(Modifier.VBOperators);
@ -1352,6 +1354,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1352,6 +1354,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
returnType,
operatorType
);
operatorDeclaration.ConversionType = opConversionType;
operatorDeclaration.ReturnTypeAttributes = returnTypeAttributes;
operatorDeclaration.Body = (BlockStatement)stmt;
operatorDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
@ -2994,8 +2997,6 @@ MemberModifier<Modifiers m> = @@ -2994,8 +2997,6 @@ MemberModifier<Modifiers m> =
| "WriteOnly" (.m.Add(Modifier.WriteOnly, t.Location);.)
| "WithEvents" (.m.Add(Modifier.WithEvents, t.Location);.)
| "Dim" (.m.Add(Modifier.Dim, t.Location);.)
| "Widening" (.m.Add(Modifier.Widening, t.Location);.)
| "Narrowing" (.m.Add(Modifier.Narrowing, t.Location);.)
.
END VBNET.

21
src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs

@ -338,5 +338,26 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -338,5 +338,26 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
TestTypeMember("public string this[int index] { get { return index.ToString(); } set { } }");
TestTypeMember("public string IList.this[int index] { get { return index.ToString(); } set { } }");
}
[Test]
public void OverloadedConversionOperators()
{
TestTypeMember("public static explicit operator TheBug(XmlNode xmlNode) { }");
TestTypeMember("public static implicit operator XmlNode(TheBug bugNode) { }");
}
[Test]
public void OverloadedTrueFalseOperators()
{
TestTypeMember("public static bool operator true(TheBug bugNode) { }");
TestTypeMember("public static bool operator false(TheBug bugNode) { }");
}
[Test]
public void OverloadedOperators()
{
TestTypeMember("public static TheBug operator +(TheBug bugNode, TheBug bugNode2) { }");
TestTypeMember("public static TheBug operator >>(TheBug bugNode, int b) { }");
}
}
}

21
src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

@ -258,5 +258,26 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -258,5 +258,26 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestStatement("On Error Resume Next");
}
[Test]
public void OverloadedConversionOperators()
{
TestTypeMember("Public Shared Narrowing Operator CType(ByVal xmlNode As XmlNode) As TheBug\nEnd Operator");
TestTypeMember("Public Shared Widening Operator CType(ByVal bugNode As TheBug) As XmlNode\nEnd Operator");
}
[Test]
public void OverloadedTrueFalseOperators()
{
TestTypeMember("Public Shared Operator IsTrue(ByVal a As TheBug) As Boolean\nEnd Operator");
TestTypeMember("Public Shared Operator IsFalse(ByVal a As TheBug) As Boolean\nEnd Operator");
}
[Test]
public void OverloadedOperators()
{
TestTypeMember("Public Shared Operator +(ByVal bugNode As TheBug, ByVal bugNode2 As TheBug) As TheBug\nEnd Operator");
TestTypeMember("Public Shared Operator >>(ByVal bugNode As TheBug, ByVal b As Integer) As TheBug\nEnd Operator");
}
}
}

46
src/Main/Base/Project/Src/Dom/ModifierEnum.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using M = ICSharpCode.NRefactory.Parser.AST.Modifier;
namespace ICSharpCode.SharpDevelop.Dom
{
@ -15,33 +16,32 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -15,33 +16,32 @@ namespace ICSharpCode.SharpDevelop.Dom
None = 0,
// Access
Private = 0x0001,
Internal = 0x0002, // == Friend
Protected = 0x0004,
Public = 0x0008,
Dim = 0x0010, // VB.NET SPECIFIC
Private = M.Private,
Internal = M.Internal, // == Friend
Protected = M.Protected,
Public = M.Public,
Dim = M.Dim, // VB.NET SPECIFIC
// Scope
Abstract = 0x0010, // == MustOverride/MustInherit
Virtual = 0x0020,
Sealed = 0x0040,
Static = 0x0080,
Override = 0x0100,
Readonly = 0x0200,
Const = 0x0400,
New = 0x0800, // == Shadows
Partial = 0x1000,
Abstract = M.Abstract, // == MustOverride/MustInherit
Virtual = M.Virtual,
Sealed = M.Sealed,
Static = M.Static,
Override = M.Override,
Readonly = M.ReadOnly,
Const = M.Const,
New = M.New, // == Shadows
Partial = M.Partial,
// Special
Extern = 0x2000,
Volatile = 0x4000,
Unsafe = 0x8000,
Overloads = 0x10000, // VB specific
WithEvents = 0x20000, // VB specific
Default = 0x40000, // VB specific
Narrowing = 0x80000, // VB specific
Widening = 0x100000, // VB specific
Synthetic = 0x200000,
Extern = M.Extern,
Volatile = M.Volatile,
Unsafe = M.Unsafe,
Overloads = M.Overloads, // VB specific
WithEvents = M.WithEvents, // VB specific
Default = M.Default, // VB specific
Synthetic = M.Synthetic,
ProtectedAndInternal = Internal | Protected,
VisibilityMask = Private | Internal | Protected | Public,

Loading…
Cancel
Save