Browse Source

custom events support

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@262 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Markus Palme 21 years ago
parent
commit
271e00448d
  1. 3
      src/Libraries/ICSharpCode.TextEditor/Project/Resources/VBNET-Mode.xshd
  2. 2
      src/Libraries/NRefactory/Project/NRefactory.csproj
  3. 2
      src/Libraries/NRefactory/Project/Src/Lexer/BuildKeywords.pl
  4. 1
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt
  5. 10
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Keywords.cs
  6. 11
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs
  7. 18
      src/Libraries/NRefactory/Project/Src/Main.cs
  8. 99
      src/Libraries/NRefactory/Project/Src/Parser/AST/VBNet/TypeLevel/CustomEventDeclaration.cs
  9. 90
      src/Libraries/NRefactory/Project/Src/Parser/AST/VBNet/TypeLevel/EventAccessorDeclaration.cs
  10. 2750
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  11. 83
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  12. 15
      src/Libraries/NRefactory/Test/NRefactoryTests.csproj
  13. 52
      src/Libraries/NRefactory/Test/Parser/TypeLevel/CustomEventTests.cs

3
src/Libraries/ICSharpCode.TextEditor/Project/Resources/VBNET-Mode.xshd

@ -161,6 +161,9 @@
<Key word = "AddHandler" /> <Key word = "AddHandler" />
<Key word = "RemoveHandler" /> <Key word = "RemoveHandler" />
<Key word = "RaiseEvent" /> <Key word = "RaiseEvent" />
<Key word = "Custom" />
<Key word = "RemoveHandler" />
<Key word = "AddHandler" />
<Key word = "Option" /> <Key word = "Option" />
<Key word = "Let" /> <Key word = "Let" />
<Key word = "GoTo" /> <Key word = "GoTo" />

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

@ -188,6 +188,8 @@
<Compile Include="Src\Parser\Visitors\CSharpToVBNetConvertVisitor.cs" /> <Compile Include="Src\Parser\Visitors\CSharpToVBNetConvertVisitor.cs" />
<Compile Include="Src\Parser\Visitors\PrefixFieldsVisitor.cs" /> <Compile Include="Src\Parser\Visitors\PrefixFieldsVisitor.cs" />
<Compile Include="Src\Parser\Visitors\VBNetToCSharpConvertVisitor.cs" /> <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" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Src\Lexer\CSharp\KeywordList.txt" /> <Content Include="Src\Lexer\CSharp\KeywordList.txt" />

2
src/Libraries/NRefactory/Project/Src/Lexer/BuildKeywords.pl

@ -10,7 +10,7 @@ $ATGTokensSection = "ATGTokensSection.gen";
#read infile #read infile
print "\n"; print "\n";
print "Reading keyword definition from '$keyword_file'.\n"; print "Reading keyword definition from '$keyword_file'.\n";
open(DAT, $keyword_file) || die("Could not open file!"); open(DAT, $keyword_file) || die("Could not open file '$keyword_file': $!");
@raw_data=<DAT>; @raw_data=<DAT>;
close(DAT); close(DAT);
print "done.\n"; print "done.\n";

1
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt

@ -223,6 +223,7 @@ ConcatStringAssign = "&="
"Narrowing" "Narrowing"
"Widening" "Widening"
"Partial" "Partial"
"Custom"
#Sets #Sets
Null("Nothing") Null("Nothing")

10
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Keywords.cs

@ -1,10 +1,3 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="none" email=""/>
// <version>$Revision$</version>
// </file>
// this file was autogenerated by a tool. // this file was autogenerated by a tool.
using System; using System;
@ -171,7 +164,8 @@ namespace ICSharpCode.NRefactory.Parser.VB
"OF", "OF",
"NARROWING", "NARROWING",
"WIDENING", "WIDENING",
"PARTIAL" "PARTIAL",
"CUSTOM"
}; };
static LookupTable keywords = new LookupTable(false); static LookupTable keywords = new LookupTable(false);

11
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs

