Browse Source

Fixed SD2-971: Correct VB arrays declaration and redim-statements are recognized as code errors.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1669 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
de05357b9e
  1. BIN
      samples/LineCounter/Article/LineCounterSDAddIn/LineCounter.sdaddin
  2. 0
      samples/LineCounter/Article/LineCounterSDAddIn/addinmanager.png
  3. 0
      samples/LineCounter/Article/LineCounterSDAddIn/projectbrowser.png
  4. 0
      samples/LineCounter/Article/LineCounterSDAddIn/properties.png
  5. 0
      samples/LineCounter/Article/LineCounterSDAddIn/screenshot.png
  6. 0
      samples/LineCounter/Article/LineCounterSDAddIn/screenshot2.png
  7. 0
      samples/LineCounter/Article/LineCounterSDAddIn/templatetype.png
  8. 75
      samples/LineCounter/Article/LineCounterSharpDevelopAddIn.html
  9. 2
      samples/LineCounter/LineCounter.addin
  10. 5
      samples/LineCounter/LineCounter.csproj
  11. 2
      samples/SdaUser/SharpDevelopInteraction/InteractionClass.cs
  12. 5
      samples/SdaUser/SharpDevelopInteraction/SharpDevelopInteraction.csproj
  13. 1727
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  14. 111
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  15. 6
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs
  16. 11
      src/Libraries/NRefactory/Test/Parser/Expressions/ArrayCreateExpressionTests.cs
  17. 29
      src/Libraries/NRefactory/Test/Parser/Statements/ReDimStatementTests.cs

BIN
samples/LineCounter/Article/LineCounterSDAddIn/LineCounter.sdaddin

Binary file not shown.

0
samples/LineCounter/Article/LineCounterSharpDevelopAddIn/addinmanager.png → samples/LineCounter/Article/LineCounterSDAddIn/addinmanager.png

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

0
samples/LineCounter/Article/LineCounterSharpDevelopAddIn/projectbrowser.png → samples/LineCounter/Article/LineCounterSDAddIn/projectbrowser.png

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

0
samples/LineCounter/Article/LineCounterSharpDevelopAddIn/properties.png → samples/LineCounter/Article/LineCounterSDAddIn/properties.png

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

0
samples/LineCounter/Article/LineCounterSharpDevelopAddIn/screenshot.png → samples/LineCounter/Article/LineCounterSDAddIn/screenshot.png

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

0
samples/LineCounter/Article/LineCounterSharpDevelopAddIn/screenshot2.png → samples/LineCounter/Article/LineCounterSDAddIn/screenshot2.png

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

0
samples/LineCounter/Article/LineCounterSharpDevelopAddIn/templatetype.png → samples/LineCounter/Article/LineCounterSDAddIn/templatetype.png

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

75
samples/LineCounter/Article/LineCounterSharpDevelopAddIn.html

