[scripting] Extracted classes to their own files
This commit is contained in:
Родитель
88e8759d1e
Коммит
e7faf7c57a
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
|
||||
namespace UnityScript2CSharp
|
||||
{
|
||||
internal class BlockIdentation : IDisposable
|
||||
{
|
||||
private readonly Writer _identationAware;
|
||||
|
||||
public BlockIdentation(Writer identationAware)
|
||||
{
|
||||
_identationAware = identationAware;
|
||||
_identationAware.Identation++;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_identationAware.Identation--;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
using CommandLine;
|
||||
|
||||
namespace UnityScript2CSharp
|
||||
{
|
||||
public class CommandLineArguments
|
||||
{
|
||||
[Option('p', HelpText = "Path of project to be converted.")] public string ProjectPath { get; set; }
|
||||
|
||||
[Option('r', HelpText = "Assembly references required by the scripts (space separated list).")] public string References { get; set; }
|
||||
|
||||
[Option('d', HelpText = "Dump the list of scripts being processed.")] public bool Dump { get; set; }
|
||||
|
||||
[Option('i', HelpText = "Ignore errors.")] public bool IgnoreErrors { get; set; }
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,14 @@
|
|||
namespace UnityScript2CSharp
|
||||
{
|
||||
public struct SourceFile
|
||||
{
|
||||
public string FileName;
|
||||
public string Contents;
|
||||
|
||||
public SourceFile(string fileName, string contents)
|
||||
{
|
||||
FileName = fileName;
|
||||
Contents = contents;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
using Boo.Lang.Compiler.Ast;
|
||||
using UnityScript.Steps;
|
||||
|
||||
namespace UnityScript2CSharp.Steps
|
||||
{
|
||||
class SelectiveUnaryExpressionExpansionProcessUnityScriptMethods : ProcessUnityScriptMethods
|
||||
{
|
||||
public override void LeaveUnaryExpression(UnaryExpression node)
|
||||
{
|
||||
if (node.Operator == UnaryOperatorType.PostDecrement ||
|
||||
node.Operator == UnaryOperatorType.PostIncrement ||
|
||||
node.Operator == UnaryOperatorType.Increment ||
|
||||
node.Operator == UnaryOperatorType.Decrement)
|
||||
return; // do not expand post/pre increment/decrement (the syntax is the same as in C#
|
||||
|
||||
base.LeaveUnaryExpression(node);
|
||||
}
|
||||
|
||||
public override void OnForStatement(ForStatement node)
|
||||
{
|
||||
Visit(node.Iterator);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,459 @@
|
|||
using System;
|
||||
using Boo.Lang.Compiler.Ast;
|
||||
using Boo.Lang.Compiler.Steps;
|
||||
|
||||
namespace UnityScript2CSharp.Steps
|
||||
{
|
||||
[Serializable]
|
||||
public class TransformKnownCalls : AbstractTransformerCompilerStep
|
||||
{
|
||||
protected bool isBinaryExp;
|
||||
public override void Run()
|
||||
{
|
||||
Visit(CompileUnit);
|
||||
}
|
||||
|
||||
public override void LeaveBinaryExpression(BinaryExpression node)
|
||||
{
|
||||
Expression left;
|
||||
string value;
|
||||
if (node != null && node.Operator == BinaryOperatorType.Assign)
|
||||
{
|
||||
left = node.Left;
|
||||
if (node.Right is MethodInvocationExpression)
|
||||
{
|
||||
var methodInvocationExpression = (MethodInvocationExpression)node.Right;
|
||||
if (methodInvocationExpression.Target is MemberReferenceExpression)
|
||||
{
|
||||
var memberReferenceExpression = (MemberReferenceExpression)methodInvocationExpression.Target;
|
||||
var target = memberReferenceExpression.Target;
|
||||
if (memberReferenceExpression.Name == "AddComponent" && 1 == methodInvocationExpression.Arguments.Count && methodInvocationExpression.Arguments[0] is StringLiteralExpression)
|
||||
{
|
||||
var stringLiteralExpression = (StringLiteralExpression)methodInvocationExpression.Arguments[0];
|
||||
value = stringLiteralExpression.Value;
|
||||
var binaryExpression = new BinaryExpression(LexicalInfo.Empty);
|
||||
binaryExpression.Operator = BinaryOperatorType.Assign;
|
||||
binaryExpression.Left = Expression.Lift(left);
|
||||
var arg_1D2_0 = binaryExpression;
|
||||
var tryCastExpression = new TryCastExpression(LexicalInfo.Empty);
|
||||
var arg_1B1_0 = tryCastExpression;
|
||||
var methodInvocationExpression2 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_182_0 = methodInvocationExpression2;
|
||||
var memberReferenceExpression2 = new MemberReferenceExpression(LexicalInfo.Empty)
|
||||
{
|
||||
Name = "AddComponent",
|
||||
Target = Expression.Lift(target)
|
||||
};
|
||||
arg_182_0.Target = memberReferenceExpression2;
|
||||
methodInvocationExpression2.Arguments = ExpressionCollection.FromArray(new Expression[]
|
||||
{
|
||||
Expression.Lift(value)
|
||||
});
|
||||
arg_1B1_0.Target = methodInvocationExpression2;
|
||||
tryCastExpression.Type = TypeReference.Lift(value);
|
||||
arg_1D2_0.Right = tryCastExpression;
|
||||
ReplaceCurrentNode(binaryExpression);
|
||||
isBinaryExp = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node.Operator != BinaryOperatorType.Assign) return;
|
||||
left = node.Left;
|
||||
if (!(node.Right is MethodInvocationExpression)) return;
|
||||
var methodInvocationExpression3 = (MethodInvocationExpression)node.Right;
|
||||
if (!(methodInvocationExpression3.Target is ReferenceExpression)) return;
|
||||
var referenceExpression = (ReferenceExpression)methodInvocationExpression3.Target;
|
||||
if (referenceExpression.Name != "AddComponent" ||
|
||||
1 != methodInvocationExpression3.Arguments.Count ||
|
||||
!(methodInvocationExpression3.Arguments[0] is StringLiteralExpression))
|
||||
return;
|
||||
var stringLiteralExpression2 = (StringLiteralExpression)methodInvocationExpression3.Arguments[0];
|
||||
value = stringLiteralExpression2.Value;
|
||||
var binaryExpression2 = new BinaryExpression(LexicalInfo.Empty)
|
||||
{
|
||||
Operator = BinaryOperatorType.Assign,
|
||||
Left = Expression.Lift(left)
|
||||
};
|
||||
var arg_3A3_0 = binaryExpression2;
|
||||
var tryCastExpression2 = new TryCastExpression(LexicalInfo.Empty);
|
||||
var arg_382_0 = tryCastExpression2;
|
||||
var methodInvocationExpression4 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_353_0 = methodInvocationExpression4;
|
||||
var referenceExpression2 = new ReferenceExpression(LexicalInfo.Empty) {Name = "AddComponent"};
|
||||
arg_353_0.Target = referenceExpression2;
|
||||
methodInvocationExpression4.Arguments = ExpressionCollection.FromArray(new Expression[]
|
||||
{
|
||||
Expression.Lift(value)
|
||||
});
|
||||
arg_382_0.Target = methodInvocationExpression4;
|
||||
tryCastExpression2.Type = TypeReference.Lift(value);
|
||||
arg_3A3_0.Right = tryCastExpression2;
|
||||
ReplaceCurrentNode(binaryExpression2);
|
||||
isBinaryExp = true;
|
||||
}
|
||||
|
||||
public override void LeaveMethodInvocationExpression(MethodInvocationExpression node)
|
||||
{
|
||||
if (node != null && node.Target is MemberReferenceExpression)
|
||||
{
|
||||
var memberReferenceExpression = (MemberReferenceExpression)node.Target;
|
||||
Expression target = memberReferenceExpression.Target;
|
||||
if (memberReferenceExpression.Name == "GetComponent" && 1 == node.Arguments.Count && node.Arguments[0] is StringLiteralExpression)
|
||||
{
|
||||
var stringLiteralExpression = (StringLiteralExpression)node.Arguments[0];
|
||||
string value = stringLiteralExpression.Value;
|
||||
var tryCastExpression = new TryCastExpression(LexicalInfo.Empty);
|
||||
var arg_13A_0 = tryCastExpression;
|
||||
var methodInvocationExpression = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_10B_0 = methodInvocationExpression;
|
||||
var memberReferenceExpression2 = new MemberReferenceExpression(LexicalInfo.Empty)
|
||||
{
|
||||
Name = "GetComponent",
|
||||
Target = Expression.Lift(target)
|
||||
};
|
||||
arg_10B_0.Target = memberReferenceExpression2;
|
||||
methodInvocationExpression.Arguments = ExpressionCollection.FromArray(new Expression[]
|
||||
{
|
||||
Expression.Lift(value)
|
||||
});
|
||||
arg_13A_0.Target = methodInvocationExpression;
|
||||
tryCastExpression.Type = TypeReference.Lift(value);
|
||||
ReplaceCurrentNode(tryCastExpression);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is ReferenceExpression)
|
||||
{
|
||||
var referenceExpression = (ReferenceExpression)node.Target;
|
||||
if (referenceExpression.Name == "GetComponent" && 1 == node.Arguments.Count && node.Arguments[0] is StringLiteralExpression)
|
||||
{
|
||||
var stringLiteralExpression2 = (StringLiteralExpression)node.Arguments[0];
|
||||
string value = stringLiteralExpression2.Value;
|
||||
var tryCastExpression2 = new TryCastExpression(LexicalInfo.Empty);
|
||||
TryCastExpression arg_280_0 = tryCastExpression2;
|
||||
var methodInvocationExpression2 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
MethodInvocationExpression arg_251_0 = methodInvocationExpression2;
|
||||
var referenceExpression2 = new ReferenceExpression(LexicalInfo.Empty) {Name = "GetComponent"};
|
||||
arg_251_0.Target = referenceExpression2;
|
||||
methodInvocationExpression2.Arguments = ExpressionCollection.FromArray(new Expression[]
|
||||
{
|
||||
Expression.Lift(value)
|
||||
});
|
||||
arg_280_0.Target = methodInvocationExpression2;
|
||||
tryCastExpression2.Type = TypeReference.Lift(value);
|
||||
ReplaceCurrentNode(tryCastExpression2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is MemberReferenceExpression)
|
||||
{
|
||||
var memberReferenceExpression3 = (MemberReferenceExpression)node.Target;
|
||||
Expression target = memberReferenceExpression3.Target;
|
||||
if (memberReferenceExpression3.Name == "GetComponent" && 1 == node.Arguments.Count && node.Arguments[0] is ReferenceExpression)
|
||||
{
|
||||
var e = (ReferenceExpression)node.Arguments[0];
|
||||
var methodInvocationExpression3 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
MethodInvocationExpression arg_3D8_0 = methodInvocationExpression3;
|
||||
var genericReferenceExpression = new GenericReferenceExpression(LexicalInfo.Empty);
|
||||
GenericReferenceExpression arg_3A9_0 = genericReferenceExpression;
|
||||
var memberReferenceExpression4 = new MemberReferenceExpression(LexicalInfo.Empty)
|
||||
{
|
||||
Name = "GetComponent",
|
||||
Target = Expression.Lift(target)
|
||||
};
|
||||
arg_3A9_0.Target = memberReferenceExpression4;
|
||||
genericReferenceExpression.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[]
|
||||
{
|
||||
TypeReference.Lift(e)
|
||||
});
|
||||
arg_3D8_0.Target = genericReferenceExpression;
|
||||
ReplaceCurrentNode(methodInvocationExpression3);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is ReferenceExpression)
|
||||
{
|
||||
var referenceExpression3 = (ReferenceExpression)node.Target;
|
||||
if (referenceExpression3.Name == "GetComponent" && 1 == node.Arguments.Count && node.Arguments[0] is ReferenceExpression)
|
||||
{
|
||||
var e = (ReferenceExpression)node.Arguments[0];
|
||||
var methodInvocationExpression4 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_4F9_0 = methodInvocationExpression4;
|
||||
var genericReferenceExpression2 = new GenericReferenceExpression(LexicalInfo.Empty);
|
||||
var arg_4CA_0 = genericReferenceExpression2;
|
||||
var referenceExpression4 = new ReferenceExpression(LexicalInfo.Empty);
|
||||
referenceExpression4.Name = "GetComponent";
|
||||
arg_4CA_0.Target = referenceExpression4;
|
||||
genericReferenceExpression2.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[]
|
||||
{
|
||||
TypeReference.Lift(e)
|
||||
});
|
||||
arg_4F9_0.Target = genericReferenceExpression2;
|
||||
ReplaceCurrentNode(methodInvocationExpression4);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is MemberReferenceExpression)
|
||||
{
|
||||
var memberReferenceExpression5 = (MemberReferenceExpression)node.Target;
|
||||
Expression target = memberReferenceExpression5.Target;
|
||||
if (memberReferenceExpression5.Name == "GetComponents" && 1 == node.Arguments.Count && node.Arguments[0] is ReferenceExpression)
|
||||
{
|
||||
var e = (ReferenceExpression)node.Arguments[0];
|
||||
var methodInvocationExpression5 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_63D_0 = methodInvocationExpression5;
|
||||
var genericReferenceExpression3 = new GenericReferenceExpression(LexicalInfo.Empty);
|
||||
var arg_60E_0 = genericReferenceExpression3;
|
||||
var memberReferenceExpression6 = new MemberReferenceExpression(LexicalInfo.Empty)
|
||||
{
|
||||
Name = "GetComponents",
|
||||
Target = Expression.Lift(target)
|
||||
};
|
||||
arg_60E_0.Target = memberReferenceExpression6;
|
||||
genericReferenceExpression3.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[]
|
||||
{
|
||||
TypeReference.Lift(e)
|
||||
});
|
||||
arg_63D_0.Target = genericReferenceExpression3;
|
||||
ReplaceCurrentNode(methodInvocationExpression5);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is ReferenceExpression)
|
||||
{
|
||||
var referenceExpression5 = (ReferenceExpression)node.Target;
|
||||
if (referenceExpression5.Name == "GetComponents" && 1 == node.Arguments.Count && node.Arguments[0] is ReferenceExpression)
|
||||
{
|
||||
var e = (ReferenceExpression)node.Arguments[0];
|
||||
var methodInvocationExpression6 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_75E_0 = methodInvocationExpression6;
|
||||
var genericReferenceExpression4 = new GenericReferenceExpression(LexicalInfo.Empty);
|
||||
var arg_72F_0 = genericReferenceExpression4;
|
||||
var referenceExpression6 = new ReferenceExpression(LexicalInfo.Empty) {Name = "GetComponents"};
|
||||
arg_72F_0.Target = referenceExpression6;
|
||||
genericReferenceExpression4.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[]
|
||||
{
|
||||
TypeReference.Lift(e)
|
||||
});
|
||||
arg_75E_0.Target = genericReferenceExpression4;
|
||||
ReplaceCurrentNode(methodInvocationExpression6);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is MemberReferenceExpression)
|
||||
{
|
||||
var memberReferenceExpression7 = (MemberReferenceExpression)node.Target;
|
||||
Expression target = memberReferenceExpression7.Target;
|
||||
if (memberReferenceExpression7.Name == "GetComponentsInChildren" && 1 == node.Arguments.Count && node.Arguments[0] is ReferenceExpression)
|
||||
{
|
||||
var e = (ReferenceExpression)node.Arguments[0];
|
||||
var methodInvocationExpression7 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_8A2_0 = methodInvocationExpression7;
|
||||
var genericReferenceExpression5 = new GenericReferenceExpression(LexicalInfo.Empty);
|
||||
var arg_873_0 = genericReferenceExpression5;
|
||||
var memberReferenceExpression8 = new MemberReferenceExpression(LexicalInfo.Empty)
|
||||
{
|
||||
Name = "GetComponentsInChildren",
|
||||
Target = Expression.Lift(target)
|
||||
};
|
||||
arg_873_0.Target = memberReferenceExpression8;
|
||||
genericReferenceExpression5.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[]
|
||||
{
|
||||
TypeReference.Lift(e)
|
||||
});
|
||||
arg_8A2_0.Target = genericReferenceExpression5;
|
||||
ReplaceCurrentNode(methodInvocationExpression7);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is ReferenceExpression)
|
||||
{
|
||||
var referenceExpression7 = (ReferenceExpression)node.Target;
|
||||
if (referenceExpression7.Name == "GetComponentsInChildren" && 1 == node.Arguments.Count && node.Arguments[0] is ReferenceExpression)
|
||||
{
|
||||
var e = (ReferenceExpression)node.Arguments[0];
|
||||
var methodInvocationExpression8 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
MethodInvocationExpression arg_9C3_0 = methodInvocationExpression8;
|
||||
var genericReferenceExpression6 = new GenericReferenceExpression(LexicalInfo.Empty);
|
||||
GenericReferenceExpression arg_994_0 = genericReferenceExpression6;
|
||||
var referenceExpression8 = new ReferenceExpression(LexicalInfo.Empty)
|
||||
{
|
||||
Name = "GetComponentsInChildren"
|
||||
};
|
||||
arg_994_0.Target = referenceExpression8;
|
||||
genericReferenceExpression6.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[]
|
||||
{
|
||||
TypeReference.Lift(e)
|
||||
});
|
||||
arg_9C3_0.Target = genericReferenceExpression6;
|
||||
ReplaceCurrentNode(methodInvocationExpression8);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is MemberReferenceExpression)
|
||||
{
|
||||
var memberReferenceExpression9 = (MemberReferenceExpression)node.Target;
|
||||
Expression target = memberReferenceExpression9.Target;
|
||||
if (memberReferenceExpression9.Name == "GetComponentInChildren" && 1 == node.Arguments.Count && node.Arguments[0] is ReferenceExpression)
|
||||
{
|
||||
var e = (ReferenceExpression)node.Arguments[0];
|
||||
var methodInvocationExpression9 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_B07_0 = methodInvocationExpression9;
|
||||
var genericReferenceExpression7 = new GenericReferenceExpression(LexicalInfo.Empty);
|
||||
var arg_AD8_0 = genericReferenceExpression7;
|
||||
var memberReferenceExpression10 = new MemberReferenceExpression(LexicalInfo.Empty);
|
||||
memberReferenceExpression10.Name = "GetComponentInChildren";
|
||||
memberReferenceExpression10.Target = Expression.Lift(target);
|
||||
arg_AD8_0.Target = memberReferenceExpression10;
|
||||
genericReferenceExpression7.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[]
|
||||
{
|
||||
TypeReference.Lift(e)
|
||||
});
|
||||
arg_B07_0.Target = genericReferenceExpression7;
|
||||
ReplaceCurrentNode(methodInvocationExpression9);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is ReferenceExpression)
|
||||
{
|
||||
var referenceExpression9 = (ReferenceExpression)node.Target;
|
||||
if (referenceExpression9.Name == "GetComponentInChildren" && 1 == node.Arguments.Count && node.Arguments[0] is ReferenceExpression)
|
||||
{
|
||||
var e = (ReferenceExpression)node.Arguments[0];
|
||||
var methodInvocationExpression10 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_C28_0 = methodInvocationExpression10;
|
||||
var genericReferenceExpression8 = new GenericReferenceExpression(LexicalInfo.Empty);
|
||||
var arg_BF9_0 = genericReferenceExpression8;
|
||||
var referenceExpression10 = new ReferenceExpression(LexicalInfo.Empty)
|
||||
{
|
||||
Name = "GetComponentInChildren"
|
||||
};
|
||||
arg_BF9_0.Target = referenceExpression10;
|
||||
genericReferenceExpression8.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[]
|
||||
{
|
||||
TypeReference.Lift(e)
|
||||
});
|
||||
arg_C28_0.Target = genericReferenceExpression8;
|
||||
ReplaceCurrentNode(methodInvocationExpression10);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is MemberReferenceExpression)
|
||||
{
|
||||
var memberReferenceExpression11 = (MemberReferenceExpression)node.Target;
|
||||
var target = memberReferenceExpression11.Target;
|
||||
if (memberReferenceExpression11.Name == "AddComponent" && 1 == node.Arguments.Count && node.Arguments[0] is StringLiteralExpression)
|
||||
{
|
||||
var stringLiteralExpression3 = (StringLiteralExpression)node.Arguments[0];
|
||||
string value = stringLiteralExpression3.Value;
|
||||
if (!isBinaryExp)
|
||||
{
|
||||
var methodInvocationExpression11 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_D49_0 = methodInvocationExpression11;
|
||||
var memberReferenceExpression12 = new MemberReferenceExpression(LexicalInfo.Empty)
|
||||
{
|
||||
Name = "AddComponent",
|
||||
Target = Expression.Lift(target)
|
||||
};
|
||||
arg_D49_0.Target = memberReferenceExpression12;
|
||||
methodInvocationExpression11.Arguments = ExpressionCollection.FromArray(new Expression[]
|
||||
{
|
||||
Expression.Lift(value)
|
||||
});
|
||||
ReplaceCurrentNode(methodInvocationExpression11);
|
||||
isBinaryExp = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is ReferenceExpression)
|
||||
{
|
||||
var referenceExpression11 = (ReferenceExpression)node.Target;
|
||||
if (referenceExpression11.Name == "AddComponent" && 1 == node.Arguments.Count && node.Arguments[0] is StringLiteralExpression)
|
||||
{
|
||||
var stringLiteralExpression4 = (StringLiteralExpression)node.Arguments[0];
|
||||
string value = stringLiteralExpression4.Value;
|
||||
if (!isBinaryExp)
|
||||
{
|
||||
var methodInvocationExpression12 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_E70_0 = methodInvocationExpression12;
|
||||
var referenceExpression12 = new ReferenceExpression(LexicalInfo.Empty) {Name = "AddComponent"};
|
||||
arg_E70_0.Target = referenceExpression12;
|
||||
methodInvocationExpression12.Arguments = ExpressionCollection.FromArray(new Expression[]
|
||||
{
|
||||
Expression.Lift(value)
|
||||
});
|
||||
ReplaceCurrentNode(methodInvocationExpression12);
|
||||
isBinaryExp = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is MemberReferenceExpression)
|
||||
{
|
||||
var memberReferenceExpression13 = (MemberReferenceExpression)node.Target;
|
||||
var target = memberReferenceExpression13.Target;
|
||||
if (memberReferenceExpression13.Name == "AddComponent" && 1 == node.Arguments.Count && node.Arguments[0] is ReferenceExpression)
|
||||
{
|
||||
var e = (ReferenceExpression)node.Arguments[0];
|
||||
var methodInvocationExpression13 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_FDD_0 = methodInvocationExpression13;
|
||||
var genericReferenceExpression9 = new GenericReferenceExpression(LexicalInfo.Empty);
|
||||
var arg_FAE_0 = genericReferenceExpression9;
|
||||
var memberReferenceExpression14 = new MemberReferenceExpression(LexicalInfo.Empty);
|
||||
memberReferenceExpression14.Name = "AddComponent";
|
||||
memberReferenceExpression14.Target = Expression.Lift(target);
|
||||
arg_FAE_0.Target = memberReferenceExpression14;
|
||||
genericReferenceExpression9.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[]
|
||||
{
|
||||
TypeReference.Lift(e)
|
||||
});
|
||||
arg_FDD_0.Target = genericReferenceExpression9;
|
||||
ReplaceCurrentNode(methodInvocationExpression13);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is ReferenceExpression)
|
||||
{
|
||||
var referenceExpression13 = (ReferenceExpression)node.Target;
|
||||
if (referenceExpression13.Name == "AddComponent" && 1 == node.Arguments.Count && node.Arguments[0] is ReferenceExpression)
|
||||
{
|
||||
var e = (ReferenceExpression)node.Arguments[0];
|
||||
var methodInvocationExpression14 = new MethodInvocationExpression(LexicalInfo.Empty);
|
||||
var arg_10FE_0 = methodInvocationExpression14;
|
||||
var genericReferenceExpression10 = new GenericReferenceExpression(LexicalInfo.Empty);
|
||||
var arg_10CF_0 = genericReferenceExpression10;
|
||||
var referenceExpression14 = new ReferenceExpression(LexicalInfo.Empty) {Name = "AddComponent"};
|
||||
arg_10CF_0.Target = referenceExpression14;
|
||||
genericReferenceExpression10.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[]
|
||||
{
|
||||
TypeReference.Lift(e)
|
||||
});
|
||||
arg_10FE_0.Target = genericReferenceExpression10;
|
||||
ReplaceCurrentNode(methodInvocationExpression14);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (node != null && node.Target is ReferenceExpression)
|
||||
{
|
||||
var referenceExpression15 = (ReferenceExpression)node.Target;
|
||||
if (referenceExpression15.Name == "Instantiate" && 3 == node.Arguments.Count)
|
||||
{
|
||||
var expression34 = node.Arguments[0];
|
||||
var expressionType = expression34.ExpressionType;
|
||||
if (expressionType != null)
|
||||
{
|
||||
var tryCastExpression3 = new TryCastExpression(LexicalInfo.Empty)
|
||||
{
|
||||
Target = Expression.Lift(node),
|
||||
Type = TypeReference.Lift(CodeBuilder.CreateTypeReference(expressionType))
|
||||
};
|
||||
ReplaceCurrentNode(tryCastExpression3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -84,10 +84,19 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BlockIdentation.cs" />
|
||||
<Compile Include="CommandLineArguments.cs" />
|
||||
<Compile Include="EntityExtensions.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SourceFile.cs" />
|
||||
<Compile Include="Steps\SelectiveUnaryExpressionExpansionProcessUnityScriptMethods.cs" />
|
||||
<Compile Include="Steps\RenameArrayDeclaration.cs" />
|
||||
<Compile Include="Steps\TransformKnownCalls.cs" />
|
||||
<Compile Include="UnityScript2CSharpConverter.cs" />
|
||||
<Compile Include="UnityScript2CSharpConverterVisitor.cs" />
|
||||
<Compile Include="UsingCollector.cs" />
|
||||
<Compile Include="Writer.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
|
|
|
@ -0,0 +1,169 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Boo.Lang.Compiler;
|
||||
using Boo.Lang.Compiler.IO;
|
||||
using Boo.Lang.Compiler.Steps;
|
||||
using Boo.Lang.Compiler.TypeSystem.Services;
|
||||
using Mono.Cecil;
|
||||
using UnityScript;
|
||||
using UnityScript.Steps;
|
||||
using UnityScript2CSharp.Steps;
|
||||
|
||||
namespace UnityScript2CSharp
|
||||
{
|
||||
class UnityScript2CSharpConverter
|
||||
{
|
||||
private readonly bool _ignoreErrors;
|
||||
|
||||
public UnityScript2CSharpConverter(bool ignoreErrors = false)
|
||||
{
|
||||
_ignoreErrors = ignoreErrors;
|
||||
}
|
||||
|
||||
public void Convert(IEnumerable<SourceFile> inputs, IEnumerable<string> definedSymbols, IEnumerable<string> referencedAssemblies, Action<string, string> onScriptConverted)
|
||||
{
|
||||
var comp = CreatAndInitializeCompiler(inputs, definedSymbols, referencedAssemblies);
|
||||
var result = comp.Run();
|
||||
|
||||
HandleCompilationResult(result);
|
||||
|
||||
var visitor = new UnityScript2CSharpConverterVisitor();
|
||||
visitor.ScriptConverted += onScriptConverted;
|
||||
result.CompileUnit.Accept(visitor);
|
||||
}
|
||||
|
||||
public IEnumerable<string> CompilerErrors { get; private set; }
|
||||
|
||||
private void HandleCompilationResult(CompilerContext result)
|
||||
{
|
||||
if (result.Errors.Count > 0)
|
||||
{
|
||||
if (!_ignoreErrors)
|
||||
throw new Exception(result.Errors.Aggregate("\t", (acc, curr) => acc + Environment.NewLine + "\t" + curr.ToString()));
|
||||
|
||||
CompilerErrors = result.Errors.Select(error => error.ToString());
|
||||
}
|
||||
|
||||
if (result.Warnings.Count > 0)
|
||||
{
|
||||
// throw new Exception(result.Warnings.Aggregate("", (acc, curr) => acc + Environment.NewLine + curr.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
internal UnityScriptCompiler CreatAndInitializeCompiler(IEnumerable<SourceFile> inputs, IEnumerable<string> definedSymbols, IEnumerable<string> referencedAssemblies)
|
||||
{
|
||||
_compiler = new UnityScriptCompiler();
|
||||
SetupCompilerParameters(definedSymbols, referencedAssemblies, null);
|
||||
SetupCompilerPipeline();
|
||||
foreach (var input in inputs)
|
||||
{
|
||||
_compiler.Parameters.Input.Add(new StringInput(input.FileName, input.Contents));
|
||||
}
|
||||
|
||||
return _compiler;
|
||||
}
|
||||
|
||||
protected virtual void SetupCompilerParameters(IEnumerable<string> definedSymbols, IEnumerable<string> assemblyReferences, IList<Assembly> actualAssemblyReferences)
|
||||
{
|
||||
_compiler.Parameters.GenerateInMemory = true;
|
||||
|
||||
foreach (var define in definedSymbols)
|
||||
_compiler.Parameters.Defines.Add(define, "1");
|
||||
|
||||
foreach (var assembly in LoadAssembliesToReference(assemblyReferences))
|
||||
{
|
||||
_compiler.Parameters.References.Add(assembly);
|
||||
//actualAssemblyReferences.Add(assembly);
|
||||
}
|
||||
|
||||
var compilerParameters = (UnityScriptCompilerParameters)_compiler.Parameters;
|
||||
|
||||
compilerParameters.AddToEnvironment(
|
||||
typeof(TypeInferenceRuleProvider),
|
||||
() => new CustomTypeInferenceRuleProvider("UnityEngineInternal.TypeInferenceRuleAttribute"));
|
||||
|
||||
compilerParameters.ScriptMainMethod = "Main";
|
||||
compilerParameters.Imports = new Boo.Lang.List<String> { "UnityEngine", "UnityEditor", "System.Collections" };
|
||||
|
||||
compilerParameters.ScriptBaseType = FindMonoBehaviour(assemblyReferences);
|
||||
}
|
||||
|
||||
private Type FindMonoBehaviour(IEnumerable<string> references)
|
||||
{
|
||||
var myassemblies = LoadAssembliesToReference(references);
|
||||
foreach (var assembly in myassemblies)
|
||||
{
|
||||
var monobehaviour = assembly.GetType("UnityEngine.MonoBehaviour");
|
||||
if (monobehaviour != null)
|
||||
return monobehaviour;
|
||||
}
|
||||
throw new Exception("MonoBehaviour not found");
|
||||
}
|
||||
|
||||
protected virtual void SetupCompilerPipeline()
|
||||
{
|
||||
var pipeline = new Boo.Lang.Compiler.Pipelines.Compile { BreakOnErrors = false };
|
||||
|
||||
pipeline.Remove(typeof(ConstantFolding));
|
||||
pipeline.Remove(typeof(ExpandPropertiesAndEvents));
|
||||
pipeline.Remove(typeof(CheckNeverUsedMembers));
|
||||
pipeline.Remove(typeof(ExpandVarArgsMethodInvocations));
|
||||
pipeline.Remove(typeof(InjectCallableConversions));
|
||||
pipeline.Remove(typeof(StricterErrorChecking));
|
||||
pipeline.Remove(typeof(RemoveDeadCode));
|
||||
pipeline.Remove(typeof(OptimizeIterationStatements));
|
||||
|
||||
pipeline.Remove(typeof(ProcessGenerators));
|
||||
pipeline.Remove(typeof(NormalizeIterationStatements));
|
||||
pipeline.Remove(typeof(ProcessMethodBodies));
|
||||
|
||||
var adjustedPipeline = UnityScriptCompiler.Pipelines.AdjustBooPipeline(pipeline);
|
||||
pipeline.Replace(typeof(ProcessUnityScriptMethods), new SelectiveUnaryExpressionExpansionProcessUnityScriptMethods());
|
||||
adjustedPipeline.Add(new RenameArrayDeclaration());
|
||||
//adjustedPipeline.Add(new TransformKnownCalls());
|
||||
_compiler.Parameters.Pipeline = adjustedPipeline;
|
||||
}
|
||||
|
||||
protected Assembly[] LoadAssembliesToReference(IEnumerable<string> references)
|
||||
{
|
||||
return CollectAssemblyReferencesAndDependencies<string>(references).Select(Assembly.LoadFrom).ToArray();
|
||||
}
|
||||
|
||||
private static IEnumerable<T> CollectAssemblyReferencesAndDependencies<T>(IEnumerable<string> assemblyPaths)
|
||||
{
|
||||
Func<string, AssemblyDefinition, object> resultFactory = (path, assembly) => path;
|
||||
|
||||
if (typeof(T) == typeof(AssemblyDefinition))
|
||||
resultFactory = (path, assembly) => assembly ?? AssemblyDefinition.ReadAssembly(path);
|
||||
|
||||
var seen = new Dictionary<string, bool>();
|
||||
|
||||
foreach (var assemblyPath in assemblyPaths)
|
||||
{
|
||||
var assemblyFile = Path.GetFileNameWithoutExtension(assemblyPath);
|
||||
if (seen.ContainsKey(assemblyFile))
|
||||
continue;
|
||||
|
||||
seen[assemblyFile] = true;
|
||||
var assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath);
|
||||
yield return (T)resultFactory(assemblyPath, assemblyDefinition);
|
||||
|
||||
var assemblyFolder = Path.GetDirectoryName(assemblyPath);
|
||||
foreach (var dep in assemblyDefinition.Modules.SelectMany(m => m.AssemblyReferences))
|
||||
{
|
||||
var dependencyPath = Path.Combine(assemblyFolder, dep.Name) + ".dll";
|
||||
if (seen.ContainsKey(dep.Name) || !File.Exists(dependencyPath))
|
||||
continue;
|
||||
|
||||
seen[dep.Name] = true;
|
||||
yield return (T)resultFactory(dependencyPath, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected UnityScriptCompiler _compiler;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,788 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Boo.Lang.Compiler.Ast;
|
||||
using Boo.Lang.Compiler.Ast.Visitors;
|
||||
using Boo.Lang.Compiler.TypeSystem;
|
||||
using Boo.Lang.Compiler.TypeSystem.Internal;
|
||||
using Boo.Lang.Compiler.TypeSystem.Reflection;
|
||||
using Attribute = Boo.Lang.Compiler.Ast.Attribute;
|
||||
using Module = Boo.Lang.Compiler.Ast.Module;
|
||||
|
||||
namespace UnityScript2CSharp
|
||||
{
|
||||
internal class UnityScript2CSharpConverterVisitor : DepthFirstVisitor
|
||||
{
|
||||
private IList<string> _usings;
|
||||
|
||||
private Writer _writer;
|
||||
|
||||
public event Action<string, string> ScriptConverted;
|
||||
|
||||
public override void OnTypeMemberStatement(TypeMemberStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnTypeMemberStatement(node);
|
||||
}
|
||||
|
||||
public override void OnExplicitMemberInfo(ExplicitMemberInfo node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnExplicitMemberInfo(node);
|
||||
}
|
||||
|
||||
public override void OnSimpleTypeReference(SimpleTypeReference node)
|
||||
{
|
||||
string typeName = null;
|
||||
var externalType = node.Entity as ExternalType;
|
||||
if (externalType != null)
|
||||
{
|
||||
switch (externalType.ActualType.FullName)
|
||||
{
|
||||
case "System.String":
|
||||
typeName = "string";
|
||||
break;
|
||||
|
||||
case "System.Boolean":
|
||||
typeName = "bool";
|
||||
break;
|
||||
|
||||
case "System.Object":
|
||||
typeName = "object";
|
||||
break;
|
||||
|
||||
case "System.Int32":
|
||||
typeName = "int";
|
||||
break;
|
||||
|
||||
case "System.Int64":
|
||||
typeName = "long";
|
||||
break;
|
||||
}
|
||||
|
||||
if (typeName == null && _usings.Contains(externalType.ActualType.Namespace))
|
||||
{
|
||||
typeName = externalType.Name;
|
||||
}
|
||||
}
|
||||
|
||||
_builderAppend(typeName ?? node.Name);
|
||||
}
|
||||
|
||||
private void _builderAppendIdented(string str)
|
||||
{
|
||||
_writer.IndentNextWrite = true;
|
||||
_writer.Write(str);
|
||||
}
|
||||
|
||||
private void _builderAppend(string str)
|
||||
{
|
||||
_writer.Write(str);
|
||||
}
|
||||
|
||||
private void _builderAppend(char str)
|
||||
{
|
||||
_writer.Write(str);
|
||||
}
|
||||
|
||||
private void _builderAppend(long str)
|
||||
{
|
||||
_writer.Write(str);
|
||||
}
|
||||
|
||||
public override void OnImport(Import node)
|
||||
{
|
||||
// Left as a no op because we handle "imports" in a separate visitor
|
||||
}
|
||||
|
||||
public override void OnArrayTypeReference(ArrayTypeReference node)
|
||||
{
|
||||
node.ElementType.Accept(this);
|
||||
_writer.Write("[]");
|
||||
}
|
||||
|
||||
public override void OnCallableTypeReference(CallableTypeReference node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnCallableTypeReference(node);
|
||||
}
|
||||
|
||||
public override void OnGenericTypeReference(GenericTypeReference node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnGenericTypeReference(node);
|
||||
}
|
||||
|
||||
public override void OnGenericTypeDefinitionReference(GenericTypeDefinitionReference node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnGenericTypeDefinitionReference(node);
|
||||
}
|
||||
|
||||
public override void OnCallableDefinition(CallableDefinition node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnCallableDefinition(node);
|
||||
}
|
||||
|
||||
public override void OnNamespaceDeclaration(NamespaceDeclaration node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnNamespaceDeclaration(node);
|
||||
}
|
||||
|
||||
public override void OnModule(Module node)
|
||||
{
|
||||
_usings = GetImportedNamespaces(node);
|
||||
_writer = new Writer(FormatUsingsFrom(_usings));
|
||||
|
||||
base.OnModule(node);
|
||||
|
||||
var handler = ScriptConverted;
|
||||
if (handler != null)
|
||||
handler(node.LexicalInfo.FullPath, _writer.Text);
|
||||
}
|
||||
|
||||
public override void OnClassDefinition(ClassDefinition node)
|
||||
{
|
||||
_builderAppendIdented($"{ModifiersToString(node.Modifiers)} class {node.Name} : ");
|
||||
for (var i = 0; i < node.BaseTypes.Count; i++)
|
||||
{
|
||||
node.BaseTypes[i].Accept(this);
|
||||
if ((i + 1) < node.BaseTypes.Count)
|
||||
_builderAppend(", ");
|
||||
}
|
||||
_writer.WriteLine();
|
||||
_writer.WriteLine("{");
|
||||
using (new BlockIdentation(_writer))
|
||||
{
|
||||
foreach (var member in node.Members)
|
||||
{
|
||||
member.Accept(this);
|
||||
}
|
||||
_writer.WriteLine();
|
||||
}
|
||||
_builderAppend("}");
|
||||
}
|
||||
|
||||
public override void OnStructDefinition(StructDefinition node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnStructDefinition(node);
|
||||
}
|
||||
|
||||
public override void OnInterfaceDefinition(InterfaceDefinition node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnInterfaceDefinition(node);
|
||||
}
|
||||
|
||||
public override void OnEnumDefinition(EnumDefinition node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnEnumDefinition(node);
|
||||
}
|
||||
|
||||
public override void OnEnumMember(EnumMember node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnEnumMember(node);
|
||||
}
|
||||
|
||||
public override void OnField(Field node)
|
||||
{
|
||||
_builderAppend(ModifiersToString(node.Modifiers));
|
||||
_builderAppend(' ');
|
||||
node.Type.Accept(this);
|
||||
_builderAppend(' ');
|
||||
_builderAppend(node.Name);
|
||||
|
||||
if (node.Initializer != null)
|
||||
{
|
||||
_builderAppend(" = ");
|
||||
}
|
||||
|
||||
_writer.WriteLine(";");
|
||||
}
|
||||
|
||||
public override void OnProperty(Property node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnProperty(node);
|
||||
}
|
||||
|
||||
public override void OnEvent(Event node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnEvent(node);
|
||||
}
|
||||
|
||||
public override void OnLocal(Local node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnLocal(node);
|
||||
}
|
||||
|
||||
public override void OnBlockExpression(BlockExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnBlockExpression(node);
|
||||
}
|
||||
|
||||
public override void OnMethod(Method node)
|
||||
{
|
||||
if (node.Name == "Main")
|
||||
return;
|
||||
|
||||
_builderAppendIdented(ModifiersToString(node.Modifiers));
|
||||
_builderAppend(' ');
|
||||
AppendReturnType(node);
|
||||
_builderAppend(' ');
|
||||
_builderAppend(node.Name);
|
||||
_builderAppend('(');
|
||||
|
||||
var last = node.Parameters.LastOrDefault();
|
||||
foreach (var parameter in node.Parameters)
|
||||
{
|
||||
parameter.Accept(this);
|
||||
if (parameter != last)
|
||||
_builderAppend(", ");
|
||||
}
|
||||
_builderAppend(')');
|
||||
node.Body.Accept(this);
|
||||
}
|
||||
|
||||
public override bool EnterBlock(Block node)
|
||||
{
|
||||
var ret = base.EnterBlock(node);
|
||||
|
||||
var parentMedhod = node.ParentNode as Method;
|
||||
if (parentMedhod == null)
|
||||
return ret;
|
||||
|
||||
foreach (var local in parentMedhod.Locals)
|
||||
{
|
||||
var internalLocal = local.Entity as InternalLocal;
|
||||
if (!IsSynthetic(internalLocal))
|
||||
internalLocal.OriginalDeclaration.ParentNode.Accept(this);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static bool IsSynthetic(InternalLocal internalLocal)
|
||||
{
|
||||
return internalLocal == null || internalLocal.OriginalDeclaration == null;
|
||||
}
|
||||
|
||||
public override void OnConstructor(Constructor node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
//base.OnConstructor(node);
|
||||
}
|
||||
|
||||
public override void OnDestructor(Destructor node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnDestructor(node);
|
||||
}
|
||||
|
||||
public override void OnParameterDeclaration(ParameterDeclaration node)
|
||||
{
|
||||
node.Type.Accept(this);
|
||||
_builderAppend(' ');
|
||||
_builderAppend(node.Name);
|
||||
}
|
||||
|
||||
public override void OnGenericParameterDeclaration(GenericParameterDeclaration node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnGenericParameterDeclaration(node);
|
||||
}
|
||||
|
||||
public override void OnDeclarationStatement(DeclarationStatement node)
|
||||
{
|
||||
node.Declaration.Accept(this);
|
||||
if (node.Initializer != null)
|
||||
{
|
||||
_builderAppend(" = ");
|
||||
node.Initializer.Accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDeclaration(Declaration node)
|
||||
{
|
||||
if (node.Type != null)
|
||||
node.Type.Accept(this);
|
||||
else
|
||||
_builderAppend($"var ");
|
||||
|
||||
_writer.Write($" {node.Name}");
|
||||
//var typeName = node.Type != null ? node.Type.Entity.TypeName(_usings) : "var";
|
||||
//if (node.ParentNode.NodeType == NodeType.ForStatement)
|
||||
// _builderAppend($"{typeName}");
|
||||
//else
|
||||
// _builderAppendIdented($"{typeName}");
|
||||
|
||||
//_writer.Write($" {node.Name}");
|
||||
}
|
||||
|
||||
public override void OnAttribute(Attribute node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnAttribute(node);
|
||||
}
|
||||
|
||||
public override void OnStatementModifier(StatementModifier node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnStatementModifier(node);
|
||||
}
|
||||
|
||||
public override void OnGotoStatement(GotoStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnGotoStatement(node);
|
||||
}
|
||||
|
||||
public override void OnLabelStatement(LabelStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnLabelStatement(node);
|
||||
}
|
||||
|
||||
public override void OnBlock(Block node)
|
||||
{
|
||||
if (node.ParentNode.NodeType == NodeType.Module)
|
||||
return;
|
||||
|
||||
_writer.WriteLine();
|
||||
_writer.WriteLine("{");
|
||||
|
||||
using (new BlockIdentation(_writer))
|
||||
base.OnBlock(node);
|
||||
|
||||
_writer.WriteLine();
|
||||
_writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public override void OnMacroStatement(MacroStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnMacroStatement(node);
|
||||
}
|
||||
|
||||
public override void OnTryStatement(TryStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnTryStatement(node);
|
||||
}
|
||||
|
||||
public override void OnExceptionHandler(ExceptionHandler node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnExceptionHandler(node);
|
||||
}
|
||||
|
||||
public override void OnIfStatement(IfStatement node)
|
||||
{
|
||||
_builderAppendIdented("if (");
|
||||
ProcessBooleanExpression(node.Condition);
|
||||
_builderAppend(")");
|
||||
|
||||
node.TrueBlock.Accept(this);
|
||||
if (node.FalseBlock != null)
|
||||
{
|
||||
_builderAppendIdented("else");
|
||||
node.FalseBlock.Accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessBooleanExpression(Expression condition)
|
||||
{
|
||||
condition.Accept(this);
|
||||
//if (!condition.Entity.IsBoolean())
|
||||
//TODO: Crash when condition = "go.gameObject.GetComponent.<ParticleEmitter>()"
|
||||
if (condition.Entity != null && !condition.Entity.IsBoolean())
|
||||
{
|
||||
_builderAppend($" != {condition.Entity.DefaultValue()}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnUnlessStatement(UnlessStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnUnlessStatement(node);
|
||||
}
|
||||
|
||||
public override void OnForStatement(ForStatement node)
|
||||
{
|
||||
_writer.Write("foreach (");
|
||||
node.Declarations[0].Accept(this);
|
||||
_writer.Write(" in ");
|
||||
node.Iterator.Accept(this);
|
||||
_writer.WriteLine(")");
|
||||
node.Block.Accept(this);
|
||||
}
|
||||
|
||||
public override void OnWhileStatement(WhileStatement node)
|
||||
{
|
||||
_builderAppendIdented("while (");
|
||||
node.Condition.Accept(this);
|
||||
_builderAppend(")");
|
||||
node.Block.Accept(this);
|
||||
}
|
||||
|
||||
public override void OnBreakStatement(BreakStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnBreakStatement(node);
|
||||
}
|
||||
|
||||
public override void OnContinueStatement(ContinueStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnContinueStatement(node);
|
||||
}
|
||||
|
||||
public override void OnReturnStatement(ReturnStatement node)
|
||||
{
|
||||
_builderAppendIdented("return ");
|
||||
base.OnReturnStatement(node);
|
||||
_builderAppend(";");
|
||||
}
|
||||
|
||||
public override void OnYieldStatement(YieldStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnYieldStatement(node);
|
||||
}
|
||||
|
||||
public override void OnRaiseStatement(RaiseStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnRaiseStatement(node);
|
||||
}
|
||||
|
||||
public override void OnUnpackStatement(UnpackStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnUnpackStatement(node);
|
||||
}
|
||||
|
||||
public override void OnExpressionStatement(ExpressionStatement node)
|
||||
{
|
||||
node.Expression.Accept(this);
|
||||
_writer.WriteLine(";");
|
||||
}
|
||||
|
||||
public override void OnOmittedExpression(OmittedExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnOmittedExpression(node);
|
||||
}
|
||||
|
||||
public override void OnExpressionPair(ExpressionPair node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnExpressionPair(node);
|
||||
}
|
||||
|
||||
public override void OnMethodInvocationExpression(MethodInvocationExpression node)
|
||||
{
|
||||
//if (node.Target.Entity.EntityType == EntityType.BuiltinFunction)
|
||||
// return;
|
||||
|
||||
if (node.Target.Entity != null && node.Target.Entity.EntityType == EntityType.BuiltinFunction)
|
||||
return;
|
||||
|
||||
node.Target.Accept(this);
|
||||
_writer.Write(_currentBrackets[0]);
|
||||
foreach (var argument in node.Arguments)
|
||||
{
|
||||
argument.Accept(this);
|
||||
}
|
||||
_writer.Write(_currentBrackets[1]);
|
||||
_currentBrackets = RoundBrackets;
|
||||
}
|
||||
|
||||
public override void OnUnaryExpression(UnaryExpression node)
|
||||
{
|
||||
node.Operand.Accept(this);
|
||||
_builderAppend(BooPrinterVisitor.GetUnaryOperatorText(node.Operator));
|
||||
}
|
||||
|
||||
public override void OnBinaryExpression(BinaryExpression node)
|
||||
{
|
||||
if (node.IsSynthetic)
|
||||
return;
|
||||
|
||||
node.Left.Accept(this);
|
||||
_builderAppend($" {CSharpOperatorFor(node.Operator)} ");
|
||||
node.Right.Accept(this);
|
||||
}
|
||||
|
||||
public override void OnConditionalExpression(ConditionalExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnConditionalExpression(node);
|
||||
}
|
||||
|
||||
public override void OnReferenceExpression(ReferenceExpression node)
|
||||
{
|
||||
_builderAppend(node.Name);
|
||||
}
|
||||
|
||||
public override void OnMemberReferenceExpression(MemberReferenceExpression node)
|
||||
{
|
||||
node.Target.Accept(this);
|
||||
_builderAppend($".{node.Name}");
|
||||
}
|
||||
|
||||
public override void OnGenericReferenceExpression(GenericReferenceExpression node)
|
||||
{
|
||||
if (IsArrayInstantiation(node))
|
||||
{
|
||||
_writer.Write("new ");
|
||||
node.GenericArguments[0].Accept(this);
|
||||
_currentBrackets = SquareBrackets;
|
||||
return;
|
||||
}
|
||||
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnGenericReferenceExpression(node);
|
||||
}
|
||||
|
||||
public override void OnQuasiquoteExpression(QuasiquoteExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnQuasiquoteExpression(node);
|
||||
}
|
||||
|
||||
public override void OnStringLiteralExpression(StringLiteralExpression node)
|
||||
{
|
||||
_builderAppend(string.Format("\"{0}\"", node.Value));
|
||||
}
|
||||
|
||||
public override void OnCharLiteralExpression(CharLiteralExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnCharLiteralExpression(node);
|
||||
}
|
||||
|
||||
public override void OnTimeSpanLiteralExpression(TimeSpanLiteralExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnTimeSpanLiteralExpression(node);
|
||||
}
|
||||
|
||||
public override void OnIntegerLiteralExpression(IntegerLiteralExpression node)
|
||||
{
|
||||
_builderAppend(node.Value);
|
||||
base.OnIntegerLiteralExpression(node);
|
||||
}
|
||||
|
||||
public override void OnDoubleLiteralExpression(DoubleLiteralExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnDoubleLiteralExpression(node);
|
||||
}
|
||||
|
||||
public override void OnNullLiteralExpression(NullLiteralExpression node)
|
||||
{
|
||||
_builderAppend("null");
|
||||
}
|
||||
|
||||
public override void OnSelfLiteralExpression(SelfLiteralExpression node)
|
||||
{
|
||||
_writer.Write("this");
|
||||
}
|
||||
|
||||
public override void OnSuperLiteralExpression(SuperLiteralExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnSuperLiteralExpression(node);
|
||||
}
|
||||
|
||||
public override void OnBoolLiteralExpression(BoolLiteralExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnBoolLiteralExpression(node);
|
||||
}
|
||||
|
||||
public override void OnRELiteralExpression(RELiteralExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnRELiteralExpression(node);
|
||||
}
|
||||
|
||||
public override void OnSpliceExpression(SpliceExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnSpliceExpression(node);
|
||||
}
|
||||
|
||||
public override void OnSpliceTypeReference(SpliceTypeReference node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnSpliceTypeReference(node);
|
||||
}
|
||||
|
||||
public override void OnSpliceMemberReferenceExpression(SpliceMemberReferenceExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnSpliceMemberReferenceExpression(node);
|
||||
}
|
||||
|
||||
public override void OnSpliceTypeMember(SpliceTypeMember node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnSpliceTypeMember(node);
|
||||
}
|
||||
|
||||
public override void OnSpliceTypeDefinitionBody(SpliceTypeDefinitionBody node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnSpliceTypeDefinitionBody(node);
|
||||
}
|
||||
|
||||
public override void OnSpliceParameterDeclaration(SpliceParameterDeclaration node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnSpliceParameterDeclaration(node);
|
||||
}
|
||||
|
||||
public override void OnExpressionInterpolationExpression(ExpressionInterpolationExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnExpressionInterpolationExpression(node);
|
||||
}
|
||||
|
||||
public override void OnHashLiteralExpression(HashLiteralExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnHashLiteralExpression(node);
|
||||
}
|
||||
|
||||
public override void OnListLiteralExpression(ListLiteralExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnListLiteralExpression(node);
|
||||
}
|
||||
|
||||
public override void OnCollectionInitializationExpression(CollectionInitializationExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnCollectionInitializationExpression(node);
|
||||
}
|
||||
|
||||
public override void OnArrayLiteralExpression(ArrayLiteralExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnArrayLiteralExpression(node);
|
||||
}
|
||||
|
||||
public override void OnGeneratorExpression(GeneratorExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnGeneratorExpression(node);
|
||||
}
|
||||
|
||||
public override void OnExtendedGeneratorExpression(ExtendedGeneratorExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnExtendedGeneratorExpression(node);
|
||||
}
|
||||
|
||||
public override void OnSlice(Slice node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnSlice(node);
|
||||
}
|
||||
|
||||
public override void OnSlicingExpression(SlicingExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnSlicingExpression(node);
|
||||
}
|
||||
|
||||
public override void OnTryCastExpression(TryCastExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnTryCastExpression(node);
|
||||
}
|
||||
|
||||
public override void OnCastExpression(CastExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnCastExpression(node);
|
||||
}
|
||||
|
||||
public override void OnTypeofExpression(TypeofExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnTypeofExpression(node);
|
||||
}
|
||||
|
||||
public override void OnCustomStatement(CustomStatement node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnCustomStatement(node);
|
||||
}
|
||||
|
||||
public override void OnCustomExpression(CustomExpression node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnCustomExpression(node);
|
||||
}
|
||||
|
||||
public override void OnStatementTypeMember(StatementTypeMember node)
|
||||
{
|
||||
System.Console.WriteLine("Node type not supported yet : {0}\n\t{1}\n\t{2}", node.GetType().Name, node.ToString(), node.ParentNode.ToString());
|
||||
base.OnStatementTypeMember(node);
|
||||
}
|
||||
|
||||
public string CSharpOperatorFor(BinaryOperatorType op)
|
||||
{
|
||||
return (op != BinaryOperatorType.And) ? ((op != BinaryOperatorType.Or) ? BooPrinterVisitor.GetBinaryOperatorText(op) : "||") : "&&";
|
||||
}
|
||||
|
||||
private static string ModifiersToString(TypeMemberModifiers modifiers)
|
||||
{
|
||||
return modifiers.ToString().ToLower().Replace(",", "");
|
||||
}
|
||||
|
||||
private string FormatUsingsFrom(IEnumerable<string> usings)
|
||||
{
|
||||
var generatedUsings = usings.Aggregate("", (acc, curr) => acc + string.Format("using {0};{1}", curr, Writer.NewLine));
|
||||
return generatedUsings + Writer.NewLine;
|
||||
}
|
||||
|
||||
private IList<string> GetImportedNamespaces(Module node)
|
||||
{
|
||||
var usingCollector = new UsingCollector();
|
||||
node.Accept(usingCollector);
|
||||
return usingCollector.Usings;
|
||||
}
|
||||
|
||||
private void AppendReturnType(Method node)
|
||||
{
|
||||
if (node.ReturnType != null)
|
||||
node.ReturnType.Accept(this);
|
||||
else
|
||||
_builderAppend("void");
|
||||
}
|
||||
|
||||
private static bool IsArrayInstantiation(GenericReferenceExpression node)
|
||||
{
|
||||
// Arrays in UnityScript are represented as a GenericReferenceExpession
|
||||
var target = node.Target as ReferenceExpression;
|
||||
return target != null && target.Name == "array";
|
||||
}
|
||||
|
||||
private char[] _currentBrackets = RoundBrackets;
|
||||
|
||||
private static char[] RoundBrackets = {'(', ')'};
|
||||
private static char[] SquareBrackets = {'[', ']'};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System.Collections.Generic;
|
||||
using Boo.Lang.Compiler.Ast;
|
||||
|
||||
namespace UnityScript2CSharp
|
||||
{
|
||||
internal class UsingCollector : DepthFirstVisitor
|
||||
{
|
||||
public UsingCollector()
|
||||
{
|
||||
Usings = new List<string>();
|
||||
}
|
||||
|
||||
public override void OnImport(Import node)
|
||||
{
|
||||
Usings.Add(node.Namespace);
|
||||
}
|
||||
|
||||
public IList<string> Usings { get; private set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityScript2CSharp
|
||||
{
|
||||
internal class Writer
|
||||
{
|
||||
private StringBuilder _builder;
|
||||
private int _indentation;
|
||||
private static readonly string _newLine = Environment.NewLine;
|
||||
|
||||
public Writer(string contents)
|
||||
{
|
||||
_builder = new StringBuilder(contents);
|
||||
}
|
||||
|
||||
public bool IndentNextWrite { get; set; }
|
||||
|
||||
public string Text { get { return _builder.ToString(); } }
|
||||
|
||||
public int Identation
|
||||
{
|
||||
get { return _indentation; }
|
||||
set
|
||||
{
|
||||
_indentation = value;
|
||||
CurrentIdentation = new String(' ', _indentation * 4);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(string str)
|
||||
{
|
||||
IndentIfRequired();
|
||||
_builder.Append(str);
|
||||
}
|
||||
|
||||
public void Write(char ch)
|
||||
{
|
||||
IndentIfRequired();
|
||||
_builder.Append(ch);
|
||||
}
|
||||
|
||||
internal void Write(long l)
|
||||
{
|
||||
IndentIfRequired();
|
||||
_builder.Append(l);
|
||||
}
|
||||
|
||||
public void WriteLine()
|
||||
{
|
||||
_builder.Append(_newLine);
|
||||
IndentNextWrite = true;
|
||||
}
|
||||
|
||||
public void WriteLine(string str)
|
||||
{
|
||||
Write(str);
|
||||
WriteLine();
|
||||
}
|
||||
|
||||
public static string NewLine { get { return _newLine; } }
|
||||
|
||||
private void IndentIfRequired()
|
||||
{
|
||||
if (IndentNextWrite)
|
||||
{
|
||||
_builder.Append(CurrentIdentation);
|
||||
IndentNextWrite = false;
|
||||
}
|
||||
}
|
||||
|
||||
private string CurrentIdentation { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Mono.Cecil" version="0.9.6.4" targetFramework="net462" />
|
||||
<package id="CommandLineParser20" version="2.0.0.0" targetFramework="net462" />
|
||||
<package id="NLog" version="4.4.10" targetFramework="net462" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче