Browse Source

Fixed C# parser bug that caused InvocationExpressions to have no or incorrect locations.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4960 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
41e2c36afa
  1. 6
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs
  2. 1017
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  3. 34
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  4. 14
      src/Libraries/NRefactory/Test/Parser/Expressions/InvocationExpressionTests.cs

6
src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs

@ -73,8 +73,10 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -73,8 +73,10 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
// SEMICOLON HACK : without a trailing semicolon, parsing expressions does not work correctly
if (la.kind == Tokens.Semicolon) lexer.NextToken();
if (expr != null) {
expr.StartLocation = startLocation;
expr.EndLocation = t.EndLocation;
if (expr.StartLocation.IsEmpty)
expr.StartLocation = startLocation;
if (expr.EndLocation.IsEmpty)
expr.EndLocation = t.EndLocation;
expr.AcceptVisitor(new SetParentVisitor(), null);
}
Expect(Tokens.EOF);

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

File diff suppressed because it is too large Load Diff

34
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -1782,8 +1782,10 @@ Expr<out Expression expr> @@ -1782,8 +1782,10 @@ Expr<out Expression expr>
)
)
(. if (expr != null) {
expr.StartLocation = startLocation;
expr.EndLocation = t.EndLocation;
if (expr.StartLocation.IsEmpty)
expr.StartLocation = startLocation;
if (expr.EndLocation.IsEmpty)
expr.EndLocation = t.EndLocation;
}
.)
.
@ -1938,14 +1940,14 @@ PrimaryExpr<out Expression pexpr> @@ -1938,14 +1940,14 @@ PrimaryExpr<out Expression pexpr>
(. startLocation = la.Location; .)
(
"++" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); .)
| "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .)
)
|
"--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .)
/*--- member access */
| PointerMemberAccess<out pexpr, pexpr>
| MemberAccess<out pexpr, pexpr>
| PointerMemberAccess<out pexpr, pexpr>
| MemberAccess<out pexpr, pexpr>
/*--- invocation expression: */
| "("
| "("
(. List<Expression> parameters = new List<Expression>(); .)
(. pexpr = new InvocationExpression(pexpr, parameters); .)
[ Argument<out expr> (. SafeAdd(pexpr, parameters, expr); .)
@ -1958,13 +1960,15 @@ PrimaryExpr<out Expression pexpr> @@ -1958,13 +1960,15 @@ PrimaryExpr<out Expression pexpr>
List<Expression> indices = new List<Expression>();
pexpr = new IndexerExpression(pexpr, indices);
.)
"[" Expr<out expr> (. SafeAdd(pexpr, indices, expr); .)
{ "," Expr<out expr> (. SafeAdd(pexpr, indices, expr); .)
} "]"
"[" Expr<out expr> (. SafeAdd(pexpr, indices, expr); .)
{ "," Expr<out expr> (. SafeAdd(pexpr, indices, expr); .)
} "]"
)
(. if (pexpr != null) {
pexpr.StartLocation = startLocation;
pexpr.EndLocation = t.EndLocation;
if (pexpr.StartLocation.IsEmpty)
pexpr.StartLocation = startLocation;
if (pexpr.EndLocation.IsEmpty)
pexpr.EndLocation = t.EndLocation;
}
.)
}
@ -1980,9 +1984,9 @@ MemberAccess<out Expression expr, Expression target> @@ -1980,9 +1984,9 @@ MemberAccess<out Expression expr, Expression target>
}
}
.)
"."
"." (. Location startLocation = t.Location; .)
Identifier
(. expr = new MemberReferenceExpression(target, t.val); expr.StartLocation = t.Location; expr.EndLocation = t.EndLocation; .)
(. expr = new MemberReferenceExpression(target, t.val); expr.StartLocation = startLocation; expr.EndLocation = t.EndLocation; .)
[ IF (IsGenericInSimpleNameOrMemberAccess())
TypeArgumentList<out typeList, false>
(. ((MemberReferenceExpression)expr).TypeArguments = typeList; .)

14
src/Libraries/NRefactory/Test/Parser/Expressions/InvocationExpressionTests.cs

@ -103,6 +103,20 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -103,6 +103,20 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.IsTrue(expr.Arguments[0] is InvocationExpression);
CheckSimpleInvoke((InvocationExpression)expr.Arguments[0]);
}
[Test]
public void NestedInvocationPositions()
{
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("a.B().C(args)");
Assert.AreEqual(new Location(8, 1), expr.StartLocation);
Assert.AreEqual(new Location(14, 1), expr.EndLocation);
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject;
Assert.AreEqual(new Location(6, 1), mre.StartLocation);
Assert.AreEqual(new Location(8, 1), mre.EndLocation);
Assert.AreEqual(new Location(4, 1), mre.TargetObject.StartLocation);
Assert.AreEqual(new Location(6, 1), mre.TargetObject.EndLocation);
}
#endregion
#region VB.NET

Loading…
Cancel
Save