-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparsednta.sml
110 lines (92 loc) · 3.56 KB
/
parsednta.sml
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(* $Id$
*
* Copyright (c) 2008 Timothy Bourke (University of NSW and NICTA)
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the "BSD License" which is distributed with the
* software in the file LICENSE.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the BSD
* License for more details.
*)
local
structure ParsedOutput : NTA_TYPES_OUTPUT
=
let structure E = Expression
and Env = Environment
and D = Declaration
and ECVT = ExpressionCvt
and EnvCVT = EnvironmentCvt
type symbol = Atom.atom
in
struct
type invariant = E.expr
and select = E.boundid list
and guard = E.expr
and sync = (symbol * E.direction * E.expr list) option
and update = E.expr list
and parameter = D.param list
and declaration = Env.env
and imports = string option
and instantiation = string option
and system = string
val noInvariant = E.trueExpr
and noSelect = []
and noGuard = E.trueExpr
and noSync = NONE
and noUpdate = []
val noParameter = []
val noDeclaration = Env.base_env
val noImports = NONE
val noInstantiation = NONE
val noSystem = ""
type outstream = TextIO.StreamIO.outstream
fun pr strm str = TextIO.StreamIO.output (strm, str)
fun hasExpression e = not (E.equal (e, E.BoolCExpr true))
val hasInvariant = hasExpression
fun hasSelect s = (not o List.null) s
val hasGuard = hasExpression
val hasSync = Option.isSome
fun hasUpdate s = (not o List.null) s
fun hasParameter s = (not o List.null) s
val hasDeclaration = (not o Env.isEmpty)
val hasImports = Option.isSome
val hasInstantiation = Option.isSome
val outputInvariant = ECVT.Expr.toStream
val outputSelect = ECVT.selectToStream
val outputGuard = ECVT.Expr.toStream
fun outputSync (os, SOME sync) = ECVT.syncToStream (os, sync)
| outputSync _ = ()
val outputUpdate = ECVT.exprlistToStream
val outputParameter = ECVT.paramlistToStream
val outputDeclaration = EnvCVT.toStream
val outputTemplateDeclaration = EnvCVT.templateToStream
fun outputImports (os, NONE) = ()
| outputImports (os, SOME s) = pr os s
fun outputInstantiation (os, NONE) = ()
| outputInstantiation (os, SOME s) = pr os s
fun outputSystem (os, s) = pr os s
end
end
structure ParsedNtaOutput = NtaOutputFn (structure T = ParsedOutput
structure S = TextIO.StreamIO)
structure E = Expression
in
structure ParsedNta : PARSED_NTA = struct
open ParsedNtaOutput
(* shortcuts over Atom and AtomSet *)
infix <+ <- ++ <\ \ =:= ; open Symbol
fun freeTransitionNames (Transition {select=(sel, _), guard=(g, _),
sync=(sync, _), update=(upd, _), ...}) =
let
fun syncSubs NONE = [] | syncSubs (SOME (_, _, subs)) = subs
val exprListNames = foldl (fn (e, s)=> s ++ (E.getFreeNames e)) emptyset
val boundnms = foldl (fn (E.BoundId (nm, _), s)=> s <+ nm) emptyset sel
val updatenms = exprListNames upd
val syncnms = exprListNames (syncSubs sync)
in (updatenms ++ syncnms ++ E.getFreeNames g) \ boundnms end
end
end (* local *)