nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: parse_examples: minor fixes
[nit.git]
/
src
/
phase.nit
diff --git
a/src/phase.nit
b/src/phase.nit
index
55853a5
..
2a9d7b8
100644
(file)
--- a/
src/phase.nit
+++ b/
src/phase.nit
@@
-21,17
+21,17
@@
import poset
redef class ToolContext
# The various registered phases to performs
redef class ToolContext
# The various registered phases to performs
- # The order in the poset is the dependance of phases
+ # The order in the poset is the dependence of phases
#
# While you can directly modify the poset (nodes and edges),
# it is often simpler to use the constructor in `Phase`
var phases = new POSet[Phase]
# --disable-phase
#
# While you can directly modify the poset (nodes and edges),
# it is often simpler to use the constructor in `Phase`
var phases = new POSet[Phase]
# --disable-phase
- var opt_disable_phase = new OptionArray("DEBUG: Disable a specific phase; use `list` to get the list.", "--disable-phase")
+ var opt_disable_phase = new OptionArray("Disable a specific phase; use `list` to get the list (debug)", "--disable-phase")
- # --disable-phase
- var opt_sloppy = new OptionBool("DEBUG: force lazy semantic analysis of the source-code", "--sloppy")
+ # --sloppy
+ var opt_sloppy = new OptionBool("Force lazy semantic analysis of the source-code (debug)", "--sloppy")
redef init
do
redef init
do
@@
-69,7
+69,7
@@
redef class ToolContext
if opt_sloppy.value then semantize_is_lazy = true
end
if opt_sloppy.value then semantize_is_lazy = true
end
- # The list of phases in the order to run them
+ # The list of registered phases in the application order.
var phases_list: Sequence[Phase] is lazy do
var phases = self.phases.to_a
self.phases.sort(phases)
var phases_list: Sequence[Phase] is lazy do
var phases = self.phases.to_a
self.phases.sort(phases)
@@
-86,6
+86,11
@@
redef class ToolContext
# Set of already analyzed modules.
private var phased_modules = new HashSet[AModule]
# Set of already analyzed modules.
private var phased_modules = new HashSet[AModule]
+ # List of module to process according to `run_phases`
+ #
+ # This allow some new modules to be found and added while analysing the code.
+ var todo_nmodules: Sequence[AModule]
+
# Run all registered phases on a set of modules
fun run_phases(nmodules: Collection[AModule])
do
# Run all registered phases on a set of modules
fun run_phases(nmodules: Collection[AModule])
do
@@
-99,7
+104,11
@@
redef class ToolContext
self.info(" registered phases: {phase}", 2)
end
self.info(" registered phases: {phase}", 2)
end
- for nmodule in nmodules do
+ var todo_nmodules = nmodules.to_a
+ self.todo_nmodules = todo_nmodules
+
+ while not todo_nmodules.is_empty do
+ var nmodule = todo_nmodules.shift
if phased_modules.has(nmodule) then continue
phased_modules.add nmodule
if phased_modules.has(nmodule) then continue
phased_modules.add nmodule
@@
-110,13
+119,11
@@
redef class ToolContext
for phase in phases do
if phase.disabled then continue
for phase in phases do
if phase.disabled then continue
- self.info(" phase: {phase}", 3)
assert phase.toolcontext == self
var errcount = self.error_count
phase.process_nmodule(nmodule)
if errcount != self.error_count then
self.check_errors
assert phase.toolcontext == self
var errcount = self.error_count
phase.process_nmodule(nmodule)
if errcount != self.error_count then
self.check_errors
- break
end
errcount = self.error_count
for nclassdef in nmodule.n_classdefs do
end
errcount = self.error_count
for nclassdef in nmodule.n_classdefs do
@@
-129,15
+136,17
@@
redef class ToolContext
end
if errcount != self.error_count then
self.check_errors
end
if errcount != self.error_count then
self.check_errors
- break
end
for na in vannot.annotations do
end
for na in vannot.annotations do
- phase.process_annotated_node(na.parent.parent.as(not null), na)
+ var p = na.parent
+ if p isa AAnnotations then p = p.parent
+ assert p != null
+ phase.process_annotated_node(p, na)
end
if errcount != self.error_count then
self.check_errors
end
if errcount != self.error_count then
self.check_errors
- break
end
end
+ phase.process_nmodule_after(nmodule)
end
self.check_errors
end
end
self.check_errors
end
@@
-145,10
+154,12
@@
redef class ToolContext
var time1 = get_time
self.info("*** END SEMANTIC ANALYSIS: {time1-time0} ***", 2)
var time1 = get_time
self.info("*** END SEMANTIC ANALYSIS: {time1-time0} ***", 2)
- errors_info
+ self.check_errors
end
end
- fun phase_process_npropdef(phase: Phase, npropdef: APropdef)
+ # Process the given `phase` on the `npropdef`
+ # Called by `run_phases`
+ protected fun phase_process_npropdef(phase: Phase, npropdef: APropdef)
do
phase.process_npropdef(npropdef)
end
do
phase.process_npropdef(npropdef)
end
@@
-218,7
+229,7
@@
abstract class Phase
end
# By default, the name is the lowercased prefix of the classname
end
# By default, the name is the lowercased prefix of the classname
- redef fun to_s do return class_name.strip_extension("Phase").to_lower
+ redef fun to_s do return class_name.strip_extension("Phase").to_snake_case
# Is the phase globally disabled?
# A disabled phase is not called automatically called by `ToolContext::run_phases` and cie.
# Is the phase globally disabled?
# A disabled phase is not called automatically called by `ToolContext::run_phases` and cie.
@@
-244,4
+255,10
@@
abstract class Phase
# Note that the order of the visit is the one of the file
# @toimplement
fun process_annotated_node(node: ANode, nat: AAnnotation) do end
# Note that the order of the visit is the one of the file
# @toimplement
fun process_annotated_node(node: ANode, nat: AAnnotation) do end
+
+ # Specific actions to execute on the whole tree of a module
+ # Called at the end of a phase on a module
+ # Last called hook
+ # @toimplement
+ fun process_nmodule_after(nmodule: AModule) do end
end
end