redef class ToolContext
var transform_phase: Phase = new TransformPhase(self, [typing_phase, auto_super_init_phase])
+
+ # --no-shortcut-range
+ var opt_no_shortcut_range: OptionBool = new OptionBool("Always insantiate a range and its iterator on 'for' loops", "--no-shortcut-range")
+
+ redef init
+ do
+ super
+ self.option_context.add_option(self.opt_no_shortcut_range)
+ end
end
private class TransformPhase
do
var val
- var v = new TransformVisitor(self, npropdef)
+ var v = new TransformVisitor(self, npropdef.mpropdef.as(not null))
v.enter_visit(npropdef)
val = new ASTValidationVisitor
super Visitor
var phase: TransformPhase
- var mmodule: MModule
- var mclassdef: MClassDef
+ var mmodule: MModule is noinit
+ var mclassdef: MClassDef is noinit
var mpropdef: MPropDef
- var builder: ASTBuilder
+ var builder: ASTBuilder is noinit
- init(phase: TransformPhase, npropdef: APropdef)
+ init
do
- self.phase = phase
- self.mpropdef = npropdef.mpropdef.as(not null)
self.mclassdef = mpropdef.mclassdef
self.mmodule = mclassdef.mmodule
self.builder = new ASTBuilder(mmodule, mpropdef.mclassdef.bound_mtype)
# Shortcut on explicit range
# Avoid the instantiation of the range and the iterator
- if self.variables.length == 1 and nexpr isa ARangeExpr then
+ if self.variables.length == 1 and nexpr isa ARangeExpr and not v.phase.toolcontext.opt_no_shortcut_range.value then
var variable = variables.first
nblock.add v.builder.make_var_assign(variable, nexpr.n_expr)
var to = nexpr.n_expr2
redef class AArrayExpr
# `[x,y]` is replaced with
#
- # var t = new Array[X].with_capacity(2)
- # t.add(x)
- # t.add(y)
- # t
+ # ~~~nitish
+ # var t = new Array[X].with_capacity(2)
+ # t.add(x)
+ # t.add(y)
+ # t
+ # ~~~
redef fun accept_transform_visitor(v)
do
var nblock = v.builder.make_block
redef class ASendReassignFormExpr
# `x.foo(y)+=z` is replaced with
#
- # x.foo(y) = x.foo(y) + z
+ # ~~~nitish
+ # x.foo(y) = x.foo(y) + z
+ # ~~~
#
# witch is, in reality:
#
- # x."foo="(y, x.foo(y)."+"(z))
+ # ~~~nitish
+ # x."foo="(y, x.foo(y)."+"(z))
+ # ~~~
redef fun accept_transform_visitor(v)
do
var nblock = v.builder.make_block