nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
frontend/serialization: use types from model at deserialization
[nit.git]
/
src
/
frontend
/
simple_misc_analysis.nit
diff --git
a/src/frontend/simple_misc_analysis.nit
b/src/frontend/simple_misc_analysis.nit
index
9e3775d
..
4934e1a
100644
(file)
--- a/
src/frontend/simple_misc_analysis.nit
+++ b/
src/frontend/simple_misc_analysis.nit
@@
-24,6
+24,7
@@
module simple_misc_analysis
import phase
redef class ToolContext
import phase
redef class ToolContext
+ # Execute `AModule::do_simple_misc_analysis` on each module.
var simple_misc_analysis_phase: Phase = new SimpleMiscAnalysisPhase(self, null)
end
var simple_misc_analysis_phase: Phase = new SimpleMiscAnalysisPhase(self, null)
end
@@
-39,6
+40,12
@@
redef class AModule
do
var v = new SimpleMiscVisitor(toolcontext)
v.enter_visit(self)
do
var v = new SimpleMiscVisitor(toolcontext)
v.enter_visit(self)
+
+ var t = location.file.first_token
+ while t != null do
+ t.accept_simple_misc_token(v)
+ t = t.next_token
+ end
end
end
end
end
@@
-59,9
+66,12
@@
private class SimpleMiscVisitor
toolcontext.warning(node.hot_location, tag, msg)
end
toolcontext.warning(node.hot_location, tag, msg)
end
- init(toolcontext: ToolContext)
+ # Issue a warning if `sub` is a standalone `do` block.
+ fun check_do_expr(sub: nullable AExpr)
do
do
- self.toolcontext = toolcontext
+ if sub isa ADoExpr then
+ warning(sub, "useless-do", "Warning: superfluous `do` block.")
+ end
end
end
end
end
@@
-77,6
+87,12
@@
redef class ANode
private fun after_simple_misc(v: SimpleMiscVisitor) do end
end
private fun after_simple_misc(v: SimpleMiscVisitor) do end
end
+redef class Token
+ private fun accept_simple_misc_token(v: SimpleMiscVisitor)
+ do
+ end
+end
+
redef class ASignature
redef fun after_simple_misc(v)
do
redef class ASignature
redef fun after_simple_misc(v)
do
@@
-135,16
+151,45
@@
redef class AWhileExpr
else
n_expr.warn_parentheses(v)
end
else
n_expr.warn_parentheses(v)
end
+ v.check_do_expr(n_block)
+ end
+end
+
+redef class ADoExpr
+ redef fun after_simple_misc(v)
+ do
+ v.check_do_expr(n_block)
+ end
+end
+
+redef class ALoopExpr
+ redef fun after_simple_misc(v)
+ do
+ v.check_do_expr(n_block)
end
end
redef class AForExpr
redef fun after_simple_misc(v)
do
end
end
redef class AForExpr
redef fun after_simple_misc(v)
do
+ v.check_do_expr(n_block)
+ end
+end
+
+redef class AForGroup
+ redef fun after_simple_misc(v)
+ do
n_expr.warn_parentheses(v)
end
end
n_expr.warn_parentheses(v)
end
end
+redef class AWithExpr
+ redef fun after_simple_misc(v)
+ do
+ v.check_do_expr(n_block)
+ end
+end
+
redef class AIfExpr
redef fun after_simple_misc(v)
do
redef class AIfExpr
redef fun after_simple_misc(v)
do
@@
-172,3
+217,25
@@
redef class AOnceExpr
v.once_count = v.once_count - 1
end
end
v.once_count = v.once_count - 1
end
end
+
+redef class TSemi
+ redef fun accept_simple_misc_token(v)
+ do
+ var n = next_token
+ var p = prev_token
+ if
+ n == null or
+ n isa TEol or
+ n isa EOF or
+ n isa TComment or
+ p == null or
+ p isa TEol or
+ p isa EOF or
+ p isa TComment or
+ p isa TSemi
+ then
+ v.warning(self, "semi", "Warning: superfluous `;`.")
+ return
+ end
+ end
+end