Browse Source

Fixed StackOverflowException and endless loop when classes had cyclic inheritance. Fixed the VB expression finder for "MethodCall().MethodCall()", added unit tests for the expression finder.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@886 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
0a42f77c37
  1. 10
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/ExpressionFinder.cs
  2. 53
      src/AddIns/BackendBindings/VBNetBinding/Test/ExpressionFinderTest.cs
  3. 57
      src/AddIns/BackendBindings/VBNetBinding/Test/VBNetBinding.Tests.csproj
  4. 22
      src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs
  5. 2
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs
  6. 13
      src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs
  7. 16
      src/SharpDevelop.Tests.sln

10
src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/ExpressionFinder.cs

@ -50,7 +50,7 @@ namespace VBNetBinding.Parser @@ -50,7 +50,7 @@ namespace VBNetBinding.Parser
//Console.WriteLine("cur state {0} got token {1}/{3} going to {2}", GetStateName(state), GetTokenName(curTokenType), GetStateName(stateTable[state, curTokenType]), curTokenType);
state = stateTable[state, curTokenType];
if (state == ACCEPT || state == ACCEPT2)
if (state == ACCEPT || state == ACCEPT2 || state == DOT)
{
lastAccept = this.offset;
}
@ -510,15 +510,15 @@ namespace VBNetBinding.Parser @@ -510,15 +510,15 @@ namespace VBNetBinding.Parser
static int[,] stateTable = new int[,] {
// Err, Dot, Str, ID, New, Brk, Par, Cur, Using
/*ERROR*/ { ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR},
/*START*/ { ERROR, DOT, ACCEPT, ACCEPT, ERROR, MORE, ACCEPT2, CURLY, ACCEPTNOMORE},
/*DOT*/ { ERROR, ERROR, ACCEPT, ACCEPT, ERROR, MORE, ACCEPT, CURLY, ERROR},
/*START*/ { ERROR, ERROR, ACCEPT, ACCEPT, ERROR, MORE, ACCEPT2, CURLY, ACCEPTNOMORE},
/*DOT*/ { ERROR, ERROR, ACCEPT, ACCEPT, ERROR, MORE, ACCEPT2, CURLY, ERROR},
/*MORE*/ { ERROR, ERROR, ACCEPT, ACCEPT, ERROR, MORE, ACCEPT2, CURLY, ERROR},
/*CURLY*/ { ERROR, ERROR, ERROR, ERROR, ERROR, CURLY2, ERROR, ERROR, ERROR},
/*CURLY2*/ { ERROR, ERROR, ERROR, CURLY3, ERROR, ERROR, ERROR, ERROR, ERROR},
/*CURLY3*/ { ERROR, ERROR, ERROR, ERROR, ACCEPTNOMORE, ERROR, ERROR, ERROR, ERROR},
/*ACCEPT*/ { ERROR, ACCEPT2, ERROR, ERROR, ACCEPT, ERROR, ERROR, ERROR, ACCEPTNOMORE},
/*ACCEPT*/ { ERROR, DOT, ERROR, ERROR, ACCEPT, ERROR, ERROR, ERROR, ACCEPTNOMORE},
/*ACCEPTNOMORE*/ { ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR},
/*ACCEPT2*/ { ERROR, ACCEPT2, ERROR, ACCEPT, ACCEPT, ERROR, ERROR, ERROR, ERROR},
/*ACCEPT2*/ { ERROR, DOT, ERROR, ACCEPT, ACCEPT, ERROR, ERROR, ERROR, ERROR},
};
#endregion
}