@ -1,10 +1,3 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="none" email=""/>
// <version>$Revision$</version>
// </file>
// this file was autogenerated by a tool. // this file was autogenerated by a tool.
using System; using System;
using System.Collections; using System.Collections;
@ -218,8 +211,9 @@ namespace ICSharpCode.NRefactory.Parser.VB
public const int Narrowing = 197; public const int Narrowing = 197;
public const int Widening = 198; public const int Widening = 198;
public const int Partial = 199; public const int Partial = 199;
public const int Custom = 200;
public const int maxToken = 200; public const int maxToken = 201;
static BitArray NewSet(params int[] values) static BitArray NewSet(params int[] values)
{ {
BitArray bitArray = new BitArray(maxToken); BitArray bitArray = new BitArray(maxToken);
@ -435,6 +429,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
"Narrowing", "Narrowing",
"Widening", "Widening",
"Partial", "Partial",
"Custom",
}; };
public static string GetTokenString(int token) public static string GetTokenString(int token)
{ {

18
src/Libraries/NRefactory/Project/Src/Main.cs

@ -70,13 +70,13 @@ namespace ICSharpCode.NRefactory
// //
//} //}
//"; //";
// IParser parser = ParserFactory.CreateParser(SupportedLanguages.CSharp, new StringReader(program)); IParser parser = ParserFactory.CreateParser(@"c:\Dokumente und Einstellungen\Markus\Desktop\CustomEvents.vb");
// parser.Parse(); parser.Parse();
// if (parser.Errors.ErrorOutput.Length > 0) { if (parser.Errors.ErrorOutput.Length > 0) {
// Console.WriteLine(parser.Errors.ErrorOutput); Console.WriteLine(parser.Errors.ErrorOutput);
// Console.ReadLine(); Console.ReadLine();
// } }
/*
string searchPath = @"C:\Programme\Microsoft.NET\SDK\v1.1"; //Path.GetFullPath(Application.StartupPath + @"\..\..\..\.."); string searchPath = @"C:\Programme\Microsoft.NET\SDK\v1.1"; //Path.GetFullPath(Application.StartupPath + @"\..\..\..\..");
ArrayList files = SearchDirectory(searchPath, "*.cs", true); ArrayList files = SearchDirectory(searchPath, "*.cs", true);
ArrayList defs = new ArrayList(); ArrayList defs = new ArrayList();
@ -87,7 +87,8 @@ namespace ICSharpCode.NRefactory
IParser parser = ParserFactory.CreateParser(str); IParser parser = ParserFactory.CreateParser(str);
parser.Parse(); parser.Parse();
} }
} */
}
} }
} }
@ -106,6 +107,5 @@ namespace ICSharpCode.NRefactory
Properties with Mixed Access Levels Properties with Mixed Access Levels
Operator Overloading Operator Overloading
Generic Types Generic Types
Custom Events
*/ */

99
src/Libraries/NRefactory/Project/Src/Parser/AST/VBNet/TypeLevel/CustomEventDeclaration.cs

@ -0,0 +1,99 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Markus Palme" email="MarkusPalme@gmx.de"/>
// <version>$Revision: 230 $</version>
// </file>
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.Parser.AST
{
public class CustomEventDeclaration : AttributedNode
{
string name;
EventAccessorDeclaration addHandlerDeclaration;
EventAccessorDeclaration removeHandlerDeclaration;
EventAccessorDeclaration raiseEventDeclaration;
ArrayList implementsClause = new ArrayList();
public CustomEventDeclaration(Modifier modifier, List<AttributeSection> attributes, string name, EventAccessorDeclaration addHandlerDeclaration, EventAccessorDeclaration removeHandlerDeclaration, EventAccessorDeclaration raiseEventDeclaration, ArrayList implementsClause) : base(modifier, attributes)
{
this.modifier = modifier;
this.attributes = attributes;
this.name = name;
this.addHandlerDeclaration = addHandlerDeclaration;
this.removeHandlerDeclaration = removeHandlerDeclaration;
this.raiseEventDeclaration = raiseEventDeclaration;
this.implementsClause = implementsClause;
}
public ArrayList ImplementsClause
{
get
{
return implementsClause;
}
set
{
implementsClause = value;
}
}
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public EventAccessorDeclaration AddHandlerDeclaration
{
get
{
return addHandlerDeclaration;
}
set
{
addHandlerDeclaration = value;
}
}
public EventAccessorDeclaration RemoveHandlerDeclaration
{
get
{
return removeHandlerDeclaration;
}
set
{
removeHandlerDeclaration = value;
}
}
public EventAccessorDeclaration RaiseEventDeclaration
{
get
{
return raiseEventDeclaration;
}
set
{
raiseEventDeclaration = value;
}
}
public override object AcceptVisitor(IASTVisitor visitor, object data)
{
return visitor.Visit(this, data);
}
}
}

90
src/Libraries/NRefactory/Project/Src/Parser/AST/VBNet/TypeLevel/EventAccessorDeclaration.cs

