-
Notifications
You must be signed in to change notification settings - Fork 42
/
eval_expr.sysl
257 lines (222 loc) · 6.78 KB
/
eval_expr.sysl
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
Model [package="com.example.gen", name="Model"]:
!type Request:
id <: int?
payload <: string
!type Response:
code <: int
message <: string
names <: sequence of Request?
!union Message:
Request
Response
!alias Error [~foo]:
@comment = "some description"
string
!alias Object:
Ignored
!alias Terms:
sequence of Term
!alias Accounts:
set of Term
TodoApp:
/todos:
GET:
if failed:
return 404 <: NotFoundError
else if error:
return 500 <: ServerError
else:
return 200 <: todos
POST (newTodo <: Todo [~body], accept <: string [~header]):
if failed:
return 500 <: ErrorResponse
else:
return 200 <: todo
/{id<:int}:
GET:
return todo
/{status<:string}:
GET:
return todoWithStatus
TransformApp:
!view math(lhs <: int, rhs <: int) -> int:
lhs -> (:
out1 = lhs + rhs
out2 = lhs -> <int> (:
out3 = 5 + 1
)
out3 = lhs - rhs
out4 = lhs * rhs
out5 = lhs / rhs
out6 = lhs % rhs
)
!view compare(lhs <: int, rhs <: int) -> int:
lhs -> (:
eq = lhs == rhs
gt = lhs > rhs
lt = lhs < rhs
ge = lhs >= rhs
le = lhs <= rhs
ne = lhs != rhs
)
!view getMap(key <: string) -> string:
key -> (:
out1 = key+"1"
out2 = key+"2"
out3 = key+"3"
)
!view ListSetOps(lhs <: string) -> set of string:
lhs -> (:
count1 = [1,2] count
count2 = {1,2} count
count3 = getMap("key") count
strs = {"rhs", "lhs"} | {"lhs"}
numbers = {1} | {1,2}
numbers2 = {1,2} where(. > 2) | {1} where(. > 2)
list = [1] | [1,2]
)
!view IsKeyword(word <: string) -> bool:
word -> (:
out = word in {"break", "default","func","interface","select","case","defer"}
)
# t is map
!view JavaType(t <: sysl.Type) -> string:
t -> (:
out = if t.type ==:
"primitive" => if t.primitive ==:
"INT" => "int"
"BOOL" => "Boolean"
"DECIMAL" => "BigDecimal"
"STRING" => "String"
"STRING_8" => "String"
"sequence" => "List<" + JavaType(t.sequence).out + ">"
else t.type_ref
)
!view Getters(fields <: set of app.Type) -> set of memberFunction:
fields -> (field:
access = "public"
let IsPtr = if field.value.optional == false then "" else "*"
returnType = IsPtr + JavaType(field.value).out
methodName = "get" + field.key
)
!view Setters(fields <: set of app.Type) -> set of memberFunction:
fields -> (field:
access = "public"
methodName = "set" + field.key
)
!view classDef(types <: app.Types) -> set of classDef:
types -> (t:
className = t.key + "Impl"
classBody = Getters(t.value.fields) | Setters(t.value.fields)
)
!view GetAppAttributes(app <: sysl.App) -> object:
app -> (:
out = app.attrs.package
package = .attrs.package -> <set of package> (name:
packageName = name
)
import = {"package1", "package2"} -> <set of import>(name:
importPath = Title(name)
)
definition = classDef(app.types)
Nil = . -> <some> (:
out = .
)
stringInNull = "abc" in app.attrs.patterns
stringInList = "pqr" in ["abc", "def"]
stringInMap = "key1" in getMap("key")
stringInSet = "a" in {"a","b","c"}
stringNotInNull = "abc" !in app.attrs.patterns
stringNotInList = "pqr" !in ["abc", "def"]
stringNotInMap = "abc" !in getMap("key")
stringNotInSet = "d" !in {"a","b","c"}
)
!view TestDotScope(app <: sysl.App) -> int:
app -> (:
out = .name
package = .name -> <package> (:
packageName = .
)
import = .name
)
!view StringOps(app <: sysl.App) -> int:
app -> (:
Contains = Contains("Hello World!", "World")
Count = Count("Hello World!", "l")
Fields = Fields("Hello World!")
HasPrefix = HasPrefix("Hello World!", "Hello")
HasSuffix = HasSuffix("Hello World!", "World!")
Join = Join({"Hello", "World"}, "_")
LastIndex = LastIndex("Hello! World!", "!")
Replace = Replace("Hello/World", "/","_", -1)
Split = Split("/Hello/World", "/")
Title = Title("hello world!")
ToLower = ToLower("HELLO WORLD!")
ToTitle = ToTitle("hello world!")
ToUpper = ToUpper("hello world!")
Trim = Trim(" hello world! ", " ")
TrimLeft = TrimLeft(" hello world! ", " ")
TrimPrefix = TrimPrefix("hello world! ", "hello")
TrimRight = TrimRight(" hello world! ", " ")
TrimSpace = TrimSpace(" hello world! ")
TrimSuffix = TrimSuffix(" hello world", "world")
hasHello = "Hello" in Fields("Hello World!")
MatchString = MatchString("^([A-Z]+[a-z]+|[A-Z]+|[a-z]+)$", "HTTPCODE")
FindAllString = FindAllString("[a-z]+|[A-Z][a-z]+|[A-Z]+", "httpCode", -1)
tabs = FindAllString("\\t", "\tXXX\t", -1)
)
!view IncorrectArgsToGoFunc(app <: sysl.App) -> int:
app -> (:
WrongNumberOfArgs = Contains("Hello World")
Contains = Contains("Hello World", 1)
Join = Join(["Hello", "World"], "_")
JoinInts = Join([1,2], "_")
)
!view Flatten(app <: sysl.App) -> int:
app -> (:
let n = app.endpoints -> <set of string>(ep:
name = ep.value.method + Join(ep.value.pathvars flatten(.name), "")
)
names = n flatten(.name)
let two = 2
listOfNumbers1 = [[1,2,3], [4,5,6]] flatten(. + two)
listOfNumbers2 = [{1,2,3}, {4,5,6}] flatten(. * two)
setOfNumbers1 = {{1,2,3}, {4,5,6}} flatten(. * two)
)
!view Where(app <: sysl.App) -> int:
app -> (:
greaterThanOne = {1,2,3} where(. > 1)
strOne = {"1","2","3"} where(. == "1")
let fieldNames = app.types -> <set of name>(type:
name = type.key
)
let requestStr = "Request"
Request = fieldNames where(.name == requestStr)
let listOfTypes = app.types -> <sequence of name>(type:
name = type.key
)
ListofNames = listOfTypes
RequestFromList = listOfTypes where (.name == requestStr)
NotObjectAliases = app.alias where(.key != "Object")
)
!view Links(app <: sysl.App) -> int:
app -> (:
let out = app.types -> <set of inner>(type:
inner = type.value.fields -> <set of link>(field:
Left = field.key
Right = JavaType(field.value).out
)
)
links = out flatten(.inner)
)
!view NullCheckAppAttrs(app <: sysl.App) -> int:
app -> (:
NotHasAttrName = .attrs.name == null
NotHasAttrFoo = .attrs.foo == null
hasAttrName = .attrs.name != null
hasAttrFoo = .attrs.foo != null
)
!view ListOfTypeNames(app <: sysl.App) -> sequence of types:
app.types -> (type:
name = type.key
)