class Crokus::Transformer
here we transform an AST into another AST. we don't use Marshalling.
Attributes
code[RW]
Public Class Methods
new()
click to toggle source
# File lib/crokus/transformer.rb, line 13 def initialize @ind=-2 @verbose=true @verbose=false end
Public Instance Methods
transform(ast)
click to toggle source
# File lib/crokus/transformer.rb, line 19 def transform ast new_ast=ast.accept(self) end
Also aliased as: visit
visitAddressOf(ao,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 288 def visitAddressOf ao,args=nil e=ao.expr.accept(self) AddressOf.new(e) end
visitArrayOf(aof,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 69 def visitArrayOf aof,args=nil type=aof.type.accept(self) size=aof.size.accept(self) if aof.size ArrayOf.new(type,size) end
visitArrayOrStructInit(init,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 283 def visitArrayOrStructInit init,args=nil elements=init.elements.map{|e| e.accept(self)} ArrayOrStructInit.new(elements) end
visitArrow(arrow,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 271 def visitArrow arrow,args=nil lhs=arrow.lhs.accept(self) rhs=arrow.rhs.accept(self) Arrow.new(lhs,rhs) end
visitAssign(assign,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 129 def visitAssign assign,args=nil lhs=assign.lhs.accept(self) op=assign.op.accept(self) rhs=assign.rhs.accept(self) Assign.new(lhs,op,rhs) end
visitBinary(expr,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 246 def visitBinary expr,args=nil lhs=expr.lhs.accept(self) op=expr.op.accept(self) rhs=expr.rhs.accept(self) Binary.new(lhs,op,rhs) end
visitBody(body,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 309 def visitBody body,args=nil stmts=body.stmts.map{|stmt| stmt.accept(self)} Body.new(stmts) end
visitBreak(brk,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 203 def visitBreak brk,args=nil Break.new end
visitCase(case_,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 185 def visitCase case_,args=nil expr=case_.expr.accept(self) body=case_.body.accept(self) Case.new(expr,body) end
visitCastedExpr(cexpr,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 87 def visitCastedExpr cexpr,args=nil type=cexpr.type.accept(self) expr=cexpr.expr.accept(self) CastedExpr.new(type,expr) end
visitCasting(cast,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 81 def visitCasting cast,args=nil type=cast.type.accept(self) modifier=cast.modifier.accept(self) Casting.new(type,modifier) end
visitCharLit(lit,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 236 def visitCharLit lit,args=nil tok=lit.tok.accept(self) CharLit.new(tok) end
visitCommaStmt(comma,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 123 def visitCommaStmt comma,args=nil lhs=comma.lhs.accept(self) rhs=comma.rhs.accept(self) CommaStmt.new(lhs,rhs) end
visitCondExpr(ternary,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 259 def visitCondExpr ternary,args=nil cond=ternary.cond.accept(self) lhs=ternary.lhs.accept(self) rhs=ternary.rhs.accept(self) CondExpr.new(cond,lhs,rhs) end
visitContinue(cont,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 207 def visitContinue cont,args=nil Continue.new end
visitDecl(decl,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 30 def visitDecl decl,args=nil type=decl.type.accept(self) var=decl.var.accept(self) if decl.var init=decl.init.accept(self) if decl.init Decl.new(type,var,init) end
visitDefine(define,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 43 def visitDefine define,args=nil name=define.name.accept(self) args=define.args.map{|arg| arg.accept(self)} expr=define.expr.accept(self) Define.new(name,args,expr) end
visitDeref(deref,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 304 def visitDeref deref,args=nil e=deref.expr.accept(self) Deref.new(e) end
visitDesignUnit(du,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 25 def visitDesignUnit du,args=nil list=du.list.collect{|e| e.accept(self)} DesignUnit.new(list) end
visitDoWhile(while_,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 197 def visitDoWhile while_,args=nil cond=while_.cond.accept(self) body=while_.body.each{|stmt| stmt.accept(self)} DoWhile.new(cond,body) end
visitDotted(dotted,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 293 def visitDotted dotted,args=nil lhs=dotted.lhs.accept(self) rhs=dotted.rhs.accept(self) Dotted.new(lhs,rhs) end
visitElse(else_,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 174 def visitElse else_,args=nil body=else_.body.accept(self) Else.new(body) end
visitFloatLit(lit,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 241 def visitFloatLit lit,args=nil tok=lit.tok.accept(self) FloatLit.new(tok) end
visitFor(for_,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 154 def visitFor for_,args=nil init=for_.init.collect{|stmt| stmt.accept(self)} cond=for_.cond.accept(self) increment=for_.increment.accept(self) body=for_.body.accept(self) For.new(init,cond,increment,body) end
visitFormalArg(formalArg,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 110 def visitFormalArg formalArg,args=nil name=formalArg.name.accept(self) if formalArg.name # e.g : main(void) type=formalArg.type.accept(self) FormalArg.new(type,name) end
visitFunCall(fcall,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 148 def visitFunCall fcall,args=nil name=fcall.name.accept(self) args=fcall.args.collect{|arg| arg.accept(self)} FunCall.new(name,args) end
visitFunction(func,args=nil)
click to toggle source
.….…. end of types.….…..
# File lib/crokus/transformer.rb, line 95 def visitFunction func,args=nil type=func.type.accept(self) name=func.name.accept(self) args=func.args.collect{|arg| arg.accept(self)} body=func.body.accept(self) Function.new(name,type,args,body) end
visitFunctionProto(func,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 103 def visitFunctionProto func,args=nil type=func.type.accept(self) name=func.name.accept(self) args=func.args.collect{|arg| arg.accept(self)} FunctionProto.new(name,type,args) end
visitGoto(goto,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 216 def visitGoto goto,args=nil label=goto.label.accept(self) Goto.new(label) end
visitIdent(ident,args=nil)
click to toggle source
.….…..expresions.….…..
# File lib/crokus/transformer.rb, line 221 def visitIdent ident,args=nil tok=ident.tok.accept(self) Ident.new(tok) end
visitIf(if_,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 167 def visitIf if_,args=nil cond=if_.cond.accept(self) body=if_.body.accept(self) else_=if_.else.accept(self) if if_.else If.new(cond,body,else_) end
visitInclude(incl,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 37 def visitInclude incl,args=nil name=incl.name.accept(self) env=incl.env Include.new(name,env) end
visitIndexed(index,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 277 def visitIndexed index,args=nil lhs=index.lhs.accept(self) rhs=index.rhs.accept(self) Indexed.new(lhs,rhs) end
visitIntLit(lit,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 226 def visitIntLit lit,args=nil tok=lit.tok.accept(self) IntLit.new(tok) end
visitLabeledStmt(lstmt,args=nil)
click to toggle source
.….……stmts.….….……
# File lib/crokus/transformer.rb, line 117 def visitLabeledStmt lstmt,args=nil label=lstmt.label.accept(self) stmt=lstmt.stmt.accept(self) LabeledStmt.new(label,stmt) end
visitLabelledStmt(label,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 211 def visitLabelledStmt label,args=nil stmt=label.stmt.accept(self) LabelledStmt.new(stmt) end
visitParenth(par,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 266 def visitParenth par,args=nil e=par.expr.accept(self) Parenth.new(e) end
visitPointerTo(pto,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 64 def visitPointerTo pto,args=nil type=pto.type.accept(self) PointerTo.new(type) end
visitPostFixAccu(accu,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 136 def visitPostFixAccu accu,args=nil lhs=accu.lhs.accept(self) if accu.lhs #++i op=accu.op.accept(self) PostFixAccu.new(lhs,op) end
visitPreFixAccu(accu,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 142 def visitPreFixAccu accu,args=nil lhs=accu.lhs.accept(self) if accu.lhs #++i op=accu.op.accept(self) PreFixAccu.new(lhs,op) end
visitReturn(ret,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 162 def visitReturn ret,args=nil expr=ret.expr.accept(self) if ret.expr Return.new(expr) end
visitSizeof(sizeof,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 299 def visitSizeof sizeof,args=nil type=sizeof.type.accept(self) Sizeof.new(type) end
visitStrLit(lit,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 231 def visitStrLit lit,args=nil tok=lit.tok.accept(self) StrLit.new(tok) end
visitStruct(struct,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 75 def visitStruct struct,args=nil name=struct.name.accept(self) if struct.name decls=struct.decls.collect{|decl| decl.accept(self)} Struct.new(name,decls) end
visitSwitch(sw_,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 179 def visitSwitch sw_,args=nil expr =sw_.expr.accept(self) cases=sw_.cases.collect{|case_| case_.accept(self)} Switch.new(expr,cases) end
visitToken(tok,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 314 def visitToken tok,args=nil Token.new [tok.kind,tok.val,tok.pos] end
visitType(type,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 56 def visitType type,args=nil precisions=type.precisions.collect{|prc| prc.accept(self)} name=type.name.accept(self) ret=Type.new(name) ret.precisions=precisions ret end
visitTypedef(typdef,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 50 def visitTypedef typdef,args=nil type=typdef.type.accept(self) name=typdef.name.accept(self) Typedef.new(type,name) end
visitUnary(unary,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 253 def visitUnary unary,args=nil op=unary.op.accept(self) rhs=unary.rhs.accept(self) Unary.new(op,rhs,unary.postfix) end
visitWhile(while_,args=nil)
click to toggle source
# File lib/crokus/transformer.rb, line 191 def visitWhile while_,args=nil cond=while_.cond.accept(self) body=while_.body.accept(self) While.new(cond,body) end