@ -0,0 +1,90 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Markus Palme" email="MarkusPalme@gmx.de"/>
// <version>$Revision: 230 $</version>
// </file>
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.Parser.AST
{
public enum EventAccessorType
{
RemoveHandlerAccessor,
AddHandlerAccessor,
RaiseEventAccessor
}
public class EventAccessorDeclaration : AbstractNode
{
protected BlockStatement body = BlockStatement.Null;
protected EventAccessorType type;
protected List<AttributeSection> attributes;
protected List<ParameterDeclarationExpression> parameters;
public EventAccessorDeclaration(BlockStatement body, List<ParameterDeclarationExpression> parameters, EventAccessorType type, List<AttributeSection> attributes)
{
this.body = body;
this.parameters = parameters;
this.type = type;
this.attributes = attributes;
}
public List<ParameterDeclarationExpression> Parameters
{
get
{
return parameters;
}
set
{
parameters = value == null ? new List<ParameterDeclarationExpression>(1) : value;
}
}
public List<AttributeSection> Attributes
{
get
{
return attributes;
}
set
{
attributes = value == null ? new List<AttributeSection>(1) : value;
}
}
public EventAccessorType Type
{
get
{
return type;
}
set
{
type = value;
}
}
public BlockStatement Body
{
get
{
return body;
}
set
{
body = BlockStatement.CheckNull(value);
}
}
public override object AcceptVisitor(IASTVisitor visitor, object data)
{
return visitor.Visit(this, data);
}
}
}

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

File diff suppressed because it is too large Load Diff

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

@ -417,6 +417,7 @@ TOKENS
"Narrowing" "Narrowing"
"Widening" "Widening"
"Partial" "Partial"
"Custom"
/* END AUTOGENERATED TOKENS SECTION */ /* END AUTOGENERATED TOKENS SECTION */
PRODUCTIONS PRODUCTIONS
@ -1190,6 +1191,88 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
compilationUnit.AddChild(pDecl); compilationUnit.AddChild(pDecl);
.) .)
) )
|
"Custom" (. Point startPos = t.Location; .) "Event"
(.
EventAccessorDeclaration eventAccessorDeclaration;
EventAccessorDeclaration addHandlerAccessorDeclaration = null;
EventAccessorDeclaration removeHandlerAccessorDeclaration = null;
EventAccessorDeclaration raiseEventAccessorDeclaration = null;
ArrayList implementsClause = null;
.)
Identifier (. string customEventName = t.val; .)
"As" TypeName<out type>
[ ImplementsClause<out implementsClause> ]
EOL
{
EventAccessorDeclaration<out eventAccessorDeclaration>
(.
if(eventAccessorDeclaration.Type == EventAccessorType.AddHandlerAccessor)
{
addHandlerAccessorDeclaration = eventAccessorDeclaration;
}
else if(eventAccessorDeclaration.Type == EventAccessorType.RemoveHandlerAccessor)
{
removeHandlerAccessorDeclaration = eventAccessorDeclaration;
}
else if(eventAccessorDeclaration.Type == EventAccessorType.RaiseEventAccessor)
{
raiseEventAccessorDeclaration = eventAccessorDeclaration;
}
.)
}
"End" "Event" EOL
(.
if(addHandlerAccessorDeclaration == null)
{
Error("Need to provide AddHandler accessor.");
}
if(addHandlerAccessorDeclaration == null)
{
Error("Need to provide RemoveHandler accessor.");
}
if(addHandlerAccessorDeclaration == null)
{
Error("Need to provide RaiseEvent accessor.");
}
CustomEventDeclaration decl = new CustomEventDeclaration(m.Modifier, attributes, customEventName, addHandlerAccessorDeclaration, removeHandlerAccessorDeclaration, raiseEventAccessorDeclaration, implementsClause);
decl.StartLocation = startPos;
decl.StartLocation = t.EndLocation;
compilationUnit.AddChild(decl);
.)
.
EventAccessorDeclaration<out EventAccessorDeclaration eventAccessorDeclaration>
(.
Statement stmt = null;
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
AttributeSection section;
List<AttributeSection> attributes = new List<AttributeSection>();
eventAccessorDeclaration = null;
.) =
{ AttributeSection<out section> (. attributes.Add(section); .) }
(
"AddHandler" [ "(" [ FormalParameterList<p> ] ")" ] EOL
Block<out stmt> "End" "AddHandler" EOL
(.
eventAccessorDeclaration = new EventAccessorDeclaration((BlockStatement)stmt, p, EventAccessorType.AddHandlerAccessor, attributes);
.)
|
"RemoveHandler" [ "(" [ FormalParameterList<p> ] ")" ] EOL
Block<out stmt> "End" "RemoveHandler" EOL
(.
eventAccessorDeclaration = new EventAccessorDeclaration((BlockStatement)stmt, p, EventAccessorType.RemoveHandlerAccessor, attributes);
.)
|
"RaiseEvent" [ "(" [ FormalParameterList<p> ] ")" ] EOL
Block<out stmt> "End" "RaiseEvent" EOL
(.
eventAccessorDeclaration = new EventAccessorDeclaration((BlockStatement)stmt, p, EventAccessorType.RaiseEventAccessor, attributes);
.)
)
. .
/* 9.7 */ /* 9.7 */

