Skip to content

Commit

Permalink
Fixes for many translation issues. Adding system exception types. Ren…
Browse files Browse the repository at this point in the history
…aming TranlsationTest to GeneralTests
  • Loading branch information
Frank Laub committed Feb 27, 2010
1 parent 0d1006b commit 65a528e
Show file tree
Hide file tree
Showing 62 changed files with 1,780 additions and 1,102 deletions.
16 changes: 10 additions & 6 deletions src/DotWeb.Decompiler/Core/Interpreter.cs
Expand Up @@ -54,6 +54,7 @@ public class Interpreter
this.block = block;

if (this.block.ExceptionHandler != null &&
this.block.ExceptionHandler.TryStart.Offset != this.block.FirstInstruction.Offset &&
this.block.ExceptionHandler.Type == ExceptionHandlerType.Catch) {
Debug.Assert(!this.stack.Any());

Expand All @@ -73,7 +74,7 @@ public class Interpreter

// In debug builds, the compiler emits CIL that helps the debugger with locality,
// but screws up the stack because we assume that each block defines a stack boundry.
// That is, at the start and end of each block, the stack is assumed to be empty,
// That is, at the start and end of each block, the stack is assumed to be empty.
// This is an attempt to have instructions that cause the stack to become empty be
// consumed by the predecessors that need them in order to make this assumption true.
// Another case occurs when the compiler decides to push a value in one block
Expand Down Expand Up @@ -539,6 +540,7 @@ public class Interpreter

private void InitObj(Instruction cil) {
var obj = Pop();
// TODO: this should really be a CodeDefaultInitializerExpression
AddAssignment(obj, new CodePrimitiveExpression(null));
}

Expand All @@ -558,17 +560,19 @@ public class Interpreter
targetObject = new CodeTypeReference(method.DeclaringType);
}

if (method.IsVirtual) {
if (method.IsVirtual || method.IsConstructor) {
if (!isVirtual && targetObject is CodeThisReference) {
var callerType = this.method.DeclaringType;
var targetType = method.DeclaringType;
if (callerType.BaseType == targetType) {
if (this.typeSystem.IsSubclassOf(callerType, targetType)) {
targetObject = new CodeBaseReference();
}
}
var overrides = this.typeSystem.GetOverridesForVirtualMethod(method);
foreach (var overridenMethod in overrides) {
this.ExternalMethods.Add(overridenMethod);
if (!method.IsConstructor) {
var overrides = this.typeSystem.GetOverridesForVirtualMethod(method);
foreach (var overridenMethod in overrides) {
this.ExternalMethods.Add(overridenMethod);
}
}
}
this.ExternalMethods.Add(method);
Expand Down
14 changes: 14 additions & 0 deletions src/DotWeb.System/Collections/Generic/List.cs
Expand Up @@ -67,7 +67,21 @@ public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollect
}
}

/// <summary>
/// Removes the element at the specified index of the List&lt;T&gt;.
/// </summary>
/// <remarks>
/// This method is an O(n) operation, where n is (Count - index).
/// </remarks>
/// <exception cref="System.ArgumentOutOfRangeException">
/// index is less than 0. -or- index is equal to or greater than <see cref="Count"/>.
/// </exception>
/// <param name="index">The zero-based index of the element to remove.</param>
public void RemoveAt(int index) {
if (index < 0 || index > this.items.Length) {
throw new ArgumentOutOfRangeException("Index was out of range. Must be non-negative and less than the size of the collection.", "index");
}

if (index == 0) {
this.items.Shift();
}
Expand Down
10 changes: 6 additions & 4 deletions src/DotWeb.System/Delegate.cs
Expand Up @@ -33,11 +33,13 @@ public class Delegate
// return null;
//}

[JsCode("throw 'Not Supported';")]
public static extern Delegate Combine(Delegate a, Delegate b);
public static Delegate Combine(Delegate a, Delegate b) {
throw new NotSupportedException();
}

[JsCode("throw 'Not Supported';")]
public static extern Delegate Remove(Delegate source, Delegate value);
public static Delegate Remove(Delegate source, Delegate value) {
throw new NotSupportedException();
}
}

[UseSystem]
Expand Down
78 changes: 77 additions & 1 deletion src/DotWeb.System/Exception.cs
Expand Up @@ -60,7 +60,7 @@ public class Exception
[UseSystem]
public class SystemException : SysException
{
public SystemException() { }
public SystemException() : base("System error.") { }
public SystemException(string message) : base(message) { }
public SystemException(string message, SysException innerException) : base(message, innerException) { }
}
Expand All @@ -80,4 +80,80 @@ public class NotSupportedException : SystemException
public NotSupportedException(string message) : base(message) { }
public NotSupportedException(string message, SysException inner) : base(message, inner) { }
}

