Browse Source

added operator overload support to vb grammar

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@270 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Markus Palme 21 years ago
parent
commit
94ae1cc253
  1. 2
      src/Libraries/NRefactory/NRefactory.sln
  2. 2
      src/Libraries/NRefactory/Project/NRefactory.csproj
  3. 6
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/Enums.cs
  4. 25
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/OperatorDeclaration.cs
  5. 1817
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  6. 2594
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  7. 113
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  8. 15
      src/Libraries/NRefactory/Test/Parser/TypeLevel/OperatorDeclarationTests.cs

2
src/Libraries/NRefactory/NRefactory.sln

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# SharpDevelop 2.0.0.1
# SharpDevelop 2.0.0.260
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryTests", "Test\NRefactoryTests.csproj", "{870115DD-960A-4406-A6B9-600BCDC36A03}"

2
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -98,7 +98,6 @@ @@ -98,7 +98,6 @@
<Compile Include="Src\Parser\AST\CSharp\Statements\YieldStatement.cs" />
<Compile Include="Src\Parser\AST\CSharp\TypeLevel\DestructorDeclaration.cs" />
<Compile Include="Src\Parser\AST\CSharp\TypeLevel\IndexerDeclaration.cs" />
<Compile Include="Src\Parser\AST\CSharp\TypeLevel\OperatorDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\AttributeSection.cs" />
<Compile Include="Src\Parser\AST\General\Enums.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\ArrayCreateExpression.cs" />
@ -190,6 +189,7 @@ @@ -190,6 +189,7 @@
<Compile Include="Src\Parser\Visitors\VBNetToCSharpConvertVisitor.cs" />
<Compile Include="Src\Parser\AST\VBNet\TypeLevel\CustomEventDeclaration.cs" />
<Compile Include="Src\Parser\AST\VBNet\TypeLevel\EventAccessorDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\OperatorDeclaration.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Src\Lexer\CSharp\KeywordList.txt" />

6
src/Libraries/NRefactory/Project/Src/Parser/AST/General/Enums.cs

@ -37,9 +37,12 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -37,9 +37,12 @@ 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
// Modifier scopes
None = 0x0000,
Classes = New | Public | Protected | Internal | Private | Abstract | Sealed | Partial | Static,
VBModules = Private | Public | Protected | Internal,
VBStructures = Private | Public | Protected | Internal | New,
@ -50,6 +53,9 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -50,6 +53,9 @@ namespace ICSharpCode.NRefactory.Parser.AST
VBExternalMethods = Private | Public | Protected | Internal | New | Overloads,
VBEvents = Private | Public | Protected | Internal | New | Overloads,
VBProperties = VBMethods | Default,
VBCustomEvents = Private | Public | Protected | Internal | New | Overloads,
VBOperators = Public | Static | Overloads | New | Widening | Narrowing,
// this is not documented in the spec
VBInterfaceEvents = New,

25
src/Libraries/NRefactory/Project/Src/Parser/AST/CSharp/TypeLevel/OperatorDeclaration.cs → src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/OperatorDeclaration.cs

