Browse Source

- fixed bugs in ExpressionFinder

* expressions starting with primitive type keywords
    * fixed positions of expression if nothing is found (needed for With-CC)
- correctly resolve Array-TypeReferences

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/vbnet@6155 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
8d087bbd83
  1. 1
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg
  2. 89
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs
  3. 14
      src/Main/Base/Test/NRefactoryResolverTests.cs
  4. 10
      src/Main/Base/Test/VBExpressionFinderTests.cs
  5. 53
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs
  6. 4
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs

1
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg

@ -518,6 +518,7 @@ SimpleExpression = @@ -518,6 +518,7 @@ SimpleExpression =
( Literal
| ( "(" Expression ")" )
| IdentifierForExpressionStart
| PrimitiveTypeName
| ( "." | "!" | ".@" | "..." ) (. nextTokenIsStartOfImportsOrAccessExpression = true; wasQualifierTokenAtStart = true; .) [ XmlOpenTag ] IdentifierOrKeyword [ XmlCloseTag ]
| "GetType" "(" TypeName ")"
| "GetXmlNamespace" "(" (. readXmlIdentifier = true; .) Identifier ")"

89
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs

@ -3263,43 +3263,48 @@ partial class ExpressionFinder { @@ -3263,43 +3263,48 @@ partial class ExpressionFinder {
currentState = 138;
break;
} else {
if (set[114].Get(la.kind)) {
currentState = 411;
if (set[111].Get(la.kind)) {
currentState = 138;
break;
} else {
if (la.kind == 129) {
currentState = 409;
if (set[114].Get(la.kind)) {
currentState = 411;
break;
} else {
if (la.kind == 237) {
currentState = 406;
if (la.kind == 129) {
currentState = 409;
break;
} else {
if (la.kind == 10 || la.kind == 17 || la.kind == 19) {
stateStack.Push(138);
nextTokenIsPotentialStartOfExpression = true;
PushContext(Context.Xml, la, t);
goto case 395;
if (la.kind == 237) {
currentState = 406;
break;
} else {
if (la.kind == 127 || la.kind == 210) {
if (la.kind == 10 || la.kind == 17 || la.kind == 19) {
stateStack.Push(138);
goto case 212;
nextTokenIsPotentialStartOfExpression = true;
PushContext(Context.Xml, la, t);
goto case 395;
} else {
if (la.kind == 58 || la.kind == 126) {
if (la.kind == 127 || la.kind == 210) {
stateStack.Push(138);
PushContext(Context.Query, la, t);
goto case 152;
goto case 212;
} else {
if (set[33].Get(la.kind)) {
if (la.kind == 58 || la.kind == 126) {
stateStack.Push(138);
goto case 146;
PushContext(Context.Query, la, t);
goto case 152;
} else {
if (la.kind == 135) {
if (set[33].Get(la.kind)) {
stateStack.Push(138);
goto case 139;
goto case 146;
} else {
Error(la);
goto case 138;
if (la.kind == 135) {
stateStack.Push(138);
goto case 139;
} else {
Error(la);
goto case 138;
}
}
}
}
@ -7190,10 +7195,10 @@ partial class ExpressionFinder { @@ -7190,10 +7195,10 @@ partial class ExpressionFinder {
new BitArray(new int[] {-940564474, 1962934261, 8650975, 1108388124, 81767716, 17272068, -512676304, 4707}),
new BitArray(new int[] {-940564474, 1962934229, 8650975, 1108388124, 81767716, 17272068, -512676304, 4707}),
new BitArray(new int[] {4, -16777216, -1, -1, -1, -1, -1, 16383}),
new BitArray(new int[] {-62257156, 1174405224, -51646385, -972026621, -1039365982, 17106484, -1707866112, 8257}),
new BitArray(new int[] {-62257156, 1174405224, -51646385, -972026621, -1039365982, 17105972, -1707866112, 8257}),
new BitArray(new int[] {-62257156, 1174405160, -51646385, -972026621, -1039365982, 17105972, -1707866112, 8257}),
new BitArray(new int[] {-66451460, 1174405160, -51646385, -972026621, -1039365982, 17105972, -1707866112, 8257}),
new BitArray(new int[] {-62257156, 1174405224, -51384097, -972018405, -1030969182, 17106740, -97186288, 8259}),
new BitArray(new int[] {-62257156, 1174405224, -51384097, -972018405, -1030969182, 17106228, -97186288, 8259}),
new BitArray(new int[] {-62257156, 1174405160, -51384097, -972018405, -1030969182, 17106228, -97186288, 8259}),
new BitArray(new int[] {-66451460, 1174405160, -51384097, -972018405, -1030969182, 17106228, -97186288, 8259}),
new BitArray(new int[] {-1007673342, 889192405, 65, 1074825472, 72843296, 231424, 22030368, 4160}),
new BitArray(new int[] {4, 1140850688, 8650975, 1108355356, 9218084, 17106176, -533656048, 579}),
new BitArray(new int[] {-1007673342, 889192405, 65, 1074825472, 72843296, 231424, 22030368, 4672}),
@ -7202,40 +7207,40 @@ partial class ExpressionFinder { @@ -7202,40 +7207,40 @@ partial class ExpressionFinder {
new BitArray(new int[] {1006632960, 32, 0, 0, 0, 0, 0, 0}),
new BitArray(new int[] {1028, -16777216, -1, -1, -1, -1, -1, 16383}),
new BitArray(new int[] {-1038334, -1258291211, 65, 1074825472, 72844320, 231424, 22030368, 4160}),
new BitArray(new int[] {1007290364, 1140850720, -51646385, -972026621, -1039365982, 17105952, -1976301568, 8257}),
new BitArray(new int[] {1007290364, 1140850720, -51384097, -972018405, -1030969182, 17106208, -365621744, 8259}),
new BitArray(new int[] {-1040382, -1258291209, 65, 1074825472, 72844320, 231424, 22030368, 4160}),
new BitArray(new int[] {0, 0, -60035072, 1027, 0, 0, 134217728, 0}),
new BitArray(new int[] {0, 67108864, 0, 1073743872, 1310752, 65536, 1050656, 64}),
new BitArray(new int[] {4194304, 67108864, 0, 1073743872, 1343520, 65536, 1050656, 64}),
new BitArray(new int[] {-66451460, 1174405160, -51646385, -972026617, -1039365982, 17105972, -1707866112, 8257}),
new BitArray(new int[] {-66451460, 1174405160, -51384097, -972018401, -1030969182, 17106228, -97186288, 8259}),
new BitArray(new int[] {-1048578, 2147483647, -1, -1, -1, -1, -1, -1}),
new BitArray(new int[] {-66451460, 1174405160, -51646385, -972026621, -1039365982, 17105972, -1707866112, 8385}),
new BitArray(new int[] {-66451460, 1174405160, -51384097, -972018405, -1030969182, 17106228, -97186288, 8387}),
new BitArray(new int[] {0, 67108864, 0, 1073743872, 1343520, 65536, 1050656, 64}),
new BitArray(new int[] {4, 1140851008, 8388975, 1108347140, 821280, 21316608, -2144335872, 65}),
new BitArray(new int[] {-64354306, -973078488, -51646385, -972026621, -1039365982, 17105972, -1707866112, 8257}),
new BitArray(new int[] {-64354306, 1191182376, -1311153, -546070781, -1022588750, -1593504708, -1631823826, 8901}),
new BitArray(new int[] {-64354306, -973078488, -51384097, -972018405, -1030969182, 17106228, -97186288, 8259}),
new BitArray(new int[] {-64354306, 1191182376, -1048865, -546062565, -1014191950, -1593504452, -21144002, 8903}),
new BitArray(new int[] {0, 0, 3072, 134447104, 16777216, 8, 0, 0}),
new BitArray(new int[] {-2097156, -1, -1, -1, -1, -1, -1, -1}),
new BitArray(new int[] {-66451460, 1191182376, -1314225, -680517885, -1039365966, -1593504716, -1631823826, 8901}),
new BitArray(new int[] {-66451460, 1191182376, -1051937, -680509669, -1030969166, -1593504460, -21144002, 8903}),
new BitArray(new int[] {6291458, 0, 0, 32768, 0, 0, 0, 0}),
new BitArray(new int[] {-64354306, 1174405160, -51646385, -971993853, -1039365982, 17105972, -1707866112, 8257}),
new BitArray(new int[] {-64354306, 1174405160, -51384097, -971985637, -1030969182, 17106228, -97186288, 8259}),
new BitArray(new int[] {0, 0, 0, -1879044096, 0, 67108864, 67371040, 128}),
new BitArray(new int[] {36, 1140850688, 8388687, 1108347140, 821280, 17105920, -2144335872, 65}),
new BitArray(new int[] {2097158, 1140850688, 8388687, 1108347140, 821280, 17105920, -2144335872, 97}),
new BitArray(new int[] {2097154, -2147483648, 0, 0, 0, 0, 0, 32}),
new BitArray(new int[] {36, 1140850688, 8388687, 1108347140, 821280, 17105928, -2144335872, 65}),
new BitArray(new int[] {-66451460, 1174405160, -51646385, -972026621, -1039365966, 17105972, -1707866108, 8257}),
new BitArray(new int[] {1007290364, 1140850720, -51646385, -972010237, -1039365982, 17105952, -1976301568, 8257}),
new BitArray(new int[] {-66451460, 1174405160, -51384097, -972018405, -1030969166, 17106228, -97186284, 8259}),
new BitArray(new int[] {1007290364, 1140850720, -51384097, -972002021, -1030969182, 17106208, -365621744, 8259}),
new BitArray(new int[] {1007681536, -2147483614, 0, 0, 1024, 0, 0, 0}),
new BitArray(new int[] {1007681536, -2147483616, 0, 0, 1024, 0, 0, 0}),
new BitArray(new int[] {2097154, 0, 0, 0, 0, 0, 0, 129}),
new BitArray(new int[] {2097154, 0, 0, 32768, 0, 0, 0, 129}),
new BitArray(new int[] {-66451460, 1174405160, -51645361, -972026621, -1039365982, 17105972, -1707866112, 8257}),
new BitArray(new int[] {-65402884, 1174409128, -51646385, -971993853, -1039300446, 17105972, -1707866112, 8257}),
new BitArray(new int[] {-65402884, 1174409128, -51646385, -972026621, -1039300446, 17105972, -1707866112, 8257}),
new BitArray(new int[] {-66451460, 1174405160, -51383073, -972018405, -1030969182, 17106228, -97186288, 8259}),
new BitArray(new int[] {-65402884, 1174409128, -51384097, -971985637, -1030903646, 17106228, -97186288, 8259}),
new BitArray(new int[] {-65402884, 1174409128, -51384097, -972018405, -1030903646, 17106228, -97186288, 8259}),
new BitArray(new int[] {1048576, 3968, 0, 0, 0, 0, 0, 0}),
new BitArray(new int[] {-64354306, 1191182376, -1314225, -680517885, -1039365966, -1593504716, -1631823826, 8901}),
new BitArray(new int[] {-64354306, 1191182376, -1314225, -680485117, -1039365966, -1593504716, -1631823826, 8901}),
new BitArray(new int[] {-64354306, 1191182376, -1051937, -680509669, -1030969166, -1593504460, -21144002, 8903}),
new BitArray(new int[] {-64354306, 1191182376, -1051937, -680476901, -1030969166, -1593504460, -21144002, 8903}),
new BitArray(new int[] {2097154, 32, 0, 32768, 0, 0, 0, 0}),
new BitArray(new int[] {7340034, -2147483614, 0, 32768, 0, 0, 0, 0}),
new BitArray(new int[] {7340034, -2147483616, 0, 32768, 0, 0, 0, 0}),
@ -7289,9 +7294,9 @@ partial class ExpressionFinder { @@ -7289,9 +7294,9 @@ partial class ExpressionFinder {
new BitArray(new int[] {1016, 0, 0, 67108864, -1040187392, 32, 33554432, 0}),
new BitArray(new int[] {4, 1073741824, 8388687, 34605312, 821280, 17105920, -2144335872, 65}),
new BitArray(new int[] {0, 0, -1133776896, 3, 0, 0, 0, 0}),
new BitArray(new int[] {-64354306, 1191182376, -1314225, -680386813, -1039365966, -1593504716, -1631823826, 8901}),
new BitArray(new int[] {-64354306, 1191182376, -1051937, -680378597, -1030969166, -1593504460, -21144002, 8903}),
new BitArray(new int[] {0, 0, 33554432, 16777216, 16, 0, 16392, 0}),
new BitArray(new int[] {-66451460, 1174405160, -51645873, -972026621, -1039365982, 17105972, -1707866112, 8257}),
new BitArray(new int[] {-66451460, 1174405160, -51383585, -972018405, -1030969182, 17106228, -97186288, 8259}),
new BitArray(new int[] {1048576, 3968, 0, 0, 65536, 0, 0, 0}),
new BitArray(new int[] {0, 0, 288, 0, 0, 4210688, 0, 0}),
new BitArray(new int[] {-2, -129, -1, -1, -1, -1, -1, -1}),

14
src/Main/Base/Test/NRefactoryResolverTests.cs

@ -855,6 +855,20 @@ End Module @@ -855,6 +855,20 @@ End Module
Assert.IsTrue((result.ResolvedMember as IProperty).IsIndexer);
}
[Test]
public void VBNetArrayParameterTest()
{
string program = @"Module Main
Sub Main()
End Sub
End Module
";
TypeResolveResult result = ResolveVB<TypeResolveResult>(program, "String()", 3, 3, ExpressionContext.Type);
Assert.AreEqual("System.String", result.ResolvedType.FullyQualifiedName);
Assert.IsTrue(result.ResolvedType.IsArrayReturnType);
}
[Test]
public void ConstructorBaseCall()
{

10
src/Main/Base/Test/VBExpressionFinderTests.cs

@ -256,6 +256,16 @@ End Module", @"Module Test @@ -256,6 +256,16 @@ End Module", @"Module Test
End Module", "x", "x", ExpressionContext.Default);
}
[Test]
public void TypeKeywordMember()
{
FindFull(@"Module Test
Sub Main()
String.Format(""{0}"", ""Test"")
End Sub
End Module", "mat", "String.Format(\"{0}\", \"Test\")", ExpressionContext.Default);
}
#region Old Tests
void OldTest(string expr, int offset)
{

53
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs

@ -12,7 +12,7 @@ using System.Collections.ObjectModel; @@ -12,7 +12,7 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Visitors;
using ICSharpCode.SharpDevelop.Dom.CSharp;
@ -121,41 +121,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -121,41 +121,13 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (language == NR.SupportedLanguage.CSharp && !expression.EndsWith(";"))
expression += ";";
using (NR.IParser p = NR.ParserFactory.CreateParser(language, new System.IO.StringReader(expression))) {
p.Lexer.SetInitialLocation(new NR.Location(caretColumn + caretColumnOffset, caretLine));
expr = p.ParseExpression();
if (expr != null) {
expr.AcceptVisitor(new FixAllNodeLocations(new NR.Location(caretColumn + caretColumnOffset, caretLine)), null);
}
}
}
return expr;
}
sealed class FixAllNodeLocations : NodeTrackingAstVisitor
{
readonly NR.Location expressionStart;
public FixAllNodeLocations(ICSharpCode.NRefactory.Location expressionStart)
{
this.expressionStart = expressionStart;
}
protected override void BeginVisit(INode node)
{
node.StartLocation = FixLocation(node.StartLocation);
node.EndLocation = FixLocation(node.EndLocation);
}
NR.Location FixLocation(NR.Location location)
{
if (location.IsEmpty) {
return expressionStart;
} else if (location.Line == 1) {
return new NR.Location(location.Column - 1 + expressionStart.Column, expressionStart.Line);
} else {
return new NR.Location(location.Column, location.Line - 1 + expressionStart.Line);
}
}
}
string GetFixedExpression(ExpressionResult expressionResult)
{
@ -207,8 +179,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -207,8 +179,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return new NamespaceResolveResult(null, null, "");
}
// array
} else if (language == NR.SupportedLanguage.CSharp && expressionResult.Context.IsTypeContext && !expressionResult.Context.IsObjectCreation) {
expr = ParseTypeReference(expression);
}
if (expressionResult.Context.IsTypeContext && !expressionResult.Context.IsObjectCreation) {
expr = ParseTypeReference(expression, language);
}
if (expr == null) {
expr = ParseExpression(expression, 0);
@ -253,13 +226,19 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -253,13 +226,19 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return ResolveInternal(expr, expressionResult.Context);
}
TypeReferenceExpression ParseTypeReference(string typeReference)
TypeReferenceExpression ParseTypeReference(string typeReference, SupportedLanguage language)
{
TypeOfExpression toe = ParseExpression("typeof(" + typeReference + ")", -7) as TypeOfExpression;
string typeOfFunc = "typeof";
if (language == SupportedLanguage.VBNet)
typeOfFunc = "GetType";
TypeOfExpression toe = ParseExpression(typeOfFunc + "(" + typeReference + ")", -(typeOfFunc.Length + 1)) as TypeOfExpression;
if (toe != null)
return new TypeReferenceExpression(toe.TypeReference);
else
return null;
return null;
}
ResolveResult WithResolve(string expression, string fileContent)

4
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs

@ -91,12 +91,12 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet @@ -91,12 +91,12 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet
}
if (p.NextTokenIsPotentialStartOfExpression)
return new ExpressionResult("", DomRegion.Empty, context, expectedSet);
return new ExpressionResult("", new DomRegion(targetPosition.Line, targetPosition.Column), context, expectedSet);
int lastExpressionStartOffset = LocationToOffset(block.lastExpressionStart);
if (lastExpressionStartOffset < 0)
return new ExpressionResult(null, DomRegion.Empty, context, expectedSet);
return new ExpressionResult("", new DomRegion(targetPosition.Line, targetPosition.Column), context, expectedSet);
return MakeResult(text, lastExpressionStartOffset, offset, context, expectedSet);
}

Loading…
Cancel
Save