@ -13,21 +13,25 @@
<link rel="stylesheet" type="text/css" href="http://www.codeproject.com/styles/global.css"></head> <link rel="stylesheet" type="text/css" href="http://www.codeproject.com/styles/global.css"></head>
<body revision='acf4w5gbq8vx_bdf8h26kgddn4:106'> <body revision='acf4w5gbq8vx_bdf8h26kgddn4:106'>
<ul class="download"> <!-- Article Starts - DO NOT ADD HTML/BODY START TAGS-->
<li><a href="LineCounterSharpDevelopAddIn/LineCounterSharpDevelopAddIn.zip">Download Source Project (C#) - * KB</a></li>
<li><a href="LineCounterSharpDevelopAddIn/LineCounter.sdaddin">Download AddIn Installation Package (.sdaddin) - * KB</a></li> <!-- Download Links -->
<ul class=download>
<li><a href='LineCounterSDAddIn/LineCounterSDAddIn.zip'>Download source files - 36 Kb</a></li>
<li><a href="LineCounterSDAddIn/LineCountersdaddin.zip">Download AddIn Installation Package (.sdaddin) - 26 Kb</a></li>
</ul> </ul>
<br> <br>
<p> <p>
<img src="LineCounterSharpDevelopAddIn/screenshot.png"> <img src="LineCounterSDAddIn/screenshot.png">
</p> </p>
<h2> <h2>
Introduction<br> Introduction
</h2> </h2>
When seeing the article When seeing the article
<a href="http://www.codeproject.com/useritems/LineCounterAddin.asp" title="Line Counter - Writing a Visual Studio 2005 Add-In">Line <a href="http://www.codeproject.com/useritems/LineCounterAddin.asp" title="Line Counter - Writing a Visual Studio 2005 Add-In">Line
Counter - Writing a Visual Studio 2005 Add-In</a> Counter - Writing a Visual Studio 2005 Add-In</a>
<a href="http://www.codeproject.com/useritems/LineCounterAddin.asp" target="_blank" title="Line Counter - Writing a Visual Studio 2005 Add-In">[^]</a>, <a href="http://www.codeproject.com/useritems/LineCounterAddin.asp" target="_blank" title="Line Counter - Writing a Visual Studio 2005 Add-In">[^]</a>
written by Jon Rista,
I wanted to show you how to write that AddIn for SharpDevelop.<br> I wanted to show you how to write that AddIn for SharpDevelop.<br>
In this article I will show you how to create an AddIn, but I will not discuss In this article I will show you how to create an AddIn, but I will not discuss
the concepts of the SharpDevelop's AddIn architecture here - you can read more the concepts of the SharpDevelop's AddIn architecture here - you can read more
@ -36,23 +40,24 @@ about that in my article
Applications with the SharpDevelop Core</a> Applications with the SharpDevelop Core</a>
<a href="http://www.codeproject.com/csharp/ICSharpCodeCore.asp" target="_blank" title="Building Applications with the SharpDevelop Core">[^]</a>. <a href="http://www.codeproject.com/csharp/ICSharpCodeCore.asp" target="_blank" title="Building Applications with the SharpDevelop Core">[^]</a>.
The line counter code is taken from the VS 2005 AddIn written by Jon Rista; the The line counter code is taken from the VS 2005 AddIn written by Jon Rista; the
counting algorithm itself is from Oz Solomon.<br> counting algorithm itself is from Oz Solomon.<br> I will discuss every of my changes to the code in this article - after all, there aren't so many changes required.
<br> <br>
<h2> <h2>
Creating a new AddIn Creating a new AddIn
</h2> </h2>
Our AddIn will be a menu entry in the "Tools" menu that opens a document window Our AddIn will be a menu entry in the "Tools" menu that opens a document window
displaying the line counter UI. SharpDevelop already comes with a project displaying the line counter UI. While it is possible to develop SharpDevelop AddIns in Visual Studio, you can get
template for an AddIn extending the "Tools" menu: "Tools menu entry"<br> started a lot faster if you use SharpDevelop because it already comes with a project
<img src="LineCounterSharpDevelopAddIn/templatetype.png"><br> template for an AddIn extending the "Tools" menu: "Tools menu entry".<br>
<img src="LineCounterSDAddIn/templatetype.png"><br>
<br> <br>
We create a SharpDevelop Macro with the name "LineCounter". The "SharpDevelop We create a SharpDevelop AddIn with the name "LineCounter". The "SharpDevelop
AddIn" template could also be used, but it starts with an AddIn defining a pad AddIn" template could also be used, but it starts with an AddIn defining a pad
(a docked tool window like "Projects", "Properties"); the "Tool menu entry" (a docked tool window like "Projects", "Properties"); the "Tool menu entry"
AddIn starts with a menu command.<br> AddIn starts with a menu command.<br>
Now let's look at what SharpDevelop has generated for us:<br> Now let's look at what SharpDevelop has generated for us:<br>
We have a project with a few files:<br> We have a project with a few files:<br>
<img src="LineCounterSharpDevelopAddIn/projectbrowser.png"><br> <img src="LineCounterSDAddIn/projectbrowser.png"><br>
First look at the .addin file:<br> First look at the .addin file:<br>
The template already defines a menu item in the tools menu, we'll just modify The template already defines a menu item in the tools menu, we'll just modify
the label. And we'll add a new section to the .addin file: the &lt;Manifest&gt; the label. And we'll add a new section to the .addin file: the &lt;Manifest&gt;
@ -69,7 +74,7 @@ item inside a &lt;Condition name="SolutionOpen" action="disable"&gt;<br>
Here is how the content of LineCounter.addin should look like after these steps:<br> Here is how the content of LineCounter.addin should look like after these steps:<br>
<pre>&lt;AddIn name = "LineCounter" <pre>&lt;AddIn name = "LineCounter"
author = "Daniel Grunwald" author = "Daniel Grunwald"
url = "http://www.codeproject.com/useritems/LineCounterSharpDevelopAddIn.asp" url = "http://www.codeproject.com/useritems/LineCounterSDAddIn.asp"
description = "Advanced line counter AddIn"> description = "Advanced line counter AddIn">
&lt;Manifest> &lt;Manifest>
@ -92,7 +97,7 @@ Here is how the content of LineCounter.addin should look like after these steps:
&lt;/AddIn> &lt;/AddIn>
</pre>Our menu item uses the "class" attribute. When the menu item is </pre>Our menu item uses the "class" attribute. When the menu item is
clicked, SharpDevelop will create an instance of this class and call its Run() clicked, SharpDevelop will create an instance of this class and call its Run()
method. This class is defined the file Command.cs. The example code from the method. This class is defined in the file Command.cs. The example code from the
template accesses the currently opened text editor and reverses the letters in template accesses the currently opened text editor and reverses the letters in
the currently selected text. We are not interested in accessing the text editor, the currently selected text. We are not interested in accessing the text editor,
so we can delete the content of the Run() method and start writing our own.<br> so we can delete the content of the Run() method and start writing our own.<br>
@ -105,19 +110,20 @@ about missing references. This is because the template is missing the assembly
references to the SharpDevelop libraries - these have to hard-coded paths in references to the SharpDevelop libraries - these have to hard-coded paths in
most cases, so you should add them manually. Add references to most cases, so you should add them manually. Add references to
ICSharpCode.Core.dll and ICSharpCode.SharpDevelop.dll from the bin directory of ICSharpCode.Core.dll and ICSharpCode.SharpDevelop.dll from the bin directory of
your SharpDevelop installation. ICSharpCode.Core contains the AddIn system, we your SharpDevelop installation. ICSharpCode.Core contains the AddIn system,
need the base class of our menu command from it. ICSharpCode.SharpDevelop is the and also the base class for our menu command.
largest part of SharpDevelop, we'll use the project system from it.<br> ICSharpCode.SharpDevelop is the largest part of SharpDevelop, it contains
the project system and many other things.<br>
Make sure you set "Local copy" for the references to Make sure you set "Local copy" for the references to
<span style="FONT-WEIGHT: bold">False</span>.<br> <b>False</b>.<br>
<img src="LineCounterSharpDevelopAddIn/properties.png"><br> <img src="LineCounterSDAddIn/properties.png"><br>
<br> <br>
You should now be able to successfully compile the project. If you look into the You should now be able to successfully compile the project. If you look into the
bin/Debug directory, you will see a copy of LineCounter.addin, the compiled bin/Debug directory, you will see a copy of LineCounter.addin, the compiled
LineCounter.dll and the debug symbols.<br> LineCounter.dll and the debug symbols.<br>
If you want to test your AddIn, you need to register it with SharpDevelop. The If you want to test your AddIn, you need to register it with SharpDevelop. The
best way for testing is to copy these files to the AddIns directory of your best way for testing is to copy these files to the AddIns directory of your
SharpDevelop installation. Restart SharpDevelop to let it load the AddIn. You SharpDevelop installation. Restart SharpDevelop to load the AddIn. You
should see the "Line Counter" command in the Tools menu, disabled until you open should see the "Line Counter" command in the Tools menu, disabled until you open
a solution. If you click the menu item, the message box should show up.<br> a solution. If you click the menu item, the message box should show up.<br>
If you want to update your AddIn, you'll need to shutdown SharpDevelop, copy the If you want to update your AddIn, you'll need to shutdown SharpDevelop, copy the
@ -130,15 +136,15 @@ Visual Studio to write your AddIn...</font><br>
</h2> </h2>
Now to the real work: Implementing the line counter. We want to display the line Now to the real work: Implementing the line counter. We want to display the line
counter user interface as a document, like the start page. Document views in counter user interface as a document, like the start page. Document views in
SharpDevelop are called <span style="FONT-WEIGHT: bold">ViewContents</span>. SharpDevelop are called <b>ViewContents</b>.
There are two types of view contents: primary and secondary. A primary view There are two types of view contents: primary and secondary. A primary view
content is capable of displaying something on its own; a secondary view content content is capable of displaying something on its own; a secondary view content
extends another view content by displaying multiple tabs in the document - extends another view content by displaying multiple tabs in the document -
SharpDevelop's Windows.Forms designer is a secondary view content. We want to SharpDevelop's Windows.Forms designer is a secondary view content. We want to
display a simple document view, so we'll use a normal (primary) view display a simple document view, so we'll use a normal (primary) view
content.<span style="FONT-STYLE: italic"><br> content.<br>
<br> <br>
</span>Showing such a view content is easy:<br> Showing such a view content is easy:<br>
<pre>public override void Run() <pre>public override void Run()
{ {
WorkbenchSingleton.Workbench.ShowView(new LineCounterViewContent()); WorkbenchSingleton.Workbench.ShowView(new LineCounterViewContent());
@ -274,7 +280,7 @@ m_projIconMappings.Add("{00000001-0000-0000-0000-000000000000}", 5);
<p> <p>
Although the extension process is very different in SharpDevelop and Visual Although the extension process is very different in SharpDevelop and Visual
Studio; the API is quite similar - after all, both are modelling MSBuild Studio; the API is quite similar - after all, both are modelling MSBuild
solutions and after a similar feature set. I hope this shows you that porting solutions and a similar feature set. I hope this shows you that porting
AddIns from Visual Studio to SharpDevelop isn't very hard and we would like to AddIns from Visual Studio to SharpDevelop isn't very hard and we would like to
see more SharpDevelop AddIns in the future. see more SharpDevelop AddIns in the future.
</p> </p>
@ -282,7 +288,7 @@ m_projIconMappings.Add("{00000001-0000-0000-0000-000000000000}", 5);
Here an image showing the AddIn counting itself: Here an image showing the AddIn counting itself:
</p> </p>
<p> <p>
<img src="LineCounterSharpDevelopAddIn/screenshot2.png"> <img src="LineCounterSDAddIn/screenshot2.png">
</p> </p>
<h2> <h2>
Possible improvements Possible improvements
@ -337,7 +343,7 @@ can add SharpDevelop icons to an existing image list.<br>
} }
} }
</pre> </pre>
<span style="FONT-WEIGHT: bold"><span style="FONT-WEIGHT: bold"></span></span>We We
will use two instances of this class to control the two image lists will use two instances of this class to control the two image lists
imgProjectTypes and imgFileTypes.<br> imgProjectTypes and imgFileTypes.<br>
ScanSolution() is getting the icon index from m_projIconMappings - we will ScanSolution() is getting the icon index from m_projIconMappings - we will
@ -419,7 +425,7 @@ name "LineCountingAlgorithm". Don't be irritated that it's not defined in the
XML schema for .addin files - we are creating a new possible codon name here; XML schema for .addin files - we are creating a new possible codon name here;
the XML schema is just for code completion when editing the .addin file.<br> the XML schema is just for code completion when editing the .addin file.<br>
Now how can we define this codon type? Constructing objects from the AddInTree Now how can we define this codon type? Constructing objects from the AddInTree
is done by the <span style="FONT-WEIGHT: bold">doozers</span> (the name comes is done by the <b>doozers</b> (the name comes
from from
<a href="http://en.wikipedia.org/wiki/Fraggle_Rock#Doozers" title="Fraggle Rock: Doozers">these <a href="http://en.wikipedia.org/wiki/Fraggle_Rock#Doozers" title="Fraggle Rock: Doozers">these
guys</a> guys</a>
@ -480,8 +486,7 @@ CountingAlgorithmDescriptor. Let's define that class:<br>
} }
</pre><br> </pre><br>
<p> <p>
Now only the change to LineCounterBrowser to actually use this code is Now the LineCounterBrowser code has to be changed to use the code we just wrote.
missing.
</p> </p>
We will need a member variable storing the list of existing counting algorithms:<br> We will need a member variable storing the list of existing counting algorithms:<br>
<pre>List&lt;CountingAlgorithmDescriptor&gt; countingAlgorithms; <pre>List&lt;CountingAlgorithmDescriptor&gt; countingAlgorithms;
@ -555,7 +560,7 @@ the zip file to "LineCounter.sdaddin". That really was everything you had to do
where you can install the AddIn with just one click. AddIns installed this way where you can install the AddIn with just one click. AddIns installed this way
will be extracted to %Application Data%\.ICSharpCode\SharpDevelop2\AddIns.<br> will be extracted to %Application Data%\.ICSharpCode\SharpDevelop2\AddIns.<br>
<br> <br>
<img src="LineCounterSharpDevelopAddIn/addinmanager.png" title="AddIn Manager screenshot"><br> <img src="LineCounterSDAddIn/addinmanager.png" title="AddIn Manager screenshot"><br>
<h2> <h2>
More AddIn-writing help More AddIn-writing help
</h2> </h2>
@ -589,7 +594,7 @@ will be extracted to %Application Data%\.ICSharpCode\SharpDevelop2\AddIns.<br>
Summary Summary
</h2> </h2>
<p> <p>
This article&nbsp;shows you how to start writing SharpDevelop AddIns. It is a This article shows you how to start writing SharpDevelop AddIns. It is a
complete walkthrough from creating a new project to creating the installation complete walkthrough from creating a new project to creating the installation
package. package.
</p> </p>
@ -601,9 +606,7 @@ will be extracted to %Application Data%\.ICSharpCode\SharpDevelop2\AddIns.<br>
18<sup>th</sup> July, 2006: Article published (based on SharpDevelop 18<sup>th</sup> July, 2006: Article published (based on SharpDevelop
2.0.0.1591). 2.0.0.1591).
</ul> </ul>
<br>
<br>
<br> </body>
<br>
<br></body>
</html> </html>

