nitc :: DivByZeroVisitor :: _mmodule
The mmodule is the current modulenitc :: DivByZeroVisitor :: _toolcontext
The toolcontext is our entree point to most servicesnitc :: DivByZeroVisitor :: defaultinit
nitc :: DivByZeroVisitor :: mmodule=
The mmodule is the current modulenitc :: DivByZeroVisitor :: toolcontext
The toolcontext is our entree point to most servicesnitc :: DivByZeroVisitor :: toolcontext=
The toolcontext is our entree point to most servicesnitc $ DivByZeroVisitor :: SELF
Type of this instance, automatically specialized in every classnitc $ DivByZeroVisitor :: visit
What the visitor do when a node is visitednitc :: DivByZeroVisitor :: _mmodule
The mmodule is the current modulenitc :: DivByZeroVisitor :: _toolcontext
The toolcontext is our entree point to most servicescore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: Visitor :: current_node=
The current visited nodenitc :: DivByZeroVisitor :: defaultinit
nitc :: Visitor :: defaultinit
core :: Object :: defaultinit
nitc :: Visitor :: enter_visit
Ask the visitor to visit a given node.core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
nitc :: DivByZeroVisitor :: mmodule=
The mmodule is the current modulecore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: DivByZeroVisitor :: toolcontext
The toolcontext is our entree point to most servicesnitc :: DivByZeroVisitor :: toolcontext=
The toolcontext is our entree point to most services
# The real visitor that does the real job
private class DivByZeroVisitor
super Visitor
# The toolcontext is our entree point to most services
var toolcontext: ToolContext
# The mmodule is the current module
var mmodule: MModule
redef fun visit(node)
do
# Recursively visit all sub-nodes
node.visit_all(self)
# Now just filter out until we get what we want...
# 1. We need a `/` operation
if not node isa ASlashExpr then return
# 2. The second operand must be an integer literal
var op2 = node.n_expr2
if not op2 isa AIntegerExpr then return
# 3. Its value must be 0
# Note: because of `literal_phase` the `value` method exists
if op2.value != 0 then return
# 4. The receiver (first operand) must be an Int
var op1 = node.n_expr
var int_type = mmodule.get_primitive_class("Int").mclass_type
if not op1.mtype.is_subtype(mmodule, null, int_type) then return
# Error detected
toolcontext.warning(node.location, "div-by-zero", "Warning: division by zero.")
end
end
src/frontend/div_by_zero.nit:49,1--85,3