-
Notifications
You must be signed in to change notification settings - Fork 11
/
xmodule.grace
156 lines (151 loc) · 4.91 KB
/
xmodule.grace
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
#pragma DefaultVisibility=public
import "io" as io
import "sys" as sys
import "mgcollections" as collections
import "util" as util
import "ast" as ast
def gctCache = collections.map.new
method parseGCT(path, filepath) {
if (gctCache.contains(path)) then {
return gctCache.get(path)
}
def data = collections.map.new
if (io.exists(filepath)) then {
def tfp = io.open(filepath, "r")
var key := ""
while {!tfp.eof} do {
def line = tfp.getline
if (line.at(1) != " ") then {
key := line.substringFrom(1)to(line.size-1)
data.put(key, collections.list.new)
} else {
data.get(key).push(line.substringFrom(2)to(line.size))
}
}
tfp.close
}
gctCache.put(path, data)
return data
}
method writeGCT(path, filepath, data) {
def fp = io.open(filepath, "w")
for (data) do {key->
fp.write "{key}:\n"
for (data.get(key)) do {v->
fp.write " {v}\n"
}
}
fp.close
gctCache.put(path, data)
}
method writeGCT(path, filepath)fromValues(values)modules(modules) {
writeGCT(path, filepath,
generateGCT(path)fromValues(values)modules(modules))
}
method gctAsString(data) {
var ret := ""
for (data) do {key->
ret := ret ++ "{key}:\n"
for (data.get(key)) do {v->
ret := ret ++ " {v}\n"
}
}
return ret
}
method generateGCT(path)fromValues(values)modules(modules) {
def methods = collections.list.new
def confidentials = collections.list.new
var theDialect := false
for (values) do { v->
if (v.kind == "vardec") then {
if (ast.isPublic(v)) then {
methods.push(v.name.value)
if (ast.isWritable(v)) then {
methods.push(v.name.value ++ ":=")
}
}
} elseif {v.kind == "method"} then {
if (ast.isPublic(v)) then {
methods.push(v.value.value)
} else {
confidentials.push(v.value.value)
}
} elseif {v.kind == "defdec"} then {
if (ast.isPublic(v)) then {
methods.push(v.name.value)
}
if (ast.findAnnotation(v, "parent")) then {
if (false != v.data) then {
for (v.data.elements) do {m->
methods.push(m)
}
}
}
} elseif {v.kind == "class"} then {
methods.push(v.name.value)
} elseif {v.kind == "type"} then {
methods.push(v.value)
} elseif {v.kind == "dialect"} then {
theDialect := v.value
}
}
def gct = collections.map.new
gct.put("modules", modules)
gct.put("path", collections.list.new(path))
gct.put("public", methods)
gct.put("confidential", confidentials)
if (false != theDialect) then {
gct.put("dialect", collections.list.new(theDialect))
}
def classes = collections.list.new
for (values) do {val->
if (val.kind == "class") then {
gct.put("constructors-of:{val.name.value}",
collections.list.new(val.constructorName.value))
gct.put("methods-of:{val.name.value}.{val.constructorName.value}",
val.data.elements)
classes.push(val.name.value)
}
if (val.kind == "defdec") then {
if (val.value.kind == "object") then {
def ob = val.value
var isClass := false
def obConstructors = collections.list.new
for (ob.value) do {nd->
if (nd.kind == "method") then {
if (nd.properties.contains("fresh")) then {
isClass := true
obConstructors.push(nd.value.value)
gct.put("methods-of:{val.name.value}.{nd.value.value}",
ob.data.getScope(nd.value.value).elements)
}
}
}
if (obConstructors.size > 0) then {
gct.put("constructors-of:{val.name.value}",
obConstructors)
classes.push(val.name.value)
}
}
}
}
gct.put("classes", classes)
def freshmeths = collections.list.new
for (values) do {val->
if (val.kind == "method") then {
if (val.properties.contains("fresh")) then {
freshmeths.push(val.value.value)
}
}
}
gct.put("fresh-methods", freshmeths)
for (values) do {val->
if (val.kind == "method") then {
if (val.properties.contains("fresh")) then {
gct.put("fresh:{val.value.value}",
val.properties.get("fresh").elements)
}
}
}
return gct
}