Browse Source

Fixed some NRefactory bugs (Generic method invocations in VB.NET and output visitor bugs)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@439 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
b1bfc258c3
  1. 88
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  2. 15
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  3. 236
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  4. 38
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  5. 2
      src/Libraries/NRefactory/Test/NRefactoryTests.csproj
  6. 27
      src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs
  7. 129
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs
  8. 24
      src/Libraries/NRefactory/Test/Parser/Expressions/InvocationExpressionTests.cs
  9. 2
      src/Main/Base/Project/Src/Dom/Implementations/DefaultParameter.cs

88
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -1,13 +1,14 @@ @@ -1,13 +1,14 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Diagnostics;
@ -121,6 +122,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -121,6 +122,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return typeString;
}
void PrintTemplates(List<TemplateDefinition> templates)
{
if (templates.Count == 0) return;
outputFormatter.PrintToken(Tokens.LessThan);
for (int i = 0; i < templates.Count; i++) {
if (i > 0) PrintFormattedComma();
outputFormatter.PrintIdentifier(templates[i].Name);
}
outputFormatter.PrintToken(Tokens.GreaterThan);
}
public object Visit(TypeReference typeReference, object data)
{
if (typeReference.IsGlobal) {
@ -332,16 +345,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -332,16 +345,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
outputFormatter.PrintIdentifier(typeDeclaration.Name);
if (typeDeclaration.Templates != null && typeDeclaration.Templates.Count > 0) {
outputFormatter.PrintToken(Tokens.LessThan);
for (int i = 0; i < typeDeclaration.Templates.Count; i++) {
if (i > 0) {
PrintFormattedComma();
}
outputFormatter.PrintIdentifier(typeDeclaration.Templates[i].Name);
}
outputFormatter.PrintToken(Tokens.GreaterThan);
}
PrintTemplates(typeDeclaration.Templates);
if (typeDeclaration.BaseTypes != null && typeDeclaration.BaseTypes.Count > 0) {
outputFormatter.Space();
@ -418,12 +422,16 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -418,12 +422,16 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
nodeTracker.TrackedVisit(delegateDeclaration.ReturnType, data);
outputFormatter.Space();
outputFormatter.PrintIdentifier(delegateDeclaration.Name);
PrintTemplates(delegateDeclaration.Templates);
if (prettyPrintOptions.BeforeDelegateDeclarationParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(delegateDeclaration.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
foreach (TemplateDefinition templateDefinition in delegateDeclaration.Templates) {
nodeTracker.TrackedVisit(templateDefinition, data);
}
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
return null;
@ -573,12 +581,16 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -573,12 +581,16 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
nodeTracker.TrackedVisit(methodDeclaration.TypeReference, data);
outputFormatter.Space();
outputFormatter.PrintIdentifier(methodDeclaration.Name);
PrintTemplates(methodDeclaration.Templates);
if (prettyPrintOptions.BeforeMethodDeclarationParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(methodDeclaration.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
foreach (TemplateDefinition templateDefinition in methodDeclaration.Templates) {
nodeTracker.TrackedVisit(templateDefinition, data);
}
OutputBlock(methodDeclaration.Body, this.prettyPrintOptions.MethodBraceStyle);
return null;
}
@ -1568,8 +1580,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1568,8 +1580,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Null);
return null;
}
if (primitiveExpression.Value is bool) {
if ((bool)primitiveExpression.Value) {
object val = primitiveExpression.Value;
if (val is bool) {
if ((bool)val) {
outputFormatter.PrintToken(Tokens.True);
} else {
outputFormatter.PrintToken(Tokens.False);
@ -1577,30 +1592,45 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1577,30 +1592,45 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
if (primitiveExpression.Value is string) {
outputFormatter.PrintText('"' + ConvertString(primitiveExpression.Value.ToString()) + '"');
if (val is string) {
outputFormatter.PrintText('"' + ConvertString(val.ToString()) + '"');
return null;
}
if (primitiveExpression.Value is char) {
outputFormatter.PrintText("'" + ConvertCharLiteral((char)primitiveExpression.Value) + "'");
if (val is char) {
outputFormatter.PrintText("'" + ConvertCharLiteral((char)val) + "'");
return null;
}
if (primitiveExpression.Value is decimal) {
outputFormatter.PrintText(((decimal)primitiveExpression.Value).ToString(NumberFormatInfo.InvariantInfo) + "m");
if (val is decimal) {
outputFormatter.PrintText(((decimal)val).ToString(NumberFormatInfo.InvariantInfo) + "m");
return null;
}
if (primitiveExpression.Value is float) {
outputFormatter.PrintText(((float)primitiveExpression.Value).ToString(NumberFormatInfo.InvariantInfo) + "f");
if (val is float) {
outputFormatter.PrintText(((float)val).ToString(NumberFormatInfo.InvariantInfo) + "f");
return null;
}
if (val is double) {
string text = ((double)val).ToString(NumberFormatInfo.InvariantInfo);
if (text.IndexOf('.') < 0)
outputFormatter.PrintText(text + ".0");
else
outputFormatter.PrintText(text);
return null;
}
if (primitiveExpression.Value is IFormattable) {
outputFormatter.PrintText(((IFormattable)primitiveExpression.Value).ToString(null, NumberFormatInfo.InvariantInfo));
if (val is IFormattable) {
outputFormatter.PrintText(((IFormattable)val).ToString(null, NumberFormatInfo.InvariantInfo));
if (val is uint || val is ulong) {
outputFormatter.PrintText("u");
}
if (val is long || val is ulong) {
outputFormatter.PrintText("l");
}
} else {
outputFormatter.PrintIdentifier(primitiveExpression.Value.ToString());
outputFormatter.PrintText(val.ToString());
}
return null;
@ -1856,6 +1886,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1856,6 +1886,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
nodeTracker.TrackedVisit(invocationExpression.TargetObject, data);
if (invocationExpression.TypeParameters != null && invocationExpression.TypeParameters.Count > 0) {
OutputFormatter.PrintToken(Tokens.LessThan);
AppendCommaSeparatedList(invocationExpression.TypeParameters);
OutputFormatter.PrintToken(Tokens.GreaterThan);
}
if (prettyPrintOptions.BeforeMethodCallParentheses) {
outputFormatter.Space();
}
@ -2338,6 +2374,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2338,6 +2374,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
tokenList.Add(Tokens.Volatile);
}
outputFormatter.PrintTokenList(tokenList);
if ((modifier & Modifier.Partial) != 0) {
outputFormatter.PrintText("partial ");
}
}
void AppendCommaSeparatedList(IList list)

15
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="none" email=""/>
@ -151,7 +151,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -151,7 +151,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (typeReference.IsArrayType) {
for (int i = 0; i < typeReference.RankSpecifier.Length; ++i) {
outputFormatter.PrintToken(Tokens.OpenParenthesis);
for (int j = 1; j < typeReference.RankSpecifier[i]; ++j) {
for (int j = 0; j < typeReference.RankSpecifier[i]; ++j) {
outputFormatter.PrintToken(Tokens.Comma);
}
outputFormatter.PrintToken(Tokens.CloseParenthesis);
@ -1859,6 +1859,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1859,6 +1859,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(InvocationExpression invocationExpression, object data)
{
nodeTracker.TrackedVisit(invocationExpression.TargetObject, data);
if (invocationExpression.TypeParameters != null && invocationExpression.TypeParameters.Count > 0) {
outputFormatter.PrintToken(Tokens.OpenParenthesis);
outputFormatter.PrintToken(Tokens.Of);
outputFormatter.Space();
AppendCommaSeparatedList(invocationExpression.TypeParameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
}
outputFormatter.PrintToken(Tokens.OpenParenthesis);
AppendCommaSeparatedList(invocationExpression.Parameters);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
@ -2347,6 +2354,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2347,6 +2354,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Const);
outputFormatter.Space();
}
if ((modifier & Modifier.Partial) == Modifier.Partial) {
outputFormatter.PrintToken(Tokens.Partial);
outputFormatter.Space();
}
// TODO : Extern
if ((modifier & Modifier.Extern) == Modifier.Extern) {

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

@ -3634,90 +3634,32 @@ out name); @@ -3634,90 +3634,32 @@ out name);
#line 1727 "VBNET.ATG"
pexpr = new FieldReferenceExpression(pexpr, name);
} else {
lexer.NextToken();
InvocationExpression(
#line 1728 "VBNET.ATG"
ArrayList parameters = new ArrayList();
if (StartOf(24)) {
if (StartOf(19)) {
Argument(
#line 1730 "VBNET.ATG"
out expr);
#line 1730 "VBNET.ATG"
if (expr != null) { parameters.Add(expr); }
}
while (la.kind == 12) {
lexer.NextToken();
if (StartOf(19)) {
Argument(
#line 1733 "VBNET.ATG"
out expr);
#line 1733 "VBNET.ATG"
if (expr != null) { parameters.Add(expr); }
}
}
}
Expect(24);
#line 1736 "VBNET.ATG"
pexpr = new InvocationExpression(pexpr, parameters);
ref pexpr);
}
}
} else if (la.kind == 10) {
lexer.NextToken();
IdentifierOrKeyword(
#line 1740 "VBNET.ATG"
#line 1732 "VBNET.ATG"
out name);
#line 1740 "VBNET.ATG"
#line 1732 "VBNET.ATG"
pexpr = new FieldReferenceExpression(pexpr, name);
while (la.kind == 10 || la.kind == 23) {
if (la.kind == 10) {
lexer.NextToken();
IdentifierOrKeyword(
#line 1742 "VBNET.ATG"
#line 1734 "VBNET.ATG"
out name);
#line 1742 "VBNET.ATG"
#line 1734 "VBNET.ATG"
pexpr = new FieldReferenceExpression(pexpr, name);
} else {
lexer.NextToken();
#line 1743 "VBNET.ATG"
ArrayList parameters = new ArrayList();
if (StartOf(24)) {
#line 1745 "VBNET.ATG"
expr = null;
if (StartOf(19)) {
Argument(
#line 1745 "VBNET.ATG"
out expr);
}
#line 1745 "VBNET.ATG"
if (expr != null) { parameters.Add(expr); }
while (la.kind == 12) {
lexer.NextToken();
#line 1747 "VBNET.ATG"
expr = null;
if (StartOf(19)) {
Argument(
#line 1748 "VBNET.ATG"
out expr);
}
#line 1748 "VBNET.ATG"
if (expr != null) { parameters.Add(expr); }
}
}
Expect(24);
#line 1751 "VBNET.ATG"
pexpr = new InvocationExpression(pexpr, parameters);
InvocationExpression(
#line 1735 "VBNET.ATG"
ref pexpr);
}
}
} else SynErr(239);
@ -3936,36 +3878,66 @@ out TypeReference type) { @@ -3936,36 +3878,66 @@ out TypeReference type) {
}
}
void Argument(
#line 1938 "VBNET.ATG"
out Expression argumentexpr) {
void InvocationExpression(
#line 1740 "VBNET.ATG"
ref Expression pexpr) {
#line 1940 "VBNET.ATG"
Expression expr;
argumentexpr = null;
string name;
#line 1741 "VBNET.ATG"
List<TypeReference> typeParameters = new List<TypeReference>();
ArrayList parameters = null;
TypeReference type;
Expect(23);
#line 1745 "VBNET.ATG"
Point start = t.Location;
if (la.kind == 200) {
lexer.NextToken();
TypeName(
#line 1747 "VBNET.ATG"
out type);
#line 1747 "VBNET.ATG"
if (type != null) typeParameters.Add(type);
Expect(24);
Expect(23);
}
ArgumentList(
#line 1750 "VBNET.ATG"
out parameters);
Expect(24);
#line 1752 "VBNET.ATG"
pexpr = new InvocationExpression(pexpr, parameters, typeParameters);
#line 1753 "VBNET.ATG"
pexpr.StartLocation = start; pexpr.EndLocation = t.Location;
}
void ArgumentList(
#line 1923 "VBNET.ATG"
out ArrayList arguments) {
#line 1925 "VBNET.ATG"
arguments = new ArrayList();
Expression expr = null;
if (
#line 1944 "VBNET.ATG"
IsNamedAssign()) {
Identifier();
if (StartOf(19)) {
Argument(
#line 1929 "VBNET.ATG"
out expr);
#line 1944 "VBNET.ATG"
name = t.val;
Expect(13);
Expect(11);
Expr(
#line 1944 "VBNET.ATG"
#line 1929 "VBNET.ATG"
if (expr != null) { arguments.Add(expr); }
while (la.kind == 12) {
lexer.NextToken();
Argument(
#line 1932 "VBNET.ATG"
out expr);
#line 1946 "VBNET.ATG"
argumentexpr = new NamedArgumentExpression(name, expr);
} else if (StartOf(19)) {
Expr(
#line 1949 "VBNET.ATG"
out argumentexpr);
} else SynErr(242);
#line 1932 "VBNET.ATG"
if (expr != null) { arguments.Add(expr); }
}
}
}
void ConditionalAndExpr(
@ -4118,8 +4090,8 @@ out Expression outExpr) { @@ -4118,8 +4090,8 @@ out Expression outExpr) {
ShiftExpr(
#line 1835 "VBNET.ATG"
out outExpr);
while (StartOf(25)) {
if (StartOf(26)) {
while (StartOf(24)) {
if (StartOf(25)) {
if (la.kind == 26) {
lexer.NextToken();
@ -4140,7 +4112,7 @@ out outExpr); @@ -4140,7 +4112,7 @@ out outExpr);
#line 1841 "VBNET.ATG"
op = BinaryOperatorType.GreaterThanOrEqual;
} else SynErr(243);
} else SynErr(242);
ShiftExpr(
#line 1843 "VBNET.ATG"
out expr);
@ -4158,7 +4130,7 @@ out expr); @@ -4158,7 +4130,7 @@ out expr);
#line 1847 "VBNET.ATG"
op = BinaryOperatorType.ReferenceInequality;
} else SynErr(244);
} else SynErr(243);
Expr(
#line 1848 "VBNET.ATG"
out expr);
@ -4249,7 +4221,7 @@ out Expression outExpr) { @@ -4249,7 +4221,7 @@ out Expression outExpr) {
UnaryExpr(
#line 1888 "VBNET.ATG"
out outExpr);
while (StartOf(27)) {
while (StartOf(26)) {
if (la.kind == 16) {
lexer.NextToken();
@ -4341,34 +4313,39 @@ out name); @@ -4341,34 +4313,39 @@ out name);
#line 1981 "VBNET.ATG"
typeref = new TypeReference(name);
} else SynErr(245);
} else SynErr(244);
}
void ArgumentList(
#line 1923 "VBNET.ATG"
out ArrayList arguments) {
void Argument(
#line 1938 "VBNET.ATG"
out Expression argumentexpr) {
#line 1925 "VBNET.ATG"
arguments = new ArrayList();
Expression expr = null;
#line 1940 "VBNET.ATG"
Expression expr;
argumentexpr = null;
string name;
if (StartOf(19)) {
Argument(
#line 1929 "VBNET.ATG"
out expr);
if (
#line 1944 "VBNET.ATG"
IsNamedAssign()) {
Identifier();
#line 1929 "VBNET.ATG"
if (expr != null) { arguments.Add(expr); }
while (la.kind == 12) {
lexer.NextToken();
Argument(
#line 1932 "VBNET.ATG"
#line 1944 "VBNET.ATG"
name = t.val;
Expect(13);
Expect(11);
Expr(
#line 1944 "VBNET.ATG"
out expr);
#line 1932 "VBNET.ATG"
if (expr != null) { arguments.Add(expr); }
}
}
#line 1946 "VBNET.ATG"
argumentexpr = new NamedArgumentExpression(name, expr);
} else if (StartOf(19)) {
Expr(
#line 1949 "VBNET.ATG"
out argumentexpr);
} else SynErr(245);
}
void ArrayTypeModifiers(
@ -4545,7 +4522,7 @@ out ParameterDeclarationExpression p) { @@ -4545,7 +4522,7 @@ out ParameterDeclarationExpression p) {
Expression expr = null;
p = null;ArrayList arrayModifiers = null;
while (StartOf(28)) {
while (StartOf(27)) {
ParameterModifier(
#line 2168 "VBNET.ATG"
mod);
@ -4641,14 +4618,14 @@ out label); @@ -4641,14 +4618,14 @@ out label);
Expect(13);
Statement();
} else if (StartOf(29)) {
} else if (StartOf(28)) {
EmbeddedStatement(
#line 2226 "VBNET.ATG"
out stmt);
#line 2226 "VBNET.ATG"
compilationUnit.AddChild(stmt);
} else if (StartOf(30)) {
} else if (StartOf(29)) {
LocalDeclarationStatement(
#line 2227 "VBNET.ATG"
out stmt);
@ -5201,7 +5178,7 @@ out embeddedStatement); @@ -5201,7 +5178,7 @@ out embeddedStatement);
#line 2446 "VBNET.ATG"
statement = ifStatement;
} else if (StartOf(29)) {
} else if (StartOf(28)) {
EmbeddedStatement(
#line 2449 "VBNET.ATG"
out embeddedStatement);
@ -5220,7 +5197,7 @@ out embeddedStatement); @@ -5220,7 +5197,7 @@ out embeddedStatement);
}
if (la.kind == 85) {
lexer.NextToken();
if (StartOf(29)) {
if (StartOf(28)) {
EmbeddedStatement(
#line 2455 "VBNET.ATG"
out embeddedStatement);
@ -5341,7 +5318,7 @@ out resumeStatement); @@ -5341,7 +5318,7 @@ out resumeStatement);
UnaryExpr(
#line 2499 "VBNET.ATG"
out expr);
if (StartOf(31)) {
if (StartOf(30)) {
AssignmentOperator(
#line 2501 "VBNET.ATG"
out op);
@ -5735,7 +5712,7 @@ IsResumeNext()) { @@ -5735,7 +5712,7 @@ IsResumeNext()) {
resumeStatement = new ResumeStatement(true);
} else if (la.kind == 153) {
lexer.NextToken();
if (StartOf(32)) {
if (StartOf(31)) {
LabelName(
#line 2650 "VBNET.ATG"
out label);
@ -5761,7 +5738,7 @@ out CaseLabel caseClause) { @@ -5761,7 +5738,7 @@ out CaseLabel caseClause) {
#line 2672 "VBNET.ATG"
caseClause = new CaseLabel();
} else if (StartOf(33)) {
} else if (StartOf(32)) {
if (la.kind == 112) {
lexer.NextToken();
}
@ -6166,10 +6143,10 @@ out blockStmt); @@ -6166,10 +6143,10 @@ out blockStmt);
case 239: s = "invalid SimpleExpr"; break;
case 240: s = "invalid AssignmentOperator"; break;
case 241: s = "invalid CastTarget"; break;
case 242: s = "invalid Argument"; break;
case 242: s = "invalid RelationalExpr"; break;
case 243: s = "invalid RelationalExpr"; break;
case 244: s = "invalid RelationalExpr"; break;
case 245: s = "invalid NonArrayTypeName"; break;
case 244: s = "invalid NonArrayTypeName"; break;
case 245: s = "invalid Argument"; break;
case 246: s = "invalid AttributeArguments"; break;
case 247: s = "invalid ParameterModifier"; break;
case 248: s = "invalid Statement"; break;
@ -6222,7 +6199,6 @@ out blockStmt); @@ -6222,7 +6199,6 @@ out blockStmt);
{x,x,T,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,T,T, x,T,x,x, x,x,T,T, T,T,T,T, T,T,x,T, T,T,x,T, T,T,T,T, T,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, T,x,T,x, x,x,x,T, T,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,T,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,x,T, x,x,x,x, x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,T,x,T, T,x,x,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,x},
{x,x,T,T, T,T,T,T, T,T,T,x, T,x,T,T, T,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,T,T, x,T,x,x, x,x,T,T, T,T,T,T, T,T,x,T, T,T,x,T, T,T,T,T, T,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, T,x,T,x, x,x,x,T, T,x,T,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,T,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,x,T, x,x,x,x, x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},

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

@ -1725,33 +1725,33 @@ SimpleExpr<out Expression pexpr> @@ -1725,33 +1725,33 @@ SimpleExpr<out Expression pexpr>
)
{
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name); .)
| "(" (.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); .)
| InvocationExpression<ref pexpr>
}
|
/* this form only occurs in with statements*/
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name);.)
{
"." IdentifierOrKeyword<out name> (. pexpr = new FieldReferenceExpression(pexpr, name); .)
| "(" (.ArrayList parameters = new ArrayList(); .)
[
(. expr = null; .) [ Argument<out expr>] (. if (expr != null) { parameters.Add(expr); } .)
{
"," (. expr = null; .)
[ Argument<out expr> ] (. if (expr != null) { parameters.Add(expr); } .)
}
]
")" (. pexpr = new InvocationExpression(pexpr, parameters); .)
| InvocationExpression<ref pexpr>
}
)
.
.
InvocationExpression<ref Expression pexpr>
(. List<TypeReference> typeParameters = new List<TypeReference>();
ArrayList parameters = null;
TypeReference type; .)
=
"(" (. Point start = t.Location; .)
[ "Of"
TypeName<out type> (. if (type != null) typeParameters.Add(type); .)
")" "("
]
ArgumentList<out parameters>
")"
(. pexpr = new InvocationExpression(pexpr, parameters, typeParameters); .)
(. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .)
.
/* 11.11 */