15
src/Libraries/NRefactory/Test/NRefactoryTests.csproj

@ -8,7 +8,6 @@
<RootNamespace>ICSharpCode.NRefactory.Tests</RootNamespace> <RootNamespace>ICSharpCode.NRefactory.Tests</RootNamespace>
<AssemblyName>ICSharpCode.NRefactory.Tests</AssemblyName> <AssemblyName>ICSharpCode.NRefactory.Tests</AssemblyName>
<OutputTarget>Library</OutputTarget> <OutputTarget>Library</OutputTarget>
<WarningLevel>4</WarningLevel>
<NoStdLib>False</NoStdLib> <NoStdLib>False</NoStdLib>
<NoConfig>False</NoConfig> <NoConfig>False</NoConfig>
<RunPostBuildEvent>OnSuccessfulBuild</RunPostBuildEvent> <RunPostBuildEvent>OnSuccessfulBuild</RunPostBuildEvent>
@ -16,11 +15,9 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>
<Optimize>False</Optimize>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG</DefineConstants> <DefineConstants>DEBUG</DefineConstants>
<OutputPath>..\..\..\..\bin\</OutputPath> <OutputPath>C:\corsavy\trunk\SharpDevelop\bin</OutputPath>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors> <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@ -34,7 +31,14 @@
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="nunit.framework, Version=2.2.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" /> <Reference Include="nunit.framework">
<HintPath>..\..\..\..\bin\nunit.framework.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="nunit.core">
<HintPath>..\..\..\..\bin\nunit.core.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AssemblyInfo.cs" /> <Compile Include="AssemblyInfo.cs" />
@ -127,6 +131,7 @@
<Compile Include="Output\CodeDOM\InvocationExpressionTest.cs" /> <Compile Include="Output\CodeDOM\InvocationExpressionTest.cs" />
<Compile Include="Parser\Expressions\TypeReferenceExpressionTests.cs" /> <Compile Include="Parser\Expressions\TypeReferenceExpressionTests.cs" />
<Compile Include="Parser\Expressions\GlobalReferenceExpressionTests.cs" /> <Compile Include="Parser\Expressions\GlobalReferenceExpressionTests.cs" />
<Compile Include="Parser\TypeLevel\CustomEventTests.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Project\NRefactory.csproj"> <ProjectReference Include="..\Project\NRefactory.csproj">

52
src/Libraries/NRefactory/Test/Parser/TypeLevel/CustomEventTests.cs

@ -0,0 +1,52 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision: 230 $</version>
// </file>
using System;
using System.IO;
using NUnit.Framework;
using ICSharpCode.NRefactory.Parser;
using ICSharpCode.NRefactory.Parser.AST;
namespace ICSharpCode.NRefactory.Tests.AST
{
[TestFixture]
public class CustomEventTests
{
#region C#
// No C# representation
#endregion
#region VB.NET
[Test]
public void VBNetContinueStatementTest()
{
string code = @" Public Custom Event TestEvent As EventHandler
AddHandler(ByVal value As EventHandler)
Handlers = CType([Delegate].Combine(Handlers, value), _
EventHandler)
End AddHandler
RemoveHandler(ByVal value as EventHandler)
Handlers = CType([Delegate].Remove(Handlers, value), _
EventHandler)
End RemoveHandler
RaiseEvent(ByVal sender As Object, ByVal e As EventArgs)
Dim TempHandlers As EventHandler = Handlers
If TempHandlers IsNot Nothing Then
TempHandlers(sender, e)
End If
End RaiseEvent
End Event";
CustomEventDeclaration customEventDecl = (CustomEventDeclaration)ParseUtilVBNet.ParseTypeMember(code, typeof(ContinueStatement));
Assert.IsNotNull(customEventDecl);
Assert.AreEqual("TestEvent", customEventDecl.Name);
}
#endregion
}
}
Loading…
Cancel
Save