Browse Source

Improved C# to Boo converter.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@701 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
db979be5f7
  1. 9
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitor.cs
  2. 31
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorTypeMembers.cs
  3. 6
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Test/MemberTests.cs
  4. 19
      src/AddIns/BackendBindings/Boo/StandaloneConverter/Main.cs
  5. 12
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/InterfaceImplementation.cs
  6. 12
      src/Main/Base/Project/Src/Services/Debugger/DebuggerGridControl.cs

9
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitor.cs

@ -125,7 +125,7 @@ namespace NRefactoryToBooConverter @@ -125,7 +125,7 @@ namespace NRefactoryToBooConverter
r |= B.TypeMemberModifiers.Final;
}
if ((m & Modifier.Const) != 0) {
r |= B.TypeMemberModifiers.Final;
r |= B.TypeMemberModifiers.Final | B.TypeMemberModifiers.Static;
}
if ((m & Modifier.New) != 0) {
AddError(node, "shadowing is not supported");
@ -207,10 +207,11 @@ namespace NRefactoryToBooConverter @@ -207,10 +207,11 @@ namespace NRefactoryToBooConverter
if (intrinsicTypeDictionary == null) {
intrinsicTypeDictionary = new Dictionary<string, string>();
foreach (System.Collections.DictionaryEntry entry in new BooTypeSystemServices().Primitives) {
try {
intrinsicTypeDictionary.Add(((Boo.Lang.Compiler.TypeSystem.IEntity)entry.Value).FullName, (string)entry.Key);
} catch (ArgumentException) {}
string fullName = ((Boo.Lang.Compiler.TypeSystem.IEntity)entry.Value).FullName;
string primitiveName = (string)entry.Key;
intrinsicTypeDictionary[fullName] = primitiveName;
}
intrinsicTypeDictionary["System.Object"] = "object"; // and not 'duck'
}
string result;
if (intrinsicTypeDictionary.TryGetValue(typeName, out result))

31
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorTypeMembers.cs

@ -59,6 +59,26 @@ namespace NRefactoryToBooConverter @@ -59,6 +59,26 @@ namespace NRefactoryToBooConverter
return b;
}
B.ExplicitMemberInfo ConvertInterfaceImplementations(List<InterfaceImplementation> implementations, AttributedNode node, string name)
{
if (implementations.Count == 0)
return null;
if (implementations.Count > 1) {
AddError(node, "Multiple explicit interface implementations are not supported");
}
if (implementations[0].MemberName != name) {
AddError(node, "Explicit interface implementation: Implementing member with different name is not supported");
}
B.TypeReference tr = ConvertTypeReference(implementations[0].InterfaceType);
if (tr is B.SimpleTypeReference) {
B.ExplicitMemberInfo explicitInfo = new B.ExplicitMemberInfo(GetLexicalInfo(node));
explicitInfo.InterfaceType = (B.SimpleTypeReference)tr;
return explicitInfo;
}
AddError(node, "Explicit interface implementation: invalid base type, expecting SimpleTypeReference");
return null;
}
B.Method entryPointMethod;
public object Visit(MethodDeclaration methodDeclaration, object data)
@ -72,9 +92,7 @@ namespace NRefactoryToBooConverter @@ -72,9 +92,7 @@ namespace NRefactoryToBooConverter
// TODO: Convert handles clauses to [Handles] attribute
AddError(methodDeclaration, "Handles-clause is not supported.");
}
if (methodDeclaration.InterfaceImplementations.Count > 0) {
AddError(methodDeclaration, "Explicit interface implementation is not supported.");
}
m.ExplicitInfo = ConvertInterfaceImplementations(methodDeclaration.InterfaceImplementations, methodDeclaration, methodDeclaration.Name);
if (methodDeclaration.Templates.Count > 0) {
AddError(methodDeclaration, "Declaring generic methods is not supported.");
}
@ -168,9 +186,7 @@ namespace NRefactoryToBooConverter @@ -168,9 +186,7 @@ namespace NRefactoryToBooConverter
ConvertParameters(propertyDeclaration.Parameters, m.Parameters);
m.EndSourceLocation = GetLocation(propertyDeclaration.EndLocation);
m.Type = ConvertTypeReference(propertyDeclaration.TypeReference);
if (propertyDeclaration.InterfaceImplementations.Count > 0) {
AddError(propertyDeclaration, "Explicit interface implementation is not supported.");
}
m.ExplicitInfo = ConvertInterfaceImplementations(propertyDeclaration.InterfaceImplementations, propertyDeclaration, propertyDeclaration.Name);
if (!propertyDeclaration.IsWriteOnly) {
m.Getter = new B.Method(GetLexicalInfo(propertyDeclaration.GetRegion));
if (propertyDeclaration.GetRegion != null) {
@ -205,6 +221,7 @@ namespace NRefactoryToBooConverter @@ -205,6 +221,7 @@ namespace NRefactoryToBooConverter
ConvertParameters(indexerDeclaration.Parameters, m.Parameters);
m.EndSourceLocation = GetLocation(indexerDeclaration.EndLocation);
m.Type = ConvertTypeReference(indexerDeclaration.TypeReference);
m.ExplicitInfo = ConvertInterfaceImplementations(indexerDeclaration.InterfaceImplementations, indexerDeclaration, "this");
if (!indexerDeclaration.IsWriteOnly) {
m.Getter = new B.Method(GetLexicalInfo(indexerDeclaration.GetRegion));
if (indexerDeclaration.GetRegion != null) {
@ -245,7 +262,7 @@ namespace NRefactoryToBooConverter @@ -245,7 +262,7 @@ namespace NRefactoryToBooConverter
m.EndSourceLocation = GetLocation(eventDeclaration.EndLocation);
m.Type = ConvertTypeReference(eventDeclaration.TypeReference);
if (eventDeclaration.InterfaceImplementations.Count > 0) {
AddError(eventDeclaration, "Explicit interface implementation is not supported.");
AddError(eventDeclaration, "Explicit interface implementation is not supported for events.");
}
if (eventDeclaration.Parameters.Count > 0) {
AddError(eventDeclaration, "Events with parameters are not supported.");

6
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Test/MemberTests.cs

@ -61,6 +61,12 @@ namespace NRefactoryToBooConverter.Tests @@ -61,6 +61,12 @@ namespace NRefactoryToBooConverter.Tests
TestInClass("public static int num;", "public static num as System.Int32");
}
[Test]
public void ConstantField()
{
TestInClass("public const int num = 3;", "public static final num as System.Int32 = 3");
}
[Test]
public void FullyQualifiedField()
{

19
src/AddIns/BackendBindings/Boo/StandaloneConverter/Main.cs

@ -196,18 +196,27 @@ namespace StandaloneConverter @@ -196,18 +196,27 @@ namespace StandaloneConverter
foreach (CompilerError error in errors) {
FailFile(ref isFailed, input, error.ToString());
}
if (isFailed) {
return false;
}
if (warnings.Count > 0) {
if (!isFailed && warnings.Count > 0) {
Console.WriteLine(input + ":");
foreach (CompilerWarning warning in warnings) {
Console.WriteLine(" " + warning.ToString());
}
}
using (StreamWriter w = new StreamWriter(output, false, Encoding.UTF8)) {
foreach (CompilerError error in errors) {
w.WriteLine("ERROR: " + error.ToString());
}
if (errors.Count > 0)
w.WriteLine();
foreach (CompilerWarning warning in warnings) {
w.WriteLine("# WARNING: " + warning.ToString());
}
if (warnings.Count > 0)
w.WriteLine();
BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w);
printer.OnModule(module);
if (module != null) {
printer.OnModule(module);
}
printer.Finish();
}
} catch (Exception ex) {

12
src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/InterfaceImplementation.cs

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 05.11.2005
* Time: 20:57
*/
// <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;

12
src/Main/Base/Project/Src/Services/Debugger/DebuggerGridControl.cs

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 27.10.2005
* Time: 14:18
*/
// <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.Collections.Generic;

Loading…
Cancel
Save