summaryrefslogtreecommitdiff
path: root/Source/Concurrency/Program.cs
blob: a3a621acf494a53b1a3d74cf8d8e4496fa08a586 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Boogie
{
    public class Concurrency
    {
        public static void Transform(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker)
        {
            // The order in which originalDecls are computed and then *.AddCheckers are called is 
            // apparently important.  The MyDuplicator code currently does not duplicate Attributes.
            // Consequently, all the yield attributes are eliminated by the AddCheckers code.

            List<Declaration> originalDecls = new List<Declaration>();
            Program program = linearTypeChecker.program;
            foreach (var decl in program.TopLevelDeclarations)
            {
                Procedure proc = decl as Procedure;
                if (proc != null && QKeyValue.FindBoolAttribute(proc.Attributes, "yields"))
                {
                    originalDecls.Add(proc);
                    continue;
                }
                Implementation impl = decl as Implementation;
                if (impl != null && QKeyValue.FindBoolAttribute(impl.Proc.Attributes, "yields"))
                {
                    originalDecls.Add(impl);
                }
            }

            List<Declaration> decls = new List<Declaration>();
            OwickiGries.AddCheckers(linearTypeChecker, moverTypeChecker, decls);
            if (!CommandLineOptions.Clo.TrustAtomicityTypes)
            {
                MoverCheck.AddCheckers(linearTypeChecker, moverTypeChecker, decls);
            }
            foreach (Declaration decl in decls)
            {
                Procedure proc = decl as Procedure;
                if (proc != null && QKeyValue.FindBoolAttribute(proc.Attributes, "yields"))
                {
                    proc.Modifies = new List<IdentifierExpr>();
                    linearTypeChecker.program.GlobalVariables().Iter(x => proc.Modifies.Add(Expr.Ident(x)));
                }
            }
            foreach (Declaration decl in decls)
            {
                decl.Attributes = OwickiGries.RemoveYieldsAttribute(decl.Attributes);
                decl.Attributes = OwickiGries.RemoveStableAttribute(decl.Attributes);
            }
            program.TopLevelDeclarations.RemoveAll(x => originalDecls.Contains(x));
            program.TopLevelDeclarations.AddRange(decls);
        }

    }
}