1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Program used to test the `clone` method of the astbuilder tool
16 # Program use the nit interpreter to do his job. It take a nit file into parameter and replace the ast nodes by a clone.
17 # After replace it run a basic interpretation.
18 # When a new method `clone` is implemented you need to add a redefinition to test it.
19 # When the number of method `clone` will increase its more practical to define the nodes to not clone.
20 module test_astbuilder
25 redef class ModelBuilder
26 redef fun run_naive_interpreter
(mainmodule
: MModule, arguments
: Array[String])
28 var clone_visitor
= new CloneVisitor
29 for nmodule
in self.nmodules
do
30 clone_visitor
.enter_visit
(nmodule
)
36 private class CloneVisitor
41 # return when the node is an annotation to avoid the clonage
42 if node
isa AAnnotations then return
43 node
.do_cloneable
(self)
49 private fun do_cloneable
(v
: CloneVisitor)do end
51 # Create a new clone of `self`
54 var self_clone
= self.clone
55 replace_with
(self.clone
)
56 self_clone
.location
= location
57 #Call the `validate` method to set correctly the parents and the location
62 # Implement the `do_cloeable` method for each Node were the method `clone` is defined in the astbuilder module
64 redef class ASignature
65 redef fun do_cloneable
(v
)
71 redef class AImplicitSelfExpr
72 redef fun do_cloneable
(v
)
79 redef fun do_cloneable
(v
)
85 redef class AIntegerExpr
86 redef fun do_cloneable
(v
)
93 redef fun do_cloneable
(v
)
99 redef class AFloatExpr
100 redef fun do_cloneable
(v
)
106 redef class AFalseExpr
107 redef fun do_cloneable
(v
)
113 redef class ACharExpr
114 redef fun do_cloneable
(v
)