summaryrefslogtreecommitdiff
path: root/BCT/BytecodeTranslator/ExpressionTraverser.cs
diff options
context:
space:
mode:
Diffstat (limited to 'BCT/BytecodeTranslator/ExpressionTraverser.cs')
-rw-r--r--BCT/BytecodeTranslator/ExpressionTraverser.cs52
1 files changed, 27 insertions, 25 deletions
diff --git a/BCT/BytecodeTranslator/ExpressionTraverser.cs b/BCT/BytecodeTranslator/ExpressionTraverser.cs
index 53e4ccce..d30202da 100644
--- a/BCT/BytecodeTranslator/ExpressionTraverser.cs
+++ b/BCT/BytecodeTranslator/ExpressionTraverser.cs
@@ -414,6 +414,8 @@ namespace BytecodeTranslator
var lit = Bpl.Expr.False;
lit.Type = Bpl.Type.Bool;
TranslatedExpressions.Push(lit);
+ } else if (defaultValue.Type.ResolvedType.IsStruct){
+ TranslatedExpressions.Push(Bpl.Expr.Ident(this.sink.Heap.DefaultStruct));
} else {
throw new NotImplementedException("Don't know how to translate type");
}
@@ -626,31 +628,31 @@ namespace BytecodeTranslator
#region Special case for s := default(S) when S is a struct
- // The C# source "s = new S()" when S is a struct is compiled
- // into an "initobj" instruction. That is decompiled into the
- // assignment: "s = DefaultValue(S)".
- // We translate it as a call to a pseduo-ctor that is created for S:
- // "s := S.#default_ctor()".
-
- if (assignment.Target.Type.ResolvedType.IsStruct &&
- assignment.Target.Type.TypeCode == PrimitiveTypeCode.NotPrimitive &&
- assignment.Source is IDefaultValue) {
-
- this.Visit(assignment.Target);
- var s = this.TranslatedExpressions.Pop();
-
- var structType = assignment.Target.Type;
- Bpl.IToken tok = assignment.Token();
- var proc = this.sink.FindOrCreateProcedureForDefaultStructCtor(structType);
- string methodname = proc.Name;
- var inexpr = new List<Bpl.Expr>();
- var outvars = new List<Bpl.IdentifierExpr>();
- outvars.Add((Bpl.IdentifierExpr)s);
- var call = new Bpl.CallCmd(tok, methodname, inexpr, outvars);
- this.StmtTraverser.StmtBuilder.Add(call);
-
- return;
- }
+ //// The C# source "s = new S()" when S is a struct is compiled
+ //// into an "initobj" instruction. That is decompiled into the
+ //// assignment: "s = DefaultValue(S)".
+ //// We translate it as a call to a pseduo-ctor that is created for S:
+ //// "s := S.#default_ctor()".
+
+ //if (assignment.Target.Type.ResolvedType.IsStruct &&
+ // assignment.Target.Type.TypeCode == PrimitiveTypeCode.NotPrimitive &&
+ // assignment.Source is IDefaultValue) {
+
+ // this.Visit(assignment.Target);
+ // var s = this.TranslatedExpressions.Pop();
+
+ // var structType = assignment.Target.Type;
+ // Bpl.IToken tok = assignment.Token();
+ // var proc = this.sink.FindOrCreateProcedureForDefaultStructCtor(structType);
+ // string methodname = proc.Name;
+ // var inexpr = new List<Bpl.Expr>();
+ // var outvars = new List<Bpl.IdentifierExpr>();
+ // outvars.Add((Bpl.IdentifierExpr)s);
+ // var call = new Bpl.CallCmd(tok, methodname, inexpr, outvars);
+ // this.StmtTraverser.StmtBuilder.Add(call);
+
+ // return;
+ //}
#endregion
#region Transform Right Hand Side ...