2
src/Libraries/NRefactory/Test/NRefactoryTests.csproj

@ -131,12 +131,14 @@ @@ -131,12 +131,14 @@
<Compile Include="Lexer\VBNet\LexerPositionTests.cs" />
<Compile Include="Lexer\CSharp\CustomLexerTests.cs" />
<Compile Include="Parser\Expressions\DefaultValueExpressionTests.cs" />
<Compile Include="Output\VBNet\VBNetOutputTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Project\NRefactory.csproj">
<Project>{3a9ae6aa-bc07-4a2f-972c-581e3ae2f195}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
<Folder Include="Output\VBNet" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>

27
src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
@ -114,9 +114,28 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -114,9 +114,28 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
TestExpression("12");
}
[Test]
public void LongInteger()
{
TestExpression("12l");
}
[Test]
public void LongUnsignedInteger()
{
TestExpression("12ul");
}
[Test]
public void UnsignedInteger()
{
TestExpression("12u");
}
[Test]
public void Double()
{
TestExpression("12.5");
TestExpression("12.0");
}
@ -137,5 +156,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -137,5 +156,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestExpression("@class");
}
[Test]
public void GenericDelegate()
{
TestProgram("public delegate void Predicate<T>(T item) where T : IDisposable, ICloneable;");
}
}
}

