summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Mike Barnett <mbarnett@microsoft.com>2011-05-29 19:19:29 -0700
committerGravatar Mike Barnett <mbarnett@microsoft.com>2011-05-29 19:19:29 -0700
commit404ff152f889a827ddeafae34125064f65182d10 (patch)
tree496731ef33658077ae4ccf8a9e01582f41c341cc
parent8791e9062a2c26420578a3c8114a1d2fe174c6f0 (diff)
Fixed struct ctors so that they don't return the "this" value, but just
operate on the "this" parameter since it is now a Ref. Fixed the construction of the sink's "this" parameter so that it gets created anew for each method, since it will become a local variable of the method, if the method is a struct ctor.
-rw-r--r--BCT/BytecodeTranslator/ExpressionTraverser.cs3
-rw-r--r--BCT/BytecodeTranslator/MetadataTraverser.cs13
-rw-r--r--BCT/BytecodeTranslator/Sink.cs25
-rw-r--r--BCT/BytecodeTranslator/TranslationHelper.cs8
4 files changed, 15 insertions, 34 deletions
diff --git a/BCT/BytecodeTranslator/ExpressionTraverser.cs b/BCT/BytecodeTranslator/ExpressionTraverser.cs
index 4d5c2e96..2a879059 100644
--- a/BCT/BytecodeTranslator/ExpressionTraverser.cs
+++ b/BCT/BytecodeTranslator/ExpressionTraverser.cs
@@ -562,9 +562,6 @@ namespace BytecodeTranslator
inexpr.Add(e);
thisExpr = (Bpl.IdentifierExpr) e;
}
- if (thisArg != null && methodToCall.ContainingType.ResolvedType.IsStruct) {
- outvars.Add(thisExpr);
- }
#endregion
toBoxed = new Dictionary<Bpl.IdentifierExpr, Bpl.IdentifierExpr>();
diff --git a/BCT/BytecodeTranslator/MetadataTraverser.cs b/BCT/BytecodeTranslator/MetadataTraverser.cs
index 2458d27c..c02d3caa 100644
--- a/BCT/BytecodeTranslator/MetadataTraverser.cs
+++ b/BCT/BytecodeTranslator/MetadataTraverser.cs
@@ -104,7 +104,7 @@ namespace BytecodeTranslator {
var proc = this.sink.FindOrCreateProcedureForDefaultStructCtor(typeDefinition);
- this.sink.BeginMethod();
+ this.sink.BeginMethod(typeDefinition);
var stmtTranslator = this.factory.MakeStatementTraverser(this.sink, this.PdbReader, false);
var stmts = new List<IStatement>();
@@ -206,7 +206,7 @@ namespace BytecodeTranslator {
this.sink.TranslatedProgram.TopLevelDeclarations.Add(proc);
- this.sink.BeginMethod();
+ this.sink.BeginMethod(typeDefinition);
var stmtTranslator = this.factory.MakeStatementTraverser(this.sink, this.PdbReader, false);
var stmts = new List<IStatement>();
@@ -275,7 +275,7 @@ namespace BytecodeTranslator {
return;
}
- this.sink.BeginMethod();
+ this.sink.BeginMethod(method.ContainingType);
var decl = procAndFormalMap.Decl;
var proc = decl as Bpl.Procedure;
var formalMap = procAndFormalMap.FormalMap;
@@ -299,8 +299,8 @@ namespace BytecodeTranslator {
if (!method.IsStatic && method.ContainingType.ResolvedType.IsStruct) {
Bpl.IToken tok = method.Token();
stmtTraverser.StmtBuilder.Add(Bpl.Cmd.SimpleAssign(tok,
- new Bpl.IdentifierExpr(tok, proc.OutParams[0]),
- new Bpl.IdentifierExpr(tok, proc.InParams[0])));
+ Bpl.Expr.Ident(this.sink.ThisVariable),
+ new Bpl.IdentifierExpr(tok, proc.InParams[0])));
}
#endregion
@@ -357,6 +357,9 @@ namespace BytecodeTranslator {
#region Create Local Vars For Implementation
List<Bpl.Variable> vars = new List<Bpl.Variable>();
+ if (!method.IsStatic && method.ContainingType.ResolvedType.IsStruct) {
+ vars.Add(this.sink.ThisVariable);
+ }
foreach (MethodParameter mparam in formalMap.Values) {
if (!mparam.underlyingParameter.IsByReference)
vars.Add(mparam.outParameterCopy);
diff --git a/BCT/BytecodeTranslator/Sink.cs b/BCT/BytecodeTranslator/Sink.cs
index 093233cb..81ea6e3f 100644
--- a/BCT/BytecodeTranslator/Sink.cs
+++ b/BCT/BytecodeTranslator/Sink.cs
@@ -52,7 +52,7 @@ namespace BytecodeTranslator {
}
readonly Heap heap;
- public Bpl.Variable ThisVariable = TranslationHelper.TempThisVar();
+ public Bpl.Variable ThisVariable;
public Bpl.Variable RetVariable;
public readonly string AllocationMethodName = "Alloc";
@@ -353,22 +353,12 @@ namespace BytecodeTranslator {
#endregion
Bpl.Formal/*?*/ self = null;
- Bpl.Formal selfOut = null;
#region Create 'this' parameter
if (!method.IsStatic) {
var selfType = CciTypeToBoogie(method.ContainingType);
- if (method.ContainingType.ResolvedType.IsStruct) {
- //selfType = Heap.StructType;
- in_count++;
- self = new Bpl.Formal(method.Token(), new Bpl.TypedIdent(method.Type.Token(), "thisIn", selfType), true);
- out_count++;
- selfOut = new Bpl.Formal(method.Token(), new Bpl.TypedIdent(method.Type.Token(), "this", selfType), false);
- }
- else {
- in_count++;
- //selfType = Heap.RefType;
- self = new Bpl.Formal(method.Token(), new Bpl.TypedIdent(method.Type.Token(), "this", selfType), true);
- }
+ in_count++;
+ var self_name = method.ContainingTypeDefinition.IsStruct ? "this$in" : "this";
+ self = new Bpl.Formal(method.Token(), new Bpl.TypedIdent(method.Type.Token(), self_name, selfType), true);
}
#endregion
@@ -378,11 +368,9 @@ namespace BytecodeTranslator {
int i = 0;
int j = 0;
- #region Add 'this' parameter as first in parameter and 'thisOut' parameter as first out parameter
+ #region Add 'this' parameter as first in parameter
if (self != null)
invars[i++] = self;
- if (selfOut != null)
- outvars[j++] = selfOut;
#endregion
foreach (MethodParameter mparam in formalMap.Values) {
@@ -684,9 +672,10 @@ namespace BytecodeTranslator {
/// </summary>
private Dictionary<string, Bpl.Procedure> initiallyDeclaredProcedures = new Dictionary<string, Bpl.Procedure>();
- public void BeginMethod() {
+ public void BeginMethod(ITypeReference containingType) {
this.localVarMap = new Dictionary<ILocalDefinition, Bpl.LocalVariable>();
this.localCounter = 0;
+ this.ThisVariable = new Bpl.LocalVariable(Bpl.Token.NoToken, new Bpl.TypedIdent(Bpl.Token.NoToken, "this", this.Heap.RefType));
}
public void BeginAssembly(IAssembly assembly) {
diff --git a/BCT/BytecodeTranslator/TranslationHelper.cs b/BCT/BytecodeTranslator/TranslationHelper.cs
index fde776f9..d554d83e 100644
--- a/BCT/BytecodeTranslator/TranslationHelper.cs
+++ b/BCT/BytecodeTranslator/TranslationHelper.cs
@@ -126,13 +126,5 @@ namespace BytecodeTranslator {
return typ.IsValueType && !typ.IsEnum && typ.TypeCode == PrimitiveTypeCode.NotPrimitive;
}
- #region Temp Stuff that must be replaced as soon as there is real code to deal with this
-
- public static Bpl.Variable TempThisVar() {
- return new Bpl.GlobalVariable(Bpl.Token.NoToken, new Bpl.TypedIdent(Bpl.Token.NoToken, "this", Bpl.Type.Int));
- }
-
- #endregion
-
}
}