2
samples/LineCounter/LineCounter.addin

@ -5,7 +5,7 @@
<Manifest> <Manifest>
<Identity name="Grunwald.LineCounter"/> <Identity name="Grunwald.LineCounter"/>
<Dependency addin="SharpDevelop" version="2.0"/> <Dependency addin="SharpDevelop" version="2.1"/>
</Manifest> </Manifest>
<Runtime> <Runtime>

5
samples/LineCounter/LineCounter.csproj

@ -51,6 +51,11 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="ICSharpCode.SharpDevelop.Dom">
<HintPath>..\..\bin\ICSharpCode.SharpDevelop.Dom.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="LineCounter.addin"> <None Include="LineCounter.addin">

2
samples/SdaUser/SharpDevelopInteraction/InteractionClass.cs

@ -24,7 +24,7 @@ namespace SharpDevelopInteraction
{ {
public void MakeTransparent() public void MakeTransparent()
{ {
WorkbenchSingleton.SafeThreadAsyncCall(new MethodInvoker(MakeTransparentInternal)); WorkbenchSingleton.SafeThreadAsyncCall(MakeTransparentInternal);
} }
void MakeTransparentInternal() void MakeTransparentInternal()

5
samples/SdaUser/SharpDevelopInteraction/SharpDevelopInteraction.csproj

@ -50,6 +50,11 @@
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="ICSharpCode.SharpDevelop.Dom">
<HintPath>..\..\..\bin\ICSharpCode.SharpDevelop.Dom.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="InteractionClass.cs" /> <Compile Include="InteractionClass.cs" />

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

File diff suppressed because it is too large Load Diff

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

@ -1392,19 +1392,13 @@ InitializationRankList<out List<Expression> rank>
Expression expr = null; Expression expr = null;
.) = .) =
Expr<out expr> Expr<out expr>
[ "To" [ "To" (. EnsureIsZero(expr); .)
(. if (!(expr is PrimitiveExpression) || (expr as PrimitiveExpression).StringValue != "0")
Error("lower bound of array must be zero");
.)
Expr<out expr> Expr<out expr>
] ]
(. if (expr != null) { rank.Add(expr); } .) (. if (expr != null) { rank.Add(expr); } .)
{ "," { ","
Expr<out expr> Expr<out expr>
[ "To" [ "To" (. EnsureIsZero(expr); .)
(. if (!(expr is PrimitiveExpression) || (expr as PrimitiveExpression).StringValue != "0")
Error("lower bound of array must be zero");
.)
Expr<out expr> Expr<out expr>
] ]
(. if (expr != null) { rank.Add(expr); } .) (. if (expr != null) { rank.Add(expr); } .)
@ -1540,6 +1534,15 @@ AssignmentOperator<out AssignmentOperatorType op>
/* 11.4 */ /* 11.4 */
SimpleExpr<out Expression pexpr> SimpleExpr<out Expression pexpr>
=
SimpleNonInvocationExpression<out pexpr>
{ (. string name; .)
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name); .)
| InvocationExpression<ref pexpr>
}
.
SimpleNonInvocationExpression<out Expression pexpr>
(. (.
Expression expr; Expression expr;
TypeReference type = null; TypeReference type = null;
@ -1590,21 +1593,12 @@ SimpleExpr<out Expression pexpr>
| /* 11.5.1 */ "GetType" "(" GetTypeTypeName<out type> ")" (. pexpr = new TypeOfExpression(type); .) | /* 11.5.1 */ "GetType" "(" GetTypeTypeName<out type> ")" (. pexpr = new TypeOfExpression(type); .)
| /* 11.5.2 */ "TypeOf" SimpleExpr<out expr> "Is" TypeName<out type> (. pexpr = new TypeOfIsExpression(expr, type); .) | /* 11.5.2 */ "TypeOf" SimpleExpr<out expr> "Is" TypeName<out type> (. pexpr = new TypeOfIsExpression(expr, type); .)
) )
{ InvocationOrMemberReferenceExpression<ref pexpr> }
| |
/* this form only occurs in WithStatements*/ /* this form only occurs in WithStatements*/
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name);.) "." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(null, name);.)
{ InvocationOrMemberReferenceExpression<ref pexpr> }
) )
. .
InvocationOrMemberReferenceExpression<ref Expression pexpr>
(. string name; .)
=
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name); .)
| InvocationExpression<ref pexpr>
.
InvocationExpression<ref Expression pexpr> InvocationExpression<ref Expression pexpr>
(. List<TypeReference> typeParameters = new List<TypeReference>(); (. List<TypeReference> typeParameters = new List<TypeReference>();
List<Expression> parameters = null; List<Expression> parameters = null;
@ -1820,13 +1814,16 @@ ObjectCreateExpression<out Expression oce>
List<Expression> arguments = null; List<Expression> arguments = null;
ArrayList dimensions = null; ArrayList dimensions = null;
oce = null; oce = null;
bool canBeNormal; bool canBeReDim;
.) = .) =
"New" NonArrayTypeName<out type, false> "New" NonArrayTypeName<out type, false>
["(" ArgumentList<out arguments> ")" ["(" NormalOrReDimArgumentList<out arguments, out canBeNormal, out canBeReDim> ")"
[ IF (la.kind == Tokens.OpenParenthesis) [ IF (la.kind == Tokens.OpenParenthesis)
ArrayTypeModifiers<out dimensions> ArrayTypeModifiers<out dimensions>
ArrayInitializer<out initializer> ArrayInitializer<out initializer>
| ArrayInitializer<out initializer> ] | ArrayInitializer<out initializer>
]
(. if (canBeReDim && !canBeNormal && initializer == null) initializer = new ArrayInitializerExpression(); .)
] ]
(. (.
if (type == null) type = new TypeReference("Object"); // fallback type on parser errors if (type == null) type = new TypeReference("Object"); // fallback type on parser errors
@ -1857,6 +1854,31 @@ ArgumentList<out List<Expression> arguments>
(. if (expr != null) arguments.Add(expr); .) (. if (expr != null) arguments.Add(expr); .)
. .
/* argument list that hasn't decided if it is method call or array initialisation */
NormalOrReDimArgumentList<out List<Expression> arguments, out bool canBeNormal, out bool canBeRedim>
(.
arguments = new List<Expression>();
canBeNormal = true; canBeRedim = !IsNamedAssign();
Expression expr = null;
.)
=
[ Argument<out expr>
[ "To" (. EnsureIsZero(expr); canBeNormal = false; .)
Expr<out expr>
] ]
{ ","
(. if (expr == null) canBeRedim = false; .)
(. arguments.Add(expr ?? Expression.Null); expr = null; .)
(. canBeRedim &= !IsNamedAssign(); .)
[ Argument<out expr>
[ "To" (. EnsureIsZero(expr); canBeNormal = false; .)
Expr<out expr>
] ]
(. if (expr == null) { canBeRedim = false; expr = Expression.Null; } .)
}
(. if (expr != null) arguments.Add(expr); else canBeRedim = false; .)
.
/* Spec, 11.8 */ /* Spec, 11.8 */
Argument<out Expression argumentexpr> Argument<out Expression argumentexpr>
(. (.
@ -2344,14 +2366,14 @@ EmbeddedStatement<out Statement statement>
"Error" Expr<out expr> (. statement = new ErrorStatement(expr); .) "Error" Expr<out expr> (. statement = new ErrorStatement(expr); .)
| /* 10.12.1 */ | /* 10.12.1 */
"ReDim" (. bool isPreserve = false; .) [ "Preserve" (. isPreserve = true; .) ] "ReDim" (. bool isPreserve = false; .) [ "Preserve" (. isPreserve = true; .) ]
Expr<out expr> ReDimClause<out expr>
(. (.
ReDimStatement reDimStatement = new ReDimStatement(isPreserve); ReDimStatement reDimStatement = new ReDimStatement(isPreserve);
statement = reDimStatement; statement = reDimStatement;
InvocationExpression redimClause = expr as InvocationExpression; InvocationExpression redimClause = expr as InvocationExpression;
if (redimClause != null) { reDimStatement.ReDimClauses.Add(redimClause); } if (redimClause != null) { reDimStatement.ReDimClauses.Add(redimClause); }
.) .)
{ "," Expr<out expr> { "," ReDimClause<out expr>
(. redimClause = expr as InvocationExpression; .) (. redimClause = expr as InvocationExpression; .)
(. if (redimClause != null) { reDimStatement.ReDimClauses.Add(redimClause); } .) (. if (redimClause != null) { reDimStatement.ReDimClauses.Add(redimClause); } .)
} }
@ -2561,27 +2583,28 @@ LabelName<out string name>
. .
/* 12.12.1 */ /* 12.12.1 */
/* ReDimClause<out Expression expr>
ReDimClause<out ReDimClause clause> =
(. SimpleNonInvocationExpression<out expr>
Expression initializer = null; ReDimClauseInternal<ref expr>
Expression arrayInitializer = null; .
string name;
.) = ReDimClauseInternal<ref Expression expr>
[Expr<out initializer> "." ] (. List<Expression> arguments; bool canBeNormal; bool canBeRedim; string name; .)
Qualident<out name> =
(. { "." IdentifierOrKeyword<out name> (. expr = new FieldReferenceExpression(expr, name); .)
clause = new ReDimClause(name); | IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
.) InvocationExpression<ref expr>
"(" Expr<out initializer> }
(. "("
clause.Initializers.Add(initializer); NormalOrReDimArgumentList<out arguments, out canBeNormal, out canBeRedim>
.)
{ "," Expr<out initializer> (. clause.Initializers.Add(initializer); .) }
")" ")"
[ ArrayInitializer<out arrayInitializer> ] (. expr = new InvocationExpression(expr, arguments);
. if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) {
*/ ReDimClauseInternal(ref expr);
}
.)
.
/* 10.10.2.3 */ /* 10.10.2.3 */
ResumeStatement<out ResumeStatement resumeStatement> ResumeStatement<out ResumeStatement resumeStatement>

6
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs

@ -238,5 +238,11 @@ namespace ICSharpCode.NRefactory.Parser.VB
// TODO // TODO
return false; return false;
} }
void EnsureIsZero(Expression expr)
{
if (!(expr is PrimitiveExpression) || (expr as PrimitiveExpression).StringValue != "0")
Error("lower bound of array must be zero");
}
} }
} }

