Browse Source

Fixed forum-10060: CSharp Parser not setting EndLocation on some LocalVariableDeclaration objects

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4946 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
d3bfe7a542
  1. 1147
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  2. 26
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  3. 22
      src/Libraries/NRefactory/Test/Parser/Statements/LocalVariableDeclarationTests.cs

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

File diff suppressed because it is too large Load Diff

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

@ -1483,8 +1483,6 @@ LocalVariableDeclarator<out VariableDeclaration var> @@ -1483,8 +1483,6 @@ LocalVariableDeclarator<out VariableDeclaration var>
Statement
(.
TypeReference type;
Expression expr;
Statement stmt = null;
Location startPos = la.Location;
.)
@ -1495,26 +1493,10 @@ Statement @@ -1495,26 +1493,10 @@ Statement
IF (IsLabel()) Identifier (. compilationUnit.AddChild(new LabelStatement(t.val)); .)
":" Statement
/*--- local constant declaration: */
| "const" Type<out type> (. LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifiers.Const); string ident = null; var.StartLocation = t.Location; .)
Identifier (. ident = t.val; Location varStart = t.Location; .)
"=" Expr<out expr>
(.
SafeAdd(var, var.Variables, new VariableDeclaration(ident, expr) {
StartLocation = varStart,
EndLocation = t.EndLocation,
TypeReference = type
});
.)
{ "," Identifier (. ident = t.val; .) "=" Expr<out expr>
(.
SafeAdd(var, var.Variables, new VariableDeclaration(ident, expr) {
StartLocation = varStart,
EndLocation = t.EndLocation,
TypeReference = type
});
.) }
";" (. var.EndLocation = t.EndLocation; compilationUnit.AddChild(var); .)
| "const"
LocalVariableDecl<out stmt>
(. if (stmt != null) { ((LocalVariableDeclaration)stmt).Modifier |= Modifiers.Const; } .)
";" (. compilationUnit.AddChild(stmt); .)
/*--- local variable declaration: */
| IF (IsLocalVarDecl()) LocalVariableDecl<out stmt> ";" (. compilationUnit.AddChild(stmt); .)

22
src/Libraries/NRefactory/Test/Parser/Statements/LocalVariableDeclarationTests.cs

@ -208,6 +208,28 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -208,6 +208,28 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual("System.Nullable", type.GenericTypes[0].GenericTypes[0].Type);
Assert.AreEqual("System.Int32", type.GenericTypes[0].GenericTypes[0].GenericTypes[0].Type);
}
[Test]
public void PositionTestWithoutModifier()
{
LocalVariableDeclaration lvd = ParseUtilCSharp.ParseStatement<LocalVariableDeclaration>("\ndouble w = 7;");
Assert.AreEqual(2, lvd.StartLocation.Line);
Assert.AreEqual(1, lvd.StartLocation.Column);
Assert.AreEqual(2, lvd.EndLocation.Line);
Assert.AreEqual(14, lvd.EndLocation.Column);
}
[Test]
public void PositionTestWithModifier()
{
LocalVariableDeclaration lvd = ParseUtilCSharp.ParseStatement<LocalVariableDeclaration>("\nconst double w = 7;");
Assert.AreEqual(Modifiers.Const, lvd.Modifier);
Assert.AreEqual(2, lvd.StartLocation.Line);
Assert.AreEqual(1, lvd.StartLocation.Column);
Assert.AreEqual(2, lvd.EndLocation.Line);
Assert.AreEqual(20, lvd.EndLocation.Column);
}
#endregion
#region VB.NET

Loading…
Cancel
Save