Browse Source

Fixed parsing of try statements with multiple catch clauses (bug introduced in r4526).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4530 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
d23af1f02a
  1. 1006
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  2. 32
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  3. 23
      src/Libraries/NRefactory/Test/Parser/Statements/TryCatchStatementTests.cs

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

File diff suppressed because it is too large Load Diff

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

@ -1697,14 +1697,16 @@ SwitchLabel<out CaseLabel label> @@ -1697,14 +1697,16 @@ SwitchLabel<out CaseLabel label>
TryStatement<out Statement tryStatement>
(.
Statement blockStmt = null, finallyStmt = null;
List<CatchClause> catchClauses = null;
CatchClause catchClause = null;
List<CatchClause> catchClauses = new List<CatchClause>();
.)
=
"try" Block<out blockStmt>
(
CatchClauses<out catchClauses> [ "finally" Block<out finallyStmt> ]
| "finally" Block<out finallyStmt>
)
{
CatchClause<out catchClause>
(. if (catchClause != null) catchClauses.Add(catchClause); .)
}
[ "finally" Block<out finallyStmt> ]
(.
tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt);
if (catchClauses != null) {
@ -1713,36 +1715,28 @@ TryStatement<out Statement tryStatement> @@ -1713,36 +1715,28 @@ TryStatement<out Statement tryStatement>
.)
.
CatchClauses<out List<CatchClause> catchClauses>
(.
catchClauses = new List<CatchClause>();
.)
CatchClause<out CatchClause catchClause>
=
"catch" (. string identifier;
Statement stmt;
TypeReference typeRef;
Location startPos = t.Location;
CatchClause catchClause = null;
catchClause = null;
.)
/*--- general catch clause (as only catch clause) */
(
/*--- general catch clause */
Block<out stmt> (. catchClause = new CatchClause(stmt); .)
/*--- specific catch clause */
| "(" ClassType<out typeRef, false> (. identifier = null; .)
[ Identifier (. identifier = t.val; .) ]
")" Block<out stmt>
(. catchClause = new CatchClause(typeRef, identifier, stmt); .)
{ IF (IsTypedCatch()) "catch" "(" ClassType<out typeRef, false> (. identifier = null; .)
[ Identifier (. identifier = t.val; .) ]
")" Block<out stmt>
(. catchClause = new CatchClause(typeRef, identifier, stmt); .) }
/*--- general catch clause (after specific catch clauses, optional) */
[ "catch" Block<out stmt> (. catchClause = new CatchClause(stmt); .) ]
) (.
)
(.
if (catchClause != null) {
catchClause.StartLocation = startPos;
catchClause.EndLocation = t.Location;
catchClauses.Add(catchClause);
}
.)
.

23
src/Libraries/NRefactory/Test/Parser/Statements/TryCatchStatementTests.cs

@ -21,26 +21,37 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -21,26 +21,37 @@ namespace ICSharpCode.NRefactory.Tests.Ast
public void CSharpSimpleTryCatchStatementTest()
{
TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement<TryCatchStatement>("try { } catch { } ");
// TODO : Extend test.
Assert.IsTrue(tryCatchStatement.FinallyBlock.IsNull);
Assert.AreEqual(1, tryCatchStatement.CatchClauses.Count);
Assert.IsTrue(tryCatchStatement.CatchClauses[0].TypeReference.IsNull);
Assert.IsEmpty(tryCatchStatement.CatchClauses[0].VariableName);
}
[Test]
public void CSharpSimpleTryCatchStatementTest2()
{
TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement<TryCatchStatement>("try { } catch (Exception e) { } ");
// TODO : Extend test.
Assert.IsTrue(tryCatchStatement.FinallyBlock.IsNull);
Assert.AreEqual(1, tryCatchStatement.CatchClauses.Count);
Assert.AreEqual("Exception", tryCatchStatement.CatchClauses[0].TypeReference.Type);
Assert.AreEqual("e", tryCatchStatement.CatchClauses[0].VariableName);
}
[Test]
public void CSharpSimpleTryCatchFinallyStatementTest()
{
TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement<TryCatchStatement>("try { } catch (Exception) { } finally { } ");
// TODO : Extend test.
TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement<TryCatchStatement>("try { } catch (Exception) { } catch { } finally { } ");
Assert.IsFalse(tryCatchStatement.FinallyBlock.IsNull);
Assert.AreEqual(2, tryCatchStatement.CatchClauses.Count);
Assert.AreEqual("Exception", tryCatchStatement.CatchClauses[0].TypeReference.Type);
Assert.IsEmpty(tryCatchStatement.CatchClauses[0].VariableName);
Assert.IsTrue(tryCatchStatement.CatchClauses[1].TypeReference.IsNull);
Assert.IsEmpty(tryCatchStatement.CatchClauses[1].VariableName);
}
#endregion
#region VB.NET
// TODO
#endregion
// TODO
#endregion
}
}

Loading…
Cancel
Save