blob: 9079b5af3e9cd101918d70e58ac4e78dca4b31ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Cci;
using Microsoft.Cci.MetadataReader;
using Microsoft.Cci.MutableCodeModel;
using Microsoft.Cci.Contracts;
using Microsoft.Cci.ILToCodeModel;
using Bpl = Microsoft.Boogie;
namespace BytecodeTranslator {
/// <summary>
///
/// </summary>
internal class ToplevelTraverser : BaseCodeAndContractTraverser {
public readonly IContractProvider ContractProvider;
public readonly Bpl.Program TranslatedProgram;
private Dictionary<ITypeDefinition, ClassTraverser> classMap = new Dictionary<ITypeDefinition, ClassTraverser>();
public ToplevelTraverser(IContractProvider cp)
: base(cp) {
ContractProvider = cp;
TranslatedProgram = new Bpl.Program();
}
public Bpl.Variable FindOrCreateClassField(ITypeDefinition classtype, IFieldDefinition field) {
ClassTraverser ct;
if (!classMap.TryGetValue(classtype, out ct)) {
ct = new ClassTraverser(this.ContractProvider, this);
classMap.Add(classtype, ct);
return ct.FindOrCreateFieldVariable(field);
} else {
return ct.FindOrCreateFieldVariable(field);
}
}
/// <summary>
///
/// </summary>
/// <param name="typeDefinition"></param>
public override void Visit(ITypeDefinition typeDefinition) {
if (typeDefinition.IsClass) {
ClassTraverser ct;
if (!classMap.TryGetValue(typeDefinition, out ct)) {
ct = new ClassTraverser(this.contractProvider, this);
classMap.Add(typeDefinition, ct);
}
ct.Visit(typeDefinition);
} else {
Console.WriteLine("Non-Class {0} was found", typeDefinition);
throw new NotImplementedException(String.Format("Non-Class Type {0} is not yet supported.", typeDefinition.ToString()));
}
}
public override void Visit(IModule module) {
base.Visit(module);
}
public override void Visit(IAssembly assembly) {
base.Visit(assembly);
}
}
}
|