Browse Source

conditional operator and null coalescing operator for VB.NET

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3370 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Markus Palme 18 years ago
parent
commit
16fcc4255f
  1. 2
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs
  2. 5
      src/Libraries/NRefactory/Project/Src/Ast/Enums.cs
  3. 11
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  4. 8
      src/Libraries/NRefactory/Project/Src/IAstVisitor.cs
  5. 1343
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  6. 35
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  7. 8
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs
  8. 8
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs
  9. 8
      src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs
  10. 8
      src/Libraries/NRefactory/Test/Parser/Expressions/BinaryOperatorExpressionTests.cs
  11. 12
      src/Libraries/NRefactory/Test/Parser/Expressions/ConditionalExpressionTests.cs

2
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs

@ -86,6 +86,7 @@ namespace NRefactoryASTGenerator.Ast
BinaryOperatorType op; BinaryOperatorType op;
Expression right; Expression right;
public BinaryOperatorExpression() { }
public BinaryOperatorExpression(Expression left, BinaryOperatorType op, Expression right) {} public BinaryOperatorExpression(Expression left, BinaryOperatorType op, Expression right) {}
} }
@ -189,6 +190,7 @@ namespace NRefactoryASTGenerator.Ast
Expression trueExpression; Expression trueExpression;
Expression falseExpression; Expression falseExpression;
public ConditionalExpression() { }
public ConditionalExpression(Expression condition, Expression trueExpression, Expression falseExpression) {} public ConditionalExpression(Expression condition, Expression trueExpression, Expression falseExpression) {}
} }

5
src/Libraries/NRefactory/Project/Src/Ast/Enums.cs

@ -198,7 +198,10 @@ namespace ICSharpCode.NRefactory.Ast
/// <summary>VB-only: Like</summary> /// <summary>VB-only: Like</summary>
Like, Like,
/// <summary>C#: ??</summary> /// <summary>
/// C#: ??
/// VB: IF(x, y)
/// </summary>
NullCoalescing, NullCoalescing,
/// <summary>VB-only: !</summary> /// <summary>VB-only: !</summary>

11
src/Libraries/NRefactory/Project/Src/Ast/Generated.cs

