-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArcIR.fs
More file actions
66 lines (45 loc) · 1.86 KB
/
Copy pathArcIR.fs
File metadata and controls
66 lines (45 loc) · 1.86 KB
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
namespace Arc.Build
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module ArcIR =
let addObject (object': ArcObject) (ir: ArcIR) =
match ir.Objects.TryFind object'.Id with
| None ->
{ ir with Objects = ir.Objects.Add(object'.Id, object') }
| Some existing when existing = object' ->
ir
| Some existing ->
let merged =
{
existing with
DTypes = Set.union existing.DTypes object'.DTypes
Properties =
Map.fold
(fun acc key value -> Map.add key value acc)
existing.Properties
object'.Properties
Annotations =
existing.Annotations @ object'.Annotations
}
{ ir with Objects = ir.Objects.Add(object'.Id, merged) }
let addRelation (relation: ArcRelation) (ir: ArcIR) =
{ ir with Relations = ir.Relations.Add relation }
let addObjects objects ir =
objects |> Seq.fold (fun acc o -> addObject o acc) ir
let addRelations relations ir =
relations |> Seq.fold (fun acc r -> addRelation r acc) ir
let merge (left: ArcIR) (right: ArcIR) =
left
|> addObjects right.Objects.Values
|> addRelations right.Relations
let outgoing objectId ir =
ir.Relations
|> Seq.filter (fun r -> r.Subject = objectId)
let incoming objectId ir =
ir.Relations
|> Seq.filter (fun r -> r.Object = objectId)
let objectsByKind kind ir =
ir.Objects.Values
|> Seq.filter (fun o -> o.Kind = kind)
let objectsByDType dtype ir =
ir.Objects.Values
|> Seq.filter (fun o -> o.DTypes.Contains dtype)