[UseSystem]
public class ArgumentException : SystemException
{
public ArgumentException() : base("Value does not fall within the expected range.") { }
public ArgumentException(string message) : base(message) { }
public ArgumentException(string message, SysException inner) : base(message, inner) { }

public ArgumentException(string paramName, string message)
: base(message) {
this.ParamName = paramName;
}

public ArgumentException(string message, string paramName, SysException innerException)
: base(message, innerException) {
}

public override string Message {
get {
string message = base.Message;
if ((this.ParamName != null) && (this.ParamName.Length != 0)) {
return message + "\n" + "Parameter name: " + this.ParamName;
//message + Environment.NewLine + string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_ParamName_Name"), new object[] { this.m_paramName })
}
return message;
}
}

public virtual string ParamName { get; private set; }
}

[UseSystem]
public class ArgumentNullException : ArgumentException
{
public ArgumentNullException() : base(DefaultMessage) { }
public ArgumentNullException(string paramName) : base(DefaultMessage, paramName) { }
public ArgumentNullException(string message, SysException inner) : base(message, inner) { }
public ArgumentNullException(string paramName, string message) : base(message, paramName) { }

private static string DefaultMessage = "Value cannot be null.";
}

[UseSystem]
public class ArgumentOutOfRangeException : ArgumentException
{
public ArgumentOutOfRangeException() : base(RangeMessage) { }
public ArgumentOutOfRangeException(string paramName) : base(RangeMessage, paramName) { }
public ArgumentOutOfRangeException(string message, SysException inner) : base(message, inner) { }
public ArgumentOutOfRangeException(string paramName, string message) : base(message, paramName) { }

public ArgumentOutOfRangeException(string paramName, object actualValue, string message)
: base(message, paramName) {
this.ActualValue = actualValue;
}

public virtual object ActualValue { get; private set; }
public override string Message {
get {
string message = base.Message;
if (this.ActualValue == null) {
return message;
}
//string str2 = string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_ActualValue"), this.m_actualValue.ToString());
string str2 = "Actual value was " + this.ActualValue.ToString();
if (message == null) {
return str2;
}
//return (message + Environment.NewLine + str2);
return message + "\n" + str2;
}
}

private static string RangeMessage {
get { return "Specified argument was out of the range of valid values."; }
}
}
}
39 changes: 7 additions & 32 deletions src/DotWeb.Translator/Generator/JavaScript/JsCodeGenerator.cs
Expand Up @@ -111,6 +111,7 @@ public class JsCodeGenerator: ICodeStatementVisitor, ICodeMemberVisitor
WriteLine("}}");
if (stmt.Catches.Any()) {
WriteLine("catch (__ex__) {{");
WriteLine("console.log(__ex__);");
this.writer.Indent++;
bool isFirst = true;
foreach (var catchClause in stmt.Catches) {
Expand Down Expand Up @@ -335,40 +336,14 @@ public class JsCodeGenerator: ICodeStatementVisitor, ICodeMemberVisitor
this.currentMethod = method;
this.locals.Clear();

//if (method.Instructions != null) {
// WriteLine("/*");
// foreach (var il in method.Instructions) {
// this.WriteLine(il);
// }
// WriteLine(" */");
//}

string[] args = method.Parameters.Select(x => Print(x)).ToArray();
string name = method.Name;
if (method.Definition.IsConstructor) {
WriteLine("{0}.prototype.{1} = function({2}) {{",
Print(method.Definition.DeclaringType),
JsPrinter.CtorMethodName,
string.Join(", ", args)
);
}
else if (method.Definition.IsStatic) {
if (name == ".cctor")
name = JsPrinter.CtorMethodName;

WriteLine("{0}.{1} = function({2}) {{",
Print(method.Definition.DeclaringType),
this.printer.GetMethodName(method.Definition),
string.Join(", ", args)
);
}
else {
WriteLine("{0}.prototype.{1} = function({2}) {{",
Print(method.Definition.DeclaringType),
this.printer.GetMethodName(method.Definition),
string.Join(", ", args)
);
Write(Print(method.Definition.DeclaringType));
Write(".");
if (!method.Definition.IsStatic) {
Write("prototype.");
}
Write(this.printer.GetMethodName(method.Definition));
WriteLine(" = function({0}) {{", string.Join(", ", args));

this.writer.Indent++;
if (string.IsNullOrEmpty(method.NativeCode)) {
Expand Down

0 comments on commit 65a528e

Please sign in to comment.