clone
method of the astbuilder toolProgram use the nit interpreter to do his job. It take a nit file into parameter and replace the ast nodes by a clone.
After replace it run a basic interpretation.
When a new method clone
is implemented you need to add a redefinition to test it.
When the number of method clone
will increase its more practical to define the nodes to not clone.
nitc :: CloneVisitor
nitc :: test_astbuilder $ AImplicitSelfExpr
When there is no explicit receiver,self
is implicit
nitc :: test_astbuilder $ ASignature
A signature in a method definition. eg(x,y:X,z:Z):T
nitc :: test_astbuilder $ ModelBuilder
A model builder knows how to load nit source files and build the associated modelnitc :: test_astbuilder $ AImplicitSelfExpr
When there is no explicit receiver,self
is implicit
nitc :: test_astbuilder $ ASignature
A signature in a method definition. eg(x,y:X,z:Z):T
nitc :: test_astbuilder $ ModelBuilder
A model builder knows how to load nit source files and build the associated modelnitc :: actors_generation_phase
Generate a support module for each module that contain a class annotated withis actor
nitc :: actors_injection_phase
Injects model for the classes annotated with "is actor" sonitc :: astbuilder
Instantiation and transformation of semantic nodes in the AST of expressions and statementscflags
and ldflags
to specify
extra_java_files
to compile extra java files
nitc :: i18n_phase
Basic support of internationalization through the generation of id-to-string tablesSerializable::inspect
to show more useful information
nitc :: modelbuilder
more_collections :: more_collections
Highly specific, but useful, collections-related classes.threaded
annotation
nitc :: serialization_code_gen_phase
Phase generating methods (code) to serialize Nit objectsserialization :: serialization_core
Abstract services to serialize Nit objects to different formatsnitc :: serialization_model_phase
Phase generating methods (model-only) to serialize Nit objectsserialize_to_json
and JsonSerializer
nitc :: toolcontext
Common command-line tool infrastructure than handle options and error messagescore :: union_find
union–find algorithm using an efficient disjoint-set data structure
# Program used to test the `clone` method of the astbuilder tool
# Program use the nit interpreter to do his job. It take a nit file into parameter and replace the ast nodes by a clone.
# After replace it run a basic interpretation.
# When a new method `clone` is implemented you need to add a redefinition to test it.
# When the number of method `clone` will increase its more practical to define the nodes to not clone.
module test_astbuilder
import nit
import astbuilder
redef class ModelBuilder
redef fun run_naive_interpreter(mainmodule: MModule, arguments: Array[String])
do
var clone_visitor = new CloneVisitor
for nmodule in self.nmodules do
clone_visitor.enter_visit(nmodule)
end
super
end
end
private class CloneVisitor
super Visitor
redef fun visit(node)
do
# return when the node is an annotation to avoid the clonage
if node isa AAnnotations then return
node.do_cloneable(self)
node.visit_all(self)
end
end
redef class ANode
private fun do_cloneable(v: CloneVisitor)do end
# Create a new clone of `self`
fun replace_clone
do
var self_clone = self.clone
replace_with(self.clone)
self_clone.location = location
#Call the `validate` method to set correctly the parents and the location
self_clone.validate
end
end
# Implement the `do_cloeable` method for each Node were the method `clone` is defined in the astbuilder module
redef class ASignature
redef fun do_cloneable(v)
do
replace_clone
end
end
redef class AImplicitSelfExpr
redef fun do_cloneable(v)
do
replace_clone
end
end
redef class ASelfExpr
redef fun do_cloneable(v)
do
replace_clone
end
end
redef class AIntegerExpr
redef fun do_cloneable(v)
do
replace_clone
end
end
redef class ATrueExpr
redef fun do_cloneable(v)
do
replace_clone
end
end
redef class AFloatExpr
redef fun do_cloneable(v)
do
replace_clone
end
end
redef class AFalseExpr
redef fun do_cloneable(v)
do
replace_clone
end
end
redef class ACharExpr
redef fun do_cloneable(v)
do
replace_clone
end
end
src/test_astbuilder.nit:15,1--118,3