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. 2378
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  5. 14
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  6. 10
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  7. 8
      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 @@ -15,6 +15,10 @@ namespace ICSharpCode.NRefactory.Ast
{
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 systemType = "";
int pointerNestingLevel;
@ -211,6 +215,8 @@ namespace ICSharpCode.NRefactory.Ast @@ -211,6 +215,8 @@ namespace ICSharpCode.NRefactory.Ast
static string GetSystemType(string type)
{
if (types == null) return type;
if (types.ContainsKey(type)) {
return types[type];
}

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

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

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

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

2378
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> @@ -382,16 +382,24 @@ TypeParameterConstraints<TemplateDefinition template>
"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 */
NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
(.

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

@ -128,10 +128,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -128,10 +128,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object VisitTypeReference(TypeReference typeReference, object data)
{
if (typeReference == TypeReference.ClassConstraint) {
outputFormatter.PrintToken(Tokens.Class);
} 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;
}

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

@ -129,10 +129,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -129,10 +129,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object VisitTypeReference(TypeReference typeReference, object data)
{
if (typeReference == TypeReference.ClassConstraint) {
outputFormatter.PrintToken(Tokens.Class);
} 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;
}

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

@ -376,5 +376,23 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -376,5 +376,23 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
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"); @@ -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" +
"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