Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@188 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
20 changed files with 3855 additions and 3459 deletions
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,88 @@
@@ -0,0 +1,88 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Daniel Grunwald |
||||
* Date: 16.07.2005 |
||||
* Time: 16:32 |
||||
*/ |
||||
|
||||
using System; |
||||
using System.Text; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
|
||||
using ICSharpCode.NRefactory.Parser; |
||||
using ICSharpCode.NRefactory.Parser.VB; |
||||
using ICSharpCode.NRefactory.Parser.AST; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// This class converts C# constructs to their VB.NET equivalents.
|
||||
/// </summary>
|
||||
public class CSharpToVBNetConvertVisitor : AbstractASTVisitor |
||||
{ |
||||
// The following conversions are implemented:
|
||||
// Conflicting field/property names -> m_field
|
||||
// a == null -> a Is Nothing
|
||||
// a != null -> a Is Not Nothing
|
||||
|
||||
// The following conversions should be implemented in the future:
|
||||
// ForStatement -> ForNextStatement when for-loop is simple
|
||||
// if (Event != null) Event(this, bla); -> RaiseEvent Event(this, bla)
|
||||
|
||||
public override object Visit(BinaryOperatorExpression binaryOperatorExpression, object data) |
||||
{ |
||||
if (binaryOperatorExpression.Op == BinaryOperatorType.Equality || binaryOperatorExpression.Op == BinaryOperatorType.InEquality) { |
||||
if (IsNullLiteralExpression(binaryOperatorExpression.Left)) { |
||||
Expression tmp = binaryOperatorExpression.Left; |
||||
binaryOperatorExpression.Left = binaryOperatorExpression.Right; |
||||
binaryOperatorExpression.Right = tmp; |
||||
} |
||||
if (IsNullLiteralExpression(binaryOperatorExpression.Right)) { |
||||
if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) { |
||||
binaryOperatorExpression.Op = BinaryOperatorType.ReferenceEquality; |
||||
} else { |
||||
binaryOperatorExpression.Op = BinaryOperatorType.ReferenceInequality; |
||||
} |
||||
} |
||||
} |
||||
return base.Visit(binaryOperatorExpression, data); |
||||
} |
||||
|
||||
bool IsNullLiteralExpression(Expression expr) |
||||
{ |
||||
PrimitiveExpression pe = expr as PrimitiveExpression; |
||||
if (pe == null) return false; |
||||
return pe.Value == null; |
||||
} |
||||
|
||||
public override object Visit(TypeDeclaration td, object data) |
||||
{ |
||||
// Conflicting field/property names -> m_field
|
||||
List<string> properties = new List<string>(); |
||||
foreach (object o in td.Children) { |
||||
PropertyDeclaration pd = o as PropertyDeclaration; |
||||
if (pd != null) { |
||||
properties.Add(pd.Name); |
||||
} |
||||
} |
||||
List<VariableDeclaration> conflicts = new List<VariableDeclaration>(); |
||||
foreach (object o in td.Children) { |
||||
FieldDeclaration fd = o as FieldDeclaration; |
||||
if (fd != null) { |
||||
foreach (VariableDeclaration var in fd.Fields) { |
||||
string name = var.Name; |
||||
foreach (string propertyName in properties) { |
||||
if (name.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase)) { |
||||
conflicts.Add(var); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
new PrefixFieldsVisitor(conflicts, "m_").Run(td); |
||||
return base.Visit(td, data); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,170 @@
@@ -0,0 +1,170 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Daniel Grunwald |
||||
* Date: 16.07.2005 |
||||
* Time: 16:33 |
||||
*/ |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Parser.AST; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// Prefixes the names of the specified fields with the prefix and replaces the use.
|
||||
/// </summary>
|
||||
public class PrefixFieldsVisitor : AbstractASTVisitor |
||||
{ |
||||
List<VariableDeclaration> fields; |
||||
List<string> curBlock = new List<string>(); |
||||
Stack<List<string>> blocks = new Stack<List<string>>(); |
||||
string prefix; |
||||
|
||||
public PrefixFieldsVisitor(List<VariableDeclaration> fields, string prefix) |
||||
{ |
||||
this.fields = fields; |
||||
this.prefix = prefix; |
||||
} |
||||
|
||||
public void Run(TypeDeclaration typeDeclaration) |
||||
{ |
||||
base.Visit(typeDeclaration, null); |
||||
foreach (VariableDeclaration decl in fields) { |
||||
decl.Name = prefix + decl.Name; |
||||
} |
||||
} |
||||
|
||||
public override object Visit(TypeDeclaration typeDeclaration, object data) |
||||
{ |
||||
// TODO: treat fields of base types like locals
|
||||
return base.Visit(typeDeclaration, data); |
||||
} |
||||
|
||||
public override object Visit(BlockStatement blockStatement, object data) |
||||
{ |
||||
Push(); |
||||
object result = base.Visit(blockStatement, data); |
||||
Pop(); |
||||
return result; |
||||
} |
||||
|
||||
public override object Visit(MethodDeclaration methodDeclaration, object data) |
||||
{ |
||||
Push(); |
||||
object result = base.Visit(methodDeclaration, data); |
||||
Pop(); |
||||
return result; |
||||
} |
||||
|
||||
public override object Visit(PropertyGetRegion p, object data) |
||||
{ |
||||
Push(); |
||||
object result = base.Visit(p, data); |
||||
Pop(); |
||||
return result; |
||||
} |
||||
|
||||
public override object Visit(PropertySetRegion p, object data) |
||||
{ |
||||
Push(); |
||||
object result = base.Visit(p, data); |
||||
Pop(); |
||||
return result; |
||||
} |
||||
|
||||
public override object Visit(ConstructorDeclaration constructorDeclaration, object data) |
||||
{ |
||||
Push(); |
||||
object result = base.Visit(constructorDeclaration, data); |
||||
Pop(); |
||||
return result; |
||||
} |
||||
|
||||
private void Push() |
||||
{ |
||||
blocks.Push(curBlock); |
||||
curBlock = new List<string>(); |
||||
} |
||||
|
||||
private void Pop() |
||||
{ |
||||
curBlock = blocks.Pop(); |
||||
} |
||||
|
||||
public override object Visit(LocalVariableDeclaration localVariableDeclaration, object data) |
||||
{ |
||||
foreach (VariableDeclaration decl in localVariableDeclaration.Variables) { |
||||
//print("add variable ${decl.Name} to block")
|
||||
curBlock.Add(decl.Name); |
||||
} |
||||
return base.Visit(localVariableDeclaration, data); |
||||
} |
||||
|
||||
public override object Visit(ParameterDeclarationExpression parameterDeclarationExpression, object data) |
||||
{ |
||||
curBlock.Add(parameterDeclarationExpression.ParameterName); |
||||
//print("add parameter ${parameterDeclarationExpression.ParameterName} to block")
|
||||
return base.Visit(parameterDeclarationExpression, data); |
||||
} |
||||
|
||||
public override object Visit(IdentifierExpression identifierExpression, object data) |
||||
{ |
||||
string name = identifierExpression.Identifier; |
||||
foreach (VariableDeclaration var in fields) { |
||||
if (var.Name == name && !IsLocal(name)) { |
||||
identifierExpression.Identifier = prefix + name; |
||||
break; |
||||
} |
||||
} |
||||
return base.Visit(identifierExpression, data); |
||||
} |
||||
|
||||
public override object Visit(FieldReferenceExpression fieldReferenceExpression, object data) |
||||
{ |
||||
if (fieldReferenceExpression.TargetObject is ThisReferenceExpression) { |
||||
string name = fieldReferenceExpression.FieldName; |
||||
foreach (VariableDeclaration var in fields) { |
||||
if (var.Name == name) { |
||||
fieldReferenceExpression.FieldName = prefix + name; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
return base.Visit(fieldReferenceExpression, data); |
||||
} |
||||
|
||||
bool IsLocal(string name) |
||||
{ |
||||
foreach (List<string> block in blocks) { |
||||
if (block.Contains(name)) |
||||
return true; |
||||
} |
||||
return curBlock.Contains(name); |
||||
} |
||||
|
||||
/* |
||||
public override object Visit(invocationExpression as InvocationExpression, object data) |
||||
{ |
||||
// this method is a workaround for a bug in SharpRefactory
|
||||
result = data |
||||
if invocationExpression.TargetObject != null: |
||||
result = invocationExpression.TargetObject.AcceptVisitor(self, data) |
||||
if invocationExpression.Parameters != null: |
||||
for n as INode in invocationExpression.Parameters: |
||||
n.AcceptVisitor(self, data) |
||||
return result |
||||
} |
||||
|
||||
public override object Visit(indexerExpression as IndexerExpression, object data) |
||||
{ |
||||
// this method is a workaround for a bug in SharpRefactory
|
||||
result = indexerExpression.TargetObject.AcceptVisitor(self, data) |
||||
for n as INode in indexerExpression.Indices { |
||||
n.AcceptVisitor(self, data) |
||||
} |
||||
return result |
||||
} |
||||
*/ |
||||
} |
||||
} |
||||
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Daniel Grunwald |
||||
* Date: 16.07.2005 |
||||
* Time: 18:24 |
||||
*/ |
||||
|
||||
using System; |
||||
using System.Text; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
|
||||
using ICSharpCode.NRefactory.Parser; |
||||
using ICSharpCode.NRefactory.Parser.VB; |
||||
using ICSharpCode.NRefactory.Parser.AST; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// This class converts VB.NET constructs to their C# equivalents.
|
||||
/// </summary>
|
||||
public class VBNetToCSharpConvertVisitor : AbstractASTVisitor |
||||
{ |
||||
// The following conversions are implemented:
|
||||
// MyBase.New() and MyClass.New() calls inside the constructor are converted to :base() and :this()
|
||||
|
||||
// The following conversions should be implemented in the future:
|
||||
// Public Event EventName(param As String) -> automatic delegate declaration
|
||||
|
||||
public override object Visit(ConstructorDeclaration constructorDeclaration, object data) |
||||
{ |
||||
// MyBase.New() and MyClass.New() calls inside the constructor are converted to :base() and :this()
|
||||
BlockStatement body = constructorDeclaration.Body; |
||||
if (body != null && body.Children.Count > 0) { |
||||
StatementExpression se = body.Children[0] as StatementExpression; |
||||
if (se != null) { |
||||
InvocationExpression ie = se.Expression as InvocationExpression; |
||||
if (ie != null) { |
||||
FieldReferenceExpression fre = ie.TargetObject as FieldReferenceExpression; |
||||
if (fre != null && "New".Equals(fre.FieldName, StringComparison.InvariantCultureIgnoreCase)) { |
||||
if (fre.TargetObject is BaseReferenceExpression || fre.TargetObject is ClassReferenceExpression) { |
||||
body.Children.RemoveAt(0); |
||||
ConstructorInitializer ci = constructorDeclaration.ConstructorInitializer; |
||||
ci.Arguments = ie.Parameters; |
||||
if (fre.TargetObject is BaseReferenceExpression) |
||||
ci.ConstructorInitializerType = ConstructorInitializerType.Base; |
||||
else |
||||
ci.ConstructorInitializerType = ConstructorInitializerType.This; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return base.Visit(constructorDeclaration, data); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue