Class: Crokus::Visitor

Inherits:
Object
  • Object
show all
Includes:
Indent
Defined in:
lib/crokus/visitor.rb

Direct Known Subclasses

IRDumper, PrettyPrinter

Constant Summary

Constants included from Indent

Indent::INDENT

Instance Method Summary collapse

Methods included from Indent

#dedent, #indent, #say

Constructor Details

#initializeVisitor

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) ⇒ Object



13
14
15
# File 'lib/crokus/visitor.rb', line 13

def visit ast
  ast.accept(self)
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)
  aof.size.accept(self) 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)}
  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)
  arrow.rhs.accept(self)
  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)
  assign.op.accept(self)
  assign.rhs.accept(self)
  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)
  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)}
  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)
  case_.body.accept(self)
  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)
  cexpr.expr.accept(self)
  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)
  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

.….……stmts.….….……



134
135
136
137
138
# File 'lib/crokus/visitor.rb', line 134

def visitCommaStmt comma,args=nil
  lhs=comma.lhs.accept(self)
  rhs=comma.rhs.accept(self)
  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)
  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)
  decl.var.accept(self) if decl.var #case of struct decl only.
  decl.init.accept(self) 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)
  define.expr.accept(self)
  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)}
  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)
  while_.body.each{|stmt| stmt.accept(self)}
  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)}
  for_.cond.accept(self)
  for_.increment.accept(self)
  for_.body.accept(self)
  dedent
  for_
end

#visitFormalArg(formalArg, args = nil) ⇒ Object



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) if formalArg.name # e.g : main(void)
  formalArg.type.accept(self)
  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)
  fcall.args.each{|arg| arg.accept(self)}
  dedent
  fcall
end

#visitFunction(func, args = nil) ⇒ Object

.….…. end of types.….…..



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)
  func.name.accept(self)
  func.args.each{|arg| arg.accept(self)}
  func.body.accept(self)
  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)
  func.name.accept(self)
  func.args.each{|arg| arg.accept(self)}
  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)
  dedent
  goto
end

#visitIdent(ident, args = nil) ⇒ Object

.….…..expresions.….…..



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)
  if_.body.accept(self)
  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)
  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)
  index.rhs.accept(self)
  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)
  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)
  pointed.rhs.accept(self)
  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)
  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 #++i
  op =accu.op.accept(self)
  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 #++i
  op =accu.op.accept(self)
  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) 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)
  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)
  sw_.cases.each{|case_| case_.accept(self)}
  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)}
  type.name.accept(self)
  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)
  typdef.name.accept(self)
  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)
  while_.body.each{|stmt| stmt.accept(self)}
  dedent
  while_
end