53
src/AddIns/BackendBindings/VBNetBinding/Test/ExpressionFinderTest.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
/*
* Created by SharpDevelop.
* User: DG
* Date: 13.12.2005
* Time: 19:58
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using NUnit.Framework;
using VBNetBinding.Parser;
namespace VBNetBinding.Tests
{
[TestFixture]
public class ExpressionFinderTest
{
ExpressionFinder ef;
[SetUp]
public void Init()
{
ef = new ExpressionFinder();
}
void Test(string expr, int offset)
{
string fulltext = "Test\n " + expr + ".AnotherField \n TestEnde";
Assert.AreEqual(expr, ef.FindFullExpression(fulltext, 6 + offset).Expression);
}
[Test]
public void FieldReference()
{
Test("abc", 1);
Test("abc.def", 6);
}
[Test]
public void WithFieldReference()
{
Test(".abc", 2);
Test(".abc.def", 7);
}
[Test]
public void MethodCall()
{
Test("abc.Method().Method()", 16);
}
}
}

57
src/AddIns/BackendBindings/VBNetBinding/Test/VBNetBinding.Tests.csproj

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>VBNetBinding.Tests</RootNamespace>
<AssemblyName>VBNetBinding.Tests</AssemblyName>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{50A89267-A28B-4DF3-8E62-912E005143B8}</ProjectGuid>
<OutputPath>..\..\..\..\..\bin\UnitTests\</OutputPath>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<FileAlignment>4096</FileAlignment>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE</DefineConstants>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExpressionFinderTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Libraries\NUnit.Framework\nunit.framework.dll.csproj">
<Project>{83DD7E12-A705-4DBA-9D71-09C8973D9382}</Project>
<Name>nunit.framework.dll</Name>
</ProjectReference>
<ProjectReference Include="..\Project\VBNetBinding.csproj">
<Project>{BF38FB72-B380-4196-AF8C-95749D726C61}</Project>
<Name>VBNetBinding</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

22
src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs

@ -432,17 +432,21 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -432,17 +432,21 @@ namespace ICSharpCode.SharpDevelop.Dom
public List<IClass> GetAccessibleTypes(IClass callingClass)
{
List<IClass> types = new List<IClass>();
List<IClass> visitedTypes = new List<IClass>();
bool isClassInInheritanceTree = callingClass.IsTypeInInheritanceTree(this);
foreach (IClass c in InnerClasses) {
if (c.IsAccessible(callingClass, isClassInInheritanceTree)) {
types.Add(c);
IClass currentClass = this;
do {
if (visitedTypes.Contains(currentClass))
break;
visitedTypes.Add(currentClass);
bool isClassInInheritanceTree = callingClass.IsTypeInInheritanceTree(currentClass);
foreach (IClass c in currentClass.InnerClasses) {
if (c.IsAccessible(callingClass, isClassInInheritanceTree)) {
types.Add(c);
}
}
}
IClass baseClass = BaseClass;
if (baseClass != null) {
types.AddRange(baseClass.GetAccessibleTypes(callingClass));
}
currentClass = currentClass.BaseClass;
} while (currentClass != null);
return types;
}
}

2
src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs

@ -202,7 +202,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -202,7 +202,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
expr.AcceptVisitor(v, null);
if (v.result == null) return null;
v.result.TargetObject = innermost.Expression;
return ResolveInternal(v.result, ExpressionContext.Default);
return ResolveInternal(expr, ExpressionContext.Default);
} else {
return ResolveInternal(innermost.Expression, ExpressionContext.Default);
}

13
src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs

@ -757,11 +757,14 @@ namespace ICSharpCode.Core @@ -757,11 +757,14 @@ namespace ICSharpCode.Core
}
if (name.IndexOf('.') < 0) {
// Try inner classes of parent classes
while ((curType = curType.BaseClass) != null) {
foreach (IClass innerClass in curType.InnerClasses) {
if (language.NameComparer.Equals(innerClass.Name, name))
return innerClass.DefaultReturnType;
// Try inner classes (in full inheritance tree)
// Don't use loop with cur = cur.BaseType because of inheritance cycles
foreach (IClass baseClass in curType.ClassInheritanceTree) {
if (baseClass.ClassType == ClassType.Class) {
foreach (IClass innerClass in baseClass.InnerClasses) {
if (language.NameComparer.Equals(innerClass.Name, name))
return innerClass.DefaultReturnType;
}
}
}
}

16
src/SharpDevelop.Tests.sln

@ -1,9 +1,13 @@ @@ -1,9 +1,13 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# SharpDevelop 2.0.0.866
# SharpDevelop 2.0.0.885
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AddIns", "AddIns", "{14A277EE-7DF1-4529-B639-7D1EF334C1C5}"
ProjectSection(SolutionItems) = postProject
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VBNetBinding.Tests", "AddIns\BackendBindings\VBNetBinding\Test\VBNetBinding.Tests.csproj", "{50A89267-A28B-4DF3-8E62-912E005143B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VBNetBinding", "AddIns\BackendBindings\VBNetBinding\Project\VBNetBinding.csproj", "{BF38FB72-B380-4196-AF8C-95749D726C61}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor.Tests", "AddIns\DisplayBindings\XmlEditor\Test\XmlEditor.Tests.csproj", "{FC0FE702-A87D-4D70-A9B6-1ECCD611125F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor", "AddIns\DisplayBindings\XmlEditor\Project\XmlEditor.csproj", "{6B717BD1-CD5E-498C-A42E-9E6A4584DC48}"
@ -178,6 +182,14 @@ Global @@ -178,6 +182,14 @@ Global
{1F1AC7CD-D154-45BB-8EAF-804CA8055F5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F1AC7CD-D154-45BB-8EAF-804CA8055F5A}.Release|Any CPU.Build.0 = Release|Any CPU
{1F1AC7CD-D154-45BB-8EAF-804CA8055F5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF38FB72-B380-4196-AF8C-95749D726C61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF38FB72-B380-4196-AF8C-95749D726C61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF38FB72-B380-4196-AF8C-95749D726C61}.Release|Any CPU.Build.0 = Release|Any CPU
{BF38FB72-B380-4196-AF8C-95749D726C61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50A89267-A28B-4DF3-8E62-912E005143B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50A89267-A28B-4DF3-8E62-912E005143B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50A89267-A28B-4DF3-8E62-912E005143B8}.Release|Any CPU.Build.0 = Release|Any CPU
{50A89267-A28B-4DF3-8E62-912E005143B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -190,6 +202,8 @@ Global @@ -190,6 +202,8 @@ Global
{6604365C-C702-4C10-9BA8-637F1E3D4D0D} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5}
{6B717BD1-CD5E-498C-A42E-9E6A4584DC48} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5}
{FC0FE702-A87D-4D70-A9B6-1ECCD611125F} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5}
{BF38FB72-B380-4196-AF8C-95749D726C61} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5}
{50A89267-A28B-4DF3-8E62-912E005143B8} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5}
{B08385CD-F0CC-488C-B4F4-EEB34B6D2688} = {6604365C-C702-4C10-9BA8-637F1E3D4D0D}
{1D18D788-F7EE-4585-A23B-34DC8EC63CB8} = {6604365C-C702-4C10-9BA8-637F1E3D4D0D}
{EC06F96A-AEEC-49D6-B03D-AB87C6EB674C} = {6604365C-C702-4C10-9BA8-637F1E3D4D0D}

Loading…
Cancel
Save