summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar mikebarnett <unknown>2011-03-02 16:52:31 +0000
committerGravatar mikebarnett <unknown>2011-03-02 16:52:31 +0000
commit59317a63d7e25749f5d542e3c406c69c73bbc48d (patch)
treed84e0a0ca60884ca258574fd46bc96fa45e76370
parent9a63fa89c511abbbb1da91044988136d33241b84 (diff)
Create a static constructor only for types that don't already define one.
Fix a problem in two of the heaps where the AST for "type Type;" wasn't getting created.
-rw-r--r--BCT/BytecodeTranslator/Heap.cs6
-rw-r--r--BCT/BytecodeTranslator/MetadataTraverser.cs12
-rw-r--r--BCT/RegressionTests/TranslationTest/GeneralHeapInput.txt60
-rw-r--r--BCT/RegressionTests/TranslationTest/SplitFieldsHeapInput.txt72
-rw-r--r--BCT/RegressionTests/TranslationTest/TwoDBoxHeapInput.txt70
-rw-r--r--BCT/RegressionTests/TranslationTest/TwoDIntHeapInput.txt70
6 files changed, 275 insertions, 15 deletions
diff --git a/BCT/BytecodeTranslator/Heap.cs b/BCT/BytecodeTranslator/Heap.cs
index 919ab243..4bd086c0 100644
--- a/BCT/BytecodeTranslator/Heap.cs
+++ b/BCT/BytecodeTranslator/Heap.cs
@@ -67,6 +67,9 @@ procedure {:inline 1} Alloc() returns (x: int)
program = null;
string prelude = this.InitialPreludeText + this.DelegateEncodingText;
var b = RepresentationFor.ParsePrelude(prelude, this, out program);
+ if (b) {
+ this.TypeType = new Bpl.CtorType(this.TypeTypeDecl.tok, this.TypeTypeDecl, new Bpl.TypeSeq());
+ }
return b;
}
@@ -305,6 +308,9 @@ procedure {:inline 1} Alloc() returns (x: int)
program = null;
string prelude = this.InitialPreludeText + this.DelegateEncodingText;
var b = RepresentationFor.ParsePrelude(prelude, this, out program);
+ if (b) {
+ this.TypeType = new Bpl.CtorType(this.TypeTypeDecl.tok, this.TypeTypeDecl, new Bpl.TypeSeq());
+ }
return b;
}
diff --git a/BCT/BytecodeTranslator/MetadataTraverser.cs b/BCT/BytecodeTranslator/MetadataTraverser.cs
index 76280212..9fc2f4ee 100644
--- a/BCT/BytecodeTranslator/MetadataTraverser.cs
+++ b/BCT/BytecodeTranslator/MetadataTraverser.cs
@@ -171,9 +171,14 @@ namespace BytecodeTranslator {
public override void Visit(ITypeDefinition typeDefinition) {
if (typeDefinition.IsClass) {
+ bool savedSawCctor = this.sawCctor;
+ this.sawCctor = false;
sink.FindOrCreateType(typeDefinition);
- CreateStaticConstructor(typeDefinition);
base.Visit(typeDefinition);
+ if (!this.sawCctor) {
+ CreateStaticConstructor(typeDefinition);
+ }
+ this.sawCctor = savedSawCctor;
} else if (typeDefinition.IsDelegate) {
sink.AddDelegateType(typeDefinition);
} else if (typeDefinition.IsInterface) {
@@ -188,6 +193,8 @@ namespace BytecodeTranslator {
}
}
+ private bool sawCctor = false;
+
private void CreateStaticConstructor(ITypeDefinition typeDefinition) {
var proc = new Bpl.Procedure(Bpl.Token.NoToken,
TypeHelper.GetTypeName(typeDefinition) + ".#cctor",
@@ -244,6 +251,9 @@ namespace BytecodeTranslator {
///
/// </summary>
public override void Visit(IMethodDefinition method) {
+
+ if (method.IsStaticConstructor) this.sawCctor = true;
+
bool isEventAddOrRemove = method.IsSpecialName && (method.Name.Value.StartsWith("add_") || method.Name.Value.StartsWith("remove_"));
if (isEventAddOrRemove)
return;
diff --git a/BCT/RegressionTests/TranslationTest/GeneralHeapInput.txt b/BCT/RegressionTests/TranslationTest/GeneralHeapInput.txt
index 00b54a84..a9ca1990 100644
--- a/BCT/RegressionTests/TranslationTest/GeneralHeapInput.txt
+++ b/BCT/RegressionTests/TranslationTest/GeneralHeapInput.txt
@@ -188,8 +188,6 @@ implementation DelegateRemoveHelper(oldi: int, m: int, o: int) returns (i: int)
-type Type;
-
type Field;
var $Heap: HeapType where IsGoodHeap($Heap);
@@ -212,6 +210,8 @@ function {:inline true} Write(H: HeapType, o: ref, f: Field, v: box) : HeapType
H[o, f := v]
}
+type Type;
+
function $DynamicType(ref) : Type;
var $Head: [int]int;
@@ -260,6 +260,16 @@ implementation RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#ctor(thi
+procedure RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#cctor();
+
+
+
+implementation RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#cctor()
+{
+}
+
+
+
const unique RegressionTestInput.AsyncAttribute: Type;
procedure RegressionTestInput.AsyncAttribute.#ctor(this: int);
@@ -278,6 +288,16 @@ implementation RegressionTestInput.AsyncAttribute.#ctor(this: int)
+procedure RegressionTestInput.AsyncAttribute.#cctor();
+
+
+
+implementation RegressionTestInput.AsyncAttribute.#cctor()
+{
+}
+
+
+
const unique RegressionTestInput.ClassWithBoolTypes: Type;
var RegressionTestInput.ClassWithBoolTypes.staticB: bool;
@@ -314,7 +334,6 @@ implementation RegressionTestInput.ClassWithBoolTypes.#ctor$System.Boolean(this:
var z: bool;
z := z$in;
- $Heap := Write($Heap, this, RegressionTestInput.ClassWithBoolTypes.staticB, Bool2Box(false));
$Heap := Write($Heap, this, RegressionTestInput.ClassWithBoolTypes.b, Bool2Box(false));
assert {:sourceFile "Class1.cs"} {:sourceLine 72} true;
call System.Object.#ctor(this);
@@ -351,6 +370,17 @@ implementation RegressionTestInput.ClassWithBoolTypes.Main()
+procedure RegressionTestInput.ClassWithBoolTypes.#cctor();
+
+
+
+implementation RegressionTestInput.ClassWithBoolTypes.#cctor()
+{
+ RegressionTestInput.ClassWithBoolTypes.staticB := false;
+}
+
+
+
const unique RegressionTestInput.ClassWithArrayTypes: Type;
var RegressionTestInput.ClassWithArrayTypes.s: int;
@@ -473,7 +503,6 @@ procedure RegressionTestInput.ClassWithArrayTypes.#ctor(this: int);
implementation RegressionTestInput.ClassWithArrayTypes.#ctor(this: int)
{
- $Heap := Write($Heap, this, RegressionTestInput.ClassWithArrayTypes.s, Int2Box(0));
$Heap := Write($Heap, this, RegressionTestInput.ClassWithArrayTypes.a, Int2Box(0));
call System.Object.#ctor(this);
return;
@@ -481,6 +510,17 @@ implementation RegressionTestInput.ClassWithArrayTypes.#ctor(this: int)
+procedure RegressionTestInput.ClassWithArrayTypes.#cctor();
+
+
+
+implementation RegressionTestInput.ClassWithArrayTypes.#cctor()
+{
+ RegressionTestInput.ClassWithArrayTypes.s := 0;
+}
+
+
+
const unique RegressionTestInput.Class0: Type;
var RegressionTestInput.Class0.StaticInt: int;
@@ -709,9 +749,19 @@ procedure RegressionTestInput.Class0.#ctor(this: int);
implementation RegressionTestInput.Class0.#ctor(this: int)
{
- $Heap := Write($Heap, this, RegressionTestInput.Class0.StaticInt, Int2Box(0));
call System.Object.#ctor(this);
return;
}
+
+procedure RegressionTestInput.Class0.#cctor();
+
+
+
+implementation RegressionTestInput.Class0.#cctor()
+{
+ RegressionTestInput.Class0.StaticInt := 0;
+}
+
+
diff --git a/BCT/RegressionTests/TranslationTest/SplitFieldsHeapInput.txt b/BCT/RegressionTests/TranslationTest/SplitFieldsHeapInput.txt
index f634d13a..176360d8 100644
--- a/BCT/RegressionTests/TranslationTest/SplitFieldsHeapInput.txt
+++ b/BCT/RegressionTests/TranslationTest/SplitFieldsHeapInput.txt
@@ -29,6 +29,8 @@ implementation Alloc() returns (x: int)
+type ref = int;
+
procedure DelegateAdd(a: int, b: int) returns (c: int);
@@ -186,6 +188,10 @@ implementation DelegateRemoveHelper(oldi: int, m: int, o: int) returns (i: int)
+type Type;
+
+function $DynamicType(ref) : Type;
+
var $Head: [int]int;
var $Next: [int][int]int;
@@ -194,6 +200,8 @@ var $Method: [int][int]int;
var $Receiver: [int][int]int;
+const unique RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap: Type;
+
var RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.x: [int]int;
var RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.y: [int]int;
@@ -230,6 +238,18 @@ implementation RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#ctor(thi
+procedure RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#cctor();
+
+
+
+implementation RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#cctor()
+{
+}
+
+
+
+const unique RegressionTestInput.AsyncAttribute: Type;
+
procedure RegressionTestInput.AsyncAttribute.#ctor(this: int);
@@ -246,6 +266,18 @@ implementation RegressionTestInput.AsyncAttribute.#ctor(this: int)
+procedure RegressionTestInput.AsyncAttribute.#cctor();
+
+
+
+implementation RegressionTestInput.AsyncAttribute.#cctor()
+{
+}
+
+
+
+const unique RegressionTestInput.ClassWithBoolTypes: Type;
+
var RegressionTestInput.ClassWithBoolTypes.staticB: bool;
var RegressionTestInput.ClassWithBoolTypes.b: [int]bool;
@@ -280,7 +312,6 @@ implementation RegressionTestInput.ClassWithBoolTypes.#ctor$System.Boolean(this:
var z: bool;
z := z$in;
- RegressionTestInput.ClassWithBoolTypes.staticB[this] := false;
RegressionTestInput.ClassWithBoolTypes.b[this] := false;
assert {:sourceFile "Class1.cs"} {:sourceLine 72} true;
call System.Object.#ctor(this);
@@ -317,6 +348,19 @@ implementation RegressionTestInput.ClassWithBoolTypes.Main()
+procedure RegressionTestInput.ClassWithBoolTypes.#cctor();
+
+
+
+implementation RegressionTestInput.ClassWithBoolTypes.#cctor()
+{
+ RegressionTestInput.ClassWithBoolTypes.staticB := false;
+}
+
+
+
+const unique RegressionTestInput.ClassWithArrayTypes: Type;
+
var RegressionTestInput.ClassWithArrayTypes.s: int;
var RegressionTestInput.ClassWithArrayTypes.a: [int]int;
@@ -437,7 +481,6 @@ procedure RegressionTestInput.ClassWithArrayTypes.#ctor(this: int);
implementation RegressionTestInput.ClassWithArrayTypes.#ctor(this: int)
{
- RegressionTestInput.ClassWithArrayTypes.s[this] := 0;
RegressionTestInput.ClassWithArrayTypes.a[this] := 0;
call System.Object.#ctor(this);
return;
@@ -445,6 +488,19 @@ implementation RegressionTestInput.ClassWithArrayTypes.#ctor(this: int)
+procedure RegressionTestInput.ClassWithArrayTypes.#cctor();
+
+
+
+implementation RegressionTestInput.ClassWithArrayTypes.#cctor()
+{
+ RegressionTestInput.ClassWithArrayTypes.s := 0;
+}
+
+
+
+const unique RegressionTestInput.Class0: Type;
+
var RegressionTestInput.Class0.StaticInt: int;
procedure RegressionTestInput.Class0.StaticMethod$System.Int32(x$in: int) returns ($result: int);
@@ -671,9 +727,19 @@ procedure RegressionTestInput.Class0.#ctor(this: int);
implementation RegressionTestInput.Class0.#ctor(this: int)
{
- RegressionTestInput.Class0.StaticInt[this] := 0;
call System.Object.#ctor(this);
return;
}
+
+procedure RegressionTestInput.Class0.#cctor();
+
+
+
+implementation RegressionTestInput.Class0.#cctor()
+{
+ RegressionTestInput.Class0.StaticInt := 0;
+}
+
+
diff --git a/BCT/RegressionTests/TranslationTest/TwoDBoxHeapInput.txt b/BCT/RegressionTests/TranslationTest/TwoDBoxHeapInput.txt
index 35328269..cde891c4 100644
--- a/BCT/RegressionTests/TranslationTest/TwoDBoxHeapInput.txt
+++ b/BCT/RegressionTests/TranslationTest/TwoDBoxHeapInput.txt
@@ -196,6 +196,10 @@ function Int2Box(int) : box;
function Bool2Box(bool) : box;
+type Type;
+
+function $DynamicType(ref) : Type;
+
var $Head: [int]int;
var $Next: [int][int]int;
@@ -204,6 +208,8 @@ var $Method: [int][int]int;
var $Receiver: [int][int]int;
+const unique RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap: Type;
+
const unique RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.x: int;
const unique RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.y: int;
@@ -240,6 +246,18 @@ implementation RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#ctor(thi
+procedure RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#cctor();
+
+
+
+implementation RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#cctor()
+{
+}
+
+
+
+const unique RegressionTestInput.AsyncAttribute: Type;
+
procedure RegressionTestInput.AsyncAttribute.#ctor(this: int);
@@ -256,6 +274,18 @@ implementation RegressionTestInput.AsyncAttribute.#ctor(this: int)
+procedure RegressionTestInput.AsyncAttribute.#cctor();
+
+
+
+implementation RegressionTestInput.AsyncAttribute.#cctor()
+{
+}
+
+
+
+const unique RegressionTestInput.ClassWithBoolTypes: Type;
+
var RegressionTestInput.ClassWithBoolTypes.staticB: bool;
const unique RegressionTestInput.ClassWithBoolTypes.b: bool;
@@ -290,7 +320,6 @@ implementation RegressionTestInput.ClassWithBoolTypes.#ctor$System.Boolean(this:
var z: bool;
z := z$in;
- $Heap[this, RegressionTestInput.ClassWithBoolTypes.staticB] := Bool2Box(false);
$Heap[this, RegressionTestInput.ClassWithBoolTypes.b] := Bool2Box(false);
assert {:sourceFile "Class1.cs"} {:sourceLine 72} true;
call System.Object.#ctor(this);
@@ -327,6 +356,19 @@ implementation RegressionTestInput.ClassWithBoolTypes.Main()
+procedure RegressionTestInput.ClassWithBoolTypes.#cctor();
+
+
+
+implementation RegressionTestInput.ClassWithBoolTypes.#cctor()
+{
+ RegressionTestInput.ClassWithBoolTypes.staticB := false;
+}
+
+
+
+const unique RegressionTestInput.ClassWithArrayTypes: Type;
+
var RegressionTestInput.ClassWithArrayTypes.s: int;
const unique RegressionTestInput.ClassWithArrayTypes.a: int;
@@ -447,7 +489,6 @@ procedure RegressionTestInput.ClassWithArrayTypes.#ctor(this: int);
implementation RegressionTestInput.ClassWithArrayTypes.#ctor(this: int)
{
- $Heap[this, RegressionTestInput.ClassWithArrayTypes.s] := Int2Box(0);
$Heap[this, RegressionTestInput.ClassWithArrayTypes.a] := Int2Box(0);
call System.Object.#ctor(this);
return;
@@ -455,6 +496,19 @@ implementation RegressionTestInput.ClassWithArrayTypes.#ctor(this: int)
+procedure RegressionTestInput.ClassWithArrayTypes.#cctor();
+
+
+
+implementation RegressionTestInput.ClassWithArrayTypes.#cctor()
+{
+ RegressionTestInput.ClassWithArrayTypes.s := 0;
+}
+
+
+
+const unique RegressionTestInput.Class0: Type;
+
var RegressionTestInput.Class0.StaticInt: int;
procedure RegressionTestInput.Class0.StaticMethod$System.Int32(x$in: int) returns ($result: int);
@@ -681,9 +735,19 @@ procedure RegressionTestInput.Class0.#ctor(this: int);
implementation RegressionTestInput.Class0.#ctor(this: int)
{
- $Heap[this, RegressionTestInput.Class0.StaticInt] := Int2Box(0);
call System.Object.#ctor(this);
return;
}
+
+procedure RegressionTestInput.Class0.#cctor();
+
+
+
+implementation RegressionTestInput.Class0.#cctor()
+{
+ RegressionTestInput.Class0.StaticInt := 0;
+}
+
+
diff --git a/BCT/RegressionTests/TranslationTest/TwoDIntHeapInput.txt b/BCT/RegressionTests/TranslationTest/TwoDIntHeapInput.txt
index e48e4bd1..9f63170c 100644
--- a/BCT/RegressionTests/TranslationTest/TwoDIntHeapInput.txt
+++ b/BCT/RegressionTests/TranslationTest/TwoDIntHeapInput.txt
@@ -186,6 +186,10 @@ implementation DelegateRemoveHelper(oldi: int, m: int, o: int) returns (i: int)
var $Heap: HeapType where IsGoodHeap($Heap);
+type Type;
+
+function $DynamicType(ref) : Type;
+
var $Head: [int]int;
var $Next: [int][int]int;
@@ -194,6 +198,8 @@ var $Method: [int][int]int;
var $Receiver: [int][int]int;
+const unique RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap: Type;
+
const unique RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.x: int;
const unique RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.y: int;
@@ -230,6 +236,18 @@ implementation RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#ctor(thi
+procedure RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#cctor();
+
+
+
+implementation RegressionTestInput.WriteToTheHeapAValueReadFromTheHeap.#cctor()
+{
+}
+
+
+
+const unique RegressionTestInput.AsyncAttribute: Type;
+
procedure RegressionTestInput.AsyncAttribute.#ctor(this: int);
@@ -246,6 +264,18 @@ implementation RegressionTestInput.AsyncAttribute.#ctor(this: int)
+procedure RegressionTestInput.AsyncAttribute.#cctor();
+
+
+
+implementation RegressionTestInput.AsyncAttribute.#cctor()
+{
+}
+
+
+
+const unique RegressionTestInput.ClassWithBoolTypes: Type;
+
var RegressionTestInput.ClassWithBoolTypes.staticB: bool;
const unique RegressionTestInput.ClassWithBoolTypes.b: bool;
@@ -280,7 +310,6 @@ implementation RegressionTestInput.ClassWithBoolTypes.#ctor$System.Boolean(this:
var z: bool;
z := z$in;
- $Heap[this, RegressionTestInput.ClassWithBoolTypes.staticB] := false;
$Heap[this, RegressionTestInput.ClassWithBoolTypes.b] := false;
assert {:sourceFile "Class1.cs"} {:sourceLine 72} true;
call System.Object.#ctor(this);
@@ -317,6 +346,19 @@ implementation RegressionTestInput.ClassWithBoolTypes.Main()
+procedure RegressionTestInput.ClassWithBoolTypes.#cctor();
+
+
+
+implementation RegressionTestInput.ClassWithBoolTypes.#cctor()
+{
+ RegressionTestInput.ClassWithBoolTypes.staticB := false;
+}
+
+
+
+const unique RegressionTestInput.ClassWithArrayTypes: Type;
+
var RegressionTestInput.ClassWithArrayTypes.s: int;
const unique RegressionTestInput.ClassWithArrayTypes.a: int;
@@ -437,7 +479,6 @@ procedure RegressionTestInput.ClassWithArrayTypes.#ctor(this: int);
implementation RegressionTestInput.ClassWithArrayTypes.#ctor(this: int)
{
- $Heap[this, RegressionTestInput.ClassWithArrayTypes.s] := 0;
$Heap[this, RegressionTestInput.ClassWithArrayTypes.a] := 0;
call System.Object.#ctor(this);
return;
@@ -445,6 +486,19 @@ implementation RegressionTestInput.ClassWithArrayTypes.#ctor(this: int)
+procedure RegressionTestInput.ClassWithArrayTypes.#cctor();
+
+
+
+implementation RegressionTestInput.ClassWithArrayTypes.#cctor()
+{
+ RegressionTestInput.ClassWithArrayTypes.s := 0;
+}
+
+
+
+const unique RegressionTestInput.Class0: Type;
+
var RegressionTestInput.Class0.StaticInt: int;
procedure RegressionTestInput.Class0.StaticMethod$System.Int32(x$in: int) returns ($result: int);
@@ -671,9 +725,19 @@ procedure RegressionTestInput.Class0.#ctor(this: int);
implementation RegressionTestInput.Class0.#ctor(this: int)
{
- $Heap[this, RegressionTestInput.Class0.StaticInt] := 0;
call System.Object.#ctor(this);
return;
}
+
+procedure RegressionTestInput.Class0.#cctor();
+
+
+
+implementation RegressionTestInput.Class0.#cctor()
+{
+ RegressionTestInput.Class0.StaticInt := 0;
+}
+
+