Browse Source

Fixed SD2-968: C# to VB conversion error for generic structures.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1671 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
d8cc294df5
  1. 6
      src/Libraries/NRefactory/Project/Src/Ast/TypeReference.cs
  2. 6
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  3. 6
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  4. 2380
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  5. 14
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  6. 16
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  7. 14
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  8. 18
      src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs
  9. 18
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

6
src/Libraries/NRefactory/Project/Src/Ast/TypeReference.cs

@ -15,6 +15,10 @@ namespace ICSharpCode.NRefactory.Ast
{ {
public class TypeReference : AbstractNode, INullable, ICloneable public class TypeReference : AbstractNode, INullable, ICloneable
{ {
public static readonly TypeReference StructConstraint = new TypeReference("constraint: struct");
public static readonly TypeReference ClassConstraint = new TypeReference("constraint: class");
public static readonly TypeReference NewConstraint = new TypeReference("constraint: new");
string type = ""; string type = "";
string systemType = ""; string systemType = "";
int pointerNestingLevel; int pointerNestingLevel;
@ -211,6 +215,8 @@ namespace ICSharpCode.NRefactory.Ast
static string GetSystemType(string type) static string GetSystemType(string type)
{ {
if (types == null) return type;
if (types.ContainsKey(type)) { if (types.ContainsKey(type)) {
return types[type]; return types[type];
} }

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

@ -5012,19 +5012,19 @@ out TypeReference type) {
lexer.NextToken(); lexer.NextToken();
#line 2038 "cs.ATG" #line 2038 "cs.ATG"
type = new TypeReference("struct"); type = TypeReference.StructConstraint;
} else if (la.kind == 58) { } else if (la.kind == 58) {
lexer.NextToken(); lexer.NextToken();
#line 2039 "cs.ATG" #line 2039 "cs.ATG"
type = new TypeReference("struct"); type = TypeReference.ClassConstraint;
} else if (la.kind == 88) { } else if (la.kind == 88) {
lexer.NextToken(); lexer.NextToken();
Expect(20); Expect(20);
Expect(21); Expect(21);
#line 2040 "cs.ATG" #line 2040 "cs.ATG"
type = new TypeReference("struct"); type = TypeReference.NewConstraint;
} else if (StartOf(9)) { } else if (StartOf(9)) {
Type( Type(
#line 2041 "cs.ATG" #line 2041 "cs.ATG"

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

@ -2035,9 +2035,9 @@ TypeParameterConstraintsClause<List<TemplateDefinition> templates>
TypeParameterConstraintsClauseBase<out TypeReference type> TypeParameterConstraintsClauseBase<out TypeReference type>
(. TypeReference t; type = null; .) (. TypeReference t; type = null; .)
= =
"struct" (. type = new TypeReference("struct"); .) "struct" (. type = TypeReference.StructConstraint; .)
| "class" (. type = new TypeReference("struct"); .) | "class" (. type = TypeReference.ClassConstraint; .)
| "new" "(" ")" (. type = new TypeReference("struct"); .) | "new" "(" ")" (. type = TypeReference.NewConstraint; .)
| Type<out t> (. type = t; .) | Type<out t> (. type = t; .)
. .

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

File diff suppressed because it is too large Load Diff

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

@ -382,16 +382,24 @@ TypeParameterConstraints<TemplateDefinition template>
"As" "As"
( (
"{" "{"
TypeName<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .) TypeParameterConstraint<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
{ {
"," ","
TypeName<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .) TypeParameterConstraint<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
} }
"}" "}"
| TypeName<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .) | TypeParameterConstraint<out constraint> (. if (constraint != null) { template.Bases.Add(constraint); } .)
) )
. .
TypeParameterConstraint<out TypeReference constraint>
(. constraint = null; .)
= "Class" (. constraint = TypeReference.ClassConstraint; .)
| "Structure" (. constraint = TypeReference.StructConstraint; .)
| "New" (. constraint = TypeReference.NewConstraint; .)
| TypeName<out constraint>
.
/* 6.4.2 */ /* 6.4.2 */
NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes> NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
(. (.

16
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -128,9 +128,19 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object VisitTypeReference(TypeReference typeReference, object data) public object VisitTypeReference(TypeReference typeReference, object data)
{ {
PrintTypeReferenceWithoutArray(typeReference); if (typeReference == TypeReference.ClassConstraint) {
if (typeReference.IsArrayType) { outputFormatter.PrintToken(Tokens.Class);
PrintArrayRank(typeReference.RankSpecifier, 0); } else if (typeReference == TypeReference.StructConstraint) {
outputFormatter.PrintToken(Tokens.Struct);
} else if (typeReference == TypeReference.NewConstraint) {
outputFormatter.PrintToken(Tokens.New);
outputFormatter.PrintToken(Tokens.OpenParenthesis);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
} else {
PrintTypeReferenceWithoutArray(typeReference);
if (typeReference.IsArrayType) {
PrintArrayRank(typeReference.RankSpecifier, 0);
}
} }
return null; return null;
} }

14
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

@ -129,9 +129,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object VisitTypeReference(TypeReference typeReference, object data) public object VisitTypeReference(TypeReference typeReference, object data)
{ {
PrintTypeReferenceWithoutArray(typeReference); if (typeReference == TypeReference.ClassConstraint) {
if (typeReference.IsArrayType) { outputFormatter.PrintToken(Tokens.Class);
PrintArrayRank(typeReference.RankSpecifier, 0); } else if (typeReference == TypeReference.StructConstraint) {
outputFormatter.PrintToken(Tokens.Structure);
} else if (typeReference == TypeReference.NewConstraint) {
outputFormatter.PrintToken(Tokens.New);
} else {
PrintTypeReferenceWithoutArray(typeReference);
if (typeReference.IsArrayType) {
PrintArrayRank(typeReference.RankSpecifier, 0);
}
} }
return null; return null;
} }

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

@ -376,5 +376,23 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{ {
TestStatement("using (obj) {\n}"); TestStatement("using (obj) {\n}");
} }
[Test]
public void NewConstraint()
{
TestProgram("public struct Rational<T, O> where O : IRationalMath<T>, new()\n{\n}");
}
[Test]
public void StructConstraint()
{
TestProgram("public struct Rational<T, O> where O : struct\n{\n}");
}
[Test]
public void ClassConstraint()
{
TestProgram("public struct Rational<T, O> where O : class\n{\n}");
}
} }
} }

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

@ -373,5 +373,23 @@ End Using");
"\t.AddLine(New Point(Me.ClientSize.Width / 2, 0), (New Point(Me.ClientSize.Width / 2, Me.ClientSize.Height)))\n" + "\t.AddLine(New Point(Me.ClientSize.Width / 2, 0), (New Point(Me.ClientSize.Width / 2, Me.ClientSize.Height)))\n" +
"End With"); "End With");
} }
[Test]
public void NewConstraint()
{
TestProgram("Public Class Rational(Of T, O As {IRationalMath(Of T), New})\nEnd Class");
}
[Test]
public void StructConstraint()
{
TestProgram("Public Class Rational(Of T, O As {IRationalMath(Of T), Structure})\nEnd Class");
}
[Test]
public void ClassConstraint()
{
TestProgram("Public Class Rational(Of T, O As {IRationalMath(Of T), Class})\nEnd Class");
}
} }
} }

Loading…
Cancel
Save