@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
Multiply,
Divide,
Modulus,
Concat,
Not,
BitNot,
@ -50,13 +51,20 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -50,13 +51,20 @@ namespace ICSharpCode.NRefactory.Parser.AST
True,
False,
// VB specific
IsTrue,
IsFalse,
Like,
Power,
CType,
DivideInteger
}
public class OperatorDeclaration : MethodDeclaration
{
ConversionType conversionType = ConversionType.None;
TypeReference convertToType;
List<AttributeSection> returnTypeAttributes = new List<AttributeSection>();
OverloadableOperatorType overloadableOperator = OverloadableOperatorType.None;
public ConversionType ConversionType {
@ -68,6 +76,16 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -68,6 +76,16 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
public List<AttributeSection> ReturnTypeAttributes
{
get {
return returnTypeAttributes;
}
set {
returnTypeAttributes = value;
}
}
public TypeReference ConvertToType {
get {
return convertToType;
@ -77,7 +95,6 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -77,7 +95,6 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
public OverloadableOperatorType OverloadableOperator {
get {
return overloadableOperator;
@ -122,7 +139,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -122,7 +139,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
) : base(null, modifier, typeReference, parameters, attributes)
{
this.overloadableOperator = overloadableOperator;
convertToType = TypeReference.Null;
convertToType = TypeReference.Null;
}
public override object AcceptVisitor(IASTVisitor visitor, object data)

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

File diff suppressed because it is too large Load Diff

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

File diff suppressed because it is too large Load Diff

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

@ -514,7 +514,8 @@ ImportClause<out Using u> @@ -514,7 +514,8 @@ ImportClause<out Using u>
NamespaceMemberDecl
(.
Modifiers m = new Modifiers();
AttributeSection section;List<AttributeSection> attributes = new List<AttributeSection>();
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
string qualident;
.) =
"Namespace"
@ -635,6 +636,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes> @@ -635,6 +636,7 @@ NonModuleDeclaration<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(newType);
compilationUnit.BlockStart(newType);
newType.StartLocation = t.Location;
System.Console.WriteLine("XXX " + t.Location.ToString());
newType.Type = Types.Struct;
.)
Identifier (. newType.Name = t.val; .)
@ -1194,6 +1196,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1194,6 +1196,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
|
"Custom" (. Point startPos = t.Location; .) "Event"
(.
m.Check(Modifier.VBCustomEvents);
EventAccessorDeclaration eventAccessorDeclaration;
EventAccessorDeclaration addHandlerAccessorDeclaration = null;
EventAccessorDeclaration removeHandlerAccessorDeclaration = null;
@ -1240,9 +1243,113 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1240,9 +1243,113 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
CustomEventDeclaration decl = new CustomEventDeclaration(m.Modifier, attributes, customEventName, addHandlerAccessorDeclaration, removeHandlerAccessorDeclaration, raiseEventAccessorDeclaration, implementsClause);
decl.StartLocation = startPos;
decl.StartLocation = t.EndLocation;
decl.EndLocation = t.EndLocation;
compilationUnit.AddChild(decl);
.)
| /* UnaryOperatorDeclaration */
"Operator"
(.
m.Check(Modifier.VBOperators);
Point startPos = t.Location;
TypeReference returnType = NullTypeReference.Instance;
TypeReference operandType = NullTypeReference.Instance;
string operandName;
OverloadableOperatorType operatorType;
AttributeSection section;
List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
List<AttributeSection> returnTypeAttributes = new List<AttributeSection>();
.)
OverloadableOperator<out operatorType>
"(" [ "ByVal" ] Identifier (. operandName = t.val; .)
[ "As" TypeName<out operandType> ]
(. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParamModifier.In)); .)
{
","
[ "ByVal" ] Identifier (. operandName = t.val; .)
[ "As" TypeName<out operandType> ]
(. parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParamModifier.In)); .)
}
")"
[ "As" { AttributeSection<out section> (. returnTypeAttributes.Add(section); .) } TypeName<out returnType> EOL ]
Block<out stmt> "End" "Operator" EOL
(.
OperatorDeclaration operatorDeclaration = new OperatorDeclaration(m.Modifier,
attributes,
parameters,
returnType,
operatorType
);
operatorDeclaration.ConvertToType = returnType;
operatorDeclaration.ReturnTypeAttributes = returnTypeAttributes;
operatorDeclaration.Body = (BlockStatement)stmt;
operatorDeclaration.StartLocation = startPos;
operatorDeclaration.EndLocation = t.EndLocation;
compilationUnit.AddChild(operatorDeclaration);
.)
.
OverloadableOperator<out OverloadableOperatorType operatorType>
(. operatorType = OverloadableOperatorType.None; .)
=
"+" (. operatorType = OverloadableOperatorType.Add; .)
|
"-" (. operatorType = OverloadableOperatorType.Subtract; .)
|
"*" (. operatorType = OverloadableOperatorType.Multiply; .)
|
"/" (. operatorType = OverloadableOperatorType.Divide; .)
|
"\\" (. operatorType = OverloadableOperatorType.DivideInteger; .)
|
"&" (. operatorType = OverloadableOperatorType.Concat; .)
|
"Like" (. operatorType = OverloadableOperatorType.Like; .)
|
"Mod" (. operatorType = OverloadableOperatorType.Modulus; .)
|
"And" (. operatorType = OverloadableOperatorType.BitwiseAnd; .)
|
"Or" (. operatorType = OverloadableOperatorType.BitwiseOr; .)
|
"Xor" (. operatorType = OverloadableOperatorType.ExclusiveOr; .)
|
"^" (. operatorType = OverloadableOperatorType.Power; .)
|
"<<" (. operatorType = OverloadableOperatorType.ShiftLeft; .)
|
">>" (. operatorType = OverloadableOperatorType.ShiftRight; .)
|
"=" (. operatorType = OverloadableOperatorType.Equality; .)
|
"<>" (. operatorType = OverloadableOperatorType.InEquality; .)
|
"<" (. operatorType = OverloadableOperatorType.LessThan; .)
|
"<=" (. operatorType = OverloadableOperatorType.LessThanOrEqual; .)
|
">" (. operatorType = OverloadableOperatorType.GreaterThan; .)
|
">=" (. operatorType = OverloadableOperatorType.GreaterThanOrEqual; .)
|
"CType" (. operatorType = OverloadableOperatorType.CType; .)
|
Identifier
(.
string opName = t.val;
switch(opName.ToLower())
{
case "istrue":
operatorType = OverloadableOperatorType.IsTrue;
break;
case "isfalse":
operatorType = OverloadableOperatorType.IsFalse;
break;
default:
Error("Invalid operator. Possible operators are '+', '-', 'Not', 'IsTrue', 'IsFalse'.");
break;
}
.)
.
EventAccessorDeclaration<out EventAccessorDeclaration eventAccessorDeclaration>
@ -2854,6 +2961,8 @@ MemberModifier<Modifiers m> = @@ -2854,6 +2961,8 @@ MemberModifier<Modifiers m> =
| "WriteOnly" (. /* m.Add(Modifier.WriteOnly); */ .)
| "WithEvents" (.m.Add(Modifier.WithEvents);.)
| "Dim" (.m.Add(Modifier.Dim);.)
| "Widening" (.m.Add(Modifier.Widening);.)
| "Narrowing" (.m.Add(Modifier.Narrowing);.)
.
END VBNET.

15
src/Libraries/NRefactory/Test/Parser/TypeLevel/OperatorDeclarationTests.cs

@ -51,7 +51,20 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -51,7 +51,20 @@ namespace ICSharpCode.NRefactory.Tests.AST
#endregion
#region VB.NET
// No VB.NET representation
[Test]
public void VBNetImplictOperatorDeclarationTest()
{
string programm = @"Public Shared Operator + (ByVal v As Complex) As Complex
Return v
End Operator";
OperatorDeclaration od = (OperatorDeclaration)ParseUtilVBNet.ParseTypeMember(programm, typeof(OperatorDeclaration));
Assert.IsFalse(od.IsConversionOperator);
Assert.AreEqual(1, od.Parameters.Count);
Assert.AreEqual(ConversionType.None, od.ConversionType);
Assert.AreEqual("Complex", od.ConvertToType.Type);
}
#endregion
}
}

Loading…
Cancel
Save