@ -434,6 +434,11 @@ namespace ICSharpCode.NRefactory.Ast {
} }
} }
public BinaryOperatorExpression() {
left = Expression.Null;
right = Expression.Null;
}
public BinaryOperatorExpression(Expression left, BinaryOperatorType op, Expression right) { public BinaryOperatorExpression(Expression left, BinaryOperatorType op, Expression right) {
Left = left; Left = left;
Op = op; Op = op;
@ -832,6 +837,12 @@ namespace ICSharpCode.NRefactory.Ast {
} }
} }
public ConditionalExpression() {
condition = Expression.Null;
trueExpression = Expression.Null;
falseExpression = Expression.Null;
}
public ConditionalExpression(Expression condition, Expression trueExpression, Expression falseExpression) { public ConditionalExpression(Expression condition, Expression trueExpression, Expression falseExpression) {
Condition = condition; Condition = condition;
TrueExpression = trueExpression; TrueExpression = trueExpression;

8
src/Libraries/NRefactory/Project/Src/IAstVisitor.cs

@ -1,10 +1,10 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // Dieser Code wurde von einem Tool generiert.
// Runtime Version:2.0.50727.1434 // Laufzeitversion:2.0.50727.3053
// //
// Changes to this file may cause incorrect behavior and will be lost if // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// the code is regenerated. // der Code erneut generiert wird.
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

1343
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

35
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -1673,6 +1673,7 @@ SimpleNonInvocationExpression<out Expression pexpr>
| /* 11.4.5 */ "AddressOf" Expr<out expr> (. pexpr = new AddressOfExpression(expr); .) | /* 11.4.5 */ "AddressOf" Expr<out expr> (. pexpr = new AddressOfExpression(expr); .)
| /* 11.5.1 */ "GetType" "(" GetTypeTypeName<out type> ")" (. pexpr = new TypeOfExpression(type); .) | /* 11.5.1 */ "GetType" "(" GetTypeTypeName<out type> ")" (. pexpr = new TypeOfExpression(type); .)
| /* 11.5.2 */ "TypeOf" SimpleExpr<out expr> "Is" TypeName<out type> (. pexpr = new TypeOfIsExpression(expr, type); .) | /* 11.5.2 */ "TypeOf" SimpleExpr<out expr> "Is" TypeName<out type> (. pexpr = new TypeOfIsExpression(expr, type); .)
| /* 11.22 */ IF (la.kind == Tokens.If) ConditionalExpression<out pexpr>
) )
| |
/* this form only occurs in WithStatements*/ /* this form only occurs in WithStatements*/
@ -1680,6 +1681,40 @@ SimpleNonInvocationExpression<out Expression pexpr>
) )
. .
ConditionalExpression<out Expression expr>
(.
ConditionalExpression conditionalExpression = new ConditionalExpression();
BinaryOperatorExpression binaryOperatorExpression = new BinaryOperatorExpression();
conditionalExpression.StartLocation = binaryOperatorExpression.StartLocation = la.Location;
Expression condition = null;
Expression trueExpr = null;
Expression falseExpr = null;
.)
=
"If" "(" Expr<out condition> "," Expr<out trueExpr> [ "," Expr<out falseExpr> ] ")"
(.
if(falseExpr != null)
{
conditionalExpression.Condition = condition;
conditionalExpression.TrueExpression = trueExpr;
conditionalExpression.FalseExpression = falseExpr;
conditionalExpression.EndLocation = t.EndLocation;
expr = conditionalExpression;
}
else
{
binaryOperatorExpression.Left = condition;
binaryOperatorExpression.Right = trueExpr;
binaryOperatorExpression.Op = BinaryOperatorType.NullCoalescing;
binaryOperatorExpression.EndLocation = t.EndLocation;
expr = binaryOperatorExpression;
}
.)
.
InvocationExpression<ref Expression pexpr> InvocationExpression<ref Expression pexpr>
(. List<TypeReference> typeParameters = new List<TypeReference>(); (. List<TypeReference> typeParameters = new List<TypeReference>();
List<Expression> parameters = null; List<Expression> parameters = null;

8
src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs

@ -1,10 +1,10 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // Dieser Code wurde von einem Tool generiert.
// Runtime Version:2.0.50727.1434 // Laufzeitversion:2.0.50727.3053
// //
// Changes to this file may cause incorrect behavior and will be lost if // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// the code is regenerated. // der Code erneut generiert wird.
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

8
src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs

@ -1,10 +1,10 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // Dieser Code wurde von einem Tool generiert.
// Runtime Version:2.0.50727.1434 // Laufzeitversion:2.0.50727.3053
// //
// Changes to this file may cause incorrect behavior and will be lost if // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// the code is regenerated. // der Code erneut generiert wird.
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

8
src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs

@ -1,10 +1,10 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // Dieser Code wurde von einem Tool generiert.
// Runtime Version:2.0.50727.1434 // Laufzeitversion:2.0.50727.3053
// //
// Changes to this file may cause incorrect behavior and will be lost if // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// the code is regenerated. // der Code erneut generiert wird.
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

8
src/Libraries/NRefactory/Test/Parser/Expressions/BinaryOperatorExpressionTests.cs

@ -432,8 +432,14 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{ {
VBNetTestBinaryOperatorExpressionTest("a Like b", BinaryOperatorType.Like); VBNetTestBinaryOperatorExpressionTest("a Like b", BinaryOperatorType.Like);
} }
#endregion
[Test]
public void VBNetNullCoalescingTest()
{
VBNetTestBinaryOperatorExpressionTest("If(a, b)", BinaryOperatorType.NullCoalescing);
}
#endregion
#region AddIntegerTests #region AddIntegerTests
string AddIntegerToBoe(string input, int number) string AddIntegerToBoe(string input, int number)

12
src/Libraries/NRefactory/Test/Parser/Expressions/ConditionalExpressionTests.cs

@ -91,7 +91,17 @@ namespace ICSharpCode.NRefactory.Tests.Ast
#endregion #endregion
#region VB.NET #region VB.NET
// No VB.NET representation
[Test]
public void VBNetConditionalExpressionTest()
{
ConditionalExpression ce = ParseUtilVBNet.ParseExpression<ConditionalExpression>("If(x IsNot Nothing, x.Test, \"nothing\")");
Assert.IsTrue(ce.Condition is BinaryOperatorExpression);
Assert.IsTrue(ce.TrueExpression is MemberReferenceExpression);
Assert.IsTrue(ce.FalseExpression is PrimitiveExpression);
}
#endregion #endregion
} }
} }

Loading…
Cancel
Save