Class: Crokus::Visitor
- Inherits:
-
Object
show all
- Includes:
- Indent
- Defined in:
- lib/crokus/visitor.rb
Constant Summary
Constants included
from Indent
Indent::INDENT
Instance Method Summary
collapse
-
#initialize ⇒ Visitor
constructor
A new instance of Visitor.
-
#visit(ast, args = nil) ⇒ Object
-
#visitAddressOf(ao, args = nil) ⇒ Object
-
#visitArrayOf(aof, args = nil) ⇒ Object
-
#visitArrayOrStructInit(init, args = nil) ⇒ Object
-
#visitArrow(arrow, args = nil) ⇒ Object
-
#visitAssign(assign, args = nil) ⇒ Object
-
#visitBinary(expr, args = nil) ⇒ Object
-
#visitBody(body, args = nil) ⇒ Object
-
#visitBreak(brk, args = nil) ⇒ Object
-
#visitCase(case_, args = nil) ⇒ Object
-
#visitCastedExpr(cexpr, args = nil) ⇒ Object
-
#visitCasting(cast, args = nil) ⇒ Object
-
#visitCharLit(lit, args = nil) ⇒ Object
-
#visitCommaStmt(comma, args = nil) ⇒ Object
-
#visitCondExpr(cexpr, args = nil) ⇒ Object
-
#visitContinue(brk, args = nil) ⇒ Object
-
#visitDecl(decl, args = nil) ⇒ Object
-
#visitDefine(define, args = nil) ⇒ Object
-
#visitDeref(deref, args = nil) ⇒ Object
-
#visitDesignUnit(du, args = nil) ⇒ Object
-
#visitDoWhile(while_, args = nil) ⇒ Object
-
#visitFloatLit(lit, args = nil) ⇒ Object
-
#visitFor(for_, args = nil) ⇒ Object
-
#visitFormalArg(formalArg, args = nil) ⇒ Object
-
#visitFunCall(fcall, args = nil) ⇒ Object
-
#visitFunction(func, args = nil) ⇒ Object
-
#visitFunctionProto(func, args = nil) ⇒ Object
-
#visitGoto(goto, args = nil) ⇒ Object
-
#visitIdent(ident, args = nil) ⇒ Object
-
#visitIf(if_, args = nil) ⇒ Object
-
#visitInclude(include, args = nil) ⇒ Object
-
#visitIndexed(index, args = nil) ⇒ Object
-
#visitIntLit(lit, args = nil) ⇒ Object
-
#visitLabelledStmt(label, args = nil) ⇒ Object
-
#visitParenth(par, args = nil) ⇒ Object
-
#visitPointed(pointed, args = nil) ⇒ Object
-
#visitPointerTo(pto, args = nil) ⇒ Object
-
#visitPostFixAccu(accu, args = nil) ⇒ Object
-
#visitPreFixAccu(accu, args = nil) ⇒ Object
-
#visitReturn(ret, args = nil) ⇒ Object
-
#visitSizeof(sizeof, args = nil) ⇒ Object
-
#visitStrLit(lit, args = nil) ⇒ Object
-
#visitStruct(struct, args = nil) ⇒ Object
-
#visitSwitch(sw_, args = nil) ⇒ Object
-
#visitToken(tok, args = nil) ⇒ Object
-
#visitType(type, args = nil) ⇒ Object
-
#visitTypedef(typdef, args = nil) ⇒ Object
-
#visitUnary(unary, args = nil) ⇒ Object
-
#visitWhile(while_, args = nil) ⇒ Object
Methods included from Indent
#dedent, #indent, #say
Constructor Details
Returns a new instance of Visitor.
7
8
9
10
11
|
# File 'lib/crokus/visitor.rb', line 7
def initialize
@ind=-2
@verbose=true
@verbose=false
end
|
Instance Method Details
#visit(ast, args = nil) ⇒ Object
13
14
15
|
# File 'lib/crokus/visitor.rb', line 13
def visit ast,args=nil
ast.accept(self,args)
end
|
#visitAddressOf(ao, args = nil) ⇒ Object
320
321
322
323
|
# File 'lib/crokus/visitor.rb', line 320
def visitAddressOf ao,args=nil
indent "AddressOf"
dedent
end
|
#visitArrayOf(aof, args = nil) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/crokus/visitor.rb', line 75
def visitArrayOf aof,args=nil
indent "ArrayOf"
aof.type.accept(self,args)
aof.size.accept(self,args) if aof.size
dedent
aof
end
|
#visitArrayOrStructInit(init, args = nil) ⇒ Object
314
315
316
317
318
|
# File 'lib/crokus/visitor.rb', line 314
def visitArrayOrStructInit init,args=nil
indent "ArrayOrStructInit"
init.elements.each{|e| e.accept(self,args)}
dedent
end
|
#visitArrow(arrow, args = nil) ⇒ Object
300
301
302
303
304
305
|
# File 'lib/crokus/visitor.rb', line 300
def visitArrow arrow,args=nil
indent "arrow"
arrow.lhs.accept(self,args)
arrow.rhs.accept(self,args)
dedent
end
|
#visitAssign(assign, args = nil) ⇒ Object
140
141
142
143
144
145
|
# File 'lib/crokus/visitor.rb', line 140
def visitAssign assign,args=nil
assign.lhs.accept(self,args)
assign.op.accept(self,args)
assign.rhs.accept(self,args)
assign
end
|
#visitBinary(expr, args = nil) ⇒ Object
278
279
280
281
282
283
284
285
|
# File 'lib/crokus/visitor.rb', line 278
def visitBinary expr,args=nil
indent "Binary"
expr.lhs.accept(self,args)
expr.op.accept(self,args)
expr.rhs.accept(self,args)
dedent
expr
end
|
#visitBody(body, args = nil) ⇒ Object
344
345
346
347
348
|
# File 'lib/crokus/visitor.rb', line 344
def visitBody body,args=nil
indent "body"
body.stmts.each{|stmt| stmt.accept(self,args)}
dedent
end
|
#visitBreak(brk, args = nil) ⇒ Object
224
225
226
227
228
|
# File 'lib/crokus/visitor.rb', line 224
def visitBreak brk,args=nil
indent "Break"
dedent
brk
end
|
#visitCase(case_, args = nil) ⇒ Object
200
201
202
203
204
205
206
|
# File 'lib/crokus/visitor.rb', line 200
def visitCase case_,args=nil
indent "Case"
case_.expr.accept(self,args)
case_.body.accept(self,args)
dedent
case_
end
|
#visitCastedExpr(cexpr, args = nil) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/crokus/visitor.rb', line 96
def visitCastedExpr cexpr,args=nil
indent "CastedExpr"
cexpr.type.accept(self,args)
cexpr.expr.accept(self,args)
dedent
cexpr
end
|
#visitCasting(cast, args = nil) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/crokus/visitor.rb', line 89
def visitCasting cast,args=nil
indent "Casting"
cast.type.accept(self,args)
dedent
cast
end
|
#visitCharLit(lit, args = nil) ⇒ Object
261
262
263
|
# File 'lib/crokus/visitor.rb', line 261
def visitCharLit lit,args=nil
lit
end
|
#visitCommaStmt(comma, args = nil) ⇒ Object
134
135
136
137
138
|
# File 'lib/crokus/visitor.rb', line 134
def visitCommaStmt comma,args=nil
lhs=comma.lhs.accept(self,args)
rhs=comma.rhs.accept(self,args)
comma
end
|
#visitCondExpr(cexpr, args = nil) ⇒ Object
269
270
271
272
273
274
275
276
|
# File 'lib/crokus/visitor.rb', line 269
def visitCondExpr cexpr,args=nil
indent "condexpr"
cexpr.cond.accept(self,args)
cexpr.lhs.accept(self,args)
cexpr.rhs.accept(self,args)
dedent
cexpr
end
|
#visitContinue(brk, args = nil) ⇒ Object
230
231
232
233
234
|
# File 'lib/crokus/visitor.rb', line 230
def visitContinue brk,args=nil
indent "Continue"
dedent
brk
end
|
#visitDecl(decl, args = nil) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/crokus/visitor.rb', line 28
def visitDecl decl,args=nil
indent "Decl"
decl.type.accept(self,args)
decl.var.accept(self,args) if decl.var
decl.init.accept(self,args) if decl.init
dedent
decl
end
|
#visitDefine(define, args = nil) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/crokus/visitor.rb', line 44
def visitDefine define,args=nil
indent "Define"
define.name.accept(self,args)
define.expr.accept(self,args)
dedent
define
end
|
#visitDeref(deref, args = nil) ⇒ Object
339
340
341
342
|
# File 'lib/crokus/visitor.rb', line 339
def visitDeref deref,args=nil
indent "Deref"
dedent
end
|
#visitDesignUnit(du, args = nil) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/crokus/visitor.rb', line 21
def visitDesignUnit du,args=nil
indent "DesignUnit"
du.list.each{|e| e.accept(self,args)}
dedent
du
end
|
#visitDoWhile(while_, args = nil) ⇒ Object
216
217
218
219
220
221
222
|
# File 'lib/crokus/visitor.rb', line 216
def visitDoWhile while_,args=nil
indent "DoWhile"
while_.cond.accept(self,args)
while_.body.each{|stmt| stmt.accept(self,args)}
dedent
while_
end
|
#visitFloatLit(lit, args = nil) ⇒ Object
265
266
267
|
# File 'lib/crokus/visitor.rb', line 265
def visitFloatLit lit,args=nil
lit
end
|
#visitFor(for_, args = nil) ⇒ Object
167
168
169
170
171
172
173
174
175
|
# File 'lib/crokus/visitor.rb', line 167
def visitFor for_,args=nil
indent "For"
for_.init.each{|stmt| stmt.accept(self,args)}
for_.cond.accept(self,args)
for_.increment.accept(self,args)
for_.body.accept(self,args)
dedent
for_
end
|
125
126
127
128
129
130
131
|
# File 'lib/crokus/visitor.rb', line 125
def visitFormalArg formalArg,args=nil
indent "FormalArg"
formalArg.name.accept(self,args) if formalArg.name
formalArg.type.accept(self,args)
dedent
formalArg
end
|
#visitFunCall(fcall, args = nil) ⇒ Object
159
160
161
162
163
164
165
|
# File 'lib/crokus/visitor.rb', line 159
def visitFunCall fcall,args=nil
indent "FunCall"
fcall.name.accept(self,args)
fcall.args.each{|arg| arg.accept(self,args)}
dedent
fcall
end
|
#visitFunction(func, args = nil) ⇒ Object
106
107
108
109
110
111
112
113
114
|
# File 'lib/crokus/visitor.rb', line 106
def visitFunction func,args=nil
indent "Function"
func.type.accept(self,args)
func.name.accept(self,args)
func.args.each{|arg| arg.accept(self,args)}
func.body.accept(self,args)
dedent
func
end
|
#visitFunctionProto(func, args = nil) ⇒ Object
116
117
118
119
120
121
122
123
|
# File 'lib/crokus/visitor.rb', line 116
def visitFunctionProto func,args=nil
indent "FunctionProto"
func.type.accept(self,args)
func.name.accept(self,args)
func.args.each{|arg| arg.accept(self,args)}
dedent
func
end
|
#visitGoto(goto, args = nil) ⇒ Object
242
243
244
245
246
247
|
# File 'lib/crokus/visitor.rb', line 242
def visitGoto goto,args=nil
indent "Goto"
goto.label.accept(self,args)
dedent
goto
end
|
#visitIdent(ident, args = nil) ⇒ Object
249
250
251
|
# File 'lib/crokus/visitor.rb', line 249
def visitIdent ident,args=nil
ident
end
|
#visitIf(if_, args = nil) ⇒ Object
184
185
186
187
188
189
190
|
# File 'lib/crokus/visitor.rb', line 184
def visitIf if_,args=nil
indent "If"
if_.cond.accept(self,args)
if_.body.accept(self,args)
dedent
if_
end
|
#visitInclude(include, args = nil) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/crokus/visitor.rb', line 37
def visitInclude include,args=nil
indent "Include"
include.name.accept(self,args)
dedent
include
end
|
#visitIndexed(index, args = nil) ⇒ Object
307
308
309
310
311
312
|
# File 'lib/crokus/visitor.rb', line 307
def visitIndexed index,args=nil
indent "Index"
index.lhs.accept(self,args)
index.rhs.accept(self,args)
dedent
end
|
#visitIntLit(lit, args = nil) ⇒ Object
253
254
255
|
# File 'lib/crokus/visitor.rb', line 253
def visitIntLit lit,args=nil
lit
end
|
#visitLabelledStmt(label, args = nil) ⇒ Object
236
237
238
239
240
|
# File 'lib/crokus/visitor.rb', line 236
def visitLabelledStmt label,args=nil
indent "LabelledStmt"
dedent
label
end
|
#visitParenth(par, args = nil) ⇒ Object
293
294
295
296
297
298
|
# File 'lib/crokus/visitor.rb', line 293
def visitParenth par,args=nil
indent "Parenth"
par.expr.accept(self,args)
dedent
par
end
|
#visitPointed(pointed, args = nil) ⇒ Object
325
326
327
328
329
330
|
# File 'lib/crokus/visitor.rb', line 325
def visitPointed pointed,args=nil
indent "Pointed"
pointed.lhs.accept(self,args)
pointed.rhs.accept(self,args)
dedent
end
|
#visitPointerTo(pto, args = nil) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/crokus/visitor.rb', line 68
def visitPointerTo pto,args=nil
indent "PointerTo"
pto.type.accept(self,args)
dedent
pto
end
|
#visitPostFixAccu(accu, args = nil) ⇒ Object
147
148
149
150
151
|
# File 'lib/crokus/visitor.rb', line 147
def visitPostFixAccu accu,args=nil
lhs=accu.lhs.accept(self,args) if accu.lhs
op =accu.op.accept(self,args)
accu
end
|
#visitPreFixAccu(accu, args = nil) ⇒ Object
153
154
155
156
157
|
# File 'lib/crokus/visitor.rb', line 153
def visitPreFixAccu accu,args=nil
lhs=accu.lhs.accept(self,args) if accu.lhs
op =accu.op.accept(self,args)
accu
end
|
#visitReturn(ret, args = nil) ⇒ Object
177
178
179
180
181
182
|
# File 'lib/crokus/visitor.rb', line 177
def visitReturn ret,args=nil
indent "Return"
ret.expr.accept(self,args) if ret.expr
dedent
ret
end
|
#visitSizeof(sizeof, args = nil) ⇒ Object
332
333
334
335
336
337
|
# File 'lib/crokus/visitor.rb', line 332
def visitSizeof sizeof,args=nil
indent "Sizeof"
sizeof.type.accept(self,args)
dedent
sizeof
end
|
#visitStrLit(lit, args = nil) ⇒ Object
257
258
259
|
# File 'lib/crokus/visitor.rb', line 257
def visitStrLit lit,args=nil
lit
end
|
#visitStruct(struct, args = nil) ⇒ Object
83
84
85
86
87
|
# File 'lib/crokus/visitor.rb', line 83
def visitStruct struct,args=nil
indent "Struct"
dedent
struct
end
|
#visitSwitch(sw_, args = nil) ⇒ Object
192
193
194
195
196
197
198
|
# File 'lib/crokus/visitor.rb', line 192
def visitSwitch sw_,args=nil
indent "Switch"
sw_.expr.accept(self,args)
sw_.cases.each{|case_| case_.accept(self,args)}
dedent
sw_
end
|
#visitToken(tok, args = nil) ⇒ Object
17
18
19
|
# File 'lib/crokus/visitor.rb', line 17
def visitToken tok, args=nil
tok
end
|
#visitType(type, args = nil) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/crokus/visitor.rb', line 60
def visitType type,args=nil
indent "Type"
type.precisions.each{|precision| precision.accept(self,args)}
type.name.accept(self,args)
dedent
type
end
|
#visitTypedef(typdef, args = nil) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/crokus/visitor.rb', line 52
def visitTypedef typdef,args=nil
indent "Typdef"
typdef.type.accept(self,args)
typdef.name.accept(self,args)
dedent
typdef
end
|
#visitUnary(unary, args = nil) ⇒ Object
287
288
289
290
291
|
# File 'lib/crokus/visitor.rb', line 287
def visitUnary unary,args=nil
indent "Unary"
dedent
unary
end
|
#visitWhile(while_, args = nil) ⇒ Object
208
209
210
211
212
213
214
|
# File 'lib/crokus/visitor.rb', line 208
def visitWhile while_,args=nil
indent "While"
while_.cond.accept(self,args)
while_.body.each{|stmt| stmt.accept(self,args)}
dedent
while_
end
|