Browse Source

Added invocation of generic methods to c# parser.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@156 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
79e5c60dcf
  1. 18
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/Expressions/InvocationExpression.cs
  2. 1983
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  3. 15
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  4. 12
      src/Libraries/NRefactory/Test/Parser/Expressions/FieldReferenceExpressionTests.cs
  5. 11
      src/Libraries/NRefactory/Test/Parser/Expressions/InvocationExpressionTests.cs

18
src/Libraries/NRefactory/Project/Src/Parser/AST/General/Expressions/InvocationExpression.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.Parser.AST {
@ -9,6 +10,7 @@ namespace ICSharpCode.NRefactory.Parser.AST { @@ -9,6 +10,7 @@ namespace ICSharpCode.NRefactory.Parser.AST {
Expression targetObject;
// List<Expression> parameters;
ArrayList parameters;
List<TypeReference> typeParameters;
public Expression TargetObject {
get {
@ -28,12 +30,28 @@ namespace ICSharpCode.NRefactory.Parser.AST { @@ -28,12 +30,28 @@ namespace ICSharpCode.NRefactory.Parser.AST {
}
}
public List<TypeReference> TypeParameters {
get {
return typeParameters;
}
set {
typeParameters = value == null ? new List<TypeReference>(1) : value;
}
}
public InvocationExpression(Expression targetObject, ArrayList parameters)
{
this.TargetObject = targetObject;
this.Parameters = parameters;
}
public InvocationExpression(Expression targetObject, ArrayList parameters, List<TypeReference> typeParameters)
{
this.TargetObject = targetObject;
this.Parameters = parameters;
this.TypeParameters = typeParameters;
}
public InvocationExpression(Expression targetObject)
{
this.TargetObject = targetObject;

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

File diff suppressed because it is too large Load Diff

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

@ -309,6 +309,15 @@ bool IsLocalVarDecl () { @@ -309,6 +309,15 @@ bool IsLocalVarDecl () {
pt.kind == Tokens.Identifier;
}
/* True if lookahead is type parameters (<...>) followed by the specified token */
bool IsGenericFollowedBy(int token)
{
Token t = la;
if (t.kind != Tokens.LessThan) return false;
StartPeek();
return SkipGeneric(ref t) && t.kind == token;
}
/* True, if lookahead ident is "where" */
bool IdentIsWhere () {
return la.kind == Tokens.Identifier && la.val == "where";
@ -1869,6 +1878,7 @@ UnaryExpr<out Expression uExpr> @@ -1869,6 +1878,7 @@ UnaryExpr<out Expression uExpr>
PrimaryExpr<out Expression pexpr>
(.
TypeReference type = null;
List<TypeReference> typeList = null;
bool isArrayCreation = false;
Expression expr;
pexpr = null;
@ -1976,6 +1986,11 @@ PrimaryExpr<out Expression pexpr> @@ -1976,6 +1986,11 @@ PrimaryExpr<out Expression pexpr>
[ Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
{ "," Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
} ] ")" (. pexpr = new InvocationExpression(pexpr, parameters); .)
| ( IF (IsGenericFollowedBy(Tokens.OpenParenthesis)) TypeArgumentList<out typeList> )
"(" (. ArrayList parameters = new ArrayList(); .)
[ Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
{ "," Argument<out expr> (. if (expr != null) {parameters.Add(expr);} .)
} ] ")" (. pexpr = new InvocationExpression(pexpr, parameters, typeList); .)
/*--- element access */
| (. if (isArrayCreation) Error("element access not allow on array creation");
ArrayList indices = new ArrayList();

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

@ -27,6 +27,18 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -27,6 +27,18 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.IsTrue(fre.TargetObject is IdentifierExpression);
Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier);
}
[Test]
public void CSharpGenericFieldReferenceExpressionTest()
{
FieldReferenceExpression fre = (FieldReferenceExpression)ParseUtilCSharp.ParseExpression("SomeClass<string>.myField", typeof(FieldReferenceExpression));
Assert.AreEqual("myField", fre.FieldName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
Assert.AreEqual("SomeClass", tr.Type);
Assert.AreEqual(1, tr.GenericTypes.Count);
Assert.AreEqual("System.String", tr.GenericTypes[0].SystemType);
}
#endregion
#region VB.NET

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

@ -32,6 +32,17 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -32,6 +32,17 @@ namespace ICSharpCode.NRefactory.Tests.AST
CheckSimpleInvoke((InvocationExpression)ParseUtilCSharp.ParseExpression("myMethod()", typeof(InvocationExpression)));
}
[Test]
public void CSharpGenericInvocationExpressionTest()
{
InvocationExpression expr = (InvocationExpression)ParseUtilCSharp.ParseExpression("myMethod<char>('a')", typeof(InvocationExpression));
Assert.AreEqual(1, expr.Parameters.Count);
Assert.IsTrue(expr.TargetObject is IdentifierExpression);
Assert.AreEqual("myMethod", ((IdentifierExpression)expr.TargetObject).Identifier);
Assert.AreEqual(1, expr.TypeParameters.Count);
Assert.AreEqual("System.Char", expr.TypeParameters[0].SystemType);
}
[Test]
public void CSharpInvalidNestedInvocationExpressionTest()
{

Loading…
Cancel
Save