Class: WrapCall
- Inherits:
-
Parser::TreeRewriter
- Object
- Parser::AST::Processor
- Parser::TreeRewriter
- WrapCall
- Defined in:
- lib/rdl/typecheck.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(offset) ⇒ WrapCall
constructor
A new instance of WrapCall.
- #on_and_asgn(node) ⇒ Object
- #on_op_asgn(node) ⇒ Object
- #on_or_asgn(node) ⇒ Object
- #on_send(node) ⇒ Object
Methods inherited from Parser::TreeRewriter
Constructor Details
#initialize(offset) ⇒ WrapCall
Returns a new instance of WrapCall.
2310 2311 2312 |
# File 'lib/rdl/typecheck.rb', line 2310 def initialize(offset) @offset = offset end |
Class Method Details
.rewrite(ast) ⇒ Object
2314 2315 2316 2317 2318 2319 |
# File 'lib/rdl/typecheck.rb', line 2314 def self.rewrite(ast) rewriter = WrapCall.new(ast.location.expression.begin_pos) buffer = Parser::Source::Buffer.new("(ast)") buffer.source = ast.location.expression.source rewriter.rewrite(buffer, ast) end |
Instance Method Details
#on_and_asgn(node) ⇒ Object
2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 |
# File 'lib/rdl/typecheck.rb', line 2282 def on_and_asgn(node) if node.children[0].type == :send rec_ast = node.children[0].children[0] rec_code = WrapCall.rewrite(rec_ast)+"." if rec_ast.is_a?(AST::Node) rec_meth_ast = node.children[0] rec_meth_code = WrapCall.rewrite(rec_meth_ast) elargs_ast = node.children[0].children[2] elargs_code = WrapCall.rewrite(elargs_ast) rhs_ast = node.children[1] rhs_code = WrapCall.rewrite(rhs_ast) mutation_meth = node.children[0].children[1].to_s + "=" if RDL::Globals.comp_type_map[node.object_id] align_replace(node.location.expression, @offset, "#{rec_code}__rdl_dyn_type_check(:#{mutation_meth}, #{node.object_id}, #{elargs_code}, #{rec_meth_code} && #{rhs_code})") end else lhs = node.location.name.source rhs_ast = node.children[1] rhs_code = WrapCall.rewrite(rhs_ast) align_replace(node.location.expression, @offset, "#{lhs} = #{lhs} && #{rhs_code}") end end |
#on_op_asgn(node) ⇒ Object
2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 |
# File 'lib/rdl/typecheck.rb', line 2218 def on_op_asgn(node) if node.children[0].type == :send rec_ast = node.children[0].children[0] rec_code = WrapCall.rewrite(rec_ast) + "." if rec_ast.is_a?(AST::Node) rec_meth_ast = node.children[0] rec_meth_code = WrapCall.rewrite(rec_meth_ast) elargs_ast = node.children[0].children[2] elargs_code = WrapCall.rewrite(elargs_ast) rhs_ast = node.children[2] rhs_code = WrapCall.rewrite(rhs_ast) op_meth = node.children[1] mutation_meth = node.children[0].children[1].to_s + "=" if RDL::Globals.comp_type_map[node.object_id] op_code = "#{rec_meth_code}.__rdl_dyn_type_check(:#{op_meth}, #{node.object_id}, #{rhs_code})" else op_code = "#{rec_meth_code}.send(:#{op_meth}, #{rhs_code})" end if RDL::Globals.comp_type_map[node.object_id.object_id] align_replace(node.location.expression, @offset, "#{rec_code}__rdl_dyn_type_check(:#{mutation_meth}, #{node.object_id.object_id}, #{elargs_code}, #{op_code})") end else lhs = node.location.name.source meth = node.children[1] rhs_ast = node.children[2] rhs_code = WrapCall.rewrite(rhs_ast) if RDL::Globals.comp_type_map[node.object_id] align_replace(node.location.expression, @offset, "#{lhs} = #{lhs}.__rdl_dyn_type_check(:#{meth}, #{node.object_id}, #{rhs_code})") end end end |
#on_or_asgn(node) ⇒ Object
2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 |
# File 'lib/rdl/typecheck.rb', line 2255 def on_or_asgn(node) if node.children[0].type == :send rec_ast = node.children[0].children[0] rec_code = WrapCall.rewrite(rec_ast)+"." if rec_ast.is_a?(AST::Node) rec_meth_ast = node.children[0] rec_meth_code = WrapCall.rewrite(rec_meth_ast) elargs_ast = node.children[0].children[2] elargs_code = WrapCall.rewrite(elargs_ast) rhs_ast = node.children[1] rhs_code = WrapCall.rewrite(rhs_ast) mutation_meth = node.children[0].children[1].to_s + "=" if RDL::Globals.comp_type_map[node.object_id] align_replace(node.location.expression, @offset, "#{rec_code}__rdl_dyn_type_check(:#{mutation_meth}, #{node.object_id}, #{elargs_code}, #{rec_meth_code} || #{rhs_code})") end else lhs = node.location.name.source rhs_ast = node.children[1] rhs_code = WrapCall.rewrite(rhs_ast) align_replace(node.location.expression, @offset, "#{lhs} = #{lhs} || #{rhs_code}") end end |
#on_send(node) ⇒ Object
2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 |
# File 'lib/rdl/typecheck.rb', line 2206 def on_send(node) rec_ast = node.children[0] rec_code = WrapCall.rewrite(rec_ast)+"." if rec_ast.is_a?(AST::Node) ## receiver is nil, or it gets rewritten args_code = node.children[2..-1].map { |n| WrapCall.rewrite(n) if n.is_a?(AST::Node) } args_code = args_code.empty? ? nil : ","+args_code.join(",") ## no args, or args get rewritten unless node.children[1] == :__rdl_dyn_type_check ## I don't believe this check is necessary, but at one point I had this issue so I'm leaving it in if RDL::Globals.comp_type_map[node.object_id] ## Only do this if a call is associated with a type in the map. Otherwise, it may be a call to a non-dependently typed method. align_replace(node.location.expression, @offset, "#{rec_code}__rdl_dyn_type_check(:#{node.children[1]}, #{node.object_id} #{args_code})") end end end |