11
src/Libraries/NRefactory/Test/Parser/Expressions/ArrayCreateExpressionTests.cs

@ -38,6 +38,17 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual(0, ace.Arguments.Count); Assert.AreEqual(0, ace.Arguments.Count);
Assert.AreEqual(new int[] {0}, ace.CreateType.RankSpecifier); Assert.AreEqual(new int[] {0}, ace.CreateType.RankSpecifier);
} }
[Test]
public void VBNetArrayCreateExpressionTest2()
{
ArrayCreateExpression ace = ParseUtilVBNet.ParseExpression<ArrayCreateExpression>("New Integer(0 To 5){0, 1, 2, 3, 4, 5}");
Assert.AreEqual("Integer", ace.CreateType.Type);
Assert.AreEqual(1, ace.Arguments.Count);
Assert.AreEqual(5, (ace.Arguments[0] as PrimitiveExpression).Value);
Assert.AreEqual(new int[] {0}, ace.CreateType.RankSpecifier);
}
#endregion #endregion
} }

29
src/Libraries/NRefactory/Test/Parser/Statements/ReDimStatementTests.cs

@ -16,11 +16,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[TestFixture] [TestFixture]
public class ReDimStatementTests public class ReDimStatementTests
{ {
#region C#
// No C# representation
#endregion
#region VB.NET
[Test] [Test]
public void VBNetReDimStatementTest() public void VBNetReDimStatementTest()
{ {
@ -51,10 +46,8 @@ Class X
ReDim sTransform(2, iTransformType - 1) ReDim sTransform(2, iTransformType - 1)
ReDim Preserve _Items(_Count) ReDim Preserve _Items(_Count)
ReDim Preserve _Items(nCapacity) ReDim Preserve _Items(nCapacity)
ReDim Preserve _Items(_Count) ReDim Preserve _Items(0 To _Count)
ReDim Preserve _Items(nCapacity) ReDim Preserve _Items(0 To nCapacity)
ReDim Preserve _Items(_Count)
ReDim Preserve _Items(nCapacity)
ReDim sU(m - 1, n - 1) ReDim sU(m - 1, n - 1)
ReDim sW(n - 1) ReDim sW(n - 1)
ReDim sV(n - 1, n - 1) ReDim sV(n - 1, n - 1)
@ -65,30 +58,22 @@ Class X
If (IsNothing(ColLengths)) Then ReDim ColLengths(0) If (IsNothing(ColLengths)) Then ReDim ColLengths(0)
If (ColLengths.Length = (SubItem + 1)) Then ReDim Preserve ColLengths(SubItem + 1) If (ColLengths.Length = (SubItem + 1)) Then ReDim Preserve ColLengths(SubItem + 1)
ReDim sTransform(2, iTransformType - 1) ReDim sTransform(2, iTransformType - 1)
ReDim Preserve _Items(_Count)
ReDim Preserve _Items(nCapacity)
ReDim Preserve _Items(_Count)
ReDim Preserve _Items(nCapacity)
ReDim Preserve _Items(_Count)
ReDim Preserve _Items(nCapacity)
ReDim Preserve Samples(Samples.GetUpperBound(0) + 1) ReDim Preserve Samples(Samples.GetUpperBound(0) + 1)
ReDim Samples(0) ReDim Samples(0)
ReDim BaseCssContent(BaseCssContentRows - 1) ReDim BaseCssContent(BaseCssContentRows - 1)
ReDim mabtRxBuf(Bytes2Read - 1) ReDim mabtRxBuf(Bytes2Read - 1)
ReDim mabtRxBuf(Bytes2Read - 1)
ReDim Preserve primarykey(primarykey.Length) ReDim Preserve primarykey(primarykey.Length)
ReDim Preserve primarykey(primarykey.Length)
ReDim Preserve IntArray(10, 10, 20)
ReDim Preserve IntArray(10, 10, 15) ReDim Preserve IntArray(10, 10, 15)
ReDim X(10, 10) ReDim X(10, 10)
ReDim Preserve IntArray(10, 10, 20) ReDim Preserve IntArray(0 To 10, 10, 0 To 20)
ReDim Preserve IntArray(10, 10, 15) ReDim Preserve IntArray(10, 10, 15)
ReDim X(10, 10) ReDim X(0 To 10, 0 To 10)
ReDim GetMe().IntArray(0 To 10, 10, 0 To 20)
ReDim GetMe(ExplicitParameter := 3).IntArray(0 To 10, 10, 0 To 20)
ReDim SomeType(Of Integer).IntArray(0 To 10, 10, 0 To 20)
End Sub End Sub
End Class"; End Class";
TypeDeclaration typeDeclaration = ParseUtilVBNet.ParseGlobal<TypeDeclaration>(program); TypeDeclaration typeDeclaration = ParseUtilVBNet.ParseGlobal<TypeDeclaration>(program);
} }
#endregion
} }
} }

Loading…
Cancel
Save