129
src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

@ -0,0 +1,129 @@ @@ -0,0 +1,129 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using NUnit.Framework;
using ICSharpCode.NRefactory.Parser;
using ICSharpCode.NRefactory.Parser.AST;
using ICSharpCode.NRefactory.PrettyPrinter;
namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
[TestFixture]
public class VBNetOutputTest
{
void TestProgram(string program)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguages.VBNet, new StringReader(program));
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
outputVisitor.Visit(parser.CompilationUnit, null);
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text));
}
string StripWhitespace(string text)
{
return text.Trim().Replace("\t", "").Replace("\r", "").Replace("\n", " ").Replace(" ", " ");
}
void TestTypeMember(string program)
{
TestProgram("Class A\n" + program + "\nEnd Class");
}
void TestStatement(string statement)
{
TestTypeMember("Sub Method()\n" + statement + "\nEnd Sub");
}
void TestExpression(string expression)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguages.VBNet, new StringReader(expression));
Expression e = parser.ParseExpression();
Assert.AreEqual("", parser.Errors.ErrorOutput);
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
e.AcceptVisitor(outputVisitor, null);
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(StripWhitespace(expression), StripWhitespace(outputVisitor.Text));
}
[Test]
public void Field()
{
TestTypeMember("Private a As Integer");
}
[Test]
public void Method()
{
TestTypeMember("Sub Method()\nEnd Sub");
}
[Test]
public void PartialModifier()
{
TestProgram("Public Partial Class Foo\nEnd Class");
}
[Test]
public void GenericClassDefinition()
{
TestProgram("Public Class Foo(Of T As {IDisposable, ICloneable})\nEnd Class");
}
[Test]
public void GenericClassDefinitionWithBaseType()
{
TestProgram("Public Class Foo(Of T As IDisposable)\nInherits BaseType\nEnd Class");
}
[Test]
public void GenericMethodDefinition()
{
TestTypeMember("Public Sub Foo(Of T As {IDisposable, ICloneable})(ByVal arg As T)\nEnd Sub");
}
[Test]
public void ArrayRank()
{
TestStatement("Dim a As Object(,,)");
}
[Test]
public void Assignment()
{
TestExpression("a = b");
}
[Test]
public void Integer()
{
TestExpression("12");
}
[Test]
public void GenericMethodInvocation()
{
TestExpression("GenericMethod(Of T)(arg)");
}
[Test]
public void SpecialIdentifierName()
{
TestExpression("[Class]");
}
[Test]
public void GenericDelegate()
{
TestProgram("Public Delegate Function Predicate(Of T)(ByVal item As T) As String");
}
}
}

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

