-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpr-struct.lua
More file actions
96 lines (90 loc) · 1.78 KB
/
Copy pathcpr-struct.lua
File metadata and controls
96 lines (90 loc) · 1.78 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
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
StructDeclarator = Class("StructDeclarator", {
cpr = function(self, wt, indent)
--wt:add(indent)
self.ctype:cpr(wt, indent, self)
if self.width then
wt:add(" : ")
self.width:cpr(wt, indent)
end
end,
},
function(S, self)
--idump(self)
if self.width then
disown(self.width)
end
disown(self.ctype)
return self
end)
StructDeclaration = Class("StructDeclaration", {
cpr = function(self, wt, indent)
if not self.anon then
wt:add(indent)
self.ctype:cpr(wt, indent, self)
wt:add(" ")
for k, v in ipairs(self) do
if k > 1 then
wt:add(", ")
end
v:cpr(wt, indent)
end
wt:add(";\n")
else
wt:add(indent)
self.anon:cpr(wt, indent)
wt:add(";\n")
end
end,
},
function(S, self)
--idump(self)
for k, v in ipairs(self) do
disown(v)
end
if self.anon then
disown(self.anon)
end
--disown(self.ctype)
return self
end)
Struct = Class("Struct", {
cpr = function(self, wt, indent)
if self.ref then
local ref = self.ref
if ref.union then
wt:add("union ", ref.cid or ref.id)
else
wt:add("struct ", ref.cid or ref.id)
end
else
if self.union then
wt:add("union ")
else
wt:add("struct ")
end
if not self.anon then
wt:add(self.cid or self.id)
wt:add(" ")
elseif self.id then
wt:add("/* ")
wt:add(self.cid or self.id)
wt:add(" */ ")
end
wt:add("{\n")
do
local indent2 = indent .. " "
for k, v in ipairs(self) do
v:cpr(wt, indent2)
end
end
wt:add(indent, "}")
end
end,
},
function(S, self)
--idump(self)
for k, v in ipairs(self) do
disown(v)
end
return self
end)