@ -23,6 +23,16 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -23,6 +23,16 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.AreEqual("myMethod", ((IdentifierExpression)ie.TargetObject).Identifier);
}
void CheckGenericInvoke(InvocationExpression expr)
{
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);
}
#region C#
[Test]
public void CSharpSimpleInvocationExpressionTest()
@ -33,12 +43,7 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -33,12 +43,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
[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);
CheckGenericInvoke((InvocationExpression)ParseUtilCSharp.ParseExpression("myMethod<char>('a')", typeof(InvocationExpression)));
}
[Test]
@ -63,6 +68,13 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -63,6 +68,13 @@ namespace ICSharpCode.NRefactory.Tests.AST
{
CheckSimpleInvoke((InvocationExpression)ParseUtilVBNet.ParseExpression("myMethod()", typeof(InvocationExpression)));
}
[Test]
public void VBNetGenericInvocationExpressionTest()
{
CheckGenericInvoke((InvocationExpression)ParseUtilVBNet.ParseExpression("myMethod(Of Char)(\"a\"c)", typeof(InvocationExpression)));
}
[Test]
public void PrimitiveExpression1Test()
{

2
src/Main/Base/Project/Src/Dom/Implementations/DefaultParameter.cs

@ -145,7 +145,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -145,7 +145,7 @@ namespace ICSharpCode.SharpDevelop.Dom
if(0 != (cmp = ((int)Modifiers - (int)value.Modifiers)))
return cmp;
if (ReturnType.Equals(value.ReturnType))
if (object.Equals(ReturnType, value.ReturnType))
return 0;
else
return -1;

Loading…
Cancel
Save